Stripe PaymentMethod vs Card: 我应该使用 default_source 还是 default_payment_method?

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

Stripe PaymentMethod vs Card: Do I use default_source or default_payment_method?

问题

我困惑于检查客户是否设置了付款方式或来源时应该使用什么。我应该使用 default_source 还是 default_payment_method

我需要检查客户是否有付款方式或来源。如果没有,应该提示填写账单详细信息表单,直到设置完成。

在 Stripe 文档中发现 Sources API 已弃用

当创建卡对象时,会设置 default_source,当没有默认卡时

我正在将 Stripe 集成到我的 React-Python 应用中,我感到困惑是否应该选择第一种选项:stripe.Customer.card.create,它会设置 default_source,还是我应该选择第二种选项:

// stripe-react 集成代码片段
const { error, paymentMethod } = await stripe.createPaymentMethod({
  type: "card",
  card: elements.getElement(CardNumberElement),
});

// Python
payment_method = stripe.PaymentMethod.attach(
         payment_method_id,
         customer=stripe_customer_id,
    )

// 设置为默认付款方式
customer = stripe.Customer.modify(stripe_customer_id,
    invoice_settings={
        "default_payment_method": payment_method["id"]
    })

当选择第二种选项时,我可以看到付款方式已设置在账单门户中。似乎能够完成任务。只是在何时使用 Card 而不是 PaymentMethod 时感到困惑。

英文:

I am confused as to which do I use for checking if customer has set a payment method or source. Do I use default_source or default_payment_method?

I need to check if a customer has a payment method or source. If there's none, billing details form should be prompt until it gets set.

Found in stripe docs that the Sources API is deprecated.

The default_source is set when creating a card object and when there's no default card..

I'm integrating stripe in my React-Python app and I'm confused if I should do first option : stripe.Customer.card.create which sets the default_source or if I do the 2nd option:

// stripe-react integration snippet
const { error, paymentMethod } = await stripe.createPaymentMethod({
  type: "card",
  card: elements.getElement(CardNumberElement),
});

// python
payment_method = stripe.PaymentMethod.attach(
         payment_method_id,
         customer=stripe_customer_id,
    )

// set as default payment method
customer = stripe.Customer.modify(stripe_customer_id,
    invoice_settings={
        "default_payment_method": payment_method["id"]
    })

When I do the 2nd option, I can see the payment methods are set in the billing portal. It seems to do the job. Just confused when to use Card over PaymentMethod.

答案1

得分: 1

如果您想检查客户是否配置了默认付款方式或来源,那么您需要同时检查客户对象上的default_source字段和invoice_settings.default_payment_method字段。客户在这两个字段中都设置了值是有效状态,此时invoice_settings.default_payment_method优先考虑。

要创建新的付款方式,您应该使用设置意向(Setup Intents)以及下面链接文档中概述的方法:
https://stripe.com/docs/payments/accept-a-payment-deferred?type=setup

或者,如果您希望使用Stripe托管的页面来收集付款方式的详细信息,可以使用此处显示的流程:
https://stripe.com/docs/payments/save-and-reuse?platform=checkout

英文:

If you want to check whether a Customer has a default payment method or source configured, then you will want to check both the default_source field and the invoice_settings.default_payment_method fields on the Customer object. It is a valid state for a Customer to have a value set in both of those fields, in which case invoice_settings.default_payment_method is given priority.

For creating new Payment Methods, you should use Setup Intents and the approach outlined in the document linked below:
https://stripe.com/docs/payments/accept-a-payment-deferred?type=setup

Alternatively you can use the flow shown here if you would prefer to use a Stripe-hosted page for collecting payment method details:
https://stripe.com/docs/payments/save-and-reuse?platform=checkout

huangapple
  • 本文由 发表于 2023年3月31日 04:02:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/75892532.html
匿名

发表评论

匿名网友

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

确定