您必须创建一个“braintree 客户”,然后将 Braintree.customer.id 存储到您的用户对象中。
然后,如果您有一个 Braintree 客户 ID,您可以像我一样生成一个自定义客户令牌。在您的后端调用它以生成一个,然后在您的 Drop-in show({clientToken}) 选项字段中使用它
if(!req.user.brainTreeCustomerId){
gateway.customer.create({
firstName: req.user.name.first,
lastName: req.user.name.last,
email: req.user.email
}, function (err, result) {
if(err) return error(res, 500, "Something went wrong while creating customer payment profile");
if(result.success){
req.user.brainTreeCustomerId = result.customer.id;
req.user.save();
}
});
}
return gateway.clientToken.generate({
customerId: req.user.brainTreeCustomerId
})
.then(response => {
console.log(response);
return result(res, 200, response.clientToken);
}).catch(error(res));