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

Next.js电商项目中Stripe listLineItems函数调用报错解决

解决Stripe listLineItems调用报错:TypeError: Cannot read properties of undefined (reading 'listLineItems')

这个报错的核心原因是Stripe API函数的调用路径拼写错误,你之前直接尝试调用的listLineItems并非顶层方法,因此会触发"读取undefined的属性"错误,同时也会因为找错层级导致在官方文档中找不到对应函数。

正确的调用路径是嵌套在checkout.sessions下的方法,正确写法示例:

// 初始化Stripe客户端
const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY);

// 获取订单明细的正确写法
async function fetchOrderLineItems(sessionId) {
  try {
    const lineItems = await stripe.checkout.sessions.listLineItems(sessionId);
    return lineItems.data;
  } catch (error) {
    console.error('获取订单项失败:', error);
    throw error;
  }
}

你之前找不到文档是因为找错了层级,这个方法属于Stripe Checkout Sessions的子方法,需要在Checkout相关的文档板块下查找。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.12 18:40:39