feat 支付限额配置

This commit is contained in:
xxm1995
2024-03-23 23:16:52 +08:00
committed by 喵呀
parent c8ebf069ad
commit c7f4faf79f
24 changed files with 122 additions and 29 deletions

View File

@@ -4,7 +4,6 @@ import cn.bootx.platform.common.core.annotation.IgnoreAuth;
import cn.bootx.platform.common.core.exception.BizException;
import cn.bootx.platform.common.core.rest.Res;
import cn.bootx.platform.common.core.rest.ResResult;
import cn.bootx.platform.daxpay.service.core.channel.alipay.service.AliPayTransferService;
import cn.hutool.core.thread.ThreadUtil;
import com.baomidou.lock.LockInfo;
import com.baomidou.lock.LockTemplate;
@@ -28,7 +27,6 @@ import java.util.Objects;
@RequiredArgsConstructor
public class TestController {
private final LockTemplate lockTemplate;
private final AliPayTransferService aliPayTransferService;
@Operation(summary = "锁测试1")
@GetMapping("/lock1")
@@ -59,13 +57,5 @@ public class TestController {
return "ok";
}
@IgnoreAuth
@Operation(summary = "支付宝回调测试")
@GetMapping("/queryAmount")
public String alipay(){
aliPayTransferService.queryAccountAmount();
return "ok";
}
}

View File

@@ -25,6 +25,9 @@ public interface AliPayCode {
/** APP支付必填 APP支付产品 */
String QUICK_MSECURITY_PAY = "QUICK_MSECURITY_PAY";
/** 询余额账户类型 */
String QUERY_ACCOUNT_TYPE = "ACCTRANS_ACCOUNT";
/** 付款码支付 */
String BAR_CODE = "bar_code";

View File

@@ -35,5 +35,5 @@ public class PlatformLocal {
private Integer orderTimeout;
/** 支付限额 */
private Integer limitAmount;
private Integer singleLimit;
}

View File

@@ -41,6 +41,10 @@ public class AliPayConfig extends MpBaseEntity implements EntityBaseFunction<Ali
@DbColumn(comment = "是否启用")
private Boolean enable;
/** 支付限额 */
@DbColumn(comment = "支付限额")
private Integer singleLimit;
/**
* 服务器异步通知页面路径, 需要填写本网关服务的地址, 不可以直接填写业务系统的地址
* 1. 需http://或者https://格式的完整路径,
@@ -74,6 +78,13 @@ public class AliPayConfig extends MpBaseEntity implements EntityBaseFunction<Ali
@DbColumn(comment = "签名类型 RSA2")
public String signType;
/**
* 是商家与支付宝签约后,商家获得的支付宝商家唯一识别码,以 2088 开头的 16 位数字组成,在开放平台中账户中心获取
*/
@EncryptionField
@DbColumn(comment = "合作者身份ID")
private String alipayUserId;
/** 支付宝公钥 */
@BigField
@EncryptionField

View File

@@ -57,6 +57,10 @@ public class AliPayService {
if (!alipayConfig.getPayWays().contains(payWayEnum.getCode())) {
throw new PayFailureException("该支付宝支付方式不可用");
}
// 验证订单金额是否超限
if(payChannelParam.getAmount() > alipayConfig.getSingleLimit()){
throw new PayFailureException("支付宝支付金额超过限额");
}
}
/**

View File

@@ -2,13 +2,17 @@ package cn.bootx.platform.daxpay.service.core.channel.alipay.service;
import cn.bootx.platform.daxpay.service.core.channel.alipay.entity.AliPayConfig;
import com.alipay.api.domain.AlipayFundAccountQueryModel;
import com.alipay.api.domain.AlipayFundTransToaccountTransferModel;
import com.alipay.api.response.AlipayFundAccountQueryResponse;
import com.alipay.api.response.AlipayFundTransToaccountTransferResponse;
import com.ijpay.alipay.AliPayApi;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import static cn.bootx.platform.daxpay.service.code.AliPayCode.QUERY_ACCOUNT_TYPE;
@Slf4j
@Service
@RequiredArgsConstructor
@@ -20,12 +24,10 @@ public class AliPayTransferService {
* 余额查询接口
*/
@SneakyThrows
public void queryAccountAmount() {
AliPayConfig config = payConfigService.getAndCheckConfig();
payConfigService.initConfig(config);
public void queryAccountAmount(AliPayConfig config) {
AlipayFundAccountQueryModel model = new AlipayFundAccountQueryModel();
model.setAccountType("ACCTRANS_ACCOUNT");
model.setAlipayUserId("2088441532699265");
model.setAccountType(QUERY_ACCOUNT_TYPE);
model.setAlipayUserId(config.getAlipayUserId());
AlipayFundAccountQueryResponse response = AliPayApi.accountQueryToResponse(model, null);
System.out.println(response);
}
@@ -35,6 +37,7 @@ public class AliPayTransferService {
*/
@SneakyThrows
public void transfer() {
AlipayFundTransToaccountTransferModel model = new AlipayFundTransToaccountTransferModel();
AlipayFundTransToaccountTransferResponse response = AliPayApi.transferToResponse(model);
}
}

View File

@@ -3,6 +3,7 @@ package cn.bootx.platform.daxpay.service.core.channel.cash.service;
import cn.bootx.platform.common.core.exception.DataNotExistException;
import cn.bootx.platform.common.core.rest.dto.LabelValue;
import cn.bootx.platform.daxpay.code.PayChannelEnum;
import cn.bootx.platform.daxpay.exception.pay.PayFailureException;
import cn.bootx.platform.daxpay.service.code.WalletPayWay;
import cn.bootx.platform.daxpay.service.core.channel.cash.dao.CashConfigManager;
import cn.bootx.platform.daxpay.service.core.channel.cash.entity.CashConfig;
@@ -38,6 +39,18 @@ public class CashPayConfigService {
return cashConfigManager.findById(ID).orElseThrow(() -> new DataNotExistException("现金配置不存在"));
}
/**
* 获取并检查钱包配置
*/
public CashConfig getAndCheckConfig() {
CashConfig config = this.getConfig();
if (!config.getEnable()){
throw new PayFailureException("钱包支付未启用");
}
return config;
}
/**
* 更新
*/

View File

@@ -41,6 +41,9 @@ public class UnionPayConfig extends MpBaseEntity implements EntityBaseFunction<U
@DbColumn(comment = "是否启用")
private Boolean enable;
/** 支付限额 */
@DbColumn(comment = "支付限额")
private Integer singleLimit;
/**
* 商户收款账号

View File

@@ -52,6 +52,10 @@ public class UnionPayService {
if (!unionPayConfig.getPayWays().contains(payWayEnum.getCode())) {
throw new PayFailureException("该云闪付支付方式不可用");
}
// 支付金额是否超限
if (payChannelParam.getAmount() > unionPayConfig.getSingleLimit()) {
throw new PayFailureException("云闪付支付金额超限");
}
}
/**

View File

@@ -3,6 +3,7 @@ package cn.bootx.platform.daxpay.service.core.channel.voucher.service;
import cn.bootx.platform.common.core.exception.DataNotExistException;
import cn.bootx.platform.common.core.rest.dto.LabelValue;
import cn.bootx.platform.daxpay.code.PayChannelEnum;
import cn.bootx.platform.daxpay.exception.pay.PayFailureException;
import cn.bootx.platform.daxpay.service.code.VoucherPayWay;
import cn.bootx.platform.daxpay.service.core.channel.voucher.dao.VoucherConfigManager;
import cn.bootx.platform.daxpay.service.core.channel.voucher.entity.VoucherConfig;
@@ -33,10 +34,22 @@ public class VoucherConfigService {
private final PayChannelConfigService payChannelConfigService;
/**
* 获取钱包配置
* 获取储值卡配置
*/
public VoucherConfig getConfig(){
return manager.findById(ID).orElseThrow(() -> new DataNotExistException("钱包配置不存在"));
return manager.findById(ID).orElseThrow(() -> new DataNotExistException("储值卡配置不存在"));
}
/**
* 获取并检查储值卡配置
*/
public VoucherConfig getAndCheckConfig() {
VoucherConfig config = this.getConfig();
if (!config.getEnable()){
throw new PayFailureException("储值卡支付未启用");
}
return config;
}
/**

View File

@@ -46,6 +46,10 @@ public class WeChatPayConfig extends MpBaseEntity implements EntityBaseFunction<
@DbColumn(comment = "是否启用")
private Boolean enable;
/** 支付限额 */
@DbColumn(comment = "支付限额")
private Integer singleLimit;
/**
* 服务器异步通知页面路径, 需要填写本网关服务的地址, 不可以直接填写业务系统的地址
* 1. 需http://或者https://格式的完整路径,

View File

@@ -70,6 +70,10 @@ public class WeChatPayService {
if (!payWays.contains(payWayEnum.getCode())) {
throw new PayFailureException("该微信支付方式不可用");
}
// 支付金额是否超限
if (payChannelParam.getAmount() > weChatPayConfig.getSingleLimit()) {
throw new PayFailureException("微信支付金额超限");
}
}
/**

View File

@@ -41,7 +41,7 @@ public class PaymentAssistService {
platform.setSignSecret(config.getSignSecret());
platform.setNotifyUrl(config.getNotifyUrl());
platform.setOrderTimeout(config.getOrderTimeout());
platform.setLimitAmount(config.getLimitAmount());
platform.setSingleLimit(config.getSingleLimit());
platform.setWebsiteUrl(config.getWebsiteUrl());
}

View File

@@ -2,7 +2,10 @@ package cn.bootx.platform.daxpay.service.core.payment.pay.strategy;
import cn.bootx.platform.daxpay.code.PayChannelEnum;
import cn.bootx.platform.daxpay.exception.pay.PayAmountAbnormalException;
import cn.bootx.platform.daxpay.exception.pay.PayFailureException;
import cn.bootx.platform.daxpay.param.pay.PayChannelParam;
import cn.bootx.platform.daxpay.service.core.channel.cash.entity.CashConfig;
import cn.bootx.platform.daxpay.service.core.channel.cash.service.CashPayConfigService;
import cn.bootx.platform.daxpay.service.core.channel.cash.service.CashRecordService;
import cn.bootx.platform.daxpay.service.func.AbsPayStrategy;
import lombok.RequiredArgsConstructor;
@@ -26,6 +29,8 @@ public class CashPayStrategy extends AbsPayStrategy {
private final CashRecordService cashRecordService;
private final CashPayConfigService cashPayConfigService;
/**
* 现金支付
*/
@@ -39,11 +44,16 @@ public class CashPayStrategy extends AbsPayStrategy {
*/
@Override
public void doBeforePayHandler() {
CashConfig config = cashPayConfigService.getAndCheckConfig();
// 检查金额
PayChannelParam payChannelParam = this.getPayChannelParam();
if (payChannelParam.getAmount() <= 0) {
throw new PayAmountAbnormalException();
}
// 支付金额是否超限
if (payChannelParam.getAmount() > config.getSingleLimit()) {
throw new PayFailureException("现金支付金额超过限制");
}
}
/**

View File

@@ -4,6 +4,8 @@ import cn.bootx.platform.daxpay.code.PayChannelEnum;
import cn.bootx.platform.daxpay.exception.pay.PayFailureException;
import cn.bootx.platform.daxpay.param.channel.VoucherPayParam;
import cn.bootx.platform.daxpay.service.core.channel.voucher.entity.Voucher;
import cn.bootx.platform.daxpay.service.core.channel.voucher.entity.VoucherConfig;
import cn.bootx.platform.daxpay.service.core.channel.voucher.service.VoucherConfigService;
import cn.bootx.platform.daxpay.service.core.channel.voucher.service.VoucherPayService;
import cn.bootx.platform.daxpay.service.core.channel.voucher.service.VoucherQueryService;
import cn.bootx.platform.daxpay.service.core.channel.voucher.service.VoucherRecordService;
@@ -38,6 +40,8 @@ public class VoucherPayStrategy extends AbsPayStrategy {
private final VoucherRecordService voucherRecordService;
private final VoucherConfigService voucherConfigService;
private Voucher voucher;
@Override
@@ -63,8 +67,14 @@ public class VoucherPayStrategy extends AbsPayStrategy {
catch (JSONException e) {
throw new PayFailureException("储值卡支付参数错误");
}
this.voucher = voucherQueryService.getAndCheckVoucher(voucherPayParam);
VoucherConfig config = voucherConfigService.getAndCheckConfig();
// 支付金额是否超限
if (this.getPayChannelParam().getAmount() > config.getSingleLimit()) {
throw new PayFailureException("现金支付金额超过限制");
}
// 金额是否满足
this.voucher = voucherQueryService.getAndCheckVoucher(voucherPayParam);
if (this.getPayChannelParam().getAmount() > this.voucher.getBalance()) {
throw new PayFailureException("储值卡余额不足");
}

View File

@@ -82,7 +82,7 @@ public class WalletPayStrategy extends AbsPayStrategy {
}
// 判断是否超过限额
if (getPayChannelParam().getAmount() > this.walletConfig.getSingleLimit()){
throw new PayFailureException("钱包单次支付金额超过限额");
throw new PayFailureException("钱包支付金额超过限额");
}
// 判断余额

View File

@@ -43,7 +43,7 @@ public class PlatformConfig extends MpBaseEntity implements EntityBaseFunction<P
private String returnUrl;
@DbColumn(comment = "支付限额")
private Integer limitAmount;
private Integer singleLimit;
@DbColumn(comment = "订单默认超时时间(分钟)")
private Integer orderTimeout;

View File

@@ -30,6 +30,9 @@ public class AliPayConfigDto extends BaseDto implements Serializable {
@DbColumn(comment = "是否启用")
private Boolean enable;
@Schema(description = "支付限额")
private Integer singleLimit;
@Schema(description = "服务器异步通知页面路径 需http://或者https://格式的完整路径,不能加?id=123这类自定义参数必须外网可以正常访问")
private String notifyUrl;
@@ -45,6 +48,10 @@ public class AliPayConfigDto extends BaseDto implements Serializable {
@Schema(description = "签名类型")
private String signType;
@Schema(description = "合作者身份ID")
@SensitiveInfo(value = SensitiveInfo.SensitiveType.OTHER, front = 15)
private String alipayUserId;
@Schema(description = "支付宝公钥")
@SensitiveInfo(value = SensitiveInfo.SensitiveType.OTHER, front = 15)
private String alipayPublicKey;

View File

@@ -28,6 +28,8 @@ public class UnionPayConfigDto extends BaseDto {
@Schema(description = "是否启用")
private Boolean enable;
@Schema(description = "支付限额")
private Integer singleLimit;
/**
* 商户收款账号

View File

@@ -32,6 +32,9 @@ public class WeChatPayConfigDto extends BaseDto implements Serializable {
@DbColumn(comment = "是否启用")
private Boolean enable;
@Schema(description = "支付限额")
private Integer singleLimit;
@Schema(description = "异步通知地址")
private String notifyUrl;

View File

@@ -21,6 +21,9 @@ public class AliPayConfigParam {
@Schema(description = "是否启用")
private Boolean enable;
@Schema(description = "支付限额")
private Integer singleLimit;
@Schema(description = "服务器异步通知页面路径 需http://或者https://格式的完整路径,不能加?id=123这类自定义参数必须外网可以正常访问")
private String notifyUrl;
@@ -36,6 +39,9 @@ public class AliPayConfigParam {
@Schema(description = "签名类型")
public String signType;
@Schema(description = "合作者身份ID")
private String alipayUserId;
@Schema(description = "支付宝公钥")
public String alipayPublicKey;

View File

@@ -25,6 +25,9 @@ public class UnionPayConfigParam {
@Schema(description = "是否启用")
private Boolean enable;
@Schema(description = "支付限额")
private Integer singleLimit;
/**
* 商户收款账号
*/

View File

@@ -29,6 +29,9 @@ public class WeChatPayConfigParam {
@DbColumn(comment = "是否启用")
private Boolean enable;
@Schema(description = "支付限额")
private Integer singleLimit;
@Schema(description = "异步通知地址")
private String notifyUrl;