2017-03-13 26 views
0

此命令meteor add patrickml:braintree在Meteor應用程序目錄中運行。Meteor patrickml:braintree身份驗證錯誤

在client.main.js中:
波浪線在變量braintree下,並且IDE顯示「未解析的變量或類型」。

Template.payment.onRendered(function() { 
    Meteor.call('getClientToken', function (error, clientToken) { 
    if (error) { 
     console.log(error); //<---- always prints out 
    } else { 
    //vvvvvvvvv 
     braintree.setup(clientToken, "dropin", { 
     container: "payment-form", // Injecting into <div id="payment-form"></div> 
     onPaymentMethodReceived: function (response) { 
      var nonce = response.nonce; 
      console.log(nonce); 
     } 
     }); 
    } 
    }); 
}); 

在下面的服務器代碼中,clientId總是未定義的。

//server/main.js 
'getClientToken': function (clientId) { 
    console.log(clientId); //<--------- undefined 
    let generateToken = Meteor.wrapAsync(gateway.clientToken.generate, gateway.clientToken); 
    let options = {}; 

    if (clientId) { 
     options.clientId = clientId; 
    } 

    let response = generateToken(options); 
    return response.clientToken; 
    } 

而且服務器控制檯打印出:

Exception while invoking method 'getClientToken' authenticationError: Authentication Error

任何想法是錯誤的,如何解決呢? thx

+0

的布倫特裏例外['authenticationError'(https://developers.braintreepayments.com/reference/general/exceptions/#authentication-error)當你的API密鑰是不正確的上升。你有沒有檢查你的網關配置,以確保你使用正確的密鑰? – Shea

+0

@Shea這是沙箱環境,鍵被從他們的網頁複製和粘貼,基本上是字母「x」的長串, –

回答

0

完全披露:我在布倫特裏工作。如果您有任何其他問題,請隨時聯繫support

當您配置網關對象時,請確保您使用API credentials documented in your Sandbox Control Panel。這裏是你如何能找到它們:

  1. 登錄到sandbox Control Panel
  2. 導航到帳戶>我的用戶
  3. API鍵,符號化密鑰,加密密鑰,單擊查看授權
    • 如果沒有出現API密鑰,請點擊生成新的API密鑰
  4. 點擊查看私鑰欄下看到你公共私鑰商家ID,環境

當你擁有它們,使用它們來配置你的網關對象。例如:

var braintree = require("braintree"); 

var gateway = braintree.connect({ 
    environment: braintree.Environment.Sandbox, 
    merchantId: "replaceWithYourMerchantId", 
    publicKey: "replaceWithYourPublicKey", 
    privateKey: "replaceWithYourPrivateKey" 
});