I am using the node.js braintree sdk to try creating sub merchant accounts. However, it has been unsuccessful so far and I keep getting a not authorized error but I don't know how to pass the token in this call.
Here's the gateway I am using:
// gateway
const braintree = require("braintree");
const gateway = new braintree.BraintreeGateway({
environment: braintree.Environment.Sandbox,
merchantId: process.env.BRAINTREE_MERCHANT_ID,
publicKey: process.env.BRAINTREE_PUBLIC_KEY,
privateKey: process.env.BRAINTREE_PRIVATE_KEY
});
And here's the call I'm making:
// sub merchant call
exports.createSubMerchant = async (req, res) => {
let {
firstName,
lastName,
email,
phone,
dateOfBirth,
ssn,
address1,
address2,
locality,
region,
postalCode,
businessLegalName,
businessDbaName,
taxId,
businessAddress1,
businessAddress2,
businessLocality,
businessRegion,
businessPostalCode,
fundingDescriptor,
fundingDestination,
fundingEmail,
fundingMobilePhone,
fundingAccountNumber,
fundingRoutingNumber,
tosAccepted,
id
} = req.body;
const merchantAccountParams = {
individual: {
firstName: firstName,
lastName: lastName,
email: email,
phone: phone,
dateOfBirth: dateOfBirth,
ssn: ssn,
address: {
streetAddress: `${address1}${address2 ? `, ${address2}` : null}`,
locality: locality,
region: region,
postalCode: postalCode
}
},
business: {
legalName: businessLegalName,
dbaName: businessDbaName,
taxId: taxId,
address: {
streetAddress: `${businessAddress1}${businessAddress2 ? `, ${businessAddress2}` : null}`,
locality: businessLocality,
region: businessRegion,
postalCode: businessPostalCode
}
},
funding: {
descriptor: fundingDescriptor,
destination: fundingDestination, // braintree.MerchantAccount.FundingDestination.Bank,
email: fundingEmail,
mobilePhone: fundingMobilePhone,
accountNumber: fundingAccountNumber,
routingNumber: fundingRoutingNumber
},
tosAccepted: tosAccepted,
masterMerchantAccountId: process.env.BRAINTREE_MERCHANT_ID,
id: id
};
try {
let result = await gateway.merchantAccount.create(merchantAccountParams)
console.log(`result: `, result)
res.json(result)
} catch (e) { console.log(e); res.json({error: e}) }
};
The result is this error:
UnauthorizedError: No authorization token was found
But I don't see where to add the token when looking at the Merchant Account: Create docs of braintree.
Please share if you have the solution on how to make this call to add sub merchants.
After receiving a response from Braintree, they confirmed they no longer offer this program.