Passed
Push — main ( f8bc98...8782ff )
by Stas
02:47 queued 21s
created

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