roy*_*rma 5 android node.js stripe-payments
我正在尝试为我的产品实现一个非常简单的流程:
客户将卡添加到他的帐户
客户提出请求 -> 为请求价格在他的卡上创建一个保留
根据请求交付 -> 执行卡上的初始保留
在阅读有关 Stripe 的新 Intent API 的大量文档后,这看起来非常简单。
A. 创建一个 Stripe 客户
stripe.customers.create({ email: user.email, description:${user.email} 的客户});
B. 给客户贴一张卡(支付方式),setup intent用这张卡创建一个授权未来的费用
stripe.setupIntents.create({ 'customer': customer_id, 'payment_method': paymentMethodId });
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'
});
Run Code Online (Sandbox Code Playgroud)
D. 根据要求交付,只需在步骤 C 中创建capture的原始文件paymentIntent。
const captureHoldIntent = await stripe.paymentIntents.capture(paymentIntentId);
我实际遇到的问题发生在步骤 C 和 D 之间:
无法为 user_id KAJSD92 错误保存交易错误:无法捕获此 PaymentIntent,因为它的状态为 requires_confirmation。只能捕获具有以下状态之一的 PaymentIntent:requires_capture。
虽然我理解此错误消息,但我的困惑是为什么paymentIntent步骤 C 中的created 不会更改为requires_capture状态,而是 always require_confirmation,即使它已经被确认?
缺失的部分是调用paymentIntents.confirm以“确认”该服务实际上想要保留该卡。之后,意图状态更改为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'
});
Run Code Online (Sandbox Code Playgroud)
const confirmPaymentIntent = await stripe.paymentIntents.confirm(intentId);
const captureHoldIntent = await stripe.paymentIntents.capture(intentId);
| 归档时间: |
|
| 查看次数: |
3201 次 |
| 最近记录: |