Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: braintree.connect is not a function

I've implemented a braintree using its documentation but, facing this error in the terminal. it's showing that braintree.connect is not a function, but in the documentation it has been provided hard coded.


var gateway = braintree.connect({
  environment: braintree.Environment.Sandbox,
  merchantId: "useYourMerchantId",
  publicKey: "useYourPublicKey",
  privateKey: "useYourPrivateKey"
});

Here is my code!

const { response } = require("express");

var gateway = braintree.connect({
  environment: braintree.Environment.Sandbox,
  merchantId: "useYourMerchantId",
  publicKey: "useYourPublicKey",
  privateKey: "useYourPrivateKey"
});

exports.getToken = (req,res) => {
    gateway.clientToken.generate({}, function (err, response) {
        if(err){
            res.status(500).json(err)
        }else{
            res.send(response)
        }
      });
}

exports.processPayment = (req,res) => {
    let nonceFromTheClient = req.body.paymentMethodNonce

    let amountFromTheClient = req.body.amount

    gateway.transaction.sale({
        amount: amountFromTheClient,
        paymentMethodNonce: nonceFromTheClient,
        options: {
          submitForSettlement: true
        }
      }, function (err, result) {
          if (err) {
              res.status(500).json(error)
          }else{
              res.json(result);
          }
      });
}
like image 865
Sumit Avatar asked Sep 20 '20 12:09

Sumit


1 Answers

They have changed the process and I think forgot to update their official documentation. Here is the new way to initialise Braintree in nodejs mentioned on their github repo.

var gateway = new braintree.BraintreeGateway({
  environment: braintree.Environment.Sandbox,
  merchantId: 'your_merchant_id',
  publicKey: 'your_public_key',
  privateKey: 'your_private_key'
}); 
like image 96
Shafqat Jamil Khan Avatar answered Sep 22 '22 02:09

Shafqat Jamil Khan