[英]Stripe Intent API Hold Card and then Charge Not Working
I'm trying to implement a pretty straightforward flow for my product:我正在尝试为我的产品实现一个非常简单的流程:
Customer adds card to his account客户将卡添加到他的帐户
Customer makes a request -> Create a hold on his card for the request price客户提出请求 -> 以请求价格在他的卡上创建保留
On request delivered -> Execute the initial hold made on the card根据要求交付 -> 执行卡上的初始保留
Upon reading through loads of docs on Stripe's new Intent API, this seemed pretty simple.在阅读有关 Stripe 的新 Intent API 的大量文档后,这看起来非常简单。
A. Create a Stripe customer A. 创建一个 Stripe 客户
stripe.customers.create({ email: user.email, description:
Customer for ${user.email} });
stripe.customers.create({ email: user.email, description:
${user.email} 的客户});
B. Attach a card (payment method) to the customer, create a setup intent
with this card to authorize future charges B. 给客户附上一张卡(支付方式),用这张卡创建一个setup intent
来授权未来的收费
stripe.setupIntents.create({ 'customer': customer_id, 'payment_method': paymentMethodId });
C. On a request made by the customer, create paymentIntent with capture_method
set to manual
C. 根据客户的要求,创建 paymentIntent 并将capture_method
设置为manual
const paymentIntent = await stripe.paymentIntents.create({
'amount': price * 100, //convert shekels to agorot
'currency': 'ILS',
'customer': customer_id,
'payment_method': payment_method,
'payment_method_types': ['card'],
'capture_method': 'manual'
});
D. On request delivered, simply capture
the original paymentIntent
created in step C. D. 根据请求交付,只需capture
在步骤 C 中创建的原始paymentIntent
。
const captureHoldIntent = await stripe.paymentIntents.capture(paymentIntentId);
The issue I'm getting actually is occurring between steps C and D:我遇到的问题实际上发生在步骤 C 和 D 之间:
Failed to save transaction for user_id KAJSD92 error Error: This PaymentIntent could not be captured because it has a status of requires_confirmation. Failed to save transaction for user_id KAJSD92 error 错误:无法捕获此 PaymentIntent,因为它的状态为 requires_confirmation。 Only a PaymentIntent with one of the following statuses may be captured: requires_capture.只能捕获具有以下状态之一的 PaymentIntent:requires_capture。
While I understand this error message, my confusion is as to why the paymentIntent
created in step C doesn't change to the requires_capture
status and is instead always require_confirmation
, even though it has already been confirmed?虽然我理解此错误消息,但我的困惑是为什么在步骤paymentIntent
中创建的 paymentIntent 不会更改为requires_capture
状态,而是始终是require_confirmation
,即使它已经被确认?
The missing piece was calling paymentIntents.confirm
to "confirm" that the service actually wants to place a hold on the card.缺少的部分是调用paymentIntents.confirm
以“确认”该服务实际上想要暂停卡。 After that, the intents status was changed to requires_capture
which allowed me to call the capture
method.之后,意图状态更改为requires_capture
,这允许我调用capture
方法。
const paymentIntent = await stripe.paymentIntents.create({
'amount': price * 100, //convert shekels to agorot
'currency': 'ILS',
'customer': customer_id,
'payment_method': payment_method,
'payment_method_types': ['card'],
'capture_method': 'manual'
});
const confirmPaymentIntent = await stripe.paymentIntents.confirm(intentId);
const captureHoldIntent = await stripe.paymentIntents.capture(intentId);
need to add ' confirm:true ' while creating the paymentIntents在创建 paymentIntents 时需要添加 ' confirm:true '
const payment = await stripe.paymentIntents.create({
amount,
currency: "USD",
description: "Delicious empanadas",
payment_method: id,
confirm:true,
payment_method_types: ['card'],
capture_method: 'manual',
});
then do capture然后做捕获
const intent = await stripe.paymentIntents.capture(stripe_payment_intent_id, {
amount_to_capture: AMOUNT_XXX,
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.