From 7b6dbe8d05ae93b6ecf703c6907e6697bb7e42e4 Mon Sep 17 00:00:00 2001 From: xxm1995 Date: Fri, 26 Jan 2024 16:51:33 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E6=94=AF=E4=BB=98=E9=80=80=E6=AC=BE?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=AD=96=E7=95=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _doc/Task.md | 4 +- .../daxpay/code/PayRefundStatusEnum.java | 15 +- .../platform/daxpay/code/PayStatusEnum.java | 2 +- .../bootx/platform/daxpay/util/PayUtil.java | 10 - .../daxpay/service/code/AliPayCode.java | 1 - .../service/code/PayRepairTypeEnum.java | 3 +- .../service/code/RefundRepairTypeEnum.java | 20 ++ .../service/common/context/CallbackLocal.java | 11 +- .../common/context/PaymentContext.java | 2 +- .../service/common/context/RepairLocal.java | 10 +- .../alipay/service/AliPayCallbackService.java | 26 ++- .../voucher/dao/VoucherPayOrderMapper.java | 1 + .../voucher/dao/VoucherPaymentManager.java | 1 + .../voucher/entity/VoucherPayOrder.java | 1 + .../service/VoucherPayOrderService.java | 1 + .../wallet/dao/WalletPaymentManager.java | 1 + .../wallet/dao/WalletPaymentMapper.java | 1 + .../channel/wallet/entity/WalletPayOrder.java | 1 + .../wallet/service/WalletPayOrderService.java | 1 + .../service/WeChatPayCallbackService.java | 23 +- .../core/order/pay/entity/PayOrder.java | 18 -- .../callback/result/PayCallbackResult.java | 28 --- .../callback/service/PayCallbackService.java | 19 +- .../service/PayRefundCallbackService.java | 45 +++- .../close/service/PayCloseService.java | 2 +- .../close/strategy/AliPayCloseStrategy.java | 2 +- .../close/strategy/CashPayCloseStrategy.java | 2 +- .../close/strategy/UnionPayCloseStrategy.java | 2 +- .../strategy/VoucherPayCloseStrategy.java | 2 +- .../strategy/WalletPayCloseStrategy.java | 2 +- .../strategy/WeChatPayCloseStrategy.java | 2 +- .../core/payment/pay/service/PayService.java | 2 +- .../payment/pay/strategy/AliPayStrategy.java | 2 +- .../payment/pay/strategy/CashPayStrategy.java | 2 +- .../pay/strategy/UnionPayStrategy.java | 2 +- .../pay/strategy/VoucherPayStrategy.java | 2 +- .../pay/strategy/WalletPayStrategy.java | 2 +- .../pay/strategy/WeChatPayStrategy.java | 2 +- .../factory/PayReconcileStrategyFactory.java | 2 +- .../strategy/AlipayReconcileStrategy.java | 2 +- .../strategy/WechatPayReconcileStrategy.java | 2 +- .../refund/service/PayRefundService.java | 2 +- .../refund/strategy/AliPayRefundStrategy.java | 2 +- .../strategy/CashPayRefundStrategy.java | 2 +- .../strategy/UnionPayRefundStrategy.java | 2 +- .../strategy/VoucherPayRefundStrategy.java | 2 +- .../strategy/WalletPayRefundStrategy.java | 2 +- .../strategy/WeChatPayRefundStrategy.java | 2 +- .../factory/PayRepairStrategyFactory.java | 2 +- .../factory/RefundRepairStrategyFactory.java | 114 ++++++++++ .../payment/repair/param/PayRepairParam.java | 10 - ...RepairResult.java => PayRepairResult.java} | 8 +- .../repair/result/RefundRepairResult.java | 27 +++ .../repair/service/PayRepairService.java | 108 +++++----- .../repair/service/RefundRepairService.java | 203 ++++++++++++++++++ .../{ => pay}/AliPayRepairStrategy.java | 50 +++-- .../{ => pay}/CashPayRepairStrategy.java | 15 +- .../{ => pay}/UnionPayRepairStrategy.java | 12 +- .../{ => pay}/VoucherPayRepairStrategy.java | 17 +- .../{ => pay}/WalletPayRepairStrategy.java | 15 +- .../{ => pay}/WeChatPayRepairStrategy.java | 41 ++-- .../refund/AliRefundRepairStrategy.java | 29 +++ .../refund/CashRefundRepairStrategy.java | 29 +++ .../refund/UnionRefundRepairStrategy.java | 29 +++ .../refund/VoucherRefundRepairStrategy.java | 29 +++ .../refund/WalletRefundRepairStrategy.java | 24 +++ .../refund/WeChatRefundRepairStrategy.java | 29 +++ .../payment/sync/service/PaySyncService.java | 37 ++-- .../sync/strategy/AliPaySyncStrategy.java | 9 + .../sync/strategy/WeChatPaySyncStrategy.java | 9 + .../record/repair/entity/PayRepairRecord.java | 31 ++- .../service/PayRepairRecordService.java | 9 + .../dto/record/repair/PayRepairRecordDto.java | 21 +- ...Strategy.java => AbsCallbackStrategy.java} | 21 +- .../service/func/AbsPayCloseStrategy.java | 7 - .../service/func/AbsPayRepairStrategy.java | 25 ++- .../daxpay/service/func/AbsPayStrategy.java | 6 - .../service/func/AbsReconcileStrategy.java | 9 +- .../service/func/AbsRefundRepairStrategy.java | 33 +++ .../service/func/AbsRefundStrategy.java | 7 - .../daxpay/service/func/PayStrategy.java | 7 + 81 files changed, 969 insertions(+), 346 deletions(-) create mode 100644 daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/code/RefundRepairTypeEnum.java delete mode 100644 daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/callback/result/PayCallbackResult.java create mode 100644 daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/factory/RefundRepairStrategyFactory.java rename daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/result/{RepairResult.java => PayRepairResult.java} (75%) create mode 100644 daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/result/RefundRepairResult.java create mode 100644 daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/service/RefundRepairService.java rename daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/{ => pay}/AliPayRepairStrategy.java (65%) rename daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/{ => pay}/CashPayRepairStrategy.java (72%) rename daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/{ => pay}/UnionPayRepairStrategy.java (76%) rename daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/{ => pay}/VoucherPayRepairStrategy.java (72%) rename daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/{ => pay}/WalletPayRepairStrategy.java (75%) rename daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/{ => pay}/WeChatPayRepairStrategy.java (69%) create mode 100644 daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/refund/AliRefundRepairStrategy.java create mode 100644 daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/refund/CashRefundRepairStrategy.java create mode 100644 daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/refund/UnionRefundRepairStrategy.java create mode 100644 daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/refund/VoucherRefundRepairStrategy.java create mode 100644 daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/refund/WalletRefundRepairStrategy.java create mode 100644 daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/refund/WeChatRefundRepairStrategy.java rename daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/{AbsPayCallbackStrategy.java => AbsCallbackStrategy.java} (88%) diff --git a/_doc/Task.md b/_doc/Task.md index e7a9bab8..fab19eeb 100644 --- a/_doc/Task.md +++ b/_doc/Task.md @@ -83,9 +83,9 @@ - [x] 支付修复策略优化存储记录信息 - [x] 去除各通道支付记录,统一为通道支付记录 - 2024-01-26: - - [ ] 优化支付修复时的触发来源的获取 - - [ ] 调整支付修复策略, 拆分为支付和退款修复两大类 + - [x] 优化支付修复时的触发来源的获取 - [ ] 增加退款同步策略, 对退款中的状态的退款订单进行处理 + - [ ] 调整支付修复策略, 拆分为支付和退款修复两大类 - **任务池** - [ ] 微信退款状态不一致补偿 - [ ] 支付SDK编写 diff --git a/daxpay-single/daxpay-single-core/src/main/java/cn/bootx/platform/daxpay/code/PayRefundStatusEnum.java b/daxpay-single/daxpay-single-core/src/main/java/cn/bootx/platform/daxpay/code/PayRefundStatusEnum.java index 381b69b7..e4f41329 100644 --- a/daxpay-single/daxpay-single-core/src/main/java/cn/bootx/platform/daxpay/code/PayRefundStatusEnum.java +++ b/daxpay-single/daxpay-single-core/src/main/java/cn/bootx/platform/daxpay/code/PayRefundStatusEnum.java @@ -1,8 +1,12 @@ package cn.bootx.platform.daxpay.code; +import cn.bootx.platform.common.core.exception.DataNotExistException; import lombok.AllArgsConstructor; import lombok.Getter; +import java.util.Arrays; +import java.util.Objects; + /** * 退款状态枚举 * @author xxm @@ -21,7 +25,16 @@ public enum PayRefundStatusEnum { /** 编码 */ private final String code; - /** 名称 */ private final String name; + + /** + * 根据编码获取枚举 + */ + public static PayRefundStatusEnum findByCode(String code){ + return Arrays.stream(values()) + .filter(statusEnum -> Objects.equals(statusEnum.getCode(), code)) + .findFirst() + .orElseThrow(() -> new DataNotExistException("该枚举不存在")); + } } diff --git a/daxpay-single/daxpay-single-core/src/main/java/cn/bootx/platform/daxpay/code/PayStatusEnum.java b/daxpay-single/daxpay-single-core/src/main/java/cn/bootx/platform/daxpay/code/PayStatusEnum.java index 51b13ac7..11b406a4 100644 --- a/daxpay-single/daxpay-single-core/src/main/java/cn/bootx/platform/daxpay/code/PayStatusEnum.java +++ b/daxpay-single/daxpay-single-core/src/main/java/cn/bootx/platform/daxpay/code/PayStatusEnum.java @@ -33,7 +33,7 @@ public enum PayStatusEnum { * 根据编码获取枚举 */ public static PayStatusEnum findByCode(String code){ - return Arrays.stream(PayStatusEnum.values()) + return Arrays.stream(values()) .filter(payStatusEnum -> Objects.equals(payStatusEnum.getCode(), code)) .findFirst() .orElseThrow(() -> new DataNotExistException("该枚举不存在")); diff --git a/daxpay-single/daxpay-single-core/src/main/java/cn/bootx/platform/daxpay/util/PayUtil.java b/daxpay-single/daxpay-single-core/src/main/java/cn/bootx/platform/daxpay/util/PayUtil.java index 5aa4cee9..8ee56ff3 100644 --- a/daxpay-single/daxpay-single-core/src/main/java/cn/bootx/platform/daxpay/util/PayUtil.java +++ b/daxpay-single/daxpay-single-core/src/main/java/cn/bootx/platform/daxpay/util/PayUtil.java @@ -74,16 +74,6 @@ public class PayUtil { return LocalDateTimeUtil.format(dateTime, DatePattern.PURE_DATETIME_PATTERN); } - /** - * 过滤出需要的可退款数据 - */ - public RefundableInfo refundableInfoFilter(List refundableInfos, PayChannelEnum payChannelEnum){ - return refundableInfos.stream() - .filter(o -> Objects.equals(o.getChannel(), payChannelEnum.getCode())) - .findFirst() - .orElseThrow(() -> new PayFailureException("退款数据不存在")); - } - /** * 获取支付单的超时时间 */ diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/code/AliPayCode.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/code/AliPayCode.java index d1e27941..20bdbfad 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/code/AliPayCode.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/code/AliPayCode.java @@ -50,7 +50,6 @@ public interface AliPayCode { /** 交易付款时间 yyyy-MM-dd HH:mm:ss */ String GMT_PAYMENT = "gmt_payment"; - /** 退款业务号 */ String OUT_BIZ_NO = "out_biz_no"; diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/code/PayRepairTypeEnum.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/code/PayRepairTypeEnum.java index 199af3e3..0723e6c3 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/code/PayRepairTypeEnum.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/code/PayRepairTypeEnum.java @@ -16,8 +16,7 @@ public enum PayRepairTypeEnum { CLOSE_LOCAL("close_local","关闭本地支付"), WAIT_PAY("wait_pay","待支付"), /** 同时也会关闭本地支付 */ - CLOSE_GATEWAY("close_gateway","关闭网关支付"), - REFUND("refund","退款"); + CLOSE_GATEWAY("close_gateway","关闭网关支付"); private final String code; private final String name; diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/code/RefundRepairTypeEnum.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/code/RefundRepairTypeEnum.java new file mode 100644 index 00000000..6ee892e7 --- /dev/null +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/code/RefundRepairTypeEnum.java @@ -0,0 +1,20 @@ +package cn.bootx.platform.daxpay.service.code; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 退款修复类型枚举 + * @author xxm + * @since 2024/1/26 + */ +@Getter +@AllArgsConstructor +public enum RefundRepairTypeEnum { + + SUCCESS("success","退款成功"), + FAIL("fail","退款失败"); + + private final String code; + private final String name; +} diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/common/context/CallbackLocal.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/common/context/CallbackLocal.java index dc612391..dc7da569 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/common/context/CallbackLocal.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/common/context/CallbackLocal.java @@ -1,5 +1,7 @@ package cn.bootx.platform.daxpay.service.common.context; +import cn.bootx.platform.daxpay.code.PayRefundStatusEnum; +import cn.bootx.platform.daxpay.code.PayStatusEnum; import cn.bootx.platform.daxpay.service.code.PayCallbackStatusEnum; import lombok.Data; import lombok.experimental.Accessors; @@ -25,12 +27,15 @@ public class CallbackLocal { /** * 第三方支付平台订单号 - * 1. 如付款码支付直接成功时会出现 */ private String gatewayOrderNo; - /** 网关状态 */ - private String gatewayPayStatus; + /** + * 网关返回状态 + * @see PayStatusEnum 支付状态 + * @see PayRefundStatusEnum 退款状态 + */ + private String gatewayStatus; /** 金额(元) */ private String amount; diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/common/context/PaymentContext.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/common/context/PaymentContext.java index 74d2a004..63f67e81 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/common/context/PaymentContext.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/common/context/PaymentContext.java @@ -36,7 +36,7 @@ public class PaymentContext { /** 支付同步相关信息 */ private final PaySyncLocal paySyncInfo = new PaySyncLocal(); - /** 支付修复相关 */ + /** 修复相关信息 */ private final RepairLocal repairInfo = new RepairLocal(); /** 对账相关信息 */ diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/common/context/RepairLocal.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/common/context/RepairLocal.java index e861cc1e..17e9cf71 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/common/context/RepairLocal.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/common/context/RepairLocal.java @@ -1,11 +1,12 @@ package cn.bootx.platform.daxpay.service.common.context; -import cn.bootx.platform.daxpay.service.code.PayRepairSourceEnum; import lombok.Data; import lombok.experimental.Accessors; +import java.time.LocalDateTime; + /** - * 支付修复上下文 + * 修复相关信息 * @author xxm * @since 2024/1/25 */ @@ -14,6 +15,9 @@ import lombok.experimental.Accessors; public class RepairLocal { /** 触发来源 */ - private PayRepairSourceEnum source; + private String source; + + /** 支付完成/退款时间 */ + private LocalDateTime finishTime; } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/alipay/service/AliPayCallbackService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/alipay/service/AliPayCallbackService.java index 7b3b14aa..775d0309 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/alipay/service/AliPayCallbackService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/alipay/service/AliPayCallbackService.java @@ -3,11 +3,12 @@ package cn.bootx.platform.daxpay.service.core.channel.alipay.service; import cn.bootx.platform.common.core.util.CertUtil; import cn.bootx.platform.common.core.util.LocalDateTimeUtil; import cn.bootx.platform.daxpay.code.PayChannelEnum; +import cn.bootx.platform.daxpay.code.PayStatusEnum; import cn.bootx.platform.daxpay.service.code.PayCallbackTypeEnum; import cn.bootx.platform.daxpay.service.common.context.CallbackLocal; import cn.bootx.platform.daxpay.service.common.local.PaymentContextLocal; import cn.bootx.platform.daxpay.service.core.channel.alipay.entity.AliPayConfig; -import cn.bootx.platform.daxpay.service.func.AbsPayCallbackStrategy; +import cn.bootx.platform.daxpay.service.func.AbsCallbackStrategy; import cn.hutool.core.date.DatePattern; import cn.hutool.core.util.CharsetUtil; import cn.hutool.core.util.StrUtil; @@ -34,23 +35,20 @@ import static cn.bootx.platform.daxpay.service.code.AliPayCode.*; */ @Slf4j @Service -public class AliPayCallbackService extends AbsPayCallbackStrategy { +public class AliPayCallbackService extends AbsCallbackStrategy { @Resource private AliPayConfigService aliasConfigService; /** - * 获取支付通道 + * 策略标识 */ @Override - public PayChannelEnum getPayChannel() { + public PayChannelEnum getChannel() { return PayChannelEnum.ALI; } - /** - * 获取交易状态 - */ /** * 验证信息格式是否合法 */ @@ -93,10 +91,11 @@ public class AliPayCallbackService extends AbsPayCallbackStrategy { callback.setGatewayOrderNo(callbackParam.get(TRADE_NO)); // 支付订单ID callback.setOrderId(Long.valueOf(callbackParam.get(OUT_TRADE_NO))); - // 交易状态 - callback.setGatewayPayStatus(callbackParam.get(TRADE_STATUS)); + // 支付状态 + PayStatusEnum payStatus = Objects.equals(callbackParam.get(TRADE_STATUS), NOTIFY_TRADE_SUCCESS) ? PayStatusEnum.SUCCESS : PayStatusEnum.FAIL; + callback.setGatewayStatus(payStatus.getCode()); // 支付金额 - callback.setGatewayPayStatus(callbackParam.get(TOTAL_AMOUNT)); + callback.setAmount(callbackParam.get(TOTAL_AMOUNT)); // 支付时间 String gmpTime = callbackParam.get(GMT_PAYMENT); @@ -119,10 +118,10 @@ public class AliPayCallbackService extends AbsPayCallbackStrategy { callback.setGatewayOrderNo(callbackParam.get(OUT_BIZ_NO)); // 退款订单Id callback.setOrderId(Long.valueOf(callbackParam.get(OUT_TRADE_NO))); - // 交易状态 - callback.setGatewayPayStatus(callbackParam.get(TRADE_STATUS)); + // 退款状态 + callback.setGatewayStatus(callbackParam.get(TRADE_STATUS)); // 退款金额 - callback.setGatewayPayStatus(callbackParam.get(REFUND_FEE)); + callback.setAmount(callbackParam.get(REFUND_FEE)); // 退款时间 String gmpTime = callbackParam.get(GMT_REFUND); @@ -159,5 +158,4 @@ public class AliPayCallbackService extends AbsPayCallbackStrategy { public String getReturnMsg() { return "success"; } - } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/voucher/dao/VoucherPayOrderMapper.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/voucher/dao/VoucherPayOrderMapper.java index a3362b33..9fbb6968 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/voucher/dao/VoucherPayOrderMapper.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/voucher/dao/VoucherPayOrderMapper.java @@ -8,6 +8,7 @@ import org.apache.ibatis.annotations.Mapper; * @author xxm * @since 2022/3/14 */ +@Deprecated @Mapper public interface VoucherPayOrderMapper extends BaseMapper { diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/voucher/dao/VoucherPaymentManager.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/voucher/dao/VoucherPaymentManager.java index f2d26da8..e60bfa72 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/voucher/dao/VoucherPaymentManager.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/voucher/dao/VoucherPaymentManager.java @@ -12,6 +12,7 @@ import java.util.Optional; * @author xxm * @since 2022/3/14 */ +@Deprecated @Slf4j @Repository @RequiredArgsConstructor diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/voucher/entity/VoucherPayOrder.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/voucher/entity/VoucherPayOrder.java index 1275ed84..5a23f26c 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/voucher/entity/VoucherPayOrder.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/voucher/entity/VoucherPayOrder.java @@ -23,6 +23,7 @@ import lombok.experimental.Accessors; */ @EqualsAndHashCode(callSuper = true) @Data +@Deprecated @DbTable(comment = "储值卡支付记录") @Accessors(chain = true) @TableName(value = "pay_voucher_pay_order",autoResultMap = true) diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/voucher/service/VoucherPayOrderService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/voucher/service/VoucherPayOrderService.java index 4a0ef980..282bc611 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/voucher/service/VoucherPayOrderService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/voucher/service/VoucherPayOrderService.java @@ -23,6 +23,7 @@ import java.util.Optional; */ @Slf4j @Service +@Deprecated @RequiredArgsConstructor public class VoucherPayOrderService { diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wallet/dao/WalletPaymentManager.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wallet/dao/WalletPaymentManager.java index 544a689a..64632510 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wallet/dao/WalletPaymentManager.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wallet/dao/WalletPaymentManager.java @@ -10,6 +10,7 @@ import java.util.Optional; @Repository @RequiredArgsConstructor +@Deprecated public class WalletPaymentManager extends BaseManager { public Optional findByPaymentId(Long paymentId) { diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wallet/dao/WalletPaymentMapper.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wallet/dao/WalletPaymentMapper.java index 5a5a3d58..010558af 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wallet/dao/WalletPaymentMapper.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wallet/dao/WalletPaymentMapper.java @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Mapper; @Mapper +@Deprecated public interface WalletPaymentMapper extends BaseMapper { } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wallet/entity/WalletPayOrder.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wallet/entity/WalletPayOrder.java index 0cdbcc4b..1f9f72bc 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wallet/entity/WalletPayOrder.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wallet/entity/WalletPayOrder.java @@ -16,6 +16,7 @@ import lombok.experimental.Accessors; * @author xxm * @since 2020/12/8 */ +@Deprecated @EqualsAndHashCode(callSuper = true) @Data @DbTable(comment = "钱包交易记录") diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wallet/service/WalletPayOrderService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wallet/service/WalletPayOrderService.java index c4c7f7c5..1bb56676 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wallet/service/WalletPayOrderService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wallet/service/WalletPayOrderService.java @@ -21,6 +21,7 @@ import java.util.Optional; * @author xxm * @since 2020/12/8 */ +@Deprecated @Slf4j @Service @RequiredArgsConstructor diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wechat/service/WeChatPayCallbackService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wechat/service/WeChatPayCallbackService.java index 218957ba..5de2dda3 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wechat/service/WeChatPayCallbackService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wechat/service/WeChatPayCallbackService.java @@ -2,11 +2,12 @@ package cn.bootx.platform.daxpay.service.core.channel.wechat.service; import cn.bootx.platform.common.core.util.LocalDateTimeUtil; import cn.bootx.platform.daxpay.code.PayChannelEnum; +import cn.bootx.platform.daxpay.code.PayStatusEnum; import cn.bootx.platform.daxpay.service.code.PayCallbackTypeEnum; import cn.bootx.platform.daxpay.service.common.context.CallbackLocal; import cn.bootx.platform.daxpay.service.common.local.PaymentContextLocal; import cn.bootx.platform.daxpay.service.core.channel.wechat.entity.WeChatPayConfig; -import cn.bootx.platform.daxpay.service.func.AbsPayCallbackStrategy; +import cn.bootx.platform.daxpay.service.func.AbsCallbackStrategy; import cn.hutool.core.date.DatePattern; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONUtil; @@ -32,16 +33,17 @@ import static cn.bootx.platform.daxpay.service.code.WeChatPayCode.*; */ @Slf4j @Service -public class WeChatPayCallbackService extends AbsPayCallbackStrategy { +public class WeChatPayCallbackService extends AbsCallbackStrategy { @Resource private WeChatPayConfigService weChatPayConfigService; + /** - * 支付通道 + * 策略标识 */ @Override - public PayChannelEnum getPayChannel() { - return PayChannelEnum.WECHAT; + public PayChannelEnum getChannel() { + return PayChannelEnum.ALI; } /** @@ -85,10 +87,11 @@ public class WeChatPayCallbackService extends AbsPayCallbackStrategy { callbackInfo.setGatewayOrderNo(callbackParam.get(TRANSACTION_ID)); // 支付订单ID callbackInfo.setOrderId(Long.valueOf(callbackParam.get(OUT_TRADE_NO))); - // 交易状态 - callbackInfo.setGatewayPayStatus(callbackParam.get(RESULT_CODE)); + // 支付状态 + PayStatusEnum payStatus = WxPayKit.codeIsOk(callbackParam.get(RESULT_CODE)) ? PayStatusEnum.SUCCESS : PayStatusEnum.FAIL; + callbackInfo.setGatewayStatus(payStatus.getCode()); // 支付金额 - callbackInfo.setGatewayPayStatus(callbackParam.get(TOTAL_FEE)); + callbackInfo.setAmount(callbackParam.get(TOTAL_FEE)); String timeEnd = callbackParam.get(TIME_END); if (StrUtil.isNotBlank(timeEnd)) { LocalDateTime time = LocalDateTimeUtil.parse(timeEnd, DatePattern.PURE_DATETIME_PATTERN); @@ -119,9 +122,9 @@ public class WeChatPayCallbackService extends AbsPayCallbackStrategy { // 退款订单Id callbackInfo.setOrderId(Long.valueOf(callbackParam.get(OUT_REFUND_NO))); // 交易状态 - callbackInfo.setGatewayPayStatus(callbackParam.get(REFUND_STATUS)); + callbackInfo.setGatewayStatus(callbackParam.get(REFUND_STATUS)); // 退款金额 - callbackInfo.setGatewayPayStatus(callbackParam.get(REFUND_FEE)); + callbackInfo.setAmount(callbackParam.get(REFUND_FEE)); // 退款时间 String timeEnd = callbackParam.get(SUCCESS_TIME); diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/order/pay/entity/PayOrder.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/order/pay/entity/PayOrder.java index ba573333..b075307f 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/order/pay/entity/PayOrder.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/order/pay/entity/PayOrder.java @@ -1,28 +1,21 @@ package cn.bootx.platform.daxpay.service.core.order.pay.entity; -import cn.bootx.platform.common.core.annotation.BigField; import cn.bootx.platform.common.core.function.EntityBaseFunction; import cn.bootx.platform.common.mybatisplus.base.MpBaseEntity; import cn.bootx.platform.daxpay.code.PayChannelEnum; import cn.bootx.platform.daxpay.code.PayStatusEnum; -import cn.bootx.platform.daxpay.entity.RefundableInfo; -import cn.bootx.platform.daxpay.service.common.typehandler.RefundableInfoTypeHandler; import cn.bootx.platform.daxpay.service.core.order.pay.convert.PayOrderConvert; import cn.bootx.platform.daxpay.service.dto.order.pay.PayOrderDto; import cn.bootx.table.modify.annotation.DbColumn; import cn.bootx.table.modify.annotation.DbTable; -import cn.bootx.table.modify.mysql.annotation.DbMySqlFieldType; import cn.bootx.table.modify.mysql.annotation.DbMySqlIndex; -import cn.bootx.table.modify.mysql.constants.MySqlFieldTypeEnum; import cn.bootx.table.modify.mysql.constants.MySqlIndexType; -import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; import java.time.LocalDateTime; -import java.util.List; /** * 支付订单 @@ -74,17 +67,6 @@ public class PayOrder extends MpBaseEntity implements EntityBaseFunction refundableInfos; - /** * 支付状态 * @see PayStatusEnum diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/callback/result/PayCallbackResult.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/callback/result/PayCallbackResult.java deleted file mode 100644 index 3b7b7f3e..00000000 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/callback/result/PayCallbackResult.java +++ /dev/null @@ -1,28 +0,0 @@ -package cn.bootx.platform.daxpay.service.core.payment.callback.result; - -import cn.bootx.platform.daxpay.service.code.PayCallbackStatusEnum; -import lombok.Data; -import lombok.experimental.Accessors; - -/** - * 支付回调处理结果 - * - * @author xxm - * @since 2021/6/22 - */ -@Deprecated -@Data -@Accessors(chain = true) -public class PayCallbackResult { - - /** - * 处理状态 - * @see PayCallbackStatusEnum - */ - private String status; - - - /** 提示信息 */ - private String msg; - -} diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/callback/service/PayCallbackService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/callback/service/PayCallbackService.java index c640954c..47c9e6fe 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/callback/service/PayCallbackService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/callback/service/PayCallbackService.java @@ -8,7 +8,6 @@ import cn.bootx.platform.daxpay.service.common.context.CallbackLocal; import cn.bootx.platform.daxpay.service.common.local.PaymentContextLocal; import cn.bootx.platform.daxpay.service.core.order.pay.entity.PayOrder; import cn.bootx.platform.daxpay.service.core.order.pay.service.PayOrderQueryService; -import cn.bootx.platform.daxpay.service.core.payment.repair.param.PayRepairParam; import cn.bootx.platform.daxpay.service.core.payment.repair.service.PayRepairService; import com.baomidou.lock.LockInfo; import com.baomidou.lock.LockTemplate; @@ -42,7 +41,7 @@ public class PayCallbackService { public void payCallback() { CallbackLocal callbackInfo = PaymentContextLocal.get().getCallbackInfo(); // 加锁 - LockInfo lock = lockTemplate.lock("payment:callback:" + callbackInfo.getOrderId()); + LockInfo lock = lockTemplate.lock("callback:payment:" + callbackInfo.getOrderId()); if (Objects.isNull(lock)){ callbackInfo.setCallbackStatus(PayCallbackStatusEnum.IGNORE).setMsg("回调正在处理中,忽略本次回调请求"); log.warn("订单号: {} 回调正在处理中,忽略本次回调请求", callbackInfo.getOrderId()); @@ -53,22 +52,22 @@ public class PayCallbackService { PayOrder payOrder = payOrderQueryService.findById(callbackInfo.getOrderId()).orElse(null); // 支付单不存在,记录回调记录, TODO 取消支付网关的订单支付情况 if (Objects.isNull(payOrder)) { - callbackInfo.setCallbackStatus(PayCallbackStatusEnum.NOT_FOUND).setMsg("支付单不存在,记录回调记录"); + callbackInfo.setCallbackStatus(PayCallbackStatusEnum.NOT_FOUND) + .setMsg("支付单不存在,记录回调记录"); return; } // 成功状态 - if (Objects.equals(PayCallbackStatusEnum.SUCCESS.getCode(), callbackInfo.getGatewayPayStatus())) { + if (Objects.equals(PayCallbackStatusEnum.SUCCESS.getCode(), callbackInfo.getGatewayStatus())) { // 回调时间超出了支付单超时时间, 记录一下, 不做处理 TODO 这块应该把订单给当成正常结束给处理了, if (Objects.nonNull(payOrder.getExpiredTime()) && LocalDateTimeUtil.ge(LocalDateTime.now(), payOrder.getExpiredTime())) { callbackInfo.setCallbackStatus(PayCallbackStatusEnum.EXCEPTION).setMsg("回调时间超出了支付单支付有效时间"); return; } - // 成功处理 + // 支付成功处理 this.success(payOrder); - } - else { + } else { // 失败状态 this.fail(payOrder); } @@ -95,8 +94,7 @@ public class PayCallbackService { return; } // 执行支付完成修复逻辑 - PayRepairParam payRepairParam = new PayRepairParam().setRepairType(PayRepairTypeEnum.SUCCESS); - payRepairService.repair(payOrder, payRepairParam); + payRepairService.repair(payOrder, PayRepairTypeEnum.SUCCESS); } /** @@ -118,8 +116,7 @@ public class PayCallbackService { } // 执行支付关闭修复逻辑 - PayRepairParam payRepairParam = new PayRepairParam().setRepairType(PayRepairTypeEnum.CLOSE_LOCAL); - payRepairService.repair(payOrder, payRepairParam); + payRepairService.repair(payOrder, PayRepairTypeEnum.CLOSE_LOCAL); } } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/callback/service/PayRefundCallbackService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/callback/service/PayRefundCallbackService.java index 59e00ff8..dff8ebaf 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/callback/service/PayRefundCallbackService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/callback/service/PayRefundCallbackService.java @@ -1,9 +1,13 @@ package cn.bootx.platform.daxpay.service.core.payment.callback.service; +import cn.bootx.platform.daxpay.code.PayRefundStatusEnum; import cn.bootx.platform.daxpay.service.code.PayCallbackStatusEnum; +import cn.bootx.platform.daxpay.service.code.RefundRepairTypeEnum; import cn.bootx.platform.daxpay.service.common.context.CallbackLocal; import cn.bootx.platform.daxpay.service.common.local.PaymentContextLocal; -import cn.bootx.platform.daxpay.service.core.order.pay.service.PayOrderQueryService; +import cn.bootx.platform.daxpay.service.core.order.refund.dao.PayRefundOrderManager; +import cn.bootx.platform.daxpay.service.core.order.refund.entity.PayRefundOrder; +import cn.bootx.platform.daxpay.service.core.payment.repair.service.RefundRepairService; import com.baomidou.lock.LockInfo; import com.baomidou.lock.LockTemplate; import lombok.RequiredArgsConstructor; @@ -21,8 +25,9 @@ import java.util.Objects; @Service @RequiredArgsConstructor public class PayRefundCallbackService { + private final PayRefundOrderManager refundOrderManager; - private final PayOrderQueryService payOrderQueryService; + private final RefundRepairService reflectionService; private final LockTemplate lockTemplate; @@ -33,17 +38,49 @@ public class PayRefundCallbackService { CallbackLocal callbackInfo = PaymentContextLocal.get().getCallbackInfo(); // 加锁 - LockInfo lock = lockTemplate.lock("payment:callback:" + callbackInfo.getOrderId()); + LockInfo lock = lockTemplate.lock("callback:refund:" + callbackInfo.getOrderId()); if (Objects.isNull(lock)){ callbackInfo.setCallbackStatus(PayCallbackStatusEnum.IGNORE).setMsg("回调正在处理中,忽略本次回调请求"); log.warn("订单号: {} 回调正在处理中,忽略本次回调请求", callbackInfo.getOrderId()); return; } - try { + // 获取退款单 + PayRefundOrder refundOrder = refundOrderManager.findById(callbackInfo.getPayRepairOrderId()).orElse(null); + // 退款单不存在,记录回调记录 + if (Objects.isNull(refundOrder)) { + callbackInfo.setCallbackStatus(PayCallbackStatusEnum.NOT_FOUND).setMsg("退款单不存在,记录回调记录"); + return; + } + + // 退款成功还是失败 + if (Objects.equals(PayRefundStatusEnum.SUCCESS.getCode(), callbackInfo.getGatewayStatus())) { + reflectionService.repair(refundOrder, RefundRepairTypeEnum.SUCCESS); + } else { + reflectionService.repair(refundOrder, RefundRepairTypeEnum.FAIL); + } } finally { lockTemplate.releaseLock(lock); } } + + /** + * 成功处理 + */ + private void success(PayRefundOrder refundOrder) { + // 支付退款订单修复 + + // 支付退款订单成功修复 + } + + /** + * 失败处理 + */ + private void fail(PayRefundOrder refundOrder) { + // 退款订单失败修复 + + // 支付订单退款失败修复 + + } } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/close/service/PayCloseService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/close/service/PayCloseService.java index e20be013..6ebaca5e 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/close/service/PayCloseService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/close/service/PayCloseService.java @@ -97,7 +97,7 @@ public class PayCloseService { // 2.初始化关闭支付的参数 for (AbsPayCloseStrategy strategy : payCloseStrategies) { - strategy.initCloseParam(payOrder, orderChannelMap.get(strategy.getType().getCode())); + strategy.initCloseParam(payOrder, orderChannelMap.get(strategy.getChannel().getCode())); } // 3.关闭前准备 diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/close/strategy/AliPayCloseStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/close/strategy/AliPayCloseStrategy.java index 47f33c95..71d2ffe8 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/close/strategy/AliPayCloseStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/close/strategy/AliPayCloseStrategy.java @@ -28,7 +28,7 @@ public class AliPayCloseStrategy extends AbsPayCloseStrategy { private final AliPayCloseService aliPayCloseService; @Override - public PayChannelEnum getType() { + public PayChannelEnum getChannel() { return PayChannelEnum.ALI; } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/close/strategy/CashPayCloseStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/close/strategy/CashPayCloseStrategy.java index 562168c9..55848fae 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/close/strategy/CashPayCloseStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/close/strategy/CashPayCloseStrategy.java @@ -23,7 +23,7 @@ public class CashPayCloseStrategy extends AbsPayCloseStrategy { private final CashService cashService; @Override - public PayChannelEnum getType() { + public PayChannelEnum getChannel() { return PayChannelEnum.CASH; } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/close/strategy/UnionPayCloseStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/close/strategy/UnionPayCloseStrategy.java index c46a0a72..02ec2e03 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/close/strategy/UnionPayCloseStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/close/strategy/UnionPayCloseStrategy.java @@ -22,7 +22,7 @@ public class UnionPayCloseStrategy extends AbsPayCloseStrategy { @Override - public PayChannelEnum getType() { + public PayChannelEnum getChannel() { return PayChannelEnum.UNION_PAY; } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/close/strategy/VoucherPayCloseStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/close/strategy/VoucherPayCloseStrategy.java index 7470ed6d..71194467 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/close/strategy/VoucherPayCloseStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/close/strategy/VoucherPayCloseStrategy.java @@ -26,7 +26,7 @@ public class VoucherPayCloseStrategy extends AbsPayCloseStrategy { private final VoucherPayOrderService voucherPayOrderService; @Override - public PayChannelEnum getType() { + public PayChannelEnum getChannel() { return PayChannelEnum.VOUCHER; } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/close/strategy/WalletPayCloseStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/close/strategy/WalletPayCloseStrategy.java index 24bcf558..745f1315 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/close/strategy/WalletPayCloseStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/close/strategy/WalletPayCloseStrategy.java @@ -25,7 +25,7 @@ public class WalletPayCloseStrategy extends AbsPayCloseStrategy { private final WalletPayOrderService walletPayOrderService; @Override - public PayChannelEnum getType() { + public PayChannelEnum getChannel() { return PayChannelEnum.WALLET; } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/close/strategy/WeChatPayCloseStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/close/strategy/WeChatPayCloseStrategy.java index 85e516c4..8e685709 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/close/strategy/WeChatPayCloseStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/close/strategy/WeChatPayCloseStrategy.java @@ -29,7 +29,7 @@ public class WeChatPayCloseStrategy extends AbsPayCloseStrategy { private WeChatPayConfig weChatPayConfig; @Override - public PayChannelEnum getType() { + public PayChannelEnum getChannel() { return PayChannelEnum.WECHAT; } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/pay/service/PayService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/pay/service/PayService.java index f7de959e..1866c6ef 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/pay/service/PayService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/pay/service/PayService.java @@ -175,7 +175,7 @@ public class PayService { } // 5.2 如果异步支付完成, 进行订单完成处理 AsyncPayLocal asyncPayInfo = PaymentContextLocal.get().getAsyncPayInfo(); - if (payOrder.isAsyncPay()) { + if (asyncPayInfo.isPayComplete()) { payOrder.setGatewayOrderNo(asyncPayInfo.getGatewayOrderNo()) .setStatus(SUCCESS.getCode()) .setPayTime(LocalDateTime.now()); diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/pay/strategy/AliPayStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/pay/strategy/AliPayStrategy.java index 1ab59ae2..7a42ef95 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/pay/strategy/AliPayStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/pay/strategy/AliPayStrategy.java @@ -41,7 +41,7 @@ public class AliPayStrategy extends AbsPayStrategy { private AliPayParam aliPayParam; @Override - public PayChannelEnum getType() { + public PayChannelEnum getChannel() { return PayChannelEnum.ALI; } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/pay/strategy/CashPayStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/pay/strategy/CashPayStrategy.java index 5cd20d28..f30a5b7f 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/pay/strategy/CashPayStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/pay/strategy/CashPayStrategy.java @@ -30,7 +30,7 @@ public class CashPayStrategy extends AbsPayStrategy { * 现金支付 */ @Override - public PayChannelEnum getType() { + public PayChannelEnum getChannel() { return PayChannelEnum.CASH; } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/pay/strategy/UnionPayStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/pay/strategy/UnionPayStrategy.java index 8c3e8e42..a4080c95 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/pay/strategy/UnionPayStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/pay/strategy/UnionPayStrategy.java @@ -22,7 +22,7 @@ import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROT public class UnionPayStrategy extends AbsPayStrategy { @Override - public PayChannelEnum getType() { + public PayChannelEnum getChannel() { return PayChannelEnum.UNION_PAY; } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/pay/strategy/VoucherPayStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/pay/strategy/VoucherPayStrategy.java index cb911d7a..452db6bb 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/pay/strategy/VoucherPayStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/pay/strategy/VoucherPayStrategy.java @@ -33,7 +33,7 @@ public class VoucherPayStrategy extends AbsPayStrategy { private Voucher voucher; @Override - public PayChannelEnum getType() { + public PayChannelEnum getChannel() { return PayChannelEnum.VOUCHER; } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/pay/strategy/WalletPayStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/pay/strategy/WalletPayStrategy.java index 821ad500..4f6874bc 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/pay/strategy/WalletPayStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/pay/strategy/WalletPayStrategy.java @@ -42,7 +42,7 @@ public class WalletPayStrategy extends AbsPayStrategy { private Wallet wallet; @Override - public PayChannelEnum getType() { + public PayChannelEnum getChannel() { return PayChannelEnum.WALLET; } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/pay/strategy/WeChatPayStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/pay/strategy/WeChatPayStrategy.java index 3a2c8b8b..5be68366 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/pay/strategy/WeChatPayStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/pay/strategy/WeChatPayStrategy.java @@ -44,7 +44,7 @@ public class WeChatPayStrategy extends AbsPayStrategy { * 类型 */ @Override - public PayChannelEnum getType() { + public PayChannelEnum getChannel() { return PayChannelEnum.WECHAT; } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/reconcile/factory/PayReconcileStrategyFactory.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/reconcile/factory/PayReconcileStrategyFactory.java index 17e769c6..d4e839c4 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/reconcile/factory/PayReconcileStrategyFactory.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/reconcile/factory/PayReconcileStrategyFactory.java @@ -34,7 +34,7 @@ public class PayReconcileStrategyFactory { PayChannelEnum channelEnum = PayChannelEnum.findByCode(channel); Map beansOfType = SpringUtil.getBeansOfType(AbsReconcileStrategy.class); return beansOfType.values().stream() - .filter(strategy -> Objects.equals(strategy.getType(), channelEnum)) + .filter(strategy -> Objects.equals(strategy.getChannel(), channelEnum)) .findFirst() .orElseThrow(PayUnsupportedMethodException::new); } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/reconcile/strategy/AlipayReconcileStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/reconcile/strategy/AlipayReconcileStrategy.java index 3bde33e3..3a7df688 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/reconcile/strategy/AlipayReconcileStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/reconcile/strategy/AlipayReconcileStrategy.java @@ -38,7 +38,7 @@ public class AlipayReconcileStrategy extends AbsReconcileStrategy { * @see PayChannelEnum */ @Override - public PayChannelEnum getType() { + public PayChannelEnum getChannel() { return PayChannelEnum.ALI; } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/reconcile/strategy/WechatPayReconcileStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/reconcile/strategy/WechatPayReconcileStrategy.java index d591f389..29730427 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/reconcile/strategy/WechatPayReconcileStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/reconcile/strategy/WechatPayReconcileStrategy.java @@ -37,7 +37,7 @@ public class WechatPayReconcileStrategy extends AbsReconcileStrategy { * @see PayChannelEnum */ @Override - public PayChannelEnum getType() { + public PayChannelEnum getChannel() { return PayChannelEnum.WECHAT; } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/refund/service/PayRefundService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/refund/service/PayRefundService.java index f93ea1a9..c2c98919 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/refund/service/PayRefundService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/refund/service/PayRefundService.java @@ -142,7 +142,7 @@ public class PayRefundService { // 2.初始化退款策略的参数 for (AbsRefundStrategy refundStrategy : payRefundStrategies) { - PayChannelOrder payChannelOrder = orderChannelMap.get(refundStrategy.getType().getCode()); + PayChannelOrder payChannelOrder = orderChannelMap.get(refundStrategy.getChannel().getCode()); if (Objects.isNull(payChannelOrder)){ throw new PayFailureException("[数据异常]进行退款的通道没有对应的支付单, 无法退款"); } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/refund/strategy/AliPayRefundStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/refund/strategy/AliPayRefundStrategy.java index 5215c30a..43a7801c 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/refund/strategy/AliPayRefundStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/refund/strategy/AliPayRefundStrategy.java @@ -33,7 +33,7 @@ public class AliPayRefundStrategy extends AbsRefundStrategy { * @see PayChannelEnum */ @Override - public PayChannelEnum getType() { + public PayChannelEnum getChannel() { return PayChannelEnum.ALI; } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/refund/strategy/CashPayRefundStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/refund/strategy/CashPayRefundStrategy.java index 066127e8..c2f7014e 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/refund/strategy/CashPayRefundStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/refund/strategy/CashPayRefundStrategy.java @@ -29,7 +29,7 @@ public class CashPayRefundStrategy extends AbsRefundStrategy { * @see PayChannelEnum */ @Override - public PayChannelEnum getType() { + public PayChannelEnum getChannel() { return PayChannelEnum.CASH; } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/refund/strategy/UnionPayRefundStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/refund/strategy/UnionPayRefundStrategy.java index f21b3788..a7838416 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/refund/strategy/UnionPayRefundStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/refund/strategy/UnionPayRefundStrategy.java @@ -23,7 +23,7 @@ public class UnionPayRefundStrategy extends AbsRefundStrategy { * @see PayChannelEnum */ @Override - public PayChannelEnum getType() { + public PayChannelEnum getChannel() { return PayChannelEnum.UNION_PAY; } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/refund/strategy/VoucherPayRefundStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/refund/strategy/VoucherPayRefundStrategy.java index d07f0e00..e4ba7812 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/refund/strategy/VoucherPayRefundStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/refund/strategy/VoucherPayRefundStrategy.java @@ -30,7 +30,7 @@ public class VoucherPayRefundStrategy extends AbsRefundStrategy { * @see PayChannelEnum */ @Override - public PayChannelEnum getType() { + public PayChannelEnum getChannel() { return PayChannelEnum.VOUCHER; } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/refund/strategy/WalletPayRefundStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/refund/strategy/WalletPayRefundStrategy.java index 34d1a6b6..15dd8ad3 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/refund/strategy/WalletPayRefundStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/refund/strategy/WalletPayRefundStrategy.java @@ -29,7 +29,7 @@ public class WalletPayRefundStrategy extends AbsRefundStrategy { * @see PayChannelEnum */ @Override - public PayChannelEnum getType() { + public PayChannelEnum getChannel() { return PayChannelEnum.WALLET; } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/refund/strategy/WeChatPayRefundStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/refund/strategy/WeChatPayRefundStrategy.java index b22186d0..c5d0b19f 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/refund/strategy/WeChatPayRefundStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/refund/strategy/WeChatPayRefundStrategy.java @@ -38,7 +38,7 @@ public class WeChatPayRefundStrategy extends AbsRefundStrategy { * @see PayChannelEnum */ @Override - public PayChannelEnum getType() { + public PayChannelEnum getChannel() { return PayChannelEnum.WECHAT; } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/factory/PayRepairStrategyFactory.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/factory/PayRepairStrategyFactory.java index c31e782b..54664bbf 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/factory/PayRepairStrategyFactory.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/factory/PayRepairStrategyFactory.java @@ -2,7 +2,7 @@ package cn.bootx.platform.daxpay.service.core.payment.repair.factory; import cn.bootx.platform.daxpay.code.PayChannelEnum; import cn.bootx.platform.daxpay.exception.pay.PayUnsupportedMethodException; -import cn.bootx.platform.daxpay.service.core.payment.repair.strategy.*; +import cn.bootx.platform.daxpay.service.core.payment.repair.strategy.pay.*; import cn.bootx.platform.daxpay.service.func.AbsPayRepairStrategy; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.extra.spring.SpringUtil; diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/factory/RefundRepairStrategyFactory.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/factory/RefundRepairStrategyFactory.java new file mode 100644 index 00000000..8e4b55a4 --- /dev/null +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/factory/RefundRepairStrategyFactory.java @@ -0,0 +1,114 @@ +package cn.bootx.platform.daxpay.service.core.payment.repair.factory; + +import cn.bootx.platform.daxpay.code.PayChannelEnum; +import cn.bootx.platform.daxpay.exception.pay.PayUnsupportedMethodException; +import cn.bootx.platform.daxpay.service.core.payment.repair.strategy.refund.*; +import cn.bootx.platform.daxpay.service.func.AbsRefundRepairStrategy; +import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.extra.spring.SpringUtil; +import lombok.experimental.UtilityClass; +import lombok.val; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +import static cn.bootx.platform.daxpay.code.PayChannelEnum.ASYNC_TYPE_CODE; + +/** + * 支付退款修复策略工厂 + * @author xxm + * @since 2024/1/26 + */ +@UtilityClass +public class RefundRepairStrategyFactory { + + /** + * 根据传入的支付通道创建策略 + * @return 支付策略 + */ + public static AbsRefundRepairStrategy create(PayChannelEnum channelEnum) { + + AbsRefundRepairStrategy strategy; + switch (channelEnum) { + case ALI: + strategy = SpringUtil.getBean(AliRefundRepairStrategy.class); + break; + case WECHAT: + strategy = SpringUtil.getBean(WeChatRefundRepairStrategy.class); + break; + case UNION_PAY: + strategy = SpringUtil.getBean(UnionRefundRepairStrategy.class); + break; + case CASH: + strategy = SpringUtil.getBean(CashRefundRepairStrategy.class); + break; + case WALLET: + strategy = SpringUtil.getBean(WalletRefundRepairStrategy.class); + break; + case VOUCHER: + strategy = SpringUtil.getBean(VoucherRefundRepairStrategy.class); + break; + default: + throw new PayUnsupportedMethodException(); + } + return strategy; + } + + /** + * 根据传入的支付类型批量创建策略, 异步支付在后面 + */ + public static List createAsyncLast(List channelCodes) { + return create(channelCodes, true); + } + + /** + * 根据传入的支付类型批量创建策略, 异步支付在前面 + */ + public static List createAsyncFront(List channelCodes) { + return create(channelCodes, false); + } + + /** + * 根据传入的支付类型批量创建策略 + * @param asyncSort 是否异步支付在后面 + * @return 支付策略 + */ + private static List create(List channelCodes, boolean asyncSort) { + if (CollectionUtil.isEmpty(channelCodes)) { + return Collections.emptyList(); + } + + // 同步支付 + val syncChannels = channelCodes.stream() + .filter(code -> !ASYNC_TYPE_CODE.contains(code)) + .map(PayChannelEnum::findByCode) + .collect(Collectors.toList()); + + // 异步支付 + val asyncChannels = channelCodes.stream() + .filter(ASYNC_TYPE_CODE::contains) + .map(PayChannelEnum::findByCode) + .collect(Collectors.toList()); + + List sortList = new ArrayList<>(channelCodes.size()); + + // 异步在后面 + if (asyncSort) { + sortList.addAll(syncChannels); + sortList.addAll(asyncChannels); + } + else { + sortList.addAll(asyncChannels); + sortList.addAll(syncChannels); + } + + // 此处有一个根据Type的反转排序, + return sortList.stream() + .filter(Objects::nonNull) + .map(RefundRepairStrategyFactory::create) + .collect(Collectors.toList()); + } +} diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/param/PayRepairParam.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/param/PayRepairParam.java index 620120f5..ee33a24f 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/param/PayRepairParam.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/param/PayRepairParam.java @@ -1,6 +1,5 @@ package cn.bootx.platform.daxpay.service.core.payment.repair.param; -import cn.bootx.platform.daxpay.service.code.PayRepairSourceEnum; import cn.bootx.platform.daxpay.service.code.PayRepairTypeEnum; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -15,15 +14,6 @@ import lombok.experimental.Accessors; @Accessors(chain = true) public class PayRepairParam { - @Schema(description = "修复来源") - @Deprecated - private PayRepairSourceEnum repairSource; - @Schema(description = "修复类型") private PayRepairTypeEnum repairType; - - @Schema(description = "金额") - private Integer amount; - - } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/result/RepairResult.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/result/PayRepairResult.java similarity index 75% rename from daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/result/RepairResult.java rename to daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/result/PayRepairResult.java index f455c344..2ccde52c 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/result/RepairResult.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/result/PayRepairResult.java @@ -5,17 +5,17 @@ import lombok.Data; import lombok.experimental.Accessors; /** - * 修复结果 + * 支付修复结果 * @author xxm * @since 2024/1/4 */ @Data @Accessors(chain = true) -public class RepairResult { +public class PayRepairResult { /** 修复记录ID */ - private Long id; + private Long repairId; /** 修复前状态 */ private PayStatusEnum beforeStatus; /** 修复后状态 */ - private PayStatusEnum repairStatus; + private PayStatusEnum afterPayStatus; } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/result/RefundRepairResult.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/result/RefundRepairResult.java new file mode 100644 index 00000000..0950b825 --- /dev/null +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/result/RefundRepairResult.java @@ -0,0 +1,27 @@ +package cn.bootx.platform.daxpay.service.core.payment.repair.result; + +import cn.bootx.platform.daxpay.code.PayRefundStatusEnum; +import cn.bootx.platform.daxpay.code.PayStatusEnum; +import lombok.Data; +import lombok.experimental.Accessors; + +/** + * 退款修复结果 + * @author xxm + * @since 2024/1/26 + */ +@Data +@Accessors(chain = true) +public class RefundRepairResult { + + /** 修复ID */ + private Long repairId; + /** 退款修复前状态 */ + private PayRefundStatusEnum beforeRefundStatus; + /** 退款修复后状态 */ + private PayRefundStatusEnum afterRefundStatus; + /** 支付修复前状态 */ + private PayStatusEnum beforePayStatus; + /** 支付修复后状态 */ + private PayStatusEnum afterPayStatus; +} diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/service/PayRepairService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/service/PayRepairService.java index 574f456e..a32d6f26 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/service/PayRepairService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/service/PayRepairService.java @@ -1,26 +1,30 @@ package cn.bootx.platform.daxpay.service.core.payment.repair.service; +import cn.bootx.platform.common.core.function.CollectorsFunction; import cn.bootx.platform.daxpay.code.PayStatusEnum; -import cn.bootx.platform.daxpay.service.code.PayRepairSourceEnum; +import cn.bootx.platform.daxpay.service.code.PayRepairTypeEnum; import cn.bootx.platform.daxpay.service.common.local.PaymentContextLocal; import cn.bootx.platform.daxpay.service.core.order.pay.dao.PayChannelOrderManager; import cn.bootx.platform.daxpay.service.core.order.pay.entity.PayChannelOrder; import cn.bootx.platform.daxpay.service.core.order.pay.entity.PayOrder; import cn.bootx.platform.daxpay.service.core.order.pay.service.PayOrderService; import cn.bootx.platform.daxpay.service.core.payment.repair.factory.PayRepairStrategyFactory; -import cn.bootx.platform.daxpay.service.core.payment.repair.param.PayRepairParam; -import cn.bootx.platform.daxpay.service.core.payment.repair.result.RepairResult; +import cn.bootx.platform.daxpay.service.core.payment.repair.result.PayRepairResult; import cn.bootx.platform.daxpay.service.core.record.repair.entity.PayRepairRecord; import cn.bootx.platform.daxpay.service.core.record.repair.service.PayRepairRecordService; import cn.bootx.platform.daxpay.service.func.AbsPayRepairStrategy; +import cn.hutool.core.util.IdUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.Optional; +import java.util.function.Function; import java.util.stream.Collectors; /** @@ -43,54 +47,57 @@ public class PayRepairService { * 修复支付单 */ @Transactional(rollbackFor = Exception.class) - public RepairResult repair(PayOrder order, PayRepairParam repairParam){ - // 获取支付单管理的通道支付订单 - List payChannelOrders = channelOrderManager.findAllByPaymentId(order.getId()); - List channels = payChannelOrders.stream() - .map(PayChannelOrder::getChannel) - .collect(Collectors.toList()); + public PayRepairResult repair(PayOrder order, PayRepairTypeEnum repairType){ + // 1. 获取支付单管理的通道支付订单 + Map channelOrderMap = channelOrderManager.findAllByPaymentId(order.getId()) + .stream() + .collect(Collectors.toMap(PayChannelOrder::getChannel, Function.identity(), CollectorsFunction::retainLatest)); + List channels = new ArrayList<>(channelOrderMap.keySet()); - // 初始化修复参数 + // 2.1 初始化修复参数 List repairStrategies = PayRepairStrategyFactory.createAsyncLast(channels); - repairStrategies.forEach(repairStrategy -> repairStrategy.initRepairParam(order)); - repairStrategies.forEach(AbsPayRepairStrategy::doBeforeHandler); - RepairResult repairResult = new RepairResult().setBeforeStatus(PayStatusEnum.findByCode(order.getStatus())); + for (AbsPayRepairStrategy repairStrategy : repairStrategies) { + repairStrategy.initRepairParam(order,channelOrderMap.get(repairStrategy.getChannel().getCode())); + } - // 根据不同的类型执行对应的修复逻辑 - switch (repairParam.getRepairType()) { + // 2.2 执行前置处理 + repairStrategies.forEach(AbsPayRepairStrategy::doBeforeHandler); + + // 3. 根据不同的类型执行对应的修复逻辑 + PayRepairResult repairResult = new PayRepairResult().setBeforeStatus(PayStatusEnum.findByCode(order.getStatus())); + switch (repairType) { case SUCCESS: this.success(order, repairStrategies); - repairResult.setRepairStatus(PayStatusEnum.SUCCESS); + repairResult.setAfterPayStatus(PayStatusEnum.SUCCESS); break; case CLOSE_LOCAL: this.closeLocal(order, repairStrategies); - repairResult.setRepairStatus(PayStatusEnum.CLOSE); + repairResult.setAfterPayStatus(PayStatusEnum.CLOSE); break; case WAIT_PAY: - this.wait(order, repairStrategies); - repairResult.setRepairStatus(PayStatusEnum.PROGRESS); + this.waitPay(order, repairStrategies); + repairResult.setAfterPayStatus(PayStatusEnum.PROGRESS); break; case CLOSE_GATEWAY: this.closeGateway(order, repairStrategies); - repairResult.setRepairStatus(PayStatusEnum.CLOSE); - break; - case REFUND: - this.refund(order, repairStrategies); -// repairResult.setRepairStatus(PayStatusEnum.REFUNDED); + repairResult.setAfterPayStatus(PayStatusEnum.CLOSE); break; default: - repairResult.setRepairStatus(repairResult.getBeforeStatus()); - break; + log.error("走到了理论上讲不会走到的分支"); } - PayRepairRecord payRepairRecord = this.saveRecord(order, repairParam, repairResult); - return repairResult.setId(payRepairRecord.getId()); + // 设置修复iD + repairResult.setRepairId(IdUtil.getSnowflakeNextId()); + this.saveRecord(order, repairType, repairResult); + return repairResult; } /** * 变更未待支付 * */ - private void wait(PayOrder order, List repairStrategies) { + private void waitPay(PayOrder order, List repairStrategies) { + + repairStrategies.forEach(AbsPayRepairStrategy::doCloseLocalHandler); // 修改订单支付状态为成功 order.setStatus(PayStatusEnum.PROGRESS.getCode()); payOrderService.updateById(order); @@ -103,10 +110,10 @@ public class PayRepairService { */ private void success(PayOrder order, List strategies) { LocalDateTime payTime = PaymentContextLocal.get() - .getReconcileInfo() - .getPayTime(); + .getRepairInfo() + .getFinishTime(); // 执行个通道的成功处理方法 - strategies.forEach(AbsPayRepairStrategy::doSuccessHandler); + strategies.forEach(AbsPayRepairStrategy::doPaySuccessHandler); // 修改订单支付状态为成功 order.setStatus(PayStatusEnum.SUCCESS.getCode()); @@ -117,8 +124,7 @@ public class PayRepairService { /** * 关闭支付 - * 同步: 执行支付单所有的支付通道关闭支付逻辑, 如果来源是网关同步, 则不需要调用网关关闭 - * 回调: 执行所有的支付通道关闭支付逻辑 + * 同步/对账: 执行支付单所有的支付通道关闭支付逻辑, 不需要调用网关关闭, */ private void closeLocal(PayOrder order, List absPayStrategies) { // 执行策略的关闭方法 @@ -128,6 +134,7 @@ public class PayRepairService { } /** * 关闭网关交易, 同时也会关闭本地支付 + * 回调: 执行所有的支付通道关闭支付逻辑 */ private void closeGateway(PayOrder payOrder, List absPayStrategies) { // 执行策略的关闭方法 @@ -136,41 +143,26 @@ public class PayRepairService { payOrderService.updateById(payOrder); } - /** - * 退款 TODO 需要调用退款同步策略进行补偿 - * 同步: - * 回调: - */ - public void refund(PayOrder payOrder, List strategies){ - // 判断修复后价格总价格是否为0 - - // 为0变更为全部退款 - - // 不为0调用退款同步接口 - - } - /** * 保存记录 */ - private PayRepairRecord saveRecord(PayOrder order, PayRepairParam repairParam, RepairResult repairResult){ + private void saveRecord(PayOrder order, PayRepairTypeEnum recordType, PayRepairResult repairResult){ // 修复后的状态 - String afterStatus = Optional.ofNullable(repairResult.getRepairStatus()).map(PayStatusEnum::getCode).orElse(null); + String afterStatus = Optional.ofNullable(repairResult.getAfterPayStatus()).map(PayStatusEnum::getCode).orElse(null); // 修复发起来源 - PayRepairSourceEnum source = PaymentContextLocal.get() + String source = PaymentContextLocal.get() .getRepairInfo() .getSource(); - PayRepairRecord payRepairRecord = new PayRepairRecord() - .setPaymentId(order.getId()) + .setRepairId(repairResult.getRepairId()) + .setOrderId(order.getId()) .setAsyncChannel(order.getAsyncChannel()) - .setBusinessNo(order.getBusinessNo()) + .setOrderNo(order.getBusinessNo()) .setBeforeStatus(repairResult.getBeforeStatus().getCode()) .setAfterStatus(afterStatus) - .setAmount(repairParam.getAmount()) - .setRepairSource(source.getCode()) - .setRepairType(repairParam.getRepairType().getCode()); + .setRepairSource(source) + .setRepairType(recordType.getCode()); + payRepairRecord.setId(repairResult.getRepairId()); recordService.saveRecord(payRepairRecord); - return payRepairRecord; } } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/service/RefundRepairService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/service/RefundRepairService.java new file mode 100644 index 00000000..3d26d874 --- /dev/null +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/service/RefundRepairService.java @@ -0,0 +1,203 @@ +package cn.bootx.platform.daxpay.service.core.payment.repair.service; + +import cn.bootx.platform.common.core.exception.DataNotExistException; +import cn.bootx.platform.daxpay.code.PayRefundStatusEnum; +import cn.bootx.platform.daxpay.code.PayStatusEnum; +import cn.bootx.platform.daxpay.service.code.RefundRepairTypeEnum; +import cn.bootx.platform.daxpay.service.common.local.PaymentContextLocal; +import cn.bootx.platform.daxpay.service.core.order.pay.dao.PayChannelOrderManager; +import cn.bootx.platform.daxpay.service.core.order.pay.dao.PayOrderManager; +import cn.bootx.platform.daxpay.service.core.order.pay.entity.PayChannelOrder; +import cn.bootx.platform.daxpay.service.core.order.pay.entity.PayOrder; +import cn.bootx.platform.daxpay.service.core.order.refund.dao.PayRefundChannelOrderManager; +import cn.bootx.platform.daxpay.service.core.order.refund.dao.PayRefundOrderManager; +import cn.bootx.platform.daxpay.service.core.order.refund.entity.PayRefundChannelOrder; +import cn.bootx.platform.daxpay.service.core.order.refund.entity.PayRefundOrder; +import cn.bootx.platform.daxpay.service.core.payment.repair.result.RefundRepairResult; +import cn.bootx.platform.daxpay.service.core.record.repair.entity.PayRepairRecord; +import cn.bootx.platform.daxpay.service.core.record.repair.service.PayRepairRecordService; +import cn.hutool.core.util.IdUtil; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Arrays; +import java.util.Objects; +import java.util.Optional; + +/** + * 退款订单修复, 只有存在异步支付的退款订单才存在修复 + * @author xxm + * @since 2024/1/26 + */ +@Slf4j +@Service +@RequiredArgsConstructor +public class RefundRepairService { + + private final PayOrderManager payOrderManager; + + private final PayChannelOrderManager payChannelOrderManager; + + private final PayRefundOrderManager refundOrderManager; + + private final PayRefundChannelOrderManager refundChannelOrderManager; + + private final PayRepairRecordService recordService; + + /** + * 修复支付单 + */ + @Transactional(rollbackFor = Exception.class) + public RefundRepairResult repair(PayRefundOrder refundOrder, RefundRepairTypeEnum repairType){ + + // 获取关联支付单 + PayOrder payOrder = payOrderManager.findById(refundOrder.getPaymentId()) + .orElseThrow(() -> new RuntimeException("支付单不存在")); + // 关联异步支付通道支付单 + PayChannelOrder payChannelOrder = payChannelOrderManager.findByPaymentIdAndChannel(payOrder.getId(), payOrder.getAsyncChannel()) + .orElseThrow(DataNotExistException::new); + // 异步通道退款单 + PayRefundChannelOrder refundChannelOrder = refundChannelOrderManager.findByPaymentIdAndChannel(refundOrder.getPaymentId(), payOrder.getAsyncChannel()) + .orElseThrow(DataNotExistException::new); + + // 根据不同的类型执行对应的修复逻辑 + RefundRepairResult repairResult = new RefundRepairResult(); + if (Objects.requireNonNull(repairType) == RefundRepairTypeEnum.SUCCESS) { + repairResult = this.success(refundOrder,payOrder,refundChannelOrder,payChannelOrder); + } else if (repairType == RefundRepairTypeEnum.FAIL) { + repairResult = this.closeLocal(refundOrder,payOrder,refundChannelOrder,payChannelOrder); + } else { + log.error("走到了理论上讲不会走到的分支"); + } + + // 设置修复ID并保存修复记录 + repairResult.setRepairId(IdUtil.getSnowflakeNextId()); + PayRepairRecord payRepairRecord = this.payRepairRecord(payOrder, repairType, repairResult); + PayRepairRecord refundRepairRecord = this.refundRepairRecord(refundOrder, repairType, repairResult); + recordService.saveAllRecord(Arrays.asList(payRepairRecord, refundRepairRecord)); + + return repairResult; + } + + /** + * 退款成功, 更新退款单和支付单 + */ + private RefundRepairResult success(PayRefundOrder refundOrder, PayOrder payOrder, PayRefundChannelOrder refundChannelOrder, PayChannelOrder payChannelOrder) { + // 更新通道支付单全部退款还是部分退款 + if (Objects.equals(payChannelOrder.getRefundableBalance(),0)){ + payChannelOrder.setStatus(PayStatusEnum.REFUNDED.getCode()); + } else { + payChannelOrder.setStatus(PayStatusEnum.PARTIAL_REFUND.getCode()); + } + + // 订单相关状态 + PayStatusEnum beforePayStatus = PayStatusEnum.findByCode(refundOrder.getStatus()); + PayStatusEnum afterPayRefundStatus; + PayRefundStatusEnum beforeRefundStatus = PayRefundStatusEnum.findByCode(refundOrder.getStatus()); + + // 判断订单全部退款还是部分退款 + if (Objects.equals(payOrder.getRefundableBalance(),0)){ + afterPayRefundStatus = PayStatusEnum.REFUNDED; + } else { + afterPayRefundStatus = PayStatusEnum.PARTIAL_REFUND; + } + // 设置退款为完成状态 + refundOrder.setStatus(PayRefundStatusEnum.SUCCESS.getCode()); + refundChannelOrder.setStatus(PayRefundStatusEnum.SUCCESS.getCode()); + + // 更新订单和退款相关订单 + payChannelOrderManager.updateById(payChannelOrder); + payOrderManager.updateById(payOrder); + refundOrderManager.updateById(refundOrder); + refundChannelOrderManager.updateById(refundChannelOrder); + return new RefundRepairResult() + .setBeforePayStatus(beforePayStatus) + .setAfterPayStatus(afterPayRefundStatus) + .setBeforeRefundStatus(beforeRefundStatus) + .setAfterRefundStatus(PayRefundStatusEnum.SUCCESS); + } + + + /** + * 退款失败, 将失败的退款金额归还回订单 + */ + private RefundRepairResult closeLocal(PayRefundOrder refundOrder, PayOrder payOrder, PayRefundChannelOrder refundChannelOrder, PayChannelOrder payChannelOrder) { + + // 更新通道支付单全部退款还是部分退款 + if (Objects.equals(payChannelOrder.getRefundableBalance(),0)){ + payChannelOrder.setStatus(PayStatusEnum.REFUNDED.getCode()); + } else { + payChannelOrder.setStatus(PayStatusEnum.PARTIAL_REFUND.getCode()); + } + + // 订单相关状态 + PayStatusEnum beforePayStatus = PayStatusEnum.findByCode(refundOrder.getStatus()); + PayStatusEnum afterPayRefundStatus; + PayRefundStatusEnum beforeRefundStatus = PayRefundStatusEnum.findByCode(refundOrder.getStatus()); + + // 判断订单是支付成功还是部分退款 + + + if (Objects.equals(payOrder.getRefundableBalance(),0)){ + afterPayRefundStatus = PayStatusEnum.REFUNDED; + } else { + afterPayRefundStatus = PayStatusEnum.PARTIAL_REFUND; + } + + // 设置退款为失败状态 + refundOrder.setStatus(PayRefundStatusEnum.FAIL.getCode()); + refundChannelOrder.setStatus(PayRefundStatusEnum.FAIL.getCode()); + + // 更新订单和退款相关订单 + payChannelOrderManager.updateById(payChannelOrder); + payOrderManager.updateById(payOrder); + refundOrderManager.updateById(refundOrder); + refundChannelOrderManager.updateById(refundChannelOrder); + return new RefundRepairResult() + .setBeforePayStatus(beforePayStatus) + .setAfterPayStatus(afterPayRefundStatus) + .setBeforeRefundStatus(beforeRefundStatus) + .setAfterRefundStatus(PayRefundStatusEnum.FAIL); + } + + /** + * 支付订单的修复记录 + */ + private PayRepairRecord payRepairRecord(PayOrder order, RefundRepairTypeEnum repairType, RefundRepairResult repairResult){ + // 修复后的状态 + String afterStatus = Optional.ofNullable(repairResult.getBeforePayStatus()).map(PayStatusEnum::getCode).orElse(null); + // 修复发起来源 + String source = PaymentContextLocal.get() + .getRepairInfo() + .getSource(); + return new PayRepairRecord() + .setOrderId(order.getId()) + .setAsyncChannel(order.getAsyncChannel()) + .setOrderNo(order.getBusinessNo()) + .setBeforeStatus(repairResult.getAfterPayStatus().getCode()) + .setAfterStatus(afterStatus) + .setRepairSource(source) + .setRepairType(repairType.getCode()); + } + + /** + * 退款订单的修复记录 + */ + private PayRepairRecord refundRepairRecord(PayRefundOrder refundOrder, RefundRepairTypeEnum repairType, RefundRepairResult repairResult){ + // 修复后的状态 + String afterStatus = Optional.ofNullable(repairResult.getAfterRefundStatus()).map(PayRefundStatusEnum::getCode).orElse(null); + // 修复发起来源 + String source = PaymentContextLocal.get() + .getRepairInfo() + .getSource(); + return new PayRepairRecord() + .setOrderId(refundOrder.getId()) + .setOrderNo(refundOrder.getRefundNo()) + .setBeforeStatus(repairResult.getBeforeRefundStatus().getCode()) + .setAfterStatus(afterStatus) + .setRepairSource(source) + .setRepairType(repairType.getCode()); + } +} diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/AliPayRepairStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/pay/AliPayRepairStrategy.java similarity index 65% rename from daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/AliPayRepairStrategy.java rename to daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/pay/AliPayRepairStrategy.java index a21078d1..1a3653f9 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/AliPayRepairStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/pay/AliPayRepairStrategy.java @@ -1,20 +1,20 @@ -package cn.bootx.platform.daxpay.service.core.payment.repair.strategy; +package cn.bootx.platform.daxpay.service.core.payment.repair.strategy.pay; import cn.bootx.platform.daxpay.code.PayChannelEnum; -import cn.bootx.platform.daxpay.exception.pay.PayFailureException; +import cn.bootx.platform.daxpay.code.PayStatusEnum; import cn.bootx.platform.daxpay.service.common.local.PaymentContextLocal; import cn.bootx.platform.daxpay.service.core.channel.alipay.entity.AliPayConfig; import cn.bootx.platform.daxpay.service.core.channel.alipay.service.AliPayCloseService; import cn.bootx.platform.daxpay.service.core.channel.alipay.service.AliPayConfigService; -import cn.bootx.platform.daxpay.service.core.channel.alipay.service.AliPayOrderService; import cn.bootx.platform.daxpay.service.core.order.pay.dao.PayChannelOrderManager; -import cn.bootx.platform.daxpay.service.core.order.pay.entity.PayChannelOrder; import cn.bootx.platform.daxpay.service.func.AbsPayRepairStrategy; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Service; +import java.time.LocalDateTime; + import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE; /** @@ -27,11 +27,19 @@ import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROT @Service @RequiredArgsConstructor public class AliPayRepairStrategy extends AbsPayRepairStrategy { - private final AliPayOrderService orderService; private final AliPayCloseService closeService; + private final AliPayConfigService aliPayConfigService; - private final PayChannelOrderManager orderChannelManager; + private final PayChannelOrderManager payChannelOrderManager; + + /** + * 策略标识 + */ + @Override + public PayChannelEnum getChannel() { + return PayChannelEnum.ALI; + } /** * 修复前处理 @@ -41,16 +49,26 @@ public class AliPayRepairStrategy extends AbsPayRepairStrategy { AliPayConfig config = aliPayConfigService.getConfig(); aliPayConfigService.initConfig(config); } + /** * 支付成功处理 */ @Override - public void doSuccessHandler() { - PayChannelOrder orderChannel = orderChannelManager.findByPaymentIdAndChannel(this.getOrder().getId(), PayChannelEnum.ALI.getCode()) - .orElseThrow(() -> new PayFailureException("支付宝订单不存在")); - // 将支付方式写入上下文 - PaymentContextLocal.get().getAsyncPayInfo().setPayWay(orderChannel.getPayWay()); + public void doPaySuccessHandler() { + LocalDateTime payTime = PaymentContextLocal.get() + .getRepairInfo() + .getFinishTime(); + this.getChannelOrder().setStatus(PayStatusEnum.SUCCESS.getCode()) + .setPayTime(payTime); + payChannelOrderManager.updateById(this.getChannelOrder()); + } + /** + * 等待支付处理 + */ + @Override + public void doWaitPayHandler() { + super.doWaitPayHandler(); } /** @@ -58,7 +76,7 @@ public class AliPayRepairStrategy extends AbsPayRepairStrategy { */ @Override public void doCloseLocalHandler() { - orderService.updateClose(this.getOrder().getId()); + this.getChannelOrder().setStatus(PayStatusEnum.CLOSE.getCode()); } @@ -70,12 +88,4 @@ public class AliPayRepairStrategy extends AbsPayRepairStrategy { closeService.close(this.getOrder()); this.doCloseLocalHandler(); } - - /** - * 退款 - */ - @Override - public void doRefundHandler() { - orderService.updateRefund(this.getOrder().getId(), 0); - } } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/CashPayRepairStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/pay/CashPayRepairStrategy.java similarity index 72% rename from daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/CashPayRepairStrategy.java rename to daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/pay/CashPayRepairStrategy.java index 446a5886..8c593ffd 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/CashPayRepairStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/pay/CashPayRepairStrategy.java @@ -1,5 +1,7 @@ -package cn.bootx.platform.daxpay.service.core.payment.repair.strategy; +package cn.bootx.platform.daxpay.service.core.payment.repair.strategy.pay; +import cn.bootx.platform.daxpay.code.PayChannelEnum; +import cn.bootx.platform.daxpay.code.PayStatusEnum; import cn.bootx.platform.daxpay.service.core.channel.cash.service.CashService; import cn.bootx.platform.daxpay.service.func.AbsPayRepairStrategy; import lombok.RequiredArgsConstructor; @@ -23,13 +25,20 @@ public class CashPayRepairStrategy extends AbsPayRepairStrategy { private final CashService cashService; + /** + * 策略标识 + */ + @Override + public PayChannelEnum getChannel() { + return PayChannelEnum.CASH; + } + /** * 取消支付 */ @Override public void doCloseLocalHandler() { cashService.close(this.getOrder().getId()); - - + this.getChannelOrder().setStatus(PayStatusEnum.CLOSE.getCode()); } } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/UnionPayRepairStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/pay/UnionPayRepairStrategy.java similarity index 76% rename from daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/UnionPayRepairStrategy.java rename to daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/pay/UnionPayRepairStrategy.java index 051cf7ba..7ae4a84c 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/UnionPayRepairStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/pay/UnionPayRepairStrategy.java @@ -1,5 +1,6 @@ -package cn.bootx.platform.daxpay.service.core.payment.repair.strategy; +package cn.bootx.platform.daxpay.service.core.payment.repair.strategy.pay; +import cn.bootx.platform.daxpay.code.PayChannelEnum; import cn.bootx.platform.daxpay.service.func.AbsPayRepairStrategy; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -19,6 +20,15 @@ import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROT @RequiredArgsConstructor public class UnionPayRepairStrategy extends AbsPayRepairStrategy { + + /** + * 策略标识 + */ + @Override + public PayChannelEnum getChannel() { + return PayChannelEnum.UNION_PAY; + } + /** * 取消支付 */ diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/VoucherPayRepairStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/pay/VoucherPayRepairStrategy.java similarity index 72% rename from daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/VoucherPayRepairStrategy.java rename to daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/pay/VoucherPayRepairStrategy.java index c2093fd7..8c0bbaae 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/VoucherPayRepairStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/pay/VoucherPayRepairStrategy.java @@ -1,6 +1,7 @@ -package cn.bootx.platform.daxpay.service.core.payment.repair.strategy; +package cn.bootx.platform.daxpay.service.core.payment.repair.strategy.pay; -import cn.bootx.platform.daxpay.service.core.channel.voucher.service.VoucherPayOrderService; +import cn.bootx.platform.daxpay.code.PayChannelEnum; +import cn.bootx.platform.daxpay.code.PayStatusEnum; import cn.bootx.platform.daxpay.service.core.channel.voucher.service.VoucherPayService; import cn.bootx.platform.daxpay.service.func.AbsPayRepairStrategy; import lombok.RequiredArgsConstructor; @@ -21,7 +22,15 @@ import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROT @RequiredArgsConstructor public class VoucherPayRepairStrategy extends AbsPayRepairStrategy { private final VoucherPayService voucherPayService; - private final VoucherPayOrderService voucherPayOrderService; + + + /** + * 策略标识 + */ + @Override + public PayChannelEnum getChannel() { + return PayChannelEnum.VOUCHER; + } /** * 取消支付 @@ -29,6 +38,6 @@ public class VoucherPayRepairStrategy extends AbsPayRepairStrategy { @Override public void doCloseLocalHandler() { voucherPayService.close(this.getOrder().getId()); - voucherPayOrderService.updateClose(this.getOrder().getId()); + this.getChannelOrder().setStatus(PayStatusEnum.CLOSE.getCode()); } } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/WalletPayRepairStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/pay/WalletPayRepairStrategy.java similarity index 75% rename from daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/WalletPayRepairStrategy.java rename to daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/pay/WalletPayRepairStrategy.java index db8a2b05..8c7b4ecb 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/WalletPayRepairStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/pay/WalletPayRepairStrategy.java @@ -1,5 +1,7 @@ -package cn.bootx.platform.daxpay.service.core.payment.repair.strategy; +package cn.bootx.platform.daxpay.service.core.payment.repair.strategy.pay; +import cn.bootx.platform.daxpay.code.PayChannelEnum; +import cn.bootx.platform.daxpay.code.PayStatusEnum; import cn.bootx.platform.daxpay.service.core.channel.wallet.service.WalletPayOrderService; import cn.bootx.platform.daxpay.service.core.channel.wallet.service.WalletPayService; import cn.bootx.platform.daxpay.service.func.AbsPayRepairStrategy; @@ -25,12 +27,21 @@ public class WalletPayRepairStrategy extends AbsPayRepairStrategy { private final WalletPayService walletPayService; + + /** + * 策略标识 + */ + @Override + public PayChannelEnum getChannel() { + return PayChannelEnum.WALLET; + } + /** * 取消支付 */ @Override public void doCloseLocalHandler() { walletPayService.close(this.getOrder().getId()); - walletPayOrderService.updateClose(this.getOrder().getId()); + this.getChannelOrder().setStatus(PayStatusEnum.CLOSE.getCode()); } } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/WeChatPayRepairStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/pay/WeChatPayRepairStrategy.java similarity index 69% rename from daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/WeChatPayRepairStrategy.java rename to daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/pay/WeChatPayRepairStrategy.java index eb818b81..27f72fc2 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/WeChatPayRepairStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/pay/WeChatPayRepairStrategy.java @@ -1,19 +1,20 @@ -package cn.bootx.platform.daxpay.service.core.payment.repair.strategy; +package cn.bootx.platform.daxpay.service.core.payment.repair.strategy.pay; import cn.bootx.platform.daxpay.code.PayChannelEnum; -import cn.bootx.platform.daxpay.exception.pay.PayFailureException; +import cn.bootx.platform.daxpay.code.PayStatusEnum; +import cn.bootx.platform.daxpay.service.common.local.PaymentContextLocal; import cn.bootx.platform.daxpay.service.core.channel.wechat.entity.WeChatPayConfig; import cn.bootx.platform.daxpay.service.core.channel.wechat.service.WeChatPayCloseService; import cn.bootx.platform.daxpay.service.core.channel.wechat.service.WeChatPayConfigService; -import cn.bootx.platform.daxpay.service.core.channel.wechat.service.WeChatPayOrderService; import cn.bootx.platform.daxpay.service.core.order.pay.dao.PayChannelOrderManager; -import cn.bootx.platform.daxpay.service.core.order.pay.entity.PayChannelOrder; import cn.bootx.platform.daxpay.service.func.AbsPayRepairStrategy; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Service; +import java.time.LocalDateTime; + import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE; /** @@ -27,13 +28,21 @@ import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROT @RequiredArgsConstructor public class WeChatPayRepairStrategy extends AbsPayRepairStrategy { private final WeChatPayCloseService closeService; - private final WeChatPayOrderService orderService; - private final PayChannelOrderManager payChannelOrderManager; private final WeChatPayConfigService weChatPayConfigService; + private final PayChannelOrderManager payChannelOrderManager; + private WeChatPayConfig weChatPayConfig; + /** + * 策略标识 + */ + @Override + public PayChannelEnum getChannel() { + return PayChannelEnum.WECHAT; + } + /** * 修复前处理 */ @@ -46,17 +55,13 @@ public class WeChatPayRepairStrategy extends AbsPayRepairStrategy { * 支付成功处理 */ @Override - public void doSuccessHandler() { - PayChannelOrder orderChannel = payChannelOrderManager.findByPaymentIdAndChannel(this.getOrder().getId(), PayChannelEnum.WECHAT.getCode()) - .orElseThrow(() -> new PayFailureException("支付宝订单不存在")); - orderService.updateAsyncSuccess(this.getOrder(), orderChannel.getAmount()); - } - - /** - * 退款处理 todo 需要结合退款同步功能进行协同实现 - */ - @Override - public void doRefundHandler() { + public void doPaySuccessHandler() { + LocalDateTime payTime = PaymentContextLocal.get() + .getRepairInfo() + .getFinishTime(); + this.getChannelOrder().setStatus(PayStatusEnum.SUCCESS.getCode()) + .setPayTime(payTime); + payChannelOrderManager.updateById(this.getChannelOrder()); } /** @@ -64,7 +69,7 @@ public class WeChatPayRepairStrategy extends AbsPayRepairStrategy { */ @Override public void doCloseLocalHandler() { - orderService.updateClose(this.getOrder().getId()); + this.getChannelOrder().setStatus(PayStatusEnum.CLOSE.getCode()); } /** diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/refund/AliRefundRepairStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/refund/AliRefundRepairStrategy.java new file mode 100644 index 00000000..7cc75650 --- /dev/null +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/refund/AliRefundRepairStrategy.java @@ -0,0 +1,29 @@ +package cn.bootx.platform.daxpay.service.core.payment.repair.strategy.refund; + +import cn.bootx.platform.daxpay.code.PayChannelEnum; +import cn.bootx.platform.daxpay.service.func.AbsRefundRepairStrategy; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Service; + +import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE; + +/** + * + * @author xxm + * @since 2024/1/26 + */ +@Slf4j +@Scope(SCOPE_PROTOTYPE) +@Service +@RequiredArgsConstructor +public class AliRefundRepairStrategy extends AbsRefundRepairStrategy { + /** + * 策略标识 + */ + @Override + public PayChannelEnum getChannel() { + return PayChannelEnum.ALI; + } +} diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/refund/CashRefundRepairStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/refund/CashRefundRepairStrategy.java new file mode 100644 index 00000000..ed36552b --- /dev/null +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/refund/CashRefundRepairStrategy.java @@ -0,0 +1,29 @@ +package cn.bootx.platform.daxpay.service.core.payment.repair.strategy.refund; + +import cn.bootx.platform.daxpay.code.PayChannelEnum; +import cn.bootx.platform.daxpay.service.func.AbsRefundRepairStrategy; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Service; + +import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE; + +/** + * + * @author xxm + * @since 2024/1/26 + */ +@Slf4j +@Scope(SCOPE_PROTOTYPE) +@Service +@RequiredArgsConstructor +public class CashRefundRepairStrategy extends AbsRefundRepairStrategy { + /** + * 策略标识 + */ + @Override + public PayChannelEnum getChannel() { + return PayChannelEnum.CASH; + } +} diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/refund/UnionRefundRepairStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/refund/UnionRefundRepairStrategy.java new file mode 100644 index 00000000..4825e034 --- /dev/null +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/refund/UnionRefundRepairStrategy.java @@ -0,0 +1,29 @@ +package cn.bootx.platform.daxpay.service.core.payment.repair.strategy.refund; + +import cn.bootx.platform.daxpay.code.PayChannelEnum; +import cn.bootx.platform.daxpay.service.func.AbsRefundRepairStrategy; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Service; + +import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE; + +/** + * + * @author xxm + * @since 2024/1/26 + */ +@Slf4j +@Scope(SCOPE_PROTOTYPE) +@Service +@RequiredArgsConstructor +public class UnionRefundRepairStrategy extends AbsRefundRepairStrategy { + /** + * 策略标识 + */ + @Override + public PayChannelEnum getChannel() { + return PayChannelEnum.UNION_PAY; + } +} diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/refund/VoucherRefundRepairStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/refund/VoucherRefundRepairStrategy.java new file mode 100644 index 00000000..5d36335a --- /dev/null +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/refund/VoucherRefundRepairStrategy.java @@ -0,0 +1,29 @@ +package cn.bootx.platform.daxpay.service.core.payment.repair.strategy.refund; + +import cn.bootx.platform.daxpay.code.PayChannelEnum; +import cn.bootx.platform.daxpay.service.func.AbsRefundRepairStrategy; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Service; + +import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE; + +/** + * + * @author xxm + * @since 2024/1/26 + */ +@Slf4j +@Scope(SCOPE_PROTOTYPE) +@Service +@RequiredArgsConstructor +public class VoucherRefundRepairStrategy extends AbsRefundRepairStrategy { + /** + * 策略标识 + */ + @Override + public PayChannelEnum getChannel() { + return PayChannelEnum.VOUCHER; + } +} diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/refund/WalletRefundRepairStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/refund/WalletRefundRepairStrategy.java new file mode 100644 index 00000000..39bdc064 --- /dev/null +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/refund/WalletRefundRepairStrategy.java @@ -0,0 +1,24 @@ +package cn.bootx.platform.daxpay.service.core.payment.repair.strategy.refund; + +import cn.bootx.platform.daxpay.code.PayChannelEnum; +import cn.bootx.platform.daxpay.service.func.AbsRefundRepairStrategy; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Service; + +import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE; + +@Slf4j +@Scope(SCOPE_PROTOTYPE) +@Service +@RequiredArgsConstructor +public class WalletRefundRepairStrategy extends AbsRefundRepairStrategy { + /** + * 策略标识 + */ + @Override + public PayChannelEnum getChannel() { + return PayChannelEnum.WALLET; + } +} diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/refund/WeChatRefundRepairStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/refund/WeChatRefundRepairStrategy.java new file mode 100644 index 00000000..caaac487 --- /dev/null +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/repair/strategy/refund/WeChatRefundRepairStrategy.java @@ -0,0 +1,29 @@ +package cn.bootx.platform.daxpay.service.core.payment.repair.strategy.refund; + +import cn.bootx.platform.daxpay.code.PayChannelEnum; +import cn.bootx.platform.daxpay.service.func.AbsRefundRepairStrategy; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Service; + +import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE; + +/** + * + * @author xxm + * @since 2024/1/26 + */ +@Slf4j +@Scope(SCOPE_PROTOTYPE) +@Service +@RequiredArgsConstructor +public class WeChatRefundRepairStrategy extends AbsRefundRepairStrategy { + /** + * 策略标识 + */ + @Override + public PayChannelEnum getChannel() { + return PayChannelEnum.WECHAT; + } +} diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/sync/service/PaySyncService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/sync/service/PaySyncService.java index a06d7662..6be4c9a6 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/sync/service/PaySyncService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/sync/service/PaySyncService.java @@ -14,14 +14,14 @@ import cn.bootx.platform.daxpay.service.common.context.RepairLocal; import cn.bootx.platform.daxpay.service.common.local.PaymentContextLocal; import cn.bootx.platform.daxpay.service.core.order.pay.entity.PayOrder; import cn.bootx.platform.daxpay.service.core.order.pay.service.PayOrderQueryService; -import cn.bootx.platform.daxpay.service.core.payment.repair.param.PayRepairParam; -import cn.bootx.platform.daxpay.service.core.payment.repair.result.RepairResult; +import cn.bootx.platform.daxpay.service.core.payment.repair.result.PayRepairResult; import cn.bootx.platform.daxpay.service.core.payment.repair.service.PayRepairService; import cn.bootx.platform.daxpay.service.core.payment.sync.factory.PaySyncStrategyFactory; import cn.bootx.platform.daxpay.service.core.payment.sync.result.PayGatewaySyncResult; import cn.bootx.platform.daxpay.service.core.record.sync.entity.PaySyncRecord; import cn.bootx.platform.daxpay.service.core.record.sync.service.PaySyncRecordService; import cn.bootx.platform.daxpay.service.func.AbsPaySyncStrategy; +import cn.hutool.core.util.StrUtil; import com.baomidou.lock.LockInfo; import com.baomidou.lock.LockTemplate; import lombok.RequiredArgsConstructor; @@ -104,7 +104,7 @@ public class PaySyncService { // 判断网关状态是否和支付单一致, 同时特定情况下更新网关同步状态 boolean statusSync = this.checkAndAdjustSyncStatus(syncResult,payOrder); - RepairResult repairResult = new RepairResult(); + PayRepairResult repairResult = new PayRepairResult(); try { // 状态不一致,执行支付单修复逻辑 if (!statusSync){ @@ -118,12 +118,12 @@ public class PaySyncService { } // 同步成功记录日志 - this.saveRecord( payOrder, syncResult, !statusSync, repairResult.getId(), null); + this.saveRecord( payOrder, syncResult, !statusSync, repairResult.getRepairId(), null); return new PaySyncResult() .setGatewayStatus(syncResult.getSyncStatus().getCode()) .setSuccess(true) .setRepair(!statusSync) - .setRepairId(repairResult.getId()); + .setRepairId(repairResult.getRepairId()); } finally { lockTemplate.releaseLock(lock); } @@ -175,48 +175,37 @@ public class PaySyncService { /** * 根据同步的结果对支付单进行处理 */ - private RepairResult resultHandler(PayGatewaySyncResult syncResult, PayOrder payOrder){ + private PayRepairResult resultHandler(PayGatewaySyncResult syncResult, PayOrder payOrder){ PaySyncStatusEnum syncStatusEnum = syncResult.getSyncStatus(); // 如果没有支付来源, 设置支付来源为同步 RepairLocal repairInfo = PaymentContextLocal.get().getRepairInfo(); - if (repairInfo.getSource() == null){ - repairInfo.setSource(PayRepairSourceEnum.SYNC); + if (StrUtil.isBlank(repairInfo.getSource())){ + repairInfo.setSource(PayRepairSourceEnum.SYNC.getCode()); } - PayRepairParam repairParam = new PayRepairParam(); - RepairResult repair = new RepairResult(); + PayRepairResult repair = new PayRepairResult(); // 对支付网关同步的结果进行处理 switch (syncStatusEnum) { // 支付成功 支付宝退款时也是支付成功状态, 除非支付完成 case PAY_SUCCESS: { - repairParam.setRepairType(PayRepairTypeEnum.SUCCESS); - repair = repairService.repair(payOrder, repairParam); + repair = repairService.repair(payOrder, PayRepairTypeEnum.SUCCESS); break; } // 待支付, 将订单状态重新设置为待支付 case PAY_WAIT: { - repairParam.setRepairType(PayRepairTypeEnum.WAIT_PAY); - repair = repairService.repair(payOrder,repairParam); + repair = repairService.repair(payOrder,PayRepairTypeEnum.WAIT_PAY); break; } // 交易关闭和未找到, 都对本地支付订单进行关闭, 不需要再调用网关进行关闭 case CLOSED: case NOT_FOUND: { - repairParam.setRepairType(PayRepairTypeEnum.CLOSE_LOCAL); - repair = repairService.repair(payOrder, repairParam); + repair = repairService.repair(payOrder, PayRepairTypeEnum.CLOSE_LOCAL); break; } // 超时关闭和交易不存在(特殊) 关闭本地支付订单, 同时调用网关进行关闭, 确保后续这个订单不能被支付 case TIMEOUT: case NOT_FOUND_UNKNOWN:{ - repairParam.setRepairType(PayRepairTypeEnum.CLOSE_GATEWAY); - repair = repairService.repair(payOrder, repairParam); - break; - } - // 交易退款 TODO 未实现 - case REFUND: { - repairParam.setRepairType(PayRepairTypeEnum.REFUND); - repair = repairService.repair(payOrder, repairParam); + repair = repairService.repair(payOrder, PayRepairTypeEnum.CLOSE_GATEWAY); break; } // 调用出错 diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/sync/strategy/AliPaySyncStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/sync/strategy/AliPaySyncStrategy.java index 828523e9..c525acb4 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/sync/strategy/AliPaySyncStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/sync/strategy/AliPaySyncStrategy.java @@ -1,6 +1,7 @@ package cn.bootx.platform.daxpay.service.core.payment.sync.strategy; +import cn.bootx.platform.daxpay.code.PayChannelEnum; import cn.bootx.platform.daxpay.service.core.channel.alipay.entity.AliPayConfig; import cn.bootx.platform.daxpay.service.core.channel.alipay.service.AliPayConfigService; import cn.bootx.platform.daxpay.service.core.channel.alipay.service.AliPaySyncService; @@ -26,6 +27,14 @@ public class AliPaySyncStrategy extends AbsPaySyncStrategy { private final AliPaySyncService alipaySyncService; + /** + * 策略标识 + */ + @Override + public PayChannelEnum getChannel() { + return PayChannelEnum.ALI; + } + /** * 异步支付单与支付网关进行状态比对 */ diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/sync/strategy/WeChatPaySyncStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/sync/strategy/WeChatPaySyncStrategy.java index ae10e660..134cc4b2 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/sync/strategy/WeChatPaySyncStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/sync/strategy/WeChatPaySyncStrategy.java @@ -1,5 +1,6 @@ package cn.bootx.platform.daxpay.service.core.payment.sync.strategy; +import cn.bootx.platform.daxpay.code.PayChannelEnum; import cn.bootx.platform.daxpay.service.core.channel.wechat.entity.WeChatPayConfig; import cn.bootx.platform.daxpay.service.core.channel.wechat.service.WeChatPayConfigService; import cn.bootx.platform.daxpay.service.core.channel.wechat.service.WeChatPaySyncService; @@ -27,6 +28,14 @@ public class WeChatPaySyncStrategy extends AbsPaySyncStrategy { private WeChatPayConfig weChatPayConfig; + /** + * 策略标识 + */ + @Override + public PayChannelEnum getChannel() { + return PayChannelEnum.WECHAT; + } + /** * 异步支付单与支付网关进行状态比对 */ diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/record/repair/entity/PayRepairRecord.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/record/repair/entity/PayRepairRecord.java index aa574c2e..8aaa0b08 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/record/repair/entity/PayRepairRecord.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/record/repair/entity/PayRepairRecord.java @@ -5,6 +5,7 @@ import cn.bootx.platform.common.mybatisplus.base.MpCreateEntity; import cn.bootx.platform.daxpay.code.PayStatusEnum; import cn.bootx.platform.daxpay.service.code.PayRepairSourceEnum; import cn.bootx.platform.daxpay.service.code.PayRepairTypeEnum; +import cn.bootx.platform.daxpay.service.code.RefundRepairTypeEnum; import cn.bootx.platform.daxpay.service.core.record.repair.convert.PayRepairRecordConvert; import cn.bootx.platform.daxpay.service.dto.record.repair.PayRepairRecordDto; import cn.bootx.table.modify.annotation.DbColumn; @@ -15,7 +16,7 @@ import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; /** - * 支付修复记录 + * 支付修复记录 包括支付修复记录和退款修复记录 * @author xxm * @since 2024/1/6 */ @@ -26,13 +27,26 @@ import lombok.experimental.Accessors; @DbTable(comment = "支付修复记录") public class PayRepairRecord extends MpCreateEntity implements EntityBaseFunction { - /** 支付ID */ - @DbColumn(comment = "支付ID") - private Long paymentId; + /** + * 如果一次修复产生的修复记录只有一条, 则该字段为与ID一致 + * 如果一次修复产生的修复记录有多个, 则使用这个ID作为关联 + */ + @DbColumn(comment = "修复ID") + private Long repairId; - /** 业务号 */ + /** 支付ID/退款ID */ + @DbColumn(comment = "业务ID") + private Long orderId; + + /** + * 业务号, 支付业务号/退款号 + */ @DbColumn(comment = "业务号") - private String businessNo; + private String orderNo; + + /** 类型 支付修复/退款修复 */ + @DbColumn(comment = "类型") + private String type; /** * 修复来源 @@ -44,6 +58,7 @@ public class PayRepairRecord extends MpCreateEntity implements EntityBaseFunctio /** * 修复类型 * @see PayRepairTypeEnum + * @see RefundRepairTypeEnum */ @DbColumn(comment = "修复类型") private String repairType; @@ -66,10 +81,6 @@ public class PayRepairRecord extends MpCreateEntity implements EntityBaseFunctio @DbColumn(comment = "修复后状态") private String afterStatus; - /** 金额变动 */ - @DbColumn(comment = "金额变动") - private Integer amount; - /** * 转换 */ diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/record/repair/service/PayRepairRecordService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/record/repair/service/PayRepairRecordService.java index b1ef44ae..2804808a 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/record/repair/service/PayRepairRecordService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/record/repair/service/PayRepairRecordService.java @@ -14,6 +14,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; +import java.util.List; + /** * * @author xxm @@ -46,4 +48,11 @@ public class PayRepairRecordService { public void saveRecord(PayRepairRecord record){ repairRecordManager.save(record); } + /** + * 保存记录 + */ + @Transactional(propagation = Propagation.REQUIRES_NEW) + public void saveAllRecord(List records){ + repairRecordManager.saveAll(records); + } } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/dto/record/repair/PayRepairRecordDto.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/dto/record/repair/PayRepairRecordDto.java index 5f0354ae..d3a2fbb0 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/dto/record/repair/PayRepairRecordDto.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/dto/record/repair/PayRepairRecordDto.java @@ -21,13 +21,24 @@ import lombok.experimental.Accessors; @Schema(title = "支付修复记录") public class PayRepairRecordDto extends BaseDto { - /** 支付ID */ - @Schema(description = "支付ID") - private Long paymentId; + /** + * 如果一次修复产生的修复记录只有一条, 则该字段为与ID一致 + * 如果一次修复产生的修复记录有多个, 则使用这个ID作为关联 + */ + @Schema(description = "修复ID") + private Long repairId; - /** 业务号 */ + /** 支付ID/退款ID */ + @Schema(description = "业务ID") + private Long orderId; + + /** 支付业务号/退款号 业务号 */ @Schema(description = "业务号") - private String businessNo; + private String orderNo; + + /** 类型 支付修复/退款修复 */ + @Schema(description = "类型") + private String type; /** * 修复来源 diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsPayCallbackStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsCallbackStrategy.java similarity index 88% rename from daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsPayCallbackStrategy.java rename to daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsCallbackStrategy.java index 48e26342..05eb6fda 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsPayCallbackStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsCallbackStrategy.java @@ -1,6 +1,5 @@ package cn.bootx.platform.daxpay.service.func; -import cn.bootx.platform.daxpay.code.PayChannelEnum; import cn.bootx.platform.daxpay.service.code.PayCallbackStatusEnum; import cn.bootx.platform.daxpay.service.code.PayCallbackTypeEnum; import cn.bootx.platform.daxpay.service.code.PayRepairSourceEnum; @@ -18,13 +17,13 @@ import java.time.LocalDateTime; import java.util.Map; /** - * 支付回调处理抽象类 + * 回调处理抽象类, 处理支付回调和退款回调 * * @author xxm * @since 2021/6/21 */ @Slf4j -public abstract class AbsPayCallbackStrategy implements PayStrategy { +public abstract class AbsCallbackStrategy implements PayStrategy { @Resource private PayCallbackRecordService callbackRecordService; @Resource @@ -33,7 +32,7 @@ public abstract class AbsPayCallbackStrategy implements PayStrategy { private PayRefundCallbackService refundCallbackService; /** - * 支付回调 + * 回调处理入口 */ public String callback(Map params) { CallbackLocal callbackInfo = PaymentContextLocal.get().getCallbackInfo(); @@ -46,16 +45,16 @@ public abstract class AbsPayCallbackStrategy implements PayStrategy { this.saveCallbackRecord(); return null; } - PaymentContextLocal.get().getRepairInfo().setSource(PayRepairSourceEnum.CALLBACK); + PaymentContextLocal.get().getRepairInfo().setSource(PayRepairSourceEnum.CALLBACK.getCode()); // 判断回调类型 PayCallbackTypeEnum callbackType = this.getCallbackType(); if (callbackType == PayCallbackTypeEnum.PAY){ - // 解析数据并放处理 + // 解析支付数据并放处理 this.resolvePayData(); payCallbackService.payCallback(); } else { - // 解析数据并放处理 + // 解析退款数据并放处理 this.resolveRefundData(); refundCallbackService.refundCallback(); } @@ -64,12 +63,6 @@ public abstract class AbsPayCallbackStrategy implements PayStrategy { return this.getReturnMsg(); } - /** - * 支付通道 - * @see PayChannelEnum - */ - public abstract PayChannelEnum getPayChannel(); - /** * 验证信息格式 */ @@ -102,7 +95,7 @@ public abstract class AbsPayCallbackStrategy implements PayStrategy { public void saveCallbackRecord() { CallbackLocal callbackInfo = PaymentContextLocal.get().getCallbackInfo(); PayCallbackRecord payNotifyRecord = new PayCallbackRecord() - .setPayChannel(this.getPayChannel().getCode()) + .setPayChannel(this.getChannel().getCode()) .setNotifyInfo(JSONUtil.toJsonStr(callbackInfo.getCallbackParam())) .setNotifyTime(LocalDateTime.now()) .setOrderId(callbackInfo.getOrderId()) diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsPayCloseStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsPayCloseStrategy.java index 44b62899..ad60b40e 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsPayCloseStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsPayCloseStrategy.java @@ -1,6 +1,5 @@ package cn.bootx.platform.daxpay.service.func; -import cn.bootx.platform.daxpay.code.PayChannelEnum; import cn.bootx.platform.daxpay.code.PayStatusEnum; import cn.bootx.platform.daxpay.service.core.order.pay.entity.PayChannelOrder; import cn.bootx.platform.daxpay.service.core.order.pay.entity.PayOrder; @@ -22,12 +21,6 @@ public abstract class AbsPayCloseStrategy implements PayStrategy{ /** 支付通道订单 */ private PayChannelOrder channelOrder = null; - /** - * 策略标识 - * @see PayChannelEnum - */ - public abstract PayChannelEnum getType(); - public void initCloseParam(PayOrder order, PayChannelOrder channelOrder){ this.order = order; this.channelOrder = channelOrder; diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsPayRepairStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsPayRepairStrategy.java index b7c86a61..2148dad2 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsPayRepairStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsPayRepairStrategy.java @@ -1,5 +1,6 @@ package cn.bootx.platform.daxpay.service.func; +import cn.bootx.platform.daxpay.service.core.order.pay.entity.PayChannelOrder; import cn.bootx.platform.daxpay.service.core.order.pay.entity.PayOrder; import lombok.Getter; import lombok.Setter; @@ -13,19 +14,20 @@ import lombok.Setter; */ @Getter @Setter -public abstract class AbsPayRepairStrategy { +public abstract class AbsPayRepairStrategy implements PayStrategy{ /** 支付订单 */ private PayOrder order = null; - /** 支付订单 */ - + /** 通道支付订单 */ + private PayChannelOrder channelOrder = null; /** * 初始化修复参数 */ - public void initRepairParam(PayOrder order){ + public void initRepairParam(PayOrder order, PayChannelOrder channelOrder){ this.order = order; + this.channelOrder = channelOrder; } /** @@ -38,7 +40,14 @@ public abstract class AbsPayRepairStrategy { /** * 支付成功处理 */ - public void doSuccessHandler(){ + public void doPaySuccessHandler(){ + + } + + /** + * 等待支付处理 + */ + public void doWaitPayHandler(){ } @@ -54,10 +63,4 @@ public abstract class AbsPayRepairStrategy { this.doCloseLocalHandler(); } - /** - * 退款处理 todo 需要结合退款同步功能进行协同实现 - */ - public void doRefundHandler() { - - } } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsPayStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsPayStrategy.java index 3965cc8a..efdf4be8 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsPayStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsPayStrategy.java @@ -1,6 +1,5 @@ package cn.bootx.platform.daxpay.service.func; -import cn.bootx.platform.daxpay.code.PayChannelEnum; import cn.bootx.platform.daxpay.param.pay.PayChannelParam; import cn.bootx.platform.daxpay.param.pay.PayParam; import cn.bootx.platform.daxpay.service.core.order.pay.builder.PayBuilder; @@ -32,11 +31,6 @@ public abstract class AbsPayStrategy implements PayStrategy{ /** 支付方式参数 支付参数中的与这个不一致, 以这个为准 */ private PayChannelParam payChannelParam = null; - /** - * 策略标识 - * @see PayChannelEnum - */ - public abstract PayChannelEnum getType(); /** * 初始化支付的参数支付上下文 diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsReconcileStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsReconcileStrategy.java index e91d75fb..c3d65fe3 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsReconcileStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsReconcileStrategy.java @@ -1,6 +1,5 @@ package cn.bootx.platform.daxpay.service.func; -import cn.bootx.platform.daxpay.code.PayChannelEnum; import cn.bootx.platform.daxpay.service.core.order.reconcile.entity.PayReconcileOrder; import lombok.Getter; @@ -10,17 +9,11 @@ import lombok.Getter; * @since 2024/1/18 */ @Getter -public abstract class AbsReconcileStrategy { +public abstract class AbsReconcileStrategy implements PayStrategy { /** 对账订单 */ private PayReconcileOrder recordOrder; - /** - * 策略标识 - * @see PayChannelEnum - */ - public abstract PayChannelEnum getType(); - /** * 对账前处理, 主要是初始化支付SDK配置 */ diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsRefundRepairStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsRefundRepairStrategy.java index 3f286c7c..ed2c6868 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsRefundRepairStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsRefundRepairStrategy.java @@ -1,5 +1,9 @@ package cn.bootx.platform.daxpay.service.func; +import cn.bootx.platform.daxpay.service.core.order.pay.entity.PayChannelOrder; +import cn.bootx.platform.daxpay.service.core.order.pay.entity.PayOrder; +import cn.bootx.platform.daxpay.service.core.order.refund.entity.PayRefundChannelOrder; +import cn.bootx.platform.daxpay.service.core.order.refund.entity.PayRefundOrder; import lombok.Getter; /** @@ -9,4 +13,33 @@ import lombok.Getter; */ @Getter public abstract class AbsRefundRepairStrategy implements PayStrategy{ + private PayRefundOrder refundOrder; + private PayRefundChannelOrder refundChannelOrder; + private PayOrder payOrder; + private PayChannelOrder payChannelOrder; + + /** + * 初始化参数 + */ + public void initParam(PayRefundOrder refundOrder, + PayRefundChannelOrder refundChannelOrder, + PayOrder payOrder, + PayChannelOrder payChannelOrder){ + this.refundOrder = refundOrder; + this.refundChannelOrder = refundChannelOrder; + this.payOrder = payOrder; + this.payChannelOrder = payChannelOrder; + } + + /** + * 修复前处理 + */ + public void doBeforeHandler(){ + + } + + /** + * 支付成功修复 + */ + } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsRefundStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsRefundStrategy.java index e6e260cd..9e532d9a 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsRefundStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsRefundStrategy.java @@ -1,6 +1,5 @@ package cn.bootx.platform.daxpay.service.func; -import cn.bootx.platform.daxpay.code.PayChannelEnum; import cn.bootx.platform.daxpay.code.PayRefundStatusEnum; import cn.bootx.platform.daxpay.code.PayStatusEnum; import cn.bootx.platform.daxpay.param.pay.RefundChannelParam; @@ -36,12 +35,6 @@ public abstract class AbsRefundStrategy implements PayStrategy{ /** 当前通道的退款订单 */ private PayRefundChannelOrder refundChannelOrder; - /** - * 策略标识 - * @see PayChannelEnum - */ - public abstract PayChannelEnum getType(); - /** * 初始化参数 */ diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/PayStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/PayStrategy.java index 02c458d0..d7ca0d92 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/PayStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/PayStrategy.java @@ -1,9 +1,16 @@ package cn.bootx.platform.daxpay.service.func; +import cn.bootx.platform.daxpay.code.PayChannelEnum; + /** * 支付相关策略标识接口 * @author xxm * @since 2023/12/27 */ public interface PayStrategy { + + /** + * 策略标识 + */ + PayChannelEnum getChannel(); }