为了遵守 SCA 规定,我目前正在将我的应用从使用 Stripe Charges API 迁移到使用 Stripe PaymentIntents API。
我的订阅创建代码大致如下所示:
Map<String, Object> srchOpts = new HashMap<>();
srchOpts.put("email", userEmail);
List<Customer> matchingCustomers = Customer.list(srchOpts).getData();
Customer customer = null;
Subscription subscription = null;
if ( matchingCustomers.isEmpty() ){
Map<String, Object> params = new HashMap<String, Object>();
params.put("email", userEmail);
params.put("payment_token", stripeToken);
customer = Customer.create(params);
}
else if (matchingCustomers.size() == 1) {
customer = matchingCustomers.get(0);
Map<String, Object> params = new HashMap<String, Object>();
params.put("source", stripeToken);
PaymentSourceCollection paymentSources = customer.getSources();
paymentSources.create(params);
}
Map<String, Object> item = new HashMap<String, Object>();
item.put("plan", planId); // e.g. my-pro-plan (no trial days)
Map<String, Object> items = new HashMap<String, Object>();
items.put("0", item);
Map<String, Object> params = new HashMap<String, Object>();
params.put("items", items);
params.put("customer", customer.getId());
params.put("off_session", false);
subscription = Subscription.create(params);
我可以在 Stripe 控制面板(在测试模式下(上看到客户已创建并拥有我指定的卡,但 Subscription.create 调用失败,并显示:
com.stripe.exception.InvalidRequestException:此客户没有附加的付款来源;代码:resource_missing
客户有一个卡集(只有 1 个,因此它必须是默认卡(,客户创建调用发生在订阅创建调用之前,并且客户 ID 正在传递给子创建调用。我是否需要传入其他参数?
我尝试在创建客户时设置Customer.invoice_settings.default_payment_method
,这使我通过了订阅创建。从 Stripe 控制面板来看,一切看起来都很好,除了我正在使用 SCA 测试卡进行测试,因此在客户进一步进行身份验证之前,交易是不完整的。
我需要响应中的客户端密钥令牌才能继续,我以为我会从#Subscription.getLatestInvoiceObject().getPaymentIntentObject().getClientSecret()
那里得到它,但getLatestInvoiceObject()
调用返回null
。
我没有在默认为charge_automatically
的订阅对象上设置collection_method
。这就是我想要的,因为客户正在会话中,因此null
Invoice
可能是有意义的,但是如何获取客户端密钥以传递回前端?订阅响应返回的SetupIntent
对象公开客户端密码,但该对象也null
。
订阅Invoices
将使用以下三种付款方式中的任何一种(按优先顺序(:
Subscription
的default_payment_method
(参考(或default_source
(参考(Customer
的invoice_settings.default_payment_method
(参考资料(Customer
的default_source
(注意:客户没有默认付款方式的概念(
另外值得注意的是,付款方式和来源是两种不同的资源。卡片(ID前缀为card_
的对象(可以用作任一类型。