Search code examples
meteorbraintree

Meteor patrickml:braintree Authentication Error


This command meteor add patrickml:braintree was run in a Meteor app directory.

In the client.main.js:
A squiggly line Under the variable braintree and the IDE says "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);
        }
      });
    }
  });
});

In the server code below, clientId is always undefined.

//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;
  }

And the server console prints out:

Exception while invoking method 'getClientToken' authenticationError: Authentication Error

Any idea what is wrong and how to fix it? thx


Solution

  • Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support.

    When you configure your gateway object, make sure that you use the API credentials documented in your Sandbox Control Panel. Here's how you can find them:

    1. Log into the sandbox Control Panel
    2. Navigate to Account > My user
    3. Under API Keys, Tokenization Keys, Encryption Keys, click View Authorizations
      • If no API keys appear, click Generate New API Key
    4. Click View under the Private Key column to see your public and private keys, merchant ID, and environment

    When you have them, use them to configure your gateway object. For example:

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