|
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\InAppProducts; |
|
19
|
|
|
|
|
20
|
|
|
use alxmsl\Google\InitializationInterface; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Class of in-app product purchase resource |
|
24
|
|
|
* @author alxmsl |
|
25
|
|
|
*/ |
|
26
|
|
|
final class Resource implements InitializationInterface { |
|
27
|
|
|
/** |
|
28
|
|
|
* @var string default language of the localized data BCP 47 |
|
29
|
|
|
*/ |
|
30
|
|
|
private $defaultLanguage = ''; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var null|Price default in-app product price |
|
34
|
|
|
*/ |
|
35
|
|
|
private $defaultPrice = null; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var Listing[] language of the localized data, specified with a BCP 47 language |
|
39
|
|
|
*/ |
|
40
|
|
|
private $listings = []; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var string package name of the parent app |
|
44
|
|
|
*/ |
|
45
|
|
|
private $packageName = ''; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var Price[] prices per buyer region |
|
49
|
|
|
*/ |
|
50
|
|
|
private $prices = []; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @var string purchase type enum value |
|
54
|
|
|
*/ |
|
55
|
|
|
private $purchaseType = ''; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @var Season|null season for a seasonal subscription |
|
59
|
|
|
*/ |
|
60
|
|
|
private $season = null; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @var string stock-keeping-unit of the product |
|
64
|
|
|
*/ |
|
65
|
|
|
private $sku = ''; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @var string in-app product status |
|
69
|
|
|
*/ |
|
70
|
|
|
private $status = ''; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @var string subscription period, specified in ISO 8601 format |
|
74
|
|
|
*/ |
|
75
|
|
|
private $subscriptionPeriod = ''; |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @var string trial period, specified in ISO 8601 format |
|
79
|
|
|
*/ |
|
80
|
|
|
private $trialPeriod = ''; |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @return string default language of the localized data BCP 47 |
|
84
|
|
|
*/ |
|
85
|
2 |
|
public function getDefaultLanguage() { |
|
86
|
2 |
|
return $this->defaultLanguage; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @return null|Price default in-app product price |
|
91
|
|
|
*/ |
|
92
|
2 |
|
public function getDefaultPrice() { |
|
93
|
2 |
|
return $this->defaultPrice; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @return Listing[] language of the localized data, specified with a BCP 47 language |
|
98
|
|
|
*/ |
|
99
|
2 |
|
public function getListings() { |
|
100
|
2 |
|
return $this->listings; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @return string package name of the parent app |
|
105
|
|
|
*/ |
|
106
|
2 |
|
public function getPackageName() { |
|
107
|
2 |
|
return $this->packageName; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @return Price[] prices per buyer region |
|
112
|
|
|
*/ |
|
113
|
2 |
|
public function getPrices() { |
|
114
|
2 |
|
return $this->prices; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @return string purchase type enum value |
|
119
|
|
|
*/ |
|
120
|
2 |
|
public function getPurchaseType() { |
|
121
|
2 |
|
return $this->purchaseType; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @return Season|null season for a seasonal subscription |
|
126
|
|
|
*/ |
|
127
|
2 |
|
public function getSeason() { |
|
128
|
2 |
|
return $this->season; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @return string stock-keeping-unit of the product, |
|
133
|
|
|
*/ |
|
134
|
2 |
|
public function getSku() { |
|
135
|
2 |
|
return $this->sku; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* @return string in-app product status |
|
140
|
|
|
*/ |
|
141
|
2 |
|
public function getStatus() { |
|
142
|
2 |
|
return $this->status; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* @return string subscription period, specified in ISO 8601 format |
|
147
|
|
|
*/ |
|
148
|
2 |
|
public function getSubscriptionPeriod() { |
|
149
|
2 |
|
return $this->subscriptionPeriod; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* @return string trial period, specified in ISO 8601 format |
|
154
|
|
|
*/ |
|
155
|
1 |
|
public function getTrialPeriod() { |
|
156
|
1 |
|
return $this->trialPeriod; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* @inheritdoc |
|
161
|
|
|
*/ |
|
162
|
1 |
|
public static function initializeByString($string) { |
|
163
|
1 |
|
$Object = json_decode($string); |
|
164
|
1 |
|
$Resource = new Resource(); |
|
165
|
|
|
|
|
166
|
1 |
|
$Resource->defaultLanguage = (string) $Object->defaultLanguage; |
|
167
|
1 |
|
$Resource->defaultPrice = Price::initializeByObject($Object->defaultPrice); |
|
168
|
1 |
|
$Resource->packageName = (string) $Object->packageName; |
|
169
|
1 |
|
$Resource->purchaseType = (string) $Object->purchaseType; |
|
170
|
1 |
|
$Resource->sku = (string) $Object->sku; |
|
171
|
1 |
|
$Resource->status = (string) $Object->status; |
|
172
|
1 |
|
$Resource->subscriptionPeriod = (string) @$Object->subscriptionPeriod; |
|
173
|
1 |
|
$Resource->trialPeriod = (string) @$Object->trialPeriod; |
|
174
|
|
|
|
|
175
|
1 |
|
if (isset($Object->season)) { |
|
176
|
1 |
|
$Resource->season = Season::initializeByObject($Object->season); |
|
177
|
1 |
|
} |
|
178
|
1 |
|
foreach ($Object->listings as $key => $Item) { |
|
179
|
1 |
|
$Resource->listings[$key] = Listing::initializeByObject($Item); |
|
180
|
1 |
|
} |
|
181
|
1 |
|
foreach ($Object->prices as $key => $Item) { |
|
182
|
1 |
|
$Resource->prices[$key] = Price::initializeByObject($Item); |
|
183
|
1 |
|
} |
|
184
|
1 |
|
return $Resource; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* @inheritdoc |
|
189
|
|
|
*/ |
|
190
|
1 |
|
public function __toString() { |
|
191
|
|
|
$format = <<<'EOD' |
|
192
|
|
|
language: %s |
|
193
|
|
|
package: %s |
|
194
|
|
|
type: %s |
|
195
|
|
|
sku: %s |
|
196
|
|
|
status: %s |
|
197
|
1 |
|
EOD; |
|
198
|
1 |
|
return sprintf($format |
|
199
|
1 |
|
, $this->getDefaultLanguage() |
|
200
|
1 |
|
, $this->getPackageName() |
|
201
|
1 |
|
, $this->getPurchaseType() |
|
202
|
1 |
|
, $this->getSku() |
|
203
|
1 |
|
, $this->getStatus()); |
|
204
|
|
|
} |
|
205
|
|
|
} |
|
206
|
|
|
|