【问题标题】:How do i generate a customer id while doing transaction Braintree如何在进行交易 Braintree 时生成客户 ID
【发布时间】:2018-08-09 07:07:12
【问题描述】:

我的目标是在生成客户 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】:

    全面披露:我在 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);
      }
    });
    

    【讨论】:

      猜你喜欢
      • 2019-11-11
      • 2016-03-09
      • 2015-01-09
      • 2021-12-02
      • 2016-05-04
      • 2013-05-09
      • 2018-11-21
      • 1970-01-01
      • 2016-09-19
      相关资源
      最近更新 更多