1. 迁移创建支付交易单接口
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package cn.iocoder.mall.payservice.enums;
|
||||
|
||||
import cn.iocoder.common.framework.exception.ErrorCode;
|
||||
|
||||
/**
|
||||
* 错误码枚举类
|
||||
*
|
||||
* 管理员系统,使用 1-004-000-000 段
|
||||
*/
|
||||
public interface PayErrorCodeConstants {
|
||||
|
||||
// ========== APP 模块 ==========
|
||||
ErrorCode PAY_APP_NOT_FOUND = new ErrorCode(1004000000, "App 不存在");
|
||||
ErrorCode PAY_APP_IS_DISABLE = new ErrorCode(1004000001, "App 已经被禁用");
|
||||
|
||||
// ========== TRANSACTION PAY 模块 ==========
|
||||
ErrorCode PAY_TRANSACTION_NOT_FOUND = new ErrorCode(100401000, "支付交易单不存在");
|
||||
ErrorCode PAY_TRANSACTION_STATUS_IS_NOT_WAITING = new ErrorCode(100401001, "支付交易单不处于待支付");
|
||||
ErrorCode PAY_TRANSACTION_STATUS_IS_NOT_SUCCESS = new ErrorCode(100401002, "支付交易单不处于已支付");
|
||||
ErrorCode PAY_TRANSACTION_ERROR_USER = new ErrorCode(100401003, "支付交易单用户不正确");
|
||||
|
||||
ErrorCode PAY_TRANSACTION_EXTENSION_NOT_FOUND = new ErrorCode(100401050, "支付交易拓展单不存在");
|
||||
ErrorCode PAY_TRANSACTION_EXTENSION_STATUS_IS_NOT_WAITING = new ErrorCode(100401051, "支付交易拓展单不处于待支付");
|
||||
ErrorCode PAY_TRANSACTION_EXTENSION_STATUS_IS_NOT_SUCCESS = new ErrorCode(100401052, "支付交易单不处于已支付");
|
||||
|
||||
// ========== TRANSACTION REFUND 模块 ==========
|
||||
ErrorCode PAY_REFUND_PRICE_EXCEED = new ErrorCode(100402000, "退款金额超过支付交易单可退金额");
|
||||
ErrorCode PAY_REFUND_NOT_FOUND = new ErrorCode(100402001, "退款单不存在");
|
||||
ErrorCode PAY_REFUND_STATUS_NOT_WAITING = new ErrorCode(100402002, "退款单不处于待处理");
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package cn.iocoder.mall.payservice.enums.transaction;
|
||||
|
||||
/**
|
||||
* 支付交易状态枚举
|
||||
*/
|
||||
public enum PayTransactionStatusEnum {
|
||||
|
||||
WAITING(1, "等待支付"),
|
||||
SUCCESS(2, "支付成功"),
|
||||
CANCEL(3, "取消支付"), // 例如说,支付单超时
|
||||
;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private Integer value;
|
||||
/**
|
||||
* 名字
|
||||
*/
|
||||
private String name;
|
||||
|
||||
PayTransactionStatusEnum(Integer value, String name) {
|
||||
this.value = value;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public PayTransactionStatusEnum setValue(Integer value) {
|
||||
this.value = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public PayTransactionStatusEnum setName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
package cn.iocoder.mall.payservice.rpc;
|
||||
@@ -1,10 +1,19 @@
|
||||
package cn.iocoder.mall.payservice.rpc.transaction;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.payservice.rpc.transaction.dto.PayTransactionCreateReqDTO;
|
||||
|
||||
/**
|
||||
* 支付交易单 RPC 接口
|
||||
*/
|
||||
public interface PayTransactionRpc {
|
||||
|
||||
|
||||
/**
|
||||
* 创建支付交易单
|
||||
*
|
||||
* @param createReqDTO 创建信息
|
||||
* @return 支付交易单号
|
||||
*/
|
||||
CommonResult<Integer> createPayTransaction(PayTransactionCreateReqDTO createReqDTO);
|
||||
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
<dependency>
|
||||
<!-- 支付服务 -->
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<artifactId>product-service-api</artifactId>
|
||||
<artifactId>pay-service-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package cn.iocoder.mall.payservice.convert.app;
|
||||
|
||||
import cn.iocoder.mall.payservice.dal.mysql.dataobject.app.PayAppDO;
|
||||
import cn.iocoder.mall.payservice.rpc.app.dto.PayAppRespDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper
|
||||
public interface PayAppConvert {
|
||||
|
||||
PayAppConvert INSTANCE = Mappers.getMapper(PayAppConvert.class);
|
||||
|
||||
PayAppRespDTO convert(PayAppDO bean);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package cn.iocoder.mall.payservice.convert.transaction;
|
||||
|
||||
import cn.iocoder.mall.payservice.dal.mysql.dataobject.transaction.PayTransactionDO;
|
||||
import cn.iocoder.mall.payservice.rpc.transaction.dto.PayTransactionCreateReqDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper
|
||||
public interface PayTransactionConvert {
|
||||
|
||||
PayTransactionConvert INSTANCE = Mappers.getMapper(PayTransactionConvert.class);
|
||||
|
||||
PayTransactionDO convert(PayTransactionCreateReqDTO bean);
|
||||
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package cn.iocoder.mall.payservice.convert.transaction;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper
|
||||
public interface TransactionConvert {
|
||||
|
||||
TransactionConvert INSTANCE = Mappers.getMapper(TransactionConvert.class);
|
||||
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package cn.iocoder.mall.payservice.dal.mysql.dataobject.app;
|
||||
|
||||
import cn.iocoder.mall.mybatis.core.dataobject.DeletableDO;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
@@ -10,6 +11,7 @@ import lombok.experimental.Accessors;
|
||||
*
|
||||
* 每个接入的业务都是一个应用,进行个性化的配置
|
||||
*/
|
||||
@TableName("pay_app")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Accessors(chain = true)
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package cn.iocoder.mall.payservice.dal.mysql.mapper.app;
|
||||
|
||||
import cn.iocoder.mall.payservice.dal.mysql.dataobject.app.PayAppDO;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface PayAppMapper extends BaseMapper<PayAppDO> {
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package cn.iocoder.mall.payservice.dal.mysql.mapper.transaction;
|
||||
|
||||
import cn.iocoder.mall.payservice.dal.mysql.dataobject.transaction.PayTransactionDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@@ -12,4 +13,9 @@ public interface PayTransactionMapper extends BaseMapper<PayTransactionDO> {
|
||||
// new QueryWrapperX<PayTransactionDO>());
|
||||
// }
|
||||
|
||||
default PayTransactionDO selectByAppIdAndOrderId(String appId, String orderId) {
|
||||
return selectOne(new QueryWrapper<PayTransactionDO>().eq("app_id", appId)
|
||||
.eq("order_id", orderId));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,22 @@
|
||||
package cn.iocoder.mall.payservice.rpc.transaction;
|
||||
|
||||
public class PayTransactionRpcImpl {
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.payservice.rpc.transaction.dto.PayTransactionCreateReqDTO;
|
||||
import cn.iocoder.mall.payservice.service.transaction.PayTransactionService;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
|
||||
@DubboService
|
||||
public class PayTransactionRpcImpl implements PayTransactionRpc {
|
||||
|
||||
@Autowired
|
||||
private PayTransactionService payTransactionService;
|
||||
|
||||
@Override
|
||||
public CommonResult<Integer> createPayTransaction(PayTransactionCreateReqDTO createReqDTO) {
|
||||
return success(payTransactionService.createPayTransaction(createReqDTO));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,20 @@
|
||||
package cn.iocoder.mall.payservice.service.app;
|
||||
|
||||
import cn.iocoder.mall.payservice.rpc.app.dto.PayAppRespDTO;
|
||||
|
||||
/**
|
||||
* 支付应用 Service 接口
|
||||
*/
|
||||
public interface PayAppService {
|
||||
|
||||
|
||||
/**
|
||||
* 交易支付应用的合法性
|
||||
*
|
||||
* 如果不合法,抛出 {@link cn.iocoder.common.framework.exception.ServiceException} 业务异常
|
||||
*
|
||||
* @param payAppId 应用编号
|
||||
* @return 应用信息
|
||||
*/
|
||||
PayAppRespDTO validPayApp(String payAppId);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,25 +1,38 @@
|
||||
package cn.iocoder.mall.payservice.service.app.impl;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.mall.payservice.convert.app.PayAppConvert;
|
||||
import cn.iocoder.mall.payservice.dal.mysql.dataobject.app.PayAppDO;
|
||||
import cn.iocoder.mall.payservice.dal.mysql.mapper.app.PayAppMapper;
|
||||
import cn.iocoder.mall.payservice.rpc.app.dto.PayAppRespDTO;
|
||||
import cn.iocoder.mall.payservice.service.app.PayAppService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import static cn.iocoder.mall.payservice.enums.PayErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 支付应用 Service 实现类
|
||||
*/
|
||||
@Service
|
||||
public class PayAppServiceImpl implements PayAppService {
|
||||
|
||||
@Autowired
|
||||
private PayAppMapper payAppMapper;
|
||||
|
||||
|
||||
// public PayAppDO validPayApp(String appId) {
|
||||
// PayAppDO payAppDO = payAppMapper.selectById(appId);
|
||||
// // 校验是否存在
|
||||
// if (payAppDO == null) {
|
||||
// throw ServiceExceptionUtil.exception(PayErrorCodeEnum.PAY_APP_NOT_FOUND.getCode());
|
||||
// }
|
||||
// // 校验是否禁用
|
||||
// if (CommonStatusEnum.DISABLE.getValue().equals(payAppDO.getStatus())) {
|
||||
// throw ServiceExceptionUtil.exception(PayErrorCodeEnum.PAY_APP_IS_DISABLE.getCode());
|
||||
// }
|
||||
// return payAppDO;
|
||||
// }
|
||||
@Override
|
||||
public PayAppRespDTO validPayApp(String payAppId) {
|
||||
PayAppDO payAppDO = payAppMapper.selectById(payAppId);
|
||||
// 校验是否存在
|
||||
if (payAppDO == null) {
|
||||
throw ServiceExceptionUtil.exception(PAY_APP_NOT_FOUND);
|
||||
}
|
||||
// 校验是否禁用
|
||||
if (CommonStatusEnum.DISABLE.getValue().equals(payAppDO.getStatus())) {
|
||||
throw ServiceExceptionUtil.exception(PAY_APP_IS_DISABLE);
|
||||
}
|
||||
return PayAppConvert.INSTANCE.convert(payAppDO);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
package cn.iocoder.mall.payservice.service.transaction;
|
||||
|
||||
import cn.iocoder.mall.payservice.rpc.transaction.dto.PayTransactionCreateReqDTO;
|
||||
|
||||
/**
|
||||
* 支付交易单 Service 接口
|
||||
*/
|
||||
public interface PayTransactionService {
|
||||
|
||||
|
||||
/**
|
||||
* 创建支付交易单
|
||||
*
|
||||
* @param createReqDTO 创建信息
|
||||
* @return 支付交易单号
|
||||
*/
|
||||
Integer createPayTransaction(PayTransactionCreateReqDTO createReqDTO);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
package cn.iocoder.mall.payservice.service.transaction.impl;
|
||||
|
||||
import cn.iocoder.mall.payservice.convert.transaction.PayTransactionConvert;
|
||||
import cn.iocoder.mall.payservice.dal.mysql.dataobject.transaction.PayTransactionDO;
|
||||
import cn.iocoder.mall.payservice.dal.mysql.mapper.transaction.PayTransactionMapper;
|
||||
import cn.iocoder.mall.payservice.enums.transaction.PayTransactionStatusEnum;
|
||||
import cn.iocoder.mall.payservice.rpc.app.dto.PayAppRespDTO;
|
||||
import cn.iocoder.mall.payservice.rpc.transaction.dto.PayTransactionCreateReqDTO;
|
||||
import cn.iocoder.mall.payservice.service.app.PayAppService;
|
||||
import cn.iocoder.mall.payservice.service.transaction.PayTransactionService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -11,87 +18,36 @@ import org.springframework.validation.annotation.Validated;
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
@Slf4j
|
||||
public class PayTransactionServiceImpl implements PayTransactionService {
|
||||
|
||||
@Autowired
|
||||
private PayTransactionMapper transactionMapper;
|
||||
private PayTransactionMapper payTransactionMapper;
|
||||
|
||||
@Autowired
|
||||
private PayAppService payAppService;
|
||||
|
||||
@Override
|
||||
public Integer createPayTransaction(PayTransactionCreateReqDTO createReqDTO) {
|
||||
// 校验 App
|
||||
PayAppRespDTO payAppRespDTO = payAppService.validPayApp(createReqDTO.getAppId());
|
||||
|
||||
// /**
|
||||
// * 创建pay_transaction
|
||||
// *
|
||||
// * @param createBO 创建pay_transaction BO
|
||||
// * @return pay_transaction
|
||||
// */
|
||||
// public TransactionBO createTransaction(@Valid TransactionCreateBO createBO) {
|
||||
// // 插入到数据库
|
||||
// PayTransactionDO transactionDO = TransactionConvert.INSTANCE.convert(createBO);
|
||||
// transactionMapper.insert(transactionDO);
|
||||
// // 返回
|
||||
// return TransactionConvert.INSTANCE.convert(transactionDO);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 更新pay_transaction
|
||||
// *
|
||||
// * @param updateBO 更新pay_transaction BO
|
||||
// */
|
||||
// public void updateTransaction(@Valid TransactionUpdateBO updateBO) {
|
||||
// // 校验更新的pay_transaction是否存在
|
||||
// if (transactionMapper.selectById(updateBO.getId()) == null) {
|
||||
// throw ServiceExceptionUtil.exception(AuthErrorCodeConstants.TRANSACTION_NOT_FOUND);
|
||||
// }
|
||||
// // 更新到数据库
|
||||
// PayTransactionDO updateObject = TransactionConvert.INSTANCE.convert(updateBO);
|
||||
// transactionMapper.updateById(updateObject);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 删除pay_transaction
|
||||
// *
|
||||
// * @param transactionId pay_transaction编号
|
||||
// */
|
||||
// public void deleteTransaction(Integer transactionId) {
|
||||
// // 校验删除的pay_transaction是否存在
|
||||
// if (transactionMapper.selectById(transactionId) == null) {
|
||||
// throw ServiceExceptionHelper.exception(AuthErrorCodeConstants.TRANSACTION_NOT_FOUND);
|
||||
// }
|
||||
// // 标记删除
|
||||
// transactionMapper.deleteById(transactionId);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 获得pay_transaction
|
||||
// *
|
||||
// * @param transactionId pay_transaction编号
|
||||
// * @return pay_transaction
|
||||
// */
|
||||
// public TransactionBO getTransaction(Integer transactionId) {
|
||||
// PayTransactionDO transactionDO = transactionMapper.selectById(transactionId);
|
||||
// return TransactionConvert.INSTANCE.convert(transactionDO);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 获得pay_transaction列表
|
||||
// *
|
||||
// * @param transactionIds pay_transaction编号列表
|
||||
// * @return pay_transaction列表
|
||||
// */
|
||||
// public List<TransactionBO> listTransactions(List<Integer> transactionIds) {
|
||||
// List<PayTransactionDO> transactionDOs = transactionMapper.selectBatchIds(transactionIds);
|
||||
// return TransactionConvert.INSTANCE.convertList(transactionDOs);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 获得pay_transaction分页
|
||||
// *
|
||||
// * @param pageBO pay_transaction分页查询
|
||||
// * @return pay_transaction分页结果
|
||||
// */
|
||||
// public PageResult<TransactionBO> pageTransaction(TransactionPageBO pageBO) {
|
||||
// IPage<PayTransactionDO> transactionDOPage = transactionMapper.selectPage(pageBO);
|
||||
// return TransactionConvert.INSTANCE.convertPage(transactionDOPage);
|
||||
// }
|
||||
// 查询对应的支付交易单是否已经存在。如果是,则直接返回
|
||||
PayTransactionDO payTransaction = payTransactionMapper.selectByAppIdAndOrderId(
|
||||
createReqDTO.getAppId(), createReqDTO.getOrderId());
|
||||
if (payTransaction != null) {
|
||||
log.warn("[createTransaction][appId({}) orderId({}) 已经存在对应的支付交易单({})]", createReqDTO.getAppId(),
|
||||
createReqDTO.getOrderId(), payTransaction.toString()); // 理论来说,不会出现这个情况
|
||||
return payTransaction.getId();
|
||||
}
|
||||
|
||||
// 创建支付交易单
|
||||
payTransaction = PayTransactionConvert.INSTANCE.convert(createReqDTO)
|
||||
.setStatus(PayTransactionStatusEnum.WAITING.getValue())
|
||||
.setNotifyUrl(payAppRespDTO.getPayNotifyUrl());
|
||||
payTransactionMapper.insert(payTransaction);
|
||||
// 最终返回
|
||||
return payTransaction.getId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user