-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_test.go
75 lines (64 loc) · 1.45 KB
/
client_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
package alipay
import (
"os"
"strconv"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
var (
client *Client
outTradeNo string
)
func init() {
var err error
client, err = newTestClient()
if err != nil {
panic(err)
}
outTradeNo = strconv.FormatInt(time.Now().UnixNano(), 10)
}
func newTestClient() (*Client, error) {
options := Options{
Gateway: GatewayDevelopment,
AppID: os.Getenv("APP_ID"),
AppPrivateKey: os.Getenv("APP_PRIVATE_KEY"),
AlipayPublicKey: os.Getenv("ALIPAY_PUBLIC_KEY"),
}
return NewClient(options)
}
func TestClient_Execute(t *testing.T) {
request := TradePrecreateRequest{
OutTradeNo: outTradeNo,
TotalAmount: "0.01",
Subject: "fresh meat",
}
var response TradePrecreateResponse
err := client.Execute(request, &response)
assert.NoError(t, err)
assert.True(t, response.IsSuccess())
t.Logf("%#v", response)
}
func TestClient_SDKExecute(t *testing.T) {
request := TradeAppPayRequest{
TotalAmount: "0.01",
Subject: "fresh meat",
OutTradeNo: outTradeNo,
}
query, err := client.SDKExecute(request)
assert.NoError(t, err)
assert.NotEmpty(t, query)
t.Log(query)
}
func TestClient_PageExecute(t *testing.T) {
request := TradePagePayRequest{
OutTradeNo: outTradeNo,
ProductCode: "FAST_INSTANT_TRADE_PAY",
TotalAmount: "0.01",
Subject: "fresh meat",
}
url, err := client.PageExecute(request)
assert.NoError(t, err)
assert.NotEmpty(t, url)
t.Log(url)
}