Completed
Push — master ( 2afac7...02ca58 )
by Olivier
04:58
created

Source::isChargeable()   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\Source;
11
12
use Shapin\Stripe\Model\ContainsMetadata;
13
use Shapin\Stripe\Model\CreatableFromArray;
14
use Shapin\Stripe\Model\LivemodeTrait;
15
use Shapin\Stripe\Model\MetadataTrait;
16
use Shapin\Stripe\Model\MetadataCollection;
17
use Money\Currency;
18
use Money\Money;
19
20
final class Source implements CreatableFromArray, ContainsMetadata
21
{
22
    const FLOW_CODE_VERIFICATION = 'code_verification';
23
    const FLOW_NONE = 'none';
24
    const FLOW_REDIRECT = 'redirect';
25
    const FLOW_RECEIVER = 'receiver';
26
27
    const NOTIFICATION_METHOD_EMAIL = 'email';
28
    const NOTIFICATION_METHOD_MANUAL = 'manual';
29
    const NOTIFICATION_METHOD_NONE = 'none';
30
31
    const REFUND_ATTRIBUTES_METHOD_EMAIL = 'email';
32
    const REFUND_ATTRIBUTES_METHOD_MANUAL = 'manual';
33
34
    const STATUS_CANCELED = 'canceled';
35
    const STATUS_CHARGEABLE = 'chargeable';
36
    const STATUS_CONSUMED = 'consumed';
37
    const STATUS_FAILED = 'failed';
38
    const STATUS_PENDING = 'pending';
39
40
    const TYPE_ACH_CREDIT_TRANSFER = 'ach_credit_transfer';
41
    const TYPE_ACH_DEBIT = 'ach_debit';
42
    const TYPE_ALIPAY = 'alipay';
43
    const TYPE_BANCONTACT = 'bancontact';
44
    const TYPE_CARD = 'card';
45
    const TYPE_CARD_PRESENT = 'card_present';
46
    const TYPE_EPS = 'eps';
47
    const TYPE_GIROPAY = 'giropay';
48
    const TYPE_IDEAL = 'ideal';
49
    const TYPE_MULTIBANCO = 'multibanco';
50
    const TYPE_P24 = 'p24';
51
    const TYPE_PAPER_CHECK = 'paper_check';
52
    const TYPE_SEPA_CREDIT_TRANSFER = 'sepa_credit_transfer';
53
    const TYPE_SEPA_DEBIT = 'sepa_debit';
54
    const TYPE_SOFORT = 'sofort';
55
    const TYPE_THREE_D_SECURE = 'three_d_secure';
56
57
    const USAGE_REUSABLE = 'reusable';
58
    const USAGE_SINGLE_USE = 'single_use';
59
60
    use LivemodeTrait, MetadataTrait;
61
62
    /**
63
     * @var string
64
     */
65
    private $id;
66
67
    /**
68
     * @var ?AchCreditTransfer
69
     */
70
    private $achCreditTransfer;
71
72
    /**
73
     * @var ?Money
74
     */
75
    private $amount;
76
77
    /**
78
     * @var ?Card
79
     */
80
    private $card;
81
82
    /**
83
     * @var ?string
84
     */
85
    private $clientSecret;
86
87
    /**
88
     * @var ?CodeVerification
89
     */
90
    private $codeVerification;
91
92
    /**
93
     * @var \DateTimeImmutable
94
     */
95
    private $createdAt;
96
97
    /**
98
     * @var ?Currency
99
     */
100
    private $currency;
101
102
    /**
103
     * @var ?string
104
     */
105
    private $customer;
106
107
    /**
108
     * @var ?string
109
     */
110
    private $flow;
111
112
    /**
113
     * @var ?Owner
114
     */
115
    private $owner;
116
117
    /**
118
     * @var ?Receiver
119
     */
120
    private $receiver;
121
122
    /**
123
     * @var ?Redirect
124
     */
125
    private $redirect;
126
127
    /**
128
     * @var ?string
129
     */
130
    private $statementDescriptor;
131
132
    /**
133
     * @var ?string
134
     */
135
    private $status;
136
137
    /**
138
     * @var ?string
139
     */
140
    private $type;
141
142
    /**
143
     * @var ?string
144
     */
145
    private $usage;
146
147 17
    public static function createFromArray(array $data): self
148
    {
149 17
        $model = new self();
150
151 17
        if (isset($data['currency'])) {
152 10
            $currency = new Currency(strtoupper($data['currency']));
153 10
            $model->amount = isset($data['amount']) ? new Money($data['amount'], $currency) : null;
154 10
            $model->currency = $currency;
155 10
            if (isset($data['receiver'])) {
156 10
                $model->receiver = Receiver::createFromArray($data['receiver'], $currency);
157
            }
158
        }
159
160 17
        $model->id = $data['id'];
161 17
        if (isset($data['ach_credit_transfer'])) {
162 10
            $model->achCreditTransfer = AchCreditTransfer::createFromArray($data['ach_credit_transfer']);
163
        }
164 17
        if (isset($data['card'])) {
165 5
            $model->card = Card::createFromArray($data['card']);
166
        }
167 17
        $model->clientSecret = $data['client_secret'] ?? null;
168 17
        if (isset($data['code_verification'])) {
169
            $model->codeVerification = CodeVerification::createFromArray($data['code_verification']);
170
        }
171 17
        $model->createdAt = new \DateTimeImmutable('@'.$data['created']);
172 17
        $model->customer = $data['customer'] ?? null;
173 17
        $model->flow = $data['flow'] ?? null;
174 17
        $model->live = $data['livemode'];
175 17
        $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...
176 17
        $model->owner = isset($data['owner']) ? Owner::createFromArray($data['owner']) : null;
177 17
        if (isset($data['redirect'])) {
178
            $model->redirect = Redirect::createFromArray($data['redirect']);
179
        }
180 17
        $model->statementDescriptor = $data['statement_descriptor'] ?? null;
181 17
        $model->status = $data['status'] ?? null;
182 17
        $model->type = $data['type'] ?? null;
183 17
        $model->usage = $data['usage'] ?? null;
184
185 17
        return $model;
186
    }
187
188 1
    public function isThreeDSecure(): bool
189
    {
190 1
        return self::TYPE_THREE_D_SECURE === $this->type;
191
    }
192
193 1
    public function isCanceled(): bool
194
    {
195 1
        return self::STATUS_CANCELED === $this->status;
196
    }
197
198 1
    public function isChargeable(): bool
199
    {
200 1
        return self::STATUS_CHARGEABLE === $this->status;
201
    }
202
203 1
    public function isConsumed(): bool
204
    {
205 1
        return self::STATUS_CONSUMED === $this->status;
206
    }
207
208 1
    public function isFailed(): bool
209
    {
210 1
        return self::STATUS_FAILED === $this->status;
211
    }
212
213 1
    public function isPending(): bool
214
    {
215 1
        return self::STATUS_PENDING === $this->status;
216
    }
217
218 2
    public function getId(): string
219
    {
220 2
        return $this->id;
221
    }
222
223 2
    public function getAchCreditTransfer(): ?AchCreditTransfer
224
    {
225 2
        return $this->achCreditTransfer;
226
    }
227
228 2
    public function getAmount(): ?Money
229
    {
230 2
        return $this->amount;
231
    }
232
233 1
    public function getCard(): ?Card
234
    {
235 1
        return $this->card;
236
    }
237
238 2
    public function getClientSecret(): ?string
239
    {
240 2
        return $this->clientSecret;
241
    }
242
243 2
    public function getCodeVerification(): ?CodeVerification
244
    {
245 2
        return $this->codeVerification;
246
    }
247
248 2
    public function getCreatedAt(): \DateTimeImmutable
249
    {
250 2
        return $this->createdAt;
251
    }
252
253 2
    public function getCurrency(): ?Currency
254
    {
255 2
        return $this->currency;
256
    }
257
258 2
    public function getCustomer(): ?string
259
    {
260 2
        return $this->customer;
261
    }
262
263 2
    public function getFlow(): ?string
264
    {
265 2
        return $this->flow;
266
    }
267
268 2
    public function getOwner(): ?Owner
269
    {
270 2
        return $this->owner;
271
    }
272
273 2
    public function getReceiver(): ?Receiver
274
    {
275 2
        return $this->receiver;
276
    }
277
278 2
    public function getRedirect(): ?Redirect
279
    {
280 2
        return $this->redirect;
281
    }
282
283 2
    public function getStatementDescriptor(): ?string
284
    {
285 2
        return $this->statementDescriptor;
286
    }
287
288 2
    public function getStatus(): ?string
289
    {
290 2
        return $this->status;
291
    }
292
293 2
    public function getType(): ?string
294
    {
295 2
        return $this->type;
296
    }
297
298 2
    public function getUsage(): ?string
299
    {
300 2
        return $this->usage;
301
    }
302
}
303