Stripe中的 googlePay 和 applePay (Java)
在网站中接入stripe的googlepay和applepay工作主要在前端,后端需要配合前端做少量工作,前端部分可参考官方文档:https://stripe/docs/stripe-js/elements/payment-request-button
流程如下图所示
在pom文件中引入依赖
<dependency>
<groupId>com.stripe</groupId>
<artifactId>stripe-java</artifactId>
<version>20.62.0</version>
</dependency>
后端Java代码:
//googlekey
public Map<String,Object> googlekey(BigDecimal money) throws StripeException {
Stripe.apiKey = key;
PaymentIntentCreateParams params =
PaymentIntentCreateParams.builder()
.setCurrency("usd")
.setAmount(money.longValue()*100)
.build();
PaymentIntent intent = PaymentIntent.create(params);
Map<String,Object> result=new HashMap<>();
result.put("clientSecret",intent.getClientSecret());
result.put("googlePayId",intent.getId());
return result;
}
public Boolean googleRefund(String googlePayId) throws StripeException {
Stripe.apiKey = key;
Refund refund = Refund.create(RefundCreateParams.builder()
.setPaymentIntent(googlePayId)
.build());
return true;
}
更多推荐
Stripe中的 googlePay 和 applePay (Java)
发布评论