stripe支付 旧版 charge付款方式 demo代码
stripe支付 新版paymentIntent(付款意图) demo代码 可参考.
特点:
1.实现客户绑卡,解卡等
2.全部由服务端进行操作,前端可自定义绑卡,无需使用stripe SDK收集卡信息
3.用户授权进行冻结银行卡的资金,然后 订单结算时进行捕获花费的金额并解冻其余冻结的金额
/**
* @program: test
* @description: stripe 支付charge方式 旧版
* @author: 闲走天涯
* @create: 2021-09-02 13:48
*/
public class ChargeTest {
// key格式 sk_test开头为测试环境key,sk_live开头为生产环境key
private static final String privateKey = "test_key";
/**
* 创建token
* 用于卡信息加密
* @param creditCard
* @return
*/
public static Token createToken(CreditCard creditCard){
try{
Stripe.apiKey = privateKey;
Map<String, Object> cardParam = new HashMap<>();
Map<String, Object> card = new HashMap<>();
card.put("exp_month",creditCard.getCardExpiryMonth());
card.put("exp_year",creditCard.getCardExpiryYear());
card.put("number",creditCard.getCardNo());
card.put("cvc",creditCard.getCvv());
card.put("name",creditCard.getName());
cardParam.put("card", card);
Token token = Token.create(cardParam);
if(token != null && VerifyData.strIsNotNull(token.getId())){
return token;
}
}catch (Exception e){
e.printStackTrace();
}
return null;
}
/**
* 创建stripe客户对象并绑定银行卡信息
* @param tokenId 加密后的卡信息token对象id
* @param email
* @param name
* @return
*/
public static Customer createCustomer(String tokenId,String email,String name){
Stripe.apiKey = privateKey;
try {
//创建客户并绑定支付卡信息
Map<String, Object> customerParams = new HashMap<>();
customerParams.put("source", tokenId);
if(VerifyData.strIsNotNull(email)){
customerParams.put("email",email);
}
if(VerifyData.strIsNotNull(name)