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

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