之前我们写了海外的印度 Razorpay 支付,Razorpay 的付款流程跟国内基本是一样的,首先拿着金额等信息生成订单号,再根据订单号进行支付,本次简单的了解下 Stripe 支付流程,进行一下支付测试 支付流程还不太一样
首先是 Stripe 的官网 https://stripe/zh-cn-us ,我们在官网进行一下注册,邮箱的话国内邮箱就可以,因为等会需要拿 秘钥 进行支付测试,
这里是直接用stripe的checkout方式 进行测试,如图 ,支付卡号地址:https://stripe/docs/testing#international-cards
这里点击支付后,会调用一个创建 tokens 的接口, 我们拿到这个接口返回的 id , 把表单信息 和 id 信息传回后台,就会知道这笔订单的支付状态成功还是失败
springboot 继承方式,首先引用 maven 插件
<dependency>
<groupId>com.stripe</groupId>
<artifactId>stripe-java</artifactId>
<version>19.10.0</version>
</dependency>
接下来我们根据 token_id 拿到支付状态 ,这里表单信息根据你自己的来,这里写死替代
@RequestMapping(value = "pay", method = RequestMethod.GET)
public AjaxResult creditCardPay(@RequestParam(value = "tokenId", required = true) String tokenId){
try {
Stripe.apiKey = "你的秘钥";
logger.info("支付请求token{}",tokenId);
//======StripeStep1: 根据客户端source获取到customer对象
Map<String, Object> customerParams = new HashMap<String, Object>();
customerParams.put("email", "676291554@qq");//选填:email
//customerParams.put("name", "测试");//选填: name 如,顾客的姓名
//customerParams.put("description", "我是商品描述");//选填: description 如,商品的名称
customerParams.put("source", tokenId);
Customer customer = null;
try {
// Customer 对象api https://stripe/docs/api/customers/object
customer = Customer.create(customerParams);
} catch (StripeException e) {
e.printStackTrace();
return AjaxResult.error("支付失败");
}
//======StripeStep2: 根据customer对象进行支付
Map<String, Object> chargeParams = new HashMap<String, Object>();
chargeParams.put("amount", 100);//必须是整数
chargeParams.put("currency", "USD");//USD 美元、CNY 人民币
chargeParams.put("customer", customer.getId());//类似: cus_AFGbOSiITuJVDs
// Charge 对象api https://stripe/docs/api/charges/object
Charge charge = null;
try {
charge = Charge.create(chargeParams);
} catch (StripeException e) {
e.printStackTrace();
return AjaxResult.error("支付失败");
}
if ("succeeded".equalsIgnoreCase(charge.getStatus())) {
//成功后做的事情
}
} else {
//支付失败
}
return AjaxResult.success();
}catch (Exception e){
e.printStackTrace();
return AjaxResult.error("支付失败");
}
}
然后我们可以在 stripe 控制台看到支付结果
更多推荐
Springboot 整合 Stripe 国际支付进行收款操作,Stripe 国际支付的支付流程
发布评论