我正在使用 node.js Braintree sdk 来尝试创建子商家帐户。但是,到目前为止它一直不成功,我不断收到未经授权的错误,但我不知道如何在此调用中传递令牌。
这是我正在使用的网关:
// 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
});
这是我正在打的电话:
// 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}) }
};
结果是这个错误:
UnauthorizedError: No authorization token was found
但是在查看商家帐户时,我看不到在哪里添加令牌: Create docs of braintree。
如果您有关于如何拨打此电话以添加子商家的解决方案,请分享。