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

Payment::setRecurring()   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
 * Payment Class
12
 *
13
 * Classe responsável por representar o recurso Payment.
14
 *
15
 */
16
final class Payment extends Model
17
{
18
    /**
19
     *  @param array $data
20
     *  array de dados do Payment.
21
     *
22
     *  + [`'type'`] string.
23
     *  + [`'method'`] string.
24
     *  + [`'installments'`] int.
25
     *  + [`'capture'`] bool.
26
     *  + [`'fraud_analysis'`] bool.
27
     *  + [`'softdescriptor'`] string.
28
     *  + [`'pix_expires_in'`] int.
29
     *  + [`'recurring'`] bool.
30
     *
31
     *  + [`'card'`] array (opcional) dos dados do Payment Card.
32
     *  + &emsp; [`'holder'`] string.
33
     *  + &emsp; [`'number'`] string.
34
     *  + &emsp; [`'expiry_month'`] string.
35
     *  + &emsp; [`'expiry_year'`] string.
36
     *  + &emsp; [`'cvv'`] string.
37
     *  + &emsp; [`'token'`] string.
38
     *  + &emsp; [`'tokenize'`] bool.
39
     *
40
     *  + [`'boleto'`] array (opcional) dos dados do Boleto.
41
     *  + &emsp; [`'due_date'`] string (opcional) {Formato: `Y-m-d H:i:s`}.
42
     *  + &emsp; [`'instructions'`] string[] (opcional) dos dados da instruções.
43
     */
44
    public function __construct(?array $data = [])
45
    {
46
        parent::__construct($data);
47
    }
48
49
    public function schema(SchemaBuilder $schema): Schema
50
    {
51
        $schema->string('type')->nullable(); // card, boleto ou pix
52
        $schema->string('method')->nullable();
53
        $schema->int('installments')->nullable(); // 1 ~ 12
54
        $schema->bool('capture')->nullable();
55
        $schema->bool('fraud_analysis')->nullable();
56
        $schema->string('softdescriptor')->nullable();
57
        $schema->int('pix_expires_in')->nullable();
58
        $schema->bool('recurring')->nullable();
59
60
        $schema->has('card', PaymentCard::class)->nullable();
61
        $schema->has('boleto', Boleto::class)->nullable();
62
63
        return $schema->build();
64
    }
65
66
    protected function installments(): Mutator
67
    {
68
        return new Mutator(
69
            null,
70
            fn ($value, $ctx) =>
71
            is_null($value) ? $value :
72
            (
73
                Assert::value(intval($value))->gt(0)->get()
74
                ?? $ctx->raise('inválido (informe um valor de 1 à 12)')
75
            )
76
        );
77
    }
78
79
    /**
80
     * Retorna o valor da propriedade `type`.
81
     *
82
     * @return string|null
83
     */
84
    public function getType(): ?string
85
    {
86
        return $this->get('type');
87
    }
88
89
    /**
90
     * Seta o valor da propriedade `type`.
91
     *
92
     * @param string|null $type
93
     * @return self
94
     */
95
    public function setType(?string $type = null): self
96
    {
97
        $this->set('type', $type);
98
        return $this;
99
    }
100
101
    /**
102
     * Retorna o valor da propriedade `method`.
103
     *
104
     * @return string|null
105
     */
106
    public function getMethod(): ?string
107
    {
108
        return $this->get('method');
109
    }
110
111
    /**
112
     * Seta o valor da propriedade `method`.
113
     *
114
     * @param string|null $method
115
     * @return self
116
     */
117
    public function setMethod(?string $method = null): self
118
    {
119
        $this->set('method', $method);
120
        return $this;
121
    }
122
123
    /**
124
     * Retorna o valor da propriedade `installments`.
125
     *
126
     * @return integer|null
127
     */
128
    public function getInstallments(): ?int
129
    {
130
        return $this->get('installments');
131
    }
132
133
    /**
134
     * Seta o valor da propriedade `installments`.
135
     *
136
     * @param integer|null $installments
137
     * @return self
138
     */
139
    public function setInstallments(?int $installments = null): self
140
    {
141
        $this->set('installments', $installments);
142
        return $this;
143
    }
144
145
    /**
146
     * Retorna o valor da propriedade `capture`.
147
     *
148
     * @return boolean|null
149
     */
150
    public function getCapture(): ?bool
151
    {
152
        return $this->get('capture');
153
    }
154
155
    /**
156
     * Seta o valor da propriedade `capture`.
157
     *
158
     * @param boolean|null $capture
159
     * @return self
160
     */
161
    public function setCapture(?bool $capture = null): self
162
    {
163
        $this->set('capture', $capture);
164
        return $this;
165
    }
166
167
    /**
168
     * Retorna o valor da propriedade `fraud_analysis`.
169
     *
170
     * @return boolean|null
171
     */
172
    public function getFraudAnalysis(): ?bool
173
    {
174
        return $this->get('fraud_analysis');
175
    }
176
177
    /**
178
     * Seta o valor da propriedade `fraud_analysis`.
179
     *
180
     * @param boolean|null $fraudAnalysis
181
     * @return self
182
     */
183
    public function setFraudAnalysis(?bool $fraudAnalysis = null): self
184
    {
185
        $this->set('fraud_analysis', $fraudAnalysis);
186
        return $this;
187
    }
188
189
    /**
190
     * Retorna o valor da propriedade `softdescriptor`.
191
     *
192
     * @return string|null
193
     */
194
    public function getSoftDescriptor(): ?string
195
    {
196
        return $this->get('softdescriptor');
197
    }
198
199
    /**
200
     * Seta o valor da propriedade `softdescriptor`.
201
     *
202
     * @param string|null $softDescriptor
203
     * @return self
204
     */
205
    public function setSoftDescriptor(?string $softDescriptor = null): self
206
    {
207
        $this->set('softdescriptor', $softDescriptor);
208
        return $this;
209
    }
210
211
    /**
212
     * Retorna o valor da propriedade `pix_expires_in`.
213
     *
214
     * @return integer|null
215
     */
216
    public function getPixExpiresIn(): ?int
217
    {
218
        return $this->get('pix_expires_in');
219
    }
220
221
    /**
222
     * Seta o valor da propriedade `pix_expires_in`.
223
     *
224
     * @param integer|null $pixExpiresIn
225
     * @return self
226
     */
227
    public function setPixExpiresIn(?int $pixExpiresIn = null): self
228
    {
229
        $this->set('pix_expires_in', $pixExpiresIn);
230
        return $this;
231
    }
232
233
    /**
234
     * Retorna o valor da propriedade `recurring`.
235
     *
236
     * @return bool|null
237
     */
238
    public function getRecurring(): ?bool
239
    {
240
        return $this->get('recurring');
241
    }
242
243
    /**
244
     * Seta o valor da propriedade `recurring`.
245
     *
246
     * @param bool|null $recurring
247
     * @return self
248
     */
249
    public function setRecurring(?bool $recurring = null): self
250
    {
251
        $this->set('recurring', $recurring);
252
        return $this;
253
    }
254
255
    /**
256
     * Retorna o objeto `Card` vinculado ao `Payment`.
257
     *
258
     * @return PaymentCard|null
259
     */
260
    public function getCard(): ?PaymentCard
261
    {
262
        return $this->get('card');
263
    }
264
265
    /**
266
     * Seta o objeto `Card` vinculado ao `Payment`.
267
     *
268
     * @param PaymentCard|null $card
269
     * @return self
270
     */
271
    public function setCard(?PaymentCard $card = null): self
272
    {
273
        $this->set('card', $card);
274
        return $this;
275
    }
276
277
    /**
278
     * Retorna o objeto `Boleto` vinculado ao `Payment`.
279
     *
280
     * @return Boleto|null
281
     */
282
    public function getBoleto(): ?Boleto
283
    {
284
        return $this->get('boleto');
285
    }
286
287
    /**
288
     * Seta o objeto `Boleto` vinculado ao `Payment`.
289
     *
290
     * @param Boleto|null $boleto
291
     * @return self
292
     */
293
    public function setBoleto(?Boleto $boleto = null): self
294
    {
295
        $this->set('boleto', $boleto);
296
        return $this;
297
    }
298
299
}
300