当我尝试使用 java sdk 创建 Stripe Customer 时,它抛出 "Invalid Object"

When I try to create a Stripe Customer using java sdk, it is throwing "Invalid Object"

我正在尝试创建一个带地址的 Stripe 客户,但我无法这样做,因为它最终会抛出无效对象错误。如果我删除地址,我就可以创建客户。但我的要求是创建具有 his/her 地址的客户。

这是我要执行的代码。

Address address = new Address();
address.setPostalCode("250532");
address.setState("Maharashtra");
address.setLine2("20/2, Ganesh Street");
address.setCity("Mumbai");
address.setCountry("IN");

Map<String, Object> customerParams = new HashMap<>();

customerParams.put("email", "test@gmail.com");
customerParams.put("name", "Radhey");
customerParams.put("description", "Test Customer");
customerParams.put("address", address);
customerParams.put("source", token);
Customer customer = Customer.create(customerParams);

在代码的最后一行抛出无效对象错误。

下面给出的是堆栈跟踪:

com.stripe.exception.InvalidRequestException: Invalid object
    at com.stripe.net.LiveStripeResponseGetter.handleAPIError(LiveStripeResponseGetter.java:645)
    at com.stripe.net.LiveStripeResponseGetter._request(LiveStripeResponseGetter.java:490)
    at com.stripe.net.LiveStripeResponseGetter.request(LiveStripeResponseGetter.java:73)
    at com.stripe.net.APIResource.request(APIResource.java:161)
    at com.stripe.model.Customer.create(Customer.java:380)
    at com.stripe.model.Customer.create(Customer.java:265)
    at stripe.Test.chargeCreditCard(Test.java:51)
    at stripe.Test.main(Test.java:19)

评论区@RyanM 的解决方案对我有用。

Have you considered attempting to use the new builder syntax that is in the current Stripe docs? It matches with the current Java doc which includes the specifications when providing an Address while creating a Customer https://stripe.dev/stripe-java/com/stripe/param/CustomerCreateParams.Address.html