使用Stripe进行实时支付时出现错误,请求技术支持
Stripe实时模式支付报错解决方法
我使用Stripe作为支付网关实现支付功能,测试模式下代码运行正常,但切换至实时支付模式时无法正常工作并报错。
我的代码:
const stripe = require('stripe')('sk_test_your_key'); // To create a PaymentIntent for confirmation, see our guide at: https://stripe.com/docs/payments/payment-intents/creating-payment-intents#creating-for-automatic const paymentIntent = await stripe.paymentIntents.confirm( 'pi_test_id', {payment_method: 'pm_card_visa'} );
收到的错误信息:
Error: You cannot use the test ID 'pm_card_visa' in livemode. If you are testing your integration, please use your testmode API keys instead.
解决方法:
- 替换API密钥:将代码中的测试密钥
sk_test_your_key替换为Stripe后台获取的实时模式密钥(以sk_live_开头) - 替换测试资源ID:
- 不能继续使用测试支付方式ID
pm_card_visa,实时模式下必须使用用户通过前端Stripe Elements组件提交后返回的真实支付方式ID(格式为pm_开头) - 同时
pi_test_id也要替换为实时模式下创建的PaymentIntent ID,测试环境的ID无法在实时模式中使用
- 不能继续使用测试支付方式ID
- 逻辑修正:实时模式下,需先通过实时密钥创建对应的PaymentIntent,再使用用户提供的真实支付方式ID进行确认,不能直接复用测试环境的固定ID
内容的提问来源于stack exchange,提问作者Ali Coder
相关产品推荐
相关产品推荐

