单元测试 在线支付订单、退款

This commit is contained in:
Lemon
2023-08-30 11:02:18 +08:00
parent 6ae0503956
commit 39087d9b10
3 changed files with 1887 additions and 1865 deletions

View File

@@ -231,23 +231,32 @@ public class SpringBootTestController {
// 生成订单 // 生成订单
// OrderBasicInfo orderBasicInfo = generateAnOrder(); // OrderBasicInfo orderBasicInfo = generateAnOrder();
// System.out.println(orderBasicInfo); // System.out.println(orderBasicInfo);
// 支付订单 // // 支付订单
// int a = payOrder(orderBasicInfo); // int a = payOrder(orderBasicInfo);
// System.out.println(a); // System.out.println(a);
// 结算订单 // 结算订单
OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode("C65033300551"); OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode("C46006767636");
settleOrder(orderBasicInfo); settleOrder(orderBasicInfo);
// 订单退款 // 订单退款
BigDecimal payAmount = orderBasicInfo.getPayAmount();
BigDecimal settleAmount = orderBasicInfo.getSettleAmount();
BigDecimal refundAmt = payAmount.subtract(settleAmount);
// 延时分账的,可以部分解冻
memberAdapayRecordService.updateRefundAmountFromFreezeAmount("1234", refundAmt);
// 实时分账,全部解冻
// memberAdapayRecordService.unfreezeAmountAndUpdateSpendAmount("test01", payAmount, refundAmt);
} }
// 生成订单
private OrderBasicInfo generateAnOrder() throws ParseException { private OrderBasicInfo generateAnOrder() throws ParseException {
GenerateOrderDTO dto = new GenerateOrderDTO(); GenerateOrderDTO dto = new GenerateOrderDTO();
PileConnectorDetailVO vo = new PileConnectorDetailVO(); PileConnectorDetailVO vo = new PileConnectorDetailVO();
vo.setStationId("2"); vo.setStationId("2");
dto.setPileConnector(vo); dto.setPileConnector(vo);
dto.setMemberId("67945248"); dto.setMemberId("1");
dto.setStartMode("1"); dto.setStartMode("1");
dto.setPayMode("4"); dto.setPayMode("4");
dto.setPileSn("88000000000001"); dto.setPileSn("88000000000001");
@@ -261,6 +270,7 @@ public class SpringBootTestController {
return orderBasicInfo; return orderBasicInfo;
} }
// 支付订单
private int payOrder(OrderBasicInfo orderBasicInfo) throws Exception { private int payOrder(OrderBasicInfo orderBasicInfo) throws Exception {
// PayOrderDTO dto = new PayOrderDTO(); // PayOrderDTO dto = new PayOrderDTO();
// dto.setMemberId(orderBasicInfo.getMemberId()); // dto.setMemberId(orderBasicInfo.getMemberId());
@@ -271,7 +281,7 @@ public class SpringBootTestController {
// //
// Map<String, Object> map = orderBasicInfoService.payOrder(dto); // Map<String, Object> map = orderBasicInfoService.payOrder(dto);
// return map; // return map;
String paymentId = "test01"; String paymentId = "1234";
BigDecimal amount = orderBasicInfo.getPayAmount(); BigDecimal amount = orderBasicInfo.getPayAmount();
String orderCode = orderBasicInfo.getOrderCode(); String orderCode = orderBasicInfo.getOrderCode();
@@ -315,7 +325,7 @@ public class SpringBootTestController {
} }
// 结算订单
private void settleOrder(OrderBasicInfo orderBasicInfo) { private void settleOrder(OrderBasicInfo orderBasicInfo) {
TransactionRecordsData data = TransactionRecordsData.builder() TransactionRecordsData data = TransactionRecordsData.builder()
.transactionCode(orderBasicInfo.getTransactionCode()) .transactionCode(orderBasicInfo.getTransactionCode())
@@ -346,7 +356,16 @@ public class SpringBootTestController {
.build(); .build();
orderBasicInfoService.settleOrder(data, orderBasicInfo); // orderBasicInfoService.settleOrder(data, orderBasicInfo);
// 获取更新数据后的orderBasicInfo对象
orderBasicInfoService.returnUpdateOrderBasicInfo(orderBasicInfo, data);
// 获取更新数据后的orderDetail对象/更新订单详情 查询订单详情 修改订单数据
OrderDetail orderDetail = orderBasicInfoService.returnUpdateOrderDetail(orderBasicInfo, data);
// 更新数据库
OrderTransactionDTO dto = new OrderTransactionDTO();
dto.setOrderBasicInfo(orderBasicInfo);
dto.setOrderDetail(orderDetail);
transactionService.doUpdateOrder(dto);
} }

View File

@@ -339,4 +339,7 @@ public interface IOrderBasicInfoService {
*/ */
void retryRefundOrder(String orderCode) throws BaseAdaPayException; void retryRefundOrder(String orderCode) throws BaseAdaPayException;
void returnUpdateOrderBasicInfo(OrderBasicInfo orderBasicInfo, TransactionRecordsData data);
OrderDetail returnUpdateOrderDetail(OrderBasicInfo orderBasicInfo, TransactionRecordsData data);
} }

View File

@@ -889,7 +889,7 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
* 返回更新后的OrderBasicInfo对象 * 返回更新后的OrderBasicInfo对象
* 专用方法,其他地方如果要用请仔细检查 * 专用方法,其他地方如果要用请仔细检查
*/ */
private void returnUpdateOrderBasicInfo(OrderBasicInfo orderBasicInfo, TransactionRecordsData data) { public void returnUpdateOrderBasicInfo(OrderBasicInfo orderBasicInfo, TransactionRecordsData data) {
// 订单编号 // 订单编号
String orderCode = orderBasicInfo.getOrderCode(); String orderCode = orderBasicInfo.getOrderCode();
// 消费金额就是订单总金额/交易记录传过来的消费金额 // 消费金额就是订单总金额/交易记录传过来的消费金额
@@ -929,7 +929,7 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
* *
* @return 查询并更新过数据的orderDetail * @return 查询并更新过数据的orderDetail
*/ */
private OrderDetail returnUpdateOrderDetail(OrderBasicInfo orderBasicInfo, TransactionRecordsData data) { public OrderDetail returnUpdateOrderDetail(OrderBasicInfo orderBasicInfo, TransactionRecordsData data) {
String orderCode = orderBasicInfo.getOrderCode(); String orderCode = orderBasicInfo.getOrderCode();
BigDecimal orderAmount = orderBasicInfo.getOrderAmount(); BigDecimal orderAmount = orderBasicInfo.getOrderAmount();
// 更新订单详情 查询订单详情 修改订单数据 // 更新订单详情 查询订单详情 修改订单数据