使用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
相关产品推荐
相关产品推荐

