Checkout::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 11
nc 2
nop 1
dl 0
loc 12
ccs 12
cts 12
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace BPCI\SumUp\Checkout;
3
4
use BPCI\SumUp\Customer\Customer;
5
use BPCI\SumUp\Customer\CustomerInterface;
6
use BPCI\SumUp\Customer\PaymentInstrument\PaymentInstrument;
7
use BPCI\SumUp\Customer\PaymentInstrument\PaymentInstrumentInterface;
8
use BPCI\SumUp\Traits\PropertyHandler;
9
use BPCI\SumUp\Traits\PropertyHandlerInterface;
10
use BPCI\SumUp\Utils\Currency;
11
12
class Checkout implements CheckoutInterface, PropertyHandlerInterface
13
{
14
	use PropertyHandler;
15
16
	const PENDING = 'PENDING';
17
	const COMPLETED = 'COMPLETED';
18
	const FAILED = 'FAILED';
19
20
	protected $id;
21
	protected $status;
22
	protected $amount;
23
	protected $feeAmount;
24
	protected $currency;
25
	protected $payToEmail;
26
	protected $payFromEmail;
27
	protected $description;
28
	protected $redirectUrl;
29
	protected $validUntil;
30
	protected $token;
31
	protected $transactionId;
32
	protected $transactionCode;
33
	protected $type;
34
	protected $installments;
35
36
	/**
37
	 * Checkout reference
38
	 *
39
	 * @var string
40
	 */
41
	protected $reference;
42
43
	/**
44
	 * Customer
45
	 *
46
	 * @var null|Customer
47
	 */
48
	protected $customer;
49
50
	/**
51
     * PaymentInstrument
52
	 *
53
	 *
54
     * @var null|PaymentInstrument
55
	 */
56
	protected $card;
57
58
59
	/**
60
	 * checkout constructor
61
	 *
62
	 * @param array $data
63
	 */
64 3
	public function __construct(array $data = null) {
65 3
		if ($data !== null) {
66 3
            $this->setAmount($data['amount']??0);
67 3
            $this->setPayToEmail($data['pay_to_email']??'');
68 3
            $this->setCheckoutReference($data['checkout_reference']??'');
69 3
            $this->setCurrency($data['currency']??'');
70 3
			$this->setDescription($data['description']??null);
71 3
			$this->setFeeAmount($data['fee_amount']??null);
72 3
			$this->setPayFromEmail($data['pay_from_mail']??null);
73 3
			$this->setId($data['id']??null);
74 3
			$this->setRedirectUrl($data['redirect_url']??null);
75 3
			$this->setStatus($data['status']??null);
76
		}
77 3
	}
78
79
    /**
80
     * @inheritDoc
81
     */
82 3
    public function setCheckoutReference(string $reference): CheckoutInterface
83
    {
84 3
        $this->reference = trim($reference) === '' ? null : $reference;
85
86 3
        return $this;
87
    }
88
89
	/**
90
	 * @inheritDoc
91
	 */
92 2
	public function isValid(): bool {
93 2
		return $this->getReference() !== null
94 2
			&& $this->getAmount() !== null
95 2
			&& $this->getPayToEmail() !== null
96 2
            && $this->getAmount() > 0
97 2
			&& Currency::isValid($this->getCurrency());
98
	}
99
100
	/**
101
     * Get checkout reference
102
     *
103
     * @return  string
104
	 */
105 2
    public function getReference(): ?string
106
    {
107 2
        return $this->reference;
108
	}
109
110
	/**
111
     * Set checkout reference
112
     *
113
     * @param  string $reference Checkout reference
114
     *
115
     * @return  CheckoutInterface
116
	 */
117
    public function setReference(?string $reference): CheckoutInterface
118
    {
119
        $this->reference = $reference;
120
121
		return $this;
122
	}
123
124
	/**
125
	 * @inheritDoc
126
	 */
127 2
	public function getAmount():? float {
128 2
		return $this->amount;
129
	}
130
131
	/**
132
	 * @inheritDoc
133
	 */
134 3
	public function setAmount(float $amount): CheckoutInterface {
135 3
		$this->amount = $amount > 0 ? $amount : null;
136 3
		return $this;
137
	}
138
139
    /**
140
     * @inheritDoc
141
     */
142 2
    public function getPayToEmail():? string
143
    {
144 2
        return $this->payToEmail;
145
    }
146
147
    /**
148
     * @inheritDoc
149
     */
150 3
    public function setPayToEmail(string $email): CheckoutInterface
151
    {
152 3
        $this->payToEmail = trim($email) === '' ? null : $email;
153
154 3
        return $this;
155
    }
156
157
	/**
158
	 * @inheritDoc
159
	 */
160 2
	public function getCurrency():? string {
161 2
		return $this->currency;
162
	}
163
164
	/**
165
	 * @inheritDoc
166
	 */
167 3
	public function setCurrency(?string $currency): CheckoutInterface {
168 3
		$this->currency = $currency;
169 3
		return $this;
170
	}
171
172
	/**
173
	 * @inheritDoc
174
	 */
175 2
    public function getId():? string
176
    {
177 2
        return $this->id;
178
	}
179
180
	/**
181
	 * @inheritDoc
182
	 */
183 3
    public function setId(?string $id): CheckoutInterface
184
    {
185 3
        $this->id = $id;
186 3
		return $this;
187
	}
188
189
	/**
190
	 * @inheritDoc
191
	 */
192
    public function getStatus():? string
193
    {
194
        return $this->status;
195
	}
196
197
	/**
198
	 * @inheritDoc
199
	 */
200 3
    public function setStatus(?string $status): CheckoutInterface
201
    {
202 3
        $this->status = $status;
203 3
		return $this;
204
	}
205
206
    /**
207
     * @inheritDoc
208
     */
209 1
    public function getCheckoutReference():? string
210
    {
211 1
        return $this->reference;
212
    }
213
214
	/**
215
	 * @inheritDoc
216
	 */
217 2
	public function getDescription():? string {
218 2
		return $this->description;
219
	}
220
221
	/**
222
	 * @inheritDoc
223
	 */
224 3
	public function setDescription(?string $description): CheckoutInterface {
225 3
		$this->description = $description;
226 3
		return $this;
227
	}
228
229
	/**
230
	 * @inheritDoc
231
	 */
232 2
	public function getFeeAmount():? float {
233 2
		return $this->feeAmount;
234
	}
235
236
	/**
237
	 * @inheritDoc
238
	 */
239 3
	public function setFeeAmount(?float $fee): CheckoutInterface {
240 3
		$this->feeAmount = $fee;
241 3
		return $this;
242
	}
243
244
	/**
245
	 * @inheritDoc
246
	 */
247 2
	public function getPayFromEmail():? string {
248 2
		return $this->payFromEmail;
249
	}
250
251
	/**
252
	 * @inheritDoc
253
	 */
254 3
	public function setPayFromEmail(?string $email): CheckoutInterface {
255 3
		$this->payFromEmail = $email;
256 3
		return $this;
257
	}
258
259
	/**
260
	 * @inheritDoc
261
	 */
262 2
	public function getRedirectUrl():? string {
263 2
		return $this->redirectUrl;
264
	}
265
266
	/**
267
	 * @inheritDoc
268
	 */
269 3
	public function setRedirectUrl(?string $url): CheckoutInterface {
270 3
		$this->redirectUrl = $url;
271 3
		return $this;
272
	}
273
274
    public function getValidUntil():? string
275
    {
276
		return $this->validUntil;
277
	}
278
279 2
    public function setValidUntil(?string $timestamp): CheckoutInterface
280
    {
281 2
		$this->validUntil = $timestamp;
282 2
		return $this;
283
	}
284
285
    public function getTransactionCode():? string
286
    {
287
		return $this->transactionCode;
288
	}
289
290 1
    public function setTransactionCode(?string $code): CheckoutInterface
291
    {
292 1
		$this->transactionCode = $code;
293 1
		return $this;
294
	}
295
296
    public function getTransactionId():? string
297
    {
298
		return $this->transactionId;
299
	}
300
301 1
    public function setTransactionId(?string $id): CheckoutInterface
302
    {
303 1
		$this->transactionId = $id;
304 1
		return $this;
305
	}
306
307
    public function getTransactions():? array
308
    {
309
//        return $this->transactions;
310
		//TODO remember myself whats is it.
311
		return [];
312
	}
313
314
    public function setTransactions(?Array $transactions): CheckoutInterface
315
    {
316
//        $this->transactions = $transactions;
317
		//TODO remember myself whats is it.
318
		return $this;
319
	}
320
321
    public function getToken():? string
322
    {
323
		return $this->token;
324
	}
325
326 1
    public function setToken(?string $token): CheckoutInterface
327
    {
328 1
		$this->token = $token;
329 1
		return $this;
330
	}
331
332
	/**
333
	 * Get customer
334
	 * @return CustomerInterface|null
335
	 */
336
	public function getCustomer(): ?CustomerInterface
337
	{
338
		return $this->customer;
339
	}
340
341
	/**
342
	 * Set customer
343
	 *
344
	 * @param  null|CustomerInterface  $customer  Customer
345
	 *
346
	 * @return  CheckoutInterface
347
	 */
348 3
	public function setCustomer(?CustomerInterface $customer): CheckoutInterface
349
	{
350 3
		$this->customer = $customer;
351
352 3
		return $this;
353
	}
354
355
	/**
356
	 * Get card
357
	 *
358
     * @return  null|PaymentInstrumentInterface
359
	 */
360
    public function getCard(): ?PaymentInstrumentInterface
361
	{
362
		return $this->card;
363
	}
364
365
	/**
366
	 * Set card
367
	 *
368
     * @param  null|PaymentInstrumentInterface $card
369
	 *
370
	 * @return  CheckoutInterface
371
	 */
372
    public function setCard(?PaymentInstrumentInterface $card): CheckoutInterface
373
	{
374
		$this->card = $card;
375
376
		return $this;
377
	}
378
379
	/**
380
	 * @return mixed
381
	 */
382 2
	public function getType():? string
383
	{
384 2
		return $this->type;
385
	}
386
387
	/**
388
	 * @param mixed $type
389
	 * @return CheckoutInterface
390
	 */
391
	public function setType(?string $type = null): CheckoutInterface
392
	{
393
		$this->type = $type;
394
395
		return $this;
396
	}
397
398
    public function getInstallments(): string
399
    {
400
        return $this->installments;
401
    }
402
403
	public function setInstallments(?string $installments): CheckoutInterface{
404
		$this->installments = $installments;
405
		return $this;
406
	}
407
408
}
409