1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ipag\Sdk\Model; |
4
|
|
|
|
5
|
|
|
use Ipag\Sdk\Model\Schema\Schema; |
6
|
|
|
use Ipag\Sdk\Model\Schema\SchemaBuilder; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Checkout Class |
10
|
|
|
* |
11
|
|
|
* Classe responsável por representar o recurso Checkout. |
12
|
|
|
* |
13
|
|
|
*/ |
14
|
|
|
final class Checkout extends Model |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @param array $data |
18
|
|
|
* array de dados do Checkout. |
19
|
|
|
* |
20
|
|
|
* + [`'seller_id'`] string. |
21
|
|
|
* + [`'expires_in'`] int. |
22
|
|
|
* |
23
|
|
|
* + [`'customer'`] array (opcional) dos dados do Customer. |
24
|
|
|
* +   [`'name'`] string. |
25
|
|
|
* +   [`'tax_receipt'`] string. |
26
|
|
|
* +   [`'email'`] string. |
27
|
|
|
* +   [`'phone'`] string. |
28
|
|
|
* +   [`'birthdate'`] string. |
29
|
|
|
* +   [`'address'`] array (opcional) dos dados do Address. |
30
|
|
|
* +    [`'street'`] string (opcional). |
31
|
|
|
* +    [`'number'`] string (opcional). |
32
|
|
|
* +    [`'district'`] string (opcional). |
33
|
|
|
* +    [`'city'`] string (opcional). |
34
|
|
|
* +    [`'state'`] string (opcional). |
35
|
|
|
* +    [`'zipcode'`] string (opcional). |
36
|
|
|
* |
37
|
|
|
* + [`'installment_setting'`] array (opcional) dos dados do Installment Setting. |
38
|
|
|
* +   [`'max_installments'`] int. |
39
|
|
|
* +   [`'min_installment_value'`] float. |
40
|
|
|
* +   [`'interest'`] float. |
41
|
|
|
* +   [`'interest_free_installments'`] int. |
42
|
|
|
* |
43
|
|
|
* + [`'order'`] array (opcional) dos dados do Order. |
44
|
|
|
* +   [`'order_id'`] string. |
45
|
|
|
* +   [`'amount'`] float. |
46
|
|
|
* +   [`'return_url'`] string. |
47
|
|
|
* +   [`'return_type'`] string. |
48
|
|
|
* |
49
|
|
|
* + [`'products'`] Product[] (opcional) dos dados do Product. |
50
|
|
|
* +   [ |
51
|
|
|
* +    [`'name'`] string |
52
|
|
|
* +    [`'unit_price'`] string |
53
|
|
|
* +    [`'quantity'`] int |
54
|
|
|
* +    [`'sku'`] string |
55
|
|
|
* +    [`'description'`] string |
56
|
|
|
* +   ], [`...`] |
57
|
|
|
* |
58
|
|
|
* + [`'split_rules'`] SplitRules[] (opcional) dos dados do Split Rules. |
59
|
|
|
* +   [ |
60
|
|
|
* +    [`'receiver_id'`] string. |
61
|
|
|
* +    [`'amount'`] float. |
62
|
|
|
* +    [`'percentage'`] float. |
63
|
|
|
* +    [`'charge_processing_fee'`] bool. |
64
|
|
|
* +    [`'seller_id'`] string. |
65
|
|
|
* +    [`'liable'`] bool. |
66
|
|
|
* +    [`'hold_receivables'`] bool. |
67
|
|
|
* +   ], [`...`] |
68
|
|
|
*/ |
69
|
|
|
public function __construct(?array $data = []) |
70
|
|
|
{ |
71
|
|
|
parent::__construct($data); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function schema(SchemaBuilder $schema): Schema |
75
|
|
|
{ |
76
|
|
|
$schema->string('seller_id')->nullable(); |
77
|
|
|
$schema->int('expires_in')->nullable(); |
78
|
|
|
$schema->has('customer', Customer::class)->nullable(); |
79
|
|
|
$schema->has('installment_setting', InstallmentSetting::class)->nullable(); |
80
|
|
|
$schema->has('order', Order::class)->nullable(); |
81
|
|
|
$schema->hasMany('products', Product::class)->default([])->nullable(); |
82
|
|
|
$schema->hasMany('split_rules', SplitRules::class)->default([])->nullable(); |
83
|
|
|
|
84
|
|
|
return $schema->build(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Retorna o objeto `Customer` vinculado ao `Checkout`. |
89
|
|
|
* |
90
|
|
|
* @return Customer|null |
91
|
|
|
*/ |
92
|
|
|
public function getCustomer(): ?Customer |
93
|
|
|
{ |
94
|
|
|
return $this->get('customer'); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Seta o objeto `Customer` vinculado ao `Checkout`. |
99
|
|
|
* |
100
|
|
|
* @param Customer|null $customer |
101
|
|
|
* @return self |
102
|
|
|
*/ |
103
|
|
|
public function setCustomer(?Customer $customer = null): self |
104
|
|
|
{ |
105
|
|
|
$this->set('customer', $customer); |
106
|
|
|
return $this; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Retorna o objeto `InstallmentSetting` vinculado ao `Checkout`. |
111
|
|
|
* |
112
|
|
|
* @return InstallmentSetting|null |
113
|
|
|
*/ |
114
|
|
|
public function getInstallmentSetting(): ?InstallmentSetting |
115
|
|
|
{ |
116
|
|
|
return $this->get('installment_setting'); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Seta o objeto `InstallmentSetting` vinculado ao `Checkout`. |
121
|
|
|
* |
122
|
|
|
* @param InstallmentSetting|null $installmentSetting |
123
|
|
|
* @return self |
124
|
|
|
*/ |
125
|
|
|
public function setInstallmentSetting(?InstallmentSetting $installmentSetting = null): self |
126
|
|
|
{ |
127
|
|
|
$this->set('installment_setting', $installmentSetting); |
128
|
|
|
return $this; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Retorna o objeto `Order` vinculado ao `Checkout`. |
133
|
|
|
* |
134
|
|
|
* @return Order|null |
135
|
|
|
*/ |
136
|
|
|
public function getOrder(): ?Order |
137
|
|
|
{ |
138
|
|
|
return $this->get('order'); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Seta o objeto `Order` vinculado ao `Checkout`. |
143
|
|
|
* |
144
|
|
|
* @param Order|null $order |
145
|
|
|
* @return self |
146
|
|
|
*/ |
147
|
|
|
public function setOrder(?Order $order = null): self |
148
|
|
|
{ |
149
|
|
|
$this->set('order', $order); |
150
|
|
|
return $this; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Retorna os produtos vinculados ao `Checkout`. |
155
|
|
|
* |
156
|
|
|
* @return array|null |
157
|
|
|
*/ |
158
|
|
|
public function getProducts(): ?array |
159
|
|
|
{ |
160
|
|
|
return $this->get('products'); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* Seta os produtos vinculados ao `Checkout`. |
165
|
|
|
* |
166
|
|
|
* @param array $products |
167
|
|
|
* @return self |
168
|
|
|
*/ |
169
|
|
|
public function setProducts(array $products = []): self |
170
|
|
|
{ |
171
|
|
|
$this->set('products', $products); |
172
|
|
|
return $this; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Adiciona um produto ao `Checkout`. |
177
|
|
|
* |
178
|
|
|
* @param Product $product |
179
|
|
|
* @return self |
180
|
|
|
*/ |
181
|
|
|
public function addProduct(Product $product): self |
182
|
|
|
{ |
183
|
|
|
$this->set( |
184
|
|
|
'products', |
185
|
|
|
[ |
186
|
|
|
...$this->get('products'), |
187
|
|
|
$product |
188
|
|
|
] |
189
|
|
|
); |
190
|
|
|
|
191
|
|
|
return $this; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Retorna as regras de split vinculados ao `Checkout`. |
196
|
|
|
* |
197
|
|
|
* @return array|null |
198
|
|
|
*/ |
199
|
|
|
public function getSplitRules(): ?array |
200
|
|
|
{ |
201
|
|
|
return $this->get('split_rules'); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* Seta as regras vinculados ao `Checkout`. |
206
|
|
|
* |
207
|
|
|
* @param array $splitRules |
208
|
|
|
* @return self |
209
|
|
|
*/ |
210
|
|
|
public function setSplitRules(array $splitRules = []): self |
211
|
|
|
{ |
212
|
|
|
$this->set('split_rules', $splitRules); |
213
|
|
|
return $this; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* Adiciona uma regra de split ao `Checkout`. |
218
|
|
|
* |
219
|
|
|
* @param SplitRules $splitRule |
220
|
|
|
* @return self |
221
|
|
|
*/ |
222
|
|
|
public function addSplitRule(SplitRules $splitRule): self |
223
|
|
|
{ |
224
|
|
|
$this->set( |
225
|
|
|
'split_rules', |
226
|
|
|
[ |
227
|
|
|
...$this->get('split_rules'), |
228
|
|
|
$splitRule |
229
|
|
|
] |
230
|
|
|
); |
231
|
|
|
|
232
|
|
|
return $this; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* Retorna o valor da propriedade `seller_id`. |
237
|
|
|
* |
238
|
|
|
* @return string|null |
239
|
|
|
*/ |
240
|
|
|
public function getSellerId(): ?string |
241
|
|
|
{ |
242
|
|
|
return $this->get('seller_id'); |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* Seta o valor da propriedade `seller_id`. |
247
|
|
|
* |
248
|
|
|
* @param string|null $sellerId |
249
|
|
|
* @return self |
250
|
|
|
*/ |
251
|
|
|
public function setSellerId(?string $sellerId = null): self |
252
|
|
|
{ |
253
|
|
|
$this->set('seller_id', $sellerId); |
254
|
|
|
return $this; |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* Retorna o valor da propriedade `expires_in`. |
259
|
|
|
* |
260
|
|
|
* @return integer|null |
261
|
|
|
*/ |
262
|
|
|
public function getExpiresIn(): ?int |
263
|
|
|
{ |
264
|
|
|
return $this->get('expires_in'); |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
/** |
268
|
|
|
* Seta o valor da propriedade `expires_in`. |
269
|
|
|
* |
270
|
|
|
* @param integer|null $expiresIn |
271
|
|
|
* @return self |
272
|
|
|
*/ |
273
|
|
|
public function setExpiresIn(?int $expiresIn = null): self |
274
|
|
|
{ |
275
|
|
|
$this->set('expires_in', $expiresIn); |
276
|
|
|
return $this; |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
} |