Passed
Pull Request — master (#7)
by Lucas
02:44
created

PaymentTransaction::getRedirectUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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
 * PaymentTransaction Class
12
 *
13
 * Classe responsável por representar o recurso Payment Transaction.
14
 *
15
 */
16
final class PaymentTransaction extends Model
17
{
18
    /**
19
     *  @param array $data
20
     *  array de dados do Payment Transaction.
21
     *
22
     *  + [`'amount'`] float.
23
     *  + [`'order_id'`] string.
24
     *  + [`'callback_url'`] string.
25
     *  + [`'redirect_url'`] string.
26
     *
27
     *  + [`'antifraud'`] array (opcional) dos dados do Antifraud.
28
     *  + &emsp; [`'fingerprint'`] string.
29
     *  + &emsp; [`'provider'`] string.
30
     *
31
     *  + [`'payment'`] array (opcional) dos dados do Payment.
32
     *  + &emsp; [`'type'`] string.
33
     *  + &emsp; [`'method'`] string.
34
     *  + &emsp; [`'installments'`] int.
35
     *  + &emsp; [`'capture'`] bool.
36
     *  + &emsp; [`'fraud_analysis'`] bool.
37
     *  + &emsp; [`'softdescriptor'`] string.
38
     *  + &emsp; [`'pix_expires_in'`] int.
39
     *  + &emsp; [`'card'`] array (opcional) dos dados do Card.
40
     *  + &emsp;&emsp; [`'holder'`] string.
41
     *  + &emsp;&emsp; [`'number'`] string.
42
     *  + &emsp;&emsp; [`'expiry_month'`] string.
43
     *  + &emsp;&emsp; [`'expiry_year'`] string.
44
     *  + &emsp;&emsp; [`'cvv'`] string.
45
     *  + &emsp;&emsp; [`'token'`] string.
46
     *  + &emsp;&emsp; [`'tokenize'`] bool.
47
     *  + &emsp; [`'boleto'`] array (opcional) dos dados do Boleto.
48
     *  + &emsp;&emsp; [`'due_date'`] string (opcional) {Formato: `Y-m-d H:i:s`}.
49
     *  + &emsp;&emsp; [`'instructions'`] string[ ] (opcional) dos dados da instruções.
50
     *
51
     *  + [`'customer'`] array (opcional) dos dados do Customer.
52
     *  + &emsp; [`'name'`] string.
53
     *  + &emsp; [`'cpf_cnpj'`] string.
54
     *  + &emsp; [`'email'`] string.
55
     *  + &emsp; [`'phone'`] string.
56
     *  + &emsp; [`'birthdate'`] string {`Formato: Y-m-d`}.
57
     *  + &emsp; [`'ip'`] string.
58
     *  + &emsp; [`'billing_address'`] array (opcional) dos dados do Address.
59
     *  + &emsp;&emsp; `...`
60
     *  + &emsp; [`'shipping_address'`] array (opcional) dos dados do Address.
61
     *  + &emsp;&emsp; `...`
62
     *
63
     *  + [`'subscription'`] array (opcional) dos dados do Subscription.
64
     *  + &emsp; [`'frequency'`] int.
65
     *  + &emsp; [`'interval'`] string.
66
     *  + &emsp; [`'starting_date'`] string {`Formato: Y-m-d`}.
67
     *  + &emsp; [`'amount'`] float.
68
     *  + &emsp; [`'installments'`] int.
69
     *  + &emsp; [`'cycles'`] int.
70
     *
71
     *  + [`'split_rules'`] SplitRules[] (opcional) dos dados do Split Rules.
72
     *  + &emsp; [`'seller_id'`] string.
73
     *  + &emsp; [`'percentage'`] float.
74
     *  + &emsp; [`'amount'`] float.
75
     *  + &emsp; [`'liable'`] bool.
76
     *  + &emsp; [`'charge_processing_fee'`] bool.
77
     *  + &emsp; [`'hold_receivables'`] bool.
78
     *
79
     *  + [`'products'`] Product[] (opcional) dos dados do Product.
80
     *  + &emsp; [
81
     *  + &emsp;&emsp; [`'name'`] string
82
     *  + &emsp;&emsp; [`'unit_price'`] string
83
     *  + &emsp;&emsp; [`'quantity'`] int
84
     *  + &emsp;&emsp; [`'sku'`] string
85
     *  + &emsp;&emsp; [`'description'`] string
86
     *  + &emsp; ], [`...`]
87
     *
88
     *  + [`'event'`] array (opcional) dos dados do Event.
89
     *  + &emsp; [`'name'`] string (opcional).
90
     *  + &emsp; [`'date'`] string (opcional).
91
     *  + &emsp; [`'type'`] string (opcional).
92
     *  + &emsp; [`'subtype'`] string (opcional).
93
     *  + &emsp; [`'venue'`] array (opcional) dos dados do Venue.
94
     *  + &emsp;&emsp; [`'name'`] string (opcional).
95
     *  + &emsp;&emsp; [`'capacity'`] int (opcional).
96
     *  + &emsp;&emsp; [`'address'`] string (opcional).
97
     *  + &emsp;&emsp; [`'city'`] string (opcional).
98
     *  + &emsp;&emsp; [`'state'`] string (opcional).
99
     *  + &emsp; [`'tickets'`] array (opcional) dos dados do `Ticket`.
100
     *  + &emsp;&emsp; [`'id'`] string (opcional).
101
     *  + &emsp;&emsp; [`'category'`] string (opcional).
102
     *  + &emsp;&emsp; [`'premium'`] bool (opcional).
103
     *  + &emsp;&emsp; [`'section'`] string (opcional).
104
     *  + &emsp;&emsp; [`'attendee'`] array (opcional) dos dados do Attendee.
105
     *  + &emsp;&emsp; &emsp; [`'document'`] string (opcional).
106
     *  + &emsp;&emsp; &emsp; [`'dob'`] string (opcional) {Formato: `Y-m-d`}.
107
     */
108
    public function __construct(?array $data = [])
109
    {
110
        parent::__construct($data);
111
    }
112
113
    public function schema(SchemaBuilder $schema): Schema
114
    {
115
        $schema->float('amount')->nullable();
116
        $schema->string('order_id')->nullable();
117
        $schema->string('callback_url')->nullable();
118
        $schema->string('redirect_url')->nullable();
119
120
        $schema->has('antifraud', PaymentAntifraud::class)->nullable();
121
        $schema->has('payment', Payment::class)->nullable();
122
        $schema->has('customer', Customer::class)->nullable();
123
        $schema->hasMany('products', Product::class)->nullable();
124
        $schema->has('subscription', PaymentSubscription::class)->nullable();
125
        $schema->hasMany('split_rules', PaymentSplitRules::class)->nullable();
126
        $schema->has('event', Event::class)->nullable();
127
128
        return $schema->build();
129
    }
130
131
    protected function amount(): Mutator
132
    {
133
        return new Mutator(
134
            null,
135
            fn($value, $ctx) =>
136
            is_null($value) ? $value :
137
            (
138
                Assert::value(floatval($value))->gte(0)->get()
139
                ?? $ctx->raise('inválido')
140
            )
141
        );
142
    }
143
144
    /**
145
     * Retorna o valor da propriedade `amount`.
146
     *
147
     * @return float|null
148
     */
149
    public function getAmount(): ?float
150
    {
151
        return $this->get('amount');
152
    }
153
154
    /**
155
     * Seta o valor da propriedade `amount`.
156
     *
157
     * @param float|null $amount
158
     * @return self
159
     */
160
    public function setAmount(?float $amount = null): self
161
    {
162
        $this->set('amount', $amount);
163
        return $this;
164
    }
165
166
    /**
167
     * Retorna o valor da propriedade `order_id`.
168
     *
169
     * @return string|null
170
     */
171
    public function getOrderId(): ?string
172
    {
173
        return $this->get('order_id');
174
    }
175
176
    /**
177
     * Seta o valor da propriedade `order_id`.
178
     *
179
     * @param string|null $orderId
180
     * @return self
181
     */
182
    public function setOrderId(?string $orderId = null): self
183
    {
184
        $this->set('order_id', $orderId);
185
        return $this;
186
    }
187
188
    /**
189
     * Retorna o valor da propriedade `callback_url`.
190
     *
191
     * @return string|null
192
     */
193
    public function getCallbackUrl(): ?string
194
    {
195
        return $this->get('callback_url');
196
    }
197
198
    /**
199
     * Seta o valor da propriedade `callback_url`.
200
     *
201
     * @param string|null $callbackUrl
202
     * @return self
203
     */
204
    public function setCallbackUrl(?string $callbackUrl = null): self
205
    {
206
        $this->set('callback_url', $callbackUrl);
207
        return $this;
208
    }
209
210
    /**
211
     * Retorna o valor da propriedade `redirect_url`.
212
     *
213
     * @return string|null
214
     */
215
    public function getRedirectUrl(): ?string
216
    {
217
        return $this->get('redirect_url');
218
    }
219
220
    public function setRedirectUrl(?string $redirectUrl = null): self
221
    {
222
        $this->set('redirect_url', $redirectUrl);
223
        return $this;
224
    }
225
226
    /**
227
     * Retorna o valor da propriedade `PaymentAntifraud`.
228
     *
229
     * @return PaymentAntifraud|null
230
     */
231
    public function getAntifraud(): ?PaymentAntifraud
232
    {
233
        return $this->get('antifraud');
234
    }
235
236
    /**
237
     * Seta o valor da propriedade `PaymentAntifraud`.
238
     *
239
     * @param PaymentAntifraud|null $antifraud
240
     * @return self
241
     */
242
    public function setAntifraud(?PaymentAntifraud $antifraud = null): self
243
    {
244
        $this->set('antifraud', $antifraud);
245
        return $this;
246
    }
247
248
    /**
249
     * Retorna o objeto `Payment` vinculado ao `PaymentTransaction`
250
     *
251
     * @return Payment|null
252
     */
253
    public function getPayment(): ?Payment
254
    {
255
        return $this->get('payment');
256
    }
257
258
    /**
259
     * Seta o objeto `Payment` vinculado ao `PaymentTransaction`
260
     *
261
     * @param Payment|null $payment
262
     * @return self
263
     */
264
    public function setPayment(?Payment $payment = null): self
265
    {
266
        $this->set('payment', $payment);
267
        return $this;
268
    }
269
270
    /**
271
     * Retorna o objeto `Customer` vinculado ao `PaymentTransaction`
272
     *
273
     * @return Customer|null
274
     */
275
    public function getCustomer(): ?Customer
276
    {
277
        return $this->get('customer');
278
    }
279
280
    /**
281
     * Seta o objeto `Customer` vinculado ao `PaymentTransaction`
282
     *
283
     * @param Customer|null $customer
284
     * @return self
285
     */
286
    public function setCustomer(?Customer $customer = null): self
287
    {
288
        $this->set('customer', $customer);
289
        return $this;
290
    }
291
292
    /**
293
     * Retorna o array `Product` vinculado ao `PaymentTransaction`
294
     *
295
     * @return array|null
296
     */
297
    public function getProducts(): ?array
298
    {
299
        return $this->get('products');
300
    }
301
302
    /**
303
     * Seta o array `Product` vinculado ao `PaymentTransaction`
304
     *
305
     * @param array|null $products
306
     * @return self
307
     */
308
    public function setProducts(?array $products = null): self
309
    {
310
        $this->set('products', $products);
311
        return $this;
312
    }
313
314
    /**
315
     * Adiciona um `Product` ao `PaymentTransaction`
316
     *
317
     * @param Product $product
318
     * @return self
319
     */
320
    public function addProduct(Product $product): self
321
    {
322
        $this->set(
323
            'products',
324
            [
325
                ...$this->get('products'),
326
                $product
327
            ]
328
        );
329
330
        return $this;
331
    }
332
333
    /**
334
     * Retorna o objeto `PaymentSubscription` vinculado ao `PaymentTransaction`
335
     *
336
     * @return PaymentSubscription|null
337
     */
338
    public function getSubscription(): ?PaymentSubscription
339
    {
340
        return $this->get('subscription');
341
    }
342
343
    /**
344
     * Seta o objeto `PaymentSubscription` vinculado ao `PaymentTransaction`
345
     *
346
     * @param PaymentSubscription|null $subscription
347
     * @return self
348
     */
349
    public function setSubscription(?PaymentSubscription $subscription = null): self
350
    {
351
        $this->set('subscription', $subscription);
352
        return $this;
353
    }
354
355
    /**
356
     * Retorna um array com os objetos `PaymentSplitRules` vinculados ao `PaymentTransaction`o objeto `PaymentSplitRules` vinculado ao `PaymentTransaction`
357
     *
358
     * @return array|null
359
     */
360
    public function getSplitRules(): ?array
361
    {
362
        return $this->get('split_rules');
363
    }
364
365
    /**
366
     * Seta o array com os objetos `PaymentSplitRules` vinculado ao `PaymentTransaction`
367
     *
368
     * @param array|null $splitRules
369
     * @return self
370
     */
371
    public function setSplitRules(?array $splitRules = null): self
372
    {
373
        $this->set('split_rules', $splitRules);
374
        return $this;
375
    }
376
377
    /**
378
     * Adiciona um `PaymentSplitRules` ao `PaymentTransaction`
379
     *
380
     * @param PaymentSplitRules $splitRules
381
     * @return self
382
     */
383
    public function addSplitRules(PaymentSplitRules $splitRules): self
384
    {
385
        $this->set(
386
            'split_rules',
387
            [
388
                ...$this->get('split_rules'),
389
                $splitRules
390
            ]
391
        );
392
393
        return $this;
394
    }
395
396
    /**
397
     * Retorna o objeto `Event` vinculado ao `PaymentTransaction`
398
     *
399
     * @return Event|null
400
     */
401
    public function getEvent(): ?Event
402
    {
403
        return $this->get('event');
404
    }
405
406
    /**
407
     * Seta o objeto `Event` vinculado ao `PaymentTransaction`
408
     *
409
     * @param Event|null $event
410
     * @return self
411
     */
412
    public function setEvent(?Event $event = null): self
413
    {
414
        $this->set('event', $event);
415
        return $this;
416
    }
417
418
}