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
|
|
|
* +   [`'fingerprint'`] string. |
29
|
|
|
* +   [`'provider'`] string. |
30
|
|
|
* |
31
|
|
|
* + [`'payment'`] array (opcional) dos dados do Payment. |
32
|
|
|
* +   [`'type'`] string. |
33
|
|
|
* +   [`'method'`] string. |
34
|
|
|
* +   [`'installments'`] int. |
35
|
|
|
* +   [`'capture'`] bool. |
36
|
|
|
* +   [`'fraud_analysis'`] bool. |
37
|
|
|
* +   [`'softdescriptor'`] string. |
38
|
|
|
* +   [`'pix_expires_in'`] int. |
39
|
|
|
* +   [`'card'`] array (opcional) dos dados do Card. |
40
|
|
|
* +    [`'holder'`] string. |
41
|
|
|
* +    [`'number'`] string. |
42
|
|
|
* +    [`'expiry_month'`] string. |
43
|
|
|
* +    [`'expiry_year'`] string. |
44
|
|
|
* +    [`'cvv'`] string. |
45
|
|
|
* +    [`'token'`] string. |
46
|
|
|
* +    [`'tokenize'`] bool. |
47
|
|
|
* +   [`'boleto'`] array (opcional) dos dados do Boleto. |
48
|
|
|
* +    [`'due_date'`] string (opcional) {Formato: `Y-m-d H:i:s`}. |
49
|
|
|
* +    [`'instructions'`] string[ ] (opcional) dos dados da instruções. |
50
|
|
|
* |
51
|
|
|
* + [`'customer'`] array (opcional) dos dados do Customer. |
52
|
|
|
* +   [`'name'`] string. |
53
|
|
|
* +   [`'cpf_cnpj'`] string. |
54
|
|
|
* +   [`'email'`] string. |
55
|
|
|
* +   [`'phone'`] string. |
56
|
|
|
* +   [`'birthdate'`] string {`Formato: Y-m-d`}. |
57
|
|
|
* +   [`'ip'`] string. |
58
|
|
|
* +   [`'billing_address'`] array (opcional) dos dados do Address. |
59
|
|
|
* +    `...` |
60
|
|
|
* +   [`'shipping_address'`] array (opcional) dos dados do Address. |
61
|
|
|
* +    `...` |
62
|
|
|
* |
63
|
|
|
* + [`'subscription'`] array (opcional) dos dados do Subscription. |
64
|
|
|
* +   [`'frequency'`] int. |
65
|
|
|
* +   [`'interval'`] string. |
66
|
|
|
* +   [`'starting_date'`] string {`Formato: Y-m-d`}. |
67
|
|
|
* +   [`'amount'`] float. |
68
|
|
|
* +   [`'installments'`] int. |
69
|
|
|
* +   [`'cycles'`] int. |
70
|
|
|
* |
71
|
|
|
* + [`'split_rules'`] SplitRules[] (opcional) dos dados do Split Rules. |
72
|
|
|
* +   [`'seller_id'`] string. |
73
|
|
|
* +   [`'percentage'`] float. |
74
|
|
|
* +   [`'amount'`] float. |
75
|
|
|
* +   [`'liable'`] bool. |
76
|
|
|
* +   [`'charge_processing_fee'`] bool. |
77
|
|
|
* +   [`'hold_receivables'`] bool. |
78
|
|
|
* |
79
|
|
|
* + [`'products'`] Product[] (opcional) dos dados do Product. |
80
|
|
|
* +   [ |
81
|
|
|
* +    [`'name'`] string |
82
|
|
|
* +    [`'unit_price'`] string |
83
|
|
|
* +    [`'quantity'`] int |
84
|
|
|
* +    [`'sku'`] string |
85
|
|
|
* +    [`'description'`] string |
86
|
|
|
* +   ], [`...`] |
87
|
|
|
* |
88
|
|
|
* + [`'event'`] array (opcional) dos dados do Event. |
89
|
|
|
* +   [`'name'`] string (opcional). |
90
|
|
|
* +   [`'date'`] string (opcional). |
91
|
|
|
* +   [`'type'`] string (opcional). |
92
|
|
|
* +   [`'subtype'`] string (opcional). |
93
|
|
|
* +   [`'venue'`] array (opcional) dos dados do Venue. |
94
|
|
|
* +    [`'name'`] string (opcional). |
95
|
|
|
* +    [`'capacity'`] int (opcional). |
96
|
|
|
* +    [`'address'`] string (opcional). |
97
|
|
|
* +    [`'city'`] string (opcional). |
98
|
|
|
* +    [`'state'`] string (opcional). |
99
|
|
|
* +   [`'tickets'`] array (opcional) dos dados do `Ticket`. |
100
|
|
|
* +    [`'id'`] string (opcional). |
101
|
|
|
* +    [`'category'`] string (opcional). |
102
|
|
|
* +    [`'premium'`] bool (opcional). |
103
|
|
|
* +    [`'section'`] string (opcional). |
104
|
|
|
* +    [`'attendee'`] array (opcional) dos dados do Attendee. |
105
|
|
|
* +      [`'document'`] string (opcional). |
106
|
|
|
* +      [`'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
|
|
|
} |