feat:【MALL 商城】商城分佣提现,完成对微信转账(小程序)的对接
This commit is contained in:
parent
fd8567f0fa
commit
44548ee03f
|
@ -31,6 +31,7 @@ import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLogi
|
|||
@Validated
|
||||
@Slf4j
|
||||
public class AppBrokerageRecordController {
|
||||
|
||||
@Resource
|
||||
private BrokerageRecordService brokerageRecordService;
|
||||
|
||||
|
@ -49,4 +50,4 @@ public class AppBrokerageRecordController {
|
|||
return success(brokerageRecordService.calculateProductBrokeragePrice(getLoginUserId(), spuId));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package cn.iocoder.yudao.module.pay.controller.app.transfer;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.module.pay.service.transfer.PayTransferService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "用户 APP - 转账单")
|
||||
@RestController
|
||||
@RequestMapping("/pay/transfer")
|
||||
@Validated
|
||||
@Slf4j
|
||||
public class AppPayTransferController {
|
||||
|
||||
@Resource
|
||||
private PayTransferService transferService;
|
||||
|
||||
@GetMapping("/sync")
|
||||
@Operation(summary = "同步转账单") // 目的:解决微信转账的异步回调可能有延迟的问题
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
public CommonResult<Boolean> syncTransfer(@RequestParam("id") Long id) {
|
||||
transferService.syncTransfer(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
}
|
|
@ -140,7 +140,7 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|||
PayOrderDO order = validateOrderCanSubmit(reqVO.getId());
|
||||
// 1.32 校验支付渠道是否有效
|
||||
PayChannelDO channel = validateChannelCanSubmit(order.getAppId(), reqVO.getChannelCode());
|
||||
PayClient client = channelService.getPayClient(channel.getId());
|
||||
PayClient<?> client = channelService.getPayClient(channel.getId());
|
||||
|
||||
// 2. 插入 PayOrderExtensionDO
|
||||
String no = noRedisDAO.generate(payProperties.getOrderNoPrefix());
|
||||
|
@ -237,7 +237,7 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|||
appService.validPayApp(appId);
|
||||
// 校验支付渠道是否有效
|
||||
PayChannelDO channel = channelService.validPayChannel(appId, channelCode);
|
||||
PayClient client = channelService.getPayClient(channel.getId());
|
||||
PayClient<?> client = channelService.getPayClient(channel.getId());
|
||||
if (client == null) {
|
||||
log.error("[validatePayChannelCanSubmit][渠道编号({}) 找不到对应的支付客户端]", channel.getId());
|
||||
throw exception(CHANNEL_NOT_FOUND);
|
||||
|
|
|
@ -98,7 +98,7 @@ public class PayRefundServiceImpl implements PayRefundService {
|
|||
PayOrderDO order = validatePayOrderCanRefund(reqDTO, app.getId());
|
||||
// 1.3 校验支付渠道是否有效
|
||||
PayChannelDO channel = channelService.validPayChannel(order.getChannelId());
|
||||
PayClient client = channelService.getPayClient(channel.getId());
|
||||
PayClient<?> client = channelService.getPayClient(channel.getId());
|
||||
if (client == null) {
|
||||
log.error("[refund][渠道编号({}) 找不到对应的支付客户端]", channel.getId());
|
||||
throw exception(CHANNEL_NOT_FOUND);
|
||||
|
|
|
@ -52,6 +52,13 @@ public interface PayTransferService {
|
|||
*/
|
||||
int syncTransfer();
|
||||
|
||||
/**
|
||||
* 【单个】同步渠道转账单状态
|
||||
*
|
||||
* @param id 转账单编号
|
||||
*/
|
||||
void syncTransfer(Long id);
|
||||
|
||||
/**
|
||||
* 渠道的转账通知
|
||||
*
|
||||
|
|
|
@ -68,7 +68,7 @@ public class PayTransferServiceImpl implements PayTransferService {
|
|||
PayAppDO payApp = appService.validPayApp(reqDTO.getAppKey());
|
||||
// 1.2 校验支付渠道是否有效
|
||||
PayChannelDO channel = channelService.validPayChannel(payApp.getId(), reqDTO.getChannelCode());
|
||||
PayClient client = channelService.getPayClient(channel.getId());
|
||||
PayClient<?> client = channelService.getPayClient(channel.getId());
|
||||
if (client == null) {
|
||||
log.error("[createTransfer][渠道编号({}) 找不到对应的支付客户端]", channel.getId());
|
||||
throw exception(CHANNEL_NOT_FOUND);
|
||||
|
@ -273,10 +273,19 @@ public class PayTransferServiceImpl implements PayTransferService {
|
|||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void syncTransfer(Long id) {
|
||||
PayTransferDO transfer = transferMapper.selectById(id);
|
||||
if (transfer == null) {
|
||||
throw exception(PAY_TRANSFER_NOT_FOUND);
|
||||
}
|
||||
syncTransfer(transfer);
|
||||
}
|
||||
|
||||
private boolean syncTransfer(PayTransferDO transfer) {
|
||||
try {
|
||||
// 1. 查询转账订单信息
|
||||
PayClient payClient = channelService.getPayClient(transfer.getChannelId());
|
||||
PayClient<?> payClient = channelService.getPayClient(transfer.getChannelId());
|
||||
if (payClient == null) {
|
||||
log.error("[syncTransfer][渠道编号({}) 找不到对应的支付客户端]", transfer.getChannelId());
|
||||
return false;
|
||||
|
|
|
@ -311,7 +311,7 @@ public class PayChannelServiceTest extends BaseDbUnitTest {
|
|||
.thenReturn(mockClient);
|
||||
|
||||
// 调用
|
||||
PayClient client = channelService.getPayClient(id);
|
||||
PayClient<?> client = channelService.getPayClient(id);
|
||||
// 断言
|
||||
assertSame(client, mockClient);
|
||||
}
|
||||
|
|
|
@ -350,7 +350,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
|
|||
when(channelService.validPayChannel(eq(1L), eq(PayChannelEnum.ALIPAY_APP.getCode())))
|
||||
.thenReturn(channel);
|
||||
// mock 方法(client)
|
||||
PayClient client = mock(PayClient.class);
|
||||
PayClient<?> client = mock(PayClient.class);
|
||||
when(channelService.getPayClient(eq(10L))).thenReturn(client);
|
||||
// mock 方法()
|
||||
PayOrderRespDTO unifiedOrderResp = randomPojo(PayOrderRespDTO.class, o ->
|
||||
|
@ -404,7 +404,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
|
|||
when(channelService.validPayChannel(eq(1L), eq(PayChannelEnum.ALIPAY_APP.getCode())))
|
||||
.thenReturn(channel);
|
||||
// mock 方法(client)
|
||||
PayClient client = mock(PayClient.class);
|
||||
PayClient<?> client = mock(PayClient.class);
|
||||
when(channelService.getPayClient(eq(10L))).thenReturn(client);
|
||||
// mock 方法(支付渠道的调用)
|
||||
PayOrderRespDTO unifiedOrderResp = randomPojo(PayOrderRespDTO.class, o -> o.setChannelErrorCode(null).setChannelErrorMsg(null)
|
||||
|
@ -462,7 +462,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
|
|||
o -> o.setOrderId(id).setStatus(PayOrderStatusEnum.WAITING.getStatus()));
|
||||
orderExtensionMapper.insert(orderExtension);
|
||||
// mock 方法(PayClient 已支付)
|
||||
PayClient client = mock(PayClient.class);
|
||||
PayClient<?> client = mock(PayClient.class);
|
||||
when(channelService.getPayClient(eq(orderExtension.getChannelId()))).thenReturn(client);
|
||||
when(client.getOrder(eq(orderExtension.getNo()))).thenReturn(randomPojo(PayOrderRespDTO.class,
|
||||
o -> o.setStatus(PayOrderStatusEnum.SUCCESS.getStatus())));
|
||||
|
@ -481,7 +481,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
|
|||
o -> o.setOrderId(id).setStatus(PayOrderStatusEnum.WAITING.getStatus()));
|
||||
orderExtensionMapper.insert(orderExtension);
|
||||
// mock 方法(PayClient 已支付)
|
||||
PayClient client = mock(PayClient.class);
|
||||
PayClient<?> client = mock(PayClient.class);
|
||||
when(channelService.getPayClient(eq(orderExtension.getChannelId()))).thenReturn(client);
|
||||
when(client.getOrder(eq(orderExtension.getNo()))).thenReturn(randomPojo(PayOrderRespDTO.class,
|
||||
o -> o.setStatus(PayOrderStatusEnum.WAITING.getStatus())));
|
||||
|
@ -873,7 +873,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
|
|||
.setCreateTime(LocalDateTime.now()));
|
||||
orderExtensionMapper.insert(orderExtension);
|
||||
// mock 方法(PayClient)
|
||||
PayClient client = mock(PayClient.class);
|
||||
PayClient<?> client = mock(PayClient.class);
|
||||
when(channelService.getPayClient(eq(10L))).thenReturn(client);
|
||||
// mock 方法(PayClient 异常)
|
||||
when(client.getOrder(any())).thenThrow(new RuntimeException());
|
||||
|
@ -900,7 +900,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
|
|||
.setCreateTime(LocalDateTime.now()));
|
||||
orderExtensionMapper.insert(orderExtension);
|
||||
// mock 方法(PayClient)
|
||||
PayClient client = mock(PayClient.class);
|
||||
PayClient<?> client = mock(PayClient.class);
|
||||
when(channelService.getPayClient(eq(10L))).thenReturn(client);
|
||||
// mock 方法(PayClient 成功返回)
|
||||
PayOrderRespDTO respDTO = randomPojo(PayOrderRespDTO.class,
|
||||
|
@ -934,7 +934,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
|
|||
.setCreateTime(LocalDateTime.now()));
|
||||
orderExtensionMapper.insert(orderExtension);
|
||||
// mock 方法(PayClient)
|
||||
PayClient client = mock(PayClient.class);
|
||||
PayClient<?> client = mock(PayClient.class);
|
||||
when(channelService.getPayClient(eq(10L))).thenReturn(client);
|
||||
// mock 方法(PayClient 成功返回)
|
||||
PayOrderRespDTO respDTO = randomPojo(PayOrderRespDTO.class,
|
||||
|
@ -965,7 +965,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
|
|||
.setOrderId(order.getId()));
|
||||
orderExtensionMapper.insert(orderExtension);
|
||||
// mock 方法(PayClient)
|
||||
PayClient client = mock(PayClient.class);
|
||||
PayClient<?> client = mock(PayClient.class);
|
||||
when(channelService.getPayClient(eq(10L))).thenReturn(client);
|
||||
|
||||
// 调用
|
||||
|
@ -1012,7 +1012,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
|
|||
.setChannelId(10L));
|
||||
orderExtensionMapper.insert(orderExtension);
|
||||
// mock 方法(PayClient)
|
||||
PayClient client = mock(PayClient.class);
|
||||
PayClient<?> client = mock(PayClient.class);
|
||||
when(channelService.getPayClient(eq(10L))).thenReturn(client);
|
||||
// mock 方法(PayClient 退款返回)
|
||||
PayOrderRespDTO respDTO = randomPojo(PayOrderRespDTO.class,
|
||||
|
@ -1046,7 +1046,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
|
|||
.setChannelId(10L));
|
||||
orderExtensionMapper.insert(orderExtension);
|
||||
// mock 方法(PayClient)
|
||||
PayClient client = mock(PayClient.class);
|
||||
PayClient<?> client = mock(PayClient.class);
|
||||
when(channelService.getPayClient(eq(10L))).thenReturn(client);
|
||||
// mock 方法(PayClient 成功返回)
|
||||
PayOrderRespDTO respDTO = randomPojo(PayOrderRespDTO.class,
|
||||
|
@ -1080,7 +1080,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest {
|
|||
.setChannelId(10L));
|
||||
orderExtensionMapper.insert(orderExtension);
|
||||
// mock 方法(PayClient)
|
||||
PayClient client = mock(PayClient.class);
|
||||
PayClient<?> client = mock(PayClient.class);
|
||||
when(channelService.getPayClient(eq(10L))).thenReturn(client);
|
||||
// mock 方法(PayClient 关闭返回)
|
||||
PayOrderRespDTO respDTO = randomPojo(PayOrderRespDTO.class,
|
||||
|
|
|
@ -331,7 +331,7 @@ public class PayRefundServiceTest extends BaseDbAndRedisUnitTest {
|
|||
.setCode(PayChannelEnum.ALIPAY_APP.getCode()));
|
||||
when(channelService.validPayChannel(eq(1L))).thenReturn(channel);
|
||||
// mock 方法(client)
|
||||
PayClient client = mock(PayClient.class);
|
||||
PayClient<?> client = mock(PayClient.class);
|
||||
when(channelService.getPayClient(eq(10L))).thenReturn(client);
|
||||
// mock 数据(refund 已存在)
|
||||
PayRefundDO refund = randomPojo(PayRefundDO.class, o ->
|
||||
|
@ -363,7 +363,7 @@ public class PayRefundServiceTest extends BaseDbAndRedisUnitTest {
|
|||
.setCode(PayChannelEnum.ALIPAY_APP.getCode()));
|
||||
when(channelService.validPayChannel(eq(10L))).thenReturn(channel);
|
||||
// mock 方法(client)
|
||||
PayClient client = mock(PayClient.class);
|
||||
PayClient<?> client = mock(PayClient.class);
|
||||
when(channelService.getPayClient(eq(10L))).thenReturn(client);
|
||||
// mock 方法(client 调用发生异常)
|
||||
when(client.unifiedRefund(any(PayRefundUnifiedReqDTO.class))).thenThrow(new RuntimeException());
|
||||
|
@ -407,7 +407,7 @@ public class PayRefundServiceTest extends BaseDbAndRedisUnitTest {
|
|||
.setCode(PayChannelEnum.ALIPAY_APP.getCode()));
|
||||
when(channelService.validPayChannel(eq(10L))).thenReturn(channel);
|
||||
// mock 方法(client)
|
||||
PayClient client = mock(PayClient.class);
|
||||
PayClient<?> client = mock(PayClient.class);
|
||||
when(channelService.getPayClient(eq(10L))).thenReturn(client);
|
||||
// mock 方法(client 成功)
|
||||
PayRefundRespDTO refundRespDTO = randomPojo(PayRefundRespDTO.class);
|
||||
|
@ -664,7 +664,7 @@ public class PayRefundServiceTest extends BaseDbAndRedisUnitTest {
|
|||
.setOrderNo("P110").setNo("R220"));
|
||||
refundMapper.insert(refund);
|
||||
// mock 方法(client)
|
||||
PayClient client = mock(PayClient.class);
|
||||
PayClient<?> client = mock(PayClient.class);
|
||||
when(channelService.getPayClient(eq(10L))).thenReturn(client);
|
||||
// mock 方法(client 返回指定状态)
|
||||
PayRefundRespDTO respDTO = randomPojo(PayRefundRespDTO.class, o -> o.setStatus(status));
|
||||
|
@ -686,7 +686,7 @@ public class PayRefundServiceTest extends BaseDbAndRedisUnitTest {
|
|||
.setOrderNo("P110").setNo("R220"));
|
||||
refundMapper.insert(refund);
|
||||
// mock 方法(client)
|
||||
PayClient client = mock(PayClient.class);
|
||||
PayClient<?> client = mock(PayClient.class);
|
||||
when(channelService.getPayClient(eq(10L))).thenReturn(client);
|
||||
// mock 方法(client 抛出异常)
|
||||
when(client.getRefund(eq("P110"), eq("R220"))).thenThrow(new RuntimeException());
|
||||
|
|
|
@ -42,7 +42,7 @@ public class PayClientFactoryImplIntegrationTest {
|
|||
// 创建客户端
|
||||
Long channelId = RandomUtil.randomLong();
|
||||
payClientFactory.createOrUpdatePayClient(channelId, PayChannelEnum.WX_PUB.getCode(), config);
|
||||
PayClient client = payClientFactory.getPayClient(channelId);
|
||||
PayClient<?> client = payClientFactory.getPayClient(channelId);
|
||||
// 发起支付
|
||||
PayOrderUnifiedReqDTO reqDTO = buildPayOrderUnifiedReqDTO();
|
||||
// CommonResult<?> result = client.unifiedOrder(reqDTO);
|
||||
|
@ -65,7 +65,7 @@ public class PayClientFactoryImplIntegrationTest {
|
|||
// 创建客户端
|
||||
Long channelId = RandomUtil.randomLong();
|
||||
payClientFactory.createOrUpdatePayClient(channelId, PayChannelEnum.WX_PUB.getCode(), config);
|
||||
PayClient client = payClientFactory.getPayClient(channelId);
|
||||
PayClient<?> client = payClientFactory.getPayClient(channelId);
|
||||
// 发起支付
|
||||
PayOrderUnifiedReqDTO reqDTO = buildPayOrderUnifiedReqDTO();
|
||||
// CommonResult<?> result = client.unifiedOrder(reqDTO);
|
||||
|
@ -88,7 +88,7 @@ public class PayClientFactoryImplIntegrationTest {
|
|||
// 创建客户端
|
||||
Long channelId = RandomUtil.randomLong();
|
||||
payClientFactory.createOrUpdatePayClient(channelId, PayChannelEnum.ALIPAY_QR.getCode(), config);
|
||||
PayClient client = payClientFactory.getPayClient(channelId);
|
||||
PayClient<?> client = payClientFactory.getPayClient(channelId);
|
||||
// 发起支付
|
||||
PayOrderUnifiedReqDTO reqDTO = buildPayOrderUnifiedReqDTO();
|
||||
reqDTO.setNotifyUrl("http://yunai.natapp1.cc/admin-api/pay/notify/callback/18"); // TODO @tina: 这里改成你的 natapp 回调地址
|
||||
|
@ -112,7 +112,7 @@ public class PayClientFactoryImplIntegrationTest {
|
|||
// 创建客户端
|
||||
Long channelId = RandomUtil.randomLong();
|
||||
payClientFactory.createOrUpdatePayClient(channelId, PayChannelEnum.ALIPAY_WAP.getCode(), config);
|
||||
PayClient client = payClientFactory.getPayClient(channelId);
|
||||
PayClient<?> client = payClientFactory.getPayClient(channelId);
|
||||
// 发起支付
|
||||
PayOrderUnifiedReqDTO reqDTO = buildPayOrderUnifiedReqDTO();
|
||||
// CommonResult<?> result = client.unifiedOrder(reqDTO);
|
||||
|
|
Loading…
Reference in New Issue