mirror of
https://gitee.com/dromara/dax-pay.git
synced 2025-09-03 19:16:21 +00:00
feat 支付回调记录/支付关闭记录/支付修复记录/支付同步记录 联调
This commit is contained in:
@@ -5,7 +5,7 @@ import cn.bootx.platform.common.core.rest.Res;
|
||||
import cn.bootx.platform.common.core.rest.ResResult;
|
||||
import cn.bootx.platform.common.core.rest.param.PageParam;
|
||||
import cn.bootx.platform.daxpay.service.core.record.repair.service.PayRepairRecordService;
|
||||
import cn.bootx.platform.daxpay.service.dto.order.repair.PayRepairRecordDto;
|
||||
import cn.bootx.platform.daxpay.service.dto.record.repair.PayRepairRecordDto;
|
||||
import cn.bootx.platform.daxpay.service.param.record.PayRepairRecordQuery;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
|
@@ -15,10 +15,10 @@ import java.util.Objects;
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum PayStatusEnum {
|
||||
FAIL("fail","失败"),
|
||||
PROGRESS("progress","支付中"),
|
||||
SUCCESS("success","成功"),
|
||||
CLOSE("close","支付关闭"),
|
||||
FAIL("fail","失败"),
|
||||
PARTIAL_REFUND("partial_refund","部分退款"),
|
||||
REFUNDED("refunded","全部退款");
|
||||
|
||||
|
@@ -4,33 +4,20 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 支付回调通知状态
|
||||
* 支付回调处理状态
|
||||
* @author xxm
|
||||
* @since 2023/12/20
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum PayNotifyStatusEnum {
|
||||
public enum PayCallbackStatusEnum {
|
||||
|
||||
// 回调处理状态
|
||||
/** 失败 */
|
||||
FAIL("fail","失败"),
|
||||
|
||||
/** 成功 */
|
||||
SUCCESS("success","成功"),
|
||||
|
||||
/** 忽略 */
|
||||
FAIL("fail","失败"),
|
||||
IGNORE("ignore","忽略"),
|
||||
|
||||
/** 超时 */
|
||||
TIMEOUT("timeout","超时"),
|
||||
|
||||
/** 未找到本地订单 需要行进订单撤销 */
|
||||
NOT_FOUND("not_found","未找到");
|
||||
|
||||
/** 状态 */
|
||||
private final String code;
|
||||
|
||||
/** 状态描述 */
|
||||
private final String desc;
|
||||
private final String name;
|
||||
}
|
@@ -12,7 +12,7 @@ import lombok.Getter;
|
||||
@AllArgsConstructor
|
||||
public enum PayRepairTypeEnum {
|
||||
|
||||
SUCCESS("success","成功"),
|
||||
SUCCESS("success","支付成功"),
|
||||
CLOSE_LOCAL("close_local","关闭本地支付"),
|
||||
WAIT("wait","待支付"),
|
||||
/** 同时也会关闭本地支付 */
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package cn.bootx.platform.daxpay.service.core.payment.callback.result;
|
||||
|
||||
import cn.bootx.platform.daxpay.code.PayStatusEnum;
|
||||
import cn.bootx.platform.daxpay.service.code.PayCallbackStatusEnum;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@@ -16,10 +16,11 @@ public class PayCallbackResult {
|
||||
|
||||
/**
|
||||
* 处理状态
|
||||
* @see PayStatusEnum
|
||||
* @see PayCallbackStatusEnum
|
||||
*/
|
||||
private String status;
|
||||
|
||||
|
||||
/** 提示信息 */
|
||||
private String msg;
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package cn.bootx.platform.daxpay.service.core.payment.callback.service;
|
||||
|
||||
import cn.bootx.platform.common.core.util.LocalDateTimeUtil;
|
||||
import cn.bootx.platform.daxpay.service.code.PayNotifyStatusEnum;
|
||||
import cn.bootx.platform.daxpay.service.code.PayCallbackStatusEnum;
|
||||
import cn.bootx.platform.daxpay.service.code.PayRepairSourceEnum;
|
||||
import cn.bootx.platform.daxpay.service.code.PayRepairTypeEnum;
|
||||
import cn.bootx.platform.daxpay.code.PayStatusEnum;
|
||||
@@ -43,17 +43,17 @@ public class PayCallbackService {
|
||||
|
||||
// 支付单不存在,记录回调记录, TODO 取消支付网关的订单支付情况
|
||||
if (Objects.isNull(payOrder)) {
|
||||
return new PayCallbackResult().setStatus(PayNotifyStatusEnum.NOT_FOUND.getCode()).setMsg("支付单不存在,记录回调记录");
|
||||
return new PayCallbackResult().setStatus(PayCallbackStatusEnum.NOT_FOUND.getCode()).setMsg("支付单不存在,记录回调记录");
|
||||
}
|
||||
|
||||
// 回调时间超出了支付单超时时间, 记录一下, 不做处理 TODO 这块应该把订单给当成正常结束给处理了,
|
||||
if (Objects.nonNull(payOrder.getExpiredTime())
|
||||
&& LocalDateTimeUtil.ge(LocalDateTime.now(), payOrder.getExpiredTime())) {
|
||||
return new PayCallbackResult().setStatus(PayNotifyStatusEnum.TIMEOUT.getCode()).setMsg("回调时间超出了支付单支付有效时间");
|
||||
return new PayCallbackResult().setStatus(PayCallbackStatusEnum.TIMEOUT.getCode()).setMsg("回调时间超出了支付单支付有效时间");
|
||||
}
|
||||
|
||||
// 成功状态
|
||||
if (Objects.equals(PayNotifyStatusEnum.SUCCESS.getCode(), tradeStatus)) {
|
||||
if (Objects.equals(PayCallbackStatusEnum.SUCCESS.getCode(), tradeStatus)) {
|
||||
return this.success(payOrder);
|
||||
}
|
||||
else {
|
||||
@@ -66,16 +66,16 @@ public class PayCallbackService {
|
||||
* 成功处理 使用补偿
|
||||
*/
|
||||
private PayCallbackResult success(PayOrder payOrder) {
|
||||
PayCallbackResult result = new PayCallbackResult().setStatus(PayNotifyStatusEnum.SUCCESS.getCode());
|
||||
PayCallbackResult result = new PayCallbackResult().setStatus(PayCallbackStatusEnum.SUCCESS.getCode());
|
||||
|
||||
// 支付单已经被支付,不需要重复处理
|
||||
if (Objects.equals(payOrder.getStatus(), PayStatusEnum.SUCCESS.getCode())) {
|
||||
return result.setStatus(PayNotifyStatusEnum.IGNORE.getCode()).setMsg("支付单已经是支付成功状态,不进行处理");
|
||||
return result.setStatus(PayCallbackStatusEnum.IGNORE.getCode()).setMsg("支付单已经是支付成功状态,不进行处理");
|
||||
}
|
||||
|
||||
// 支付单已被取消,记录回调记录 TODO 考虑不全, 需要做支付订单的取消处理
|
||||
if (!Objects.equals(payOrder.getStatus(), PayStatusEnum.PROGRESS.getCode())) {
|
||||
return result.setStatus(PayNotifyStatusEnum.FAIL.getCode()).setMsg("支付单不是待支付状态,记录回调记录");
|
||||
return result.setStatus(PayCallbackStatusEnum.FAIL.getCode()).setMsg("支付单不是待支付状态,记录回调记录");
|
||||
}
|
||||
|
||||
// 执行支付完成修复逻辑
|
||||
@@ -94,12 +94,12 @@ public class PayCallbackService {
|
||||
|
||||
// payment已被取消,记录回调记录,后期处理 TODO 考虑不完善, 后续优化
|
||||
if (!Objects.equals(payOrder.getStatus(), PayStatusEnum.PROGRESS.getCode())) {
|
||||
return result.setStatus(PayNotifyStatusEnum.IGNORE.getCode()).setMsg("支付单已经取消,记录回调记录");
|
||||
return result.setStatus(PayCallbackStatusEnum.IGNORE.getCode()).setMsg("支付单已经取消,记录回调记录");
|
||||
}
|
||||
|
||||
// payment支付成功, 状态非法 TODO 考虑不完善, 后续优化
|
||||
if (!Objects.equals(payOrder.getStatus(), PayStatusEnum.SUCCESS.getCode())) {
|
||||
return result.setStatus(PayNotifyStatusEnum.FAIL.getCode()).setMsg("支付单状态非法,支付网关状态为失败,但支付单状态为已完成");
|
||||
return result.setStatus(PayCallbackStatusEnum.FAIL.getCode()).setMsg("支付单状态非法,支付网关状态为失败,但支付单状态为已完成");
|
||||
}
|
||||
|
||||
// 执行支付关闭修复逻辑
|
||||
|
@@ -241,7 +241,7 @@ public class PaySyncService {
|
||||
PaySyncRecord paySyncRecord = new PaySyncRecord()
|
||||
.setPaymentId(payOrder.getId())
|
||||
.setBusinessNo(payOrder.getBusinessNo())
|
||||
.setChannel(payOrder.getAsyncChannel())
|
||||
.setAsyncChannel(payOrder.getAsyncChannel())
|
||||
.setSyncInfo(syncResult.getSyncInfo())
|
||||
.setGatewayStatus(syncResult.getSyncStatus().getCode())
|
||||
.setRepairOrder(repair)
|
||||
|
@@ -3,7 +3,7 @@ package cn.bootx.platform.daxpay.service.core.record.callback.entity;
|
||||
import cn.bootx.platform.common.core.function.EntityBaseFunction;
|
||||
import cn.bootx.platform.common.mybatisplus.base.MpCreateEntity;
|
||||
import cn.bootx.platform.daxpay.code.PayChannelEnum;
|
||||
import cn.bootx.platform.daxpay.code.PayStatusEnum;
|
||||
import cn.bootx.platform.daxpay.service.code.PayCallbackStatusEnum;
|
||||
import cn.bootx.platform.daxpay.service.core.record.callback.convert.PayCallbackRecordConvert;
|
||||
import cn.bootx.platform.daxpay.service.dto.record.callback.PayCallbackRecordDto;
|
||||
import cn.bootx.table.modify.annotation.DbColumn;
|
||||
@@ -44,15 +44,9 @@ public class PayCallbackRecord extends MpCreateEntity implements EntityBaseFunct
|
||||
@DbColumn(comment = "通知消息")
|
||||
private String notifyInfo;
|
||||
|
||||
/**
|
||||
* 支付状态
|
||||
* @see PayStatusEnum
|
||||
*/
|
||||
@DbColumn(comment = "支付状态")
|
||||
private String payStatus;
|
||||
|
||||
/**
|
||||
* 回调处理状态
|
||||
* @see PayCallbackStatusEnum
|
||||
*/
|
||||
@DbColumn(comment = "回调处理状态")
|
||||
private String status;
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package cn.bootx.platform.daxpay.service.core.record.repair.convert;
|
||||
|
||||
import cn.bootx.platform.daxpay.service.core.record.repair.entity.PayRepairRecord;
|
||||
import cn.bootx.platform.daxpay.service.dto.order.repair.PayRepairRecordDto;
|
||||
import cn.bootx.platform.daxpay.service.dto.record.repair.PayRepairRecordDto;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
|
@@ -2,8 +2,11 @@ package cn.bootx.platform.daxpay.service.core.record.repair.entity;
|
||||
|
||||
import cn.bootx.platform.common.core.function.EntityBaseFunction;
|
||||
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.core.record.repair.convert.PayRepairRecordConvert;
|
||||
import cn.bootx.platform.daxpay.service.dto.order.repair.PayRepairRecordDto;
|
||||
import cn.bootx.platform.daxpay.service.dto.record.repair.PayRepairRecordDto;
|
||||
import cn.bootx.table.modify.annotation.DbColumn;
|
||||
import cn.bootx.table.modify.annotation.DbTable;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
@@ -31,11 +34,17 @@ public class PayRepairRecord extends MpCreateEntity implements EntityBaseFunctio
|
||||
@DbColumn(comment = "业务号")
|
||||
private String businessNo;
|
||||
|
||||
/** 修复来源 */
|
||||
/**
|
||||
* 修复来源
|
||||
* @see PayRepairSourceEnum
|
||||
*/
|
||||
@DbColumn(comment = "修复来源")
|
||||
private String repairSource;
|
||||
|
||||
/** 修复类型 */
|
||||
/**
|
||||
* 修复类型
|
||||
* @see PayRepairTypeEnum
|
||||
*/
|
||||
@DbColumn(comment = "修复类型")
|
||||
private String repairType;
|
||||
|
||||
@@ -43,11 +52,17 @@ public class PayRepairRecord extends MpCreateEntity implements EntityBaseFunctio
|
||||
@DbColumn(comment = "修复的异步通道")
|
||||
private String asyncChannel;
|
||||
|
||||
/** 修复前状态 */
|
||||
/**
|
||||
* 修复前状态
|
||||
* @see PayStatusEnum
|
||||
*/
|
||||
@DbColumn(comment = "修复前状态")
|
||||
private String beforeStatus;
|
||||
|
||||
/** 修复后状态 */
|
||||
/**
|
||||
* 修复后状态
|
||||
* @see PayStatusEnum
|
||||
*/
|
||||
@DbColumn(comment = "修复后状态")
|
||||
private String afterStatus;
|
||||
|
||||
|
@@ -6,7 +6,7 @@ import cn.bootx.platform.common.core.rest.param.PageParam;
|
||||
import cn.bootx.platform.common.mybatisplus.util.MpUtil;
|
||||
import cn.bootx.platform.daxpay.service.core.record.repair.dao.PayRepairRecordManager;
|
||||
import cn.bootx.platform.daxpay.service.core.record.repair.entity.PayRepairRecord;
|
||||
import cn.bootx.platform.daxpay.service.dto.order.repair.PayRepairRecordDto;
|
||||
import cn.bootx.platform.daxpay.service.dto.record.repair.PayRepairRecordDto;
|
||||
import cn.bootx.platform.daxpay.service.param.record.PayRepairRecordQuery;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@@ -30,7 +30,7 @@ public class PaySyncRecordManager extends BaseManager<PaySyncRecordMapper, PaySy
|
||||
Page<PaySyncRecord> mpPage = MpUtil.getMpPage(pageParam, PaySyncRecord.class);
|
||||
return lambdaQuery().orderByDesc(MpIdEntity::getId)
|
||||
.like(Objects.nonNull(param.getPaymentId()), PaySyncRecord::getPaymentId, param.getPaymentId())
|
||||
.eq(Objects.nonNull(param.getChannel()), PaySyncRecord::getChannel, param.getChannel())
|
||||
.eq(Objects.nonNull(param.getAsyncChannel()), PaySyncRecord::getAsyncChannel, param.getAsyncChannel())
|
||||
.eq(Objects.nonNull(param.getStatus()), PaySyncRecord::getGatewayStatus, param.getStatus())
|
||||
.page(mpPage);
|
||||
}
|
||||
|
@@ -7,7 +7,6 @@ import cn.bootx.platform.daxpay.code.PaySyncStatusEnum;
|
||||
import cn.bootx.platform.daxpay.service.core.record.sync.convert.PaySyncRecordConvert;
|
||||
import cn.bootx.platform.daxpay.service.dto.record.sync.PaySyncRecordDto;
|
||||
import cn.bootx.table.modify.annotation.DbColumn;
|
||||
import cn.bootx.table.modify.annotation.DbComment;
|
||||
import cn.bootx.table.modify.annotation.DbTable;
|
||||
import cn.bootx.table.modify.mysql.annotation.DbMySqlFieldType;
|
||||
import cn.bootx.table.modify.mysql.constants.MySqlFieldTypeEnum;
|
||||
@@ -37,11 +36,11 @@ public class PaySyncRecord extends MpCreateEntity implements EntityBaseFunction<
|
||||
private String businessNo;
|
||||
|
||||
/**
|
||||
* 支付通道
|
||||
* 同步通道
|
||||
* @see PayChannelEnum#getCode()
|
||||
*/
|
||||
@DbColumn(comment = "支付通道")
|
||||
private String channel;
|
||||
@DbColumn(comment = "同步通道")
|
||||
private String asyncChannel;
|
||||
|
||||
/** 通知消息 */
|
||||
@DbMySqlFieldType(MySqlFieldTypeEnum.LONGTEXT)
|
||||
|
@@ -2,7 +2,7 @@ package cn.bootx.platform.daxpay.service.dto.record.callback;
|
||||
|
||||
import cn.bootx.platform.common.core.rest.dto.BaseDto;
|
||||
import cn.bootx.platform.daxpay.code.PayChannelEnum;
|
||||
import cn.bootx.platform.daxpay.code.PayStatusEnum;
|
||||
import cn.bootx.platform.daxpay.service.code.PayCallbackStatusEnum;
|
||||
import cn.bootx.table.modify.mysql.annotation.DbMySqlFieldType;
|
||||
import cn.bootx.table.modify.mysql.constants.MySqlFieldTypeEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
@@ -39,15 +39,9 @@ public class PayCallbackRecordDto extends BaseDto {
|
||||
@Schema(description = "通知消息")
|
||||
private String notifyInfo;
|
||||
|
||||
/**
|
||||
* 支付状态
|
||||
* @see PayStatusEnum
|
||||
*/
|
||||
@Schema(description = "支付状态")
|
||||
private String payStatus;
|
||||
|
||||
/**
|
||||
* 回调处理状态
|
||||
* @see PayCallbackStatusEnum
|
||||
*/
|
||||
@Schema(description = "回调处理状态")
|
||||
private String status;
|
||||
|
@@ -1,6 +1,9 @@
|
||||
package cn.bootx.platform.daxpay.service.dto.order.repair;
|
||||
package cn.bootx.platform.daxpay.service.dto.record.repair;
|
||||
|
||||
import cn.bootx.platform.common.core.rest.dto.BaseDto;
|
||||
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.table.modify.annotation.DbColumn;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
@@ -26,23 +29,36 @@ public class PayRepairRecordDto extends BaseDto {
|
||||
@Schema(description = "业务号")
|
||||
private String businessNo;
|
||||
|
||||
/** 修复来源 */
|
||||
/**
|
||||
* 修复来源
|
||||
* @see PayRepairSourceEnum
|
||||
*/
|
||||
@Schema(description = "修复来源")
|
||||
private String repairSource;
|
||||
|
||||
/** 修复类型 */
|
||||
/**
|
||||
* 修复类型
|
||||
* @see PayRepairTypeEnum
|
||||
*/
|
||||
@Schema(description = "修复类型")
|
||||
private String repairType;
|
||||
|
||||
/** 修复的异步通道 */
|
||||
@DbColumn(comment = "修复的异步通道")
|
||||
private String asyncChannel;
|
||||
|
||||
/** 修复前状态 */
|
||||
@Schema(description = "修复前状态")
|
||||
/**
|
||||
* 修复前状态
|
||||
* @see PayStatusEnum
|
||||
*/
|
||||
@Schema(description = "修复前订单状态")
|
||||
private String beforeStatus;
|
||||
|
||||
/** 修复后状态 */
|
||||
@Schema(description = "修复后状态")
|
||||
/**
|
||||
* 修复后状态
|
||||
* @see PayStatusEnum
|
||||
*/
|
||||
@Schema(description = "修复后订单状态")
|
||||
private String afterStatus;
|
||||
|
||||
/** 金额变动 */
|
@@ -26,14 +26,17 @@ public class PaySyncRecordDto extends BaseDto {
|
||||
@Schema(description = "支付记录id")
|
||||
private Long paymentId;
|
||||
|
||||
@Schema(description = "业务号")
|
||||
private String businessNo;
|
||||
|
||||
/**
|
||||
* 支付通道
|
||||
* 同步通道
|
||||
* @see PayChannelEnum#getCode()
|
||||
*/
|
||||
@Schema(description = "支付通道")
|
||||
private String channel;
|
||||
@Schema(description = "同步通道")
|
||||
private String asyncChannel;
|
||||
|
||||
/** 通知消息 */
|
||||
/** 同步消息 */
|
||||
@Schema(description = "同步消息")
|
||||
private String syncInfo;
|
||||
|
||||
@@ -45,13 +48,13 @@ public class PaySyncRecordDto extends BaseDto {
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 支付单如果状态不一致, 是否修复成功
|
||||
* 支付单如果状态不一致, 是否进行修复
|
||||
*/
|
||||
@DbColumn(comment = "是否进行修复")
|
||||
private boolean repairOrder;
|
||||
|
||||
@Schema(description = "错误消息")
|
||||
private String msg;
|
||||
private String errorMsg;
|
||||
|
||||
/** 同步时间 */
|
||||
@Schema(description = "同步时间")
|
||||
|
@@ -105,7 +105,7 @@ public abstract class AbsPayCallbackStrategy implements PayStrategy {
|
||||
.setNotifyTime(LocalDateTime.now())
|
||||
.setPaymentId(this.getPaymentId())
|
||||
.setPayChannel(this.getPayChannel().getCode())
|
||||
.setPayStatus(result.getStatus())
|
||||
.setStatus(result.getStatus())
|
||||
.setMsg(result.getMsg());
|
||||
callbackRecordManager.save(payNotifyRecord);
|
||||
}
|
||||
|
@@ -28,7 +28,7 @@ public class PaySyncRecordQuery {
|
||||
* @see PayChannelEnum#getCode()
|
||||
*/
|
||||
@Schema(description = "支付通道")
|
||||
private String channel;
|
||||
private String asyncChannel;
|
||||
|
||||
/** 通知消息 */
|
||||
@Schema(description = "同步消息")
|
||||
|
Reference in New Issue
Block a user