1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Huawei\IAP\Response; |
4
|
|
|
|
5
|
|
|
abstract class ValidationResponse |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* @var int |
9
|
|
|
* Success |
10
|
|
|
*/ |
11
|
|
|
const RESPONSE_CODE_0 = 0; |
12
|
|
|
/** |
13
|
|
|
* @var int |
14
|
|
|
* The parameter passed to the API is invalid. |
15
|
|
|
* This error may also indicate that an agreement is not signed |
16
|
|
|
* or parameters are not set correctly for the in-app purchase |
17
|
|
|
* settlement in HUAWEI IAP, or the required permission is not in the list. |
18
|
|
|
* |
19
|
|
|
* Solution: Check whether the parameter passed to the API is correctly set. |
20
|
|
|
* If so, check whether required settings in HUAWEI IAP are correctly configured. |
21
|
|
|
*/ |
22
|
|
|
const RESPONSE_CODE_5 = 5; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var int |
26
|
|
|
* A critical error occurs during API operations. |
27
|
|
|
* |
28
|
|
|
* Solution: Rectify the fault based on the error information in the response. |
29
|
|
|
* If the fault persists, contact Huawei technical support. |
30
|
|
|
*/ |
31
|
|
|
const RESPONSE_CODE_6 = 6; |
32
|
|
|
/** |
33
|
|
|
* @var int |
34
|
|
|
* A user failed to consume or confirm a product because the user does not own the product. |
35
|
|
|
*/ |
36
|
|
|
const RESPONSE_CODE_8 = 8; |
37
|
|
|
/** |
38
|
|
|
* @var int |
39
|
|
|
* The product cannot be consumed or confirmed because it has been consumed or confirmed. |
40
|
|
|
*/ |
41
|
|
|
const RESPONSE_CODE_9 = 9; |
42
|
|
|
/** |
43
|
|
|
* @var int |
44
|
|
|
* The user account is abnormal, for example, the user has been deregistered. |
45
|
|
|
*/ |
46
|
|
|
const RESPONSE_CODE_11 = 11; |
47
|
|
|
/** |
48
|
|
|
* @var int |
49
|
|
|
* The order does not exist. Only the latest order of the specified product can be queried. |
50
|
|
|
* The order in this query may not the latest one. |
51
|
|
|
* |
52
|
|
|
* Solution: Token verification is not required for historical orders. |
53
|
|
|
* Make sure that your integration is performed based on the guide. |
54
|
|
|
* If the problem persists, contact Huawei technical support. |
55
|
|
|
*/ |
56
|
|
|
const RESPONSE_CODE_12 = 12; |
57
|
|
|
|
58
|
|
|
protected $dataModel = []; |
59
|
|
|
protected $responseCode; |
60
|
|
|
protected $responseMessage; |
61
|
|
|
|
62
|
1 |
|
public function __construct(array $raw) |
63
|
|
|
{ |
64
|
1 |
|
$this->parseDataModel($raw); |
65
|
1 |
|
$this->parseResonseDetails($raw); |
66
|
1 |
|
} |
67
|
|
|
|
68
|
|
|
abstract protected function parseDataModel(array $raw); |
69
|
|
|
|
70
|
1 |
|
protected function parseResonseDetails(array $raw) |
71
|
|
|
{ |
72
|
1 |
|
$responseCode = $raw['responseCode'] ?? null; |
73
|
|
|
|
74
|
1 |
|
if ($responseCode !== null) { |
75
|
1 |
|
$this->responseCode = (int)$responseCode; |
76
|
|
|
} |
77
|
|
|
|
78
|
1 |
|
$responseMessage = $raw['responseMessage'] ?? null; |
79
|
|
|
|
80
|
1 |
|
if ($responseMessage !== null) { |
81
|
|
|
$this->responseMessage = (string)$responseMessage; |
82
|
|
|
} |
83
|
1 |
|
} |
84
|
|
|
|
85
|
|
|
public function getResponseMessage(): ?string |
86
|
|
|
{ |
87
|
|
|
return $this->responseMessage; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function getResponseCode(): ?int |
91
|
|
|
{ |
92
|
|
|
return $this->responseCode; |
93
|
|
|
} |
94
|
|
|
|
95
|
1 |
|
public function isResponseValid(): bool |
96
|
|
|
{ |
97
|
1 |
|
return $this->responseCode === self::RESPONSE_CODE_0; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Returns TRUE if such property exists in dataModel, |
102
|
|
|
* Otherwise - FALSE |
103
|
|
|
* |
104
|
|
|
* @param string $property |
105
|
|
|
* |
106
|
|
|
* @return bool |
107
|
|
|
*/ |
108
|
1 |
|
public function isDatumExists(string $property): bool |
109
|
|
|
{ |
110
|
1 |
|
return array_key_exists($property, $this->dataModel); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Get dataModel property if exists |
115
|
|
|
* |
116
|
|
|
* @param string $property |
117
|
|
|
* |
118
|
|
|
* @return mixed|null |
119
|
|
|
*/ |
120
|
|
|
public function getDatum(string $property) |
121
|
|
|
{ |
122
|
|
|
return $this->dataModel[$property] ?? null; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @return array |
127
|
|
|
*/ |
128
|
|
|
public function getDataModel() |
129
|
|
|
{ |
130
|
|
|
return $this->dataModel; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* For consumables or non-consumables, the value is always false. |
135
|
|
|
* |
136
|
|
|
* For subscriptions, the options are as follows: |
137
|
|
|
* - true: A subscription is in active state and will be automatically renewed |
138
|
|
|
* on the next renewal date. |
139
|
|
|
* - false: A user has canceled the subscription. The user can access the subscribed |
140
|
|
|
* content before the next renewal date but will be unable to access |
141
|
|
|
* the content after the date unless the user enables automatic renewal. |
142
|
|
|
* If a grace period is provided, this value remains TRUE for the subscription |
143
|
|
|
* as long as it is still in the grace period. The next settlement date |
144
|
|
|
* is automatically extended every day until the grace period ends |
145
|
|
|
* or the user changes the payment method. |
146
|
|
|
* |
147
|
|
|
* @return bool |
148
|
|
|
*/ |
149
|
1 |
|
public function isAutoRenewing(): bool |
150
|
|
|
{ |
151
|
1 |
|
return $this->dataModel['autoRenewing']; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* App ID |
156
|
|
|
* |
157
|
|
|
* @return string |
158
|
|
|
*/ |
159
|
1 |
|
public function getApplicationId(): string |
160
|
|
|
{ |
161
|
1 |
|
return $this->dataModel['applicationId']; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Product type. The options are as follows: |
166
|
|
|
* 0: consumable |
167
|
|
|
* 1: non-consumable |
168
|
|
|
* 2: subscription |
169
|
|
|
* |
170
|
|
|
* @return int |
171
|
|
|
*/ |
172
|
1 |
|
public function getKind(): int |
173
|
|
|
{ |
174
|
1 |
|
return $this->dataModel['kind']; |
175
|
|
|
} |
176
|
|
|
/** |
177
|
|
|
* App package name. |
178
|
|
|
* |
179
|
|
|
* @return string|null |
180
|
|
|
*/ |
181
|
1 |
|
public function getPackageName(): ?string |
182
|
|
|
{ |
183
|
1 |
|
return $this->dataModel['packageName'] ?? null; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Product ID. Each product must have a unique ID, |
188
|
|
|
* which is maintained in the PMS or passed when the app initiates a purchase. |
189
|
|
|
* |
190
|
|
|
* @return string |
191
|
|
|
*/ |
192
|
1 |
|
public function getProductId(): string |
193
|
|
|
{ |
194
|
1 |
|
return $this->dataModel['productId']; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* Order ID, which uniquely identifies a transaction and is generated |
199
|
|
|
* by the Huawei IAP server during payment. |
200
|
|
|
* |
201
|
|
|
* A different order ID is generated for each fee deduction. |
202
|
|
|
* |
203
|
|
|
* @return string |
204
|
|
|
*/ |
205
|
|
|
public function getOrderId(): string |
206
|
|
|
{ |
207
|
|
|
return $this->dataModel['orderId']; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* ID of the subscription group to which a subscription belongs. |
212
|
|
|
* |
213
|
|
|
* @note Returned only in the subscription scenario. |
214
|
|
|
* @return string|null |
215
|
|
|
*/ |
216
|
1 |
|
public function getProductGroup(): ?string |
217
|
|
|
{ |
218
|
1 |
|
return $this->dataModel['productGroup'] ?? null; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* Timestamp of the purchase time, which is the number of milliseconds |
223
|
|
|
* from 00:00:00 on January 1, 1970 to the purchase time. |
224
|
|
|
* |
225
|
|
|
* If the purchase is not complete, this parameter is left empty. |
226
|
|
|
* |
227
|
|
|
* @note Returned only in the subscription scenario. |
228
|
|
|
* @return int|null |
229
|
|
|
*/ |
230
|
1 |
|
public function getPurchaseTime(): ?int |
231
|
|
|
{ |
232
|
1 |
|
return $this->dataModel['purchaseTime'] ?? null; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* Transaction status. The options are as follows: |
237
|
|
|
* -1: initialized |
238
|
|
|
* 0: purchased |
239
|
|
|
* 1: canceled |
240
|
|
|
* 2: refunded |
241
|
|
|
* |
242
|
|
|
* @return int |
243
|
|
|
*/ |
244
|
1 |
|
public function getPurchaseState(): int |
245
|
|
|
{ |
246
|
1 |
|
return $this->dataModel['purchaseState']; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* Information stored on the merchant side, which is passed by the app |
251
|
|
|
* when the payment API is called. |
252
|
|
|
* |
253
|
|
|
* @return null|string |
254
|
|
|
*/ |
255
|
|
|
public function getDeveloperPayload(): ?string |
256
|
|
|
{ |
257
|
|
|
return $this->dataModel['developerPayload'] ?? null; |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* Challenge defined when an app initiates a consumption request. |
262
|
|
|
* The challenge uniquely identifies the consumption request |
263
|
|
|
* and exists only for one-off products. |
264
|
|
|
* |
265
|
|
|
* @return string|null |
266
|
|
|
*/ |
267
|
|
|
public function getDeveloperChallenge(): ?string |
268
|
|
|
{ |
269
|
|
|
return $this->dataModel['developerChallenge'] ?? null; |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* Purchase token, which uniquely identifies the mapping between a product and a user. |
274
|
|
|
* It is generated by the Huawei IAP server when the payment is complete. |
275
|
|
|
* |
276
|
|
|
* This parameter uniquely identifies the mapping between a product and a user. |
277
|
|
|
* It does not change when the subscription is renewed. |
278
|
|
|
* |
279
|
|
|
* If the value needs to be stored, you are advised to reserve 128 characters. |
280
|
|
|
* |
281
|
|
|
* @return string |
282
|
|
|
*/ |
283
|
1 |
|
public function getPurchaseToken(): string |
284
|
|
|
{ |
285
|
1 |
|
return $this->dataModel['purchaseToken']; |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* Purchase type. The options are as follows: |
290
|
|
|
* 0: in the sandbox |
291
|
|
|
* 1: in the promotion period (currently unsupported) |
292
|
|
|
* |
293
|
|
|
* This parameter is not returned during formal purchase. |
294
|
|
|
* |
295
|
|
|
* @return int |
296
|
|
|
*/ |
297
|
1 |
|
public function getPurchaseType(): ?int |
298
|
|
|
{ |
299
|
1 |
|
return $this->dataModel['purchaseType'] ?? null; |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
/** |
303
|
|
|
* Currency. The value must comply with the ISO 4217 standard. |
304
|
|
|
* |
305
|
|
|
* @return string|null |
306
|
|
|
*/ |
307
|
1 |
|
public function getCurrency(): ?string |
308
|
|
|
{ |
309
|
1 |
|
return $this->dataModel['currency'] ?? null; |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
/** |
313
|
|
|
* Value after the actual price of a product is multiplied by 100. |
314
|
|
|
* The actual price is accurate to two decimal places. |
315
|
|
|
* |
316
|
|
|
* For example, if the value of this parameter is 501, the actual product price is 5.01. |
317
|
|
|
* |
318
|
|
|
* @return int|null |
319
|
|
|
*/ |
320
|
1 |
|
public function getPrice(): ?int |
321
|
|
|
{ |
322
|
1 |
|
return $this->dataModel['price'] ?? null; |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
/** |
326
|
|
|
* Country or region code, which is used to identify a country or region. |
327
|
|
|
* The value must comply with the ISO 3166 standard. |
328
|
|
|
* |
329
|
|
|
* @return string|null |
330
|
|
|
*/ |
331
|
1 |
|
public function getCountry(): ?string |
332
|
|
|
{ |
333
|
1 |
|
return $this->dataModel['country'] ?? null; |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
/** |
337
|
|
|
* Transaction order ID. |
338
|
|
|
* |
339
|
|
|
* @return string|null |
340
|
|
|
*/ |
341
|
1 |
|
public function getPayOrderId(): ?string |
342
|
|
|
{ |
343
|
1 |
|
return $this->dataModel['payOrderId'] ?? null; |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
/** |
347
|
|
|
* Payment method. For details about the value, please refer to |
348
|
|
|
* @see https://developer.huawei.com/consumer/en/doc/HMSCore-References-V5/server-data-model-0000001050986133-V5#EN-US_TOPIC_0000001050986133__section135412662210 |
349
|
|
|
* |
350
|
|
|
* @return string|null |
351
|
|
|
*/ |
352
|
|
|
public function getPayType(): ?string |
353
|
|
|
{ |
354
|
|
|
return $this->dataModel['payType'] ?? null; |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
/** |
358
|
|
|
* Confirmation status. The options are as follows: |
359
|
|
|
* 0: not confirmed |
360
|
|
|
* 1: confirmed |
361
|
|
|
* |
362
|
|
|
* If this parameter is left empty, no confirmation is required. |
363
|
|
|
* |
364
|
|
|
* @return int|null |
365
|
|
|
* @deprecated This parameter is used only for compatibility with earlier versions. |
366
|
|
|
* If your app has the latest version integrated, just ignore this parameter. |
367
|
|
|
* |
368
|
|
|
*/ |
369
|
|
|
public function getConfirmed(): ?int |
370
|
|
|
{ |
371
|
|
|
return $this->dataModel['confirmed'] ?? null; |
372
|
|
|
} |
373
|
|
|
|
374
|
|
|
/** |
375
|
|
|
* Account type. The options are as follows: |
376
|
|
|
* 0: HUAWEI ID |
377
|
|
|
* 1: AppTouch user account |
378
|
|
|
* |
379
|
|
|
* @return int|null |
380
|
|
|
*/ |
381
|
|
|
public function getAccountFlag(): ?int |
382
|
|
|
{ |
383
|
|
|
return $this->dataModel['accountFlag'] ?? null; |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
/** |
387
|
|
|
* Purchase quantity. |
388
|
|
|
* |
389
|
|
|
* @return int|null |
390
|
|
|
*/ |
391
|
1 |
|
public function getQuantity(): ?int |
392
|
|
|
{ |
393
|
1 |
|
return $this->dataModel['quantity'] ?? null; |
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
/** |
397
|
|
|
* Product name |
398
|
|
|
* |
399
|
|
|
* @return string|null |
400
|
|
|
*/ |
401
|
1 |
|
public function getProductName(): ?string |
402
|
|
|
{ |
403
|
1 |
|
return $this->dataModel['productName'] ?? null; |
404
|
|
|
} |
405
|
|
|
} |
406
|
|
|
|