如何在交易Braintree时生成客户ID(How do i generate a customer id while doing transaction Braintree)

编程入门 行业动态 更新时间:2024-10-25 15:35:24
如何在交易Braintree时生成客户ID(How do i generate a customer id while doing transaction Braintree)

我的目标是在生成客户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); } }); });

My goal is to generate a transaction sale while generating the customer id so that I could store the customer id to the database

The reason why i need customer id is because so that the same user doesn't need to enter his credit/debit card again

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); } }); });

最满意答案

充分披露:我在Braintree工作。 如果您有任何其他问题,请随时与支持部门联系。

一种选择是使用storeInVaultOnSuccess标志。 如果交易成功,则付款方式将存储在您的Braintree保险柜中。

如果您还传递customerId作为Braintree保险柜中的现有记录,则生成的存储付款方式将与该客户相关联。 否则,将为该付款方式创建新的客户记录。 您可以像这样访问结果对象上的新客户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); } });

Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support.

One option would be to use the storeInVaultOnSuccess flag. If the transaction is successful, then the payment method will be stored in your Braintree Vault.

If you also pass in a customerId for an existing record in your Braintree Vault, then the resulting stored payment method will be associated with that customer. Otherwise, a new customer record will be created for the payment method. You can access the new customer ID on the result object like this:

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); } });

更多推荐

本文发布于:2023-07-29 14:12:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1316790.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:客户   如何在   Braintree   ID   transaction

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!