Meteor patrickml:braintree 身份验证错误

Meteor patrickml:braintree Authentication Error

此命令 meteor add patrickml:braintree 位于 Meteor 应用程序目录中 运行。

在client.main.js:
变量 braintree 和 IDE 下的波浪线表示 "unresolved variable or type"。

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

知道哪里出了问题以及如何解决吗?谢谢

完全披露:我在 Braintree 工作。如果您有任何其他问题,请随时联系 support.

配置网关对象时,请确保使用 API credentials documented in your Sandbox Control Panel。找到它们的方法如下:

  1. 登录 sandbox Control Panel
  2. 导航到帐户 > 我的用户
  3. API 密钥、令牌化密钥、加密密钥 下,单击查看授权
    • 如果没有出现 API 密钥,请单击生成新的 API 密钥
  4. 单击私钥列下的查看以查看您的public私钥商家 ID 和环境

当您拥有它们时,请使用它们来配置您的网关对象。例如:

var braintree = require("braintree");

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