feat(payment): 初始化支付模块核心代码
- 添加支付常量类PaymentConstants,定义支付状态、微信、支付宝、银联等相关常量 - 创建微信支付类型常量类WechatPayType,支持JSAPI、NATIVE、H5、APP支付方式 - 新增支付控制器PaymentController,提供创建支付、查询状态、退款等统一接口 - 实现支付回调控制器PaymentNotifyController,处理微信、支付宝、银联异步通知 - 添加支付请求数据传输对象PaymentRequest,支持多种支付方式参数校验 - 定义支付响应、状态更新请求等相关DTO类- 集成Swagger注解,完善接口文档说明- 添加参数校验和异常处理机制,确保支付流程安全可靠
This commit is contained in:
141
java/payment/enums/PaymentStatus.java
Normal file
141
java/payment/enums/PaymentStatus.java
Normal file
@@ -0,0 +1,141 @@
|
||||
package com.gxwebsoft.payment.enums;
|
||||
|
||||
/**
|
||||
* 支付状态枚举
|
||||
* 定义支付过程中的各种状态
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2025-01-26
|
||||
*/
|
||||
public enum PaymentStatus {
|
||||
|
||||
/** 待支付 */
|
||||
PENDING(0, "待支付", "PENDING"),
|
||||
|
||||
/** 支付中 */
|
||||
PROCESSING(1, "支付中", "PROCESSING"),
|
||||
|
||||
/** 支付成功 */
|
||||
SUCCESS(2, "支付成功", "SUCCESS"),
|
||||
|
||||
/** 支付失败 */
|
||||
FAILED(3, "支付失败", "FAILED"),
|
||||
|
||||
/** 支付取消 */
|
||||
CANCELLED(4, "支付取消", "CANCELLED"),
|
||||
|
||||
/** 支付超时 */
|
||||
TIMEOUT(5, "支付超时", "TIMEOUT"),
|
||||
|
||||
/** 退款中 */
|
||||
REFUNDING(6, "退款中", "REFUNDING"),
|
||||
|
||||
/** 退款成功 */
|
||||
REFUNDED(7, "退款成功", "REFUNDED"),
|
||||
|
||||
/** 退款失败 */
|
||||
REFUND_FAILED(8, "退款失败", "REFUND_FAILED"),
|
||||
|
||||
/** 部分退款 */
|
||||
PARTIAL_REFUNDED(9, "部分退款", "PARTIAL_REFUNDED");
|
||||
|
||||
private final Integer code;
|
||||
private final String name;
|
||||
private final String status;
|
||||
|
||||
PaymentStatus(Integer code, String name, String status) {
|
||||
this.code = code;
|
||||
this.name = name;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据代码获取支付状态
|
||||
*/
|
||||
public static PaymentStatus getByCode(Integer code) {
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
for (PaymentStatus status : values()) {
|
||||
if (status.code.equals(code)) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据状态字符串获取支付状态
|
||||
*/
|
||||
public static PaymentStatus getByStatus(String status) {
|
||||
if (status == null) {
|
||||
return null;
|
||||
}
|
||||
for (PaymentStatus paymentStatus : values()) {
|
||||
if (paymentStatus.status.equals(status)) {
|
||||
return paymentStatus;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为最终状态(不会再变化)
|
||||
*/
|
||||
public boolean isFinalStatus() {
|
||||
return this == SUCCESS || this == FAILED || this == CANCELLED ||
|
||||
this == TIMEOUT || this == REFUNDED || this == REFUND_FAILED;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为成功状态
|
||||
*/
|
||||
public boolean isSuccessStatus() {
|
||||
return this == SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为失败状态
|
||||
*/
|
||||
public boolean isFailedStatus() {
|
||||
return this == FAILED || this == CANCELLED || this == TIMEOUT || this == REFUND_FAILED;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为退款相关状态
|
||||
*/
|
||||
public boolean isRefundStatus() {
|
||||
return this == REFUNDING || this == REFUNDED || this == REFUND_FAILED || this == PARTIAL_REFUNDED;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否可以退款
|
||||
*/
|
||||
public boolean canRefund() {
|
||||
return this == SUCCESS || this == PARTIAL_REFUNDED;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否可以取消
|
||||
*/
|
||||
public boolean canCancel() {
|
||||
return this == PENDING || this == PROCESSING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("PaymentStatus{code=%d, name='%s', status='%s'}", code, name, status);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user