xuhy
2025-01-09 712f70b2936079a131ecb1e63c6d337171618cad
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
package com.stylefeng.guns.modular.cloudPayment.example;
 
import com.unionpay.upyzt.exception.UpyztException;
import com.unionpay.upyzt.model.Refund;
import com.unionpay.upyzt.resp.RefundResp;
 
import java.time.OffsetDateTime;
import java.util.HashMap;
import java.util.Map;
 
public class RefundExample {
 
    public RefundExample(String tradeId) {
        this.tradeId = tradeId;
    }
 
    protected String tradeId;
 
 
    public static void main(String[] args) throws UpyztException {
        RefundExample refundExample = new RefundExample("1auoc0c0pp7obv4cptjpm6ej5dzohcgl");
        // 退款
        RefundResp refundResp = refundExample.create();
    }
 
    /**
     * 运行 Demos
     *
     * @param tradeId 交易ID
     */
    public static String runDemos(String tradeId) throws UpyztException {
        RefundExample refundExample = new RefundExample(tradeId);
 
        // 退款
        RefundResp refundResp = refundExample.create();
 
        // 退款订单查询(系统订单号)
        refundResp = refundExample.retrieveById(refundResp.getRefundId());
 
        // 退款订单查询(平台订单号)
        refundResp = refundExample.retrieveByOutOrderNo(refundResp.getOutOrderNo());
 
        return refundResp.getRefundId();
    }
 
    /**
     * 退款
     *
     * @return 返回参数
     * @throws UpyztException 异常
     */
    public RefundResp create() throws UpyztException {
        Map<String, Object> params = new HashMap<>();
//        params.put("out_order_no", "1auoc0c0pp7obv4cptjpm6ej5dzohcgl");
        params.put("out_order_no", "3209588457394236519");
        params.put("sent_at", OffsetDateTime.now().toString());
        params.put("amount", 100);
        params.put("orig_trade_id", this.tradeId);
        params.put("remark", "用于 SDK 示例测试");
        // params.put("total_amount", 101);
        // params.put("discount_amount", 1);
 
        System.out.println("------- 退款 -------");
        RefundResp resp = Refund.create(params);
        System.out.println(resp);
        return resp;
    }
 
    /**
     * 退款订单查询(系统订单号)
     *
     * @return 返回参数
     * @throws UpyztException 异常
     */
    public RefundResp retrieveById(String id) throws UpyztException {
        System.out.println("------- 退款订单查询(系统订单号) -------");
        RefundResp resp = Refund.retrieveById(id);
        System.out.println(resp);
        return resp;
    }
 
    /**
     * 退款订单查询(平台订单号)
     *
     * @return 返回参数
     * @throws UpyztException 异常
     */
    public RefundResp retrieveByOutOrderNo(String outOrderNo) throws UpyztException {
        System.out.println("------- 退款订单查询(平台订单号) -------");
        RefundResp resp = Refund.retrieveByOutOrderNo(outOrderNo);
        System.out.println(resp);
        return resp;
    }
 
}