【问题标题】:Stripe PaymentSource not expanding after upgrading to newest version of Java library升级到最新版本的 Java 库后,Stripe PaymentSource 未扩展
【发布时间】:2021-02-01 02:23:07
【问题描述】:

我正在尝试获取附加到给定客户的付款方式。我最近升级到了Stripe Java library 的2020.19.0 版本,我正在关注他们提出的the example

问题在于 Java 库似乎无法识别 PaymentSource 对象有任何参数:

Map<String, Object> params = Maps.newHashMap();
params.put("object", "card");
params.put("limit", 100);

// Get the credit cards
List<PaymentSource> cards =
  customer.getSources().list(params).getData();

for (PaymentSource c : cards) {
  c.getObject();    // not recognized in IDE
}

还有其他人遇到这种情况吗?

【问题讨论】:

    标签: java gradle stripe-payments


    【解决方案1】:

    stripe-java 被固定到一个特定的 API 版本。当您升级到库中的新主要版本时,它通常包含重大更改和/或升级到最新 API 版本。这就是 20.0.0 中发生的情况,如文件中的 here 所述,其中库被固定到 2020-08-27

    新的 API 版本有很多变化,包括对 Customer 资源的一些清理。默认情况下,Stripe 停止返回子列表:subscriptiontax_idssources 不会返回,除非您直接显式展开这些子列表。这允许 API 在大多数情况下更快,并在代码的特定部分有选择地选择您需要的子列表。

    在 Java 中,这意味着如果您希望能够创建/附加新卡,则需要扩展 sources 集合。这也记录在 API 参考 here 中,代码如下所示:

    List<String> expandList = new ArrayList<>();
    expandList.add("sources");
    
    Map<String, Object> retrieveParams = new HashMap<>();
    retrieveParams.put("expand", expandList);
    
    Customer customer = Customer.retrieve(
      "cus_IEB3RFCf76Fais",
      retrieveParams,
      null
    );
    
    Map<String, Object> params = new HashMap<>();
    params.put("object", "card");
    params.put("limit", 3);
    
    PaymentSourceCollection cards = customer.getSources().list(params);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-21
      • 2022-01-05
      • 2019-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多