【问题标题】:Setting a Stripe Subscription with a Customer without a Default PaymentMethod in Java在 Java 中为没有默认 PaymentMethod 的客户设置 Stripe 订阅
【发布时间】:2020-02-03 17:27:35
【问题描述】:

这个问题是关于如何为订阅收集 PaymentMethod 的误解,符合新的 SCA 要求。关键是要仔细阅读如何Sep up a Subscription,这与单笔付款略有不同。

我正在将 Stripe 实现迁移到版本 16.4.0,用于使用 Spring-boot 框架使用 Java 开发的应用程序,以支持强客户身份验证 (SCA) 要求。

问题是我无法创建订阅,因为客户没有任何付款方式

这是我的订阅工作流程:

我创建了一个客户:

   Map<String, Object> params = new HashMap<>();
   params.put("name", customerName);
   params.put("email", user.getUsername());
   params.put("description", "idweb: " + user.getIdweb() + " " + customerName);
   Customer customer = Customer.create(params);
   customerId = customer.getId();

接下来,我为该客户创建订阅:

   Map<String, Object> firstItem = new HashMap<>();
   firstItem.put("plan", baseFee);
   firstItem.put("quantity", 1);

   Map<String, Object> secondItem = new HashMap<>();
   secondItem.put("plan", perUnitFee);
   secondItem.put("quantity", propertiesBase);

   Map<String, Object> items = new HashMap<>();
   items.put("0", firstItem);
   items.put("1", secondItem);

   Map<String, Object> metadata = new HashMap<>();
   metadata.put("properties", properties);
   metadata.put("RwRate", stripePlans.getRwRate());

   Map<String, Object> subscriptionParams = new HashMap<>();
   subscriptionParams.put("customer", customerId);
   subscriptionParams.put("collection_method", "charge_automatically");
   subscriptionParams.put("items", items);
   subscriptionParams.put("metadata", metadata);

   Subscription subscription = Subscription.create(subscriptionParams);

这里系统引发了这个错误:

com.stripe.exception.InvalidRequestException: This customer has no attached payment source or default payment method.

我从文档中了解到...使用 2019-03-14 或之后的 API 版本,系统将订阅设置为状态未完成,如果付款意图失败,以便我们可以在前端收集付款方式。

如果我可以创建订阅,我会获取它的最新发票,我会从中获取它的付款意图,以将 Client Secret 传递到前端。

    Invoice invoice = Invoice.retrieve(subscription.getLatestInvoice());
    PaymentIntent paymentIntent = PaymentIntent.retrieve(invoice.getPaymentIntent());
    model.addAttribute("clientSecret", paymentIntent.getClientSecret());

从此时起,我应该能够将收取的付款方式分配给客人并保持订阅处于活动状态,以进行下一次付款,因为它一直工作到现在没有 SCA 要求。

我可能遗漏了什么,或者我的方法可能是错误的,无论如何,任何建议都会受到欢迎。我已经了解了不同的方法,设置试用期或设置 SetupIntent。但我的理想方案是在领取客户卡并准备好订阅时收取第一个配额,以便自动收取下一个配额。

【问题讨论】:

    标签: stripe-payments


    【解决方案1】:

    如果您使用 Sources,则需要设置客户的 default_source

    如果您改用较新的 PaymentMethods API(除非您有充分的理由不这样做,否则您应该使用该 API),您需要改为设置客户的 invoice_settings.default_payment_method

    the Stripe docs 中有详细信息,了解更多信息。

    【讨论】:

    • 我正在转向 PaymentMethods API,我在前端收集了 PaymentMethod 后设置订阅的问题(JS:stripe.confirmCardPayment(clientSecret,...),是订阅创建第一张发票和第二笔费用。我读过,试用期可以解决,但我想知道是否可以在前端收集 PaymentMethod 之前设置订阅并使其不完整。
    • 如果您已经有了 PaymentMethod,您可以在创建订阅时将其作为订阅的default_payment_method 作为另一个选项传递。
    • 我错过了一些东西。当客户输入卡详细信息时,我想收取其订阅的第一个配额,与 SCA 打交道,同时确认订阅,而不会为第一张发票收取第二笔费用。对于我阅读的内容,我知道这是可能的,无需设置试用期(防止双重收费),但也许不是。
    • 这个问题是关于如何根据新的 SCA 要求收集订阅的 PaymentMethod 的误解。关键是仔细阅读如何 [Sep up a Subscription][1],这与单次付款略有不同。
    猜你喜欢
    • 2018-09-26
    • 2022-01-20
    • 1970-01-01
    • 2023-02-04
    • 1970-01-01
    • 2016-08-16
    • 1970-01-01
    • 1970-01-01
    • 2015-02-14
    相关资源
    最近更新 更多