Commit df702e8d246fee0043a7e53aeecf92eaf7548752
1 parent
96ecd502
pay: 临时性的提交,准备 client 部分的重构
Showing
24 changed files
with
116 additions
and
40 deletions
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/PayClient.java
| 1 | 1 | package cn.iocoder.yudao.framework.pay.core.client; |
| 2 | 2 | |
| 3 | 3 | |
| 4 | -import cn.iocoder.yudao.framework.pay.core.client.dto.*; | |
| 4 | +import cn.iocoder.yudao.framework.pay.core.client.dto.notify.PayNotifyDataDTO; | |
| 5 | +import cn.iocoder.yudao.framework.pay.core.client.dto.notify.PayRefundNotifyDTO; | |
| 6 | +import cn.iocoder.yudao.framework.pay.core.client.dto.notify.PayOrderNotifyRespDTO; | |
| 7 | +import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; | |
| 8 | +import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO; | |
| 9 | +import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedRespDTO; | |
| 5 | 10 | |
| 6 | 11 | /** |
| 7 | 12 | * 支付客户端,用于对接各支付渠道的 SDK,实现发起支付、退款等功能 | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/PayNotifyDataDTO.java renamed to yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/notify/PayNotifyDataDTO.java
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/PayOrderNotifyRespDTO.java renamed to yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/notify/PayOrderNotifyRespDTO.java
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/PayRefundNotifyDTO.java renamed to yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/notify/PayRefundNotifyDTO.java
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/PayOrderUnifiedReqDTO.java renamed to yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/order/PayOrderUnifiedReqDTO.java
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/PayRefundUnifiedReqDTO.java renamed to yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/refund/PayRefundUnifiedReqDTO.java
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/PayRefundUnifiedRespDTO.java renamed to yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/refund/PayRefundUnifiedRespDTO.java
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/AbstractPayClient.java
| ... | ... | @@ -4,9 +4,9 @@ import cn.iocoder.yudao.framework.pay.core.client.AbstractPayCodeMapping; |
| 4 | 4 | import cn.iocoder.yudao.framework.pay.core.client.PayClient; |
| 5 | 5 | import cn.iocoder.yudao.framework.pay.core.client.PayClientConfig; |
| 6 | 6 | import cn.iocoder.yudao.framework.pay.core.client.PayCommonResult; |
| 7 | -import cn.iocoder.yudao.framework.pay.core.client.dto.PayOrderUnifiedReqDTO; | |
| 8 | -import cn.iocoder.yudao.framework.pay.core.client.dto.PayRefundUnifiedReqDTO; | |
| 9 | -import cn.iocoder.yudao.framework.pay.core.client.dto.PayRefundUnifiedRespDTO; | |
| 7 | +import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; | |
| 8 | +import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO; | |
| 9 | +import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedRespDTO; | |
| 10 | 10 | import lombok.extern.slf4j.Slf4j; |
| 11 | 11 | |
| 12 | 12 | import javax.validation.Validation; | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AbstractAlipayClient.java
| ... | ... | @@ -4,7 +4,11 @@ import cn.hutool.core.bean.BeanUtil; |
| 4 | 4 | import cn.hutool.core.date.LocalDateTimeUtil; |
| 5 | 5 | import cn.iocoder.yudao.framework.pay.core.client.AbstractPayCodeMapping; |
| 6 | 6 | import cn.iocoder.yudao.framework.pay.core.client.PayCommonResult; |
| 7 | -import cn.iocoder.yudao.framework.pay.core.client.dto.*; | |
| 7 | +import cn.iocoder.yudao.framework.pay.core.client.dto.notify.PayNotifyDataDTO; | |
| 8 | +import cn.iocoder.yudao.framework.pay.core.client.dto.notify.PayRefundNotifyDTO; | |
| 9 | +import cn.iocoder.yudao.framework.pay.core.client.dto.notify.PayOrderNotifyRespDTO; | |
| 10 | +import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO; | |
| 11 | +import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedRespDTO; | |
| 8 | 12 | import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient; |
| 9 | 13 | import cn.iocoder.yudao.framework.pay.core.enums.PayNotifyRefundStatusEnum; |
| 10 | 14 | import com.alipay.api.AlipayApiException; |
| ... | ... | @@ -106,11 +110,15 @@ public abstract class AbstractAlipayClient extends AbstractPayClient<AlipayPayCl |
| 106 | 110 | AlipayTradeRefundModel model=new AlipayTradeRefundModel(); |
| 107 | 111 | model.setTradeNo(reqDTO.getChannelOrderNo()); |
| 108 | 112 | model.setOutTradeNo(reqDTO.getPayTradeNo()); |
| 113 | + | |
| 109 | 114 | model.setOutRequestNo(reqDTO.getMerchantRefundId()); |
| 110 | - model.setRefundAmount(calculateAmount(reqDTO.getAmount()).toString()); | |
| 115 | + model.setRefundAmount(calculateAmount(reqDTO.getAmount() / 2).toString()); | |
| 111 | 116 | model.setRefundReason(reqDTO.getReason()); |
| 117 | + | |
| 112 | 118 | AlipayTradeRefundRequest refundRequest = new AlipayTradeRefundRequest(); |
| 113 | 119 | refundRequest.setBizModel(model); |
| 120 | + refundRequest.setNotifyUrl(reqDTO.getNotifyUrl()); | |
| 121 | + refundRequest.setReturnUrl(reqDTO.getNotifyUrl()); | |
| 114 | 122 | try { |
| 115 | 123 | AlipayTradeRefundResponse response = client.execute(refundRequest); |
| 116 | 124 | log.info("[doUnifiedRefund][response({}) 发起退款 渠道返回", toJsonString(response)); | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayPcPayClient.java
| 1 | 1 | package cn.iocoder.yudao.framework.pay.core.client.impl.alipay; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.util.StrUtil; |
| 4 | +import cn.hutool.http.Method; | |
| 4 | 5 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
| 5 | 6 | import cn.iocoder.yudao.framework.pay.core.client.PayCommonResult; |
| 6 | -import cn.iocoder.yudao.framework.pay.core.client.dto.PayOrderUnifiedReqDTO; | |
| 7 | +import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; | |
| 7 | 8 | import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum; |
| 8 | 9 | import com.alibaba.fastjson.JSONObject; |
| 9 | 10 | import com.alipay.api.AlipayApiException; |
| ... | ... | @@ -36,24 +37,25 @@ public class AlipayPcPayClient extends AbstractAlipayClient { |
| 36 | 37 | JSONObject bizContent = new JSONObject(); |
| 37 | 38 | // 参数说明可查看: https://opendocs.alipay.com/open/028r8t?scene=22 |
| 38 | 39 | bizContent.put("out_trade_no", reqDTO.getMerchantOrderId()); |
| 39 | - bizContent.put("total_amount", calculateAmount(reqDTO.getAmount())); | |
| 40 | 40 | bizContent.put("subject", reqDTO.getSubject()); |
| 41 | - bizContent.put("product_code", "FAST_INSTANT_TRADE_PAY"); | |
| 41 | + bizContent.put("total_amount", calculateAmount(reqDTO.getAmount())); | |
| 42 | + bizContent.put("product_code", "FAST_INSTANT_TRADE_PAY"); // 销售产品码. 目前电脑支付场景下仅支持 FAST_INSTANT_TRADE_PAY | |
| 42 | 43 | // PC扫码支付的方式:支持前置模式和跳转模式。4: 订单码-可定义宽度的嵌入式二维码 |
| 43 | - bizContent.put("qr_pay_mode", "4"); | |
| 44 | +// bizContent.put("qr_pay_mode", "4"); | |
| 44 | 45 | // 自定义二维码宽度 |
| 45 | - bizContent.put("qrcode_width", "150"); | |
| 46 | +// bizContent.put("qrcode_width", "150"); | |
| 46 | 47 | request.setBizContent(bizContent.toJSONString()); |
| 47 | 48 | request.setNotifyUrl(reqDTO.getNotifyUrl()); |
| 48 | 49 | request.setReturnUrl(""); |
| 49 | 50 | // 执行请求 |
| 50 | 51 | AlipayTradePagePayResponse response; |
| 51 | 52 | try { |
| 52 | - response = client.pageExecute(request); | |
| 53 | + response = client.pageExecute(request, Method.GET.name()); | |
| 53 | 54 | } catch (AlipayApiException e) { |
| 54 | 55 | log.error("[unifiedOrder][request({}) 发起支付失败]", JsonUtils.toJsonString(reqDTO), e); |
| 55 | 56 | return PayCommonResult.build(e.getErrCode(), e.getErrMsg(), null, codeMapping); |
| 56 | 57 | } |
| 58 | + System.out.println(response.getBody()); | |
| 57 | 59 | // 响应为表单格式,前端可嵌入响应的页面或关闭当前支付窗口 |
| 58 | 60 | return PayCommonResult.build(StrUtil.blankToDefault(response.getCode(),"10000") ,response.getMsg(), response, codeMapping); |
| 59 | 61 | } | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayQrPayClient.java
| 1 | 1 | package cn.iocoder.yudao.framework.pay.core.client.impl.alipay; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.pay.core.client.PayCommonResult; |
| 4 | -import cn.iocoder.yudao.framework.pay.core.client.dto.PayOrderUnifiedReqDTO; | |
| 4 | +import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; | |
| 5 | 5 | import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum; |
| 6 | 6 | import com.alipay.api.AlipayApiException; |
| 7 | 7 | import com.alipay.api.domain.AlipayTradePrecreateModel; | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayWapPayClient.java
| 1 | 1 | package cn.iocoder.yudao.framework.pay.core.client.impl.alipay; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.date.DateUtil; |
| 4 | +import cn.hutool.http.Method; | |
| 4 | 5 | import cn.iocoder.yudao.framework.pay.core.client.PayCommonResult; |
| 5 | -import cn.iocoder.yudao.framework.pay.core.client.dto.PayOrderUnifiedReqDTO; | |
| 6 | +import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; | |
| 6 | 7 | import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum; |
| 7 | 8 | import com.alipay.api.AlipayApiException; |
| 8 | 9 | import com.alipay.api.domain.AlipayTradeWapPayModel; |
| ... | ... | @@ -50,10 +51,11 @@ public class AlipayWapPayClient extends AbstractAlipayClient { |
| 50 | 51 | // 执行请求 |
| 51 | 52 | AlipayTradeWapPayResponse response; |
| 52 | 53 | try { |
| 53 | - response = client.pageExecute(request); | |
| 54 | + response = client.pageExecute(request, Method.GET.name()); | |
| 54 | 55 | } catch (AlipayApiException e) { |
| 55 | 56 | return PayCommonResult.build(e.getErrCode(), e.getErrMsg(), null, codeMapping); |
| 56 | 57 | } |
| 58 | + System.out.println(response.getBody()); | |
| 57 | 59 | |
| 58 | 60 | // TODO 芋艿:sub Code |
| 59 | 61 | if(response.isSuccess() && Objects.isNull(response.getCode()) && Objects.nonNull(response.getBody())){ | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXLitePayClient.java
| ... | ... | @@ -9,7 +9,12 @@ import cn.hutool.core.util.StrUtil; |
| 9 | 9 | import cn.iocoder.yudao.framework.common.util.io.FileUtils; |
| 10 | 10 | import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; |
| 11 | 11 | import cn.iocoder.yudao.framework.pay.core.client.PayCommonResult; |
| 12 | -import cn.iocoder.yudao.framework.pay.core.client.dto.*; | |
| 12 | +import cn.iocoder.yudao.framework.pay.core.client.dto.notify.PayNotifyDataDTO; | |
| 13 | +import cn.iocoder.yudao.framework.pay.core.client.dto.notify.PayRefundNotifyDTO; | |
| 14 | +import cn.iocoder.yudao.framework.pay.core.client.dto.notify.PayOrderNotifyRespDTO; | |
| 15 | +import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; | |
| 16 | +import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO; | |
| 17 | +import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedRespDTO; | |
| 13 | 18 | import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient; |
| 14 | 19 | import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum; |
| 15 | 20 | import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXNativePayClient.java
| ... | ... | @@ -8,7 +8,12 @@ import cn.hutool.core.util.StrUtil; |
| 8 | 8 | import cn.iocoder.yudao.framework.common.util.io.FileUtils; |
| 9 | 9 | import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; |
| 10 | 10 | import cn.iocoder.yudao.framework.pay.core.client.PayCommonResult; |
| 11 | -import cn.iocoder.yudao.framework.pay.core.client.dto.*; | |
| 11 | +import cn.iocoder.yudao.framework.pay.core.client.dto.notify.PayNotifyDataDTO; | |
| 12 | +import cn.iocoder.yudao.framework.pay.core.client.dto.notify.PayRefundNotifyDTO; | |
| 13 | +import cn.iocoder.yudao.framework.pay.core.client.dto.notify.PayOrderNotifyRespDTO; | |
| 14 | +import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; | |
| 15 | +import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO; | |
| 16 | +import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedRespDTO; | |
| 12 | 17 | import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient; |
| 13 | 18 | import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum; |
| 14 | 19 | import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXPubPayClient.java
| ... | ... | @@ -9,7 +9,12 @@ import cn.hutool.core.util.StrUtil; |
| 9 | 9 | import cn.iocoder.yudao.framework.common.util.io.FileUtils; |
| 10 | 10 | import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; |
| 11 | 11 | import cn.iocoder.yudao.framework.pay.core.client.PayCommonResult; |
| 12 | -import cn.iocoder.yudao.framework.pay.core.client.dto.*; | |
| 12 | +import cn.iocoder.yudao.framework.pay.core.client.dto.notify.PayNotifyDataDTO; | |
| 13 | +import cn.iocoder.yudao.framework.pay.core.client.dto.notify.PayRefundNotifyDTO; | |
| 14 | +import cn.iocoder.yudao.framework.pay.core.client.dto.notify.PayOrderNotifyRespDTO; | |
| 15 | +import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; | |
| 16 | +import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO; | |
| 17 | +import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedRespDTO; | |
| 13 | 18 | import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient; |
| 14 | 19 | import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum; |
| 15 | 20 | import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-pay/src/test/java/cn.iocoder.yudao.framework.pay.core.client.impl/PayClientFactoryImplIntegrationTest.java
| ... | ... | @@ -5,7 +5,7 @@ import cn.hutool.core.util.RandomUtil; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 6 | 6 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
| 7 | 7 | import cn.iocoder.yudao.framework.pay.core.client.PayClient; |
| 8 | -import cn.iocoder.yudao.framework.pay.core.client.dto.PayOrderUnifiedReqDTO; | |
| 8 | +import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; | |
| 9 | 9 | import cn.iocoder.yudao.framework.pay.core.client.impl.alipay.AlipayPayClientConfig; |
| 10 | 10 | import cn.iocoder.yudao.framework.pay.core.client.impl.alipay.AlipayQrPayClient; |
| 11 | 11 | import cn.iocoder.yudao.framework.pay.core.client.impl.alipay.AlipayWapPayClient; | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-pay/src/test/java/cn.iocoder.yudao.framework.pay.core.client.impl/alipay/AlipayQrPayClientTest.java
| ... | ... | @@ -2,7 +2,7 @@ package cn.iocoder.yudao.framework.pay.core.client.impl.alipay; |
| 2 | 2 | import cn.hutool.core.util.ReflectUtil; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants; |
| 4 | 4 | import cn.iocoder.yudao.framework.pay.core.client.PayCommonResult; |
| 5 | -import cn.iocoder.yudao.framework.pay.core.client.dto.PayOrderUnifiedReqDTO; | |
| 5 | +import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; | |
| 6 | 6 | import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; |
| 7 | 7 | import com.alipay.api.AlipayApiException; |
| 8 | 8 | import com.alipay.api.DefaultAlipayClient; | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/notify/PayNotifyController.java
| ... | ... | @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.pay.controller.admin.notify; |
| 3 | 3 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; |
| 4 | 4 | import cn.iocoder.yudao.framework.pay.core.client.PayClient; |
| 5 | 5 | import cn.iocoder.yudao.framework.pay.core.client.PayClientFactory; |
| 6 | -import cn.iocoder.yudao.framework.pay.core.client.dto.PayNotifyDataDTO; | |
| 6 | +import cn.iocoder.yudao.framework.pay.core.client.dto.notify.PayNotifyDataDTO; | |
| 7 | 7 | import cn.iocoder.yudao.module.pay.service.order.PayOrderService; |
| 8 | 8 | import cn.iocoder.yudao.module.pay.service.refund.PayRefundService; |
| 9 | 9 | import io.swagger.v3.oas.annotations.Operation; | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/order/PayOrderConvert.java
| 1 | 1 | package cn.iocoder.yudao.module.pay.convert.order; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | -import cn.iocoder.yudao.framework.pay.core.client.dto.PayOrderUnifiedReqDTO; | |
| 4 | +import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; | |
| 5 | 5 | import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO; |
| 6 | 6 | import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderRespDTO; |
| 7 | 7 | import cn.iocoder.yudao.module.pay.controller.admin.order.vo.*; | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderService.java
| 1 | 1 | package cn.iocoder.yudao.module.pay.service.order; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.framework.pay.core.client.dto.PayNotifyDataDTO; | |
| 3 | +import cn.iocoder.yudao.framework.pay.core.client.dto.notify.PayNotifyDataDTO; | |
| 4 | 4 | import cn.iocoder.yudao.module.pay.controller.admin.order.vo.PayOrderExportReqVO; |
| 5 | 5 | import cn.iocoder.yudao.module.pay.controller.admin.order.vo.PayOrderPageReqVO; |
| 6 | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java
| ... | ... | @@ -9,9 +9,9 @@ import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
| 9 | 9 | import cn.iocoder.yudao.framework.pay.config.PayProperties; |
| 10 | 10 | import cn.iocoder.yudao.framework.pay.core.client.PayClient; |
| 11 | 11 | import cn.iocoder.yudao.framework.pay.core.client.PayClientFactory; |
| 12 | -import cn.iocoder.yudao.framework.pay.core.client.dto.PayNotifyDataDTO; | |
| 13 | -import cn.iocoder.yudao.framework.pay.core.client.dto.PayOrderNotifyRespDTO; | |
| 14 | -import cn.iocoder.yudao.framework.pay.core.client.dto.PayOrderUnifiedReqDTO; | |
| 12 | +import cn.iocoder.yudao.framework.pay.core.client.dto.notify.PayNotifyDataDTO; | |
| 13 | +import cn.iocoder.yudao.framework.pay.core.client.dto.notify.PayOrderNotifyRespDTO; | |
| 14 | +import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; | |
| 15 | 15 | import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; |
| 16 | 16 | import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO; |
| 17 | 17 | import cn.iocoder.yudao.module.pay.controller.admin.order.vo.PayOrderExportReqVO; |
| ... | ... | @@ -42,7 +42,6 @@ import javax.annotation.Resource; |
| 42 | 42 | import java.time.LocalDateTime; |
| 43 | 43 | import java.util.Collection; |
| 44 | 44 | import java.util.List; |
| 45 | -import java.util.Objects; | |
| 46 | 45 | |
| 47 | 46 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 48 | 47 | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/refund/PayRefundService.java
| 1 | 1 | package cn.iocoder.yudao.module.pay.service.refund; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.framework.pay.core.client.dto.PayNotifyDataDTO; | |
| 3 | +import cn.iocoder.yudao.framework.pay.core.client.dto.notify.PayNotifyDataDTO; | |
| 4 | 4 | import cn.iocoder.yudao.module.pay.api.refund.dto.PayRefundCreateReqDTO; |
| 5 | 5 | import cn.iocoder.yudao.module.pay.controller.admin.refund.vo.PayRefundExportReqVO; |
| 6 | 6 | import cn.iocoder.yudao.module.pay.controller.admin.refund.vo.PayRefundPageReqVO; | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/refund/PayRefundServiceImpl.java
| ... | ... | @@ -3,13 +3,14 @@ package cn.iocoder.yudao.module.pay.service.refund; |
| 3 | 3 | import cn.hutool.core.util.RandomUtil; |
| 4 | 4 | import cn.hutool.core.util.StrUtil; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; |
| 6 | +import cn.iocoder.yudao.framework.pay.config.PayProperties; | |
| 6 | 7 | import cn.iocoder.yudao.framework.pay.core.client.PayClient; |
| 7 | 8 | import cn.iocoder.yudao.framework.pay.core.client.PayClientFactory; |
| 8 | 9 | import cn.iocoder.yudao.framework.pay.core.client.PayCommonResult; |
| 9 | -import cn.iocoder.yudao.framework.pay.core.client.dto.PayNotifyDataDTO; | |
| 10 | -import cn.iocoder.yudao.framework.pay.core.client.dto.PayRefundNotifyDTO; | |
| 11 | -import cn.iocoder.yudao.framework.pay.core.client.dto.PayRefundUnifiedReqDTO; | |
| 12 | -import cn.iocoder.yudao.framework.pay.core.client.dto.PayRefundUnifiedRespDTO; | |
| 10 | +import cn.iocoder.yudao.framework.pay.core.client.dto.notify.PayNotifyDataDTO; | |
| 11 | +import cn.iocoder.yudao.framework.pay.core.client.dto.notify.PayRefundNotifyDTO; | |
| 12 | +import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO; | |
| 13 | +import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedRespDTO; | |
| 13 | 14 | import cn.iocoder.yudao.framework.pay.core.enums.PayNotifyRefundStatusEnum; |
| 14 | 15 | import cn.iocoder.yudao.module.pay.api.refund.dto.PayRefundCreateReqDTO; |
| 15 | 16 | import cn.iocoder.yudao.module.pay.controller.admin.refund.vo.PayRefundExportReqVO; |
| ... | ... | @@ -55,6 +56,9 @@ import java.util.Objects; |
| 55 | 56 | public class PayRefundServiceImpl implements PayRefundService { |
| 56 | 57 | |
| 57 | 58 | @Resource |
| 59 | + private PayProperties payProperties; | |
| 60 | + | |
| 61 | + @Resource | |
| 58 | 62 | private PayClientFactory payClientFactory; |
| 59 | 63 | |
| 60 | 64 | @Resource |
| ... | ... | @@ -162,6 +166,7 @@ public class PayRefundServiceImpl implements PayRefundService { |
| 162 | 166 | .setChannelOrderNo(order.getChannelOrderNo()) |
| 163 | 167 | .setPayTradeNo(orderExtensionDO.getNo()) |
| 164 | 168 | .setMerchantRefundId(merchantRefundId) // TODO 芋艿:需要优化 |
| 169 | + .setNotifyUrl(genChannelPayNotifyUrl(channel)) // TODO 芋艿:优化下 notifyUrl | |
| 165 | 170 | .setReason(reqDTO.getReason()); |
| 166 | 171 | // 向渠道发起退款申请 |
| 167 | 172 | PayCommonResult<PayRefundUnifiedRespDTO> refundUnifiedResult = client.unifiedRefund(unifiedReqDTO); |
| ... | ... | @@ -173,6 +178,16 @@ public class PayRefundServiceImpl implements PayRefundService { |
| 173 | 178 | return payRefundDO.getId(); |
| 174 | 179 | } |
| 175 | 180 | |
| 181 | + /** | |
| 182 | + * 根据支付渠道的编码,生成支付渠道的回调地址 | |
| 183 | + * | |
| 184 | + * @param channel 支付渠道 | |
| 185 | + * @return 支付渠道的回调地址 配置地址 + "/" + channel id | |
| 186 | + */ | |
| 187 | + private String genChannelPayNotifyUrl(PayChannelDO channel) { | |
| 188 | + return payProperties.getCallbackUrl() + "/" + channel.getId(); | |
| 189 | + } | |
| 190 | + | |
| 176 | 191 | @Override |
| 177 | 192 | @Transactional(rollbackFor = Exception.class) |
| 178 | 193 | public void notifyPayRefund(Long channelId, PayNotifyDataDTO notifyData) { | ... | ... |
yudao-ui-admin/src/views/pay/order/submit.vue
| ... | ... | @@ -12,8 +12,9 @@ |
| 12 | 12 | </el-descriptions> |
| 13 | 13 | </el-card> |
| 14 | 14 | |
| 15 | + | |
| 15 | 16 | <!-- 支付选择框 --> |
| 16 | - <el-card style="margin-top: 10px"> | |
| 17 | + <el-card style="margin-top: 10px" v-loading="submitLoading" element-loading-text="提交支付中..."> | |
| 17 | 18 | <!-- 支付宝 --> |
| 18 | 19 | <el-descriptions title="选择支付宝支付"> |
| 19 | 20 | </el-descriptions> |
| ... | ... | @@ -46,6 +47,10 @@ |
| 46 | 47 | :close-on-press-escape="false"> |
| 47 | 48 | <qrcode-vue :value="qrCode.url" size="310" level="H" /> |
| 48 | 49 | </el-dialog> |
| 50 | + | |
| 51 | + <!-- 阿里支付 --> | |
| 52 | + <div ref="alipayWap" v-html="alipayHtml.value" /> | |
| 53 | + | |
| 49 | 54 | </div> |
| 50 | 55 | </template> |
| 51 | 56 | <script> |
| ... | ... | @@ -77,12 +82,14 @@ export default { |
| 77 | 82 | wx_pub: require("@/assets/images/pay/icon/wx_pub.svg"), |
| 78 | 83 | mock: require("@/assets/images/pay/icon/mock.svg"), |
| 79 | 84 | }, |
| 85 | + submitLoading: false, // 提交支付的 loading | |
| 80 | 86 | qrCode: { // 支付二维码 |
| 81 | 87 | url: '', |
| 82 | 88 | title: '', |
| 83 | 89 | visible: false, |
| 84 | 90 | }, |
| 85 | 91 | interval: undefined, // 定时任务,轮询是否完成支付 |
| 92 | + alipayHtml: '' // 阿里支付的 HTML | |
| 86 | 93 | }; |
| 87 | 94 | }, |
| 88 | 95 | created() { |
| ... | ... | @@ -136,14 +143,20 @@ export default { |
| 136 | 143 | }, |
| 137 | 144 | /** 提交支付 */ |
| 138 | 145 | submit(channelCode) { |
| 146 | + this.submitLoading = true | |
| 139 | 147 | submitOrder({ |
| 140 | 148 | id: this.id, |
| 141 | 149 | channelCode: channelCode |
| 142 | 150 | }).then(response => { |
| 151 | + const invokeResponse = response.data.invokeResponse | |
| 143 | 152 | // 不同的支付,调用不同的策略 |
| 144 | 153 | if (channelCode === PayChannelEnum.ALIPAY_QR.code) { |
| 145 | - this.submitAfterAlipayQr(response.data.invokeResponse) | |
| 154 | + this.submitAfterAlipayQr(invokeResponse) | |
| 155 | + } else if (channelCode === PayChannelEnum.ALIPAY_PC.code | |
| 156 | + || channelCode === PayChannelEnum.ALIPAY_WAP.code) { | |
| 157 | + this.submitAfterAlipayPc(invokeResponse) | |
| 146 | 158 | } |
| 159 | + | |
| 147 | 160 | // 打开轮询任务 |
| 148 | 161 | this.createQueryInterval() |
| 149 | 162 | }) |
| ... | ... | @@ -155,6 +168,23 @@ export default { |
| 155 | 168 | url: invokeResponse.qrCode, |
| 156 | 169 | visible: true |
| 157 | 170 | } |
| 171 | + this.submitLoading = false | |
| 172 | + }, | |
| 173 | + /** 提交支付后(支付宝 PC 网站支付) */ | |
| 174 | + submitAfterAlipayPc(invokeResponse) { | |
| 175 | + // 渲染支付页面 | |
| 176 | + this.alipayHtml = { | |
| 177 | + value: invokeResponse.body, | |
| 178 | + visible: true | |
| 179 | + } | |
| 180 | + // 防抖避免重复支付 | |
| 181 | + this.$nextTick(() => { | |
| 182 | + // 提交支付表单 | |
| 183 | + // this.$refs.alipayWap.children[0].submit(); | |
| 184 | + // setTimeout(() => { | |
| 185 | + // this.submitLoading = false | |
| 186 | + // }, 1000); | |
| 187 | + }); | |
| 158 | 188 | }, |
| 159 | 189 | /** 轮询查询任务 */ |
| 160 | 190 | createQueryInterval() { | ... | ... |