英文:
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: "default_incomplete",
payment_settings: { save_default_payment_method: "on_subscription" },
expand: ["latest_invoice.payment_intent"],
});
Then I pass the client_secret to my front end and I render the Stripe Payment Component (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",
});
}}
>
Pay Now
</Button>
</Elements>;
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论