3

我想複製布倫特裏演示應用程序... import * as braintree from 'braintree';運行時錯誤:類繼承值對象的對象]不使用離子3.</p> <p>我已經進口布倫特里與構造函數或空

但我無法連接braintree。

消息讀取......「運行時錯誤:類延伸值[對象的對象]不是一個構造或空」

這是在我的TS代碼文件

import { Component } from '@angular/core'; 
import { IonicPage, NavController, NavParams, ViewController } from 'ionic-angular'; 

import * as braintree from 'braintree'; 

@IonicPage() 
@Component({ 
    selector: 'page-apply', 
    templateUrl: 'apply.html', 
}) 

export class ApplyPage { 

    gateway: any; 

    constructor(public navCtrl: NavController, public navParams: NavParams, public viewCtrl: ViewController) { 
    this.gateway = braintree.connect({ 
     environment: braintree.Environment.Sandbox, 
     merchantId: 'personalMerchantId', 
     publicKey: 'personalPublicKey', 
     privateKey: 'personalPrivateKey' 
    }); 
    } 

    ionViewDidLoad() { 
    console.log('ionViewDidLoad ApplyPage'); 
    } 


} 

這是模塊

'use strict'; 

module.exports = require('./lib/braintree'); 

的index.js文件而這種碼內碼坐在其中的index.js點

0 braintree.js文件
'use strict'; 

let version = require('../package.json').version; 
let Config = require('./braintree/config').Config; 
let Environment = require('./braintree/environment').Environment; 
let BraintreeGateway = require('./braintree/braintree_gateway').BraintreeGateway; 
let errorTypes = require('./braintree/error_types').errorTypes; 

let Transaction = require('./braintree/transaction').Transaction; 

let CreditCard = require('./braintree/credit_card').CreditCard; 
let PayPalAccount = require('./braintree/paypal_account').PayPalAccount; 
let AndroidPayCard = require('./braintree/android_pay_card').AndroidPayCard; 
let ApplePayCard = require('./braintree/apple_pay_card').ApplePayCard; 
let VenmoAccount = require('./braintree/venmo_account').VenmoAccount; 
let CoinbaseAccount = require('./braintree/coinbase_account').CoinbaseAccount; 
let AmexExpressCheckoutCard = require('./braintree/amex_express_checkout_card').AmexExpressCheckoutCard; 
let VisaCheckoutCard = require('./braintree/visa_checkout_card').VisaCheckoutCard; 
let MasterpassCard = require('./braintree/masterpass_card').MasterpassCard; 

let CreditCardVerification = require('./braintree/credit_card_verification').CreditCardVerification; 
let Subscription = require('./braintree/subscription').Subscription; 
let MerchantAccount = require('./braintree/merchant_account').MerchantAccount; 
let PaymentInstrumentTypes = require('./braintree/payment_instrument_types').PaymentInstrumentTypes; 
let WebhookNotification = require('./braintree/webhook_notification').WebhookNotification; 
let TestingGateway = require('./braintree/testing_gateway').TestingGateway; 
let ValidationErrorCodes = require('./braintree/validation_error_codes').ValidationErrorCodes; 

let CreditCardDefaults = require('./braintree/test/credit_card_defaults').CreditCardDefaults; 
let CreditCardNumbers = require('./braintree/test/credit_card_numbers').CreditCardNumbers; 
let MerchantAccountTest = require('./braintree/test/merchant_account').MerchantAccountTest; 
let Nonces = require('./braintree/test/nonces').Nonces; 
let TransactionAmounts = require('./braintree/test/transaction_amounts').TransactionAmounts; 

let connect = config => new BraintreeGateway(new Config(config)); // eslint-disable-line func-style 
let Test = { 
    CreditCardDefaults: CreditCardDefaults, 
    CreditCardNumbers: CreditCardNumbers, 
    MerchantAccountTest: MerchantAccountTest, 
    Nonces: Nonces, 
    TransactionAmounts: TransactionAmounts 
}; 

module.exports = { 
    connect: connect, 
    version: version, 
    Environment: Environment, 
    errorTypes: errorTypes, 

    Transaction: Transaction, 

    CreditCard: CreditCard, 
    PayPalAccount: PayPalAccount, 
    AndroidPayCard: AndroidPayCard, 
    ApplePayCard: ApplePayCard, 
    VenmoAccount: VenmoAccount, 
    CoinbaseAccount: CoinbaseAccount, 
    AmexExpressCheckoutCard: AmexExpressCheckoutCard, 
    VisaCheckoutCard: VisaCheckoutCard, 
    MasterpassCard: MasterpassCard, 

    CreditCardVerification: CreditCardVerification, 
    Subscription: Subscription, 
    MerchantAccount: MerchantAccount, 
    PaymentInstrumentTypes: PaymentInstrumentTypes, 
    WebhookNotification: WebhookNotification, 
    TestingGateway: TestingGateway, 
    ValidationErrorCodes: ValidationErrorCodes, 

    Test: Test 
}; 

而這是在工作ExpressJs的index.js文件坐在代碼演示

var express = require('express'); 
var router = express.Router(); 
var braintree = require('braintree'); 

var gateway = braintree.connect({ 
    environment: braintree.Environment.Sandbox, 
    merchantId: 'personalMerchantID', 
    publicKey: 'personalPublicKey', 
    privateKey: 'personal_PrivateKey' 
}); 

router.get('/', function(req, res) { 
    gateway.clientToken.generate({}, function(err, response) { 
    var token = response.clientToken; 

    res.render('index', {token : token}); 
    }); 
}); 

router.post('/add', function(req, res) { 

    var merchant_id = req.body.merchant_id; 
    var bank_account = req.body.bank_account; 
    var bank_routing = req.body.bank_routing; 

    var merchantAccountParams = { 
    individual: { 
     firstName: "Jane", 
     lastName: "Doe", 
     email: "[email protected]", 
     phone: "5553334444", 
     dateOfBirth: "1981-11-19", 
     ssn: "456-45-4567", 
     address: { 
     streetAddress: "111 Main St", 
     locality: "Chicago", 
     region: "IL", 
     postalCode: "60622" 
     } 
    }, 
    funding: { 
     destination: braintree.MerchantAccount.FundingDestination.Bank, 
     accountNumber: bank_account, 
     routingNumber: bank_routing 
    }, 
    tosAccepted: true, 
    masterMerchantAccountId: "_my_personal_master_merchant_account_ID", 
    id: merchant_id 
    }; 

    gateway.merchantAccount.create(merchantAccountParams, function (err, result) { 
    res.render('addResult', {result: result}); 
    }); 

}); 

router.get('/find', function(req, res) { 
    var merchant_id = req.query.merchant_id; 

    gateway.merchantAccount.find(merchant_id, function(err, result) { 
    res.render('findResult', {result: result, merchant_id: merchant_id}); 
    }); 

}); 

router.post('/process', function(req, res) { 
    var nonce = req.body.payment_method_nonce; 
    var total = req.body.total; 
    var service = req.body.service; 
    var merchant_id = req.body.merchant_id; 

    gateway.transaction.sale({ 
    amount: total, 
    merchantAccountId: merchant_id, 
    paymentMethodNonce: nonce, 
    serviceFeeAmount: service 
    }, function (err, result) { 
    res.render('processResult', {result: result}); 
    }); 
}); 

module.exports = router; 

再次上述代碼是由布倫特裏生產。我確信只用於演示目的。

+0

你使用任何插件? – Sampath

+0

我不這麼認爲...... –

回答

3

你不應該這樣做。

通過在移動客戶端中包含Braintree節點服務器庫,您可以將您的私鑰暴露給正在使用該應用的任何人。這是非常不安全的。

相反,您應該有一個服務器,您可以在其中接受應用程序生成的隨機數以處理事務。 @Sampath發佈的Braintree Cordova插件看起來像是一種合理的方式,可以在您的應用中生成隨機數。

+0

你是對的,但我是在braintree技術人員發送給我的braintree市場演示。目前,我仍然無法連接。但有一天這將被整理出來。謝謝。 –

+1

完全披露:我爲Braintree工作。你能提供他們給你的鏈接嗎?我想知道是否有更明確的方式顯示文檔以顯示需要服務器。 – BladeBarringer

+0

好的。我會更仔細地留意您的建議並重新編寫我的代碼。謝謝。 –

1

看來你沒有使用任何與上述實施插件。所以你必須使用一個。這是Braintree Cordova Plugin

npm install plist 
npm install xcode 

cordova platform remove ios 
cordova plugin add https://github.com/taracque/cordova-plugin-braintree 
cordova platform add ios 

在這裏,您可以看到如何none native plugin添加到應用程序離子。

+0

我能夠按照這兩個鏈接中的說明進行操作,並獲得了有希望的結果。但是,在調用第二個鏈接中的函數時導入braintree節點包會得到相同的結果。市場演示調用連接功能。當我嘗試調用相同的函數時,我收到原始錯誤消息。謝謝你的努力 –

+0

@PatrickOdum你有沒有想過如何解決這個問題?我得到相同的錯誤 – nareeboy

+0

還沒有。我認爲這與運行時錯誤有關。也許有人知道打字稿可以提供答案。 –

相關問題