RtMallScanOrderApi.java
5.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package com.diligrp.cashier.mall.api;
import com.diligrp.cashier.mall.domain.rtmall.RtMarkMessage;
import com.diligrp.cashier.mall.domain.rtmall.co.OrderCO;
import com.diligrp.cashier.mall.domain.rtmall.co.OrderInfoCO;
import com.diligrp.cashier.mall.domain.rtmall.co.PaymentAllocateCO;
import com.diligrp.cashier.mall.domain.rtmall.co.RefundCO;
import com.diligrp.cashier.mall.domain.rtmall.vo.OrderPaymentVO;
import com.diligrp.cashier.mall.domain.rtmall.vo.OrderSuccessVO;
import com.diligrp.cashier.mall.domain.rtmall.vo.RefundSuccessVO;
import com.diligrp.cashier.mall.service.biz.MallBizOrderService;
import com.diligrp.cashier.mall.service.biz.MallBizPaymentService;
import com.diligrp.cashier.mall.service.biz.MallBizRefundService;
import com.diligrp.cashier.mall.sign.RtMallSign;
import com.diligrp.cashier.mall.type.OrderType;
import com.diligrp.cashier.mall.util.RtMallValidateUtils;
import com.diligrp.cashier.shared.annotation.ParamLogPrint;
import com.diligrp.cashier.shared.annotation.RepeatSubmit;
import com.diligrp.cashier.shared.annotation.Sign;
import com.diligrp.cashier.shared.handler.duplication.SpelDuplicationSubmit;
import com.diligrp.cashier.shared.util.JsonUtils;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
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 java.util.List;
/**
* 扫码下单接口
* Pos扫支付码后,推送订单信息到商户,商户返回收银台链接
*/
@RestController
@RequestMapping(path = {"/api/rt/mall/scan", "/rt/mall/scan"})
@Validated
public class RtMallScanOrderApi {
@Resource
private MallBizPaymentService mallBizPaymentService;
@Resource
private MallBizOrderService mallBizOrderService;
@Resource
private MallBizRefundService mallBizRefundService;
/**
* 扫码下单接口
* Pos扫支付码后,推送订单信息到商户,商户返回收银台链接
* https://shopex.yuque.com/hl0rrx/vlp0m4/kmcazgnimg28d8ih?singleDoc#oJ2JC
*/
@PostMapping("/order/v1")
@ParamLogPrint(outPrint = true)
@Sign(sign = RtMallSign.class)
@RepeatSubmit(prefix = "order_payment_sync:", value = "#req['trade_id']", duplicationSubmit = SpelDuplicationSubmit.class)
public RtMarkMessage<OrderSuccessVO> createOrderPayment(@Valid @RequestBody Object req) {
OrderCO orderCo = JsonUtils.convertValue(req, OrderCO.class);
orderCo.setOrderType(OrderType.OFFLINE_SCAN.code);
RtMallValidateUtils.valid(orderCo);
return RtMarkMessage.success(mallBizOrderService.createOrder(List.of(orderCo)));
}
/**
* 支付分摊回调接口
* POS完成支付分摊后,调用此接口通知商户商品信息已就绪
* https://shopex.yuque.com/hl0rrx/vlp0m4/kmcazgnimg28d8ih?singleDoc#NdciR
*/
@PostMapping("/order/v1/callback")
@ParamLogPrint(outPrint = true)
@Sign(sign = RtMallSign.class)
public RtMarkMessage<?> handlePaymentAllocate(@Valid @RequestBody Object req) {
PaymentAllocateCO allocateCo = JsonUtils.convertValue(req, PaymentAllocateCO.class);
RtMallValidateUtils.valid(allocateCo);
mallBizPaymentService.handlePaymentAllocate(allocateCo);
return RtMarkMessage.success();
}
/**
* info
* @see https://shopex.yuque.com/hl0rrx/vlp0m4/kmcazgnimg28d8ih?singleDoc#jRAS2
* 查询订单详情
*/
@PostMapping("/order/v1/info")
@ParamLogPrint(outPrint = true)
@Sign(sign = RtMallSign.class)
public RtMarkMessage<OrderPaymentVO> info(@RequestBody Object req) {
OrderInfoCO orderInfoCo = JsonUtils.convertValue(req, OrderInfoCO.class);
RtMallValidateUtils.valid(orderInfoCo);
return RtMarkMessage.success(mallBizOrderService.info(orderInfoCo));
}
/**
* status
* @see https://shopex.yuque.com/hl0rrx/vlp0m4/kmcazgnimg28d8ih?singleDoc#iHWnf
* 查询支付单状态
*/
@PostMapping("/order/v1/status")
@ParamLogPrint(outPrint = true)
@Sign(sign = RtMallSign.class)
public RtMarkMessage<OrderPaymentVO> status(@RequestBody Object req) {
OrderInfoCO orderInfoCo = JsonUtils.convertValue(req, OrderInfoCO.class);
RtMallValidateUtils.valid(orderInfoCo);
return RtMarkMessage.success(mallBizOrderService.info(orderInfoCo));
}
/**
* cancel
* @see https://shopex.yuque.com/hl0rrx/vlp0m4/kmcazgnimg28d8ih?singleDoc#iHWnf
* 取消支付流水
*/
@PostMapping("/payment/v1/cancel")
@ParamLogPrint(outPrint = true)
@Sign(sign = RtMallSign.class)
@RepeatSubmit(prefix = "refund:", value = {"#req['order_id']", "#req['trade_id']"}, duplicationSubmit = SpelDuplicationSubmit.class)
public RtMarkMessage<RefundSuccessVO> cancel(@RequestBody Object req) {
RefundCO refundCo = JsonUtils.convertValue(req, RefundCO.class);
RtMallValidateUtils.valid(refundCo);
return RtMarkMessage.success(mallBizRefundService.refund(refundCo));
}
}