|
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
|
|
|
final class CheckoutInstallments extends Model |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @param array $data |
|
14
|
|
|
* array de dados do CheckoutInstallments. |
|
15
|
|
|
* |
|
16
|
|
|
* + [`'amount'`] float (opcional). |
|
17
|
|
|
* + [`'max_installment'`] int (opcional). |
|
18
|
|
|
* + [`'installments_without_interest'`] int (opcional). |
|
19
|
|
|
* + [`'installment_min_amount'`] float (opcional). |
|
20
|
|
|
* + [`'installment_tax'`] float (opcional). |
|
21
|
|
|
*/ |
|
22
|
|
|
public function __construct(?array $data = []) |
|
23
|
|
|
{ |
|
24
|
|
|
parent::__construct($data); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function schema(SchemaBuilder $schema): Schema |
|
28
|
|
|
{ |
|
29
|
|
|
$schema->float('amount')->nullable(); |
|
30
|
|
|
$schema->int('max_installment')->nullable(); |
|
31
|
|
|
$schema->int('installments_without_interest')->nullable(); |
|
32
|
|
|
$schema->float('installment_min_amount')->nullable(); |
|
33
|
|
|
$schema->float('installment_tax')->nullable(); |
|
34
|
|
|
|
|
35
|
|
|
return $schema->build(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
protected function amount(): Mutator |
|
39
|
|
|
{ |
|
40
|
|
|
return new Mutator( |
|
41
|
|
|
null, |
|
42
|
|
|
fn($value, $ctx) => |
|
43
|
|
|
is_null($value) ? $value : |
|
44
|
|
|
( |
|
45
|
|
|
Assert::value(floatval($value))->gte(0)->get() |
|
46
|
|
|
?? $ctx->raise('inválido') |
|
47
|
|
|
) |
|
48
|
|
|
); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
protected function max_installment(): Mutator |
|
52
|
|
|
{ |
|
53
|
|
|
return new Mutator( |
|
54
|
|
|
null, |
|
55
|
|
|
fn($value, $ctx) => |
|
56
|
|
|
is_null($value) ? $value : |
|
57
|
|
|
( |
|
58
|
|
|
Assert::value(intval($value))->gte(0)->get() |
|
59
|
|
|
?? $ctx->raise('inválido') |
|
60
|
|
|
) |
|
61
|
|
|
); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
protected function installments_without_interest(): Mutator |
|
65
|
|
|
{ |
|
66
|
|
|
return new Mutator( |
|
67
|
|
|
null, |
|
68
|
|
|
fn($value, $ctx) => |
|
69
|
|
|
is_null($value) ? $value : |
|
70
|
|
|
( |
|
71
|
|
|
Assert::value(intval($value))->gte(0)->get() |
|
72
|
|
|
?? $ctx->raise('inválido') |
|
73
|
|
|
) |
|
74
|
|
|
); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
protected function installment_min_amount(): Mutator |
|
78
|
|
|
{ |
|
79
|
|
|
return new Mutator( |
|
80
|
|
|
null, |
|
81
|
|
|
fn($value, $ctx) => |
|
82
|
|
|
is_null($value) ? $value : |
|
83
|
|
|
( |
|
84
|
|
|
Assert::value(floatval($value))->gte(0)->get() |
|
85
|
|
|
?? $ctx->raise('inválido') |
|
86
|
|
|
) |
|
87
|
|
|
); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
protected function installment_tax(): Mutator |
|
91
|
|
|
{ |
|
92
|
|
|
return new Mutator( |
|
93
|
|
|
null, |
|
94
|
|
|
fn($value, $ctx) => |
|
95
|
|
|
is_null($value) ? $value : |
|
96
|
|
|
( |
|
97
|
|
|
Assert::value(floatval($value))->gte(0)->get() |
|
98
|
|
|
?? $ctx->raise('inválido') |
|
99
|
|
|
) |
|
100
|
|
|
); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function getAmount(): ?float |
|
104
|
|
|
{ |
|
105
|
|
|
return $this->get('amount'); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function setAmount(?float $amount = null): self |
|
109
|
|
|
{ |
|
110
|
|
|
$this->set('amount', $amount); |
|
111
|
|
|
return $this; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
public function getMaxInstallment(): ?int |
|
115
|
|
|
{ |
|
116
|
|
|
return $this->get('max_installment'); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function setMaxInstallment(?int $max_installment = null): self |
|
120
|
|
|
{ |
|
121
|
|
|
$this->set('max_installment', $max_installment); |
|
122
|
|
|
return $this; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
public function getInstallmentsWithoutInterest(): ?int |
|
126
|
|
|
{ |
|
127
|
|
|
return $this->get('installments_without_interest'); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
public function setInstallmentsWithoutInterest(?int $installments_without_interest = null): self |
|
131
|
|
|
{ |
|
132
|
|
|
$this->set('installments_without_interest', $installments_without_interest); |
|
133
|
|
|
return $this; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
public function getInstallmentMinAmount(): ?float |
|
137
|
|
|
{ |
|
138
|
|
|
return $this->get('installment_min_amount'); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
public function setInstallmentMinAmount(?float $installment_min_amount = null): self |
|
142
|
|
|
{ |
|
143
|
|
|
$this->set('installment_min_amount', $installment_min_amount); |
|
144
|
|
|
return $this; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
public function getInstallmentTax(): ?float |
|
148
|
|
|
{ |
|
149
|
|
|
return $this->get('installment_tax'); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
public function setInstallmentTax(?float $installment_tax = null): self |
|
153
|
|
|
{ |
|
154
|
|
|
$this->set('installment_tax', $installment_tax); |
|
155
|
|
|
return $this; |
|
156
|
|
|
} |
|
157
|
|
|
} |