1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ipag\Sdk\Model; |
4
|
|
|
|
5
|
|
|
use Ipag\Sdk\Model\Schema\Mutator; |
6
|
|
|
use Ipag\Sdk\Model\Schema\Schema; |
7
|
|
|
use Ipag\Sdk\Model\Schema\SchemaBuilder; |
8
|
|
|
use Kubinyete\Assertation\Assert; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Card Class |
12
|
|
|
* |
13
|
|
|
* Classe responsável por representar o recurso Card. |
14
|
|
|
* |
15
|
|
|
*/ |
16
|
|
|
final class Card extends Model |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @param array $data |
21
|
|
|
* array de dados do Card. |
22
|
|
|
* |
23
|
|
|
* + [`'holderName'`] string. |
24
|
|
|
* + [`'number'`] string. |
25
|
|
|
* + [`'expiryMonth'`] string. |
26
|
|
|
* + [`'expiryYear'`] string. |
27
|
|
|
* + [`'cvv'`] string. |
28
|
|
|
*/ |
29
|
|
|
public function __construct(?array $data = []) |
30
|
|
|
{ |
31
|
|
|
parent::__construct($data); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function schema(SchemaBuilder $schema): Schema |
35
|
|
|
{ |
36
|
|
|
$schema->string('holderName')->nullable(); |
37
|
|
|
$schema->string('number')->nullable(); |
38
|
|
|
$schema->string('expiryMonth')->nullable(); |
39
|
|
|
$schema->string('expiryYear')->nullable(); |
40
|
|
|
$schema->string('cvv')->nullable(); |
41
|
|
|
$schema->string('token')->nullable(); |
42
|
|
|
$schema->bool('tokenize')->nullable(); |
43
|
|
|
|
44
|
|
|
return $schema->build(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
protected function number(): Mutator |
48
|
|
|
{ |
49
|
|
|
return new Mutator(null, fn($value) => Assert::value($value)->asDigits()->get()); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
protected function expiryMonth(): Mutator |
53
|
|
|
{ |
54
|
|
|
return new Mutator( |
55
|
|
|
null, |
56
|
|
|
fn($value, $ctx) => |
57
|
|
|
is_null($value) ? $value |
58
|
|
|
: |
59
|
|
|
( |
60
|
|
|
str_pad( |
61
|
|
|
Assert::value(intval($value))->between(1, 12)->get() |
|
|
|
|
62
|
|
|
?? $ctx->raise('inválido (informe um valor de 01 à 12)') |
63
|
|
|
, |
64
|
|
|
2, |
65
|
|
|
'0', |
66
|
|
|
STR_PAD_LEFT |
67
|
|
|
) |
68
|
|
|
) |
69
|
|
|
|
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
protected function expiryYear(): Mutator |
74
|
|
|
{ |
75
|
|
|
return new Mutator( |
76
|
|
|
null, |
77
|
|
|
fn($value, $ctx) => |
78
|
|
|
is_null($value) ? $value : |
79
|
|
|
( |
80
|
|
|
Assert::value($value)->asDigits()->lbetween(2, 2)->or()->lbetween(4, 4)->get() ?? $ctx->raise('inválido (informe um valor numérico de 2 ou 4 dígitos)') |
81
|
|
|
) |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
protected function cvv(): Mutator |
86
|
|
|
{ |
87
|
|
|
return new Mutator( |
88
|
|
|
null, |
89
|
|
|
fn($value, $ctx) => |
90
|
|
|
is_null($value) ? $value : |
91
|
|
|
( |
92
|
|
|
Assert::value($value)->asDigits()->lbetween(3, 3)->or()->lbetween(4, 4)->get() ?? $ctx->raise('inválido (informe um valor numérico de 3 ou 4 dígitos)') |
93
|
|
|
) |
94
|
|
|
); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Retorna o valor da propriedade `holderName`. |
99
|
|
|
* |
100
|
|
|
* @return string|null |
101
|
|
|
*/ |
102
|
|
|
public function getHolderName(): ?string |
103
|
|
|
{ |
104
|
|
|
return $this->get('holderName'); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Seta o valor da propriedade `holderName`. |
109
|
|
|
* |
110
|
|
|
* @param string|null $holderName |
111
|
|
|
* @return self |
112
|
|
|
*/ |
113
|
|
|
public function setHolderName(?string $holderName = null): self |
114
|
|
|
{ |
115
|
|
|
$this->set('holderName', $holderName); |
116
|
|
|
return $this; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Retorna o valor da propriedade `number`. |
121
|
|
|
* |
122
|
|
|
* @return string|null |
123
|
|
|
*/ |
124
|
|
|
public function getNumber(): ?string |
125
|
|
|
{ |
126
|
|
|
return $this->get('number'); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Seta o valor da propriedade `number`. |
131
|
|
|
* |
132
|
|
|
* @param string|null $number |
133
|
|
|
* @return self |
134
|
|
|
*/ |
135
|
|
|
public function setNumber(?string $number = null): self |
136
|
|
|
{ |
137
|
|
|
$this->set('number', $number); |
138
|
|
|
return $this; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Retorna o valor da propriedade `expiryMonth`. |
144
|
|
|
* |
145
|
|
|
* @return string|null |
146
|
|
|
*/ |
147
|
|
|
public function getExpiryMonth(): ?string |
148
|
|
|
{ |
149
|
|
|
return $this->get('expiryMonth'); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Seta o valor da propriedade `expiryMonth`. |
154
|
|
|
* |
155
|
|
|
* @param string|null $expiryMonth |
156
|
|
|
* @return self |
157
|
|
|
*/ |
158
|
|
|
public function setExpiryMonth(?string $expiryMonth = null): self |
159
|
|
|
{ |
160
|
|
|
$this->set('expiryMonth', $expiryMonth); |
161
|
|
|
return $this; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Retorna o valor da propriedade `expiryYear`. |
166
|
|
|
* |
167
|
|
|
* @return string|null |
168
|
|
|
*/ |
169
|
|
|
public function getExpiryYear(): ?string |
170
|
|
|
{ |
171
|
|
|
return $this->get('expiryYear'); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Seta o valor da propriedade `expiryYear`. |
176
|
|
|
* |
177
|
|
|
* @param string|null $expiryYear |
178
|
|
|
* @return self |
179
|
|
|
*/ |
180
|
|
|
public function setExpiryYear(?string $expiryYear = null): self |
181
|
|
|
{ |
182
|
|
|
$this->set('expiryYear', $expiryYear); |
183
|
|
|
return $this; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Retorna o valor da propriedade `cvv`. |
188
|
|
|
* |
189
|
|
|
* @return string|null |
190
|
|
|
*/ |
191
|
|
|
public function getCvv(): ?string |
192
|
|
|
{ |
193
|
|
|
return $this->get('cvv'); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* Seta o valor da propriedade `cvv`. |
198
|
|
|
* |
199
|
|
|
* @param string|null $cvv |
200
|
|
|
* @return self |
201
|
|
|
*/ |
202
|
|
|
public function setCvv(?string $cvv = null): self |
203
|
|
|
{ |
204
|
|
|
$this->set('cvv', $cvv); |
205
|
|
|
return $this; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* Retorna o valor da propriedade `token`. |
210
|
|
|
* |
211
|
|
|
* @return string|null |
212
|
|
|
*/ |
213
|
|
|
public function getToken(): ?string |
214
|
|
|
{ |
215
|
|
|
return $this->get('token'); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* Seta o valor da propriedade `token`. |
220
|
|
|
* |
221
|
|
|
* @param string|null $token |
222
|
|
|
* @return self |
223
|
|
|
*/ |
224
|
|
|
public function setToken(?string $token = null): self |
225
|
|
|
{ |
226
|
|
|
$this->set('token', $token); |
227
|
|
|
return $this; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* Retorna o valor da propriedade `tokenize`. |
232
|
|
|
* |
233
|
|
|
* @return boolean|null |
234
|
|
|
*/ |
235
|
|
|
public function getTokenize(): ?bool |
236
|
|
|
{ |
237
|
|
|
return $this->get('tokenize'); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* Seta o valor da propriedade `tokenize`. |
242
|
|
|
* |
243
|
|
|
* @param boolean|null $tokenize |
244
|
|
|
* @return self |
245
|
|
|
*/ |
246
|
|
|
public function setTokenize(?bool $tokenize = null): self |
247
|
|
|
{ |
248
|
|
|
$this->set('tokenize', $tokenize); |
249
|
|
|
return $this; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
} |