英文:
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<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
}
Anyone else run into this?
答案1
得分: 1
stripe-java被固定到特定的API版本。当您在库中升级到新的主版本时,通常会包含重大更改和/或升级到最近的API版本。这就是在20.0.0版本中所发生的,正如此处所记录的,该库被固定为2020-08-27。
那个新的API版本有很多变化,包括对Customer
资源进行了一些清理。Stripe停止默认返回子列表:只有在您直接展开这些子列表时,才会返回subscription
,tax_ids
和sources
。这在大多数情况下可以使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<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);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论