|
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
|
|
|
* Payment Class |
|
12
|
|
|
* |
|
13
|
|
|
* Classe responsável por representar o recurso Payment. |
|
14
|
|
|
* |
|
15
|
|
|
*/ |
|
16
|
|
|
final class Payment extends Model |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @param array $data |
|
20
|
|
|
* array de dados do Payment. |
|
21
|
|
|
* |
|
22
|
|
|
* + [`'type'`] string. |
|
23
|
|
|
* + [`'method'`] string. |
|
24
|
|
|
* + [`'installments'`] int. |
|
25
|
|
|
* + [`'capture'`] bool. |
|
26
|
|
|
* + [`'fraud_analysis'`] bool. |
|
27
|
|
|
* + [`'softdescriptor'`] string. |
|
28
|
|
|
* + [`'pix_expires_in'`] int. |
|
29
|
|
|
* |
|
30
|
|
|
* + [`'card'`] array (opcional) dos dados do Payment Card. |
|
31
|
|
|
* +   [`'holder'`] string. |
|
32
|
|
|
* +   [`'number'`] string. |
|
33
|
|
|
* +   [`'expiry_month'`] string. |
|
34
|
|
|
* +   [`'expiry_year'`] string. |
|
35
|
|
|
* +   [`'cvv'`] string. |
|
36
|
|
|
* +   [`'token'`] string. |
|
37
|
|
|
* +   [`'tokenize'`] bool. |
|
38
|
|
|
* |
|
39
|
|
|
* + [`'boleto'`] array (opcional) dos dados do Boleto. |
|
40
|
|
|
* +   [`'due_date'`] string (opcional) {Formato: `Y-m-d H:i:s`}. |
|
41
|
|
|
* +   [`'instructions'`] string[] (opcional) dos dados da instruções. |
|
42
|
|
|
*/ |
|
43
|
|
|
public function __construct(?array $data = []) |
|
44
|
|
|
{ |
|
45
|
|
|
parent::__construct($data); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function schema(SchemaBuilder $schema): Schema |
|
49
|
|
|
{ |
|
50
|
|
|
$schema->string('type')->nullable(); // card, boleto ou pix |
|
51
|
|
|
$schema->string('method')->nullable(); |
|
52
|
|
|
$schema->int('installments')->nullable(); // 1 ~ 12 |
|
53
|
|
|
$schema->bool('capture')->nullable(); |
|
54
|
|
|
$schema->bool('fraud_analysis')->nullable(); |
|
55
|
|
|
$schema->string('softdescriptor')->nullable(); |
|
56
|
|
|
$schema->int('pix_expires_in')->nullable(); |
|
57
|
|
|
|
|
58
|
|
|
$schema->has('card', PaymentCard::class)->nullable(); |
|
59
|
|
|
$schema->has('boleto', Boleto::class)->nullable(); |
|
60
|
|
|
|
|
61
|
|
|
return $schema->build(); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
protected function installments(): Mutator |
|
65
|
|
|
{ |
|
66
|
|
|
return new Mutator( |
|
67
|
|
|
null, |
|
68
|
|
|
fn($value, $ctx) => |
|
69
|
|
|
is_null($value) ? $value : |
|
70
|
|
|
( |
|
71
|
|
|
Assert::value(intval($value))->gt(0)->get() |
|
72
|
|
|
?? $ctx->raise('inválido (informe um valor de 1 à 12)') |
|
73
|
|
|
) |
|
74
|
|
|
); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Retorna o valor da propriedade `type`. |
|
79
|
|
|
* |
|
80
|
|
|
* @return string|null |
|
81
|
|
|
*/ |
|
82
|
|
|
public function getType(): ?string |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->get('type'); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Seta o valor da propriedade `type`. |
|
89
|
|
|
* |
|
90
|
|
|
* @param string|null $type |
|
91
|
|
|
* @return self |
|
92
|
|
|
*/ |
|
93
|
|
|
public function setType(?string $type = null): self |
|
94
|
|
|
{ |
|
95
|
|
|
$this->set('type', $type); |
|
96
|
|
|
return $this; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Retorna o valor da propriedade `method`. |
|
101
|
|
|
* |
|
102
|
|
|
* @return string|null |
|
103
|
|
|
*/ |
|
104
|
|
|
public function getMethod(): ?string |
|
105
|
|
|
{ |
|
106
|
|
|
return $this->get('method'); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Seta o valor da propriedade `method`. |
|
111
|
|
|
* |
|
112
|
|
|
* @param string|null $method |
|
113
|
|
|
* @return self |
|
114
|
|
|
*/ |
|
115
|
|
|
public function setMethod(?string $method = null): self |
|
116
|
|
|
{ |
|
117
|
|
|
$this->set('method', $method); |
|
118
|
|
|
return $this; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Retorna o valor da propriedade `installments`. |
|
123
|
|
|
* |
|
124
|
|
|
* @return integer|null |
|
125
|
|
|
*/ |
|
126
|
|
|
public function getInstallments(): ?int |
|
127
|
|
|
{ |
|
128
|
|
|
return $this->get('installments'); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Seta o valor da propriedade `installments`. |
|
133
|
|
|
* |
|
134
|
|
|
* @param integer|null $installments |
|
135
|
|
|
* @return self |
|
136
|
|
|
*/ |
|
137
|
|
|
public function setInstallments(?int $installments = null): self |
|
138
|
|
|
{ |
|
139
|
|
|
$this->set('installments', $installments); |
|
140
|
|
|
return $this; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* Retorna o valor da propriedade `capture`. |
|
145
|
|
|
* |
|
146
|
|
|
* @return boolean|null |
|
147
|
|
|
*/ |
|
148
|
|
|
public function getCapture(): ?bool |
|
149
|
|
|
{ |
|
150
|
|
|
return $this->get('capture'); |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* Seta o valor da propriedade `capture`. |
|
155
|
|
|
* |
|
156
|
|
|
* @param boolean|null $capture |
|
157
|
|
|
* @return self |
|
158
|
|
|
*/ |
|
159
|
|
|
public function setCapture(?bool $capture = null): self |
|
160
|
|
|
{ |
|
161
|
|
|
$this->set('capture', $capture); |
|
162
|
|
|
return $this; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* Retorna o valor da propriedade `fraud_analysis`. |
|
167
|
|
|
* |
|
168
|
|
|
* @return boolean|null |
|
169
|
|
|
*/ |
|
170
|
|
|
public function getFraudAnalysis(): ?bool |
|
171
|
|
|
{ |
|
172
|
|
|
return $this->get('fraud_analysis'); |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
/** |
|
176
|
|
|
* Seta o valor da propriedade `fraud_analysis`. |
|
177
|
|
|
* |
|
178
|
|
|
* @param boolean|null $fraudAnalysis |
|
179
|
|
|
* @return self |
|
180
|
|
|
*/ |
|
181
|
|
|
public function setFraudAnalysis(?bool $fraudAnalysis = null): self |
|
182
|
|
|
{ |
|
183
|
|
|
$this->set('fraud_analysis', $fraudAnalysis); |
|
184
|
|
|
return $this; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* Retorna o valor da propriedade `softdescriptor`. |
|
189
|
|
|
* |
|
190
|
|
|
* @return string|null |
|
191
|
|
|
*/ |
|
192
|
|
|
public function getSoftDescriptor(): ?string |
|
193
|
|
|
{ |
|
194
|
|
|
return $this->get('softdescriptor'); |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* Seta o valor da propriedade `softdescriptor`. |
|
199
|
|
|
* |
|
200
|
|
|
* @param string|null $softDescriptor |
|
201
|
|
|
* @return self |
|
202
|
|
|
*/ |
|
203
|
|
|
public function setSoftDescriptor(?string $softDescriptor = null): self |
|
204
|
|
|
{ |
|
205
|
|
|
$this->set('softdescriptor', $softDescriptor); |
|
206
|
|
|
return $this; |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
/** |
|
210
|
|
|
* Retorna o valor da propriedade `pix_expires_in`. |
|
211
|
|
|
* |
|
212
|
|
|
* @return integer|null |
|
213
|
|
|
*/ |
|
214
|
|
|
public function getPixExpiresIn(): ?int |
|
215
|
|
|
{ |
|
216
|
|
|
return $this->get('pix_expires_in'); |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
/** |
|
220
|
|
|
* Seta o valor da propriedade `pix_expires_in`. |
|
221
|
|
|
* |
|
222
|
|
|
* @param integer|null $pixExpiresIn |
|
223
|
|
|
* @return self |
|
224
|
|
|
*/ |
|
225
|
|
|
public function setPixExpiresIn(?int $pixExpiresIn = null): self |
|
226
|
|
|
{ |
|
227
|
|
|
$this->set('pix_expires_in', $pixExpiresIn); |
|
228
|
|
|
return $this; |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
/** |
|
232
|
|
|
* Retorna o objeto `Card` vinculado ao `Payment`. |
|
233
|
|
|
* |
|
234
|
|
|
* @return PaymentCard|null |
|
235
|
|
|
*/ |
|
236
|
|
|
public function getCard(): ?PaymentCard |
|
237
|
|
|
{ |
|
238
|
|
|
return $this->get('card'); |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
/** |
|
242
|
|
|
* Seta o objeto `Card` vinculado ao `Payment`. |
|
243
|
|
|
* |
|
244
|
|
|
* @param PaymentCard|null $card |
|
245
|
|
|
* @return self |
|
246
|
|
|
*/ |
|
247
|
|
|
public function setCard(?PaymentCard $card = null): self |
|
248
|
|
|
{ |
|
249
|
|
|
$this->set('card', $card); |
|
250
|
|
|
return $this; |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
/** |
|
254
|
|
|
* Retorna o objeto `Boleto` vinculado ao `Payment`. |
|
255
|
|
|
* |
|
256
|
|
|
* @return Boleto|null |
|
257
|
|
|
*/ |
|
258
|
|
|
public function getBoleto(): ?Boleto |
|
259
|
|
|
{ |
|
260
|
|
|
return $this->get('boleto'); |
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
|
|
/** |
|
264
|
|
|
* Seta o objeto `Boleto` vinculado ao `Payment`. |
|
265
|
|
|
* |
|
266
|
|
|
* @param Boleto|null $boleto |
|
267
|
|
|
* @return self |
|
268
|
|
|
*/ |
|
269
|
|
|
public function setBoleto(?Boleto $boleto = null): self |
|
270
|
|
|
{ |
|
271
|
|
|
$this->set('boleto', $boleto); |
|
272
|
|
|
return $this; |
|
273
|
|
|
} |
|
274
|
|
|
|
|
275
|
|
|
} |