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\Customer; |
11
|
|
|
|
12
|
|
|
use Shapin\Stripe\Exception\LogicException; |
13
|
|
|
use Shapin\Stripe\Model\ContainsMetadata; |
14
|
|
|
use Shapin\Stripe\Model\CreatableFromArray; |
15
|
|
|
use Shapin\Stripe\Model\LivemodeTrait; |
16
|
|
|
use Shapin\Stripe\Model\MetadataTrait; |
17
|
|
|
use Shapin\Stripe\Model\MetadataCollection; |
18
|
|
|
use Shapin\Stripe\Model\Source\Source; |
19
|
|
|
use Shapin\Stripe\Model\Source\SourceCollection; |
20
|
|
|
use Shapin\Stripe\Model\Subscription\Subscription; |
21
|
|
|
use Shapin\Stripe\Model\Subscription\SubscriptionCollection; |
22
|
|
|
use Money\Currency; |
23
|
|
|
|
24
|
|
|
final class Customer implements CreatableFromArray, ContainsMetadata |
25
|
|
|
{ |
26
|
|
|
use LivemodeTrait, MetadataTrait; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
private $id; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var int |
35
|
|
|
*/ |
36
|
|
|
private $accountBalance; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var \DateTimeImmutable |
40
|
|
|
*/ |
41
|
|
|
private $createdAt; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var ?Currency |
45
|
|
|
*/ |
46
|
|
|
private $currency; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var string |
50
|
|
|
*/ |
51
|
|
|
private $defaultSourceId; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var bool |
55
|
|
|
*/ |
56
|
|
|
private $delinquent; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @var ?string |
60
|
|
|
*/ |
61
|
|
|
private $description; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @var array |
65
|
|
|
*/ |
66
|
|
|
private $discount; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @var string |
70
|
|
|
*/ |
71
|
|
|
private $email; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @var string |
75
|
|
|
*/ |
76
|
|
|
private $invoicePrefix; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @var ?InvoiceSettings |
80
|
|
|
*/ |
81
|
|
|
private $invoiceSettings; |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @var ?Shipping |
85
|
|
|
*/ |
86
|
|
|
private $shipping; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @var SourceCollection |
90
|
|
|
*/ |
91
|
|
|
private $sources; |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @var SubscriptionCollection |
95
|
|
|
*/ |
96
|
|
|
private $subscriptions; |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @var TaxInfo |
100
|
|
|
*/ |
101
|
|
|
private $taxInfo; |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @var TaxInfoVerification |
105
|
|
|
*/ |
106
|
|
|
private $taxInfoVerification; |
107
|
|
|
|
108
|
5 |
|
private function __construct() |
109
|
|
|
{ |
110
|
5 |
|
} |
111
|
|
|
|
112
|
5 |
|
public static function createFromArray(array $data): self |
113
|
|
|
{ |
114
|
5 |
|
$model = new self(); |
115
|
5 |
|
$model->id = $data['id']; |
116
|
5 |
|
$model->accountBalance = (int) $data['account_balance']; |
117
|
5 |
|
$model->createdAt = new \DateTimeImmutable('@'.$data['created']); |
118
|
5 |
|
if (isset($data['currency'])) { |
119
|
5 |
|
$model->currency = new Currency(strtoupper($data['currency'])); |
120
|
|
|
} |
121
|
5 |
|
$model->defaultSourceId = $data['default_source']; |
122
|
5 |
|
$model->delinquent = (bool) $data['delinquent']; |
123
|
5 |
|
$model->description = $data['description']; |
124
|
5 |
|
$model->discount = array_key_exists('discount', $data) ? $data['discount'] : null; |
125
|
5 |
|
$model->email = $data['email']; |
126
|
5 |
|
$model->invoicePrefix = $data['invoice_prefix']; |
127
|
5 |
|
$model->invoiceSettings = array_key_exists('invoice_settings', $data) ? InvoiceSettings::createFromArray($data['invoice_settings']) : null; |
128
|
5 |
|
$model->live = (bool) $data['livemode']; |
129
|
5 |
|
$model->metadata = MetadataCollection::createFromArray($data['metadata']); |
|
|
|
|
130
|
5 |
|
if (isset($data['shipping'])) { |
131
|
|
|
$model->shipping = Shipping::createFromArray($data['shipping']); |
132
|
|
|
} |
133
|
5 |
|
$model->sources = SourceCollection::createFromArray($data['sources']); |
|
|
|
|
134
|
5 |
|
$model->subscriptions = SubscriptionCollection::createFromArray($data['subscriptions']); |
|
|
|
|
135
|
5 |
|
if (isset($data['tax_info'])) { |
136
|
|
|
$model->taxInfo = TaxInfo::createFromArray($data['tax_info']); |
|
|
|
|
137
|
|
|
} |
138
|
5 |
|
if (isset($data['tax_info_verification'])) { |
139
|
|
|
$model->taxInfoVerification = TaxInfoVerification::createFromArray($data['tax_info_verification']); |
|
|
|
|
140
|
|
|
} |
141
|
|
|
|
142
|
5 |
|
return $model; |
143
|
|
|
} |
144
|
|
|
|
145
|
1 |
|
public function getId(): string |
146
|
|
|
{ |
147
|
1 |
|
return $this->id; |
148
|
|
|
} |
149
|
|
|
|
150
|
1 |
|
public function getAccountBalance(): int |
151
|
|
|
{ |
152
|
1 |
|
return $this->accountBalance; |
153
|
|
|
} |
154
|
|
|
|
155
|
1 |
|
public function getCreatedAt(): \DateTimeImmutable |
156
|
|
|
{ |
157
|
1 |
|
return $this->createdAt; |
158
|
|
|
} |
159
|
|
|
|
160
|
1 |
|
public function getCurrency(): ?Currency |
161
|
|
|
{ |
162
|
1 |
|
return $this->currency; |
163
|
|
|
} |
164
|
|
|
|
165
|
1 |
|
public function getDefaultSource(): ?Source |
166
|
|
|
{ |
167
|
1 |
|
if (null === $this->defaultSourceId) { |
168
|
1 |
|
return null; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
foreach ($this->sources->getElements() as $source) { |
172
|
|
|
if ($this->defaultSourceId === $source->getId()) { |
173
|
|
|
return $source; |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
throw new LogicException('Unable to find default source in available sources.'); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
public function getDefaultSourceId(): ?string |
181
|
|
|
{ |
182
|
|
|
return $this->defaultSourceId; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
public function hasDefaultSource(): bool |
186
|
|
|
{ |
187
|
|
|
return null !== $this->defaultSourceId; |
188
|
|
|
} |
189
|
|
|
|
190
|
1 |
|
public function isDelinquent(): bool |
191
|
|
|
{ |
192
|
1 |
|
return $this->delinquent; |
193
|
|
|
} |
194
|
|
|
|
195
|
1 |
|
public function getDescription(): ?string |
196
|
|
|
{ |
197
|
1 |
|
return $this->description; |
198
|
|
|
} |
199
|
|
|
|
200
|
1 |
|
public function getDiscount(): ?array |
201
|
|
|
{ |
202
|
1 |
|
return $this->discount; |
203
|
|
|
} |
204
|
|
|
|
205
|
1 |
|
public function getEmail(): ?string |
206
|
|
|
{ |
207
|
1 |
|
return $this->email; |
208
|
|
|
} |
209
|
|
|
|
210
|
1 |
|
public function getInvoicePrefix(): ?string |
211
|
|
|
{ |
212
|
1 |
|
return $this->invoicePrefix; |
213
|
|
|
} |
214
|
|
|
|
215
|
1 |
|
public function getInvoiceSettings(): ?InvoiceSettings |
216
|
|
|
{ |
217
|
1 |
|
return $this->invoiceSettings; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
public function getShipping(): ?Shipping |
221
|
|
|
{ |
222
|
|
|
return $this->shipping; |
223
|
|
|
} |
224
|
|
|
|
225
|
1 |
|
public function getSources(): SourceCollection |
226
|
|
|
{ |
227
|
1 |
|
return $this->sources; |
228
|
|
|
} |
229
|
|
|
|
230
|
1 |
|
public function getSubscriptions(): SubscriptionCollection |
231
|
|
|
{ |
232
|
1 |
|
return $this->subscriptions; |
233
|
|
|
} |
234
|
|
|
|
235
|
1 |
|
public function getLatestSubscription(): ?Subscription |
236
|
|
|
{ |
237
|
1 |
|
$subscriptions = $this->subscriptions->getElements(); |
238
|
1 |
|
if (0 === count($subscriptions)) { |
239
|
|
|
return null; |
240
|
|
|
} |
241
|
|
|
|
242
|
1 |
|
return reset($subscriptions); |
243
|
|
|
} |
244
|
|
|
|
245
|
1 |
|
public function getTaxInfo(): ?TaxInfo |
246
|
|
|
{ |
247
|
1 |
|
return $this->taxInfo; |
248
|
|
|
} |
249
|
|
|
|
250
|
1 |
|
public function getTaxInfoVerification(): ?TaxInfoVerification |
251
|
|
|
{ |
252
|
1 |
|
return $this->taxInfoVerification; |
253
|
|
|
} |
254
|
|
|
} |
255
|
|
|
|
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..