我的目标是在生成客户 ID 的同时生成交易销售,以便我可以将客户 ID 存储到数据库中
我需要客户 ID 的原因是因为同一个用户不需要再次输入他的信用卡/借记卡
const gateway = braintree.connect({
environment: braintree.Environment.Sandbox,
merchantId: '',
publicKey: '',
privateKey: ''
});
app.post('/payment', (req, res, next) => {
gateway.transaction.sale({
amount: req.body.amount,
paymentMethodNonce: req.body.nonce,
options: {
submitForSettlement: true
}
}, function (err, result) {
if (err) {
res.json(err)
}
if (result.success) {
console.log('Transaction ID: ' + result.transaction.id);
res.json({
transactionId: result.transaction.id
})
} else {
console.error(result.message);
}
});
});
完全披露:我在布伦特里工作。如果您有任何其他问题,请随时联系支持。
一种选择是使用storeInVaultOnSuccess
标志。如果交易成功,那么付款方式将存储在您的 Braintree Vault 中。
如果您还在customerId
Braintree Vault 中为现有记录传入 a ,则生成的存储付款方式将与该客户相关联。否则,将为付款方式创建新的客户记录。您可以像这样访问结果对象上的新客户 ID:
gateway.transaction.sale({
amount: "10.00",
paymentMethodNonce: "fake-valid-nonce",
options: {
submitForSettlement: true,
storeInVaultOnSuccess: true
}
}, function (err, result) {
if (err) {
// handle err
}
if (result.success) {
console.log('Transaction ID: ' + result.transaction.id);
console.log('Customer ID: ' + result.transaction.customer.id);
} else {
console.error(result.message);
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句