pay:同步最新功能的代码(钱包、转账)

This commit is contained in:
YunaiV
2023-10-24 08:00:01 +08:00
parent 9fc31ac2ae
commit df2b1b45a4
122 changed files with 5161 additions and 455 deletions

View File

@@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.pay.api.order;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO;
import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderRespDTO;
import cn.iocoder.yudao.module.pay.enums.ApiConstants;
@@ -15,8 +16,6 @@ import org.springframework.web.bind.annotation.RequestParam;
import javax.validation.Valid;
// TODO 芋艿CommonResult
@FeignClient(name = ApiConstants.NAME) // TODO 芋艿fallbackFactory =
@Tag(name = "RPC 服务 - 支付单")
public interface PayOrderApi {
@@ -25,12 +24,12 @@ public interface PayOrderApi {
@PostMapping(PREFIX + "/create")
@Operation(summary = "创建支付单")
Long createOrder(@Valid @RequestBody PayOrderCreateReqDTO reqDTO);
CommonResult<Long> createOrder(@Valid @RequestBody PayOrderCreateReqDTO reqDTO);
@PostMapping(PREFIX + "/get")
@Operation(summary = "获得支付单")
@Parameter(name = "id", description = "支付单编号", example = "1", required = true)
PayOrderRespDTO getOrder(Long id);
CommonResult<PayOrderRespDTO> getOrder(Long id);
@PutMapping(PREFIX + "/update-price")
@Operation(summary = "更新支付订单价格")
@@ -38,7 +37,7 @@ public interface PayOrderApi {
@Parameter(name = "id", description = "支付单编号", example = "1", required = true),
@Parameter(name = "payPrice", description = "支付单价格", example = "100", required = true)
})
void updatePayOrderPrice(@RequestParam("id") Long id,
@RequestParam("payPrice") Integer payPrice);
CommonResult<Boolean> updatePayOrderPrice(@RequestParam("id") Long id,
@RequestParam("payPrice") Integer payPrice);
}

View File

@@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.pay.api.refund;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.pay.api.refund.dto.PayRefundCreateReqDTO;
import cn.iocoder.yudao.module.pay.api.refund.dto.PayRefundRespDTO;
import cn.iocoder.yudao.module.pay.enums.ApiConstants;
@@ -20,11 +21,11 @@ public interface PayRefundApi {
@PostMapping(PREFIX + "/create")
@Operation(summary = "创建退款单")
Long createRefund(@Valid @RequestBody PayRefundCreateReqDTO reqDTO);
CommonResult<Long> createRefund(@Valid @RequestBody PayRefundCreateReqDTO reqDTO);
@PostMapping(PREFIX + "/get")
@Operation(summary = "获得退款单")
@Parameter(name = "id", description = "退款单编号", example = "1", required = true)
PayRefundRespDTO getRefund(Long id);
CommonResult<PayRefundRespDTO> getRefund(Long id);
}

View File

@@ -0,0 +1,24 @@
package cn.iocoder.yudao.module.pay.api.transfer;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.pay.api.transfer.dto.PayTransferCreateReqDTO;
import cn.iocoder.yudao.module.pay.enums.ApiConstants;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import javax.validation.Valid;
@FeignClient(name = ApiConstants.NAME) // TODO 芋艿fallbackFactory =
@Tag(name = "RPC 服务 - 转账单")
public interface PayTransferApi {
String PREFIX = ApiConstants.PREFIX + "/transfer";
@PostMapping(PREFIX + "/create")
@Operation(summary = "创建转账单")
CommonResult<Long> createTransfer(@Valid @RequestBody PayTransferCreateReqDTO reqDTO);
}

View File

@@ -0,0 +1,43 @@
package cn.iocoder.yudao.module.pay.api.transfer.dto;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.pay.enums.transfer.PayTransferTypeEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Map;
@Schema(description = "RPC 服务 - 转账单创建 Request DTO")
@Data
public class PayTransferCreateReqDTO {
@Schema(description = "应用编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@NotNull(message = "应用编号不能为空")
private Long appId;
@Schema(description = "类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "转账类型不能为空")
@InEnum(PayTransferTypeEnum.class)
private Integer type;
@Schema(description = "商户订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "M101") // 例如说,内部系统 A 的订单号。需要保证每个 PayMerchantDO 唯一
@NotEmpty(message = "商户订单编号不能为空")
private String merchantOrderId;
@Schema(description = "转账金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "80")
@Min(value = 1, message = "转账金额必须大于零")
@NotNull(message = "转账金额不能为空")
private Integer price;
@Schema(description = "转账标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是标题")
@NotEmpty(message = "转账标题不能为空")
private String title;
@Schema(description = "收款方信息", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "收款方信息不能为空")
private Map<String, String> payeeInfo;
}

View File

@@ -21,17 +21,17 @@ public interface ErrorCodeConstants {
ErrorCode CHANNEL_EXIST_SAME_CHANNEL_ERROR = new ErrorCode(1_007_001_004, "已存在相同的渠道");
// ========== ORDER 模块 1-007-002-000 ==========
ErrorCode ORDER_NOT_FOUND = new ErrorCode(1_007_002_000, "支付订单不存在");
ErrorCode ORDER_STATUS_IS_NOT_WAITING = new ErrorCode(1_007_002_001, "支付订单不处于待支付");
ErrorCode ORDER_STATUS_IS_SUCCESS = new ErrorCode(1_007_002_002, "订单已支付,请刷新页面");
ErrorCode ORDER_IS_EXPIRED = new ErrorCode(1_007_002_003, "支付订单已经过期");
ErrorCode ORDER_SUBMIT_CHANNEL_ERROR = new ErrorCode(1_007_002_004, "发起支付报错,错误码:{},错误提示:{}");
ErrorCode ORDER_REFUND_FAIL_STATUS_ERROR = new ErrorCode(1_007_002_005, "支付订单退款失败,原因:状态不是已支付或已退款");
ErrorCode PAY_ORDER_NOT_FOUND = new ErrorCode(1_007_002_000, "支付订单不存在");
ErrorCode PAY_ORDER_STATUS_IS_NOT_WAITING = new ErrorCode(1_007_002_001, "支付订单不处于待支付");
ErrorCode PAY_ORDER_STATUS_IS_SUCCESS = new ErrorCode(1_007_002_002, "订单已支付,请刷新页面");
ErrorCode PAY_ORDER_IS_EXPIRED = new ErrorCode(1_007_002_003, "支付订单已经过期");
ErrorCode PAY_ORDER_SUBMIT_CHANNEL_ERROR = new ErrorCode(1_007_002_004, "发起支付报错,错误码:{},错误提示:{}");
ErrorCode PAY_ORDER_REFUND_FAIL_STATUS_ERROR = new ErrorCode(1_007_002_005, "支付订单退款失败,原因:状态不是已支付或已退款");
// ========== ORDER 模块(拓展单) 1-007-003-000 ==========
ErrorCode ORDER_EXTENSION_NOT_FOUND = new ErrorCode(1_007_003_000, "支付交易拓展单不存在");
ErrorCode ORDER_EXTENSION_STATUS_IS_NOT_WAITING = new ErrorCode(1_007_003_001, "支付交易拓展单不处于待支付");
ErrorCode ORDER_EXTENSION_IS_PAID = new ErrorCode(1_007_003_002, "订单已支付,请等待支付结果");
ErrorCode PAY_ORDER_EXTENSION_NOT_FOUND = new ErrorCode(1_007_003_000, "支付交易拓展单不存在");
ErrorCode PAY_ORDER_EXTENSION_STATUS_IS_NOT_WAITING = new ErrorCode(1_007_003_001, "支付交易拓展单不处于待支付");
ErrorCode PAY_ORDER_EXTENSION_IS_PAID = new ErrorCode(1_007_003_002, "订单已支付,请等待支付结果");
// ========== 支付模块(退款) 1-007-006-000 ==========
ErrorCode REFUND_PRICE_EXCEED = new ErrorCode(1_007_006_000, "退款金额超过订单可退款金额");
@@ -40,6 +40,42 @@ public interface ErrorCodeConstants {
ErrorCode REFUND_NOT_FOUND = new ErrorCode(1_007_006_004, "支付退款单不存在");
ErrorCode REFUND_STATUS_IS_NOT_WAITING = new ErrorCode(1_007_006_005, "支付退款单不处于待退款");
// ========== 钱包模块 1-007-007-000 ==========
ErrorCode WALLET_NOT_FOUND = new ErrorCode(1_007_007_000, "用户钱包不存在");
ErrorCode WALLET_BALANCE_NOT_ENOUGH = new ErrorCode(1_007_007_001, "钱包余额不足");
ErrorCode WALLET_TRANSACTION_NOT_FOUND = new ErrorCode(1_007_007_002, "未找到对应的钱包交易");
ErrorCode WALLET_REFUND_EXIST = new ErrorCode(1_007_007_003, "已经存在钱包退款");
ErrorCode WALLET_FREEZE_PRICE_NOT_ENOUGH = new ErrorCode(1_007_007_004, "钱包冻结余额不足");
// ========== 钱包充值模块 1-007-008-000 ==========
ErrorCode WALLET_RECHARGE_NOT_FOUND = new ErrorCode(1_007_008_000, "钱包充值记录不存在");
ErrorCode WALLET_RECHARGE_UPDATE_PAID_STATUS_NOT_UNPAID = new ErrorCode(1_007_008_001, "钱包充值更新支付状态失败,钱包充值记录不是【未支付】状态");
ErrorCode WALLET_RECHARGE_UPDATE_PAID_PAY_ORDER_ID_ERROR = new ErrorCode(1_007_008_002, "钱包充值更新支付状态失败,支付单编号不匹配");
ErrorCode WALLET_RECHARGE_UPDATE_PAID_PAY_ORDER_STATUS_NOT_SUCCESS = new ErrorCode(1_007_008_003, "钱包充值更新支付状态失败,支付单状态不是【支付成功】状态");
ErrorCode WALLET_RECHARGE_UPDATE_PAID_PAY_PRICE_NOT_MATCH = new ErrorCode(1_007_008_004, "钱包充值更新支付状态失败,支付单金额不匹配");
ErrorCode WALLET_RECHARGE_REFUND_FAIL_NOT_PAID = new ErrorCode(1_007_008_005, "钱包发起退款失败,钱包充值订单未支付");
ErrorCode WALLET_RECHARGE_REFUND_FAIL_REFUNDED = new ErrorCode(1_007_008_006, "钱包发起退款失败,钱包充值订单已退款");
ErrorCode WALLET_RECHARGE_REFUND_BALANCE_NOT_ENOUGH = new ErrorCode(1_007_008_007, "钱包发起退款失败,钱包余额不足");
ErrorCode WALLET_RECHARGE_REFUND_FAIL_REFUND_ORDER_ID_ERROR = new ErrorCode(1_007_008_008, "钱包退款更新失败,钱包退款单编号不匹配");
ErrorCode WALLET_RECHARGE_REFUND_FAIL_REFUND_NOT_FOUND = new ErrorCode(1_007_008_009, "钱包退款更新失败,退款订单不存在");
ErrorCode WALLET_RECHARGE_REFUND_FAIL_REFUND_PRICE_NOT_MATCH = new ErrorCode(1_007_008_010, "钱包退款更新失败,退款单金额不匹配");
ErrorCode WALLET_RECHARGE_PACKAGE_AND_PRICE_IS_EMPTY = new ErrorCode(1_007_008_011, "充值金额和充钱套餐不能同时为空");
ErrorCode WALLET_RECHARGE_PACKAGE_NOT_FOUND = new ErrorCode(1_007_008_012, "钱包充值套餐不存在");
ErrorCode WALLET_RECHARGE_PACKAGE_IS_DISABLE = new ErrorCode(1_007_008_013, "钱包充值套餐已禁用");
ErrorCode WALLET_RECHARGE_PACKAGE_NAME_EXISTS = new ErrorCode(1_007_008_014, "钱包充值套餐名称已存在");
// ========== 转账模块 1-007-009-000 ==========
ErrorCode PAY_TRANSFER_SUBMIT_CHANNEL_ERROR = new ErrorCode(1_007_009_000, "发起转账报错,错误码:{},错误提示:{}");
ErrorCode PAY_TRANSFER_ALIPAY_LOGIN_ID_IS_EMPTY = new ErrorCode(1_007_009_001, "支付宝登录 ID 不能为空");
ErrorCode PAY_TRANSFER_ALIPAY_ACCOUNT_NAME_IS_EMPTY = new ErrorCode(1_007_009_002, "支付宝账号名称不能为空");
ErrorCode PAY_TRANSFER_NOT_FOUND = new ErrorCode(1_007_009_003, "转账交易单不存在");
ErrorCode PAY_TRANSFER_STATUS_IS_SUCCESS = new ErrorCode(1_007_009_004, "转账单已成功转账");
ErrorCode PAY_TRANSFER_STATUS_IS_NOT_WAITING = new ErrorCode(1_007_009_005, "转账单不处于待转账");
ErrorCode PAY_TRANSFER_STATUS_IS_NOT_PENDING = new ErrorCode(1_007_009_006, "转账单不处于待转账或转账中");
ErrorCode PAY_TRANSFER_EXTENSION_NOT_FOUND = new ErrorCode(1_007_009_007, "转账交易拓展单不存在");
ErrorCode PAY_TRANSFER_TYPE_AND_CHANNEL_NOT_MATCH = new ErrorCode(1_007_009_008, "转账类型和转账渠道不匹配");
ErrorCode PAY_TRANSFER_EXTENSION_STATUS_IS_NOT_PENDING = new ErrorCode(1_007_009_009, "转账拓展单不处于待转账或转账中");
// ========== 示例订单 1-007-900-000 ==========
ErrorCode DEMO_ORDER_NOT_FOUND = new ErrorCode(1_007_900_000, "示例订单不存在");
ErrorCode DEMO_ORDER_UPDATE_PAID_STATUS_NOT_UNPAID = new ErrorCode(1_007_900_001, "示例订单更新支付状态失败,订单不是【未支付】状态");

View File

@@ -1,21 +0,0 @@
package cn.iocoder.yudao.module.pay.enums.member;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 钱包操作类型枚举
*
* @author jason
*/
@AllArgsConstructor
@Getter
public enum WalletOperateTypeEnum {
TOP_UP_INC(1, "充值增加"),
ORDER_DEC(2, "订单消费扣除");
// TODO 其它类型
private final Integer type;
private final String desc;
}

View File

@@ -1,26 +0,0 @@
package cn.iocoder.yudao.module.pay.enums.member;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 钱包交易大类枚举
*
* @author jason
*/
@AllArgsConstructor
@Getter
public enum WalletTransactionGategoryEnum {
TOP_UP(1, "充值"),
SPENDING(2, "支出");
/**
* 分类
*/
private final Integer category;
/**
* 说明
*/
private final String desc;
}

View File

@@ -0,0 +1,55 @@
package cn.iocoder.yudao.module.pay.enums.transfer;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Objects;
/**
* @author jason
*/
@Getter
@AllArgsConstructor
public enum PayTransferStatusEnum {
WAITING(0, "待转账"),
/**
* TODO 转账到银行卡. 会有T+0 T+1 到账的请情况。 还未实现
*/
IN_PROGRESS(10, "转账进行中"),
SUCCESS(20, "转账成功"),
/**
* 转账关闭 (失败,或者其它情况)
*/
CLOSED(30, "转账关闭");
/**
* 状态
*/
private final Integer status;
/**
* 状态名
*/
private final String name;
public static boolean isSuccess(Integer status) {
return Objects.equals(status, SUCCESS.getStatus());
}
public static boolean isClosed(Integer status) {
return Objects.equals(status, CLOSED.getStatus());
}
public static boolean isWaiting(Integer status) {
return Objects.equals(status, WAITING.getStatus());
}
/**
* 是否处于待转账或者转账中的状态
* @param status 状态
*/
public static boolean isPendingStatus(Integer status) {
return Objects.equals(status, WAITING.getStatus()) || Objects.equals(status, IN_PROGRESS.status);
}
}

View File

@@ -0,0 +1,41 @@
package cn.iocoder.yudao.module.pay.enums.transfer;
import cn.hutool.core.util.ArrayUtil;
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
/**
* 转账类型枚举
*
* @author jason
*/
@AllArgsConstructor
@Getter
public enum PayTransferTypeEnum implements IntArrayValuable {
ALIPAY_BALANCE(1, "支付宝余额"),
WX_BALANCE(2, "微信余额"),
BANK_CARD(3, "银行卡"),
WALLET_BALANCE(4, "钱包余额");
public static final String ALIPAY_LOGON_ID = "ALIPAY_LOGON_ID";
public static final String ALIPAY_ACCOUNT_NAME = "ALIPAY_ACCOUNT_NAME";
private final Integer type;
private final String name;
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(PayTransferTypeEnum::getType).toArray();
@Override
public int[] array() {
return ARRAYS;
}
public static PayTransferTypeEnum typeOf(Integer type) {
return ArrayUtil.firstMatch(item -> item.getType().equals(type), values());
}
}