|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* Copyright 2015 Alexey Maslov <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
6
|
|
|
* you may not use this file except in compliance with the License. |
|
7
|
|
|
* You may obtain a copy of the License at |
|
8
|
|
|
* |
|
9
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
10
|
|
|
* |
|
11
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
12
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
13
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14
|
|
|
* See the License for the specific language governing permissions and |
|
15
|
|
|
* limitations under the License. |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace alxmsl\Google\AndroidPublisher\Purchases\Subscriptions; |
|
19
|
|
|
|
|
20
|
|
|
use alxmsl\Google\InitializationInterface; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Class of in-app product subscription resource |
|
24
|
|
|
* @author alxmsl |
|
25
|
|
|
*/ |
|
26
|
|
|
final class Resource implements InitializationInterface { |
|
27
|
|
|
/** |
|
28
|
|
|
* @var bool whether the subscription will automatically be renewed when it reaches its current expiry time |
|
29
|
|
|
*/ |
|
30
|
|
|
private $autoRenewing = false; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var int time at which the subscription will expire, milliseconds |
|
34
|
|
|
*/ |
|
35
|
|
|
private $expiryTimeMillis = 0; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var string represents an in-app purchase object in the android publisher service |
|
39
|
|
|
*/ |
|
40
|
|
|
private $kind = ''; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var int time at which the subscription was granted, milliseconds |
|
44
|
|
|
*/ |
|
45
|
|
|
private $startTimeMillis = 0; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @return int time at which the subscription will expire, milliseconds |
|
49
|
|
|
*/ |
|
50
|
2 |
|
public function getExpiryTimeMillis() { |
|
51
|
2 |
|
return $this->expiryTimeMillis; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @return float time at which the subscription will expire, seconds |
|
|
|
|
|
|
56
|
|
|
*/ |
|
57
|
2 |
|
public function getExpiryTime() { |
|
58
|
2 |
|
return $this->getExpiryTimeMillis() / 1000; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @return bool check if subscription is expired now |
|
63
|
|
|
*/ |
|
64
|
2 |
|
public function isExpired() { |
|
65
|
2 |
|
return $this->getExpiryTime() < time(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @return bool whether the subscription will automatically be renewed when it reaches its current expiry time |
|
70
|
|
|
*/ |
|
71
|
2 |
|
public function isAutoRenewing() { |
|
72
|
2 |
|
return $this->autoRenewing; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @return string represents an in-app purchase object in the android publisher service |
|
77
|
|
|
*/ |
|
78
|
2 |
|
public function getKind() { |
|
79
|
2 |
|
return $this->kind; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @return int time at which the subscription was granted, milliseconds |
|
84
|
|
|
*/ |
|
85
|
2 |
|
public function getStartTimeMillis() { |
|
86
|
2 |
|
return $this->startTimeMillis; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @inheritdoc |
|
91
|
|
|
*/ |
|
92
|
1 |
|
public static function initializeByString($string) { |
|
93
|
1 |
|
$Object = json_decode($string); |
|
94
|
1 |
|
$Resource = new Resource(); |
|
95
|
|
|
|
|
96
|
1 |
|
$Resource->autoRenewing = (bool) $Object->autoRenewing; |
|
97
|
1 |
|
$Resource->expiryTimeMillis = (int) $Object->expiryTimeMillis; |
|
98
|
1 |
|
$Resource->kind = (string) $Object->kind; |
|
99
|
1 |
|
$Resource->startTimeMillis = (int) $Object->startTimeMillis; |
|
100
|
1 |
|
return $Resource; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @inheritdoc |
|
105
|
|
|
*/ |
|
106
|
1 |
|
public function __toString() { |
|
107
|
|
|
$format = <<<'EOD' |
|
108
|
|
|
started at: %s |
|
109
|
|
|
expired at: %s |
|
110
|
|
|
kind: %s |
|
111
|
|
|
auto-renewing: %s |
|
112
|
1 |
|
EOD; |
|
113
|
1 |
|
return sprintf($format |
|
114
|
1 |
|
, date('Y-m-d H:i:s', $this->getStartTimeMillis() / 1000) |
|
115
|
1 |
|
, date('Y-m-d H:i:s', $this->getExpiryTimeMillis() / 1000) |
|
116
|
1 |
|
, $this->getKind() |
|
117
|
1 |
|
, $this->isAutoRenewing() ? 'enabled' : 'disabled'); |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.