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