概要
提示:stripe 支付是国外新兴起的一种信用卡支付平台,这里将展示使用java语言进行集成,其他语言原理类似;
整体架构流程
流程简单介绍:
1、在支付表单加载过程中,需要向stripe方加载需要支付的金额,currency,以及客户资料
2、点击支付按钮后,表单提交
3、webhook监听事件异步调用函数
技术细节
1、在webhook中使用传输数据,可以使用stripe默认支持方式metaData,也可以使用中间件redis等
2、在本地部署webhook程序时,使用版本应和官网最新保持,不然事件监听不到
代码样例
<!-- https://mvnrepository.com/artifact/com.stripe/stripe-java -->
<dependency>
<groupId>com.stripe</groupId>
<artifactId>stripe-java</artifactId>
<version>22.8.0</version>
</dependency>
1、前端初始化支付表单
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script src="https://js.stripe.com/v3/"></script>
<div>
<div id="payment-element">
<!--Stripe.js injects the Payment Element-->
</div>
<button id="payCardSubmit" type="button">
<div class="spinner hidden" id="spinner"></div>
<span id="button-text">Pay now</span>
</button>
<div id="payment-message" class="hidden"></div>
</div>
<script>
const stripe = Stripe(stripePublicKey);
let elements;
$.ajax({
url:'/payment/clientSecret',
dataType:"json",
data:{
"user":user},
type:"post",
success:function(json){