1

我目前正在将我的应用从使用 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对具有状态和客户端密码的对象的访问权限,所以我必须检查和使用这些吗?

任何指向带有示例的相关文档的链接都会非常有帮助。

4

1 回答 1

1

唯一需要 SCA 的时间是您尝试付款时。在您收集了客户的付款详细信息(并可选择将其保存为新客户)后,您要求 Stripe 完成付款。然后 Stripe 将联系客户的银行,询问是否可以付款或是否需要额外的身份验证。

如果银行说不需要额外的,支付成功,一切都很好。

如果银行说需要 3DS 支票,那么您需要让您的客户通过 3DS 流程,这本质上是一个 2FA 步骤,以确保请求付款的人也是持卡人。

如果您的客户仍处于“会话状态”(例如仍在您的站点上),您将新创建的 PaymentIntent 的客户端密码传递给您的前端并使用 Stripe.js 完成 2FA 步骤并验证付款。

如果您的客户处于“会话外”状态(例如,这是一个定期订阅并且他们不在您的网站上),那么您将必须给您的客户发送电子邮件,让他们回到您的网站以执行 3DS 步骤(或者您可以使用 Stripe 的托管发票页面)。

在您的情况下,当您创建订阅时(假设您没有使用试用期),Stripe 将创建一个附有自动创建的 PaymentIntent 的发票。您可以通过Subscriptionlatest_invoice上的参数访问此发票。如果需要 3DS 步骤,PaymentIntent 将具有状态,这意味着您需要让您的客户回到“会话中”以完成付款。requires_action

使用托管发票页面,在这种情况下,Stripe 会自动向您的用户发送电子邮件,以便他们完成付款。如果没有托管发票页面,您将不得不构建自己的实现来让您的用户回到“会话中”。

创建 Customer 或 PaymentMethod 时,您不需要执行 3DS,只有当您实际尝试将资金从一个地方转移到另一个地方时。

于 2019-09-09T06:35:18.960 回答