我目前正在将我的应用从使用 Stripe Charges API 迁移到使用 Stripe PaymentIntents API,以符合 SCA 法规。我的应用程序是具有定期计费模型的订阅服务,因此我通常一直在关注迁移文档的“健身房会员”示例,以及查看其他相关文档和参考资料。
我在前端使用 Stripe Elements 在自定义表单上捕获付款详细信息等,然后使用 Stripe 付款令牌发送到我的后端以进行进一步处理(同步)。前端更新很简单,我在那里没有问题,但我对后端更新有点困惑。
我可以在文档中找到的所有代码示例(通常都很棒)展示了如何将Charge
调用转换为PaymentIntent
调用,例如这个旧的 Charge 调用:
Map<String, Object> chargeParams = new HashMap<String, Object>();
chargeParams.put("amount", 1099);
chargeParams.put("currency", "eur");
chargeParams.put("source", request.token_id);
Charge.create(chargeParams);
...使用 PaymentIntents API 变成这样:
Map<String, Object> createPaymentIntentParams = new HashMap<String, Object>();
createPaymentIntentParams.put("currency", "eur");
createPaymentIntentParams.put("amount", 1099);
createPaymentIntentParams.put("confirm", true);
createPaymentIntentParams.put("confirmation_method", "manual");
createPaymentIntentParams.put("payment_method", request.paymentMethodId);
intent = PaymentIntent.create(createPaymentIntentParams);
因此,如果客户需要额外的授权(如PaymentIntent
状态所示),请求将被退回给客户,Stripe SDK 将处理额外的安全措施。
但是我的应用程序没有Charge
以这种方式使用调用。它通常看起来像这样:
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("source", stripeToken);
customer = Customer.create(params); // potential SCA rejection ??
}
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); // potential SCA rejection ??
}
Map<String, Object> item = new HashMap<String, Object>();
item.put("plan", planId);
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());
subscription = Subscription.create(params); // potential SCA rejection ??
新Customer
创建、新PaymentSource
创建和新Subscription
创建调用是否会受到 SCA 拒绝,此时我必须返回给客户进行进一步身份验证?
如果是这样,我如何检查 Customer 和 PaymentSource 调用是否需要这样做,以及如何获取所需的客户端秘密令牌以发送回前端?Subscription 对象确实提供了SetupIntent
对具有状态和客户端密码的对象的访问权限,所以我必须检查和使用这些吗?
任何指向带有示例的相关文档的链接都会非常有帮助。