【发布时间】:2019-12-30 15:05:46
【问题描述】:
我有与 Stripe 集成的 spring boot/angular 应用程序。
我们正在尝试将 3d 安全授权包含在我们现有的系统中。具有即时自动和手动确认的基本流程很容易实现,而且它很有吸引力,但是......
我们有一个特定的案例,我们有多项服务,其中一些是即时收费(捕获)的,其中一些需要供应商确认, 并在此确认后捕获。在我们当前的实现中,我们正在创建单独的费用 对于每个异步服务(需要确认的服务),如果确认成功,我们会捕获 Charge。所以我们有一个用户操作,但有多个捕获。
现在我们正在尝试对 PaymentIntent 做同样的事情,但看起来 PaymentIntent 只能有一个 Charge 并且无法部分确认。此外,如果我们创建多个 PaymentIntent,即使使用相同的 paymentMethodId, 看起来我们需要为每个单独的用户操作。
有没有什么方法可以支持多个收费或多个 PaymentIntents,只需 1 个用户操作,以避免每次异步捕获的 3d 安全验证?
更新 No1: 我设法使用 SetupIntent 实现了这一点,但仅适用于允许您进行一次性验证并且您以后可以将其用于其他付款的卡:
@PostMapping("/createSetup")
public String createPaymentSetup(HttpServletRequest request) throws Exception {
Map<String, Object> params = new HashMap<>();
SetupIntent setupIntent = SetupIntent.create(params);
return setupIntent.getClientSecret();
}
此客户端密码将在前面用于调用 3d 验证(仍然没有任何实际付款):
this.stripe.handleCardSetup(
this.clientSecret, this.cardElement, {
payment_method_data: {
billing_details: {name: this.cardholderName.value}
}
}
).then((result) => {
if (result.error) {
console.log(result.error);
} else {
console.log(result);
console.log("Setup Intent id: " + result.setupIntent.id);
this.saveCardForFutureUse(result.setupIntent.id);
}
});
});
在 saveCardForFutureUse 中,我正在回拨以将此设置中的付款方式附加给客户:
String setupIntentId = request.getHeader("paymentId");
SetupIntent intent = SetupIntent.retrieve(setupIntentId);
PaymentMethod paymentMethod = PaymentMethod.retrieve(intent.getPaymentMethod());
Map<String, Object> params = new HashMap<String, Object>();
params.put("customer", "{CUSTOMER_ID}");
paymentMethod.attach(params);
然后我们可以使用给定的 paymentMethod 创建多个 PaymentIntents:
PaymentIntentCreateParams bid1Params = PaymentIntentCreateParams.builder()
.setAmount(3099l)
.setCurrency("usd")
.setConfirm(true)
.setPaymentMethod(paymentMethod.getId())
.setCustomer("CUSTOMER_ID")
.setOffSession(true)
.build();
PaymentIntentCreateParams bid2Params = PaymentIntentCreateParams.builder()
.setAmount(5099l)
.setCurrency("usd")
.setConfirm(true)
.setPaymentMethod(paymentMethod.getId())
.setCustomer("CUSTOMER_ID")
.setOffSession(true)
.build();
PaymentIntent bid1 = PaymentIntent.create(bid1Params);
PaymentIntent bid2 = PaymentIntent.create(bid2Params);
如果我们使用正确的卡片,例如:
4000002500003155 设置或首次交易时需要
这 2 个出价的付款意向将得到确认... 如果我们使用这样的卡片:
4000002760003184 必需 此测试卡需要在 所有交易。
他们仍将处于状态
“requires_action”
所以,对于那些卡,我每次付款都需要这个 3d...
【问题讨论】:
标签: java angular spring-boot stripe-payments