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