Completed
Pull Request — master (#12)
by Romain
06:58
created

Payment::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 5
crap 1
1
<?php
2
namespace Kerox\Messenger\Model\Callback;
3
4
use Kerox\Messenger\Model\Callback\Payment\PaymentCredential;
5
use Kerox\Messenger\Model\Callback\Payment\RequestedUserInfo;
6
use Kerox\Messenger\Model\Common\Address;
7
8
class Payment
9
{
10
11
    /**
12
     * @var string
13
     */
14
    protected $payload;
15
16
    /**
17
     * @var \Kerox\Messenger\Model\Callback\Payment\RequestedUserInfo
18
     */
19
    protected $requestedUserInfo;
20
21
    /**
22
     * @var \Kerox\Messenger\Model\Callback\Payment\PaymentCredential
23
     */
24
    protected $paymentCredential;
25
26
    /**
27
     * @var array
28
     */
29
    protected $amount;
30
31
    /**
32
     * @var string
33
     */
34
    protected $shippingOptionId;
35
36
    /**
37
     * Payment constructor.
38
     *
39
     * @param string $payload
40
     * @param \Kerox\Messenger\Model\Callback\Payment\RequestedUserInfo $requestedUserInfo
41
     * @param \Kerox\Messenger\Model\Callback\Payment\PaymentCredential $paymentCredential
42
     * @param array $amount
43
     * @param string $shippingOptionId
44
     */
45 5
    public function __construct(
46
        string $payload,
47
        RequestedUserInfo $requestedUserInfo,
48
        PaymentCredential $paymentCredential,
49
        array $amount,
50
        string $shippingOptionId
51
    ) {
52 5
        $this->payload = $payload;
53 5
        $this->requestedUserInfo = $requestedUserInfo;
54 5
        $this->paymentCredential = $paymentCredential;
55 5
        $this->amount = $amount;
56 5
        $this->shippingOptionId = $shippingOptionId;
57 5
    }
58
59
    /**
60
     * @return string
61
     */
62 1
    public function getPayload(): string
63
    {
64 1
        return $this->payload;
65
    }
66
67
    /**
68
     * @return \Kerox\Messenger\Model\Callback\Payment\RequestedUserInfo
69
     */
70 2
    public function getRequestedUserInfo(): RequestedUserInfo
71
    {
72 2
        return $this->requestedUserInfo;
73
    }
74
75
    /**
76
     * @return \Kerox\Messenger\Model\Common\Address
77
     */
78 2
    public function getShippingAddress(): Address
79
    {
80 2
        return $this->requestedUserInfo->getShippingAddress();
81
    }
82
83
    /**
84
     * @return \Kerox\Messenger\Model\Callback\Payment\PaymentCredential
85
     */
86 2
    public function getPaymentCredential(): PaymentCredential
87
    {
88 2
        return $this->paymentCredential;
89
    }
90
91
    /**
92
     * @return null|string
93
     */
94 1
    public function getCurrency()
95
    {
96 1
        return $this->amount['currency'] ?? null;
97
    }
98
99
    /**
100
     * @return null|string
101
     */
102 1
    public function getAmount()
103
    {
104 1
        return $this->amount['amount'] ?? null;
105
    }
106
107
    /**
108
     * @return string
109
     */
110 1
    public function getShippingOptionId(): string
111
    {
112 1
        return $this->shippingOptionId;
113
    }
114
115
    /**
116
     * @param array $payload
117
     * @return static
118
     */
119 5
    public static function create(array $payload)
120
    {
121 5
        $requestedUserInfo = RequestedUserInfo::create($payload['requested_user_info']);
122 5
        $paymentCredential = PaymentCredential::create($payload['payment_credential']);
123
124 5
        return new static($payload['payload'], $requestedUserInfo, $paymentCredential, $payload['amount'], $payload['shipping_option_id']);
125
    }
126
}
127