【发布时间】: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