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
|
|
|
* Get token |
58
|
|
|
* |
59
|
|
|
* @return string |
60
|
|
|
*/ |
61
|
1 |
|
public function getToken():? string |
62
|
|
|
{ |
63
|
1 |
|
return $this->token; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Set token |
68
|
|
|
* |
69
|
|
|
* @param string $token Token |
70
|
|
|
* |
71
|
|
|
* @return PaymentInstrumentInterface |
72
|
|
|
*/ |
73
|
2 |
|
public function setToken(?string $token): PaymentInstrumentInterface |
74
|
|
|
{ |
75
|
2 |
|
$this->token = $token; |
76
|
|
|
|
77
|
2 |
|
return $this; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Get active - state of token |
82
|
|
|
* |
83
|
|
|
* @return bool |
84
|
|
|
*/ |
85
|
|
|
public function getActive():? bool |
86
|
|
|
{ |
87
|
|
|
return $this->active; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Set active - state of token |
92
|
|
|
* |
93
|
|
|
* @param bool $active Active - state of token |
94
|
|
|
* |
95
|
|
|
* @return PaymentInstrumentInterface |
96
|
|
|
*/ |
97
|
2 |
|
public function setActive(?bool $active): PaymentInstrumentInterface |
98
|
|
|
{ |
99
|
2 |
|
$this->active = $active; |
100
|
|
|
|
101
|
2 |
|
return $this; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Get type of token |
106
|
|
|
* |
107
|
|
|
* @return string |
108
|
|
|
*/ |
109
|
|
|
public function getType():? string |
110
|
|
|
{ |
111
|
|
|
return $this->type; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Set type of token |
116
|
|
|
* |
117
|
|
|
* @param string $type Type of token |
118
|
|
|
* |
119
|
|
|
* @return PaymentInstrumentInterface |
120
|
|
|
*/ |
121
|
2 |
|
public function setType(?string $type): PaymentInstrumentInterface |
122
|
|
|
{ |
123
|
2 |
|
$this->type = $type; |
124
|
|
|
|
125
|
2 |
|
return $this; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Get last 4 digits of card |
130
|
|
|
* |
131
|
|
|
* @return string |
132
|
|
|
*/ |
133
|
|
|
public function getLast4Digits():? string |
134
|
|
|
{ |
135
|
|
|
return $this->last4Digits; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Set last 4 digits of card |
140
|
|
|
* |
141
|
|
|
* @param string $last4Digits Last 4 digits of card |
142
|
|
|
* |
143
|
|
|
* @return PaymentInstrumentInterface |
144
|
|
|
*/ |
145
|
2 |
|
public function setLast4Digits(?string $last4Digits): PaymentInstrumentInterface |
146
|
|
|
{ |
147
|
2 |
|
$this->last4Digits = $last4Digits; |
148
|
|
|
|
149
|
2 |
|
return $this; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Get PaymentInstrument Schema |
154
|
|
|
* |
155
|
|
|
* @return string |
156
|
|
|
*/ |
157
|
|
|
public function getCardType():? string |
158
|
|
|
{ |
159
|
|
|
return $this->cardSchema; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Set PaymentInstrument Schema |
164
|
|
|
* |
165
|
|
|
* @param string $cardSchema PaymentInstrument Schema |
166
|
|
|
* |
167
|
|
|
* @return PaymentInstrumentInterface |
168
|
|
|
*/ |
169
|
2 |
|
public function setCardType(?string $cardSchema): PaymentInstrumentInterface |
170
|
|
|
{ |
171
|
2 |
|
$this->cardSchema = $cardSchema; |
172
|
|
|
|
173
|
2 |
|
return $this; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* Get PaymentInstrument array |
178
|
|
|
* e.g.: [ |
179
|
|
|
* 'last_4_digits' => '0000', |
180
|
|
|
* 'type' => 'PaymentInstrument Schema' |
181
|
|
|
* ] |
182
|
|
|
* |
183
|
|
|
* @see http://docs.sumup.com/rest-api/checkouts-api/#customers-payment-instruments-post |
184
|
|
|
* @return array |
185
|
|
|
*/ |
186
|
|
|
public function getCard():? array |
187
|
|
|
{ |
188
|
|
|
return [ |
189
|
|
|
'last_4_digits' => $this->getLast4Digits(), |
190
|
|
|
'type' => $this->getCardType(), |
191
|
|
|
]; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Set PaymentInstrument array |
196
|
|
|
* |
197
|
|
|
* @see http://docs.sumup.com/rest-api/checkouts-api/#customers-payment-instruments-post |
198
|
|
|
* @param array $data |
199
|
|
|
* @return PaymentInstrumentInterface |
200
|
|
|
*/ |
201
|
2 |
|
public function setCard(?array $data): PaymentInstrumentInterface |
202
|
|
|
{ |
203
|
2 |
|
$this->setLast4Digits($data['last_4_digits']); |
204
|
2 |
|
$this->setCardType($data['type']); |
205
|
2 |
|
return $this; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* @return bool |
210
|
|
|
*/ |
211
|
|
|
function isActive(): bool |
|
|
|
|
212
|
|
|
{ |
213
|
|
|
return $this->active??false; |
214
|
|
|
} |
215
|
|
|
} |
216
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.