该篇文章提供的是一个简化版的stripe支付,纯后端Java,需引用对应的maven
重点说明:1 Stripe属于信用卡支付封装的实体类,在调用接口之前需要设置好秘钥和版本号
2 获取tokenId的代码stripe官网提供的是sk_开头的秘钥,实际应该为pk_开头的公钥
3 对于低版本提交charge支付,必须要带上Stripe.apiVesrsion api版本号,否则生产环境返回的状态码就不是successed。创建商户号时会有两个api版本号,一个是charge版本号,一个是tokens版本号,支付时选择对于的charge
4 测试账户4242424242424242或者5555555555554444,CVC为任意三位数,时间为任意将来时间
5 该文章上面提供的账号,公钥,秘钥以及api版本号属于可用的,按照上文提供的代码可直接拷贝验证,亲测有效。
<dependency>
<groupId>com.stripe</groupId>
<artifactId>stripe-java</artifactId>
<version>20.62.0</version>
</dependency>
1 stripe调用根据公钥----获取tokenId
Stripe.apiKey引用的是注册商户号的公钥,
Stripe.apiKey = "pk_test_51IiZg2GtURY4TP4fwDZrc9fZLOth7IGxEmFO9VF6HtEteMIOM3d06yVlKhn53m6jCdXjlG9g4fmrkMfQyUWpvJaR00RA72yXr4";
Map<String, Object> card = new HashMap<>();
card.put("number", "4242424242424242");
card.put("exp_month", 7);
card.put("exp_year", 2022);
card.put("cvc", "314");
Map<String, Object> params = new HashMap<>();
params.put("card", card);
Token token = Token.create(params);
String source = token.getId();
其中获取tokenId是为了创建支付做准备,该代码更多是在改造为前端页面编写,然后传递到后端
https://stripe/docs/api/tokens/create_card?lang=java
2 stripe创建charge
Stripe.apiKey = "sk_test_51IiZg2GtURY4TP4fK2PPwqdWQG4R5MaXiaxMF0UtB0Jrcm7ftnRzqQ9xTNcB8YJZF9F6uYEV8BU9PKorxtmUf6om00yVQfzpzP";
Stripe.apiVesrsion = '2017-08-15';
// `source` is obtained with Stripe.js; see https://stripe/docs/payments/accept-a-payment-charges#web-create-token
Map<String, Object> params = new HashMap<>();
params.put("amount", 2000);
params.put("currency", "usd");
params.put("source", "tok_mastercard");//该source为上段代码的tokenId
params.put(
"description",
"My First Test Charge (created for API docs)"
);
Charge charge = Charge.create(params);
//charge
if ("succeeded".equalsIgnoreCase(charge.getStatus())) {
//succeeded 支付成功
}
//异常捕获
//StripeException
https://stripe/docs/api/charges/create?lang=java
3 stripe退款
Stripe.apiKey = "sk_test_51IiZg2GtURY4TP4fK2PPwqdWQG4R5MaXiaxMF0UtB0Jrcm7ftnRzqQ9xTNcB8YJZF9F6uYEV8BU9PKorxtmUf6om00yVQfzpzP";
Map<String, Object> params = new HashMap<>();
params.put("charge","ch_1IqTkYGtURY4TP4fAdSpX4Al");
params.put("amount",100);//属于int类型,金额为分
Refund refund = Refund.create(params);
if ("succeeded".equalsIgnoreCase(refund.getStatus())) {
//succeeded 退款成功
}
//异常捕获
//StripeException
4 监听回调:webhook
https://stripe/docs/api/webhook_endpoints/create为官方提供的api
https://api.it120/{domain}/pay/stripe/payBack,domain为项目域名
支付宝支付与退款
https://blog.csdn/weixin_41500775/article/details/118545003?spm=1001.2014.3001.5501
微信支付与退款
https://blog.csdn/weixin_41500775/article/details/118522793?spm=1001.2014.3001.5501
paypal支付与退款
https://blog.csdn/weixin_41500775/article/details/118580295?spm=1001.2014.3001.5501
更多推荐
stripe信用卡支付与退款
发布评论