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

调用stripe.tokens.create无返回无报错,无法生成token问题求助

排查步骤
  • 确认异步函数调用方式正确
    createToken是异步函数,直接调用不会等待执行完成,进程可能在内部逻辑跑完前就退出了。请确保调用时添加await关键字,或者通过.then()/.catch()处理返回的Promise:
    // 正确调用示例1 异步上下文内
    const token = await createToken()
    // 正确调用示例2 非异步上下文内
    createToken().then(token => console.log('拿到token', token)).catch(err => console.error('报错', err))
    
  • 验证Stripe密钥是否正常加载
    在初始化stripe实例前添加日志确认密钥是否正确读取:
    const secretKey = STRIPE_SK 
    console.log('加载的Stripe密钥:', secretKey) // 确认输出不是undefined/空值
    const stripe = require('stripe')(secretKey);
    
  • 排查网络连通性问题
    Stripe API服务器位于境外,本地网络可能无法正常访问。你可以在终端直接执行curl命令测试连通性:
    curl https://api.stripe.com/v1/tokens -u 你的Stripe密钥:
    
    如果请求超时,需要给Stripe SDK配置代理:
    // 先安装依赖 npm install https-proxy-agent
    const HttpsProxyAgent = require('https-proxy-agent');
    const stripe = require('stripe')(secretKey, {
      httpAgent: new HttpsProxyAgent('http://你的代理地址:端口')
    });
    
  • 添加全局Promise异常捕获
    未被处理的Promise拒绝默认不会在控制台打印错误,可以在代码顶部添加全局监听排查隐藏错误:
    process.on('unhandledRejection', (err) => {
      console.error('捕获到未处理的Promise错误:', err)
    })
    
  • 测试更新卡信息有效期
    你当前填写的卡有效期到2022年,已经过期,建议更新为未来年份测试:
    exp_year: 2030,
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.24 08:06:00