Stripe PaymentSource在升级到最新版本的Java库后未展开。

huangapple go评论74阅读模式
英文:

Stripe PaymentSource not expanding after upgrading to newest version of Java library

问题

我正在尝试获取与特定客户关联的付款方式。我最近升级到了Stripe Java库的2020.19.0版本,并且我正在遵循他们提供的示例

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

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

// 获取信用卡
List<PaymentSource> cards = customer.getSources().list(params).getData();

for (PaymentSource c : cards) {
  c.getObject();    // 在IDE中无法识别
}

有其他人遇到过类似问题吗?

英文:

I'm trying to get the payment methods attached to a given Customer. I recently upgraded to version 2020.19.0 of the Stripe Java library and I'm following the example they've put forward.

The problem is that the Java library doesn't seem to recognize that the PaymentSource object has any parameters:

Map&lt;String, Object&gt; params = Maps.newHashMap();
params.put(&quot;object&quot;, &quot;card&quot;);
params.put(&quot;limit&quot;, 100);

// Get the credit cards
List&lt;PaymentSource&gt; cards =
  customer.getSources().list(params).getData();

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

Anyone else run into this?

答案1

得分: 1

stripe-java被固定到特定的API版本。当您在库中升级到新的主版本时,通常会包含重大更改和/或升级到最近的API版本。这就是在20.0.0版本中所发生的,正如此处所记录的,该库被固定为2020-08-27

那个新的API版本有很多变化,包括对Customer资源进行了一些清理。Stripe停止默认返回子列表:只有在您直接展开这些子列表时,才会返回subscriptiontax_idssources。这在大多数情况下可以使API更快,并且可以在代码的特定部分有选择地选择您需要的子列表。

在Java中,这意味着如果您想能够创建/附加新卡,您需要展开sources集合。这也在API参考文档中有记录,在这里,代码如下所示:

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);
英文:

stripe-java is pinned to a specific API version. When you upgrade to a new major version in the library it usually contains breaking changes and/or an upgrade to the most recent API version. This is what happened in 20.0.0 as documented here where the library was pinned to 2020-08-27.

That new API version has a lot of changes including some cleanup on the Customer resource. Stripe stopped returning sub-lists by default: subscription, tax_ids and sources are not returned unless you explicitly expand those sub-lists directly. This allows the API to be faster in most cases and to selectively select the sub-lists you need in specific parts of your code.

In Java, this means that you need to expand the sources collection if you want to be able to create/attach a new card. This is also documented in the API reference here and the code looks like this:

List&lt;String&gt; expandList = new ArrayList&lt;&gt;();
expandList.add(&quot;sources&quot;);

Map&lt;String, Object&gt; retrieveParams = new HashMap&lt;&gt;();
retrieveParams.put(&quot;expand&quot;, expandList);

Customer customer = Customer.retrieve(
  &quot;cus_IEB3RFCf76Fais&quot;,
  retrieveParams,
  null
);

Map&lt;String, Object&gt; params = new HashMap&lt;&gt;();
params.put(&quot;object&quot;, &quot;card&quot;);
params.put(&quot;limit&quot;, 3);

PaymentSourceCollection cards = customer.getSources().list(params);

huangapple
  • 本文由 发表于 2020年10月18日 07:06:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/64408192.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定