Springboot 整合 Stripe 国际支付进行收款操作,Stripe 国际支付的支付流程

       之前我们写了海外的印度 Razorpay 支付,Razorpay 的付款流程跟国内基本是一样的,首先拿着金额等信息生成订单号,再根据订单号进行支付,本次简单的了解下 Stripe 支付流程,进行一下支付测试 支付流程还不太一样

      首先是 Stripe 的官网  https://stripe.com/zh-cn-us ,我们在官网进行一下注册,邮箱的话国内邮箱就可以,因为等会需要拿 秘钥 进行支付测试,

这里是直接用stripe的checkout方式 进行测试,如图 ,支付卡号地址:https://stripe.com/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.com");//选填:email
            //customerParams.put("name", "测试");//选填: name 如,顾客的姓名
            //customerParams.put("description", "我是商品描述");//选填: description 如,商品的名称
            customerParams.put("source", tokenId);

            
            Customer customer = null;
            try {
                // Customer 对象api https://stripe.com/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.com/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 控制台看到支付结果

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值