【问题标题】:How to get and pass customer information in Stripe?如何在 Stripe 中获取和传递客户信息?
【发布时间】:2020-09-25 09:24:52
【问题描述】:

无法为我的条带交易获取 customer_id。

1) 我们如何从 Stripe 获取 customer_id?我假设它在我注册用户(获取他们的姓名和电子邮件)后开始。但是,Stripe 文档尚不清楚。有人对此有明确的代码吗?

2) 我们如何/在哪里将其放回系统中?

后端:节点。 js。赫罗库

【问题讨论】:

  • 你的问题有点不清楚。您是在尝试从 Balance Transaction 中检索 customer_id,还是在创建客户时存储 customer_id 时遇到问题?请告诉我。
  • @MadhuJayarama 两者。尝试在 a.user 注册后从我的应用生成 customer_id(没有仪表板)。然后在刷卡时通过它。这可能吗?大多数文档向我们展示了如何在仪表板中执行此操作,但这没有多大意义……因为它是一个应用程序?

标签: node.js swift heroku stripe-payments


【解决方案1】:

当您使用API 创建客户时,API 响应将包含客户的 ID。这是 Node.js 中的一个示例。

const customer = await stripe.customers.create({
  description: 'My First Test Customer (created for API docs)',
});

// This is the customer ID that is of the form "cus_xxx"
console.log(customer.id);

如果您在 Stripe Dashboard 中创建客户,则在查看详细信息页面时,客户的 ID 位于 URL 中。此外,它位于客户详细信息视图的右上角。

然后可以在创建 PaymentIntents、Subscriptions 和其他需要客户 ID 的对象时使用此客户 ID。 full API reference 中提供了每个 API 的完整参数列表。

【讨论】:

    【解决方案2】:

    您可以在API 的帮助下创建客户。

    const customer = await stripe.customers.create({
        description: 'My First Test Customer (created for API docs)',
    });
    
    const customerId = customer.id;
    

    然后您可以为特定客户将此条状 customerId 存储在您的数据库中,以便您以后可以将此 customerId 用于余额交易或创建付款意图。

    请注意Retrieve Balance Transaction API不会直接给出进行交易的客户的customerId。

    为此,您需要从余额交易中检索来源(chargeId)。

    const transactionId = 'txn_1CzRLEEHiz05HoqrMuNqqHD1'; // Replace this with Balance transaction id which you have to retrieve.
    stripe.balanceTransactions.retrieve(
        transactionId,
        function(err, balanceTransaction) {
           const chargeId = balanceTransaction.source;
        }
    );
    

    获得特定余额交易的chargeId 后,您可以在Retrieve a Charge API 中使用此chargeId 来了解customerId。

    stripe.charges.retrieve(
        chargeId,
        function(err, charge) {
           // asynchronously called
           const customerId = charge.customer;
        }
    );
    

    所以现在,您有了进行该交易的客户的 customerId。 我希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2020-12-22
      • 2020-11-28
      • 2017-03-06
      • 2013-03-13
      • 1970-01-01
      • 2019-02-07
      • 2020-03-28
      • 2014-02-20
      • 1970-01-01
      相关资源
      最近更新 更多