支付改造

This commit is contained in:
zhuyang 2021-10-09 22:23:15 +08:00
parent 001892824c
commit af8f9745e9
13 changed files with 181 additions and 124 deletions

View File

@ -7,7 +7,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients(basePackages = {"cn.iocoder.mall.productservice.rpc"})
@EnableFeignClients(basePackages = {"cn.iocoder.mall.productservice.rpc","cn.iocoder.mall.payservice.rpc"})
public class ManagementWebApplication {
public static void main(String[] args) {

View File

@ -2,20 +2,20 @@ package cn.iocoder.mall.managementweb.client.pay.transaction;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.payservice.rpc.transaction.PayTransactionRpc;
import cn.iocoder.mall.payservice.rpc.transaction.PayTransactionFeign;
import cn.iocoder.mall.payservice.rpc.transaction.dto.PayTransactionPageReqDTO;
import cn.iocoder.mall.payservice.rpc.transaction.dto.PayTransactionRespDTO;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class PayTransactionClient {
@DubboReference(version = "${dubbo.consumer.PayTransactionRpc.version}")
private PayTransactionRpc payTransactionRpc;
@Autowired
private PayTransactionFeign payTransactionFeign;
public PageResult<PayTransactionRespDTO> pagePayTransaction(PayTransactionPageReqDTO pageReqDTO) {
CommonResult<PageResult<PayTransactionRespDTO>> pagePayTransactionResult = payTransactionRpc.pagePayTransaction(pageReqDTO);
CommonResult<PageResult<PayTransactionRespDTO>> pagePayTransactionResult = payTransactionFeign.pagePayTransaction(pageReqDTO);
pagePayTransactionResult.checkError();
return pagePayTransactionResult.getData();
}

View File

@ -31,5 +31,9 @@
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-openfeign-core</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,63 @@
package cn.iocoder.mall.payservice.rpc.transaction;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.payservice.rpc.transaction.dto.*;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
/**
* Title:
* Description:
*
* @author zhuyang
* @version 1.0 2021/10/9
*/
@FeignClient(value = "pay-service")
public interface PayTransactionFeign {
/**
* 创建支付交易单
*
* @param createReqDTO 创建信息
* @return 支付交易单号
*/
@PostMapping("/pay/transaction/createPayTransaction")
CommonResult<Integer> createPayTransaction(@RequestBody PayTransactionCreateReqDTO createReqDTO);
/**
* 提交支付交易单
*
* @param submitReqDTO 提交信息
* @return 提交响应包含三方支付的响应
*/
@PostMapping("/pay/transaction/submitPayTransaction")
CommonResult<PayTransactionSubmitRespDTO> submitPayTransaction(@RequestBody PayTransactionSubmitReqDTO submitReqDTO);
/**
* 获得当支付交易单
*
* @param getReqDTO 获得条件
* @return 支付交易单
*/
@PostMapping("/pay/transaction/getPayTransaction")
CommonResult<PayTransactionRespDTO> getPayTransaction(@RequestBody PayTransactionGetReqDTO getReqDTO);
/**
* 更新交易支付成功
*
* @param successReqDTO 支付成功信息
* @return 是否成功
*/
@PostMapping("/pay/transaction/updatePayTransactionSuccess")
CommonResult<Boolean> updatePayTransactionSuccess(@RequestBody PayTransactionSuccessReqDTO successReqDTO);
/**
* 获得交易支付单分页
*
* @param pageReqDTO 分页条件
* @return 交易支付单分页
*/
@PostMapping("/pay/transaction/pagePayTransaction")
CommonResult<PageResult<PayTransactionRespDTO>> pagePayTransaction(@RequestBody PayTransactionPageReqDTO pageReqDTO);
}

View File

@ -1,52 +0,0 @@
package cn.iocoder.mall.payservice.rpc.transaction;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.payservice.rpc.transaction.dto.*;
/**
* 支付交易单 RPC 接口
*/
public interface PayTransactionRpc {
/**
* 创建支付交易单
*
* @param createReqDTO 创建信息
* @return 支付交易单号
*/
CommonResult<Integer> createPayTransaction(PayTransactionCreateReqDTO createReqDTO);
/**
* 提交支付交易单
*
* @param submitReqDTO 提交信息
* @return 提交响应包含三方支付的响应
*/
CommonResult<PayTransactionSubmitRespDTO> submitPayTransaction(PayTransactionSubmitReqDTO submitReqDTO);
/**
* 获得当支付交易单
*
* @param getReqDTO 获得条件
* @return 支付交易单
*/
CommonResult<PayTransactionRespDTO> getPayTransaction(PayTransactionGetReqDTO getReqDTO);
/**
* 更新交易支付成功
*
* @param successReqDTO 支付成功信息
* @return 是否成功
*/
CommonResult<Boolean> updatePayTransactionSuccess(PayTransactionSuccessReqDTO successReqDTO);
/**
* 获得交易支付单分页
*
* @param pageReqDTO 分页条件
* @return 交易支付单分页
*/
CommonResult<PageResult<PayTransactionRespDTO>> pagePayTransaction(PayTransactionPageReqDTO pageReqDTO);
}

View File

@ -2,8 +2,12 @@ package cn.iocoder.mall.payservice;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class PayServiceApplication {
public static void main(String[] args) {

View File

@ -1,44 +0,0 @@
package cn.iocoder.mall.payservice.rpc.transaction;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.payservice.rpc.transaction.dto.*;
import cn.iocoder.mall.payservice.service.transaction.PayTransactionService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import static cn.iocoder.common.framework.vo.CommonResult.success;
@DubboService
public class PayTransactionRpcImpl implements PayTransactionRpc {
@Autowired
private PayTransactionService payTransactionService;
@Override
public CommonResult<Integer> createPayTransaction(PayTransactionCreateReqDTO createReqDTO) {
return success(payTransactionService.createPayTransaction(createReqDTO));
}
@Override
public CommonResult<PayTransactionSubmitRespDTO> submitPayTransaction(PayTransactionSubmitReqDTO submitReqDTO) {
return success(payTransactionService.submitPayTransaction(submitReqDTO));
}
@Override
public CommonResult<PayTransactionRespDTO> getPayTransaction(PayTransactionGetReqDTO getReqDTO) {
return success(payTransactionService.getPayTransaction(getReqDTO));
}
@Override
public CommonResult<Boolean> updatePayTransactionSuccess(PayTransactionSuccessReqDTO successReqDTO) {
return success(payTransactionService.updateTransactionPaySuccess(successReqDTO.getPayChannel(),
successReqDTO.getParams()));
}
@Override
public CommonResult<PageResult<PayTransactionRespDTO>> pagePayTransaction(PayTransactionPageReqDTO pageReqDTO) {
return success(payTransactionService.pagePayTransaction(pageReqDTO));
}
}

View File

@ -0,0 +1,81 @@
package controller;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.payservice.rpc.transaction.dto.*;
import cn.iocoder.mall.payservice.service.transaction.PayTransactionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import static cn.iocoder.common.framework.vo.CommonResult.success;
/**
* Title:
* Description:
*
* @author zhuyang
* @version 1.0 2021/10/9
*/
@RestController
@RequestMapping("/pay/transaction")
public class PayTransactionController {
@Autowired
private PayTransactionService payTransactionService;
/**
* 创建支付交易单
*
* @param createReqDTO 创建信息
* @return 支付交易单号
*/
@PostMapping("createPayTransaction")
CommonResult<Integer> createPayTransaction(@RequestBody PayTransactionCreateReqDTO createReqDTO){
return success(payTransactionService.createPayTransaction(createReqDTO));
}
/**
* 提交支付交易单
*
* @param submitReqDTO 提交信息
* @return 提交响应包含三方支付的响应
*/
@PostMapping("submitPayTransaction")
CommonResult<PayTransactionSubmitRespDTO> submitPayTransaction(@RequestBody PayTransactionSubmitReqDTO submitReqDTO){
return success(payTransactionService.submitPayTransaction(submitReqDTO));
}
/**
* 获得当支付交易单
*
* @param getReqDTO 获得条件
* @return 支付交易单
*/
@PostMapping("getPayTransaction")
CommonResult<PayTransactionRespDTO> getPayTransaction(@RequestBody PayTransactionGetReqDTO getReqDTO){
return success(payTransactionService.getPayTransaction(getReqDTO));}
/**
* 更新交易支付成功
*
* @param successReqDTO 支付成功信息
* @return 是否成功
*/
@PostMapping("updatePayTransactionSuccess")
CommonResult<Boolean> updatePayTransactionSuccess(@RequestBody PayTransactionSuccessReqDTO successReqDTO){
return success(payTransactionService.updateTransactionPaySuccess(successReqDTO.getPayChannel(),
successReqDTO.getParams()));}
/**
* 获得交易支付单分页
*
* @param pageReqDTO 分页条件
* @return 交易支付单分页
*/
@PostMapping("pagePayTransaction")
CommonResult<PageResult<PayTransactionRespDTO>> pagePayTransaction(@RequestBody PayTransactionPageReqDTO pageReqDTO){
return success(payTransactionService.pagePayTransaction(pageReqDTO));}
}

View File

@ -8,7 +8,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients(basePackages = {"cn.iocoder.mall.productservice.rpc","cn.iocoder.mall.searchservice.rpc",
"cn.iocoder.mall.tradeservice.rpc"})
"cn.iocoder.mall.tradeservice.rpc","cn.iocoder.mall.payservice.rpc"})
public class ShopWebApplication {
public static void main(String[] args) {

View File

@ -1,9 +1,9 @@
package cn.iocoder.mall.shopweb.client.pay;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.payservice.rpc.transaction.PayTransactionRpc;
import cn.iocoder.mall.payservice.rpc.transaction.PayTransactionFeign;
import cn.iocoder.mall.payservice.rpc.transaction.dto.*;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Objects;
@ -11,11 +11,12 @@ import java.util.Objects;
@Service
public class PayTransactionClient {
@DubboReference(version = "${dubbo.consumer.PayTransactionRpc.version}")
private PayTransactionRpc payTransactionRpc;
@Autowired
private PayTransactionFeign payTransactionFeign;
public PayTransactionRespDTO getPayTransaction(Integer userId, String appId, String orderId) {
CommonResult<PayTransactionRespDTO> getPayTransactionResult = payTransactionRpc.getPayTransaction(new PayTransactionGetReqDTO()
CommonResult<PayTransactionRespDTO> getPayTransactionResult = payTransactionFeign.getPayTransaction(new PayTransactionGetReqDTO()
.setAppId(appId).setOrderId(orderId));
getPayTransactionResult.checkError();
if (getPayTransactionResult.getData() == null) {
@ -27,13 +28,13 @@ public class PayTransactionClient {
}
public PayTransactionSubmitRespDTO submitPayTransaction(PayTransactionSubmitReqDTO submitReqDTO) {
CommonResult<PayTransactionSubmitRespDTO> submitPayTransactionResult = payTransactionRpc.submitPayTransaction(submitReqDTO);
CommonResult<PayTransactionSubmitRespDTO> submitPayTransactionResult = payTransactionFeign.submitPayTransaction(submitReqDTO);
submitPayTransactionResult.checkError();
return submitPayTransactionResult.getData();
}
public void updatePayTransactionSuccess(Integer payChannel, String params) {
CommonResult<Boolean> updatePayTransactionSuccessResult = payTransactionRpc.updatePayTransactionSuccess(
CommonResult<Boolean> updatePayTransactionSuccessResult = payTransactionFeign.updatePayTransactionSuccess(
new PayTransactionSuccessReqDTO().setPayChannel(payChannel).setParams(params));
updatePayTransactionSuccessResult.checkError();
}

View File

@ -25,7 +25,7 @@ public interface CartFeign {
* @param addReqDTO 添加商品信息
* @return 成功
*/
@PostMapping("addCartItem")
@PostMapping("/trade/cart/addCartItem")
CommonResult<Boolean> addCartItem(@RequestBody CartItemAddReqDTO addReqDTO);
/**
@ -34,7 +34,7 @@ public interface CartFeign {
* @param updateQuantityReqDTO 更新商品数量 DTO
* @return 成功
*/
@PostMapping("updateCartItemQuantity")
@PostMapping("/trade/cart/updateCartItemQuantity")
CommonResult<Boolean> updateCartItemQuantity(@RequestBody CartItemUpdateQuantityReqDTO updateQuantityReqDTO);
/**
@ -43,7 +43,7 @@ public interface CartFeign {
* @param updateSelectedReqDTO 更新商品是否选中 DTO
* @return 成功
*/
@PostMapping("updateCartItemSelected")
@PostMapping("/trade/cart/updateCartItemSelected")
CommonResult<Boolean> updateCartItemSelected(@RequestBody CartItemUpdateSelectedReqDTO updateSelectedReqDTO);
/**
@ -52,10 +52,10 @@ public interface CartFeign {
* @param deleteListReqDTO 删除商品列表 DTO
* @return 成功
*/
@PostMapping("deleteCartItems")
@PostMapping("/trade/cart/deleteCartItems")
CommonResult<Boolean> deleteCartItems(@RequestBody CartItemDeleteListReqDTO deleteListReqDTO);
@GetMapping("/sumCartItemQuantity")
public CommonResult<Integer> sumCartItemQuantity(@RequestParam("userId") Integer userId) ;
@PostMapping("/listCartItems")
@PostMapping("/trade/cart/listCartItems")
public CommonResult<List<CartItemRespDTO>> listCartItems(@RequestBody CartItemListReqDTO listReqDTO) ;
}

View File

@ -29,7 +29,7 @@ public interface TradeOrderFeign {
* @param createReqDTO 订单信息
* @return 订单编号
*/
@PostMapping("createTradeOrder")
@PostMapping("/trade/order/createTradeOrder")
CommonResult<Integer> createTradeOrder(@RequestBody TradeOrderCreateReqDTO createReqDTO);
/**
@ -39,7 +39,7 @@ public interface TradeOrderFeign {
* @param fields 额外返回字段可见 {@link cn.iocoder.mall.tradeservice.enums.order.TradeOrderDetailFieldEnum}
* @return 订单交易
*/
@GetMapping("getTradeOrder")
@GetMapping("/trade/order/getTradeOrder")
CommonResult<TradeOrderRespDTO> getTradeOrder(@RequestParam("tradeOrderId")Integer tradeOrderId, @RequestParam("fields") Collection<String> fields);
/**
* 获得交易订单分页
@ -47,7 +47,7 @@ public interface TradeOrderFeign {
* @param pageDTO 订单交易分页查询
* @return 订单交易分页结果
*/
@PostMapping("pageTradeOrder")
@PostMapping("/trade/order/pageTradeOrder")
CommonResult<PageResult<TradeOrderRespDTO>> pageTradeOrder(@RequestBody TradeOrderPageReqDTO pageDTO);
// TODO 芋艿需要重构成入参是 DTO方便后续升级返回是 CommonResult用于返回失败的原因
@ -60,6 +60,6 @@ public interface TradeOrderFeign {
* @param payAmount 支付金额
* @return 成功
*/
@PostMapping("updateTradeOrderPaySuccess")
@PostMapping("/trade/order/updateTradeOrderPaySuccess")
CommonResult<Boolean> updateTradeOrderPaySuccess(@RequestParam("tradeOrderId") String tradeOrderId, @RequestParam("payAmount")Integer payAmount);
}

View File

@ -1,19 +1,19 @@
package cn.iocoder.mall.tradeservice.client.pay;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.payservice.rpc.transaction.PayTransactionRpc;
import cn.iocoder.mall.payservice.rpc.transaction.PayTransactionFeign;
import cn.iocoder.mall.payservice.rpc.transaction.dto.PayTransactionCreateReqDTO;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class PayTransactionClient {
@DubboReference(version = "${dubbo.consumer.PayTransactionRpc.version}")
private PayTransactionRpc payTransactionRpc;
@Autowired
private PayTransactionFeign payTransactionFeign;
public Integer createPayTransaction(PayTransactionCreateReqDTO createReqDTO) {
CommonResult<Integer> createPayTransactionResult = payTransactionRpc.createPayTransaction(createReqDTO);
CommonResult<Integer> createPayTransactionResult = payTransactionFeign.createPayTransaction(createReqDTO);
createPayTransactionResult.checkError();
return createPayTransactionResult.getData();
}