我的目标是在生成客户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); } });更多推荐
发布评论