如何在进行交易Braintree时生成客户ID

问题描述 投票:1回答:1

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

});
node.js payment-gateway braintree
1个回答
1
投票

完全披露:我在Braintree工作。如果您有任何其他问题,请随时联系support

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

如果您还为braintree Vault中的现有记录传入customerId,则生成的存储付款方式将与该客户相关联。否则,将为付款方式创建新的客户记录。您可以在结果对象上访问新的客户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);
  }
});
© www.soinside.com 2019 - 2024. All rights reserved.