You need to enable JavaScript to run this app. 使用Stripe创建Payment Intent时触发类型错误求助
优惠活动
大模型
产品
解决方案
定价
更多

使用Stripe创建Payment Intent时触发类型错误求助

解决Stripe Payment Intent创建时的TypeError问题

你遇到的Cannot read properties of undefined (reading 'create')错误,核心原因是调用了错误的Stripe SDK方法名——Stripe Node.js SDK中创建支付意向的方法是复数形式的paymentIntents.create(),而非你代码里写的单数paymentIntent.create()。

修正步骤:

  • 先确认Stripe实例已正确初始化:
    // CommonJS 写法
    const stripe = require('stripe')('你的Stripe秘钥');
    
    // ES 模块写法
    import Stripe from 'stripe';
    const stripe = new Stripe('你的Stripe秘钥');
    
  • 修改创建Payment Intent的代码,把单数的paymentIntent改成复数paymentIntents:
    const paymentIntent = await stripe.paymentIntents.create({
      amount: 1000, // 金额单位为分,示例为10美元
      currency: 'usd',
      // 按需添加其他参数,比如payment_method_types等
    });
    
  • 若仍有问题,检查Stripe SDK版本,旧版本可能存在方法差异,执行npm update stripe更新到最新版。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 05:34:54