Stripe在使用支付组件进行支付后未设置默认支付方式

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

Stripe not setting default payment method after payment with Payment Component

问题

在我的服务器上,我根据Stripe文档创建了一个支付意向:

const subscription = await stripe.subscriptions.create({
    customer: customer.id,
    items: [{ price: getPricePlan(plan) }],
    payment_behavior: "default_incomplete",
    payment_settings: { save_default_payment_method: "on_subscription" },
    expand: ["latest_invoice.payment_intent"],
});

然后我将client_secret传递到我的前端,并呈现Stripe支付组件(React):

<Elements options={{ clientSecret }} stripe={stripePromise}>
  <PaymentElement
    onChange={(e) => {
      setIsPaymentFormCompleted(e.complete);
    }}
  />
  <Button
    onClick={async () => {
      const response = await stripe.confirmPayment({
        type: "card",
        elements,
        redirect: "if_required",
      });
    }}
  >
    立即支付
  </Button>
</Elements>;

当我输入卡片详细信息并支付后,订阅会被创建,第一笔付款成功,但使用的卡片不会成为默认卡。这意味着对于随后的付款(例如订阅的第二个月),付款将失败,因为没有默认付款方式。

这很奇怪。你知道为什么传递了save_default_payment_method: "on_subscription"后,卡片没有被设置为默认吗?

英文:

On my server I create a payment intent based on Stripes docs with:

const subscription = await stripe.subscriptions.create({
    customer: customer.id,
    items: [{ price: getPricePlan(plan) }],
    payment_behavior: &quot;default_incomplete&quot;,
    payment_settings: { save_default_payment_method: &quot;on_subscription&quot; },
    expand: [&quot;latest_invoice.payment_intent&quot;],
  });

Then I pass the client_secret to my front end and I render the Stripe Payment Component (React)

&lt;Elements options={{ clientSecret }} stripe={stripePromise}&gt;
  &lt;PaymentElement
    onChange={(e) =&gt; {
      setIsPaymentFormCompleted(e.complete);
    }}
  /&gt;
  &lt;Button
    onClick={async () =&gt; {
      const response = await stripe.confirmPayment({
        type: &quot;card&quot;,
        elements,
        redirect: &quot;if_required&quot;,
      });
    }}
  &gt;
    Pay Now
  &lt;/Button&gt;
&lt;/Elements&gt;;

After I enter the card details and pay, the subscription is created, the first payment works but the card used does not become the default. This means that for the subsequent payment (like month 2 of the subscription for example) the payment will fail, since there is no default payment method.

This is super strange. Any idea why the card does not get set as a default given the save_default_payment_method: "on_subscription" is passed?

答案1

得分: 1

payment_settings.save_default_payment_method 在创建订阅时设置为 on_subscription 会将付款方式保存为订阅的默认方式。如果使用订阅 ID 检索订阅,您应该在 default_payment_method 属性中看到付款方式 ID。您也可以确认 payment_settings.save_default_payment_method 的值是否按预期设置为 on_subscription

英文:

Setting payment_settings.save_default_payment_method to on_subscription when creating the Subscription should save the Payment Method as the default on the Subscription.

If you retrieve the Subscription using the Subscription ID you should see the Payment Method ID in the default_payment_method property. You can also confirm the value of payment_settings.save_default_payment_method is set to on_subscription as expected.

huangapple
  • 本文由 发表于 2023年4月20日 06:42:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76059309.html
匿名

发表评论

匿名网友

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

确定