Stripe:获取信用卡信息,以便客户可以更新他们的信用卡。

huangapple go评论61阅读模式
英文:

Stripe: Get card information so customer can update their card

问题

我的应用程序使用Stripe的订阅功能。

我想创建一个标准的“账户”页面,该页面将列出客户当前的信用卡信息(如“MasterCard”和卡号的最后4位),并为客户提供更新该信息的选项。

我卡在了第一步上,即获取当前的卡片信息。为了做到这一点,我需要当前的卡片ID。我尝试过“listSources”方法,但这返回了卡片信息应该存在的地方的空数据。我需要做什么才能获取那张卡片的信息?

以下是我尝试过的内容:

(我正在使用Node,并在服务器端运行此代码)

我找到的最接近的方法是这里

var stripe = require('stripe')(STRIPE_TOKEN);

stripe.customers.listSources(
  CUSTOMER_ID,
  {object: 'bank_account', limit: 3},
  function(err, cards) {
    // 异步调用
  }
);

这会返回信息(没有错误),但文档说这个方法应该返回包含每张卡片的卡片ID的数据数组。在测试中,数据数组一直为空。

我正在使用一个具有有效订阅和我可以在Stripe仪表板上看到的卡片的客户ID进行测试。

为什么数据数组为空?

注意:还有一个检索源方法,它应该返回卡片的详细信息,但此方法要求您拥有您要获取信息的卡片的ID,这正是我现在无法获取的。

英文:

My app uses subscriptions with Stripe.

I want to create a standard "account" page, which will list the customer's current card information (like "MasterCard" and last 4 of card number), and give the customer the option of updating that information.

I'm stuck on the first piece--getting back the current card information. To do this, I need the current card_id. I have tried the "listSources" method, but this returns blank data where the card info is supposed to be. What do I need to do to get that card info?

Here is what I've tried:

(I'm using Node, and running this server side)

The closest method I have found is here:

var stripe = require('stripe')(STRIPE_TOKEN);

stripe.customers.listSources(
  CUSTOMER_ID,
  {object: 'bank_account', limit: 3},
  function(err, cards) {
    // asynchronously called
  }
);

This returns information (there's no error), but the docs say this method should return a data array of the cards that includes the card id for each. In testing, the data array keeps coming back empty.

I am testing with a customer id that has a valid subscription and a card that I can see on my Stripe dashboard.

Why is the data array coming back empty?

Note: there's also a retrieve source method, which should give back card details, but this method requires you have the id of the card you want info on, and that's what I am not able to get right now.

答案1

得分: 0

Stripe最近推出了PaymentMethods,它们取代了较旧的Tokens和Sources API。

OP的问题是他们的集成创建了PaymentMethod对象,这些对象不会显示在来源列表中,但可以通过stripe.paymentMethods.list访问。

英文:

<sup><sub>Converting this to an answer...</sub></sup>

Stripe has recently rolled out PaymentMethods, which replace (and are separate from) the older Tokens and Sources API.

OP's issue is that their integration creates PaymentMethod objects, which won't show up in the sources list, but can instead be accessed via stripe.paymentMethods.list.

huangapple
  • 本文由 发表于 2020年1月7日 00:21:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/59615521.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定