Commit 3875c80471a285380392581c724a9085382c292a
1 parent
16cea614
wallet:钱包支付,接入 user 付款界面
Showing
6 changed files
with
30 additions
and
60 deletions
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/PayOrderController.java
| ... | ... | @@ -11,7 +11,7 @@ import cn.iocoder.yudao.module.pay.convert.order.PayOrderConvert; |
| 11 | 11 | import cn.iocoder.yudao.module.pay.dal.dataobject.app.PayAppDO; |
| 12 | 12 | import cn.iocoder.yudao.module.pay.dal.dataobject.order.PayOrderDO; |
| 13 | 13 | import cn.iocoder.yudao.module.pay.dal.dataobject.order.PayOrderExtensionDO; |
| 14 | -import cn.iocoder.yudao.module.pay.framework.pay.wallet.WalletPayClient; | |
| 14 | +import cn.iocoder.yudao.module.pay.framework.pay.core.WalletPayClient; | |
| 15 | 15 | import cn.iocoder.yudao.module.pay.service.app.PayAppService; |
| 16 | 16 | import cn.iocoder.yudao.module.pay.service.order.PayOrderService; |
| 17 | 17 | import com.google.common.collect.Maps; | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/order/AppPayOrderController.java
| 1 | 1 | package cn.iocoder.yudao.module.pay.controller.app.order; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | +import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum; | |
| 4 | 5 | import cn.iocoder.yudao.module.pay.controller.admin.order.vo.PayOrderRespVO; |
| 5 | 6 | import cn.iocoder.yudao.module.pay.controller.admin.order.vo.PayOrderSubmitRespVO; |
| 6 | 7 | import cn.iocoder.yudao.module.pay.controller.app.order.vo.AppPayOrderSubmitReqVO; |
| 7 | 8 | import cn.iocoder.yudao.module.pay.controller.app.order.vo.AppPayOrderSubmitRespVO; |
| 8 | 9 | import cn.iocoder.yudao.module.pay.convert.order.PayOrderConvert; |
| 10 | +import cn.iocoder.yudao.module.pay.framework.pay.core.WalletPayClient; | |
| 9 | 11 | import cn.iocoder.yudao.module.pay.service.order.PayOrderService; |
| 12 | +import com.google.common.collect.Maps; | |
| 10 | 13 | import io.swagger.v3.oas.annotations.Operation; |
| 11 | 14 | import io.swagger.v3.oas.annotations.Parameter; |
| 12 | 15 | import io.swagger.v3.oas.annotations.tags.Tag; |
| ... | ... | @@ -16,8 +19,13 @@ import org.springframework.web.bind.annotation.*; |
| 16 | 19 | |
| 17 | 20 | import javax.annotation.Resource; |
| 18 | 21 | |
| 22 | +import java.util.Map; | |
| 23 | +import java.util.Objects; | |
| 24 | + | |
| 19 | 25 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 20 | 26 | import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; |
| 27 | +import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLoginUserId; | |
| 28 | +import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLoginUserType; | |
| 21 | 29 | |
| 22 | 30 | @Tag(name = "用户 APP - 支付订单") |
| 23 | 31 | @RestController |
| ... | ... | @@ -40,6 +48,16 @@ public class AppPayOrderController { |
| 40 | 48 | @PostMapping("/submit") |
| 41 | 49 | @Operation(summary = "提交支付订单") |
| 42 | 50 | public CommonResult<AppPayOrderSubmitRespVO> submitPayOrder(@RequestBody AppPayOrderSubmitReqVO reqVO) { |
| 51 | + // 1. 钱包支付事,需要额外传 user_id 和 user_type | |
| 52 | + if (Objects.equals(reqVO.getChannelCode(), PayChannelEnum.WALLET.getCode())) { | |
| 53 | + Map<String, String> channelExtras = reqVO.getChannelExtras() == null ? | |
| 54 | + Maps.newHashMapWithExpectedSize(2) : reqVO.getChannelExtras(); | |
| 55 | + channelExtras.put(WalletPayClient.USER_ID_KEY, String.valueOf(getLoginUserId())); | |
| 56 | + channelExtras.put(WalletPayClient.USER_TYPE_KEY, String.valueOf(getLoginUserType())); | |
| 57 | + reqVO.setChannelExtras(channelExtras); | |
| 58 | + } | |
| 59 | + | |
| 60 | + // 2. 提交支付 | |
| 43 | 61 | PayOrderSubmitRespVO respVO = payOrderService.submitOrder(reqVO, getClientIP()); |
| 44 | 62 | return success(PayOrderConvert.INSTANCE.convert3(respVO)); |
| 45 | 63 | } | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/framework/pay/wallet/WalletPayClient.java renamed to yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/framework/pay/core/WalletPayClient.java
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/framework/pay/core/package-info.java deleted
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/channel/PayChannelServiceImpl.java
| ... | ... | @@ -13,6 +13,7 @@ import cn.iocoder.yudao.module.pay.controller.admin.channel.vo.PayChannelUpdateR |
| 13 | 13 | import cn.iocoder.yudao.module.pay.convert.channel.PayChannelConvert; |
| 14 | 14 | import cn.iocoder.yudao.module.pay.dal.dataobject.channel.PayChannelDO; |
| 15 | 15 | import cn.iocoder.yudao.module.pay.dal.mysql.channel.PayChannelMapper; |
| 16 | +import cn.iocoder.yudao.module.pay.framework.pay.core.WalletPayClient; | |
| 16 | 17 | import com.google.common.cache.CacheLoader; |
| 17 | 18 | import com.google.common.cache.LoadingCache; |
| 18 | 19 | import lombok.Getter; |
| ... | ... | @@ -20,6 +21,7 @@ import lombok.extern.slf4j.Slf4j; |
| 20 | 21 | import org.springframework.stereotype.Service; |
| 21 | 22 | import org.springframework.validation.annotation.Validated; |
| 22 | 23 | |
| 24 | +import javax.annotation.PostConstruct; | |
| 23 | 25 | import javax.annotation.Resource; |
| 24 | 26 | import javax.validation.Validator; |
| 25 | 27 | import java.time.Duration; |
| ... | ... | @@ -68,6 +70,14 @@ public class PayChannelServiceImpl implements PayChannelService { |
| 68 | 70 | @Resource |
| 69 | 71 | private Validator validator; |
| 70 | 72 | |
| 73 | + /** | |
| 74 | + * 初始化,为了注册钱包 | |
| 75 | + */ | |
| 76 | + @PostConstruct | |
| 77 | + public void init() { | |
| 78 | + payClientFactory.registerPayClientClass(PayChannelEnum.WALLET, WalletPayClient.class); | |
| 79 | + } | |
| 80 | + | |
| 71 | 81 | @Override |
| 72 | 82 | public Long createChannel(PayChannelCreateReqVO reqVO) { |
| 73 | 83 | // 断言是否有重复的 | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/util/PaySeqUtils.java deleted
| 1 | -package cn.iocoder.yudao.module.pay.util; | |
| 2 | - | |
| 3 | -import cn.hutool.core.date.DatePattern; | |
| 4 | -import cn.hutool.core.date.DateUtil; | |
| 5 | - | |
| 6 | -import java.time.LocalDateTime; | |
| 7 | -import java.util.concurrent.atomic.AtomicLong; | |
| 8 | - | |
| 9 | -/** | |
| 10 | - * 支付相关编号的生产 | |
| 11 | - */ | |
| 12 | -// TODO @jason:需要改造,基于 db; | |
| 13 | -public class PaySeqUtils { | |
| 14 | - | |
| 15 | - private static final AtomicLong REFUND_REQ_NO_SEQ = new AtomicLong(0L); | |
| 16 | - | |
| 17 | - private static final AtomicLong MER_REFUND_NO_SEQ = new AtomicLong(0L); | |
| 18 | - | |
| 19 | - private static final AtomicLong MER_ORDER_NO_SEQ = new AtomicLong(0L); | |
| 20 | - | |
| 21 | - // TODO 芋艿:需要看看 | |
| 22 | - /** | |
| 23 | - * 生成商户退款单号,用于测试,应该由商户系统生成 | |
| 24 | - * @return 商户退款单 | |
| 25 | - */ | |
| 26 | - public static String genMerchantRefundNo() { | |
| 27 | - return String.format("%s%s%04d", "MR", | |
| 28 | - DateUtil.format(LocalDateTime.now(), DatePattern.PURE_DATETIME_MS_PATTERN), | |
| 29 | - (int) MER_REFUND_NO_SEQ.getAndIncrement() % 10000); | |
| 30 | - } | |
| 31 | - | |
| 32 | - // TODO 芋艿:需要看看 | |
| 33 | - | |
| 34 | - /** | |
| 35 | - * 生成退款请求号 | |
| 36 | - * @return 退款请求号 | |
| 37 | - */ | |
| 38 | - public static String genRefundReqNo() { | |
| 39 | - return String.format("%s%s%04d", "RR", | |
| 40 | - DateUtil.format(LocalDateTime.now(), DatePattern.PURE_DATETIME_MS_PATTERN), | |
| 41 | - (int) REFUND_REQ_NO_SEQ.getAndIncrement() % 10000); | |
| 42 | - } | |
| 43 | - | |
| 44 | - /** | |
| 45 | - * 生成商户订单编号号 用于测试,应该由商户系统生成 | |
| 46 | - * @return 商户订单编号 | |
| 47 | - */ | |
| 48 | - public static String genMerchantOrderNo() { | |
| 49 | - return String.format("%s%s%04d", "MO", | |
| 50 | - DateUtil.format(LocalDateTime.now(), DatePattern.PURE_DATETIME_MS_PATTERN), | |
| 51 | - (int) MER_ORDER_NO_SEQ.getAndIncrement() % 10000); | |
| 52 | - } | |
| 53 | - | |
| 54 | -} |