Completed
Push — master ( b6f7ca...4aea47 )
by Olivier
03:30
created

PaymentIntent::getInvoiceId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
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\PaymentIntent;
11
12
use Shapin\Stripe\Model\ContainsMetadata;
13
use Shapin\Stripe\Model\Charge\ChargeCollection;
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 Money\Currency;
19
use Money\Money;
20
21
final class PaymentIntent implements CreatableFromArray, ContainsMetadata
22
{
23
    use LivemodeTrait, MetadataTrait;
24
25
    const CAPTURE_METHOD_AUTOMATIC = 'automatic';
26
    const CAPTURE_METHOD_MANUAL = 'manual';
27
28
    const CONFIRMATION_METHOD_AUTOMATIC = 'automatic';
29
    const CONFIRMATION_METHOD_MANUAL = 'manual';
30
31
    const STATUS_REQUIRES_PAYMENT_METHOD = 'requires_payment_method';
32
    const STATUS_REQUIRES_CONFIRMATION = 'requires_confirmation';
33
    const STATUS_REQUIRES_ACTION = 'requires_action';
34
    const STATUS_PROCESSING = 'processing';
35
    const STATUS_REQUIRES_CAPTURE = 'requires_capture';
36
    const STATUS_CANCELED = 'canceled';
37
    const STATUS_SUCCEEDED = 'succeeded';
38
39
    /**
40
     * @var ?string
41
     */
42
    private $id;
43
44
    /**
45
     * @var Money
46
     */
47
    private $amount;
48
49
    /**
50
     * @var Money
51
     */
52
    private $amountCapturable;
53
54
    /**
55
     * @var Money
56
     */
57
    private $amountReceived;
58
59
    /**
60
     * @var ?string
61
     */
62
    private $applicationId;
63
64
    /**
65
     * @var ?Money
66
     */
67
    private $applicationFeeAmount;
68
69
    /**
70
     * @var ?\DateTimeImmutable
71
     */
72
    private $canceledAt;
73
74
    /**
75
     * @var ?string
76
     */
77
    private $cancellationReason;
78
79
    /**
80
     * @var string
81
     */
82
    private $captureMethod;
83
84
    /**
85
     * @var ChargeCollection
86
     */
87
    private $charges;
88
89
    /**
90
     * @var string
91
     */
92
    private $clientSecret;
93
94
    /**
95
     * @var string
96
     */
97
    private $confirmationMethod;
98
99
    /**
100
     * @var \DateTimeImmutable
101
     */
102
    private $createdAt;
103
104
    /**
105
     * @var Currency
106
     */
107
    private $currency;
108
109
    /**
110
     * @var string
111
     */
112
    private $customerId;
113
114
    /**
115
     * @var string
116
     */
117
    private $description;
118
119
    /**
120
     * @var string
121
     */
122
    private $invoiceId;
123
124
    /**
125
     * @var ?LastPaymentError
126
     */
127
    private $lastPaymentError;
128
129
    /**
130
     * @var ?NextAction
131
     */
132
    private $nextAction;
133
134
    /**
135
     * @var ?string
136
     */
137
    private $onBehalfOfId;
138
139
    /**
140
     * @var ?string
141
     */
142
    private $paymentMethodId;
143
144
    /**
145
     * @var array
146
     */
147
    private $paymentMethodTypes;
148
149
    /**
150
     * @var ?string
151
     */
152
    private $receiptEmail;
153
154
    /**
155
     * @var ?string
156
     */
157
    private $reviewId;
158
159
    /**
160
     * @var ?Shipping
161
     */
162
    private $shipping;
163
164
    /**
165
     * @var ?string
166
     */
167
    private $statementDescriptor;
168
169
    /**
170
     * @var string
171
     */
172
    private $status;
173
174
    /**
175
     * @var ?TransferData
176
     */
177
    private $transferData;
178
179
    /**
180
     * @var ?string
181
     */
182
    private $transferGroup;
183
184 2
    public static function createFromArray(array $data): self
185
    {
186 2
        $currency = new Currency(strtoupper($data['currency']));
187
188 2
        $model = new self();
189 2
        $model->id = $data['id'];
190 2
        $model->amount = new Money($data['amount'], $currency);
191 2
        $model->amountCapturable = new Money($data['amount_capturable'], $currency);
192 2
        $model->amountReceived = new Money($data['amount_received'], $currency);
193 2
        $model->applicationId = $data['application'];
194 2
        $model->canceledAt = isset($data['canceled_at']) ? new \DateTimeImmutable('@'.$data['canceled_at']) : null;
195 2
        $model->cancellationReason = $data['cancellation_reason'];
196 2
        $model->captureMethod = $data['capture_method'];
197 2
        $model->charges = ChargeCollection::createFromArray($data['charges']);
0 ignored issues
show
Documentation Bug introduced by
It seems like \Shapin\Stripe\Model\Cha...Array($data['charges']) of type object<self> is incompatible with the declared type object<Shapin\Stripe\Mod...harge\ChargeCollection> of property $charges.

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..

Loading history...
198 2
        $model->clientSecret = $data['client_secret'];
199 2
        $model->confirmationMethod = $data['confirmation_method'];
200 2
        $model->createdAt = new \DateTimeImmutable('@'.$data['created']);
201 2
        $model->currency = $currency;
202 2
        $model->customerId = $data['customer'];
203 2
        $model->description = $data['description'];
204 2
        $model->invoiceId = $data['invoice'];
205 2
        $model->lastPaymentError = isset($data['last_payment_error']) ? LastPaymentError::createFromArray($data['last_payment_error']) : null;
206 2
        $model->live = $data['livemode'];
207 2
        $model->metadata = MetadataCollection::createFromArray($data['metadata']);
0 ignored issues
show
Documentation Bug introduced by
It seems like \Shapin\Stripe\Model\Met...rray($data['metadata']) of type object<self> is incompatible with the declared type object<Shapin\Stripe\Model\MetadataCollection> of property $metadata.

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..

Loading history...
208 2
        $model->nextAction = isset($data['next_action']) ? LastPaymentError::createFromArray($data['next_action']) : null;
209 2
        $model->onBehalfOfId = $data['on_behalf_of'];
210 2
        $model->paymentMethodId = $data['payment_method'];
211 2
        $model->paymentMethodTypes = $data['payment_method_types'];
212 2
        $model->receiptEmail = $data['receipt_email'];
213 2
        $model->reviewId = $data['review'];
214 2
        $model->shipping = isset($data['shipping']) ? Shipping::createFromArray($data['shipping']) : null;
215 2
        $model->statementDescriptor = $data['statement_descriptor'];
216 2
        $model->status = $data['status'];
217 2
        $model->transferData = isset($data['transfer_data']) ? TransferData::createFromArray($data['transfer_data']) : null;
218 2
        $model->transferGroup = $data['transfer_group'];
219
220 2
        return $model;
221
    }
222
223 1
    public function getId(): string
224
    {
225 1
        return $this->id;
226
    }
227
228 1
    public function getAmount(): Money
229
    {
230 1
        return $this->amount;
231
    }
232
233 1
    public function getAmountCapturable(): Money
234
    {
235 1
        return $this->amountCapturable;
236
    }
237
238 1
    public function getAmountReceived(): Money
239
    {
240 1
        return $this->amountReceived;
241
    }
242
243 1
    public function getApplicationId(): ?string
244
    {
245 1
        return $this->applicationId;
246
    }
247
248 1
    public function getApplicationFeeAmount(): ?Money
249
    {
250 1
        return $this->applicationFeeAmount;
251
    }
252
253 1
    public function getCanceledAt(): \DateTimeInterface
254
    {
255 1
        return $this->canceledAt;
256
    }
257
258 1
    public function getCancellationReason(): ?string
259
    {
260 1
        return $this->cancellationReason;
261
    }
262
263 1
    public function getCaptureMethod(): string
264
    {
265 1
        return $this->captureMethod;
266
    }
267
268 1
    public function getCharges(): ChargeCollection
269
    {
270 1
        return $this->charges;
271
    }
272
273 1
    public function getClientSecret(): string
274
    {
275 1
        return $this->clientSecret;
276
    }
277
278 1
    public function getConfirmationMethod(): string
279
    {
280 1
        return $this->confirmationMethod;
281
    }
282
283 1
    public function getCreatedAt(): \DateTimeInterface
284
    {
285 1
        return $this->createdAt;
286
    }
287
288 1
    public function getCurrency(): Currency
289
    {
290 1
        return $this->currency;
291
    }
292
293 1
    public function getCustomerId(): ?string
294
    {
295 1
        return $this->customerId;
296
    }
297
298 1
    public function getDescription(): ?string
299
    {
300 1
        return $this->description;
301
    }
302
303 1
    public function getInvoiceId(): ?string
304
    {
305 1
        return $this->invoiceId;
306
    }
307
308 1
    public function getLastPaymentError(): ?LastPaymentError
309
    {
310 1
        return $this->lastPaymentError;
311
    }
312
313 1
    public function getNextAction(): ?NextAction
314
    {
315 1
        return $this->nextAction;
316
    }
317
318 1
    public function getOnBehalfOfId(): ?string
319
    {
320 1
        return $this->onBehalfOfId;
321
    }
322
323 1
    public function getPaymentMethodId(): ?string
324
    {
325 1
        return $this->paymentMethodId;
326
    }
327
328 1
    public function getPaymentMethodTypes(): array
329
    {
330 1
        return $this->paymentMethodTypes;
331
    }
332
333 1
    public function getReceiptEmail(): ?string
334
    {
335 1
        return $this->receiptEmail;
336
    }
337
338 1
    public function getReviewId(): ?string
339
    {
340 1
        return $this->reviewId;
341
    }
342
343 1
    public function getShipping(): ?Shipping
344
    {
345 1
        return $this->shipping;
346
    }
347
348 1
    public function getStatementDescriptor(): ?string
349
    {
350 1
        return $this->statementDescriptor;
351
    }
352
353 1
    public function getStatus(): string
354
    {
355 1
        return $this->status;
356
    }
357
358 1
    public function getTransferData(): ?TransferData
359
    {
360 1
        return $this->transferData;
361
    }
362
363 1
    public function getTransferGroup(): ?string
364
    {
365 1
        return $this->transferGroup;
366
    }
367
}
368