如何更新条纹中的信用卡付款
How to update credit card payment in stripe
我有一个使用 nodejs 和 reactjs 的流程让用户订阅我的网站。
因此,当用户登录时,他可以看到一些包。
当用户选择包裹并输入卡详细信息时,我执行以下操作:
1 - 根据用户详细信息(姓名、电子邮件等,自用户登录后获取)创建新客户
2 - 根据price_id选择的
为新创建的客户创建订阅
3 - 在前端收集卡片 number/cvc/expire 日期:
const cardElement = elements.getElement(CardElement);
4 - 从前端调用条带:
const { error, paymentIntent } = await stripe.confirmCardPayment(clientSecret, {
payment_method: {
card: cardElement,
billing_details: {
name: name,
}
}
});
我不确定这是否是最佳流程。但是,它正在工作。
我还管理更新订阅和取消订阅。
但是,我很难更改信用卡详细信息。
我从文档中了解到,我应该使用与创建卡支付时相同的调用。
所以我再次收集信用卡号并再次调用相同的函数:
const { error, paymentIntent } = await stripe.confirmCardPayment(clientSecret, {
payment_method: {
card: cardElement,
billing_details: {
name: name,
}
}
});
然而,调用完成于:
https://api.stripe.com/v1/payment_intents/pi_XXXX/confirm
和 returns 400 具有以下信息:
type: "invalid_request_error", code: "payment_intent_unexpected_state", doc_url: "https://stripe.com/docs/error-codes/payment-intent-unexpected-state"
我应该使用其他工具来更新信用卡信息吗?还是我叫错了?
您最初调用 confirmCardPayment()
的流程是正确的,这也是 Stripe 文档中推荐的流程:https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=elements.
hard time in changing credit card details. What I understood from docs I should use the same call as I did when I create the card payment.
要仅收集卡详细信息并创建 PaymentMethod,您应该从 Stripe.js 调用 createPaymentMethod()
[0]。这会将客户的卡转换为类似 pm_123.
的 PaymentMethod
然后您将该 PaymentMethod 发送到您的后端服务器,在那里(使用您的服务器端 Stripe API 库,如 stripe-node)您将其附加到 Stripe 客户 [1] 并更新作为客户用于定期付款的默认付款方式 [2]。
[0] https://stripe.com/docs/js/payment_methods/create_payment_method
[1] https://stripe.com/docs/api/payment_methods/attach
[2]https://stripe.com/docs/api/customers/update#update_customer-invoice_settings-default_payment_method
我有一个使用 nodejs 和 reactjs 的流程让用户订阅我的网站。 因此,当用户登录时,他可以看到一些包。 当用户选择包裹并输入卡详细信息时,我执行以下操作:
1 - 根据用户详细信息(姓名、电子邮件等,自用户登录后获取)创建新客户
2 - 根据price_id选择的
为新创建的客户创建订阅3 - 在前端收集卡片 number/cvc/expire 日期:
const cardElement = elements.getElement(CardElement);
4 - 从前端调用条带:
const { error, paymentIntent } = await stripe.confirmCardPayment(clientSecret, {
payment_method: {
card: cardElement,
billing_details: {
name: name,
}
}
});
我不确定这是否是最佳流程。但是,它正在工作。 我还管理更新订阅和取消订阅。 但是,我很难更改信用卡详细信息。 我从文档中了解到,我应该使用与创建卡支付时相同的调用。 所以我再次收集信用卡号并再次调用相同的函数:
const { error, paymentIntent } = await stripe.confirmCardPayment(clientSecret, {
payment_method: {
card: cardElement,
billing_details: {
name: name,
}
}
});
然而,调用完成于:
https://api.stripe.com/v1/payment_intents/pi_XXXX/confirm
和 returns 400 具有以下信息:
type: "invalid_request_error", code: "payment_intent_unexpected_state", doc_url: "https://stripe.com/docs/error-codes/payment-intent-unexpected-state"
我应该使用其他工具来更新信用卡信息吗?还是我叫错了?
您最初调用 confirmCardPayment()
的流程是正确的,这也是 Stripe 文档中推荐的流程:https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=elements.
hard time in changing credit card details. What I understood from docs I should use the same call as I did when I create the card payment.
要仅收集卡详细信息并创建 PaymentMethod,您应该从 Stripe.js 调用 createPaymentMethod()
[0]。这会将客户的卡转换为类似 pm_123.
然后您将该 PaymentMethod 发送到您的后端服务器,在那里(使用您的服务器端 Stripe API 库,如 stripe-node)您将其附加到 Stripe 客户 [1] 并更新作为客户用于定期付款的默认付款方式 [2]。
[0] https://stripe.com/docs/js/payment_methods/create_payment_method
[1] https://stripe.com/docs/api/payment_methods/attach
[2]https://stripe.com/docs/api/customers/update#update_customer-invoice_settings-default_payment_method