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