|
@@ -11,13 +11,23 @@ import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReq
|
|
|
import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient;
|
|
|
import cn.iocoder.yudao.framework.pay.core.client.impl.NonePayClientConfig;
|
|
|
import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum;
|
|
|
+import cn.iocoder.yudao.framework.pay.core.enums.refund.PayRefundStatusRespEnum;
|
|
|
+import cn.iocoder.yudao.module.pay.dal.dataobject.order.PayOrderExtensionDO;
|
|
|
+import cn.iocoder.yudao.module.pay.dal.dataobject.refund.PayRefundDO;
|
|
|
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO;
|
|
|
+import cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum;
|
|
|
+import cn.iocoder.yudao.module.pay.enums.order.PayOrderStatusEnum;
|
|
|
+import cn.iocoder.yudao.module.pay.service.order.PayOrderService;
|
|
|
+import cn.iocoder.yudao.module.pay.service.refund.PayRefundService;
|
|
|
import cn.iocoder.yudao.module.pay.service.wallet.PayWalletService;
|
|
|
+import cn.iocoder.yudao.module.pay.service.wallet.PayWalletTransactionService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR;
|
|
|
+import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.ORDER_EXTENSION_NOT_FOUND;
|
|
|
+import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.REFUND_NOT_FOUND;
|
|
|
|
|
|
/**
|
|
|
* 钱包支付的 PayClient 实现类
|
|
@@ -29,6 +39,12 @@ public class WalletPayClient extends AbstractPayClient<NonePayClientConfig> {
|
|
|
|
|
|
private PayWalletService wallService;
|
|
|
|
|
|
+ private PayWalletTransactionService walletTransactionService;
|
|
|
+
|
|
|
+ private PayOrderService payOrderService;
|
|
|
+
|
|
|
+ private PayRefundService payRefundService;
|
|
|
+
|
|
|
public WalletPayClient(Long channelId, NonePayClientConfig config) {
|
|
|
super(channelId, PayChannelEnum.WALLET.getCode(), config);
|
|
|
}
|
|
@@ -38,6 +54,9 @@ public class WalletPayClient extends AbstractPayClient<NonePayClientConfig> {
|
|
|
if (wallService == null) {
|
|
|
wallService = SpringUtil.getBean(PayWalletService.class);
|
|
|
}
|
|
|
+ if (walletTransactionService == null) {
|
|
|
+ walletTransactionService = SpringUtil.getBean(PayWalletTransactionService.class);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -47,7 +66,7 @@ public class WalletPayClient extends AbstractPayClient<NonePayClientConfig> {
|
|
|
String userType = MapUtil.getStr(reqDTO.getChannelExtras(), "user_type");
|
|
|
Assert.notEmpty(userId, "用户 id 不能为空");
|
|
|
Assert.notEmpty(userType, "用户类型不能为空");
|
|
|
- PayWalletTransactionDO transaction = wallService.pay(Long.valueOf(userId), Integer.valueOf(userType),
|
|
|
+ PayWalletTransactionDO transaction = wallService.orderPay(Long.valueOf(userId), Integer.valueOf(userType),
|
|
|
reqDTO.getOutTradeNo(), reqDTO.getPrice());
|
|
|
return PayOrderRespDTO.successOf(transaction.getNo(), transaction.getCreator(),
|
|
|
transaction.getCreateTime(),
|
|
@@ -73,13 +92,37 @@ public class WalletPayClient extends AbstractPayClient<NonePayClientConfig> {
|
|
|
|
|
|
@Override
|
|
|
protected PayOrderRespDTO doGetOrder(String outTradeNo) {
|
|
|
- throw new UnsupportedOperationException("待实现");
|
|
|
+ if (payOrderService == null) {
|
|
|
+ payOrderService = SpringUtil.getBean(PayOrderService.class);
|
|
|
+ }
|
|
|
+ PayOrderExtensionDO orderExtension = payOrderService.getOrderExtensionByNo(outTradeNo);
|
|
|
+ // 支付交易拓展单不存在, 返回关闭状态
|
|
|
+ if (orderExtension == null) {
|
|
|
+ return PayOrderRespDTO.closedOf(String.valueOf(ORDER_EXTENSION_NOT_FOUND.getCode()),
|
|
|
+ ORDER_EXTENSION_NOT_FOUND.getMsg(), outTradeNo, "");
|
|
|
+ }
|
|
|
+ // 关闭状态
|
|
|
+ if (PayOrderStatusEnum.isClosed(orderExtension.getStatus())) {
|
|
|
+ return PayOrderRespDTO.closedOf(orderExtension.getChannelErrorCode(),
|
|
|
+ orderExtension.getChannelErrorMsg(), outTradeNo, "");
|
|
|
+ }
|
|
|
+ // 成功状态
|
|
|
+ if (PayOrderStatusEnum.isSuccess(orderExtension.getStatus())) {
|
|
|
+ PayWalletTransactionDO walletTransaction = walletTransactionService.getWalletTransaction(
|
|
|
+ String.valueOf(orderExtension.getOrderId()), PayWalletBizTypeEnum.PAYMENT);
|
|
|
+ Assert.notNull(walletTransaction, "支付单 {} 钱包流水不能为空", outTradeNo);
|
|
|
+ return PayOrderRespDTO.successOf(walletTransaction.getNo(), walletTransaction.getCreator(),
|
|
|
+ walletTransaction.getCreateTime(), outTradeNo, walletTransaction);
|
|
|
+ }
|
|
|
+ // 其它状态为无效状态
|
|
|
+ log.error("[doGetOrder] 支付单 {} 的状态不正确", outTradeNo);
|
|
|
+ throw new IllegalStateException(String.format("支付单[%s] 状态不正确", outTradeNo));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected PayRefundRespDTO doUnifiedRefund(PayRefundUnifiedReqDTO reqDTO) {
|
|
|
try {
|
|
|
- PayWalletTransactionDO payWalletTransaction = wallService.refund(reqDTO.getOutRefundNo(),
|
|
|
+ PayWalletTransactionDO payWalletTransaction = wallService.orderRefund(reqDTO.getOutRefundNo(),
|
|
|
reqDTO.getRefundPrice(), reqDTO.getReason());
|
|
|
return PayRefundRespDTO.successOf(payWalletTransaction.getNo(), payWalletTransaction.getCreateTime(),
|
|
|
reqDTO.getOutRefundNo(), payWalletTransaction);
|
|
@@ -104,7 +147,31 @@ public class WalletPayClient extends AbstractPayClient<NonePayClientConfig> {
|
|
|
|
|
|
@Override
|
|
|
protected PayRefundRespDTO doGetRefund(String outTradeNo, String outRefundNo) {
|
|
|
- throw new UnsupportedOperationException("待实现");
|
|
|
+ if (payRefundService == null) {
|
|
|
+ payRefundService = SpringUtil.getBean(PayRefundService.class);
|
|
|
+ }
|
|
|
+ PayRefundDO payRefund = payRefundService.getRefundByNo(outRefundNo);
|
|
|
+ // 支付退款单不存在, 返回退款失败状态
|
|
|
+ if (payRefund == null) {
|
|
|
+ return PayRefundRespDTO.failureOf(String.valueOf(REFUND_NOT_FOUND), REFUND_NOT_FOUND.getMsg(),
|
|
|
+ outRefundNo, "");
|
|
|
+ }
|
|
|
+ // 退款失败
|
|
|
+ if (PayRefundStatusRespEnum.isFailure(payRefund.getStatus())) {
|
|
|
+ return PayRefundRespDTO.failureOf(payRefund.getChannelErrorCode(), payRefund.getChannelErrorMsg(),
|
|
|
+ outRefundNo, "");
|
|
|
+ }
|
|
|
+ // 退款成功
|
|
|
+ if (PayRefundStatusRespEnum.isSuccess(payRefund.getStatus())) {
|
|
|
+ PayWalletTransactionDO walletTransaction = walletTransactionService.getWalletTransaction(
|
|
|
+ String.valueOf(payRefund.getId()), PayWalletBizTypeEnum.PAYMENT_REFUND);
|
|
|
+ Assert.notNull(walletTransaction, "支付退款单 {} 钱包流水不能为空", outRefundNo);
|
|
|
+ return PayRefundRespDTO.successOf(walletTransaction.getNo(), walletTransaction.getCreateTime(),
|
|
|
+ outRefundNo, walletTransaction);
|
|
|
+ }
|
|
|
+ // 其它状态为无效状态
|
|
|
+ log.error("[doGetRefund] 支付退款单 {} 的状态不正确", outRefundNo);
|
|
|
+ throw new IllegalStateException(String.format("支付退款单[%s] 状态不正确", outRefundNo));
|
|
|
}
|
|
|
|
|
|
}
|