fix 支付宝退款没有网关订单号,微信回调退款状态部分场合获取失败

This commit is contained in:
bootx
2024-02-09 20:42:53 +08:00
parent a1efe54da4
commit 40f61c0740
9 changed files with 23 additions and 28 deletions

View File

@@ -3,6 +3,7 @@ package cn.bootx.platform.daxpay.service.common.context;
import cn.bootx.platform.daxpay.code.RefundStatusEnum;
import cn.bootx.platform.daxpay.code.PayStatusEnum;
import cn.bootx.platform.daxpay.service.code.PayCallbackStatusEnum;
import cn.bootx.platform.daxpay.service.code.PaymentTypeEnum;
import lombok.Data;
import lombok.experimental.Accessors;
@@ -46,6 +47,9 @@ public class CallbackLocal {
/** 修复号 */
private String payRepairNo;
/** 回调类型 */
private PaymentTypeEnum callbackType;
/**
* 回调处理状态
* @see PayCallbackStatusEnum

View File

@@ -3,8 +3,6 @@ package cn.bootx.platform.daxpay.service.common.context;
import lombok.Data;
import lombok.experimental.Accessors;
import java.time.LocalDateTime;
/**
* 支付同步信息
* @author xxm
@@ -14,5 +12,4 @@ import java.time.LocalDateTime;
@Accessors(chain = true)
public class PaySyncLocal {
}

View File

@@ -110,15 +110,14 @@ public class AliPayCallbackService extends AbsCallbackStrategy {
/**
* 解析退款回调数据并放到上下文中
* 注意: 支付宝退款没有网关订单号, 网关订单号是支付单的
*/
@Override
public void resolveRefundData() {
CallbackLocal callback = PaymentContextLocal.get().getCallbackInfo();
Map<String, String> callbackParam = callback.getCallbackParam();
// 网关订单号
callback.setGatewayOrderNo(callbackParam.get(OUT_BIZ_NO));
// 退款订单Id
callback.setOrderId(Long.valueOf(callbackParam.get(OUT_TRADE_NO)));
callback.setOrderId(Long.valueOf(callbackParam.get(OUT_BIZ_NO)));
// 退款状态
callback.setGatewayStatus(callbackParam.get(TRADE_STATUS));
// 退款金额

View File

@@ -94,6 +94,7 @@ public class AliPaySyncService {
/**
* 退款同步查询
* 注意: 支付宝退款没有网关订单号, 网关订单号是支付单的
*/
public RefundGatewaySyncResult syncRefundStatus(PayRefundOrder refundOrder) {
RefundGatewaySyncResult syncResult = new RefundGatewaySyncResult().setSyncStatus(RefundSyncStatusEnum.FAIL);
@@ -115,8 +116,6 @@ public class AliPaySyncService {
return syncResult;
}
String tradeStatus = response.getRefundStatus();
// 设置网关订单号
syncResult.setGatewayOrderNo(response.getTradeNo());
// 成功
if (Objects.equals(tradeStatus, AliPayCode.REFUND_SUCCESS)){
LocalDateTime localDateTime = LocalDateTimeUtil.of(response.getGmtRefundPay());

View File

@@ -51,7 +51,8 @@ public class WeChatPayCallbackService extends AbsCallbackStrategy {
*/
@Override
public boolean verifyNotify() {
Map<String, String> params = PaymentContextLocal.get().getCallbackInfo().getCallbackParam();
CallbackLocal callbackInfo = PaymentContextLocal.get().getCallbackInfo();
Map<String, String> params = callbackInfo.getCallbackParam();
String callReq = JSONUtil.toJsonStr(params);
log.info("微信发起回调 报文: {}", callReq);
String appId = params.get(APPID);
@@ -62,7 +63,7 @@ public class WeChatPayCallbackService extends AbsCallbackStrategy {
}
// 退款回调不用进行校验
PaymentTypeEnum callbackType = this.getCallbackType();
PaymentTypeEnum callbackType = callbackInfo.getCallbackType();
if (callbackType == PaymentTypeEnum.REFUND){
return true;
}

View File

@@ -64,12 +64,10 @@ public class PayRefundSyncService {
}
// 如果不是异步支付, 直接返回返回
if (!refundOrder.isAsyncPay()){
// return new SyncResult().setSuccess(false).setRepair(false).setErrorMsg("订单没有异步通道的退款,不需要同步");
throw new PayFailureException("订单没有异步通道的退款,不需要同步");
}
// 如果订单已经关闭, 直接返回失败
if (Objects.equals(refundOrder.getStatus(), RefundStatusEnum.CLOSE.getCode())){
// return new SyncResult().setSuccess(false).setRepair(false). setErrorMsg("订单已经关闭,不需要同步");
throw new PayFailureException("订单已经关闭,不需要同步");
}
return this.syncRefundOrder(refundOrder);
@@ -97,7 +95,6 @@ public class PayRefundSyncService {
// 判断是否同步成功
if (Objects.equals(syncResult.getSyncStatus(), RefundSyncStatusEnum.FAIL)) {
// 同步失败, 返回失败响应, 同时记录失败的日志
// return new SyncResult().setErrorMsg(syncResult.getErrorMsg());
this.saveRecord(refundOrder, syncResult, false, null, syncResult.getErrorMsg());
throw new PayFailureException(syncResult.getErrorMsg());
}

View File

@@ -14,7 +14,6 @@ import lombok.extern.slf4j.Slf4j;
import javax.annotation.Resource;
import java.util.Map;
import java.util.Optional;
/**
* 回调处理抽象类, 处理支付回调和退款回调
@@ -40,6 +39,11 @@ public abstract class AbsCallbackStrategy implements PayStrategy {
try {
// 将参数写入到上下文中
callbackInfo.getCallbackParam().putAll(params);
// 判断并保存回调类型
PaymentTypeEnum callbackType = this.getCallbackType();
callbackInfo.setCallbackType(callbackType);
// 验证消息
if (!this.verifyNotify()) {
callbackInfo.setCallbackStatus(PayCallbackStatusEnum.FAIL).setMsg("验证信息格式不通过");
@@ -50,8 +54,7 @@ public abstract class AbsCallbackStrategy implements PayStrategy {
// 提前设置订单修复的来源
PaymentContextLocal.get().getRepairInfo().setSource(PayRepairSourceEnum.CALLBACK);
// 判断回调类型
PaymentTypeEnum callbackType = this.getCallbackType();
if (callbackType == PaymentTypeEnum.PAY){
// 解析支付数据并放处理
this.resolvePayData();
@@ -103,17 +106,12 @@ public abstract class AbsCallbackStrategy implements PayStrategy {
public void saveCallbackRecord() {
CallbackLocal callbackInfo = PaymentContextLocal.get().getCallbackInfo();
// 回调类型
String callbackType = Optional.ofNullable(this.getCallbackType())
.map(PaymentTypeEnum::getCode)
.orElse(null);
PayCallbackRecord payNotifyRecord = new PayCallbackRecord()
.setChannel(this.getChannel().getCode())
.setNotifyInfo(JSONUtil.toJsonStr(callbackInfo.getCallbackParam()))
.setOrderId(callbackInfo.getOrderId())
.setGatewayOrderNo(callbackInfo.getGatewayOrderNo())
.setCallbackType(callbackType)
.setCallbackType(callbackInfo.getCallbackType().getCode())
.setRepairOrderNo(callbackInfo.getPayRepairNo())
.setStatus(callbackInfo.getCallbackStatus().getCode())
.setMsg(callbackInfo.getMsg());