PaymentInstrument::setToken()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace BPCI\SumUp\Customer\PaymentInstrument;
4
5
/**
6
 * Class PaymentInstrument
7
 * @package BPCI\SumUp\Customer\PaymentInstrument
8
 */
9
class PaymentInstrument implements PaymentInstrumentInterface
10
{
11
    /**
12
     * Token
13
     *
14
     * @var string
15
     */
16
    protected $token;
17
18
    /**
19
     * Active - state of token
20
     *
21
     * @var bool
22
     */
23
    protected $active;
24
25
    /**
26
     * Type of token
27
     *
28
     * @var string
29
     */
30
    protected $type;
31
32
    /**
33
     * Last 4 digits of card
34
     *
35
     * @var string
36
     */
37
    protected $last4Digits;
38
39
    /**
40
     * Schema card mastercard, visa, etc...
41
     *
42
     * @var string
43
     */
44
    protected $cardSchema;
45
46
    protected $customer;
47
48 2
    public function __construct(?array $data = [])
49
    {
50 2
        $this->setToken($data['token']??null);
51 2
        $this->setActive($data['active']??null);
52 2
        $this->setType($data['type']??null);
53 2
        $this->setCard($data['card']??null);
54 2
    }
55
56
    /**
57
     * Set PaymentInstrument array
58
     *
59
     * @see http://docs.sumup.com/rest-api/checkouts-api/#customers-payment-instruments-post
60
     * @param array $data
61
     * @return PaymentInstrumentInterface
62
     */
63 2
    public function setCard(?array $data): PaymentInstrumentInterface
64
    {
65 2
        $this->setLast4Digits($data['last_4_digits']);
66 2
        $this->setCardType($data['type']);
67
68 2
        return $this;
69
    }
70
71
    /**
72
     * Set PaymentInstrument Schema
73
     *
74
     * @param  string $cardSchema PaymentInstrument Schema
75
     *
76
     * @return PaymentInstrumentInterface
77
     */
78 2
    public function setCardType(?string $cardSchema): PaymentInstrumentInterface
79
    {
80 2
        $this->cardSchema = $cardSchema;
81
82 2
        return $this;
83
    }
84
85
    /**
86
     * Get token
87
     *
88
     * @return  string
89
     */
90 1
    public function getToken():? string
91
    {
92 1
        return $this->token;
93
    }
94
95
    /**
96
     * Set token
97
     *
98
     * @param  string  $token  Token
99
     *
100
     * @return PaymentInstrumentInterface
101
     */
102 2
    public function setToken(?string $token): PaymentInstrumentInterface
103
    {
104 2
        $this->token = $token;
105
106 2
        return $this;
107
    }
108
109
    /**
110
     * Get active - state of token
111
     *
112
     * @return  bool
113
     */
114
    public function getActive():? bool
115
    {
116
        return $this->active;
117
    }
118
119
    /**
120
     * @return bool
121
     */
122
    public function isActive(): bool
123
    {
124
        return $this->active??false;
125
    }
126
127
    /**
128
     * Set active - state of token
129
     *
130
     * @param  bool  $active  Active - state of token
131
     *
132
     * @return PaymentInstrumentInterface
133
     */
134 2
    public function setActive(?bool $active): PaymentInstrumentInterface
135
    {
136 2
        $this->active = $active;
137
138 2
        return $this;
139
    }
140
141
    /**
142
     * Get type of token
143
     *
144
     * @return  string
145
     */
146
    public function getType():? string
147
    {
148
        return $this->type;
149
    }
150
151
    /**
152
     * Set type of token
153
     *
154
     * @param  string  $type  Type of token
155
     *
156
     * @return PaymentInstrumentInterface
157
     */
158 2
    public function setType(?string $type): PaymentInstrumentInterface
159
    {
160 2
        $this->type = $type;
161
162 2
        return $this;
163
    }
164
165
    /**
166
     * Get PaymentInstrument array
167
     * e.g.: [
168
     *     'last_4_digits' => '0000',
169
     *     'type'          => 'PaymentInstrument Schema'
170
     * ]
171
     *
172
     * @see http://docs.sumup.com/rest-api/checkouts-api/#customers-payment-instruments-post
173
     * @return array
174
     */
175
    public function getCard():? array
176
    {
177
        return [
178
            'last_4_digits' => $this->getLast4Digits(),
179
            'type' => $this->getCardType(),
180
        ];
181
    }
182
183
    /**
184
     * Get last 4 digits of card
185
     *
186
     * @return  string
187
     */
188
    public function getLast4Digits():? string
189
    {
190
        return $this->last4Digits;
191
    }
192
193
    /**
194
     * Set last 4 digits of card
195
     *
196
     * @param  string  $last4Digits  Last 4 digits of card
197
     *
198
     * @return PaymentInstrumentInterface
199
     */
200 2
    public function setLast4Digits(?string $last4Digits): PaymentInstrumentInterface
201
    {
202 2
        $this->last4Digits = $last4Digits;
203
204 2
        return $this;
205
    }
206
207
    /**
208
     * Get PaymentInstrument Schema
209
     *
210
     * @return  string
211
     */
212
    public function getCardType():? string
213
    {
214
        return $this->cardSchema;
215
    }
216
}
217