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

Java创建Stripe多商品结账会话后访问URL报错,单商品可正常使用

Stripe多商品订阅结账会话报错排查解决步骤

1 先修正代码显性错误

你提供的代码存在两处直接导致参数异常的问题:

  • 变量名引用错误:第一个商品参数Map定义为paramsPriceIdList1,第二个定义为paramsPriceIdList2,但赋值时均写错为paramsPriceIdList
  • 方法名错误:Java HashMap的赋值方法为put,不是不存在的put2,错误的方法名会导致line_items的参数不符合Stripe接口要求

2 校验两个Price ID的属性匹配规则

你使用的是subscription订阅模式的结账会话,多商品订阅要求所有关联的Price必须满足以下要求:

  • 所有Price均为recurring订阅类型,不可混用one_time一次性价格
  • 所有Price的计价货币完全一致
  • 所有Price的订阅周期规则匹配:默认不支持混合不同结算周期(如周付/年付)的商品放入同一个订阅会话,若需要该能力需提前在Stripe后台开启多计划订阅配置

3 后台日志排查具体错误

登录Stripe管理后台,进入「开发者」-「日志」页面,找到对应Session.create接口的请求记录,Stripe会返回明确的参数错误原因,可快速定位是参数格式问题还是商品属性冲突问题

修正后的参考代码

// 第一个商品参数
Map<String, Object> paramsPriceIdList1 = new HashMap<>();
paramsPriceIdList1.put("price", price_id1);
paramsPriceIdList1.put("quantity", 2);

// 第二个商品参数
Map<String, Object> paramsPriceIdList2 = new HashMap<>();
paramsPriceIdList2.put("price", price_id2);
paramsPriceIdList2.put("quantity", 2);

List<Object> lineItems = new ArrayList<>();
lineItems.add(paramsPriceIdList1);
lineItems.add(paramsPriceIdList2);

Map<String, Object> params = new HashMap<>();
params.put("success_url", "https://example.com/success");
params.put("cancel_url", "https://example.com/cancel");
params.put("line_items", lineItems);
params.put("mode", "subscription");

Session session = Session.create(params);
System.out.println(session.getUrl());

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.25 01:54:04