forked from smartwalle/alipay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trade_test.go
142 lines (125 loc) · 3.36 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
package alipay_test
import (
"testing"
alipay "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.FailNow()
}
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(p)
if err != nil {
t.Fatal(err)
}
if rsp.Content.Code != alipay.CodeSuccess {
t.Fatal(rsp.Content.Msg, rsp.Content.SubMsg)
}
t.Log(rsp.Content.QRCode)
}
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(p)
if err != nil {
t.Fatal(err)
}
if rsp.Content.Code != alipay.CodeSuccess {
t.Fatal(rsp.Content.Code, rsp.Content.Msg, rsp.Content.SubMsg)
}
t.Log(rsp.Content.Msg)
}
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(p)
if err != nil {
t.Fatal(err)
}
if rsp.Content.Code != alipay.CodeSuccess {
t.Fatal(rsp.Content.Code, rsp.Content.Msg, rsp.Content.SubMsg)
}
t.Log(rsp.Content.Msg)
}
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(p)
if err != nil {
t.Fatal(err)
}
t.Logf("%v", rsp.Content)
}
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(p)
if err != nil {
t.Fatal(err)
}
t.Logf("%v", rsp.Content)
}
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(p)
if err != nil {
t.Fatal(err)
}
t.Logf("%v", rsp.Content)
}