shikeying
2024-01-11 3b67e947e36133e2a40eb2737b15ea375e157ea0
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
package com.walker.pay.allinpaycloud.generator;
 
import com.allinpay.sdk.bean.OpenResponse;
import com.walker.infrastructure.arguments.Variable;
import com.walker.pay.Order;
import com.walker.pay.PayContext;
import com.walker.pay.ResponsePay;
import com.walker.pay.allinpaycloud.BaseOrderGenerator;
import com.walker.pay.allinpaycloud.Constants;
import com.walker.pay.allinpaycloud.util.OrderUtils;
 
import java.util.Map;
 
/**
 * 微信JS支付订单生成器(公众号)
 * @author 时克英
 * @date 2023-02-27
 */
public class WechatJsOrderGenerator extends BaseOrderGenerator {
 
    @Override
    protected ResponsePay invoke(PayContext payContext, Order platformOrder) {
        this.checkSdkClient();
        OpenResponse response = this.getSdkClient().consumeApply(platformOrder);
        if(response == null){
            throw new RuntimeException("调用'通商云'订单返回空数据, orderId = " + platformOrder.getId());
        }
 
        OrderResponsePay responseValue = new OrderResponsePay();
 
        if (!Constants.SUB_CODE_OK.equals(response.getSubCode())) {
            responseValue.setStatus(false);
            responseValue.setMessage(response.getSubMsg());
            logger.debug("'微信js支付'订单返回失败:{}", response.getSubMsg());
            return responseValue;
        }
 
        if(logger.isDebugEnabled()){
            logger.debug(response.getData());
        }
 
        try {
            responseValue = OrderUtils.getOrderResponsePay(response.getData());
            if(responseValue == null){
                throw new RuntimeException("orderResponsePay = null!");
            }
            return responseValue;
 
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            throw new RuntimeException("调用'通商云'订单数据转换对象失败, orderId = " + platformOrder.getId());
        }
    }
 
    @Deprecated
    @Override
    protected ResponsePay invoke(String providerPayType, Order platformOrder, Map<String, Variable> configuration) {
        return null;
    }
}