|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This software may be modified and distributed under the terms |
|
7
|
|
|
* of the MIT license. See the LICENSE file for details. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Shapin\Stripe\Model\Subscription; |
|
11
|
|
|
|
|
12
|
|
|
use Shapin\Stripe\Model\ContainsMetadata; |
|
13
|
|
|
use Shapin\Stripe\Model\CreatableFromArray; |
|
14
|
|
|
use Shapin\Stripe\Model\LivemodeTrait; |
|
15
|
|
|
use Shapin\Stripe\Model\MetadataTrait; |
|
16
|
|
|
use Shapin\Stripe\Model\MetadataCollection; |
|
17
|
|
|
use Shapin\Stripe\Model\Plan\Plan; |
|
18
|
|
|
|
|
19
|
|
|
final class Subscription implements CreatableFromArray, ContainsMetadata |
|
20
|
|
|
{ |
|
21
|
|
|
use LivemodeTrait, MetadataTrait; |
|
22
|
|
|
|
|
23
|
|
|
const BILLING_CHARGE_AUTOMATICALLY = 'charge_automatically'; |
|
24
|
|
|
const BILLING_SEND_INVOICE = 'send_invoice'; |
|
25
|
|
|
|
|
26
|
|
|
const STATUS_TRIALING = 'trialing'; |
|
27
|
|
|
const STATUS_ACTIVE = 'active'; |
|
28
|
|
|
const STATUS_PAST_DUE = 'past_due'; |
|
29
|
|
|
const STATUS_CANCELED = 'canceled'; |
|
30
|
|
|
const STATUS_UNPAID = 'unpaid'; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
private $id; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var ?float |
|
39
|
|
|
*/ |
|
40
|
|
|
private $applicationFeePercent; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var string |
|
44
|
|
|
*/ |
|
45
|
|
|
private $billing; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var mixed |
|
49
|
|
|
*/ |
|
50
|
|
|
private $billingCycleAnchor; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @var bool |
|
54
|
|
|
*/ |
|
55
|
|
|
private $cancelAtPeriodEnd; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @var ?\DateTimeImmutable |
|
59
|
|
|
*/ |
|
60
|
|
|
private $canceledAt; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @var \DateTimeImmutable |
|
64
|
|
|
*/ |
|
65
|
|
|
private $createdAt; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @var \DateTimeImmutable |
|
69
|
|
|
*/ |
|
70
|
|
|
private $currentPeriodEndAt; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @var \DateTimeImmutable |
|
74
|
|
|
*/ |
|
75
|
|
|
private $currentPeriodStartAt; |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @var string |
|
79
|
|
|
*/ |
|
80
|
|
|
private $customer; |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @var ?int |
|
84
|
|
|
*/ |
|
85
|
|
|
private $daysUntilDue; |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @var ?string |
|
89
|
|
|
*/ |
|
90
|
|
|
private $defaultSource; |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @var ?\DateTimeImmutable |
|
94
|
|
|
*/ |
|
95
|
|
|
private $endedAt; |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @var ItemCollection |
|
99
|
|
|
*/ |
|
100
|
|
|
private $items; |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @var Plan |
|
104
|
|
|
*/ |
|
105
|
|
|
private $plan; |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @var int |
|
109
|
|
|
*/ |
|
110
|
|
|
private $quantity; |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @var \DateTimeImmutable |
|
114
|
|
|
*/ |
|
115
|
|
|
private $startAt; |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @var string |
|
119
|
|
|
*/ |
|
120
|
|
|
private $status; |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @var ?float |
|
124
|
|
|
*/ |
|
125
|
|
|
private $taxPercent; |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @var ?\DateTimeImmutable |
|
129
|
|
|
*/ |
|
130
|
|
|
private $trialEndAt; |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* @var ?\DateTimeImmutable |
|
134
|
|
|
*/ |
|
135
|
|
|
private $trialStartAt; |
|
136
|
|
|
|
|
137
|
8 |
|
public static function createFromArray(array $data): self |
|
138
|
|
|
{ |
|
139
|
8 |
|
$model = new self(); |
|
140
|
8 |
|
$model->id = $data['id']; |
|
141
|
8 |
|
$model->applicationFeePercent = null !== $data['application_fee_percent'] ? (float) $data['application_fee_percent'] : null; |
|
142
|
8 |
|
$model->billing = $data['billing']; |
|
143
|
8 |
|
$model->billingCycleAnchor = $data['billing_cycle_anchor']; |
|
144
|
8 |
|
$model->cancelAtPeriodEnd = (bool) $data['cancel_at_period_end']; |
|
145
|
8 |
|
$model->canceledAt = null !== $data['canceled_at'] ? new \DateTimeImmutable('@'.$data['canceled_at']) : null; |
|
146
|
8 |
|
$model->createdAt = new \DateTimeImmutable('@'.$data['created']); |
|
147
|
8 |
|
$model->currentPeriodEndAt = new \DateTimeImmutable('@'.$data['current_period_end']); |
|
148
|
8 |
|
$model->currentPeriodStartAt = new \DateTimeImmutable('@'.$data['current_period_start']); |
|
149
|
8 |
|
$model->customer = $data['customer']; |
|
150
|
8 |
|
$model->daysUntilDue = null !== $data['days_until_due'] ? (int) $data['days_until_due'] : null; |
|
151
|
8 |
|
$model->defaultSource = $data['default_source'] ?? null; |
|
152
|
8 |
|
$model->endedAt = null !== $data['ended_at'] ? new \DateTimeImmutable('@'.$data['ended_at']) : null; |
|
153
|
8 |
|
$model->items = ItemCollection::createFromArray($data['items']); |
|
|
|
|
|
|
154
|
8 |
|
$model->live = $data['livemode']; |
|
155
|
8 |
|
$model->metadata = MetadataCollection::createFromArray($data['metadata']); |
|
|
|
|
|
|
156
|
8 |
|
$model->plan = Plan::createFromArray($data['plan']); |
|
|
|
|
|
|
157
|
8 |
|
$model->quantity = (int) $data['quantity']; |
|
158
|
8 |
|
$model->startAt = new \DateTimeImmutable('@'.$data['start']); |
|
159
|
8 |
|
$model->status = $data['status']; |
|
160
|
8 |
|
$model->taxPercent = null !== $data['tax_percent'] ? (float) $data['tax_percent'] : null; |
|
161
|
8 |
|
$model->trialEndAt = null !== $data['trial_end'] ? new \DateTimeImmutable('@'.$data['trial_end']) : null; |
|
162
|
8 |
|
$model->trialStartAt = null !== $data['trial_start'] ? new \DateTimeImmutable('@'.$data['trial_start']) : null; |
|
163
|
|
|
|
|
164
|
8 |
|
return $model; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
1 |
|
public function isBilledAutomatically(): bool |
|
168
|
|
|
{ |
|
169
|
1 |
|
return self::BILLING_CHARGE_AUTOMATICALLY === $this->billing; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
public function isTrialing(): bool |
|
173
|
|
|
{ |
|
174
|
|
|
return self::STATUS_TRIALING === $this->status; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
public function isActive(): bool |
|
178
|
|
|
{ |
|
179
|
|
|
return self::STATUS_ACTIVE === $this->status; |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
public function isPastDue(): bool |
|
183
|
|
|
{ |
|
184
|
|
|
return self::STATUS_PAST_DUE === $this->status; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
public function isCanceled(): bool |
|
188
|
|
|
{ |
|
189
|
|
|
return self::STATUS_CANCELED === $this->status; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
public function isUnpaid(): bool |
|
193
|
|
|
{ |
|
194
|
|
|
return self::STATUS_UNPAID === $this->status; |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
1 |
|
public function getId(): string |
|
198
|
|
|
{ |
|
199
|
1 |
|
return $this->id; |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
1 |
|
public function getApplicationFeePercent(): ?float |
|
203
|
|
|
{ |
|
204
|
1 |
|
return $this->applicationFeePercent; |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
1 |
|
public function getBilling(): string |
|
208
|
|
|
{ |
|
209
|
1 |
|
return $this->billing; |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
1 |
|
public function getBillingCycleAnchor() |
|
213
|
|
|
{ |
|
214
|
1 |
|
return $this->billingCycleAnchor; |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
1 |
|
public function willBeCanceledAtPeriodEnd(): bool |
|
218
|
|
|
{ |
|
219
|
1 |
|
return $this->cancelAtPeriodEnd; |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
1 |
|
public function getCanceledAt(): ?\DateTimeImmutable |
|
223
|
|
|
{ |
|
224
|
1 |
|
return $this->canceledAt; |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
1 |
|
public function getCreatedAt(): \DateTimeImmutable |
|
228
|
|
|
{ |
|
229
|
1 |
|
return $this->createdAt; |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
1 |
|
public function getCurrentPeriodEndAt(): \DateTimeImmutable |
|
233
|
|
|
{ |
|
234
|
1 |
|
return $this->currentPeriodEndAt; |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
1 |
|
public function getCurrentPeriodStartAt(): \DateTimeImmutable |
|
238
|
|
|
{ |
|
239
|
1 |
|
return $this->currentPeriodStartAt; |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
1 |
|
public function getCustomer(): string |
|
243
|
|
|
{ |
|
244
|
1 |
|
return $this->customer; |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
1 |
|
public function getDaysUntilDue(): ?int |
|
248
|
|
|
{ |
|
249
|
1 |
|
return $this->daysUntilDue; |
|
250
|
|
|
} |
|
251
|
|
|
|
|
252
|
1 |
|
public function getDefaultSource(): ?string |
|
253
|
|
|
{ |
|
254
|
1 |
|
return $this->defaultSource; |
|
255
|
|
|
} |
|
256
|
|
|
|
|
257
|
1 |
|
public function getEndedAt(): ?\DateTimeImmutable |
|
258
|
|
|
{ |
|
259
|
1 |
|
return $this->endedAt; |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
1 |
|
public function getItems(): ItemCollection |
|
263
|
|
|
{ |
|
264
|
1 |
|
return $this->items; |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
1 |
|
public function getQuantity(): int |
|
268
|
|
|
{ |
|
269
|
1 |
|
return $this->quantity; |
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
1 |
|
public function getStartAt(): \DateTimeImmutable |
|
273
|
|
|
{ |
|
274
|
1 |
|
return $this->startAt; |
|
275
|
|
|
} |
|
276
|
|
|
|
|
277
|
1 |
|
public function getStatus(): string |
|
278
|
|
|
{ |
|
279
|
1 |
|
return $this->status; |
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
1 |
|
public function getTaxPercent(): ?float |
|
283
|
|
|
{ |
|
284
|
1 |
|
return $this->taxPercent; |
|
285
|
|
|
} |
|
286
|
|
|
|
|
287
|
1 |
|
public function getTrialEndAt(): ?\DateTimeImmutable |
|
288
|
|
|
{ |
|
289
|
1 |
|
return $this->trialEndAt; |
|
290
|
|
|
} |
|
291
|
|
|
|
|
292
|
1 |
|
public function getTrialStartAt(): ?\DateTimeImmutable |
|
293
|
|
|
{ |
|
294
|
1 |
|
return $this->trialStartAt; |
|
295
|
|
|
} |
|
296
|
|
|
} |
|
297
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..