wallet:钱包支付,接入 user 付款界面

This commit is contained in:
YunaiV 2023-09-30 22:08:15 +08:00
parent 16cea61435
commit 3875c80471
6 changed files with 30 additions and 60 deletions

View File

@ -11,7 +11,7 @@ import cn.iocoder.yudao.module.pay.convert.order.PayOrderConvert;
import cn.iocoder.yudao.module.pay.dal.dataobject.app.PayAppDO;
import cn.iocoder.yudao.module.pay.dal.dataobject.order.PayOrderDO;
import cn.iocoder.yudao.module.pay.dal.dataobject.order.PayOrderExtensionDO;
import cn.iocoder.yudao.module.pay.framework.pay.wallet.WalletPayClient;
import cn.iocoder.yudao.module.pay.framework.pay.core.WalletPayClient;
import cn.iocoder.yudao.module.pay.service.app.PayAppService;
import cn.iocoder.yudao.module.pay.service.order.PayOrderService;
import com.google.common.collect.Maps;

View File

@ -1,12 +1,15 @@
package cn.iocoder.yudao.module.pay.controller.app.order;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum;
import cn.iocoder.yudao.module.pay.controller.admin.order.vo.PayOrderRespVO;
import cn.iocoder.yudao.module.pay.controller.admin.order.vo.PayOrderSubmitRespVO;
import cn.iocoder.yudao.module.pay.controller.app.order.vo.AppPayOrderSubmitReqVO;
import cn.iocoder.yudao.module.pay.controller.app.order.vo.AppPayOrderSubmitRespVO;
import cn.iocoder.yudao.module.pay.convert.order.PayOrderConvert;
import cn.iocoder.yudao.module.pay.framework.pay.core.WalletPayClient;
import cn.iocoder.yudao.module.pay.service.order.PayOrderService;
import com.google.common.collect.Maps;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -16,8 +19,13 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Map;
import java.util.Objects;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP;
import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLoginUserId;
import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLoginUserType;
@Tag(name = "用户 APP - 支付订单")
@RestController
@ -40,6 +48,16 @@ public class AppPayOrderController {
@PostMapping("/submit")
@Operation(summary = "提交支付订单")
public CommonResult<AppPayOrderSubmitRespVO> submitPayOrder(@RequestBody AppPayOrderSubmitReqVO reqVO) {
// 1. 钱包支付事需要额外传 user_id user_type
if (Objects.equals(reqVO.getChannelCode(), PayChannelEnum.WALLET.getCode())) {
Map<String, String> channelExtras = reqVO.getChannelExtras() == null ?
Maps.newHashMapWithExpectedSize(2) : reqVO.getChannelExtras();
channelExtras.put(WalletPayClient.USER_ID_KEY, String.valueOf(getLoginUserId()));
channelExtras.put(WalletPayClient.USER_TYPE_KEY, String.valueOf(getLoginUserType()));
reqVO.setChannelExtras(channelExtras);
}
// 2. 提交支付
PayOrderSubmitRespVO respVO = payOrderService.submitOrder(reqVO, getClientIP());
return success(PayOrderConvert.INSTANCE.convert3(respVO));
}

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.pay.framework.pay.wallet;
package cn.iocoder.yudao.module.pay.framework.pay.core;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.map.MapUtil;

View File

@ -1,4 +0,0 @@
/**
* 占位无实际作用
*/
package cn.iocoder.yudao.module.pay.framework.pay.core;

View File

@ -13,6 +13,7 @@ import cn.iocoder.yudao.module.pay.controller.admin.channel.vo.PayChannelUpdateR
import cn.iocoder.yudao.module.pay.convert.channel.PayChannelConvert;
import cn.iocoder.yudao.module.pay.dal.dataobject.channel.PayChannelDO;
import cn.iocoder.yudao.module.pay.dal.mysql.channel.PayChannelMapper;
import cn.iocoder.yudao.module.pay.framework.pay.core.WalletPayClient;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import lombok.Getter;
@ -20,6 +21,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.validation.Validator;
import java.time.Duration;
@ -68,6 +70,14 @@ public class PayChannelServiceImpl implements PayChannelService {
@Resource
private Validator validator;
/**
* 初始化为了注册钱包
*/
@PostConstruct
public void init() {
payClientFactory.registerPayClientClass(PayChannelEnum.WALLET, WalletPayClient.class);
}
@Override
public Long createChannel(PayChannelCreateReqVO reqVO) {
// 断言是否有重复的

View File

@ -1,54 +0,0 @@
package cn.iocoder.yudao.module.pay.util;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import java.time.LocalDateTime;
import java.util.concurrent.atomic.AtomicLong;
/**
* 支付相关编号的生产
*/
// TODO @jason需要改造基于 db
public class PaySeqUtils {
private static final AtomicLong REFUND_REQ_NO_SEQ = new AtomicLong(0L);
private static final AtomicLong MER_REFUND_NO_SEQ = new AtomicLong(0L);
private static final AtomicLong MER_ORDER_NO_SEQ = new AtomicLong(0L);
// TODO 芋艿需要看看
/**
* 生成商户退款单号用于测试应该由商户系统生成
* @return 商户退款单
*/
public static String genMerchantRefundNo() {
return String.format("%s%s%04d", "MR",
DateUtil.format(LocalDateTime.now(), DatePattern.PURE_DATETIME_MS_PATTERN),
(int) MER_REFUND_NO_SEQ.getAndIncrement() % 10000);
}
// TODO 芋艿需要看看
/**
* 生成退款请求号
* @return 退款请求号
*/
public static String genRefundReqNo() {
return String.format("%s%s%04d", "RR",
DateUtil.format(LocalDateTime.now(), DatePattern.PURE_DATETIME_MS_PATTERN),
(int) REFUND_REQ_NO_SEQ.getAndIncrement() % 10000);
}
/**
* 生成商户订单编号号 用于测试应该由商户系统生成
* @return 商户订单编号
*/
public static String genMerchantOrderNo() {
return String.format("%s%s%04d", "MO",
DateUtil.format(LocalDateTime.now(), DatePattern.PURE_DATETIME_MS_PATTERN),
(int) MER_ORDER_NO_SEQ.getAndIncrement() % 10000);
}
}