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
|
|
|
* Customer Class |
12
|
|
|
* |
13
|
|
|
* Classe responsável por representar o recurso Customer. |
14
|
|
|
* |
15
|
|
|
* @see https://developers.ipag.com.br/pt-br/customer?id=overview Recurso Customer da API Ipag |
16
|
|
|
*/ |
17
|
|
|
final class Customer extends Model |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @param array $data |
21
|
|
|
* array de dados do Customer. |
22
|
|
|
* |
23
|
|
|
* + [`'name'`] string. |
24
|
|
|
* + [`'is_active'`] bool (opcional). |
25
|
|
|
* + [`'email'`] string (opcional). |
26
|
|
|
* + [`'phone'`] string (opcional). |
27
|
|
|
* + [`'cpf_cnpj'`] string (opcional). |
28
|
|
|
* + [`'business_name'`] string (opcional). |
29
|
|
|
* + [`'birthdate'`] string (opcional) {`Formato: Y-m-d`}. |
30
|
|
|
* + [`'ip'`] string (opcional). |
31
|
|
|
* |
32
|
|
|
* + [`'address'`] array (opcional) dos dados do Address. |
33
|
|
|
* +   [`'street'`] string (opcional). |
34
|
|
|
* +   [`'number'`] string (opcional). |
35
|
|
|
* +   [`'district'`] string (opcional). |
36
|
|
|
* +   [`'city'`] string (opcional). |
37
|
|
|
* +   [`'state'`] string (opcional). |
38
|
|
|
* +   [`'zipcode'`] string (opcional). |
39
|
|
|
* |
40
|
|
|
* + [`'billing_address'`] array (opcional) dos dados do Billing Address. |
41
|
|
|
* +   [`'street'`] string (opcional). |
42
|
|
|
* +   [`'number'`] string (opcional). |
43
|
|
|
* +   [`'district'`] string (opcional). |
44
|
|
|
* +   [`'city'`] string (opcional). |
45
|
|
|
* +   [`'state'`] string (opcional). |
46
|
|
|
* +   [`'zipcode'`] string (opcional). |
47
|
|
|
* |
48
|
|
|
* + [`'shipping_address'`] array (opcional) dos dados do Shipping Address. |
49
|
|
|
* +   [`'street'`] string (opcional). |
50
|
|
|
* +   [`'number'`] string (opcional). |
51
|
|
|
* +   [`'district'`] string (opcional). |
52
|
|
|
* +   [`'city'`] string (opcional). |
53
|
|
|
* +   [`'state'`] string (opcional). |
54
|
|
|
* +   [`'zipcode'`] string (opcional). |
55
|
|
|
* |
56
|
|
|
*/ |
57
|
|
|
public function __construct(?array $data = []) |
58
|
|
|
{ |
59
|
|
|
parent::__construct($data); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
protected function schema(SchemaBuilder $schema): Schema |
63
|
|
|
{ |
64
|
|
|
$schema->string('id')->nullable(); |
65
|
|
|
$schema->string('uuid')->nullable(); |
66
|
|
|
$schema->string('name')->nullable(); |
67
|
|
|
$schema->bool('is_active')->nullable(); |
68
|
|
|
$schema->string('email')->nullable(); |
69
|
|
|
$schema->string('phone')->nullable(); |
70
|
|
|
$schema->string('cpf_cnpj')->nullable(); |
71
|
|
|
$schema->string('tax_receipt')->nullable(); |
72
|
|
|
$schema->string('business_name')->nullable(); |
73
|
|
|
|
74
|
|
|
$schema->string('birthdate')->nullable(); //Y-m-d ou d/m/Y |
75
|
|
|
$schema->string('ip')->nullable(); |
76
|
|
|
|
77
|
|
|
$schema->has('address', Address::class)->nullable(); |
78
|
|
|
$schema->has('billing_address', Address::class)->nullable(); |
79
|
|
|
$schema->has('shipping_address', Address::class)->nullable(); |
80
|
|
|
|
81
|
|
|
return $schema->build(); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Retorna o valor da propriedade id. |
86
|
|
|
* |
87
|
|
|
* @return string|null |
88
|
|
|
*/ |
89
|
|
|
public function getId(): ?string |
90
|
|
|
{ |
91
|
|
|
return $this->get('id'); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Seta o valor da propriedade id. |
96
|
|
|
* |
97
|
|
|
* @param string|null $id |
98
|
|
|
* @return self |
99
|
|
|
*/ |
100
|
|
|
public function setId(?string $id): self |
101
|
|
|
{ |
102
|
|
|
$this->set('id', $id); |
103
|
|
|
return $this; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Retorna o valor da propriedade uuid. |
108
|
|
|
* |
109
|
|
|
* @return string|null |
110
|
|
|
*/ |
111
|
|
|
public function getUuid(): ?string |
112
|
|
|
{ |
113
|
|
|
return $this->get('uuid'); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Seta o valor da propriedade uuid. |
118
|
|
|
* |
119
|
|
|
* @param string|null $uuid |
120
|
|
|
* @return self |
121
|
|
|
*/ |
122
|
|
|
public function setUuid(?string $uuid): self |
123
|
|
|
{ |
124
|
|
|
$this->set('uuid', $uuid); |
125
|
|
|
return $this; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
protected function name(): Mutator |
129
|
|
|
{ |
130
|
|
|
return new Mutator(null, fn($value) => strval($value)); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Retorna o valor da propriedade name. |
135
|
|
|
* |
136
|
|
|
* @return string|null |
137
|
|
|
*/ |
138
|
|
|
public function getName(): ?string |
139
|
|
|
{ |
140
|
|
|
return $this->get('name'); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Seta o valor da propriedade name. |
145
|
|
|
* |
146
|
|
|
* @param string|null $name |
147
|
|
|
* @return self |
148
|
|
|
*/ |
149
|
|
|
public function setName(?string $name = null): self |
150
|
|
|
{ |
151
|
|
|
$this->set('name', $name); |
152
|
|
|
return $this; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
protected function is_active(): Mutator |
156
|
|
|
{ |
157
|
|
|
return new Mutator(null, fn($value) => (bool) $value); |
158
|
|
|
; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Retorna o valor da propriedade is_active. |
163
|
|
|
* |
164
|
|
|
* @return boolean|null |
165
|
|
|
*/ |
166
|
|
|
public function getIsActive(): ?bool |
167
|
|
|
{ |
168
|
|
|
return $this->get('is_active'); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Seta o valor da propriedade is_active. |
173
|
|
|
* |
174
|
|
|
* @param boolean|null $isActive |
175
|
|
|
* @return self |
176
|
|
|
*/ |
177
|
|
|
public function setIsActive(?bool $isActive = null): self |
178
|
|
|
{ |
179
|
|
|
$this->set('is_active', $isActive); |
180
|
|
|
return $this; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
protected function email(): Mutator |
184
|
|
|
{ |
185
|
|
|
return new Mutator( |
186
|
|
|
null, |
187
|
|
|
fn($value, $ctx) => |
188
|
|
|
is_null($value) ? |
189
|
|
|
$value : |
190
|
|
|
Assert::value($value)->email()->get() ?? $ctx->raise('inválido') |
191
|
|
|
); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Retorna o valor da propriedade email. |
196
|
|
|
* |
197
|
|
|
* @return string|null |
198
|
|
|
*/ |
199
|
|
|
public function getEmail(): ?string |
200
|
|
|
{ |
201
|
|
|
return $this->get('email'); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* Seta o valor da propriedade email. |
206
|
|
|
* |
207
|
|
|
* @param string|null $email |
208
|
|
|
* @return self |
209
|
|
|
*/ |
210
|
|
|
public function setEmail(?string $email = null): self |
211
|
|
|
{ |
212
|
|
|
$this->set('email', $email); |
213
|
|
|
return $this; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
protected function phone(): Mutator |
217
|
|
|
{ |
218
|
|
|
return new Mutator( |
219
|
|
|
null, |
220
|
|
|
fn($value, $ctx) => |
221
|
|
|
is_null($value) ? |
222
|
|
|
$value : |
223
|
|
|
Assert::value($value)->asDigits()->lbetween(10, 11)->get() ?? $ctx->raise('inválido') |
224
|
|
|
); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* Retorna o valor da propriedade phone. |
229
|
|
|
* |
230
|
|
|
* @return string|null |
231
|
|
|
*/ |
232
|
|
|
public function getPhone(): ?string |
233
|
|
|
{ |
234
|
|
|
return $this->get('phone'); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* Seta o valor da propriedade phone. |
239
|
|
|
* |
240
|
|
|
* @param string|null $phone |
241
|
|
|
* @return self |
242
|
|
|
*/ |
243
|
|
|
public function setPhone(?string $phone = null): self |
244
|
|
|
{ |
245
|
|
|
$this->set('phone', $phone); |
246
|
|
|
return $this; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
protected function cpf_cnpj(): Mutator |
250
|
|
|
{ |
251
|
|
|
return new Mutator( |
252
|
|
|
null, |
253
|
|
|
fn($value, $ctx) => |
254
|
|
|
is_null($value) ? |
255
|
|
|
$value : |
256
|
|
|
Assert::value($value)->asCpf(false)->or()->asCnpj(false)->get() ?? $ctx->raise('inválido') |
257
|
|
|
); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
protected function tax_receipt(): Mutator |
261
|
|
|
{ |
262
|
|
|
return new Mutator( |
263
|
|
|
null, |
264
|
|
|
fn($value, $ctx) => |
265
|
|
|
is_null($value) ? |
266
|
|
|
$value : |
267
|
|
|
Assert::value($value)->asCpf(false)->or()->asCnpj(false)->get() ?? $ctx->raise('inválido') |
268
|
|
|
); |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* Retorna o valor da propriedade tax_receipt. |
273
|
|
|
* |
274
|
|
|
* @return string|null |
275
|
|
|
*/ |
276
|
|
|
public function getTaxReceipt(): ?string |
277
|
|
|
{ |
278
|
|
|
return $this->get('tax_receipt'); |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
/** |
282
|
|
|
* Seta o valor da propriedade tax_receipt. |
283
|
|
|
* |
284
|
|
|
* @param string|null $taxReceipt |
285
|
|
|
* @return self |
286
|
|
|
*/ |
287
|
|
|
public function setTaxReceipt(?string $taxReceipt = null): self |
288
|
|
|
{ |
289
|
|
|
$this->set('tax_receipt', $taxReceipt); |
290
|
|
|
return $this; |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
/** |
294
|
|
|
* Retorna o valor da propriedade cpf_cnpj. |
295
|
|
|
* |
296
|
|
|
* @return string|null |
297
|
|
|
*/ |
298
|
|
|
public function getCpfCnpj(): ?string |
299
|
|
|
{ |
300
|
|
|
return $this->get('cpf_cnpj'); |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
/** |
304
|
|
|
* Seta o valor da propriedade cpf_cnpj. |
305
|
|
|
* |
306
|
|
|
* @param string|null $cpfCnpj |
307
|
|
|
* @return self |
308
|
|
|
*/ |
309
|
|
|
public function setCpfCnpj(?string $cpfCnpj = null): self |
310
|
|
|
{ |
311
|
|
|
$this->set('cpf_cnpj', $cpfCnpj); |
312
|
|
|
return $this; |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
protected function business_name(): Mutator |
316
|
|
|
{ |
317
|
|
|
return new Mutator(null, null); |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* Retorna o valor da propriedade business_name. |
322
|
|
|
* |
323
|
|
|
* @return string|null |
324
|
|
|
*/ |
325
|
|
|
public function getBusinessName(): ?string |
326
|
|
|
{ |
327
|
|
|
return $this->get('business_name'); |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
/** |
331
|
|
|
* Seta o valor da propriedade business_name. |
332
|
|
|
* |
333
|
|
|
* @param string|null $businessName |
334
|
|
|
* @return self |
335
|
|
|
*/ |
336
|
|
|
public function setBusinessName(?string $businessName = null): self |
337
|
|
|
{ |
338
|
|
|
$this->set('business_name', $businessName); |
339
|
|
|
return $this; |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
protected function birthdate(): Mutator |
343
|
|
|
{ |
344
|
|
|
return new Mutator( |
345
|
|
|
null, |
346
|
|
|
function ($value, $ctx) { |
347
|
|
|
$d = \DateTime::createFromFormat('Y-m-d', $value); |
348
|
|
|
|
349
|
|
|
return is_null($value) || |
350
|
|
|
($d && $d->format('Y-m-d') === $value) ? |
351
|
|
|
$value : $ctx->raise('inválido'); |
352
|
|
|
} |
353
|
|
|
); |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
/** |
357
|
|
|
* Retorna o valor da propriedade birthdate. |
358
|
|
|
* |
359
|
|
|
* @return string|null |
360
|
|
|
*/ |
361
|
|
|
public function getBirthdate(): ?string |
362
|
|
|
{ |
363
|
|
|
return $this->get('birthdate'); |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
/** |
367
|
|
|
* Seta o valor da propriedade birthdate. |
368
|
|
|
* |
369
|
|
|
* @param string|null $birthdate |
370
|
|
|
* @return self |
371
|
|
|
*/ |
372
|
|
|
public function setBirthdate(?string $birthdate = null): self |
373
|
|
|
{ |
374
|
|
|
$this->set('birthdate', $birthdate); |
375
|
|
|
return $this; |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
/** |
379
|
|
|
* Retorna o valor da propriedade ip. |
380
|
|
|
* |
381
|
|
|
* @return string|null |
382
|
|
|
*/ |
383
|
|
|
public function getIp(): ?string |
384
|
|
|
{ |
385
|
|
|
return $this->get('ip'); |
386
|
|
|
} |
387
|
|
|
|
388
|
|
|
/** |
389
|
|
|
* Seta o valor da propriedade ip. |
390
|
|
|
* |
391
|
|
|
* @param string|null $ip |
392
|
|
|
* @return self |
393
|
|
|
*/ |
394
|
|
|
public function setIp(?string $ip = null): self |
395
|
|
|
{ |
396
|
|
|
$this->set('ip', $ip); |
397
|
|
|
return $this; |
398
|
|
|
} |
399
|
|
|
|
400
|
|
|
/** |
401
|
|
|
* Retorna o objeto endereço do cliente. |
402
|
|
|
* |
403
|
|
|
* @return Address|null |
404
|
|
|
*/ |
405
|
|
|
public function getAddress(): ?Address |
406
|
|
|
{ |
407
|
|
|
return $this->get('address'); |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
/** |
411
|
|
|
* Seta o objeto endereço do cliente. |
412
|
|
|
* |
413
|
|
|
* @param Address|null $address |
414
|
|
|
* @return self |
415
|
|
|
*/ |
416
|
|
|
public function setAddress(?Address $address = null): self |
417
|
|
|
{ |
418
|
|
|
$this->set('address', $address); |
419
|
|
|
return $this; |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
/** |
423
|
|
|
* Retorna o objeto endereço de cobrança do cliente. |
424
|
|
|
* |
425
|
|
|
* @return Address|null |
426
|
|
|
*/ |
427
|
|
|
public function getBillingAddress(): ?Address |
428
|
|
|
{ |
429
|
|
|
return $this->get('billing_address'); |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
/** |
433
|
|
|
* Seta o objeto endereço de cobrança do cliente. |
434
|
|
|
* |
435
|
|
|
* @param Address|null $address |
436
|
|
|
* @return self |
437
|
|
|
*/ |
438
|
|
|
public function setBillingAddress(?Address $address = null): self |
439
|
|
|
{ |
440
|
|
|
$this->set('billing_address', $address); |
441
|
|
|
return $this; |
442
|
|
|
} |
443
|
|
|
|
444
|
|
|
/** |
445
|
|
|
* Retorna o objeto endereço de entrega do cliente. |
446
|
|
|
* |
447
|
|
|
* @return Address|null |
448
|
|
|
*/ |
449
|
|
|
public function getShippingAddress(): ?Address |
450
|
|
|
{ |
451
|
|
|
return $this->get('shipping_address'); |
452
|
|
|
} |
453
|
|
|
|
454
|
|
|
/** |
455
|
|
|
* Seta o objeto endereço de entrega do cliente. |
456
|
|
|
* |
457
|
|
|
* @param Address|null $address |
458
|
|
|
* @return self |
459
|
|
|
*/ |
460
|
|
|
public function setShippingAddress(?Address $address = null): self |
461
|
|
|
{ |
462
|
|
|
$this->set('shipping_address', $address); |
463
|
|
|
return $this; |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
} |