Passed
Push — main ( 4ef34d...47657f )
by Stas
04:43
created

SubscriptionResponse::getQuantity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Huawei\IAP\Response;
4
5
class SubscriptionResponse extends ValidationResponse
6
{
7
    /**
8
     * @param array $raw
9
     */
10 1
    protected function parseDataModel(array $raw)
11
    {
12 1
        if (isset($raw['inappPurchaseData'])) {
13 1
            $this->dataModel = \json_decode($raw['inappPurchaseData'], true);
14
        }
15 1
    }
16
17
    /**
18
     * Subscription status
19
     *
20
     * true:  A user has been charged for a product,
21
     *        the product has not expired, no refund has been made,
22
     *        and the product is in a grace period. In this case,
23
     *        you can provide services for the user.
24
     * false: The purchase of a product is not finished,
25
     *        the product has expired, or a refund has been made
26
     *        for the product after its purchase.
27
     *
28
     * @note If a user has canceled a subscription, the subIsvalid parameter value
29
     *       is still true until the subscription expires.
30
     *
31
     * @return bool|null
32
     */
33 1
    public function isSubValid(): ?bool
34
    {
35 1
        return $this->dataModel['subIsvalid'] ?? null;
36
    }
37
38
    /**
39
     * Order ID generated by the Huawei IAP server during fee deduction
40
     * for the previous renewal. The parameter value is the same
41
     * as that of orderId when a subscription is purchased for the first time.
42
     *
43
     * @note Returned only in the subscription scenario.
44
     *
45
     * @return string
46
     */
47
    public function getLastOrderId(): string
48
    {
49
        return $this->dataModel['lastOrderId'];
50
    }
51
52
    /**
53
     * Product name
54
     *
55
     * @return string|null
56
     */
57 1
    public function getProductName(): ?string
58
    {
59 1
        return $this->dataModel['productName'] ?? null;
60
    }
61
62
    /**
63
     * Timestamp of the first fee deduction time (in UTC),
64
     * which is the number of milliseconds from 00:00:00 on January 1, 1970
65
     * to the first successful fee deduction time.
66
     *
67
     * @note Returned only in the subscription scenario.
68
     * @return int|null
69
     */
70 1
    public function getOriPurchaseTime(): ?int
71
    {
72 1
        return $this->dataModel['oriPurchaseTime'] ?? null;
73
    }
74
75
    /**
76
     * Subscription ID.
77
     *
78
     * @note This parameter uniquely identifies the mapping
79
     *       between a product and a user. It does not change
80
     *       when the subscription is renewed.
81
     *
82
     * @return string|null
83
     */
84 1
    public function getSubscriptionId(): ?string
85
    {
86 1
        return $this->dataModel['subscriptionId'] ?? null;
87
    }
88
89
    /**
90
     * Original subscription ID.
91
     *
92
     * If a value exists, the current subscription is switched from another one.
93
     * The value can be associated with the information about the original subscription.
94
     *
95
     * @return string|null
96
     */
97 1
    public function getSubscriptionOriId(): ?string
98
    {
99 1
        return $this->dataModel['subscriptionOriId'] ?? null;
100
    }
101
102
    /**
103
     * Days of a paid subscription, excluding the free trial period and promotion period.
104
     *
105
     * @return int|null
106
     */
107
    public function getDaysLasted(): ?int
108
    {
109
        return $this->dataModel['daysLasted'] ?? null;
110
    }
111
112
    /**
113
     * Number of successful standard renewal periods
114
     * (that is, renewal periods without promotion).
115
     *
116
     * If the value is 0 or does not exist, no renewal has been performed successfully.
117
     *
118
     * @return int|null
119
     */
120 1
    public function getNumOfPeriods(): ?int
121
    {
122 1
        return $this->dataModel['numOfPeriods'] ?? null;
123
    }
124
125
    /**
126
     * Number of successful renewal periods with promotion.
127
     *
128
     * @return int|null
129
     */
130 1
    public function getNumOfDiscount(): ?int
131
    {
132 1
        return $this->dataModel['numOfDiscount'] ?? null;
133
    }
134
135
    /**
136
     * Timestamp when a subscription expires (in UTC), in milliseconds.
137
     *
138
     * For an automatic renewal receipt where the fee has been deducted successfully,
139
     * this time indicates the renewal date or expiration date.
140
     * If the value is a past time for the latest receipt of a subscription,
141
     * the subscription has expired.
142
     *
143
     * @return int|null
144
     */
145 1
    public function getExpirationDate(): ?int
146
    {
147 1
        return $this->dataModel['expirationDate'] ?? null;
148
    }
149
150
    /**
151
     * Reason why a subscription expires. The options are as follows:
152
     * 1: canceled by a user
153
     * 2: product being unavailable
154
     * 3: abnormal user signing information
155
     * 4: billing error
156
     * 5: price increase disagreed with by a user
157
     * 6: unknown error
158
     *
159
     * If there are multiple exceptions, a smaller number indicates
160
     * a higher priority (1 > 2 > 3...).
161
     *
162
     * @return int|null
163
     */
164
    public function getExpirationIntent(): ?int
165
    {
166
        return $this->dataModel['expirationIntent'] ?? null;
167
    }
168
169
    /**
170
     * Indicates whether the system still tries to renew an expired subscription.
171
     *
172
     * The options are as follows:
173
     * 0: no
174
     * 1: yes
175
     *
176
     * @return int|null
177
     */
178 1
    public function getRetryFlag(): ?int
179
    {
180 1
        return $this->dataModel['retryFlag'] ?? null;
181
    }
182
183
    /**
184
     * Indicates whether a subscription is in the renewal period with promotion.
185
     *
186
     * The options are as follows:
187
     * 1: yes
188
     * 0: no
189
     *
190
     * @return int|null
191
     */
192 1
    public function getIntroductoryFlag(): ?int
193
    {
194 1
        return $this->dataModel['introductoryFlag'] ?? null;
195
    }
196
197
    /**
198
     * Indicates whether a subscription is in the free trial period.
199
     *
200
     * The options are as follows:
201
     * 1: yes
202
     * 0: no
203
     *
204
     * @return int|null
205
     */
206 1
    public function getTrialFlag(): ?int
207
    {
208 1
        return $this->dataModel['trialFlag'] ?? null;
209
    }
210
211
    /**
212
     * Timestamp when a subscription is canceled (in UTC), in milliseconds.
213
     * When a refund occurs, the service is unavailable immediately.
214
     *
215
     * A value is returned when a user:
216
     * (1) makes a complaint and revokes a subscription
217
     *     through the customer service personnel;
218
     * (2) performs subscription upgrade or crossgrade
219
     *     that immediately takes effect and revokes
220
     *     the previous receipt of the original subscription.
221
     *
222
     * @note If a receipt is revoked, it is deemed that the purchase is not complete.
223
     * @return int|null
224
     */
225
    public function getCancelTime(): ?int
226
    {
227
        return $this->dataModel['cancelTime'] ?? null;
228
    }
229
230
    /**
231
     * Cause of subscription cancellation.
232
     *
233
     * The options are as follows:
234
     * 2: A user performs subscription upgrade or crossgrade.
235
     * 1: A user encounters a problem within the app and cancels the subscription.
236
     * 0: other causes. For example, a user mistakenly purchases a subscription
237
     *    and has to cancel it.
238
     *
239
     * @note If this parameter is left empty but the cancelTime parameter has a value, the cancellation is caused by an operation such as upgrade.
240
     *
241
     * @return int|null
242
     */
243
    public function getCancelReason(): ?int
244
    {
245
        return $this->dataModel['cancelReason'] ?? null;
246
    }
247
248
    /**
249
     * App information. This parameter is reserved.
250
     *
251
     * @return string|null
252
     */
253
    public function getAppInfo(): ?string
254
    {
255
        return $this->dataModel['appInfo'] ?? null;
256
    }
257
258
    /**
259
     * Indicates whether a user has disabled the subscription notification function.
260
     *
261
     * The options are as follows:
262
     * 1: yes
263
     * 0: no
264
     *
265
     * If the user disables the subscription notification function,
266
     * no subscription notification will be sent to this user.
267
     *
268
     * @note A value is returned only when subscription relationships are queried.
269
     *
270
     * @return int|null
271
     */
272
    public function getNotifyClosed(): ?int
273
    {
274
        return $this->dataModel['notifyClosed'] ?? null;
275
    }
276
277
    /**
278
     * Renewal status.
279
     *
280
     * The options are as follows:
281
     * 1: The subscription renewal is normal.
282
     * 0: The user has canceled subscription renewal.
283
     *
284
     * For auto-renewable subscriptions, this parameter is valid
285
     * for both valid and expired subscriptions.
286
     *
287
     * However, it does not represent users' subscription status.
288
     * Generally, when the value is 0, the app can provide
289
     * other subscription options for the user, for example,
290
     * recommending another subscription with a lower level in the same group.
291
     * The value 0 indicates that a user proactively cancels the subscription.
292
     *
293
     * @return int|null
294
     */
295 1
    public function getRenewStatus(): ?int
296
    {
297 1
        return $this->dataModel['renewStatus'] ?? null;
298
    }
299
300
    /**
301
     * Price used upon the next renewal.
302
     *
303
     * It is provided as a reference for users
304
     * when the priceConsentStatus parameter is returned.
305
     *
306
     * @return int|null
307
     */
308
    public function getRenewPrice()
309
    {
310
        return $this->dataModel['renewPrice'] ?? null;
311
    }
312
313
    /**
314
     * User opinion on the price increase of a product.
315
     *
316
     * The options are as follows:
317
     * 1: The user has agreed with the price increase.
318
     * 0: The user does not take any action. After the subscription expires, it becomes invalid.
319
     *
320
     * @return int|null
321
     */
322
    public function getPriceConsentStatus(): ?int
323
    {
324
        return $this->dataModel['priceConsentStatus'] ?? null;
325
    }
326
327
    /**
328
     * Indicates whether to postpone the settlement date.
329
     * 1: yes
330
     *
331
     * @return int|null
332
     */
333
    public function getDeferFlag(): ?int
334
    {
335
        return $this->dataModel['deferFlag'] ?? null;
336
    }
337
338
    /**
339
     * Number of days for retaining a subscription relationship
340
     * after the subscription is canceled.
341
     *
342
     * @return int|null
343
     */
344
    public function getCancelledSubKeepDays(): ?int
345
    {
346
        return $this->dataModel['cancelledSubKeepDays'] ?? null;
347
    }
348
349
    /**
350
     * Subscription cancellation initiator.
351
     *
352
     * The options are as follows:
353
     * 0: user
354
     * 1: developer
355
     * 2: Huawei
356
     *
357
     * @return int|null
358
     */
359
    public function getCancelWay(): ?int
360
    {
361
        return $this->dataModel['cancelWay'] ?? null;
362
    }
363
364
    /**
365
     * Timestamp when a user cancels a subscription (in UTC), in milliseconds.
366
     * In the time, you set a subscription renewal to be stopped in the future.
367
     * The subscription is still valid within the validity period,
368
     * but the renewal will be stopped in the future. No refund is required.
369
     *
370
     * @note cancelWay and cancellationTime are displayed
371
     *       when a subscription renewal stops (no refund is involved).
372
     *
373
     * @return int|null
374
     */
375
    public function getCancellationTime(): ?int
376
    {
377
        return $this->dataModel['cancellationTime'] ?? null;
378
    }
379
380
    /**
381
     * Timestamp when a suspended subscription is resumed (in UTC), in milliseconds.
382
     *
383
     * @return int|null
384
     */
385
    public function getResumeTime(): ?int
386
    {
387
        return $this->dataModel['resumeTime'] ?? null;
388
    }
389
390
    /**
391
     * Cancellation reason.
392
     *
393
     * The options are as follows:
394
     * 0: others
395
     * 1: too high fee
396
     * 2: technical problem, for example, product not provided
397
     * 5: in the blocklist because of fraud
398
     * 7: subscription switchover
399
     * 9: service being rarely used and not required
400
     * 10: other better apps
401
     *
402
     * @return int|null
403
     */
404
    public function getSurveyReason(): ?int
405
    {
406
        return $this->dataModel['surveyReason'] ?? null;
407
    }
408
409
    /**
410
     * When the value of surveyReason is 0, this parameter is used
411
     * to collect the cancellation reason entered by users.
412
     *
413
     * @return string|null
414
     */
415
    public function getSurveyDetails(): ?string
416
    {
417
        return $this->dataModel['surveyDetails'] ?? null;
418
    }
419
420
    /**
421
     * Timestamp when a grace period ends, that is, the number of milliseconds
422
     * from 00:00:00 on January 1, 1970 to the time.
423
     *
424
     * @return int|null
425
     */
426
    public function getGraceExpirationTime(): ?int
427
    {
428
        return $this->dataModel['graceExpirationTime'] ?? null;
429
    }
430
}
431