feat 转账订单开发

This commit is contained in:
DaxPay
2024-06-06 20:35:37 +08:00
parent 42cfd24558
commit 848c55d13c
22 changed files with 431 additions and 26 deletions

View File

@@ -1,6 +1,8 @@
package cn.daxpay.single.service.core.channel.alipay.service;
import cn.daxpay.single.service.core.channel.alipay.entity.AliPayConfig;
import cn.daxpay.single.service.core.order.transfer.entity.TransferOrder;
import cn.hutool.core.util.IdUtil;
import com.alipay.api.domain.AlipayFundAccountQueryModel;
import com.alipay.api.domain.AlipayFundTransToaccountTransferModel;
import com.alipay.api.response.AlipayFundAccountQueryResponse;
@@ -36,8 +38,17 @@ public class AliPayTransferService {
* 转账接口
*/
@SneakyThrows
public void transfer() {
public void transfer(TransferOrder order) {
AlipayFundTransToaccountTransferModel model = new AlipayFundTransToaccountTransferModel();
// model.setAmount(PayUtil.conversionAmount(order.getAmount()).toString());
model.setAmount("1.00");
model.setOutBizNo(IdUtil.getSnowflakeNextIdStr());
model.setPayeeType("ALIPAY_USERID");
model.setPayeeAccount("2088722032251651");
model.setPayerShowName("易杯光年");
model.setExtParam("{order_title: '订单标题'}");
model.setRemark("易杯光年的备注");
AlipayFundTransToaccountTransferResponse response = AliPayApi.transferToResponse(model);
System.out.println(response);
}
}

View File

@@ -40,7 +40,6 @@ public class RefundOrderService {
/**
* 手动发起退款
* 退款涉及到回调通知, 索所以需要手动初始化一下上下文
*/
public void refund(PayOrderRefundParam param) {

View File

@@ -0,0 +1,16 @@
package cn.daxpay.single.service.core.order.transfer.dao;
import cn.bootx.platform.common.mybatisplus.impl.BaseManager;
import cn.daxpay.single.service.core.order.transfer.entity.TransferOrderExtra;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;
/**
* 转账订单扩展数据
* @author xxm
* @since 2024/6/6
*/
@Slf4j
@Repository
public class TransferOrderExtraManager extends BaseManager<TransferOrderExtraMapper, TransferOrderExtra> {
}

View File

@@ -0,0 +1,14 @@
package cn.daxpay.single.service.core.order.transfer.dao;
import cn.daxpay.single.service.core.order.transfer.entity.TransferOrderExtra;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* 转账订单扩展
* @author xxm
* @since 2024/6/6
*/
@Mapper
public interface TransferOrderExtraMapper extends BaseMapper<TransferOrderExtra> {
}

View File

@@ -3,6 +3,7 @@ package cn.daxpay.single.service.core.order.transfer.entity;
import cn.bootx.platform.common.mybatisplus.base.MpBaseEntity;
import cn.daxpay.single.code.PayChannelEnum;
import cn.bootx.table.modify.annotation.DbTable;
import cn.daxpay.single.code.TransferPayeeTypeEnum;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
@@ -22,8 +23,14 @@ import java.time.LocalDateTime;
@TableName("pay_transfer_order")
public class TransferOrder extends MpBaseEntity {
/** 业务号 */
private String outTradeNo;
/** 商户转账号 */
private String bizTransferNo;
/** 转账号 */
private String transferNo;
/** 通道转账号 */
private String outTransferNo;
/**
* 支付通道
@@ -31,17 +38,40 @@ public class TransferOrder extends MpBaseEntity {
*/
private String channel;
/** 金额 */
/** 转账金额 */
private Integer amount;
/** 状态 */
private String status;
/** 标题 */
private String title;
/** 转账原因/备注 */
private String reason;
/**
* 转账类型, 微信使用
*/
private String transferType;
/** 付款方 */
private String payer;
/** 款方 */
private String payee;
/** 款方显示名称 */
private String payerShowName;
/**
* 收款人类型
* @see TransferPayeeTypeEnum
*/
private String payeeType;
/** 收款人账号 */
private String payeeAccount;
/** 收款人姓名 */
private String payeeName;
/** 状态 */
private String status;
/** 成功时间 */
private LocalDateTime successTime;

View File

@@ -0,0 +1,43 @@
package cn.daxpay.single.service.core.order.transfer.entity;
import cn.bootx.platform.common.mybatisplus.base.MpBaseEntity;
import cn.bootx.table.modify.annotation.DbColumn;
import cn.bootx.table.modify.annotation.DbTable;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.time.LocalDateTime;
/**
* 转账订单扩展数据
* @author xxm
* @since 2024/6/6
*/
@EqualsAndHashCode(callSuper = true)
@Data
@Accessors(chain = true)
@DbTable(comment = "转账订单扩展数据")
@TableName("pay_transfer_order_extra")
public class TransferOrderExtra extends MpBaseEntity {
/** 异步通知地址 */
@DbColumn(comment = "异步通知地址")
@TableField(updateStrategy = FieldStrategy.ALWAYS)
private String notifyUrl;
/** 商户扩展参数,回调时会原样返回, 以最后一次为准 */
@DbColumn(comment = "商户扩展参数")
private String attach;
/** 请求时间,时间戳转时间 */
@DbColumn(comment = "请求时间,传输时间戳")
private LocalDateTime reqTime;
/** 终端ip */
@DbColumn(comment = "支付终端ip")
private String clientIp;
}

View File

@@ -13,4 +13,8 @@ import org.springframework.stereotype.Service;
@Service
@RequiredArgsConstructor
public class TransferOrderService {
/**
* 创建订单
*/
}

View File

@@ -8,19 +8,21 @@ import cn.daxpay.single.service.core.payment.sync.strategy.pay.UnionPaySyncStrat
import cn.daxpay.single.service.core.payment.sync.strategy.pay.WeChatPaySyncStrategy;
import cn.daxpay.single.service.func.AbsPaySyncStrategy;
import cn.hutool.extra.spring.SpringUtil;
import lombok.experimental.UtilityClass;
/**
* 支付同步策略工厂类
* @author xxm
* @since 2023/7/14
*/
@UtilityClass
public class PaySyncStrategyFactory {
/**
* 获取支付同步策略, 只有异步支付方式才需要这个功能
* 获取支付同步策略
* @param channelCode 支付通道编码
* @return 支付同步策略类
*/
public static AbsPaySyncStrategy create(String channelCode) {
public AbsPaySyncStrategy create(String channelCode) {
AbsPaySyncStrategy strategy;
PayChannelEnum channelEnum = PayChannelEnum.findByCode(channelCode);
switch (channelEnum) {

View File

@@ -1,5 +1,10 @@
package cn.daxpay.single.service.core.payment.transfer.factory;
import cn.daxpay.single.code.PayChannelEnum;
import cn.daxpay.single.exception.pay.PayUnsupportedMethodException;
import cn.daxpay.single.service.core.payment.transfer.strategy.AliPayTransferStrategy;
import cn.daxpay.single.service.func.AbsTransferStrategy;
import cn.hutool.extra.spring.SpringUtil;
import lombok.experimental.UtilityClass;
/**
@@ -9,4 +14,22 @@ import lombok.experimental.UtilityClass;
*/
@UtilityClass
public class TransferFactory {
/**
* 获取转账策略
* @param channelCode 支付通道编码
* @return 支付同步策略类
*/
public AbsTransferStrategy create(String channelCode) {
AbsTransferStrategy strategy;
PayChannelEnum channelEnum = PayChannelEnum.findByCode(channelCode);
switch (channelEnum) {
case ALI:
strategy = SpringUtil.getBean(AliPayTransferStrategy.class);
break;
default:
throw new PayUnsupportedMethodException();
}
return strategy;
}
}

View File

@@ -0,0 +1,44 @@
package cn.daxpay.single.service.core.payment.transfer.service;
import cn.daxpay.single.param.payment.transfer.TransferParam;
import cn.daxpay.single.result.transfer.TransferResult;
import cn.daxpay.single.service.core.order.transfer.entity.TransferOrder;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* 转账辅助服务
* @author xxm
* @since 2024/6/6
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class TransferAssistService {
/**
* 创建转账订单
*/
public TransferOrder createOrder(TransferParam param) {
// 1. 创建转账订单
return null;
}
/**
* 更新转账订单错误信息
*/
public void updateOrderByError(TransferOrder order) {
}
/**
* 构造
* @param order
*/
public TransferResult buildResult(TransferOrder order) {
return null;
}
}

View File

@@ -1,5 +1,14 @@
package cn.daxpay.single.service.core.payment.transfer.service;
import cn.daxpay.single.code.PayChannelEnum;
import cn.daxpay.single.code.RefundStatusEnum;
import cn.daxpay.single.param.payment.transfer.TransferParam;
import cn.daxpay.single.result.transfer.TransferResult;
import cn.daxpay.single.service.common.local.PaymentContextLocal;
import cn.daxpay.single.service.core.order.transfer.entity.TransferOrder;
import cn.daxpay.single.service.core.payment.transfer.factory.TransferFactory;
import cn.daxpay.single.service.func.AbsTransferStrategy;
import cn.hutool.extra.spring.SpringUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@@ -13,4 +22,43 @@ import org.springframework.stereotype.Service;
@Service
@RequiredArgsConstructor
public class TransferService {
private final TransferAssistService transferAssistService;
/**
* 转账
*/
public TransferResult transfer(TransferParam transferParam){
// 获取策略
AbsTransferStrategy transferStrategy = TransferFactory.create(PayChannelEnum.ALI.getCode());
// 检查转账参数
transferStrategy.doValidateParam(transferParam);
// 创建转账订单并设置
TransferOrder order = transferAssistService.createOrder(transferParam);
transferStrategy.setTransferOrder(order);
// 执行预处理
transferStrategy.doBeforeHandler();
try {
// 执行转账策略
transferStrategy.doTransferHandler();
} catch (Exception e) {
log.error("转账出现错误", e);
// 记录处理失败状态
PaymentContextLocal.get().getRefundInfo().setStatus(RefundStatusEnum.FAIL);
// 更新退款失败的记录
transferAssistService.updateOrderByError(order);
return transferAssistService.buildResult(order);
}
SpringUtil.getBean(this.getClass()).successHandler(order);
return transferAssistService.buildResult(order);
}
/**
* 成功处理
*/
public void successHandler(TransferOrder order){
}
}

View File

@@ -46,4 +46,8 @@ public class AliPayTransferStrategy extends AbsTransferStrategy {
payConfigService.initConfig(this.config);
}
@Override
public void doTransferHandler() {
aliPayTransferService.transfer(this.getTransferOrder());
}
}

View File

@@ -17,7 +17,6 @@ public abstract class AbsRefundStrategy implements PayStrategy{
/** 退款订单 */
private RefundOrder refundOrder = null;
/**
* 退款前对处理, 主要进行配置的加载和检查
*/

View File

@@ -1,5 +1,6 @@
package cn.daxpay.single.service.func;
import cn.daxpay.single.param.payment.transfer.TransferParam;
import cn.daxpay.single.service.core.order.transfer.entity.TransferOrder;
import lombok.Getter;
import lombok.Setter;
@@ -15,9 +16,20 @@ public abstract class AbsTransferStrategy implements PayStrategy{
/** 转账订单 */
private TransferOrder transferOrder;
/**
* 校验参数
*/
public void doValidateParam(TransferParam transferParam) {
}
/**
* 转账前操作
*/
public void doBeforeHandler(){}
/**
* 转账操作
*/
public abstract void doTransferHandler();
}