stripe国际支付(对接支付宝、微信)

前言:stripe国际支付现在网上资料很少,且不支持中国,所以如果要用需要去支持的国家注册商户,官网的java demo是用的spark框架,我这里用的spring,验签需要手动验签,且不能用官网的方法正文:支付宝文档地址:https://stripe.com/docs/sources/alipay微信支付文档地址:https://stripe.com/docs/sources/wec...
摘要由CSDN通过智能技术生成

前言:stripe国际支付现在网上资料很少,且不支持中国,所以如果要用需要去支持的国家注册商户,官网的java demo是用的spark框架,我这里用的spring,验签需要手动验签,且不能用官网的方法

正文:

支付宝文档地址:https://stripe.com/docs/sources/alipay

微信支付文档地址:https://stripe.com/docs/sources/wechat-pay

支付宝和微信的流程差不多一样。

做了个简单的时序图

关于配置:

回调地址配置,可以每个触发事件都配置不一样的url,也可以都配置一个,我只配置了一个

获得source时候发送请求用到的公匙:

代码:

<!-- stripe支付官方包 -->
<dependency>
    <groupId>com.stripe</groupId>
    <artifactId>stripe-java</artifactId>
    <version>7.26.0</version>
</dependency>

其实只有三个接口:

1.给前端准备数据

2.授权完回调地址

3.回调接口

回调接口:

常量类:

service:

package com.otcbi.pay.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.gson.JsonSyntaxException;
import com.otcbi.coin.common.exception.ApiException;
import com.otcbi.coin.common.exception.ApiResponMessage;
import com.otcbi.constat.Consts;
import com.otcbi.pay.entity.StripeOrder;
import com.otcbi.pay.service.IGoodsOnlineService;
import com.otcbi.pay.service.IStripeOrderService;
import com.otcbi.pay.service.IStripeWebhookMessageService;
import com.otcbi.shop.dto.StripeCreateSourceDTO;
import com.otcbi.shop.entity.Orders;
import com.otcbi.shop.service.IOrdersService;
import com.stripe.Stripe;
import com.stripe.exception.SignatureVerificationException;
import com.stripe.model.Charge;
import com.stripe.model.Event;
import com.stripe.model.EventData;
import com.stripe.net.Webhook;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

@Service
public class IGoodsOnlineServiceImpl implements IGoodsOnlineService {

    private static final Logger logger = LoggerFactory.getLogger(IGoodsOnlineServiceImpl.class);

    @Value("${stripe.homeUrl}")
    private String homeUrl;

    @Value("${stripe.apiKey}")
    String stripeApiKey;

    @Value("${stripe.webhookSecret}")
    String stripeWebhookSecret;


    @Autowired
    private IOrdersService iOrdersService;

    @Autowired
    private IStripeOrderService iStripeOrderService;

    @Autowired
    private IStripeWebhookMessageService iStripeWebhookMessageService;

    public StripeCreateSourceDTO createSource(Long ordersId) throws Exception {
        Orders orders = iOrdersService.getById(ordersId);
        if (orders == null) {
            throw new ApiException(ApiResponMessage.SHOP_ORDERS_EXIST, null);
        } else if (orders.getPayState() == 2) {
            throw new ApiException(ApiResponMessage.ORDERS_ALREADY_FINISHED, null);
        }
        StripeCreateSourceDTO source = new StripeCreateSourceDTO();
        source.setUserId(orders.getUserId());

        if (orders.getPayType() == 1) {
            source.setType("alipay");
        } else if (orders.getPayType() == 2) {
            source.setType("wechat");
        }
        source.setCurrency(orders.getCoin());
        source.setOrderNum(orders.getOrderNum());
        source.setReturnUrl(homeUrl + "/stripe/createSourceRetuenBack?orderNum=" + orders.getOrderNum());

        QueryWrapper<StripeOrder> wrapper = new QueryWrapper<>();
        wrapper.eq("is_deleted", "N");
        wrapper.eq("order_num", orders.getOrderNum());
        wrapper.
  • 3
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 12
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值