You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用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无法在实时模式中使用
  • 逻辑修正:实时模式下,需先通过实时密钥创建对应的PaymentIntent,再使用用户提供的真实支付方式ID进行确认,不能直接复用测试环境的固定ID

内容的提问来源于stack exchange,提问作者Ali Coder

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 03:25:21