-
Notifications
You must be signed in to change notification settings - Fork 429
/
trade_test.go
222 lines (186 loc) · 4.99 KB
/
trade_test.go
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
package alipay_test
import (
"context"
"testing"
"github.com/smartwalle/alipay/v3"
)
func TestClient_TradeAppPay(t *testing.T) {
t.Log("========== TradeAppPay ==========")
var p = alipay.TradeAppPay{}
p.NotifyURL = "http://203.86.24.181:3000/alipay"
p.Body = "body"
p.Subject = "商品标题"
p.OutTradeNo = "01010101"
p.TotalAmount = "100.00"
p.ProductCode = "p_1010101"
param, err := client.TradeAppPay(p)
if err != nil {
t.Fatal(err)
}
t.Log(param)
}
func TestClient_TradePagePay(t *testing.T) {
t.Log("========== TradePagePay ==========")
var p = alipay.TradePagePay{}
p.NotifyURL = "http://220.112.233.229:3000/alipay"
p.ReturnURL = "http://220.112.233.229:3000"
p.Subject = "修正了中文的 Bug"
p.OutTradeNo = "trade_no_201706230111212"
p.TotalAmount = "10.00"
p.ProductCode = "FAST_INSTANT_TRADE_PAY"
p.GoodsDetail = []*alipay.GoodsDetail{&alipay.GoodsDetail{
GoodsId: "123",
GoodsName: "xxx",
Quantity: 1,
Price: 13,
}}
url, err := client.TradePagePay(p)
if err != nil {
t.Fatal(err)
}
t.Log(url)
}
func TestClient_TradePreCreate(t *testing.T) {
t.Log("========== TradePreCreate ==========")
var p = alipay.TradePreCreate{}
p.OutTradeNo = "no_0001"
p.Subject = "测试订单"
p.TotalAmount = "10.10"
rsp, err := client.TradePreCreate(context.Background(), p)
if err != nil {
t.Fatal(err)
}
if rsp.IsFailure() {
t.Fatal(rsp.Msg, rsp.SubMsg)
}
t.Logf("%v", rsp)
}
func TestClient_TradePay(t *testing.T) {
t.Log("========== Trade ==========")
var p = alipay.TradePay{}
p.OutTradeNo = "no_000111"
p.Subject = "测试订单"
p.TotalAmount = "10.10"
p.Scene = "bar_code"
p.AuthCode = "扫描用户的支付码"
rsp, err := client.TradePay(context.Background(), p)
if err != nil {
t.Fatal(err)
}
if rsp.IsFailure() {
t.Fatal(rsp.Msg, rsp.SubMsg)
}
t.Logf("%v", rsp)
}
func TestClient_TradeQuery(t *testing.T) {
t.Log("========== TradeQuery ==========")
var p = alipay.TradeQuery{}
p.OutTradeNo = "trade_no_20170623021124"
p.QueryOptions = []string{"TRADE_SETTLE_INFO"}
rsp, err := client.TradeQuery(context.Background(), p)
if err != nil {
t.Fatal(err)
}
if rsp.IsFailure() {
t.Fatal(rsp.Code, rsp.Msg, rsp.SubMsg)
}
t.Logf("%v", rsp)
}
func TestClient_TradeQuery2(t *testing.T) {
t.Log("========== TradeQuery ==========")
var p = alipay.NewPayload("alipay.trade.query")
p.AddBizField("out_trade_no", "trade_no_20170623021124")
p.AddBizField("query_options", []string{"TRADE_SETTLE_INFO"})
var rsp *alipay.TradeQueryRsp
var err = client.Request(context.Background(), p, &rsp)
if err != nil {
t.Fatal(err)
}
if rsp.IsFailure() {
t.Fatal(rsp.Code, rsp.Msg, rsp.SubMsg)
}
t.Logf("%v", rsp)
}
func TestClient_TradeQuery3(t *testing.T) {
t.Log("========== TradeQuery ==========")
var p = alipay.NewPayload("alipay.trade.query")
p.AddBizField("out_trade_no", "trade_no_20170623021124")
p.AddBizField("query_options", []string{"TRADE_SETTLE_INFO"})
var rsp map[string]interface{}
var err = client.Request(context.Background(), p, &rsp)
if err != nil {
t.Fatal(err)
}
t.Logf("%v", rsp)
}
func TestClient_TradeRefund(t *testing.T) {
t.Log("========== TradeRefund ==========")
var p = alipay.TradeRefund{}
p.RefundAmount = "100"
p.OutTradeNo = "trade_no_20170623021124"
p.OutRequestNo = "111"
rsp, err := client.TradeRefund(context.Background(), p)
if err != nil {
t.Fatal(err)
}
if rsp.IsFailure() {
t.Fatal(rsp.Msg, rsp.SubMsg)
}
t.Logf("%v", rsp)
}
func TestClient_TradeFastPayRefundQuery(t *testing.T) {
t.Log("========== TradeFastPayRefundQuery ==========")
var p = alipay.TradeFastPayRefundQuery{}
p.OutTradeNo = "trade_no_20170623021124"
p.OutRequestNo = "11"
p.QueryOptions = []string{"refund_detail_item_list"}
rsp, err := client.TradeFastPayRefundQuery(context.Background(), p)
if err != nil {
t.Fatal(err)
}
if rsp.IsFailure() {
t.Fatal(rsp.Msg, rsp.SubMsg)
}
t.Logf("%v", rsp)
}
func TestClient_TradeRefundAsync(t *testing.T) {
t.Log("========== TradeRefundAsync ==========")
var p = alipay.TradeRefundAsync{}
p.OutTradeNo = "20150320010101001"
p.RefundAmount = "10.12"
p.RefundReason = "测试退款"
p.OutRequestNo = "20150320010101001uk"
p.NotifyURL = "http://127.0.0.1:9090/notify/ali-refund"
rsp, err := client.TradeRefundAsync(context.Background(), p)
if err != nil {
t.Fatal(err)
}
if rsp.IsFailure() {
t.Fatal(rsp.Msg, rsp.SubMsg)
}
t.Logf("%v", rsp)
}
func TestClient_TradeMergePreCreate(t *testing.T) {
t.Log("========== TradeMergePreCreate ==========")
var p = alipay.TradeMergePreCreate{}
rsp, err := client.TradeMergePreCreate(context.Background(), p)
if err != nil {
t.Fatal(err)
}
if rsp.IsFailure() {
t.Fatal(rsp.Msg, rsp.SubMsg)
}
t.Logf("%v", rsp)
}
func TestClient_OpenMiniOrderCreate(t *testing.T) {
t.Log("========== OpenMiniOrderCreate ==========")
var p = alipay.OpenMiniOrderCreate{}
rsp, err := client.OpenMiniOrderCreate(context.Background(), p)
if err != nil {
t.Fatal(err)
}
if rsp.IsFailure() {
t.Fatal(rsp.Msg, rsp.SubMsg)
}
t.Logf("%v", rsp)
}