ref 异常类型拆分

This commit is contained in:
bootx
2024-06-18 22:21:41 +08:00
parent 96344eb0e9
commit 8186486355
72 changed files with 458 additions and 385 deletions

View File

@@ -7,68 +7,70 @@ package cn.daxpay.single.core.code;
*/
public interface DaxPayCommonErrorCode {
/** 未归类的错误 */
int UNCLASSIFIED_ERROR = 10000;
int UNCLASSIFIED_ERROR = 20000;
/** 不存在的支付通道 */
int CHANNEL_NOT_EXIST = 10011;
int CHANNEL_NOT_EXIST = 20011;
/** 不存在的支付方式 */
int METHOD_NOT_EXIST = 10012;
int METHOD_NOT_EXIST = 20012;
/** 不存在的状态 */
int STATUS_NOT_EXIST = 10013;
int STATUS_NOT_EXIST = 20013;
/** 支付通道未启用 */
int CHANNEL_NOT_ENABLED = 10021;
int CHANNEL_NOT_ENABLE = 20021;
/** 支付方式未启用 */
int METHOD_NOT_ENABLED = 10022;
int METHOD_NOT_ENABLE = 20022;
/** 配置未启用 */
int CONFIG_NOT_ENABLED = 10023;
int CONFIG_NOT_ENABLE = 20023;
/** 配置错误 */
int CONFIG_ERROR = 20024;
/** 不支持该能力 */
int UNSUPPORTED_ABILITY = 10030;
int UNSUPPORTED_ABILITY = 20030;
/** 交易不存在 */
int TRADE_NOT_EXIST = 10041;
int TRADE_NOT_EXIST = 20041;
/** 交易已关闭 */
int TRADE_CLOSED = 10042;
int TRADE_CLOSED = 20042;
/** 交易处理中, 请勿重复操作 */
int TRADE_PROCESSING = 10043;
int TRADE_PROCESSING = 20043;
/** 交易状态错误 */
int TRADE_STATUS_ERROR = 10044;
int TRADE_STATUS_ERROR = 20044;
/** 交易失败 */
int TRADE_FAILED = 10045;
int TRADE_FAILE = 20045;
/** 参数校验未通过 */
int PARAM_VALIDATION_FAILED = 10051;
int PARAM_VALIDATION_FAIL = 20051;
/** 验签失败 */
int VERIFY_SIGN_FAILED = 10052;
int VERIFY_SIGN_FAILED = 20052;
/** 金额超过限额 */
int AMOUNT_EXCEED_LIMIT = 10060;
/** 对账文件获取失败 */
int RECONCILE_GET_FAILED = 10071;
/** 对账交易账单不存在 */
int RECONCILE_NOT_EXIST = 10072;
/** 对账交易账单未生成 */
int RECONCILE_NOT_GENERATED = 10073;
int AMOUNT_EXCEED_LIMIT = 20060;
/** 对账失败 */
int RECONCILIATION_FAILED = 10074;
int RECONCILE_FAIL = 20071;
/** 操作失败 */
int OPERATION_FAILED = 10080;
int OPERATION_FAIL = 20080;
/** 操作处理中, 请勿重复操作 */
int OPERATION_PROCESSING = 20081;
/** 不支持的操作 */
int OPERATION_UNSUPPORTED = 20082;
/** 数据错误 */
int DATA_ERROR = 20091;
/** 未知异常,系统无法处理 */
int SYSTEM_UNKNOWN_ERROR = 20000;

View File

@@ -1,6 +1,6 @@
package cn.daxpay.single.core.code;
import cn.daxpay.single.core.exception.PayFailureException;
import cn.daxpay.single.core.exception.ChannelNotExistException;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@@ -36,7 +36,7 @@ public enum PayChannelEnum {
return Arrays.stream(values())
.filter(e -> Objects.equals(code, e.getCode()))
.findFirst()
.orElseThrow(() -> new PayFailureException("不存在的支付通道"));
.orElseThrow(() -> new ChannelNotExistException("不存在的支付通道"));
}
}

View File

@@ -1,6 +1,6 @@
package cn.daxpay.single.core.code;
import cn.daxpay.single.core.exception.PayFailureException;
import cn.daxpay.single.core.exception.MethodNotExistException;
import lombok.AllArgsConstructor;
import lombok.Getter;
@@ -40,7 +40,7 @@ public enum PayMethodEnum {
return Arrays.stream(PayMethodEnum.values())
.filter(e -> Objects.equals(code, e.getCode()))
.findFirst()
.orElseThrow(() -> new PayFailureException("不存在的支付方式"));
.orElseThrow(() -> new MethodNotExistException("不存在的支付方式"));
}
}

View File

@@ -1,6 +1,6 @@
package cn.daxpay.single.core.code;
import cn.daxpay.single.core.exception.PayFailureException;
import cn.daxpay.single.core.exception.TradeStatusErrorException;
import lombok.AllArgsConstructor;
import lombok.Getter;
@@ -40,6 +40,6 @@ public enum PaySyncStatusEnum {
return Arrays.stream(values())
.filter(item -> Objects.equals(item.getCode(), code))
.findFirst()
.orElseThrow(() -> new PayFailureException("不存在的支付状态"));
.orElseThrow(() -> new TradeStatusErrorException("不存在的支付状态"));
}
}

View File

@@ -0,0 +1,19 @@
package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
/**
* 支付通道未启用
* @author xxm
* @since 2024/6/17
*/
public class ChannelNotEnableException extends PayFailureException{
public ChannelNotEnableException(String message) {
super(DaxPayCommonErrorCode.CHANNEL_NOT_ENABLE,message);
}
public ChannelNotEnableException() {
super(DaxPayCommonErrorCode.CHANNEL_NOT_ENABLE,"支付通道未启用");
}
}

View File

@@ -1,19 +0,0 @@
package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
/**
* 支付通道未启用
* @author xxm
* @since 2024/6/17
*/
public class ChannelNotEnabledException extends PayFailureException{
public ChannelNotEnabledException(String message) {
super(DaxPayCommonErrorCode.CHANNEL_NOT_ENABLED,message);
}
public ChannelNotEnabledException() {
super(DaxPayCommonErrorCode.CHANNEL_NOT_ENABLED,"支付通道未启用");
}
}

View File

@@ -0,0 +1,19 @@
package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
/**
* 配置错误
* @author xxm
* @since 2024/6/18
*/
public class ConfigErrorException extends PayFailureException{
public ConfigErrorException(String message) {
super(DaxPayCommonErrorCode.CONFIG_ERROR,message);
}
public ConfigErrorException() {
super(DaxPayCommonErrorCode.CONFIG_ERROR,"配置错误");
}
}

View File

@@ -0,0 +1,19 @@
package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
/**
* 配置未启用
* @author xxm
* @since 2024/6/17
*/
public class ConfigNotEnableException extends PayFailureException{
public ConfigNotEnableException(String message) {
super(DaxPayCommonErrorCode.CONFIG_NOT_ENABLE,message);
}
public ConfigNotEnableException() {
super(DaxPayCommonErrorCode.CONFIG_NOT_ENABLE,"配置未启用");
}
}

View File

@@ -1,19 +0,0 @@
package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
/**
* 配置未启用
* @author xxm
* @since 2024/6/17
*/
public class ConfigNotEnabledException extends PayFailureException{
public ConfigNotEnabledException(String message) {
super(DaxPayCommonErrorCode.CONFIG_NOT_ENABLED,message);
}
public ConfigNotEnabledException() {
super(DaxPayCommonErrorCode.CONFIG_NOT_ENABLED,"配置未启用");
}
}

View File

@@ -0,0 +1,19 @@
package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
/**
* 数据错误
* @author xxm
* @since 2024/6/17
*/
public class DataErrorException extends PayFailureException{
public DataErrorException(String message) {
super(DaxPayCommonErrorCode.DATA_ERROR,message);
}
public DataErrorException() {
super(DaxPayCommonErrorCode.DATA_ERROR,"数据错误");
}
}

View File

@@ -0,0 +1,19 @@
package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
/**
* 支付方式未启用
* @author xxm
* @since 2024/6/17
*/
public class MethodNotEnableException extends PayFailureException{
public MethodNotEnableException(String message) {
super(DaxPayCommonErrorCode.METHOD_NOT_ENABLE,message);
}
public MethodNotEnableException() {
super(DaxPayCommonErrorCode.METHOD_NOT_ENABLE,"支付方式未启用");
}
}

View File

@@ -1,19 +0,0 @@
package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
/**
* 支付方式未启用
* @author xxm
* @since 2024/6/17
*/
public class MethodNotEnabledException extends PayFailureException{
public MethodNotEnabledException(String message) {
super(DaxPayCommonErrorCode.METHOD_NOT_ENABLED,message);
}
public MethodNotEnabledException() {
super(DaxPayCommonErrorCode.METHOD_NOT_ENABLED,"支付方式未启用");
}
}

View File

@@ -0,0 +1,19 @@
package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
/**
* 操作失败
* @author xxm
* @since 2024/6/17
*/
public class OperationFailException extends PayFailureException{
public OperationFailException(String message) {
super(DaxPayCommonErrorCode.OPERATION_FAIL,message);
}
public OperationFailException() {
super(DaxPayCommonErrorCode.OPERATION_FAIL,"操作失败");
}
}

View File

@@ -1,19 +0,0 @@
package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
/**
* 操作失败
* @author xxm
* @since 2024/6/17
*/
public class OperationFailedException extends PayFailureException{
public OperationFailedException(String message) {
super(DaxPayCommonErrorCode.OPERATION_FAILED,message);
}
public OperationFailedException() {
super(DaxPayCommonErrorCode.OPERATION_FAILED,"操作失败");
}
}

View File

@@ -0,0 +1,19 @@
package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
/**
* 操作处理中, 请勿重复操作
* @author xxm
* @since 2024/6/17
*/
public class OperationProcessingException extends PayFailureException{
public OperationProcessingException(String message) {
super(DaxPayCommonErrorCode.OPERATION_PROCESSING,message);
}
public OperationProcessingException() {
super(DaxPayCommonErrorCode.OPERATION_PROCESSING,"操作处理中, 请勿重复操作");
}
}

View File

@@ -0,0 +1,19 @@
package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
/**
* 不支持的操作
* @author xxm
* @since 2024/6/17
*/
public class OperationUnsupportedException extends PayFailureException{
public OperationUnsupportedException(String message) {
super(DaxPayCommonErrorCode.OPERATION_UNSUPPORTED,message);
}
public OperationUnsupportedException() {
super(DaxPayCommonErrorCode.OPERATION_UNSUPPORTED,"不支持的操作");
}
}

View File

@@ -0,0 +1,19 @@
package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
/**
* 参数校验未通过
* @author xxm
* @since 2024/6/17
*/
public class ParamValidationFailException extends PayFailureException{
public ParamValidationFailException(String message) {
super(DaxPayCommonErrorCode.PARAM_VALIDATION_FAIL,message);
}
public ParamValidationFailException() {
super(DaxPayCommonErrorCode.PARAM_VALIDATION_FAIL,"参数校验未通过");
}
}

View File

@@ -1,19 +0,0 @@
package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
/**
* 参数校验未通过
* @author xxm
* @since 2024/6/17
*/
public class ParamValidationFailedException extends PayFailureException{
public ParamValidationFailedException(String message) {
super(DaxPayCommonErrorCode.PARAM_VALIDATION_FAILED,message);
}
public ParamValidationFailedException() {
super(DaxPayCommonErrorCode.PARAM_VALIDATION_FAILED,"参数校验未通过");
}
}

View File

@@ -1,19 +0,0 @@
package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
/**
* 对账文件获取失败
* @author xxm
* @since 2024/6/17
*/
public class ReconcileGetFailedException extends PayFailureException{
public ReconcileGetFailedException(String message) {
super(DaxPayCommonErrorCode.RECONCILE_GET_FAILED,message);
}
public ReconcileGetFailedException() {
super(DaxPayCommonErrorCode.RECONCILE_GET_FAILED,"对账文件获取失败");
}
}

View File

@@ -1,19 +0,0 @@
package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
/**
* 对账交易账单不存在
* @author xxm
* @since 2024/6/17
*/
public class ReconcileNotExistException extends PayFailureException{
public ReconcileNotExistException(String message) {
super(DaxPayCommonErrorCode.RECONCILE_NOT_EXIST,message);
}
public ReconcileNotExistException() {
super(DaxPayCommonErrorCode.RECONCILE_NOT_EXIST,"对账交易账单不存在");
}
}

View File

@@ -1,19 +0,0 @@
package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
/**
* 对账交易账单未生成
* @author xxm
* @since 2024/6/17
*/
public class ReconcileNotGeneratedException extends PayFailureException{
public ReconcileNotGeneratedException(String message) {
super(DaxPayCommonErrorCode.RECONCILE_NOT_GENERATED,message);
}
public ReconcileNotGeneratedException() {
super(DaxPayCommonErrorCode.RECONCILE_NOT_GENERATED,"对账交易账单未生成");
}
}

View File

@@ -0,0 +1,19 @@
package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
/**
* 对账失败
* @author xxm
* @since 2024/6/17
*/
public class ReconciliationFailException extends PayFailureException{
public ReconciliationFailException(String message) {
super(DaxPayCommonErrorCode.RECONCILE_FAIL,message);
}
public ReconciliationFailException() {
super(DaxPayCommonErrorCode.RECONCILE_FAIL,"对账失败");
}
}

View File

@@ -1,19 +0,0 @@
package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
/**
* 对账失败
* @author xxm
* @since 2024/6/17
*/
public class ReconciliationFailedException extends PayFailureException{
public ReconciliationFailedException(String message) {
super(DaxPayCommonErrorCode.RECONCILIATION_FAILED,message);
}
public ReconciliationFailedException() {
super(DaxPayCommonErrorCode.RECONCILIATION_FAILED,"对账失败");
}
}

View File

@@ -0,0 +1,19 @@
package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
/**
* 交易失败
* @author xxm
* @since 2024/6/17
*/
public class TradeFaileException extends PayFailureException{
public TradeFaileException(String message) {
super(DaxPayCommonErrorCode.TRADE_FAILE,message);
}
public TradeFaileException() {
super(DaxPayCommonErrorCode.TRADE_FAILE,"交易失败");
}
}

View File

@@ -1,19 +0,0 @@
package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
/**
* 交易失败
* @author xxm
* @since 2024/6/17
*/
public class TradeFailedException extends PayFailureException{
public TradeFailedException(String message) {
super(DaxPayCommonErrorCode.TRADE_FAILED,message);
}
public TradeFailedException() {
super(DaxPayCommonErrorCode.TRADE_FAILED,"交易失败");
}
}

View File

@@ -2,6 +2,7 @@ package cn.daxpay.single.gateway.controller;
import cn.bootx.platform.common.core.annotation.IgnoreAuth;
import cn.daxpay.single.core.code.PaymentApiCode;
import cn.daxpay.single.core.exception.ParamValidationFailException;
import cn.daxpay.single.core.param.payment.allocation.QueryAllocOrderParam;
import cn.daxpay.single.core.param.payment.allocation.QueryAllocReceiverParam;
import cn.daxpay.single.core.param.payment.pay.QueryPayParam;
@@ -83,7 +84,7 @@ public class UniQueryController {
@PostMapping("/allocationReceiver")
public DaxResult<AllocReceiversResult> queryAllocReceive(@RequestBody QueryAllocReceiverParam param){
if (StrUtil.isAllBlank(param.getChannel(), param.getReceiverNo())){
throw new PayFailureException("所属通道和接收方编号不可同时为空");
throw new ParamValidationFailException("所属通道和接收方编号不可同时为空");
}
return DaxRes.ok(allocationReceiverService.queryAllocReceive(param));
}

View File

@@ -1,7 +1,7 @@
package cn.daxpay.single.service.code;
import cn.daxpay.single.core.code.PayMethodEnum;
import cn.daxpay.single.core.exception.PayFailureException;
import cn.daxpay.single.core.exception.MethodNotExistException;
import lombok.experimental.UtilityClass;
import java.util.Arrays;
@@ -28,7 +28,7 @@ public class AliPayWay {
return PAY_WAYS.stream()
.filter(e -> Objects.equals(code, e.getCode()))
.findFirst()
.orElseThrow(() -> new PayFailureException("不存在的支付方式"));
.orElseThrow(() -> new MethodNotExistException("不存在的支付方式"));
}
/**

View File

@@ -3,7 +3,7 @@ package cn.daxpay.single.service.core.channel.alipay.service;
import cn.bootx.platform.common.core.function.CollectorsFunction;
import cn.bootx.platform.common.mybatisplus.base.MpIdEntity;
import cn.daxpay.single.core.code.AllocDetailResultEnum;
import cn.daxpay.single.core.exception.TradeFailedException;
import cn.daxpay.single.core.exception.TradeFaileException;
import cn.daxpay.single.service.code.AliPayCode;
import cn.daxpay.single.service.common.local.PaymentContextLocal;
import cn.daxpay.single.service.core.channel.alipay.entity.AliPayConfig;
@@ -155,7 +155,7 @@ public class AliPayAllocationService {
errorMsg = alipayResponse.getMsg();
}
log.error("分账处理失败 {}", errorMsg);
throw new TradeFailedException(errorMsg);
throw new TradeFaileException(errorMsg);
}
}

View File

@@ -1,7 +1,8 @@
package cn.daxpay.single.service.core.channel.alipay.service;
import cn.daxpay.single.core.code.PaySyncStatusEnum;
import cn.daxpay.single.core.exception.PayFailureException;
import cn.daxpay.single.core.exception.OperationFailException;
import cn.daxpay.single.core.exception.TradeStatusErrorException;
import cn.daxpay.single.service.code.AliPayCode;
import cn.daxpay.single.service.core.channel.alipay.entity.AliPayConfig;
import cn.daxpay.single.service.core.order.pay.entity.PayOrder;
@@ -62,11 +63,11 @@ public class AliPayCloseService {
return;
}
log.error("网关返回关闭失败: {}", response.getSubMsg());
throw new PayFailureException(response.getSubMsg());
throw new OperationFailException(response.getSubMsg());
}
} catch (AlipayApiException e) {
log.error("关闭订单失败:", e);
throw new PayFailureException("关闭订单失败");
throw new OperationFailException("关闭订单失败");
}
}
@@ -96,12 +97,12 @@ public class AliPayCloseService {
return;
}
log.error("网关返回关闭失败: {}", response.getSubMsg());
throw new PayFailureException(response.getSubMsg());
throw new OperationFailException(response.getSubMsg());
}
}
} catch (AlipayApiException e) {
log.error("关闭订单失败:", e);
throw new PayFailureException("关闭订单失败");
throw new OperationFailException("关闭订单失败");
}
}
@@ -117,11 +118,11 @@ public class AliPayCloseService {
}
// 同步错误
else if (Objects.equals(gatewaySyncResult.getSyncStatus(), PaySyncStatusEnum.FAIL)){
throw new PayFailureException("关闭失败, 原因: "+gatewaySyncResult.getErrorMsg());
throw new OperationFailException("关闭失败, 原因: "+gatewaySyncResult.getErrorMsg());
}
// 其他状态
else {
throw new PayFailureException("当前交易状态不支持关闭操作, 请对订单同步状态后再进行操作");
throw new TradeStatusErrorException("当前交易状态不支持关闭操作, 请对订单同步状态后再进行操作");
}
}
}

View File

@@ -2,7 +2,7 @@ package cn.daxpay.single.service.core.channel.alipay.service;
import cn.bootx.platform.common.core.exception.DataNotExistException;
import cn.bootx.platform.common.core.rest.dto.LabelValue;
import cn.daxpay.single.core.exception.PayFailureException;
import cn.daxpay.single.core.exception.ChannelNotEnableException;
import cn.daxpay.single.service.code.AliPayCode;
import cn.daxpay.single.service.code.AliPayWay;
import cn.daxpay.single.service.core.channel.alipay.dao.AliPayConfigManager;
@@ -72,7 +72,7 @@ public class AliPayConfigService {
public AliPayConfig getAndCheckConfig() {
AliPayConfig alipayConfig = this.getConfig();
if (!alipayConfig.getEnable()){
throw new PayFailureException("支付宝支付未启用");
throw new ChannelNotEnableException("支付宝支付未启用");
}
return alipayConfig;
}

View File

@@ -2,7 +2,7 @@ package cn.daxpay.single.service.core.channel.alipay.service;
import cn.bootx.platform.common.core.util.LocalDateTimeUtil;
import cn.daxpay.single.core.code.ReconcileTradeEnum;
import cn.daxpay.single.core.exception.ReconciliationFailedException;
import cn.daxpay.single.core.exception.ReconciliationFailException;
import cn.daxpay.single.service.code.AliPayCode;
import cn.daxpay.single.service.code.ReconcileFileTypeEnum;
import cn.daxpay.single.service.common.local.PaymentContextLocal;
@@ -90,7 +90,7 @@ public class AliPayReconcileService {
// 判断返回结果
if (!Objects.equals(AliPayCode.SUCCESS, response.getCode())) {
log.error("获取支付宝对账单失败: {}", response.getSubMsg());
throw new ReconciliationFailedException(response.getSubMsg());
throw new ReconciliationFailException(response.getSubMsg());
}
// 获取对账单下载地址并下载

View File

@@ -1,7 +1,7 @@
package cn.daxpay.single.service.core.channel.alipay.service;
import cn.daxpay.single.core.code.RefundStatusEnum;
import cn.daxpay.single.core.exception.PayFailureException;
import cn.daxpay.single.core.exception.OperationFailException;
import cn.daxpay.single.core.util.PayUtil;
import cn.daxpay.single.service.code.AliPayCode;
import cn.daxpay.single.service.common.context.ErrorInfoLocal;
@@ -56,7 +56,7 @@ public class AliPayRefundService {
errorInfo.setErrorMsg(response.getSubMsg());
errorInfo.setErrorCode(response.getCode());
log.error("网关返回退款失败: {}", response.getSubMsg());
throw new PayFailureException(response.getSubMsg());
throw new OperationFailException(response.getSubMsg());
}
// 默认为退款中状态
refundInfo.setStatus(RefundStatusEnum.PROGRESS)
@@ -72,7 +72,7 @@ public class AliPayRefundService {
log.error("订单退款失败:", e);
errorInfo.setErrorMsg(e.getErrMsg());
errorInfo.setErrorCode(e.getErrCode());
throw new PayFailureException("订单退款失败");
throw new OperationFailException("订单退款失败");
}
}
}

View File

@@ -2,8 +2,7 @@ package cn.daxpay.single.service.core.channel.alipay.service;
import cn.bootx.platform.common.core.util.LocalDateTimeUtil;
import cn.daxpay.single.core.code.PayMethodEnum;
import cn.daxpay.single.core.exception.PayFailureException;
import cn.daxpay.single.core.exception.TradeFailedException;
import cn.daxpay.single.core.exception.*;
import cn.daxpay.single.core.param.channel.AliPayParam;
import cn.daxpay.single.core.param.payment.pay.PayParam;
import cn.daxpay.single.core.util.PayUtil;
@@ -53,21 +52,21 @@ public class AliPayService {
public void validation(PayParam payParam, AliPayConfig alipayConfig) {
if (CollUtil.isEmpty(alipayConfig.getPayWays())){
throw new PayFailureException("支付宝未配置可用的支付方式");
throw new ConfigErrorException("支付宝未配置可用的支付方式");
}
// 发起的支付类型是否在支持的范围内
PayMethodEnum payMethodEnum = Optional.ofNullable(AliPayWay.findByCode(payParam.getMethod()))
.orElseThrow(() -> new PayFailureException("非法的支付宝支付类型"));
.orElseThrow(() -> new MethodNotExistException("非法的支付宝支付类型"));
if (!alipayConfig.getPayWays().contains(payMethodEnum.getCode())) {
throw new PayFailureException("该支付宝支付方式不可用");
throw new MethodNotEnableException("该支付宝支付方式不可用");
}
// 验证订单金额是否超限
if(payParam.getAmount() > alipayConfig.getLimitAmount()){
throw new PayFailureException("支付宝支付金额超过限额");
throw new AmountExceedLimitException("支付宝支付金额超过限额");
}
// 支付参数开启分账, 配置未开启分账
if(Objects.equals(payParam.getAllocation(),true) && !Objects.equals(alipayConfig.getAllocation(),true)){
throw new PayFailureException("未开启分账配置");
throw new ConfigErrorException("未开启分账配置");
}
}
@@ -143,7 +142,7 @@ public class AliPayService {
}
catch (AlipayApiException e) {
log.error("支付宝手机支付失败", e);
throw new TradeFailedException("支付宝手机支付失败");
throw new TradeFaileException("支付宝手机支付失败");
}
}
@@ -178,7 +177,7 @@ public class AliPayService {
}
catch (AlipayApiException e) {
log.error("支付宝APP支付失败", e);
throw new PayFailureException("支付宝APP支付失败");
throw new TradeFaileException("支付宝APP支付失败");
}
}
@@ -219,7 +218,7 @@ public class AliPayService {
}
catch (AlipayApiException e) {
log.error("支付宝PC支付失败", e);
throw new PayFailureException("支付宝PC支付失败");
throw new TradeFaileException("支付宝PC支付失败");
}
}
@@ -255,7 +254,7 @@ public class AliPayService {
return response.getTradeNo();
} catch (AlipayApiException e) {
log.error("支付宝JsApi支付失败", e);
throw new PayFailureException("支付宝JsApi支付失败");
throw new TradeFaileException("支付宝JsApi支付失败");
}
}
@@ -289,7 +288,7 @@ public class AliPayService {
}
catch (AlipayApiException e) {
log.error("支付宝手机支付失败", e);
throw new PayFailureException("支付宝手机支付失败");
throw new TradeFaileException("支付宝手机支付失败");
}
}
@@ -335,7 +334,7 @@ public class AliPayService {
}
catch (AlipayApiException e) {
log.error("主动扫码支付失败", e);
throw new PayFailureException("主动扫码支付失败");
throw new TradeFaileException("主动扫码支付失败");
}
}
@@ -349,7 +348,7 @@ public class AliPayService {
errorMsg = alipayResponse.getMsg();
}
log.error("支付失败 {}", errorMsg);
throw new PayFailureException(errorMsg);
throw new TradeFaileException(errorMsg);
}
}

View File

@@ -2,7 +2,7 @@ package cn.daxpay.single.service.core.channel.alipay.service;
import cn.bootx.platform.common.core.util.LocalDateTimeUtil;
import cn.daxpay.single.core.code.TransferStatusEnum;
import cn.daxpay.single.core.exception.TradeFailedException;
import cn.daxpay.single.core.exception.TradeFaileException;
import cn.daxpay.single.service.code.AliPayCode;
import cn.daxpay.single.service.common.context.TransferLocal;
import cn.daxpay.single.service.common.local.PaymentContextLocal;
@@ -87,7 +87,7 @@ public class AliPayTransferService {
AlipayFundTransUniTransferResponse response = alipayClient.execute(request);
if (!Objects.equals(AliPayCode.SUCCESS, response.getCode())) {
log.error("网关返回退款失败: {}", response.getSubMsg());
throw new TradeFailedException(response.getSubMsg());
throw new TradeFaileException(response.getSubMsg());
}
TransferLocal transferInfo = PaymentContextLocal.get().getTransferInfo();
// 通道转账号

View File

@@ -2,7 +2,7 @@ package cn.daxpay.single.service.core.channel.union.service;
import cn.bootx.platform.common.core.exception.DataNotExistException;
import cn.bootx.platform.common.core.rest.dto.LabelValue;
import cn.daxpay.single.core.exception.ChannelNotEnabledException;
import cn.daxpay.single.core.exception.ChannelNotEnableException;
import cn.daxpay.single.service.code.UnionPayWay;
import cn.daxpay.single.service.core.channel.union.dao.UnionPayConfigManager;
import cn.daxpay.single.service.core.channel.union.entity.UnionPayConfig;
@@ -72,7 +72,7 @@ public class UnionPayConfigService {
public UnionPayConfig getAndCheckConfig() {
UnionPayConfig unionPayConfig = this.getConfig();
if (!unionPayConfig.getEnable()){
throw new ChannelNotEnabledException("云闪付支付未启用");
throw new ChannelNotEnableException("云闪付支付未启用");
}
return unionPayConfig;
}

View File

@@ -2,7 +2,7 @@ package cn.daxpay.single.service.core.channel.union.service;
import cn.bootx.platform.common.core.util.LocalDateTimeUtil;
import cn.daxpay.single.core.code.ReconcileTradeEnum;
import cn.daxpay.single.core.exception.ReconcileGetFailedException;
import cn.daxpay.single.core.exception.OperationFailException;
import cn.daxpay.single.service.code.ReconcileFileTypeEnum;
import cn.daxpay.single.service.code.UnionPayCode;
import cn.daxpay.single.service.code.UnionReconcileFieldEnum;
@@ -63,7 +63,7 @@ public class UnionPayReconcileService {
// 判断是否成功
if (!SDKConstants.OK_RESP_CODE.equals(map.get(SDKConstants.param_respCode))) {
log.warn("云闪付获取对账文件失败");
throw new ReconcileGetFailedException("云闪付获取对账文件失败");
throw new OperationFailException("云闪付获取对账文件失败");
}
try {

View File

@@ -45,13 +45,13 @@ public class UnionPayService {
public void validation(PayParam payParam, UnionPayConfig unionPayConfig) {
if (CollUtil.isEmpty(unionPayConfig.getPayWays())){
throw new MethodNotEnabledException("云闪付未配置可用的支付方式");
throw new MethodNotEnableException("云闪付未配置可用的支付方式");
}
// 发起的支付类型是否在支持的范围内
PayMethodEnum payMethodEnum = Optional.ofNullable(UnionPayWay.findByCode(payParam.getMethod()))
.orElseThrow(() -> new MethodNotExistException("非法的云闪付支付类型"));
if (!unionPayConfig.getPayWays().contains(payMethodEnum.getCode())) {
throw new MethodNotEnabledException("该云闪付支付方式不可用");
throw new MethodNotEnableException("该云闪付支付方式不可用");
}
// 支付金额是否超限
if (payParam.getAmount() > unionPayConfig.getLimitAmount()) {
@@ -151,7 +151,7 @@ public class UnionPayService {
if (!(Objects.equals(resultCode, UnionPayCode.RESP_SUCCESS))) {
log.warn("云闪付支付失败:{}", result);
String errMsg = MapUtil.getStr(result, UnionPayCode.RESP_MSG);
throw new PayFailureException(errMsg);
throw new TradeFaileException(errMsg);
}
return MapUtil.getStr(result, UnionPayCode.PAY_APP_TN);
@@ -187,7 +187,7 @@ public class UnionPayService {
if (!unionPayKit.verify(new NoticeParams(result))) {
log.warn("云闪付支付验签失败:{}", result);
throw new PayFailureException("云闪付支付验签失败");
throw new ParamValidationFailException("云闪付支付验签失败");
}
String resultCode = MapUtil.getStr(result, UnionPayCode.RESP_CODE);
@@ -196,7 +196,7 @@ public class UnionPayService {
if (!(Objects.equals(resultCode, UnionPayCode.RESP_SUCCESS))) {
log.warn("云闪付支付失败:{}", result);
String errMsg = MapUtil.getStr(result, UnionPayCode.RESP_MSG);
throw new PayFailureException(errMsg);
throw new TradeFaileException(errMsg);
}
}
}

View File

@@ -1,7 +1,7 @@
package cn.daxpay.single.service.core.channel.wechat.service;
import cn.daxpay.single.core.code.AllocReceiverTypeEnum;
import cn.daxpay.single.core.exception.OperationFailedException;
import cn.daxpay.single.core.exception.OperationFailException;
import cn.daxpay.single.service.code.WeChatPayCode;
import cn.daxpay.single.service.core.channel.wechat.entity.WeChatPayConfig;
import cn.daxpay.single.service.core.payment.allocation.entity.AllocationReceiver;
@@ -109,7 +109,7 @@ public class WeChatPayAllocationReceiverService {
errorMsg = result.get(WeChatPayCode.RETURN_MSG);
}
log.error("分账绑定或解绑失败 {}", errorMsg);
throw new OperationFailedException("分账绑定或解绑失败");
throw new OperationFailException("分账绑定或解绑失败");
}
}
}

View File

@@ -4,6 +4,7 @@ import cn.bootx.platform.common.core.function.CollectorsFunction;
import cn.bootx.platform.common.mybatisplus.base.MpIdEntity;
import cn.daxpay.single.core.code.AllocDetailResultEnum;
import cn.daxpay.single.core.code.AllocReceiverTypeEnum;
import cn.daxpay.single.core.exception.OperationFailException;
import cn.daxpay.single.service.code.WeChatPayCode;
import cn.daxpay.single.service.core.channel.wechat.entity.WeChatPayConfig;
import cn.daxpay.single.service.core.order.allocation.entity.AllocOrder;
@@ -156,7 +157,7 @@ public class WeChatPayAllocationService {
errorMsg = result.get(WeChatPayCode.RETURN_MSG);
}
log.error("分账操作失败 {}", errorMsg);
throw new PayFailureException(errorMsg);
throw new OperationFailException("分账操作失败");
}
}

View File

@@ -1,5 +1,8 @@
package cn.daxpay.single.service.core.channel.wechat.service;
import cn.daxpay.single.core.exception.ConfigErrorException;
import cn.daxpay.single.core.exception.OperationFailException;
import cn.daxpay.single.core.exception.PayFailureException;
import cn.daxpay.single.service.code.WeChatPayCode;
import cn.daxpay.single.service.core.channel.wechat.entity.WeChatPayConfig;
import cn.daxpay.single.service.core.order.pay.entity.PayOrder;
@@ -61,7 +64,7 @@ public class WeChatPayCloseService {
// 获取证书文件
if (StrUtil.isBlank(weChatPayConfig.getP12())){
String errorMsg = "微信p.12证书未配置,无法进行退款";
throw new PayFailureException(errorMsg);
throw new ConfigErrorException(errorMsg);
}
byte[] fileBytes = Base64.decode(weChatPayConfig.getP12());
ByteArrayInputStream inputStream = new ByteArrayInputStream(fileBytes);
@@ -83,7 +86,7 @@ public class WeChatPayCloseService {
errorMsg = result.get(WeChatPayCode.RETURN_MSG);
}
log.error("订单关闭失败 {}", errorMsg);
throw new PayFailureException(errorMsg);
throw new OperationFailException(errorMsg);
}
}

View File

@@ -2,6 +2,7 @@ package cn.daxpay.single.service.core.channel.wechat.service;
import cn.bootx.platform.common.core.exception.DataNotExistException;
import cn.bootx.platform.common.core.rest.dto.LabelValue;
import cn.daxpay.single.core.exception.ConfigNotEnableException;
import cn.daxpay.single.service.code.WeChatPayWay;
import cn.daxpay.single.service.core.channel.wechat.dao.WeChatPayConfigManager;
import cn.daxpay.single.service.core.channel.wechat.entity.WeChatPayConfig;
@@ -38,7 +39,7 @@ public class WeChatPayConfigService {
*/
@Transactional(rollbackFor = Exception.class)
public void update(WeChatPayConfigParam param) {
WeChatPayConfig weChatPayConfig = weChatPayConfigManager.findById(ID).orElseThrow(() -> new PayFailureException("微信支付配置不存在"));
WeChatPayConfig weChatPayConfig = weChatPayConfigManager.findById(ID).orElseThrow(() -> new ConfigNotEnableException("微信支付配置不存在"));
BeanUtil.copyProperties(param, weChatPayConfig, CopyOptions.create().ignoreNullValue());
weChatPayConfigManager.updateById(weChatPayConfig);
}
@@ -57,7 +58,7 @@ public class WeChatPayConfigService {
public WeChatPayConfig getAndCheckConfig(){
WeChatPayConfig weChatPayConfig = getConfig();
if (!weChatPayConfig.getEnable()){
throw new PayFailureException("微信支付未启用");
throw new ConfigNotEnableException("微信支付未启用");
}
return weChatPayConfig;
}

View File

@@ -2,6 +2,8 @@ package cn.daxpay.single.service.core.channel.wechat.service;
import cn.bootx.platform.common.core.util.LocalDateTimeUtil;
import cn.daxpay.single.core.code.ReconcileTradeEnum;
import cn.daxpay.single.core.exception.*;
import cn.daxpay.single.core.util.PayUtil;
import cn.daxpay.single.service.code.ReconcileFileTypeEnum;
import cn.daxpay.single.service.code.WeChatPayCode;
import cn.daxpay.single.service.common.local.PaymentContextLocal;
@@ -12,10 +14,9 @@ import cn.daxpay.single.service.core.channel.wechat.entity.WxReconcileBillDetail
import cn.daxpay.single.service.core.channel.wechat.entity.WxReconcileBillTotal;
import cn.daxpay.single.service.core.channel.wechat.entity.WxReconcileFundFlowDetail;
import cn.daxpay.single.service.core.order.reconcile.dao.ReconcileFileManager;
import cn.daxpay.single.service.core.order.reconcile.entity.ReconcileOutTrade;
import cn.daxpay.single.service.core.order.reconcile.entity.ReconcileFile;
import cn.daxpay.single.service.core.order.reconcile.entity.ReconcileOrder;
import cn.daxpay.single.core.util.PayUtil;
import cn.daxpay.single.service.core.order.reconcile.entity.ReconcileOutTrade;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.io.IoUtil;
@@ -280,16 +281,16 @@ public class WeChatPayReconcileService {
if (Objects.equals(errCode, "20002")){
if (Objects.equals("No Bill Exist",resultMsg)){
log.warn("交易账单不存在, 请检查当前商户号在指定日期内是否有成功的交易");
throw new PayFailureException("交易账单不存在");
throw new OperationFailException("交易账单不存在, 请检查当前商户号在指定日期内是否有成功的交易");
}
if (Objects.equals("Bill Creating",resultMsg)){
log.warn("交易账单未生成, 请在上午10点以后再试");
throw new PayFailureException("交易账单未生成, 请在上午10点以后再试");
throw new OperationFailException("交易账单未生成, 请在上午10点以后再试");
}
} else {
log.error("微信交易对账失败, 原因: {}, 错误码: {}, 错误信息: {}", resultMsg, errCode, res);
throw new PayFailureException("微信支付交易对账失败");
throw new OperationFailException("微信支付交易对账失败");
}
}
@@ -309,7 +310,7 @@ public class WeChatPayReconcileService {
errorMsg = result.get(WeChatPayCode.RETURN_MSG);
}
log.error("微信资金对账失败, 原因: {}, 错误码: {}, 错误信息: {}", errorMsg, returnCode, res);
throw new PayFailureException("微信资金对账失败: " + errorMsg);
throw new OperationFailException("微信资金对账失败: " + errorMsg);
}

View File

@@ -1,6 +1,8 @@
package cn.daxpay.single.service.core.channel.wechat.service;
import cn.daxpay.single.core.code.RefundStatusEnum;
import cn.daxpay.single.core.exception.ConfigErrorException;
import cn.daxpay.single.core.exception.TradeFaileException;
import cn.daxpay.single.service.common.context.ErrorInfoLocal;
import cn.daxpay.single.service.common.context.RefundLocal;
import cn.daxpay.single.service.common.local.PaymentContextLocal;
@@ -58,7 +60,7 @@ public class WeChatPayRefundService {
String errorMsg = "微信p.12证书未配置,无法进行退款";
errorInfo.setErrorMsg(errorMsg);
errorInfo.setErrorCode(RefundStatusEnum.FAIL.getCode());
throw new PayFailureException(errorMsg);
throw new ConfigErrorException(errorMsg);
}
byte[] fileBytes = Base64.decode(weChatPayConfig.getP12());
ByteArrayInputStream inputStream = new ByteArrayInputStream(fileBytes);
@@ -86,7 +88,7 @@ public class WeChatPayRefundService {
ErrorInfoLocal errorInfo = PaymentContextLocal.get().getErrorInfo();
errorInfo.setErrorMsg(errorMsg);
errorInfo.setErrorCode(Optional.ofNullable(resultCode).orElse(returnCode));
throw new PayFailureException(errorMsg);
throw new TradeFaileException(errorMsg);
}
}

View File

@@ -5,8 +5,10 @@ import cn.bootx.platform.common.core.util.LocalDateTimeUtil;
import cn.bootx.platform.common.jackson.util.JacksonUtil;
import cn.bootx.platform.common.spring.exception.RetryableException;
import cn.daxpay.single.core.code.PayMethodEnum;
import cn.daxpay.single.core.exception.*;
import cn.daxpay.single.core.param.payment.pay.PayParam;
import cn.daxpay.single.core.result.sync.PaySyncResult;
import cn.daxpay.single.core.util.PayUtil;
import cn.daxpay.single.service.code.WeChatPayCode;
import cn.daxpay.single.service.code.WeChatPayWay;
import cn.daxpay.single.service.common.context.PayLocal;
@@ -16,7 +18,6 @@ import cn.daxpay.single.service.core.order.pay.entity.PayOrder;
import cn.daxpay.single.service.core.payment.sync.service.PaySyncService;
import cn.daxpay.single.service.param.channel.wechat.WeChatPayParam;
import cn.daxpay.single.service.sdk.wechat.BarPayModel;
import cn.daxpay.single.core.util.PayUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.net.NetUtil;
import cn.hutool.core.util.StrUtil;
@@ -61,21 +62,21 @@ public class WeChatPayService {
public void validation(PayParam payParam, WeChatPayConfig weChatPayConfig) {
List<String> payWays = weChatPayConfig.getPayWays();
if (CollUtil.isEmpty(payWays)){
throw new PayFailureException("未配置微信支付方式");
throw new ConfigNotEnableException("未配置微信支付方式");
}
PayMethodEnum payMethodEnum = Optional.ofNullable(WeChatPayWay.findByCode(payParam.getMethod()))
.orElseThrow(() -> new PayFailureException("非法的微信支付类型"));
.orElseThrow(() -> new MethodNotExistException("非法的微信支付类型"));
if (!payWays.contains(payMethodEnum.getCode())) {
throw new PayFailureException("该微信支付方式不可用");
throw new MethodNotEnableException("该微信支付方式不可用");
}
// 支付金额是否超限
if (payParam.getAmount() > weChatPayConfig.getLimitAmount()) {
throw new PayFailureException("微信支付金额超限");
throw new AmountExceedLimitException("微信支付金额超限");
}
// 是否支持分账
if (Objects.equals(payParam.getAllocation(),true) && !Objects.equals(weChatPayConfig.getAllocation(),true)) {
throw new PayFailureException("未开启分账配置");
throw new ConfigNotEnableException("未开启分账配置");
}
}
@@ -202,7 +203,7 @@ public class WeChatPayService {
// 支付失败
if (!WxPayKit.codeIsOk(returnCode)) {
String errorMsg = result.get(WeChatPayCode.ERR_CODE_DES);
throw new PayFailureException(errorMsg);
throw new TradeFaileException(errorMsg);
}
String resultCode = result.get(WeChatPayCode.RESULT_CODE);
@@ -225,13 +226,13 @@ public class WeChatPayService {
}
// 支付撤销
if (Objects.equals(resultCode, WeChatPayCode.PAY_REVOKED)) {
throw new PayFailureException("用户已撤销支付");
throw new TradeStatusErrorException("用户已撤销支付");
}
// 支付失败
if (Objects.equals(resultCode, WeChatPayCode.TRADE_PAYERROR)
|| Objects.equals(resultCode, WeChatPayCode.PAY_FAIL)) {
String errorMsg = result.get(WeChatPayCode.ERR_CODE_DES);
throw new PayFailureException(errorMsg);
throw new TradeFaileException(errorMsg);
}
}
@@ -268,7 +269,7 @@ public class WeChatPayService {
errorMsg = result.get(WeChatPayCode.RETURN_MSG);
}
log.error("支付失败 {}", errorMsg);
throw new PayFailureException(errorMsg);
throw new TradeFaileException(errorMsg);
}
}

View File

@@ -1,5 +1,6 @@
package cn.daxpay.single.service.core.channel.wechat.service;
import cn.daxpay.single.core.exception.UnsupportedAbilityException;
import cn.daxpay.single.service.core.channel.wechat.entity.WeChatPayConfig;
import cn.daxpay.single.service.core.order.transfer.entity.TransferOrder;
import lombok.RequiredArgsConstructor;
@@ -22,6 +23,6 @@ public class WeChatPayTransferService {
*/
@SneakyThrows
public void transfer(TransferOrder order, WeChatPayConfig config) {
throw new PayFailureException("微信转账暂未实现");
throw new UnsupportedAbilityException("微信转账暂未实现");
}
}

View File

@@ -4,8 +4,10 @@ import cn.daxpay.single.core.code.AllocDetailResultEnum;
import cn.daxpay.single.core.code.AllocOrderResultEnum;
import cn.daxpay.single.core.code.AllocOrderStatusEnum;
import cn.daxpay.single.core.code.PayOrderAllocStatusEnum;
import cn.daxpay.single.core.exception.ParamValidationFailException;
import cn.daxpay.single.core.param.payment.allocation.AllocReceiverParam;
import cn.daxpay.single.core.param.payment.allocation.AllocationParam;
import cn.daxpay.single.core.util.OrderNoGenerateUtil;
import cn.daxpay.single.service.core.order.allocation.dao.AllocOrderDetailManager;
import cn.daxpay.single.service.core.order.allocation.dao.AllocationOrderManager;
import cn.daxpay.single.service.core.order.allocation.entity.AllocOrder;
@@ -16,7 +18,6 @@ import cn.daxpay.single.service.core.order.pay.entity.PayOrder;
import cn.daxpay.single.service.core.payment.allocation.dao.AllocationReceiverManager;
import cn.daxpay.single.service.core.payment.allocation.entity.AllocationReceiver;
import cn.daxpay.single.service.dto.allocation.AllocationGroupReceiverResult;
import cn.daxpay.single.core.util.OrderNoGenerateUtil;
import cn.hutool.core.util.IdUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -96,7 +97,7 @@ public class AllocOrderService {
.distinct()
.collect(Collectors.toList());
if (receiverNos.size() != param.getReceivers().size()){
throw new PayFailureException("分账接收方编号重复");
throw new ParamValidationFailException("分账接收方编号重复");
}
Map<String, Integer> receiverNoMap = param.getReceivers()
.stream()
@@ -104,13 +105,13 @@ public class AllocOrderService {
// 查询分账接收方信息
List<AllocationReceiver> receivers = receiverManager.findAllByReceiverNos(receiverNos);
if (receivers.size() != receiverNos.size()){
throw new PayFailureException("分账接收方列表存在重复或无效的数据");
throw new ParamValidationFailException("分账接收方列表存在重复或无效的数据");
}
// 判断分账接收方类型是否都与分账订单类型匹配
boolean anyMatch = receivers.stream()
.anyMatch(o -> !Objects.equals(o.getChannel(), payOrder.getChannel()));
if (anyMatch){
throw new PayFailureException("分账接收方列表存在非本通道的数据");
throw new ParamValidationFailException("分账接收方列表存在非本通道的数据");
}

View File

@@ -5,7 +5,6 @@ import cn.bootx.platform.common.mybatisplus.base.MpBaseEntity;
import cn.bootx.table.modify.annotation.DbColumn;
import cn.bootx.table.modify.annotation.DbTable;
import cn.bootx.table.modify.mysql.annotation.DbMySqlIndex;
import cn.daxpay.single.code.*;
import cn.daxpay.single.core.code.*;
import cn.daxpay.single.core.param.channel.AliPayParam;
import cn.daxpay.single.core.param.channel.WalletPayParam;

View File

@@ -3,7 +3,7 @@ package cn.daxpay.single.service.core.order.pay.service;
import cn.bootx.platform.common.core.rest.PageResult;
import cn.bootx.platform.common.core.rest.param.PageParam;
import cn.bootx.platform.common.mybatisplus.util.MpUtil;
import cn.daxpay.single.core.exception.ParamValidationFailedException;
import cn.daxpay.single.core.exception.ParamValidationFailException;
import cn.daxpay.single.core.exception.TradeNotExistException;
import cn.daxpay.single.core.param.payment.pay.QueryPayParam;
import cn.daxpay.single.core.result.order.PayOrderResult;
@@ -80,7 +80,7 @@ public class PayOrderQueryService {
public PayOrderResult queryPayOrder(QueryPayParam param) {
// 校验参数
if (StrUtil.isBlank(param.getBizOrderNoeNo()) && Objects.isNull(param.getOrderNo())){
throw new ParamValidationFailedException("业务号或支付单ID不能都为空");
throw new ParamValidationFailException("业务号或支付单ID不能都为空");
}
// 查询支付单
PayOrder payOrder = this.findByBizOrOrderNo(param.getOrderNo(), param.getBizOrderNoeNo())

View File

@@ -4,6 +4,9 @@ import cn.bootx.platform.common.core.exception.DataNotExistException;
import cn.bootx.platform.common.core.rest.PageResult;
import cn.bootx.platform.common.core.rest.param.PageParam;
import cn.bootx.platform.common.mybatisplus.util.MpUtil;
import cn.daxpay.single.core.exception.ParamValidationFailException;
import cn.daxpay.single.core.exception.PayFailureException;
import cn.daxpay.single.core.exception.TradeNotExistException;
import cn.daxpay.single.core.param.payment.refund.QueryRefundParam;
import cn.daxpay.single.core.result.order.RefundOrderResult;
import cn.daxpay.single.service.core.order.refund.convert.RefundOrderConvert;
@@ -75,11 +78,11 @@ public class RefundOrderQueryService {
public RefundOrderResult queryRefundOrder(QueryRefundParam param) {
// 校验参数
if (StrUtil.isBlank(param.getRefundNo()) && Objects.isNull(param.getBizRefundNo())){
throw new PayFailureException("退款号或商户退款号不能都为空");
throw new ParamValidationFailException("退款号或商户退款号不能都为空");
}
// 查询退款单
RefundOrder refundOrder = this.findByBizOrRefundNo(param.getRefundNo(), param.getBizRefundNo())
.orElseThrow(() -> new PayFailureException("退款订单不存在"));
.orElseThrow(() -> new TradeNotExistException("退款订单不存在"));
return RefundOrderConvert.CONVERT.convertResult(refundOrder);
}

View File

@@ -4,6 +4,9 @@ import cn.bootx.platform.common.core.exception.DataNotExistException;
import cn.bootx.platform.common.core.rest.PageResult;
import cn.bootx.platform.common.core.rest.param.PageParam;
import cn.bootx.platform.common.mybatisplus.util.MpUtil;
import cn.daxpay.single.core.exception.ParamValidationFailException;
import cn.daxpay.single.core.exception.PayFailureException;
import cn.daxpay.single.core.exception.TradeNotExistException;
import cn.daxpay.single.core.param.payment.transfer.QueryTransferParam;
import cn.daxpay.single.core.result.order.TransferOrderResult;
import cn.daxpay.single.service.core.order.transfer.convert.TransferOrderConvert;
@@ -75,11 +78,11 @@ public class TransferOrderQueryService {
public TransferOrderResult queryTransferOrder(QueryTransferParam param) {
// 校验参数
if (StrUtil.isBlank(param.getTransferNo()) && Objects.isNull(param.getBizTransferNo())){
throw new PayFailureException("转账号或商户转账号不能都为空");
throw new ParamValidationFailException("转账号或商户转账号不能都为空");
}
// 查询转账单
TransferOrder transferOrder = this.findByBizOrTransferNo(param.getTransferNo(), param.getBizTransferNo())
.orElseThrow(() -> new PayFailureException("转账订单不存在"));
.orElseThrow(() -> new TradeNotExistException("转账订单不存在"));
return TransferOrderConvert.CONVERT.convertResult(transferOrder);
}

View File

@@ -8,6 +8,7 @@ import cn.bootx.platform.common.core.rest.param.PageParam;
import cn.bootx.platform.common.mybatisplus.util.MpUtil;
import cn.daxpay.single.core.code.AllocReceiverTypeEnum;
import cn.daxpay.single.core.code.PayChannelEnum;
import cn.daxpay.single.core.exception.*;
import cn.daxpay.single.core.param.payment.allocation.AllocReceiverAddParam;
import cn.daxpay.single.core.param.payment.allocation.AllocReceiverRemoveParam;
import cn.daxpay.single.core.param.payment.allocation.QueryAllocReceiverParam;
@@ -110,12 +111,12 @@ public class AllocationReceiverService {
// 判断是否已经添加
LockInfo lock = lockTemplate.lock("payment:receiver:" + param.getReceiverNo(),10000,200);
if (Objects.isNull(lock)){
throw new PayFailureException("分账方处理中,请勿重复操作");
throw new OperationProcessingException("分账方处理中,请勿重复操作");
}
try {
Optional<AllocationReceiver> receiverOptional = allocationReceiverManager.findByReceiverNo(param.getReceiverNo());
if (receiverOptional.isPresent()){
throw new PayFailureException("该接收方已存在");
throw new OperationFailException("该接收方已存在");
}
AllocationReceiver receiver = AllocationReceiverConvert.CONVERT.convert(param);
// 获取策略
@@ -123,7 +124,7 @@ public class AllocationReceiverService {
// 校验
receiverStrategy.setAllocationReceiver(receiver);
if (!receiverStrategy.validation()){
throw new PayFailureException("接收方信息校验失败");
throw new ParamValidationFailException("接收方信息校验失败");
}
// 先添加到三方支付系统中, 然后保存到本地
receiverStrategy.doBeforeHandler();
@@ -141,15 +142,15 @@ public class AllocationReceiverService {
public AllocReceiverRemoveResult remove(AllocReceiverRemoveParam param){
// 判断是否存在
AllocationReceiver receiver = allocationReceiverManager.findByReceiverNo(param.getReceiverNo())
.orElseThrow(() -> new PayFailureException("该接收方不存在"));
.orElseThrow(() -> new DataErrorException("该接收方不存在"));
if (groupReceiverManager.isUsed(receiver.getId())){
throw new PayFailureException("该接收方已被使用,无法被删除");
throw new OperationFailException("该接收方已被使用,无法被删除");
}
// 获取策略
AbsAllocationReceiverStrategy receiverStrategy = PayStrategyFactory.create(receiver.getChannel(), AbsAllocationReceiverStrategy.class);
LockInfo lock = lockTemplate.lock("payment:receiver:" + param.getReceiverNo(),10000,200);
if (Objects.isNull(lock)){
throw new PayFailureException("分账方处理中,请勿重复操作");
throw new OperationProcessingException("分账方处理中,请勿重复操作");
}
try {
// 校验

View File

@@ -7,6 +7,7 @@ import cn.daxpay.single.core.code.AllocDetailResultEnum;
import cn.daxpay.single.core.code.AllocOrderResultEnum;
import cn.daxpay.single.core.code.AllocOrderStatusEnum;
import cn.daxpay.single.core.code.PayOrderAllocStatusEnum;
import cn.daxpay.single.core.exception.*;
import cn.daxpay.single.core.param.payment.allocation.AllocFinishParam;
import cn.daxpay.single.core.param.payment.allocation.AllocationParam;
import cn.daxpay.single.core.param.payment.allocation.QueryAllocOrderParam;
@@ -157,7 +158,7 @@ public class AllocationService {
AllocOrderStatusEnum.ALLOCATION_FAILED.getCode(),
AllocOrderStatusEnum.ALLOCATION_PROCESSING.getCode());
if (!list.contains(order.getStatus())){
throw new PayFailureException("分账单状态错误,无法重试");
throw new TradeStatusErrorException("分账单状态错误,无法重试");
}
List<AllocOrderDetail> details = this.getDetails(order.getId());
// 创建分账策略并初始化
@@ -210,7 +211,7 @@ public class AllocationService {
public AllocationResult finish(AllocOrder allocOrder) {
// 只有分账结束后才可以完结
if (!Arrays.asList(ALLOCATION_END.getCode(),FINISH_FAILED.getCode()).contains(allocOrder.getStatus())) {
throw new PayFailureException("分账单状态错误");
throw new TradeStatusErrorException("分账单状态错误");
}
List<AllocOrderDetail> details = this.getDetails(allocOrder.getId());
@@ -246,14 +247,14 @@ public class AllocationService {
private PayOrder getAndCheckPayOrder(AllocationParam param) {
// 查询支付单
PayOrder payOrder = payOrderQueryService.findByBizOrOrderNo(param.getOrderNo(), param.getBizOrderNo())
.orElseThrow(() -> new PayFailureException("支付单不存在"));
.orElseThrow(() -> new TradeNotExistException("支付单不存在"));
// 判断订单是否可以分账
if (!payOrder.getAllocation()){
throw new PayFailureException("该订单不允许分账");
throw new OperationUnsupportedException("该订单不允许分账");
}
// 判断分账状态
if (Objects.equals(PayOrderAllocStatusEnum.ALLOCATION.getCode(), payOrder.getAllocStatus())){
throw new PayFailureException("该订单已分账完成");
throw new TradeStatusErrorException("该订单已分账完成");
}
return payOrder;
}
@@ -264,7 +265,7 @@ public class AllocationService {
public AllocOrderResult queryAllocationOrder(QueryAllocOrderParam param) {
// 查询分账单
AllocOrder allocOrder = allocationOrderManager.findByAllocNo(param.getAllocNo())
.orElseThrow(() -> new PayFailureException("分账单不存在"));
.orElseThrow(() -> new DataErrorException("分账单不存在"));
AllocOrderResult result = AllocOrderConvert.CONVERT.toResult(allocOrder);
// 查询分账单明细
List<AllocOrderDetailResult> details = allocOrderDetailManager.findAllByOrderId(allocOrder.getId()).stream()
@@ -287,14 +288,14 @@ public class AllocationService {
AllocationGroup allocationGroup;
if (Objects.nonNull(param.getGroupNo())){
// 指定分账组
allocationGroup = groupManager.findByGroupNo(param.getGroupNo()).orElseThrow(() -> new DataNotExistException("未查询到分账组"));
allocationGroup = groupManager.findByGroupNo(param.getGroupNo()).orElseThrow(() -> new DataErrorException("未查询到分账组"));
} else {
// 默认分账组
allocationGroup = groupManager.findDefaultGroup(payOrder.getChannel()).orElseThrow(() -> new PayFailureException("未查询到默认分账组"));
allocationGroup = groupManager.findDefaultGroup(payOrder.getChannel()).orElseThrow(() -> new DataErrorException("未查询到默认分账组"));
}
// 判断通道类型是否一致
if (!Objects.equals(allocationGroup.getChannel(), payOrder.getChannel())){
throw new PayFailureException("分账接收方列表存在非本通道的数据");
throw new ParamValidationFailException("分账接收方列表存在非本通道的数据");
}
List<AllocationGroupReceiverResult> receiversByGroups = allocationGroupService.findReceiversByGroups(allocationGroup.getId());

View File

@@ -1,6 +1,8 @@
package cn.daxpay.single.service.core.payment.allocation.strategy.allocation;
import cn.daxpay.single.core.code.PayChannelEnum;
import cn.daxpay.single.core.exception.ConfigNotEnableException;
import cn.daxpay.single.core.exception.PayFailureException;
import cn.daxpay.single.service.core.channel.alipay.entity.AliPayConfig;
import cn.daxpay.single.service.core.channel.alipay.service.AliPayAllocationService;
import cn.daxpay.single.service.core.channel.alipay.service.AliPayConfigService;
@@ -49,7 +51,7 @@ public class AliPayAllocationStrategy extends AbsAllocationStrategy {
this.aliPayConfig = aliPayConfigService.getConfig();
// 判断是否支持分账
if (Objects.equals(aliPayConfig.getAllocation(),false)){
throw new PayFailureException("支付宝支付配置不支持分账");
throw new ConfigNotEnableException("支付宝支付配置未开启分账");
}
}

View File

@@ -1,6 +1,9 @@
package cn.daxpay.single.service.core.payment.allocation.strategy.allocation;
import cn.daxpay.single.core.code.PayChannelEnum;
import cn.daxpay.single.core.exception.ConfigNotEnableException;
import cn.daxpay.single.core.exception.OperationFailException;
import cn.daxpay.single.core.exception.PayFailureException;
import cn.daxpay.single.service.core.channel.wechat.entity.WeChatPayConfig;
import cn.daxpay.single.service.core.channel.wechat.service.WeChatPayAllocationService;
import cn.daxpay.single.service.core.channel.wechat.service.WeChatPayConfigService;
@@ -48,11 +51,11 @@ public class WeChatPayAllocationStrategy extends AbsAllocationStrategy {
weChatPayConfig = weChatPayConfigService.getAndCheckConfig();
// 判断是否支持分账
if (Objects.equals(weChatPayConfig.getAllocation(),false)){
throw new PayFailureException("微信支付配置不支持分账");
throw new ConfigNotEnableException("微信支付未开启分账");
}
// 如果分账金额为0, 不发起分账
if (getAllocOrder().getAmount() == 0){
throw new PayFailureException("微信订单的分账比例不正确或订单金额太小, 无法进行分账");
throw new OperationFailException("微信订单的分账比例不正确或订单金额太小, 无法进行分账");
}
}

View File

@@ -1,6 +1,8 @@
package cn.daxpay.single.service.core.payment.allocation.strategy.receiver;
import cn.daxpay.single.core.code.PayChannelEnum;
import cn.daxpay.single.core.exception.ConfigNotEnableException;
import cn.daxpay.single.core.exception.ParamValidationFailException;
import cn.daxpay.single.service.core.channel.alipay.entity.AliPayConfig;
import cn.daxpay.single.service.core.channel.alipay.service.AliPayAllocationReceiverService;
import cn.daxpay.single.service.core.channel.alipay.service.AliPayConfigService;
@@ -55,7 +57,7 @@ public class AliPayAllocationReceiverStrategy extends AbsAllocationReceiverStrat
this.aliPayConfig = payConfigService.getAndCheckConfig();
// 判断是否支持分账
if (Objects.equals(aliPayConfig.getAllocation(),false)){
throw new PayFailureException("微信支付配置不支持分账");
throw new ConfigNotEnableException("微信支付配置未开启分账");
}
}
@@ -65,7 +67,7 @@ public class AliPayAllocationReceiverStrategy extends AbsAllocationReceiverStrat
@Override
public void bind() {
if (!receiverService.validation(this.getAllocationReceiver())){
throw new PayFailureException("分账接收者参数未通过校验");
throw new ParamValidationFailException("分账接收者参数未通过校验");
}
receiverService.bind(this.getAllocationReceiver(), this.aliPayConfig);
}
@@ -76,7 +78,7 @@ public class AliPayAllocationReceiverStrategy extends AbsAllocationReceiverStrat
@Override
public void unbind() {
if (!receiverService.validation(this.getAllocationReceiver())){
throw new PayFailureException("分账参数未通过校验");
throw new ParamValidationFailException("分账参数未通过校验");
}
receiverService.unbind(this.getAllocationReceiver(), this.aliPayConfig);
}

View File

@@ -1,6 +1,8 @@
package cn.daxpay.single.service.core.payment.allocation.strategy.receiver;
import cn.daxpay.single.core.code.PayChannelEnum;
import cn.daxpay.single.core.exception.ConfigNotEnableException;
import cn.daxpay.single.core.exception.ParamValidationFailException;
import cn.daxpay.single.service.core.channel.wechat.entity.WeChatPayConfig;
import cn.daxpay.single.service.core.channel.wechat.service.WeChatPayAllocationReceiverService;
import cn.daxpay.single.service.core.channel.wechat.service.WeChatPayConfigService;
@@ -55,7 +57,7 @@ public class WeChatPayAllocationReceiverStrategy extends AbsAllocationReceiverSt
this.weChatPayConfig = payConfigService.getAndCheckConfig();
// 判断是否支持分账
if (Objects.equals(weChatPayConfig.getAllocation(),false)){
throw new PayFailureException("微信支付配置不支持分账");
throw new ConfigNotEnableException("微信支付配置未开启分账");
}
}
@@ -65,7 +67,7 @@ public class WeChatPayAllocationReceiverStrategy extends AbsAllocationReceiverSt
@Override
public void bind() {
if (!receiverService.validation(this.getAllocationReceiver())){
throw new PayFailureException("分账接收者参数未通过校验");
throw new ParamValidationFailException("分账接收者参数未通过校验");
}
receiverService.bind(this.getAllocationReceiver(),this.weChatPayConfig);
}
@@ -76,7 +78,7 @@ public class WeChatPayAllocationReceiverStrategy extends AbsAllocationReceiverSt
@Override
public void unbind() {
if (!receiverService.validation(this.getAllocationReceiver())){
throw new PayFailureException("分账参数未通过校验");
throw new ParamValidationFailException("分账参数未通过校验");
}
receiverService.unbind(this.getAllocationReceiver(),this.weChatPayConfig);
}

View File

@@ -2,6 +2,9 @@ package cn.daxpay.single.service.core.payment.cancel.service;
import cn.bootx.platform.common.core.exception.RepetitiveOperationException;
import cn.daxpay.single.core.code.PayStatusEnum;
import cn.daxpay.single.core.exception.OperationFailException;
import cn.daxpay.single.core.exception.TradeNotExistException;
import cn.daxpay.single.core.exception.TradeStatusErrorException;
import cn.daxpay.single.core.param.payment.pay.PayCancelParam;
import cn.daxpay.single.core.result.pay.PayCancelResult;
import cn.daxpay.single.service.code.PayCloseTypeEnum;
@@ -44,7 +47,7 @@ public class PayCancelService {
*/
public PayCancelResult cancel(PayCancelParam param){
PayOrder payOrder = payOrderQueryService.findByBizOrOrderNo(param.getOrderNo(), param.getBizOrderNo())
.orElseThrow(() -> new PayFailureException("支付订单不存在"));
.orElseThrow(() -> new TradeNotExistException("支付订单不存在"));
LockInfo lock = lockTemplate.lock("payment:cancel:" + payOrder.getId(),10000, 50);
if (Objects.isNull(lock)){
throw new RepetitiveOperationException("支付订单已在撤销中,请勿重复发起");
@@ -53,7 +56,7 @@ public class PayCancelService {
PayCancelResult result = new PayCancelResult();
// 状态检查, 只有支付中可以进行撤销支付
if (!Objects.equals(payOrder.getStatus(), PayStatusEnum.PROGRESS.getCode())) {
throw new PayFailureException("订单不是支付中, 无法进行撤销订单");
throw new TradeStatusErrorException("订单不是支付中, 无法进行撤销订单");
}
try {
AbsPayCancelStrategy strategy = PayStrategyFactory.create(payOrder.getChannel(), AbsPayCancelStrategy.class);
@@ -72,7 +75,7 @@ public class PayCancelService {
log.error("撤销订单失败:", e);
// 记录撤销失败的记录
this.saveRecord(payOrder, false, e.getMessage());
throw new PayFailureException("撤销订单失败");
throw new OperationFailException("撤销订单失败");
}
} finally {
lockTemplate.releaseLock(lock);

View File

@@ -2,6 +2,9 @@ package cn.daxpay.single.service.core.payment.close.service;
import cn.bootx.platform.common.core.exception.RepetitiveOperationException;
import cn.daxpay.single.core.code.PayStatusEnum;
import cn.daxpay.single.core.exception.OperationFailException;
import cn.daxpay.single.core.exception.TradeNotExistException;
import cn.daxpay.single.core.exception.TradeStatusErrorException;
import cn.daxpay.single.core.param.payment.pay.PayCloseParam;
import cn.daxpay.single.core.result.pay.PayCloseResult;
import cn.daxpay.single.service.code.PayCloseTypeEnum;
@@ -44,7 +47,7 @@ public class PayCloseService {
*/
public PayCloseResult close(PayCloseParam param){
PayOrder payOrder = payOrderQueryService.findByBizOrOrderNo(param.getOrderNo(), param.getBizOrderNo())
.orElseThrow(() -> new PayFailureException("支付订单不存在"));
.orElseThrow(() -> new TradeNotExistException("支付订单不存在"));
LockInfo lock = lockTemplate.lock("payment:close:" + payOrder.getId(),10000, 50);
if (Objects.isNull(lock)){
throw new RepetitiveOperationException("支付订单已在关闭中,请勿重复发起");
@@ -63,7 +66,7 @@ public class PayCloseService {
PayCloseResult result = new PayCloseResult();
// 状态检查, 只有支付中可以进行取消支付
if (!Objects.equals(payOrder.getStatus(), PayStatusEnum.PROGRESS.getCode())) {
throw new PayFailureException("订单不是支付中, 无法进行关闭订单");
throw new TradeStatusErrorException("订单不是支付中, 无法进行关闭订单");
}
try {
AbsPayCloseStrategy strategy = PayStrategyFactory.create(payOrder.getChannel(), AbsPayCloseStrategy.class);
@@ -82,7 +85,7 @@ public class PayCloseService {
log.error("关闭订单失败:", e);
// 记录关闭失败的记录
this.saveRecord(payOrder, false, e.getMessage());
throw new PayFailureException("关闭订单失败");
throw new OperationFailException("关闭订单失败");
}
}

View File

@@ -1,6 +1,7 @@
package cn.daxpay.single.service.core.payment.common.aop;
import cn.bootx.platform.common.core.exception.DataNotExistException;
import cn.daxpay.single.core.exception.ConfigErrorException;
import cn.daxpay.single.core.exception.ConfigNotEnableException;
import cn.daxpay.single.service.annotation.InitPaymentContext;
import cn.daxpay.single.service.core.system.config.dao.PayApiConfigManager;
import cn.daxpay.single.service.core.system.config.entity.PayApiConfig;
@@ -36,9 +37,9 @@ public class InitPlatformInfoAop {
String code = platformContext.value();
// 接口信息
PayApiConfig api = payApiConfigManager.findByCode(code)
.orElseThrow(() -> new DataNotExistException("未找到接口信息"));
.orElseThrow(() -> new ConfigErrorException("未找到接口信息"));
if (!api.isEnable()){
throw new PayFailureException("该接口权限未开放");
throw new ConfigNotEnableException("该接口权限未开放");
}
// 初始化平台信息
platformConfigService.initPlatform();

View File

@@ -2,11 +2,13 @@ package cn.daxpay.single.service.core.payment.common.aop;
import cn.bootx.platform.common.core.rest.ResResult;
import cn.bootx.platform.common.core.util.ValidationUtil;
import cn.daxpay.single.core.exception.ParamValidationFailException;
import cn.daxpay.single.core.exception.PayFailureException;
import cn.daxpay.single.core.param.PaymentCommonParam;
import cn.daxpay.single.core.result.PaymentCommonResult;
import cn.daxpay.single.core.util.DaxRes;
import cn.daxpay.single.service.annotation.PaymentVerify;
import cn.daxpay.single.service.core.payment.common.service.PaymentAssistService;
import cn.daxpay.single.core.util.DaxRes;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
@@ -33,7 +35,7 @@ public class PaymentVerifyAop {
public Object beforeMethod(ProceedingJoinPoint pjp, @SuppressWarnings("unused") PaymentVerify paymentVerify) throws Throwable {
Object[] args = pjp.getArgs();
if (args.length == 0){
throw new PayFailureException("支付方法至少有一个参数,并且需要签名支付参数需要放在第一位");
throw new ParamValidationFailException("支付方法至少有一个参数,并且需要签名支付参数需要放在第一位");
}
Object param = args[0];
if (param instanceof PaymentCommonParam){
@@ -47,7 +49,7 @@ public class PaymentVerifyAop {
paymentAssistService.reqTimeoutVerify((PaymentCommonParam) param);
} else {
throw new PayFailureException("支付参数需要继承PayCommonParam");
throw new ParamValidationFailException("支付参数需要继承PayCommonParam");
}
Object proceed;
try {
@@ -67,10 +69,10 @@ public class PaymentVerifyAop {
if (data instanceof PaymentCommonResult){
paymentAssistService.sign((PaymentCommonResult) data);
} else {
throw new PayFailureException("支付方法返回类型需要为 ResResult<T extends PaymentCommonResult> 格式");
throw new ParamValidationFailException("支付方法返回类型需要为 ResResult<T extends PaymentCommonResult> 格式");
}
} else {
throw new PayFailureException("支付方法返回类型需要为 ResResult<T extends PaymentCommonResult> 格式");
throw new ParamValidationFailException("支付方法返回类型需要为 ResResult<T extends PaymentCommonResult> 格式");
}
return proceed;
}

View File

@@ -2,7 +2,7 @@ package cn.daxpay.single.service.core.payment.common.service;
import cn.bootx.platform.common.core.util.LocalDateTimeUtil;
import cn.daxpay.single.core.code.PaySignTypeEnum;
import cn.daxpay.single.core.exception.PayFailureException;
import cn.daxpay.single.core.exception.ParamValidationFailException;
import cn.daxpay.single.core.exception.VerifySignFailedException;
import cn.daxpay.single.core.param.PaymentCommonParam;
import cn.daxpay.single.core.result.PaymentCommonResult;
@@ -86,12 +86,12 @@ public class PaymentAssistService {
if (LocalDateTimeUtil.lt(now, param.getReqTime())){
// 请求时间比服务器时间晚, 超过一分钟直接打回
if (durationSeconds > 60){
throw new PayFailureException("请求时间晚于服务器接收到的时间,请检查");
throw new ParamValidationFailException("请求时间晚于服务器接收到的时间,请检查");
}
} else {
// 请求时间比服务器时间早, 超过配置时间直接打回
if (durationSeconds > platformInfo.getReqTimeout()){
throw new PayFailureException("请求已过期,请重新发送!");
throw new ParamValidationFailException("请求已过期,请重新发送!");
}
}
@@ -113,7 +113,7 @@ public class PaymentAssistService {
} else if (Objects.equals(PaySignTypeEnum.MD5.getCode(), signType)){
result.setSign(PaySignUtil.md5Sign(result, platformInfo.getSignSecret()));
} else {
throw new PayFailureException("未获取到签名方式,请检查");
throw new ParamValidationFailException("未获取到签名方式,请检查");
}
}
}

View File

@@ -6,8 +6,12 @@ import cn.daxpay.single.core.code.PayChannelEnum;
import cn.daxpay.single.core.code.PayOrderAllocStatusEnum;
import cn.daxpay.single.core.code.PayOrderRefundStatusEnum;
import cn.daxpay.single.core.code.PayStatusEnum;
import cn.daxpay.single.core.exception.AmountExceedLimitException;
import cn.daxpay.single.core.exception.TradeStatusErrorException;
import cn.daxpay.single.core.param.payment.pay.PayParam;
import cn.daxpay.single.core.result.pay.PayResult;
import cn.daxpay.single.core.util.OrderNoGenerateUtil;
import cn.daxpay.single.core.util.PayUtil;
import cn.daxpay.single.service.common.context.PayLocal;
import cn.daxpay.single.service.common.context.PlatformLocal;
import cn.daxpay.single.service.common.local.PaymentContextLocal;
@@ -15,8 +19,6 @@ import cn.daxpay.single.service.core.order.pay.entity.PayOrder;
import cn.daxpay.single.service.core.order.pay.service.PayOrderQueryService;
import cn.daxpay.single.service.core.order.pay.service.PayOrderService;
import cn.daxpay.single.service.core.payment.sync.service.PaySyncService;
import cn.daxpay.single.core.util.OrderNoGenerateUtil;
import cn.daxpay.single.core.util.PayUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import lombok.RequiredArgsConstructor;
@@ -122,26 +124,26 @@ public class PayAssistService {
// 如果支付超时, 触发订单同步操作, 同时抛出异常
if (Objects.nonNull(payOrder.getExpiredTime()) && LocalDateTimeUtil.ge(LocalDateTime.now(), payOrder.getExpiredTime())) {
paySyncService.syncPayOrder(payOrder);
throw new PayFailureException("支付已超时,请重新确认支付状态");
throw new TradeStatusErrorException("支付已超时,请重新确认支付状态");
}
return payOrder;
}
// 已经支付状态
if (SUCCESS.getCode()
.equals(payOrder.getStatus())) {
throw new PayFailureException("已经支付成功,请勿重新支付");
throw new TradeStatusErrorException("已经支付成功,请勿重新支付");
}
// 支付失败类型状态
List<String> tradesStatus = Arrays.asList(FAIL.getCode(), CLOSE.getCode(), CANCEL.getCode());
if (tradesStatus.contains(payOrder.getStatus())) {
throw new PayFailureException("支付失败或已经被关闭");
throw new TradeStatusErrorException("支付失败或已经被关闭");
}
// 退款类型状态
if (Objects.equals(payOrder.getRefundStatus(), PayOrderRefundStatusEnum.REFUNDING.getCode())) {
throw new PayFailureException("该订单处于退款状态");
throw new TradeStatusErrorException("该订单处于退款状态");
}
// 其他状态直接抛出兜底异常
throw new PayFailureException("订单不是待支付状态,请重新确认订单状态");
throw new TradeStatusErrorException("订单不是待支付状态,请重新确认订单状态");
}
return null;
}
@@ -153,7 +155,7 @@ public class PayAssistService {
// 总额校验
PlatformLocal platformInfo = PaymentContextLocal.get().getPlatformInfo();
if (payParam.getAmount() > platformInfo.getLimitAmount()) {
throw new PayFailureException("支付金额超过限额");
throw new AmountExceedLimitException("支付金额超过限额");
}
}

View File

@@ -1,6 +1,7 @@
package cn.daxpay.single.service.core.payment.pay.strategy;
import cn.daxpay.single.core.code.PayChannelEnum;
import cn.daxpay.single.core.exception.ParamValidationFailException;
import cn.daxpay.single.core.param.channel.AliPayParam;
import cn.daxpay.single.service.core.channel.alipay.entity.AliPayConfig;
import cn.daxpay.single.service.core.channel.alipay.service.AliPayConfigService;
@@ -57,7 +58,7 @@ public class AliPayStrategy extends AbsPayStrategy {
}
}
catch (JSONException e) {
throw new PayFailureException("支付参数错误");
throw new ParamValidationFailException("支付参数错误");
}
// 检查并获取支付宝支付配置
this.alipayConfig = alipayConfigService.getAndCheckConfig();

View File

@@ -1,6 +1,7 @@
package cn.daxpay.single.service.core.payment.pay.strategy;
import cn.daxpay.single.core.code.PayChannelEnum;
import cn.daxpay.single.core.exception.ParamValidationFailException;
import cn.daxpay.single.core.param.channel.UnionPayParam;
import cn.daxpay.single.service.core.channel.union.entity.UnionPayConfig;
import cn.daxpay.single.service.core.channel.union.service.UnionPayConfigService;
@@ -59,7 +60,7 @@ public class UnionPayStrategy extends AbsPayStrategy {
}
}
catch (JSONException e) {
throw new PayFailureException("支付参数错误");
throw new ParamValidationFailException("支付参数错误");
}
// 检查并获取云闪付支付配置
this.unionPayConfig = unionPayConfigService.getAndCheckConfig();

View File

@@ -1,7 +1,7 @@
package cn.daxpay.single.service.core.payment.pay.strategy;
import cn.daxpay.single.core.code.PayChannelEnum;
import cn.daxpay.single.core.exception.PayFailureException;
import cn.daxpay.single.core.exception.*;
import cn.daxpay.single.core.param.channel.WalletPayParam;
import cn.daxpay.single.service.code.WalletCode;
import cn.daxpay.single.service.core.channel.wallet.entity.Wallet;
@@ -59,7 +59,7 @@ public class WalletPayStrategy extends AbsPayStrategy {
walletPayParam = BeanUtil.toBean(channelParam, WalletPayParam.class);
}
} catch (JSONException e) {
throw new PayFailureException("支付参数错误");
throw new ParamValidationFailException("支付参数错误");
}
WalletConfig walletConfig = walletConfigService.getAndCheckConfig();
@@ -67,23 +67,23 @@ public class WalletPayStrategy extends AbsPayStrategy {
// 获取钱包
this.wallet = walletQueryService.getWallet(walletPayParam);
if (Objects.isNull(this.wallet)){
throw new PayFailureException("钱包不存在");
throw new TradeFaileException("钱包不存在");
}
// 是否被禁用
if (Objects.equals(WalletCode.STATUS_FORBIDDEN, this.wallet.getStatus())) {
throw new PayFailureException();
throw new ConfigNotEnableException();
}
// 判断是否超过限额
if (this.getPayParam().getAmount() > walletConfig.getLimitAmount()){
throw new PayFailureException("钱包支付金额超过限额");
throw new AmountExceedLimitException("钱包支付金额超过限额");
}
// 判断余额
if (this.wallet.getBalance() < this.getPayParam().getAmount()) {
throw new PayFailureException();
throw new ConfigErrorException();
}
// 分账
if (Objects.equals(this.getPayParam().getAllocation(),true)){
throw new PayFailureException("钱包支付不支持分账");
throw new UnsupportedAbilityException("钱包支付不支持分账");
}
}

View File

@@ -4,6 +4,8 @@ import cn.bootx.platform.common.core.exception.DataNotExistException;
import cn.bootx.platform.common.core.util.CollUtil;
import cn.bootx.platform.common.core.util.LocalDateTimeUtil;
import cn.daxpay.single.core.code.PayChannelEnum;
import cn.daxpay.single.core.exception.OperationFailException;
import cn.daxpay.single.core.util.OrderNoGenerateUtil;
import cn.daxpay.single.service.code.ReconcileFileTypeEnum;
import cn.daxpay.single.service.code.ReconcileResultEnum;
import cn.daxpay.single.service.common.local.PaymentContextLocal;
@@ -22,7 +24,6 @@ import cn.daxpay.single.service.dto.order.reconcile.ReconcileTradeDetailExcel;
import cn.daxpay.single.service.func.AbsReconcileStrategy;
import cn.daxpay.single.service.param.reconcile.ReconcileUploadParam;
import cn.daxpay.single.service.util.PayStrategyFactory;
import cn.daxpay.single.core.util.OrderNoGenerateUtil;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.util.CharsetUtil;
@@ -100,7 +101,7 @@ public class ReconcileService {
public void downAndSave(ReconcileOrder reconcileOrder) {
// 如果对账单已经存在
if (reconcileOrder.isDownOrUpload()){
throw new PayFailureException("对账单文件已经下载或上传");
throw new OperationFailException("对账单文件已经下载或上传");
}
// 将对账订单写入到上下文中
PaymentContextLocal.get().getReconcileInfo().setReconcileOrder(reconcileOrder);
@@ -173,11 +174,11 @@ public class ReconcileService {
public void compare(ReconcileOrder reconcileOrder){
// 判断是否已经下载了对账单明细
if (!reconcileOrder.isDownOrUpload()){
throw new PayFailureException("请先下载对账单");
throw new OperationFailException("请先下载对账单");
}
// 是否对比完成
if (reconcileOrder.isCompare()){
throw new PayFailureException("对账单比对已经完成");
throw new OperationFailException("对账单比对已经完成");
}
// 查询对账单
List<ReconcileOutTrade> reconcileTradeDetails = reconcileOutTradeManager.findAllByReconcileId(reconcileOrder.getId());

View File

@@ -4,8 +4,12 @@ import cn.daxpay.single.core.code.PayOrderRefundStatusEnum;
import cn.daxpay.single.core.code.PaySignTypeEnum;
import cn.daxpay.single.core.code.PayStatusEnum;
import cn.daxpay.single.core.code.RefundStatusEnum;
import cn.daxpay.single.core.exception.ParamValidationFailException;
import cn.daxpay.single.core.exception.TradeStatusErrorException;
import cn.daxpay.single.core.param.payment.refund.RefundParam;
import cn.daxpay.single.core.result.pay.RefundResult;
import cn.daxpay.single.core.util.OrderNoGenerateUtil;
import cn.daxpay.single.core.util.PaySignUtil;
import cn.daxpay.single.service.common.context.ErrorInfoLocal;
import cn.daxpay.single.service.common.context.PlatformLocal;
import cn.daxpay.single.service.common.context.RefundLocal;
@@ -13,8 +17,6 @@ import cn.daxpay.single.service.common.local.PaymentContextLocal;
import cn.daxpay.single.service.core.order.pay.entity.PayOrder;
import cn.daxpay.single.service.core.order.refund.dao.RefundOrderManager;
import cn.daxpay.single.service.core.order.refund.entity.RefundOrder;
import cn.daxpay.single.core.util.OrderNoGenerateUtil;
import cn.daxpay.single.core.util.PaySignUtil;
import cn.hutool.core.util.StrUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -47,7 +49,7 @@ public class RefundAssistService {
// 非支付完成的不能进行退款
if (!Objects.equals(SUCCESS.getCode(), payOrder.getStatus())) {
PayStatusEnum statusEnum = PayStatusEnum.findByCode(payOrder.getStatus());
throw new PayFailureException("当前支付单订状态["+statusEnum.getName()+"]不允许发起退款操作");
throw new TradeStatusErrorException("当前支付单订状态["+statusEnum.getName()+"]不允许发起退款操作");
}
// 退款中和退款完成不能退款
List<String> tradesStatus = Arrays.asList(
@@ -55,16 +57,16 @@ public class RefundAssistService {
PayOrderRefundStatusEnum.REFUNDING.getCode());
if (tradesStatus.contains(payOrder.getRefundStatus())){
val statusEnum = PayOrderRefundStatusEnum.findByCode(payOrder.getRefundStatus());
throw new PayFailureException("当前支付单退款状态["+statusEnum.getName()+"]不允许发起退款操作");
throw new TradeStatusErrorException("当前支付单退款状态["+statusEnum.getName()+"]不允许发起退款操作");
}
// 退款号唯一校验
if (StrUtil.isNotBlank(param.getBizRefundNo()) && refundOrderManager.existsByRefundNo(param.getBizRefundNo())){
throw new PayFailureException("退款单号已存在");
throw new ParamValidationFailException("退款单号已存在");
}
// 金额判断
if (param.getAmount() > payOrder.getRefundableBalance()){
throw new PayFailureException("退款金额不能大于支付金额");
throw new ParamValidationFailException("退款金额不能大于支付金额");
}
}
@@ -143,7 +145,7 @@ public class RefundAssistService {
} else if (Objects.equals(PaySignTypeEnum.MD5.getCode(), signType)){
refundResult.setSign(PaySignUtil.md5Sign(refundOrder, platformInfo.getSignSecret()));
} else {
throw new PayFailureException("未获取到签名方式,请检查");
throw new ParamValidationFailException("未获取到签名方式,请检查");
}
return refundResult;
}

View File

@@ -4,6 +4,8 @@ import cn.bootx.platform.common.core.exception.DataNotExistException;
import cn.bootx.platform.common.core.util.ValidationUtil;
import cn.daxpay.single.core.code.PayOrderRefundStatusEnum;
import cn.daxpay.single.core.code.RefundStatusEnum;
import cn.daxpay.single.core.exception.TradeNotExistException;
import cn.daxpay.single.core.exception.TradeStatusErrorException;
import cn.daxpay.single.core.param.payment.refund.RefundParam;
import cn.daxpay.single.core.result.pay.RefundResult;
import cn.daxpay.single.service.common.context.RefundLocal;
@@ -142,11 +144,11 @@ public class RefundService {
public RefundResult repeatRefund(RefundOrder refundOrder, RefundParam param){
// 退款失败才可以重新发起退款, 重新发起退款
if (!Objects.equals(refundOrder.getStatus(), RefundStatusEnum.FAIL.getCode())){
throw new PayFailureException("只有失败状态的才可以重新发起退款");
throw new TradeStatusErrorException("只有失败状态的才可以重新发起退款");
}
// 获取支付订单
PayOrder payOrder = payOrderQueryService.findByBizOrOrderNo(refundOrder.getOrderNo(), refundOrder.getBizOrderNo())
.orElseThrow(() -> new DataNotExistException("支付订单不存在"));
.orElseThrow(() -> new TradeNotExistException("支付订单不存在"));
AbsRefundStrategy refundStrategy = PayStrategyFactory.create(refundOrder.getChannel(), AbsRefundStrategy.class);
// 设置退款订单对象
refundStrategy.setRefundOrder(refundOrder);

View File

@@ -6,6 +6,7 @@ import cn.daxpay.single.core.code.PayChannelEnum;
import cn.daxpay.single.core.code.PayOrderRefundStatusEnum;
import cn.daxpay.single.core.code.PayStatusEnum;
import cn.daxpay.single.core.code.PaySyncStatusEnum;
import cn.daxpay.single.core.exception.*;
import cn.daxpay.single.core.param.payment.pay.PaySyncParam;
import cn.daxpay.single.core.result.sync.PaySyncResult;
import cn.daxpay.single.service.code.PayRepairSourceEnum;
@@ -63,11 +64,11 @@ public class PaySyncService {
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public PaySyncResult sync(PaySyncParam param) {
PayOrder payOrder = payOrderQueryService.findByBizOrOrderNo(param.getOrderNo(), param.getBizOrderNo())
.orElseThrow(() -> new PayFailureException("支付订单不存在"));
.orElseThrow(() -> new TradeNotExistException("支付订单不存在"));
// 钱包支付钱包不需要同步
if (PayChannelEnum.WALLET.getCode().equals(payOrder.getChannel())){
throw new PayFailureException("支付订单不需要同步");
throw new TradeStatusErrorException("支付订单不需要同步");
}
// 执行订单同步逻辑
return this.syncPayOrder(payOrder);
@@ -95,7 +96,7 @@ public class PaySyncService {
if (Objects.equals(payRemoteSyncResult.getSyncStatus(), PaySyncStatusEnum.FAIL)){
// 同步失败, 返回失败响应, 同时记录失败的日志
this.saveRecord(payOrder, payRemoteSyncResult, false, null, payRemoteSyncResult.getErrorMsg());
throw new PayFailureException(payRemoteSyncResult.getErrorMsg());
throw new OperationFailException(payRemoteSyncResult.getErrorMsg());
}
// 支付订单的网关订单号是否一致, 不一致进行更新
if (!Objects.equals(payRemoteSyncResult.getOutOrderNo(), payOrder.getOutOrderNo())){
@@ -195,7 +196,7 @@ public class PaySyncService {
break;
}
case REFUND:
throw new PayFailureException("支付订单为退款状态,请通过执行对应的退款订单进行同步,来更新具体为什么类型退款状态");
throw new TradeStatusErrorException("支付订单为退款状态,请通过执行对应的退款订单进行同步,来更新具体为什么类型退款状态");
// 交易关闭和未找到, 都对本地支付订单进行关闭, 不需要再调用网关进行关闭
case CLOSED:
case NOT_FOUND: {
@@ -215,7 +216,7 @@ public class PaySyncService {
break;
}
default: {
throw new PayFailureException("代码有问题");
throw new SystemUnknownErrorException("代码有问题");
}
}
return repair;

View File

@@ -4,6 +4,9 @@ import cn.bootx.platform.common.core.exception.BizException;
import cn.bootx.platform.common.core.exception.RepetitiveOperationException;
import cn.daxpay.single.core.code.RefundStatusEnum;
import cn.daxpay.single.core.code.RefundSyncStatusEnum;
import cn.daxpay.single.core.exception.OperationFailException;
import cn.daxpay.single.core.exception.PayFailureException;
import cn.daxpay.single.core.exception.TradeNotExistException;
import cn.daxpay.single.core.param.payment.refund.RefundSyncParam;
import cn.daxpay.single.core.result.sync.RefundSyncResult;
import cn.daxpay.single.service.code.PayRepairSourceEnum;
@@ -57,7 +60,7 @@ public class RefundSyncService {
public RefundSyncResult sync(RefundSyncParam param){
// 先获取退款单
RefundOrder refundOrder = refundOrderQueryService.findByBizOrRefundNo(param.getRefundNo(), param.getBizRefundNo())
.orElseThrow(() -> new PayFailureException("未查询到退款订单"));
.orElseThrow(() -> new TradeNotExistException("未查询到退款订单"));
// 如果订单已经关闭, 直接返回退款关闭
if (Objects.equals(refundOrder.getStatus(), RefundStatusEnum.CLOSE.getCode())){
return new RefundSyncResult().setStatus(RefundStatusEnum.CLOSE.getCode());
@@ -88,7 +91,7 @@ public class RefundSyncService {
if (Objects.equals(refundRemoteSyncResult.getSyncStatus(), RefundSyncStatusEnum.FAIL)) {
// 同步失败, 返回失败响应, 同时记录失败的日志
this.saveRecord(refundOrder, refundRemoteSyncResult, false, null, refundRemoteSyncResult.getErrorMsg());
throw new PayFailureException(refundRemoteSyncResult.getErrorMsg());
throw new OperationFailException(refundRemoteSyncResult.getErrorMsg());
}
// 订单的通道交易号是否一致, 不一致进行更新
if (Objects.nonNull(refundRemoteSyncResult.getOutRefundNo()) && !Objects.equals(refundRemoteSyncResult.getOutRefundNo(), refundOrder.getOutRefundNo())){

View File

@@ -1,6 +1,7 @@
package cn.daxpay.single.service.core.payment.transfer.strategy;
import cn.daxpay.single.core.code.PayChannelEnum;
import cn.daxpay.single.core.exception.ParamValidationFailException;
import cn.daxpay.single.core.param.payment.transfer.TransferParam;
import cn.daxpay.single.service.core.channel.alipay.entity.AliPayConfig;
import cn.daxpay.single.service.core.channel.alipay.service.AliPayConfigService;
@@ -46,7 +47,7 @@ public class AliPayTransferStrategy extends AbsTransferStrategy {
// 转账接收方类型校验
String payeeType = transferParam.getPayeeType();
if (!Arrays.asList(ALI_USER_ID.getCode(), ALI_OPEN_ID.getCode(), ALI_LOGIN_NAME.getCode()).contains(payeeType)){
throw new PayFailureException("支付宝不支持该类型收款人");
throw new ParamValidationFailException("支付宝不支持该类型收款人");
}
}

View File

@@ -1,6 +1,7 @@
package cn.daxpay.single.service.core.payment.transfer.strategy;
import cn.daxpay.single.core.code.PayChannelEnum;
import cn.daxpay.single.core.exception.ParamValidationFailException;
import cn.daxpay.single.core.param.payment.transfer.TransferParam;
import cn.daxpay.single.service.core.channel.wechat.entity.WeChatPayConfig;
import cn.daxpay.single.service.core.channel.wechat.service.WeChatPayConfigService;
@@ -47,7 +48,7 @@ public class WeChatTransferStrategy extends AbsTransferStrategy {
// 转账接收方类型校验
String payeeType = transferParam.getPayeeType();
if (!Objects.equals(WX_PERSONAL.getCode(), payeeType)){
throw new PayFailureException("支付宝不支持该类型收款人");
throw new ParamValidationFailException("支付宝不支持该类型收款人");
}
}