Passed
Pull Request — master (#10)
by Lucas
02:17
created

Customer::setTaxId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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