1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Xsolla\SDK\Tests\Integration\API; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @group api |
7
|
|
|
*/ |
8
|
|
|
class SubscriptionsTest extends AbstractAPITest |
9
|
|
|
{ |
10
|
|
|
protected static $planId; |
11
|
|
|
|
12
|
|
|
protected static $productId; |
13
|
|
|
|
14
|
|
|
protected $plan = array( |
15
|
|
|
'name' => array( |
16
|
|
|
'en' => 'Subscription Plan Name', |
17
|
|
|
), |
18
|
|
|
'group_id' => 'group_id', |
19
|
|
|
'charge' => array( |
20
|
|
|
'amount' => 1, |
21
|
|
|
'currency' => 'USD', |
22
|
|
|
'period' => array( |
23
|
|
|
'value' => 1, |
24
|
|
|
'type' => 'month', |
25
|
|
|
), |
26
|
|
|
), |
27
|
|
|
'expiration' => array( |
28
|
|
|
'value' => 3, |
29
|
|
|
'type' => 'month', |
30
|
|
|
), |
31
|
|
|
); |
32
|
|
|
|
33
|
|
|
protected $product = array( |
34
|
|
|
'name' => 'Product Name', |
35
|
|
|
'group_id' => 'group_id', |
36
|
|
|
); |
37
|
|
|
|
38
|
|
|
public function testCreateSubscriptionPlan() |
39
|
|
|
{ |
40
|
|
|
$response = static::$xsollaClient->CreateSubscriptionPlan(array( |
41
|
|
|
'project_id' => static::$projectId, |
42
|
|
|
'request' => $this->plan, |
43
|
|
|
)); |
44
|
|
|
static::assertArrayHasKey('plan_id', $response); |
45
|
|
|
static::assertInternalType('integer', $response['plan_id']); |
46
|
|
|
static::$planId = $response['plan_id']; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @depends testCreateSubscriptionPlan |
51
|
|
|
*/ |
52
|
|
View Code Duplication |
public function testListSubscriptionPlans() |
|
|
|
|
53
|
|
|
{ |
54
|
|
|
$response = static::$xsollaClient->ListSubscriptionPlans(array( |
55
|
|
|
'project_id' => static::$projectId, |
56
|
|
|
'limit' => 100, |
57
|
|
|
)); |
58
|
|
|
static::assertInternalType('array', $response); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @depends testListSubscriptionPlans |
63
|
|
|
*/ |
64
|
|
|
public function testUpdateSubscriptionPlan() |
65
|
|
|
{ |
66
|
|
|
$response = static::$xsollaClient->UpdateSubscriptionPlan(array( |
67
|
|
|
'project_id' => static::$projectId, |
68
|
|
|
'plan_id' => static::$planId, |
69
|
|
|
'request' => $this->plan, |
70
|
|
|
)); |
71
|
|
|
static::assertInternalType('array', $response); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @depends testUpdateSubscriptionPlan |
76
|
|
|
*/ |
77
|
|
|
public function testDisableSubscriptionPlan() |
78
|
|
|
{ |
79
|
|
|
static::$xsollaClient->DisableSubscriptionPlan(array( |
80
|
|
|
'project_id' => static::$projectId, |
81
|
|
|
'plan_id' => static::$planId, |
82
|
|
|
)); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @depends testDisableSubscriptionPlan |
87
|
|
|
*/ |
88
|
|
|
public function testEnableSubscriptionPlan() |
89
|
|
|
{ |
90
|
|
|
static::$xsollaClient->EnableSubscriptionPlan(array( |
91
|
|
|
'project_id' => static::$projectId, |
92
|
|
|
'plan_id' => static::$planId, |
93
|
|
|
)); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @depends testEnableSubscriptionPlan |
98
|
|
|
*/ |
99
|
|
|
public function testDeleteSubscriptionPlan() |
100
|
|
|
{ |
101
|
|
|
static::$xsollaClient->DeleteSubscriptionPlan(array( |
102
|
|
|
'project_id' => static::$projectId, |
103
|
|
|
'plan_id' => static::$planId, |
104
|
|
|
)); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @depends testDeleteSubscriptionPlan |
109
|
|
|
*/ |
110
|
|
View Code Duplication |
public function testCreateSubscriptionProduct() |
|
|
|
|
111
|
|
|
{ |
112
|
|
|
$response = static::$xsollaClient->CreateSubscriptionProduct(array( |
113
|
|
|
'project_id' => static::$projectId, |
114
|
|
|
'request' => $this->product, |
115
|
|
|
)); |
116
|
|
|
static::assertArrayHasKey('product_id', $response); |
117
|
|
|
static::$productId = $response['product_id']; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @depends testCreateSubscriptionProduct |
122
|
|
|
*/ |
123
|
|
View Code Duplication |
public function testListSubscriptionPlansWithParams() |
|
|
|
|
124
|
|
|
{ |
125
|
|
|
$response = static::$xsollaClient->ListSubscriptionPlans(array( |
126
|
|
|
'project_id' => static::$projectId, |
127
|
|
|
'limit' => 100, |
128
|
|
|
'offset' => 0, |
129
|
|
|
'product_id' => static::$productId, |
130
|
|
|
'group_id' => $this->product['group_id'], |
131
|
|
|
'external_id' => 12345, |
132
|
|
|
)); |
133
|
|
|
static::assertInternalType('array', $response); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @depends testCreateSubscriptionProduct |
138
|
|
|
*/ |
139
|
|
View Code Duplication |
public function testUpdateSubscriptionProduct() |
|
|
|
|
140
|
|
|
{ |
141
|
|
|
$response = static::$xsollaClient->UpdateSubscriptionProduct(array( |
142
|
|
|
'project_id' => static::$projectId, |
143
|
|
|
'product_id' => static::$productId, |
144
|
|
|
'request' => $this->product, |
145
|
|
|
)); |
146
|
|
|
static::assertInternalType('array', $response); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @depends testUpdateSubscriptionProduct |
151
|
|
|
*/ |
152
|
|
|
public function testDeleteSubscriptionProduct() |
153
|
|
|
{ |
154
|
|
|
static::$xsollaClient->DeleteSubscriptionProduct(array( |
155
|
|
|
'project_id' => static::$projectId, |
156
|
|
|
'product_id' => static::$productId, |
157
|
|
|
)); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
public function testListSubscriptionProducts() |
161
|
|
|
{ |
162
|
|
|
$response = static::$xsollaClient->ListSubscriptionProducts(array( |
163
|
|
|
'project_id' => static::$projectId, |
164
|
|
|
)); |
165
|
|
|
static::assertInternalType('array', $response); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
public function testListSubscriptionProductsWithParams() |
169
|
|
|
{ |
170
|
|
|
$response = static::$xsollaClient->ListSubscriptionProducts(array( |
171
|
|
|
'project_id' => static::$projectId, |
172
|
|
|
'product_id' => static::$productId, |
173
|
|
|
)); |
174
|
|
|
static::assertInternalType('array', $response); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
public function testUpdateSubscription() |
178
|
|
|
{ |
179
|
|
|
static::markTestIncomplete('We haven\'t active subscriptions in test project.'); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
View Code Duplication |
public function testListSubscriptions() |
|
|
|
|
183
|
|
|
{ |
184
|
|
|
$response = static::$xsollaClient->ListSubscriptions(array( |
185
|
|
|
'project_id' => static::$projectId, |
186
|
|
|
'user_id' => static::$userId, |
187
|
|
|
)); |
188
|
|
|
static::assertInternalType('array', $response); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
View Code Duplication |
public function testListSubscriptionWithParams() |
|
|
|
|
192
|
|
|
{ |
193
|
|
|
$response = static::$xsollaClient->ListSubscriptions(array( |
194
|
|
|
'project_id' => static::$projectId, |
195
|
|
|
'user_id' => static::$userId, |
196
|
|
|
'plan_id' => static::$planId, |
197
|
|
|
'product_id' => static::$productId, |
198
|
|
|
)); |
199
|
|
|
static::assertInternalType('array', $response); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
View Code Duplication |
public function testListUserSubscriptionPayments() |
|
|
|
|
203
|
|
|
{ |
204
|
|
|
$response = static::$xsollaClient->ListUserSubscriptionPayments(array( |
205
|
|
|
'project_id' => static::$projectId, |
206
|
|
|
'user_id' => static::$userId, |
207
|
|
|
)); |
208
|
|
|
static::assertInternalType('array', $response); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
public function testListSubscriptionPayments() |
212
|
|
|
{ |
213
|
|
|
$response = static::$xsollaClient->ListSubscriptionPayments(array( |
214
|
|
|
'project_id' => static::$projectId, |
215
|
|
|
)); |
216
|
|
|
static::assertInternalType('array', $response); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
public function testListSubscriptionCurrencies() |
220
|
|
|
{ |
221
|
|
|
$response = static::$xsollaClient->ListSubscriptionCurrencies(array( |
222
|
|
|
'project_id' => static::$projectId, |
223
|
|
|
)); |
224
|
|
|
static::assertInternalType('array', $response); |
225
|
|
|
} |
226
|
|
|
} |
227
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.