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
|
|
|
* InstallmentSetting Class |
12
|
|
|
* |
13
|
|
|
* Classe responsável por representar o recurso Installment Settings. |
14
|
|
|
* |
15
|
|
|
*/ |
16
|
|
|
final class InstallmentSetting extends Model |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @param mixed[] $data |
20
|
|
|
* array de dados do Split Rules. |
21
|
|
|
* |
22
|
|
|
* + [`'max_installments'`] int. |
23
|
|
|
* + [`'min_installment_value'`] float. |
24
|
|
|
* + [`'interest'`] float. |
25
|
|
|
* + [`'interest_free_installments'`] int. |
26
|
|
|
* + [`'fixed_installment'`] int. |
27
|
|
|
* + [`'payment_method'`] 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->int('max_installments')->nullable(); // 1 ~ 12 |
37
|
|
|
$schema->float('min_installment_value')->nullable(); |
38
|
|
|
$schema->float('interest')->nullable(); |
39
|
|
|
$schema->int('interest_free_installments')->nullable(); // 1 ~ 12 |
40
|
|
|
$schema->int('fixed_installment')->nullable(); // 1 ~ 12 |
41
|
|
|
$schema->string('payment_method')->nullable(); // all, creditcard, boleto, transfer, pix |
42
|
|
|
|
43
|
|
|
return $schema->build(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
protected function max_installments(): Mutator |
47
|
|
|
{ |
48
|
|
|
return new Mutator( |
49
|
|
|
null, |
50
|
|
|
fn($value, $ctx) => |
51
|
|
|
is_null($value) ? $value : |
52
|
|
|
( |
53
|
|
|
Assert::value(intval($value))->gt(0)->get() |
54
|
|
|
?? $ctx->raise('inválido (informe um valor de 1 à 12)') |
55
|
|
|
) |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
protected function min_installment_value(): Mutator |
60
|
|
|
{ |
61
|
|
|
return new Mutator( |
62
|
|
|
null, |
63
|
|
|
fn($value, $ctx) => |
64
|
|
|
is_null($value) ? $value : |
65
|
|
|
( |
66
|
|
|
Assert::value(floatval($value))->gte(0)->get() |
67
|
|
|
?? $ctx->raise('inválido') |
68
|
|
|
) |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
protected function interest(): Mutator |
73
|
|
|
{ |
74
|
|
|
return new Mutator( |
75
|
|
|
null, |
76
|
|
|
fn($value, $ctx) => |
77
|
|
|
is_null($value) ? $value : |
78
|
|
|
( |
79
|
|
|
Assert::value(floatval($value))->gte(0)->get() |
80
|
|
|
?? $ctx->raise('inválido') |
81
|
|
|
) |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
protected function interest_free_installments(): Mutator |
86
|
|
|
{ |
87
|
|
|
return new Mutator( |
88
|
|
|
null, |
89
|
|
|
fn($value, $ctx) => |
90
|
|
|
is_null($value) ? $value : |
91
|
|
|
( |
92
|
|
|
Assert::value(intval($value))->gt(0)->get() |
93
|
|
|
?? $ctx->raise('inválido (informe um valor de 1 à 12)') |
94
|
|
|
) |
95
|
|
|
); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
protected function fixed_installment(): Mutator |
99
|
|
|
{ |
100
|
|
|
return new Mutator( |
101
|
|
|
null, |
102
|
|
|
fn($value, $ctx) => |
103
|
|
|
is_null($value) ? $value : |
104
|
|
|
( |
105
|
|
|
Assert::value(intval($value))->gt(0)->get() |
106
|
|
|
?? $ctx->raise('inválido (informe um valor de 1 à 12)') |
107
|
|
|
) |
108
|
|
|
); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Retorna o valor da propriedade `maxInstallments`. |
113
|
|
|
* |
114
|
|
|
* @return integer|null |
115
|
|
|
*/ |
116
|
|
|
public function getMaxInstallments(): ?int |
117
|
|
|
{ |
118
|
|
|
return $this->get('max_installments'); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Seta o valor da propriedade `maxInstallments`. |
123
|
|
|
* |
124
|
|
|
* @param integer|null $maxInstallments |
125
|
|
|
* @return self |
126
|
|
|
*/ |
127
|
|
|
public function setMaxInstallments(?int $maxInstallments = null): self |
128
|
|
|
{ |
129
|
|
|
$this->set('max_installments', $maxInstallments); |
130
|
|
|
return $this; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Retorna o valor da propriedade `minInstallmentValue`. |
135
|
|
|
* |
136
|
|
|
* @return float|null |
137
|
|
|
*/ |
138
|
|
|
public function getMinInstallmentValue(): ?float |
139
|
|
|
{ |
140
|
|
|
return $this->get('min_installment_value'); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Seta o valor da propriedade `minInstallmentValue`. |
145
|
|
|
* |
146
|
|
|
* @param float|null $minInstallmentValue |
147
|
|
|
* @return self |
148
|
|
|
*/ |
149
|
|
|
public function setMinInstallmentValue(?float $minInstallmentValue = null): self |
150
|
|
|
{ |
151
|
|
|
$this->set('min_installment_value', $minInstallmentValue); |
152
|
|
|
return $this; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Retorna o valor da propriedade `interest`. |
157
|
|
|
* |
158
|
|
|
* @return float|null |
159
|
|
|
*/ |
160
|
|
|
public function getInterest(): ?float |
161
|
|
|
{ |
162
|
|
|
return $this->get('interest'); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Seta o valor da propriedade `interest`. |
167
|
|
|
* |
168
|
|
|
* @param float|null $interest |
169
|
|
|
* @return self |
170
|
|
|
*/ |
171
|
|
|
public function setInterest(?float $interest = null): self |
172
|
|
|
{ |
173
|
|
|
$this->set('interest', $interest); |
174
|
|
|
return $this; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* Retorna o valor da propriedade `interestFreeInstallments`. |
179
|
|
|
* |
180
|
|
|
* @return integer|null |
181
|
|
|
*/ |
182
|
|
|
public function getInterestFreeInstallments(): ?int |
183
|
|
|
{ |
184
|
|
|
return $this->get('interest_free_installments'); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* Seta o valor da propriedade `interestFreeInstallments`. |
189
|
|
|
* |
190
|
|
|
* @param integer|null $interestFreeInstallments |
191
|
|
|
* @return self |
192
|
|
|
*/ |
193
|
|
|
public function setInterestFreeInstallments(?int $interestFreeInstallments = null): self |
194
|
|
|
{ |
195
|
|
|
$this->set('interest_free_installments', $interestFreeInstallments); |
196
|
|
|
return $this; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* Retorna o valor da propriedade `fixedInstallment`. |
201
|
|
|
* |
202
|
|
|
* @return integer|null |
203
|
|
|
*/ |
204
|
|
|
public function getFixedInstallment(): ?int |
205
|
|
|
{ |
206
|
|
|
return $this->get('fixed_installment'); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* Seta o valor da propriedade `fixedInstallment`. |
211
|
|
|
* |
212
|
|
|
* @param integer|null $fixedInstallment |
213
|
|
|
* @return self |
214
|
|
|
*/ |
215
|
|
|
public function setFixedInstallment(?int $fixedInstallment = null): self |
216
|
|
|
{ |
217
|
|
|
$this->set('fixed_installment', $fixedInstallment); |
218
|
|
|
return $this; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* Retorna o valor da propriedade `paymentMethod`. |
223
|
|
|
* |
224
|
|
|
* @return string|null |
225
|
|
|
*/ |
226
|
|
|
public function getPaymentMethod(): ?string |
227
|
|
|
{ |
228
|
|
|
return $this->get('payment_method'); |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* Seta o valor da propriedade `paymentMethod`. |
233
|
|
|
* |
234
|
|
|
* @param string|null $paymentMethod |
235
|
|
|
* @return self |
236
|
|
|
*/ |
237
|
|
|
public function setPaymentMethod(?string $paymentMethod = null): self |
238
|
|
|
{ |
239
|
|
|
$this->set('payment_method', $paymentMethod); |
240
|
|
|
return $this; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
} |