|
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
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Boleto Class |
|
11
|
|
|
* |
|
12
|
|
|
* Classe responsável por representar o recurso Boleto. |
|
13
|
|
|
* |
|
14
|
|
|
*/ |
|
15
|
|
|
final class Boleto extends Model |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @param array $data |
|
19
|
|
|
* array de dados do Card. |
|
20
|
|
|
* |
|
21
|
|
|
* + [`'due_date'`] string (opcional) {Formato: `Y-m-d H:i:s`}. |
|
22
|
|
|
* + [`'instructions'`] string[] (opcional) dos dados da instruções. |
|
23
|
|
|
*/ |
|
24
|
|
|
public function __construct(?array $data = []) |
|
25
|
|
|
{ |
|
26
|
|
|
parent::__construct($data); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function schema(SchemaBuilder $schema): Schema |
|
30
|
|
|
{ |
|
31
|
|
|
$schema->string('due_date')->nullable(); |
|
32
|
|
|
$schema->any('instructions')->default([])->nullable(); |
|
33
|
|
|
|
|
34
|
|
|
return $schema->build(); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
protected function due_date(): Mutator |
|
38
|
|
|
{ |
|
39
|
|
|
return new Mutator( |
|
40
|
|
|
null, |
|
41
|
|
|
function ($value, $ctx) { |
|
42
|
|
|
$d = \DateTime::createFromFormat('Y-m-d', $value); |
|
43
|
|
|
|
|
44
|
|
|
return is_null($value) || |
|
45
|
|
|
($d && $d->format('Y-m-d') === $value) ? |
|
46
|
|
|
$value : $ctx->raise('inválido'); |
|
47
|
|
|
} |
|
48
|
|
|
); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Retorna o valor da propriedade `due_date`. |
|
53
|
|
|
* |
|
54
|
|
|
* @return string|null |
|
55
|
|
|
*/ |
|
56
|
|
|
public function getDueDate(): ?string |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->get('due_date'); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Seta o valor da propriedade `due_date`. |
|
63
|
|
|
* |
|
64
|
|
|
* @param string|null $due_date |
|
65
|
|
|
* @return self |
|
66
|
|
|
*/ |
|
67
|
|
|
public function setDueDate(?string $due_date = null): self |
|
68
|
|
|
{ |
|
69
|
|
|
$this->set('due_date', $due_date); |
|
70
|
|
|
return $this; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Retorna o array `Instructions` associado ao `Boleto`. |
|
75
|
|
|
* |
|
76
|
|
|
* @return array|null |
|
77
|
|
|
*/ |
|
78
|
|
|
public function getInstructions(): ?array |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->get('instructions'); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Seta o array `Instructions` associado ao `Boleto`. |
|
85
|
|
|
* |
|
86
|
|
|
* @param array $instructions |
|
87
|
|
|
* @return self |
|
88
|
|
|
*/ |
|
89
|
|
|
public function setInstructions(array $instructions = []): self |
|
90
|
|
|
{ |
|
91
|
|
|
$this->set('instructions', $instructions); |
|
92
|
|
|
return $this; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Adiciona uma instrução ao `Boleto`. |
|
97
|
|
|
* |
|
98
|
|
|
* @param string $instruction |
|
99
|
|
|
* @return self |
|
100
|
|
|
*/ |
|
101
|
|
|
public function addInstruction(string $instruction): self |
|
102
|
|
|
{ |
|
103
|
|
|
$this->set( |
|
104
|
|
|
'instructions', |
|
105
|
|
|
[ |
|
106
|
|
|
...$this->get('instructions'), |
|
107
|
|
|
$instruction |
|
108
|
|
|
] |
|
109
|
|
|
); |
|
110
|
|
|
|
|
111
|
|
|
return $this; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
} |