当我尝试使用 java sdk 创建 Stripe Customer 时,它抛出“无效对象”

发布于 2025-01-16 21:00:57 字数 1464 浏览 2 评论 0原文

我正在尝试创建一个带有地址的 Stripe Customer,但我无法这样做,因为它最终会引发无效对象错误。如果我删除该地址,我就可以创建客户。但我的要求是用他/她的地址创建客户。

这是我试图执行的代码。

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", "[email protected]");
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)

I am trying to create a Stripe Customer with address and I not able to do so because it ends up throwing invalid object error. If I remove the address I am able to create the customer. But my requirement is to create the customer with his/her address.

This is the code that I am trying to execute.

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", "[email protected]");
customerParams.put("name", "Radhey");
customerParams.put("description", "Test Customer");
customerParams.put("address", address);
customerParams.put("source", token);
Customer customer = Customer.create(customerParams);

It is throwing invalid object error on the last line of the code.

Below given is the stacktrace:

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

混浊又暗下来 2025-01-23 21:00:57

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

您是否考虑过尝试使用新的构建器语法
在当前的 Stripe 文档中?它与当前的 Java 文档匹配
包括创建地址时提供地址时的规范
顾客
https://stripe.dev/stripe-java/com/ stripe/param/CustomerCreateParams.Address.html

The solution by @RyanM in the comment section worked for me.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文