Search code examples
javascriptmeteorbraintree

Meteor TypeError: braintree.setup is not a function


I am trying to work on braintree for our app but it seems like I keep on getting same error. I installed braintree-web successfully (twice) and I am importing braintree. I am using the correct client token.

TypeError: braintree.setup is not a function

import braintree from 'braintree-web';

Template.braintree_payment.onRendered(function(){ 
    var clientToken = "abc....";

    console.log("logging");
    braintree.setup(clientToken, "dropin", {
      container: "payment-form"
    });  
});

Solution

  • Which version of braintree-web are you using? Version 2 should indeed have a braintree.setup function, but version 3 does not.

    Version 3 should be initialised like so:

    braintree.client.create({
      authorization: 'CLIENT_AUTHORIZATION'
    }, function (err, clientInstance) {
      braintree.hostedFields.create(/* ... */);
    });
    

    Check out the docs for version 3 here: https://developers.braintreepayments.com/guides/client-sdk/setup/javascript/v3