-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient_test.go
More file actions
178 lines (170 loc) · 3.9 KB
/
client_test.go
File metadata and controls
178 lines (170 loc) · 3.9 KB
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
package appstoreserverapi
import (
"encoding/json"
"fmt"
"testing"
"time"
)
// 下面都是示例,值并不真实
var (
// 发行人: 您在 App Store Connect 中的密钥页面中的发行者 ID(例如:" 57246542-96fe-1a63-e053-0824d011072a")
// Issuer: Your issuer ID from the Keys page in App Store Connect (Ex: "57246542-96fe-1a63-e053-0824d011072a")
ISS = "57246542-96fe-1a63-e053-0824d011072a"
// 秘钥:您在 App Store Connect 中的私钥 ID(例如2X9R4HXF34:)
// Key ID: Your private key ID from App Store Connect (Ex: 2X9R4HXF34)
KID = "2X9R4HXF34"
// 应用的BundleID(例如:“com.example.testbundleid2021”)
// Bundle ID: Your app’s bundle ID (Ex: “com.example.testbundleid2021”)
BID = "com.example.testbundleid2021"
// 受众:appstoreconnect-v1
// Audience: appstoreconnect-v1
AUD = "appstoreconnect-v1"
// 签名的秘钥
// sign private key, eg:
PK = `-----BEGIN PRIVATE KEY-----
MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgnZRzSXl8m
u+DLgvWUTOvUitOCavNBqi1135GgCgYIKoZIzj0DAQehRANCAATIDAZUQ
FEjZIaV1pq1/OYCJ
-----END PRIVATE KEY-----`
)
func TestClient_GetAllSubscriptionStatuses(t *testing.T) {
c, err := NewClient(&Config{
Iss: ISS,
Kid: KID,
Bid: BID,
Pk: PK,
Aud: AUD,
ExpiryIn: time.Second * 6,
})
if err != nil {
t.Error(err)
return
}
r, err := c.ApiGetAllSubscriptionStatuses("180001239612922")
if err != nil {
t.Error(err)
return
}
b, _ := json.Marshal(r)
fmt.Println(string(b))
}
func TestClient_LookUpOrderId(t *testing.T) {
c, err := NewClient(&Config{
Iss: ISS,
Kid: KID,
Bid: BID,
Pk: PK,
Aud: AUD,
ExpiryIn: time.Minute * 10,
})
if err != nil {
t.Error(err)
return
}
r, err := c.ApiLookUpOrderId("MQKN8D872M")
if err != nil {
t.Error(err)
return
}
b, _ := json.Marshal(r)
fmt.Println(string(b))
}
func TestClient_GetTransactionHistory(t *testing.T) {
c, err := NewClient(&Config{
Iss: ISS,
Kid: KID,
Bid: BID,
Pk: PK,
Aud: AUD,
ExpiryIn: time.Minute * 10,
TryCount: 1,
})
if err != nil {
t.Error(err)
return
}
r, err := c.ApiGetTransactionHistory("52000104826360", false)
if err != nil {
t.Error(err)
return
}
b, _ := json.Marshal(r)
fmt.Println(string(b))
}
func TestClient_ApiGetRefundHistory(t *testing.T) {
c, err := NewClient(&Config{
Iss: ISS,
Kid: KID,
Bid: BID,
Pk: PK,
Aud: AUD,
ExpiryIn: time.Minute * 10,
})
if err != nil {
t.Error(err)
return
}
r, err := c.ApiGetRefundHistory("180001267635832", false)
if err != nil {
t.Error(err)
return
}
b, _ := json.Marshal(r)
fmt.Println(string(b))
}
func TestClient_ApiExtendAsubscriptionRenewalDate(t *testing.T) {
c, err := NewClient(&Config{
Iss: ISS,
Kid: KID,
Bid: BID,
Pk: PK,
Aud: AUD,
ExpiryIn: time.Minute * 10,
})
if err != nil {
t.Error(err)
return
}
r, err := c.ApiExtendAsubscriptionRenewalDate("180001267635832", ExtendRenewalDateRequest{
ExtendByDays: 30,
ExtendReasonCode: 1,
RequestIdentifier: "sdadsa234asfafadfadfas",
})
if err != nil {
t.Error(err)
return
}
b, _ := json.Marshal(r)
fmt.Println(string(b))
}
func TestClient_ApiSendConsumptionInformation(t *testing.T) {
c, err := NewClient(&Config{
Iss: ISS,
Kid: KID,
Bid: BID,
Pk: PK,
Aud: AUD,
ExpiryIn: time.Minute * 10,
})
if err != nil {
t.Error(err)
return
}
err = c.ApiSendConsumptionInformation("180001267635832", ConsumptionRequest{
AccountTenure: 0,
AppAccountToken: "",
ConsumptionStatus: 0,
CustomerConsented: false,
DeliveryStatus: 0,
LifetimeDollarsPurchased: 0,
LifetimeDollarsRefunded: 0,
Platform: 0,
PlayTime: 0,
SampleContentProvided: false,
UserStatus: 0,
})
if err != nil {
t.Error(err)
return
}
}