Passed
Push — main ( 4dc4a3...97513a )
by Stas
14:40 queued 04:40
created

SubscriptionResponse::getExpirationDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

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