使用Stripe Node SDK调用Accounts v2创建收款账户报错求助
问题描述
我正在使用Stripe Node SDK,尝试通过Accounts v2创建收款账户。已执行以下命令安装Stripe包:
npm install stripe
编写的代码如下:
import Stripe from "stripe"; const stripe = new Stripe('sk_test_51RMH4BFQg8'); const account = await stripe.v2.core.accounts.create({ display_name: 'Tester', contact_email: 'contact@example.com', identity: { country: 'us', entity_type: 'individual', }, configuration: { recipient: { }, }, });
运行代码时出现错误:
TypeError: Cannot read properties of undefined (reading 'create')
IDE自动补全仅能找到stripe.v2.core,无法识别后续的.accounts对象及.accounts.create()方法。虽然存在stripe.accounts.create()方法,但它不兼容我传入的V2格式参数。请问哪里操作出错了?
解决方法
安装对应预览版SDK:Accounts v2是预览版API,稳定版Stripe SDK不包含该接口。需要安装支持预览版的SDK版本,执行命令:
npm install stripe@beta显式指定预览版API版本:初始化Stripe客户端时,必须指定对应预览版的API版本,否则会使用默认稳定版,导致无法识别v2接口。修改初始化代码:
import Stripe from "stripe"; const stripe = new Stripe('sk_test_51RMH4BFQg8', { apiVersion: '2025-04-30.preview', });修正接口调用路径:Stripe v2账户接口的正确路径是
stripe.v2.accounts.create(),而非你代码中的stripe.v2.core.accounts.create()。修正后的调用代码:const account = await stripe.v2.accounts.create({ display_name: 'Tester', contact_email: 'contact@example.com', identity: { country: 'us', entity_type: 'individual', }, configuration: { recipient: { }, }, });
内容的提问来源于stack exchange,提问作者volume one
相关产品推荐
相关产品推荐

