|
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\Charge; |
|
11
|
|
|
|
|
12
|
|
|
use Shapin\Stripe\Model\Account\Account; |
|
13
|
|
|
use Shapin\Stripe\Model\Card\Card; |
|
14
|
|
|
use Shapin\Stripe\Model\ContainsMetadata; |
|
15
|
|
|
use Shapin\Stripe\Model\CreatableFromArray; |
|
16
|
|
|
use Shapin\Stripe\Model\LivemodeTrait; |
|
17
|
|
|
use Shapin\Stripe\Model\MetadataTrait; |
|
18
|
|
|
use Shapin\Stripe\Model\MetadataCollection; |
|
19
|
|
|
use Shapin\Stripe\Model\Refund\RefundCollection; |
|
20
|
|
|
use Shapin\Stripe\Model\Source\Source; |
|
21
|
|
|
use Money\Currency; |
|
22
|
|
|
use Money\Money; |
|
23
|
|
|
|
|
24
|
|
|
final class Charge implements CreatableFromArray, ContainsMetadata |
|
25
|
|
|
{ |
|
26
|
|
|
use LivemodeTrait, MetadataTrait; |
|
27
|
|
|
|
|
28
|
|
|
const STATUS_FAILED = 'failed'; |
|
29
|
|
|
const STATUS_PENDING = 'pending'; |
|
30
|
|
|
const STATUS_SUCCEEDED = 'succeeded'; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
private $id; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var Money |
|
39
|
|
|
*/ |
|
40
|
|
|
private $amount; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var Money |
|
44
|
|
|
*/ |
|
45
|
|
|
private $amountRefunded; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var string |
|
49
|
|
|
*/ |
|
50
|
|
|
private $application; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @var Money |
|
54
|
|
|
*/ |
|
55
|
|
|
private $applicationFee; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @var ?string |
|
59
|
|
|
*/ |
|
60
|
|
|
private $balanceTransaction; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @var bool |
|
64
|
|
|
*/ |
|
65
|
|
|
private $captured; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @var \DateTimeImmutable |
|
69
|
|
|
*/ |
|
70
|
|
|
private $createdAt; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @var Currency |
|
74
|
|
|
*/ |
|
75
|
|
|
private $currency; |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @var string |
|
79
|
|
|
*/ |
|
80
|
|
|
private $customer; |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @var string |
|
84
|
|
|
*/ |
|
85
|
|
|
private $description; |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @var ?string |
|
89
|
|
|
*/ |
|
90
|
|
|
private $destination; |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @var string |
|
94
|
|
|
*/ |
|
95
|
|
|
private $dispute; |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @var string |
|
99
|
|
|
*/ |
|
100
|
|
|
private $failureCode; |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @var string |
|
104
|
|
|
*/ |
|
105
|
|
|
private $failureMessage; |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @var array |
|
109
|
|
|
*/ |
|
110
|
|
|
private $fraudDetails; |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @var string |
|
114
|
|
|
*/ |
|
115
|
|
|
private $invoice; |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @var string |
|
119
|
|
|
*/ |
|
120
|
|
|
private $onBehalfOf; |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @var string |
|
124
|
|
|
*/ |
|
125
|
|
|
private $order; |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @var ?Outcome |
|
129
|
|
|
*/ |
|
130
|
|
|
private $outcome; |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* @var bool |
|
134
|
|
|
*/ |
|
135
|
|
|
private $paid; |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @var string |
|
139
|
|
|
*/ |
|
140
|
|
|
private $paymentIntent; |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* @var string |
|
144
|
|
|
*/ |
|
145
|
|
|
private $receiptEmail; |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* @var string |
|
149
|
|
|
*/ |
|
150
|
|
|
private $receiptNumber; |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* @var string |
|
154
|
|
|
*/ |
|
155
|
|
|
private $receiptUrl; |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* @var bool |
|
159
|
|
|
*/ |
|
160
|
|
|
private $refunded; |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* @var RefundCollection |
|
164
|
|
|
*/ |
|
165
|
|
|
private $refunds; |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* @var string |
|
169
|
|
|
*/ |
|
170
|
|
|
private $review; |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* @var array |
|
174
|
|
|
*/ |
|
175
|
|
|
private $shipping; |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* @var mixed |
|
179
|
|
|
*/ |
|
180
|
|
|
private $source; |
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* @var string |
|
184
|
|
|
*/ |
|
185
|
|
|
private $sourceTransfer; |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* @var string |
|
189
|
|
|
*/ |
|
190
|
|
|
private $statementDescriptor; |
|
191
|
|
|
|
|
192
|
|
|
/** |
|
193
|
|
|
* @var string |
|
194
|
|
|
*/ |
|
195
|
|
|
private $status; |
|
196
|
|
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* @var string |
|
199
|
|
|
*/ |
|
200
|
|
|
private $transfer; |
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* @var string |
|
204
|
|
|
*/ |
|
205
|
|
|
private $transferGroup; |
|
206
|
|
|
|
|
207
|
9 |
|
private function __construct() |
|
208
|
|
|
{ |
|
209
|
9 |
|
} |
|
210
|
|
|
|
|
211
|
9 |
|
public static function createFromArray(array $data): self |
|
212
|
|
|
{ |
|
213
|
9 |
|
$currency = new Currency(strtoupper($data['currency'])); |
|
214
|
|
|
|
|
215
|
|
|
// Most of the time, the source is a card |
|
216
|
|
|
// @see: https://stripe.com/docs/api/charges/object?lang=curl#charge_object-source |
|
217
|
9 |
|
$source = $data['source']; |
|
218
|
9 |
|
if (isset($source['object'])) { |
|
219
|
9 |
|
if ('card' === $source['object']) { |
|
220
|
7 |
|
$source = Card::createFromArray($source); |
|
221
|
2 |
|
} elseif ('account' === $source['object']) { |
|
222
|
1 |
|
$source = Account::createFromArray($source); |
|
223
|
1 |
|
} elseif ('source' === $source['object']) { |
|
224
|
1 |
|
$source = Source::createFromArray($source); |
|
225
|
|
|
} |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
9 |
|
$model = new self(); |
|
229
|
9 |
|
$model->id = $data['id']; |
|
230
|
9 |
|
$model->amount = new Money($data['amount'], $currency); |
|
231
|
9 |
|
$model->amountRefunded = new Money($data['amount_refunded'], $currency); |
|
232
|
9 |
|
$model->application = $data['application']; |
|
233
|
9 |
|
$model->applicationFee = null !== $data['application_fee'] ? new Money($data['application_fee'], $currency) : new Money(0, $currency); |
|
234
|
9 |
|
$model->balanceTransaction = $data['balance_transaction']; |
|
235
|
9 |
|
$model->captured = (bool) $data['captured']; |
|
236
|
9 |
|
$model->createdAt = new \DateTimeImmutable('@'.$data['created']); |
|
237
|
9 |
|
$model->currency = $currency; |
|
238
|
9 |
|
$model->customer = $data['customer']; |
|
239
|
9 |
|
$model->description = $data['description']; |
|
240
|
9 |
|
$model->destination = $data['destination'] ?? null; |
|
241
|
9 |
|
$model->dispute = $data['dispute']; |
|
242
|
9 |
|
$model->failureCode = $data['failure_code']; |
|
243
|
9 |
|
$model->failureMessage = $data['failure_message']; |
|
244
|
9 |
|
$model->fraudDetails = $data['fraud_details']; // TODO: It's a hash. Make something better than just keeping it as is. |
|
245
|
9 |
|
$model->invoice = $data['invoice']; |
|
246
|
9 |
|
$model->live = (bool) $data['livemode']; |
|
247
|
9 |
|
$model->metadata = MetadataCollection::createFromArray($data['metadata']); |
|
|
|
|
|
|
248
|
9 |
|
$model->onBehalfOf = $data['on_behalf_of']; |
|
249
|
9 |
|
$model->order = $data['order']; |
|
250
|
9 |
|
$model->outcome = null !== $data['outcome'] ? Outcome::createFromArray($data['outcome']) : null; |
|
251
|
9 |
|
$model->paid = (bool) $data['paid']; |
|
252
|
9 |
|
$model->paymentIntent = $data['payment_intent']; |
|
253
|
9 |
|
$model->receiptEmail = $data['receipt_email']; |
|
254
|
9 |
|
$model->receiptNumber = $data['receipt_number']; |
|
255
|
9 |
|
$model->receiptUrl = $data['receipt_number']; |
|
256
|
9 |
|
$model->refunded = (bool) $data['refunded']; |
|
257
|
9 |
|
$model->refunds = RefundCollection::createFromArray($data['refunds']); |
|
|
|
|
|
|
258
|
9 |
|
$model->review = $data['review']; |
|
259
|
9 |
|
$model->shipping = $data['shipping']; // TODO: It's a hash. Make something better than just keeping it as is. |
|
260
|
9 |
|
$model->source = $source; |
|
261
|
9 |
|
$model->sourceTransfer = $data['source_transfer']; |
|
262
|
9 |
|
$model->statementDescriptor = $data['statement_descriptor']; |
|
263
|
9 |
|
$model->status = $data['status']; |
|
264
|
9 |
|
$model->transfer = $data['transfer'] ?? null; |
|
265
|
9 |
|
$model->transferGroup = $data['transfer_group']; |
|
266
|
|
|
|
|
267
|
9 |
|
return $model; |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
2 |
|
public function isFailed(): bool |
|
271
|
|
|
{ |
|
272
|
2 |
|
return self::STATUS_FAILED === $this->status; |
|
273
|
|
|
} |
|
274
|
|
|
|
|
275
|
2 |
|
public function isSucceeded(): bool |
|
276
|
|
|
{ |
|
277
|
2 |
|
return self::STATUS_SUCCEEDED === $this->status; |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
2 |
|
public function isPending(): bool |
|
281
|
|
|
{ |
|
282
|
2 |
|
return self::STATUS_PENDING === $this->status; |
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
|
|
public function getId(): string |
|
286
|
|
|
{ |
|
287
|
|
|
return $this->id; |
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
2 |
|
public function getAmount(): Money |
|
291
|
|
|
{ |
|
292
|
2 |
|
return $this->amount; |
|
293
|
|
|
} |
|
294
|
|
|
|
|
295
|
2 |
|
public function getAmountRefunded(): Money |
|
296
|
|
|
{ |
|
297
|
2 |
|
return $this->amountRefunded; |
|
298
|
|
|
} |
|
299
|
|
|
|
|
300
|
2 |
|
public function getApplication(): ?string |
|
301
|
|
|
{ |
|
302
|
2 |
|
return $this->application; |
|
303
|
|
|
} |
|
304
|
|
|
|
|
305
|
2 |
|
public function getApplicationFee(): Money |
|
306
|
|
|
{ |
|
307
|
2 |
|
return $this->applicationFee; |
|
308
|
|
|
} |
|
309
|
|
|
|
|
310
|
2 |
|
public function getBalanceTransaction(): ?string |
|
311
|
|
|
{ |
|
312
|
2 |
|
return $this->balanceTransaction; |
|
313
|
|
|
} |
|
314
|
|
|
|
|
315
|
2 |
|
public function isCaptured(): bool |
|
316
|
|
|
{ |
|
317
|
2 |
|
return $this->captured; |
|
318
|
|
|
} |
|
319
|
|
|
|
|
320
|
2 |
|
public function getCreatedAt(): \DateTimeImmutable |
|
321
|
|
|
{ |
|
322
|
2 |
|
return $this->createdAt; |
|
323
|
|
|
} |
|
324
|
|
|
|
|
325
|
2 |
|
public function getCurrency(): Currency |
|
326
|
|
|
{ |
|
327
|
2 |
|
return $this->currency; |
|
328
|
|
|
} |
|
329
|
|
|
|
|
330
|
2 |
|
public function getCustomer(): ?string |
|
331
|
|
|
{ |
|
332
|
2 |
|
return $this->customer; |
|
333
|
|
|
} |
|
334
|
|
|
|
|
335
|
2 |
|
public function getDescription(): ?string |
|
336
|
|
|
{ |
|
337
|
2 |
|
return $this->description; |
|
338
|
|
|
} |
|
339
|
|
|
|
|
340
|
2 |
|
public function getDestination(): ?string |
|
341
|
|
|
{ |
|
342
|
2 |
|
return $this->destination; |
|
343
|
|
|
} |
|
344
|
|
|
|
|
345
|
2 |
|
public function getDispute(): ?string |
|
346
|
|
|
{ |
|
347
|
2 |
|
return $this->dispute; |
|
348
|
|
|
} |
|
349
|
|
|
|
|
350
|
2 |
|
public function getFailureCode(): ?string |
|
351
|
|
|
{ |
|
352
|
2 |
|
return $this->failureCode; |
|
353
|
|
|
} |
|
354
|
|
|
|
|
355
|
2 |
|
public function getFailureMessage(): ?string |
|
356
|
|
|
{ |
|
357
|
2 |
|
return $this->failureMessage; |
|
358
|
|
|
} |
|
359
|
|
|
|
|
360
|
2 |
|
public function getFraudDetails(): array |
|
361
|
|
|
{ |
|
362
|
2 |
|
return $this->fraudDetails; |
|
363
|
|
|
} |
|
364
|
|
|
|
|
365
|
2 |
|
public function getInvoice(): ?string |
|
366
|
|
|
{ |
|
367
|
2 |
|
return $this->invoice; |
|
368
|
|
|
} |
|
369
|
|
|
|
|
370
|
2 |
|
public function getOnBehalfOf(): ?string |
|
371
|
|
|
{ |
|
372
|
2 |
|
return $this->onBehalfOf; |
|
373
|
|
|
} |
|
374
|
|
|
|
|
375
|
2 |
|
public function getOrder(): ?string |
|
376
|
|
|
{ |
|
377
|
2 |
|
return $this->order; |
|
378
|
|
|
} |
|
379
|
|
|
|
|
380
|
2 |
|
public function getOutcome(): ?Outcome |
|
381
|
|
|
{ |
|
382
|
2 |
|
return $this->outcome; |
|
383
|
|
|
} |
|
384
|
|
|
|
|
385
|
2 |
|
public function isPaid(): bool |
|
386
|
|
|
{ |
|
387
|
2 |
|
return $this->paid; |
|
388
|
|
|
} |
|
389
|
|
|
|
|
390
|
2 |
|
public function getPaymentIntent(): ?string |
|
391
|
|
|
{ |
|
392
|
2 |
|
return $this->paymentIntent; |
|
393
|
|
|
} |
|
394
|
|
|
|
|
395
|
2 |
|
public function getReceiptEmail(): ?string |
|
396
|
|
|
{ |
|
397
|
2 |
|
return $this->receiptEmail; |
|
398
|
|
|
} |
|
399
|
|
|
|
|
400
|
2 |
|
public function getReceiptNumber(): ?string |
|
401
|
|
|
{ |
|
402
|
2 |
|
return $this->receiptNumber; |
|
403
|
|
|
} |
|
404
|
|
|
|
|
405
|
1 |
|
public function getReceiptUrl(): ?string |
|
406
|
|
|
{ |
|
407
|
1 |
|
return $this->receiptUrl; |
|
408
|
|
|
} |
|
409
|
|
|
|
|
410
|
2 |
|
public function isRefunded(): bool |
|
411
|
|
|
{ |
|
412
|
2 |
|
return $this->refunded; |
|
413
|
|
|
} |
|
414
|
|
|
|
|
415
|
2 |
|
public function getRefunds(): RefundCollection |
|
416
|
|
|
{ |
|
417
|
2 |
|
return $this->refunds; |
|
418
|
|
|
} |
|
419
|
|
|
|
|
420
|
2 |
|
public function getReview(): ?string |
|
421
|
|
|
{ |
|
422
|
2 |
|
return $this->review; |
|
423
|
|
|
} |
|
424
|
|
|
|
|
425
|
2 |
|
public function getShipping(): ?array |
|
426
|
|
|
{ |
|
427
|
2 |
|
return $this->shipping; |
|
428
|
|
|
} |
|
429
|
|
|
|
|
430
|
2 |
|
public function getSource() |
|
431
|
|
|
{ |
|
432
|
2 |
|
return $this->source; |
|
433
|
|
|
} |
|
434
|
|
|
|
|
435
|
2 |
|
public function getSourceTransfer(): ?string |
|
436
|
|
|
{ |
|
437
|
2 |
|
return $this->sourceTransfer; |
|
438
|
|
|
} |
|
439
|
|
|
|
|
440
|
2 |
|
public function getStatementDescriptor(): ?string |
|
441
|
|
|
{ |
|
442
|
2 |
|
return $this->statementDescriptor; |
|
443
|
|
|
} |
|
444
|
|
|
|
|
445
|
2 |
|
public function getStatus(): string |
|
446
|
|
|
{ |
|
447
|
2 |
|
return $this->status; |
|
448
|
|
|
} |
|
449
|
|
|
|
|
450
|
2 |
|
public function getTransfer(): ?string |
|
451
|
|
|
{ |
|
452
|
2 |
|
return $this->transfer; |
|
453
|
|
|
} |
|
454
|
|
|
|
|
455
|
2 |
|
public function getTransferGroup(): ?string |
|
456
|
|
|
{ |
|
457
|
2 |
|
return $this->transferGroup; |
|
458
|
|
|
} |
|
459
|
|
|
} |
|
460
|
|
|
|
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..