Completed
Push — master ( bbee1f...c48ed6 )
by
unknown
14s queued 14s
created

Builder   F

Complexity

Total Complexity 477

Size/Duplication

Total Lines 2852
Duplicated Lines 0.42 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 477
lcom 1
cbo 1
dl 12
loc 2852
rs 0.8
c 0
b 0
f 0

35 Methods

Rating   Name   Duplication   Size   Complexity  
A confirmationEvent() 0 34 2
A loginEvent() 0 44 2
B registrationEvent() 0 56 2
A payoutEvent() 0 45 2
B transactionEvent() 0 99 2
A installEvent() 0 22 2
A refundEvent() 0 41 2
B transferEvent() 0 107 2
B kycProfileEvent() 0 98 2
A kycSubmitEvent() 0 34 2
B orderItemEvent() 0 119 2
B orderSubmitEvent() 0 111 2
A postBackEvent() 0 30 1
A __construct() 0 12 3
A build() 0 11 1
A replace() 0 6 5
A addIdentity() 0 5 1
B addWebsiteData() 0 21 9
B addIpData() 0 18 7
F addBrowserData() 0 111 44
F addUserData() 0 100 35
C addShortUserData() 0 39 14
D addCCTransactionData() 3 81 33
B addCardData() 0 31 11
C addBillingData() 0 46 17
B addProductData() 0 21 8
D addPayoutData() 3 76 27
A addInstallData() 0 10 2
D addRefundData() 0 71 25
F addTransferData() 3 136 48
F addKycData() 0 121 45
F addOrderData() 3 197 82
D addPostbackData() 0 69 27
A addCustomField() 0 16 5
A addGroupId() 0 9 3

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like Builder often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Builder, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Covery\Client\Envelopes;
4
5
use Covery\Client\EnvelopeInterface;
6
use Covery\Client\IdentityNodeInterface;
7
8
class Builder
9
{
10
    /**
11
     * @var string
12
     */
13
    private $type;
14
    /**
15
     * @var string
16
     */
17
    private $sequenceId;
18
    /**
19
     * @var IdentityNodeInterface[]
20
     */
21
    private $identities = array();
22
    /**
23
     * @var array
24
     */
25
    private $data = array();
26
27
    /**
28
     * Returns builder for confirmation event
29
     *
30
     * @param string $sequenceId
31
     * @param string $userId
32
     * @param int|null $timestamp If null provided, takes current time
33
     * @param bool|null $isEmailConfirmed
34
     * @param bool|null $idPhoneConfirmed
35
     * @param string|null $email
36
     * @param string|null $phone
37
     * @param string|null $groupId
38
     *
39
     * @return Builder
40
     */
41
    public static function confirmationEvent(
42
        $sequenceId,
43
        $userId,
44
        $timestamp = null,
45
        $isEmailConfirmed = null,
46
        $idPhoneConfirmed = null,
47
        $email = null,
48
        $phone = null,
49
        $groupId = null
50
    ) {
51
        $builder = new self('confirmation', $sequenceId);
52
        if ($timestamp === null) {
53
            $timestamp = time();
54
        }
55
56
        return $builder->addUserData(
57
            $email,
58
            $userId,
59
            $phone,
60
            null,
61
            null,
62
            null,
63
            null,
64
            null,
65
            null,
66
            null,
67
            null,
68
            null,
69
            $timestamp,
70
            $isEmailConfirmed,
71
            $idPhoneConfirmed,
72
            null
73
        )->addGroupId($groupId);
74
    }
75
76
    /**
77
     * Returns builder for login event
78
     *
79
     * @param string $sequenceId
80
     * @param string $userId
81
     * @param int|null $timestamp
82
     * @param string|null $email
83
     * @param bool|null $failed
84
     * @param string|null $gender
85
     * @param string|null $trafficSource
86
     * @param string|null $affiliateId
87
     * @param string|null $password
88
     * @param string|null $campaign
89
     * @param string|null $groupId
90
     *
91
     * @return Builder
92
     */
93
    public static function loginEvent(
94
        $sequenceId,
95
        $userId,
96
        $timestamp = null,
97
        $email = null,
98
        $failed = null,
99
        $gender = null,
100
        $trafficSource = null,
101
        $affiliateId = null,
102
        $password = null,
103
        $campaign = null,
104
        $groupId = null
105
    ) {
106
        $builder = new self('login', $sequenceId);
107
        if ($timestamp === null) {
108
            $timestamp = time();
109
        }
110
111
        return $builder->addUserData(
112
            $email,
113
            $userId,
114
            null,
115
            null,
116
            null,
117
            null,
118
            $gender,
119
            null,
120
            null,
121
            null,
122
            null,
123
            $timestamp,
124
            null,
125
            null,
126
            null,
127
            $failed,
128
            null,
129
            null,
130
            null,
131
            null,
132
            null,
133
            null,
134
            $password
135
        )->addWebsiteData(null, $trafficSource, $affiliateId, $campaign)->addGroupId($groupId);
136
    }
137
138
    /**
139
     * Returns builder for registration event
140
     *
141
     * @param string $sequenceId
142
     * @param string $userId
143
     * @param int|null $timestamp
144
     * @param string|null $email
145
     * @param string|null $userName
146
     * @param string|null $firstName
147
     * @param string|null $lastName
148
     * @param int|null $age
149
     * @param string|null $gender
150
     * @param string|null $phone
151
     * @param string|null $country
152
     * @param string|null $socialType
153
     * @param string|null $websiteUrl
154
     * @param string|null $trafficSource
155
     * @param string|null $affiliateId
156
     * @param string|null $password
157
     * @param string|null $campaign
158
     * @param string|null $groupId
159
     *
160
     * @return Builder
161
     */
162
    public static function registrationEvent(
163
        $sequenceId,
164
        $userId,
165
        $timestamp = null,
166
        $email = null,
167
        $userName = null,
168
        $firstName = null,
169
        $lastName = null,
170
        $age = null,
171
        $gender = null,
172
        $phone = null,
173
        $country = null,
174
        $socialType = null,
175
        $websiteUrl = null,
176
        $trafficSource = null,
177
        $affiliateId = null,
178
        $password = null,
179
        $campaign = null,
180
        $groupId = null
181
    ) {
182
        $builder = new self('registration', $sequenceId);
183
        if ($timestamp === null) {
184
            $timestamp = time();
185
        }
186
187
        return $builder->addWebsiteData(
188
            $websiteUrl,
189
            $trafficSource,
190
            $affiliateId,
191
            $campaign
192
        )->addUserData(
193
            $email,
194
            $userId,
195
            $phone,
196
            $userName,
197
            $firstName,
198
            $lastName,
199
            $gender,
200
            $age,
201
            $country,
202
            $socialType,
203
            $timestamp,
204
            null,
205
            null,
206
            null,
207
            null,
208
            null,
209
            null,
210
            null,
211
            null,
212
            null,
213
            null,
214
            null,
215
            $password
216
        )-> addGroupId($groupId);
217
    }
218
219
    /**
220
     * Returns builder for payout request
221
     *
222
     * @param string $sequenceId
223
     * @param string $userId
224
     * @param string $payoutId
225
     * @param string $currency
226
     * @param int|float $amount
227
     * @param int|null $payoutTimestamp
228
     * @param string|null $cardId
229
     * @param string|null $accountId
230
     * @param string|null $method
231
     * @param string|null $system
232
     * @param string|null $mid
233
     * @param int|float $amountConverted
234
     * @param string|null $firstName
235
     * @param string|null $lastName
236
     * @param string|null $country
237
     * @param string|null $email
238
     * @param string|null $phone
239
     * @param int|null $cardBin
240
     * @param string|null $cardLast4
241
     * @param int|null $cardExpirationMonth
242
     * @param int|null $cardExpirationYear
243
     * @param string|null $groupId
244
     *
245
     * @return Builder
246
     */
247
    public static function payoutEvent(
248
        $sequenceId,
249
        $userId,
250
        $payoutId,
251
        $currency,
252
        $amount,
253
        $payoutTimestamp = null,
254
        $cardId = null,
255
        $accountId = null,
256
        $method = null,
257
        $system = null,
258
        $mid = null,
259
        $amountConverted = null,
260
        $firstName = null,
261
        $lastName = null,
262
        $country = null,
263
        $email = null,
264
        $phone = null,
265
        $cardBin = null,
266
        $cardLast4 = null,
267
        $cardExpirationMonth = null,
268
        $cardExpirationYear = null,
269
        $groupId = null
270
    ) {
271
        $builder = new self('payout', $sequenceId);
272
        if ($payoutTimestamp === null) {
273
            $payoutTimestamp = time();
274
        }
275
        return $builder->addPayoutData(
276
            $payoutId,
277
            $payoutTimestamp,
278
            $amount,
279
            $currency,
280
            $cardId,
281
            $accountId,
282
            $method,
283
            $system,
284
            $mid,
285
            $amountConverted,
286
            $cardBin,
287
            $cardLast4,
288
            $cardExpirationMonth,
289
            $cardExpirationYear
290
        )->addShortUserData($email, $userId, $phone, $firstName, $lastName, $country)->addGroupId($groupId);
291
    }
292
293
    /**
294
     * Returns builder for transaction request
295
     *
296
     * @param string $sequenceId
297
     * @param string $userId
298
     * @param string $transactionId
299
     * @param int|float $transactionAmount
300
     * @param string $transactionCurrency
301
     * @param int|null $transactionTimestamp
302
     * @param string|null $transactionMode
303
     * @param string|null $transactionType
304
     * @param int|null $cardBin
305
     * @param string|null $cardId
306
     * @param string|null $cardLast4
307
     * @param int|null $expirationMonth
308
     * @param int|null $expirationYear
309
     * @param int|null $age
310
     * @param string|null $country
311
     * @param string|null $email
312
     * @param string|null $gender
313
     * @param string|null $firstName
314
     * @param string|null $lastName
315
     * @param string|null $phone
316
     * @param string|null $userName
317
     * @param string|null $paymentAccountId
318
     * @param string|null $paymentMethod
319
     * @param string|null $paymentMidName
320
     * @param string|null $paymentSystem
321
     * @param int|float|null $transactionAmountConverted
322
     * @param string|null $transactionSource
323
     * @param string|null $billingAddress
324
     * @param string|null $billingCity
325
     * @param string|null $billingCountry
326
     * @param string|null $billingFirstName
327
     * @param string|null $billingLastName
328
     * @param string|null $billingFullName
329
     * @param string|null $billingState
330
     * @param string|null $billingZip
331
     * @param string|null $productDescription
332
     * @param string|null $productName
333
     * @param int|float|null $productQuantity
334
     * @param string|null $websiteUrl
335
     * @param string|null $merchantIp
336
     * @param string|null $affiliateId
337
     * @param string|null $campaign
338
     * @param string|null $merchantCountry
339
     * @param string|null $mcc
340
     * @param string|null $acquirerMerchantId
341
     * @param string|null $groupId
342
     *
343
     * @return Builder
344
     */
345
    public static function transactionEvent(
346
        $sequenceId,
347
        $userId,
348
        $transactionId,
349
        $transactionAmount,
350
        $transactionCurrency,
351
        $transactionTimestamp = null,
352
        $transactionMode = null,
353
        $transactionType = null,
354
        $cardBin = null,
355
        $cardId = null,
356
        $cardLast4 = null,
357
        $expirationMonth = null,
358
        $expirationYear = null,
359
        $age = null,
360
        $country = null,
361
        $email = null,
362
        $gender = null,
363
        $firstName = null,
364
        $lastName = null,
365
        $phone = null,
366
        $userName = null,
367
        $paymentAccountId = null,
368
        $paymentMethod = null,
369
        $paymentMidName = null,
370
        $paymentSystem = null,
371
        $transactionAmountConverted = null,
372
        $transactionSource = null,
373
        $billingAddress = null,
374
        $billingCity = null,
375
        $billingCountry = null,
376
        $billingFirstName = null,
377
        $billingLastName = null,
378
        $billingFullName = null,
379
        $billingState = null,
380
        $billingZip = null,
381
        $productDescription = null,
382
        $productName = null,
383
        $productQuantity = null,
384
        $websiteUrl = null,
385
        $merchantIp = null,
386
        $affiliateId = null,
387
        $campaign = null,
388
        $merchantCountry = null,
389
        $mcc = null,
390
        $acquirerMerchantId = null,
391
        $groupId = null
392
    ) {
393
        $builder = new self('transaction', $sequenceId);
394
        if ($transactionTimestamp === null) {
395
            $transactionTimestamp = time();
396
        }
397
398
        return $builder
399
            ->addCCTransactionData(
400
                $transactionId,
401
                $transactionSource,
402
                $transactionType,
403
                $transactionMode,
404
                $transactionTimestamp,
405
                $transactionCurrency,
406
                $transactionAmount,
407
                $transactionAmountConverted,
408
                $paymentMethod,
409
                $paymentSystem,
410
                $paymentMidName,
411
                $paymentAccountId,
412
                $merchantCountry,
413
                $mcc,
414
                $acquirerMerchantId
415
            )
416
            ->addBillingData(
417
                $billingFirstName,
418
                $billingLastName,
419
                $billingFullName,
420
                $billingCountry,
421
                $billingState,
422
                $billingCity,
423
                $billingAddress,
424
                $billingZip
425
            )
426
            ->addCardData($cardBin, $cardLast4, $expirationMonth, $expirationYear, $cardId)
427
            ->addUserData(
428
                $email,
429
                $userId,
430
                $phone,
431
                $userName,
432
                $firstName,
433
                $lastName,
434
                $gender,
435
                $age,
436
                $country
437
            )
438
            ->addProductData($productQuantity, $productName, $productDescription)
439
            ->addWebsiteData($websiteUrl, null, $affiliateId, $campaign)
440
            ->addIpData(null, null, $merchantIp)
441
            ->addGroupId($groupId);
442
443
    }
444
445
    /**
446
     * Returns builder for install request
447
     *
448
     * @param string $sequenceId
449
     * @param string|null $userId
450
     * @param int|null $installTimestamp
451
     * @param string|null $country
452
     * @param string|null $websiteUrl
453
     * @param string|null $trafficSource
454
     * @param string|null $affiliateId
455
     * @param string|null $campaign
456
     * @param string|null $groupId
457
     * @return Builder
458
     */
459
    public static function installEvent(
460
        $sequenceId,
461
        $userId = null,
462
        $installTimestamp = null,
463
        $country = null,
464
        $websiteUrl = null,
465
        $trafficSource = null,
466
        $affiliateId = null,
467
        $campaign = null,
468
        $groupId = null
469
    ) {
470
        $builder = new self('install', $sequenceId);
471
        if ($installTimestamp === null) {
472
            $installTimestamp = time();
473
        }
474
475
        return $builder->addInstallData(
476
            $installTimestamp
477
        )->addWebsiteData($websiteUrl, $trafficSource, $affiliateId, $campaign)
478
        ->addShortUserData(null, $userId, null, null, null, $country)
479
        ->addGroupId($groupId);
480
    }
481
482
    /**
483
     * Returns builder for refund request
484
     *
485
     * @param string $sequenceId
486
     * @param string $refundId
487
     * @param int|float $refundAmount
488
     * @param string $refundCurrency
489
     * @param int|null $refundTimestamp
490
     * @param int|float|null $refundAmountConverted
491
     * @param string|null $refundSource
492
     * @param string|null $refundType
493
     * @param string|null $refundCode
494
     * @param string|null $refundReason
495
     * @param string|null $agentId
496
     * @param string|null $refundMethod
497
     * @param string|null $refundSystem
498
     * @param string|null $refundMid
499
     * @param string|null $email
500
     * @param string|null $phone
501
     * @param string|null $userId
502
     * @param string|null $groupId
503
     *
504
     * @return Builder
505
     */
506
    public static function refundEvent(
507
        $sequenceId,
508
        $refundId,
509
        $refundAmount,
510
        $refundCurrency,
511
        $refundTimestamp = null,
512
        $refundAmountConverted = null,
513
        $refundSource = null,
514
        $refundType = null,
515
        $refundCode = null,
516
        $refundReason = null,
517
        $agentId = null,
518
        $refundMethod = null,
519
        $refundSystem = null,
520
        $refundMid = null,
521
        $email = null,
522
        $phone = null,
523
        $userId = null,
524
        $groupId = null
525
    ) {
526
        $builder = new self('refund', $sequenceId);
527
        if ($refundTimestamp === null) {
528
            $refundTimestamp = time();
529
        }
530
531
        return $builder->addRefundData(
532
            $refundId,
533
            $refundTimestamp,
534
            $refundAmount,
535
            $refundCurrency,
536
            $refundAmountConverted,
537
            $refundSource,
538
            $refundType,
539
            $refundCode,
540
            $refundReason,
541
            $agentId,
542
            $refundMethod,
543
            $refundSystem,
544
            $refundMid
545
        )->addUserData($email, $userId, $phone)->addGroupId($groupId);
546
    }
547
548
    /**
549
     * Returns builder for transfer request
550
     *
551
     * @param string $sequenceId
552
     * @param string $eventId
553
     * @param float $amount
554
     * @param string $currency
555
     * @param string $accountId
556
     * @param string $secondAccountId
557
     * @param string $accountSystem
558
     * @param string $userId
559
     * @param string|null $method
560
     * @param int|null $eventTimestamp
561
     * @param float|null $amountConverted
562
     * @param string|null $email
563
     * @param string|null $phone
564
     * @param int|null $birthDate
565
     * @param string|null $firstname
566
     * @param string|null $lastname
567
     * @param string|null $fullname
568
     * @param string|null $state
569
     * @param string|null $city
570
     * @param string|null $address
571
     * @param string|null $zip
572
     * @param string|null $gender
573
     * @param string|null $country
574
     * @param string|null $operation
575
     * @param string|null $secondEmail
576
     * @param string|null $secondPhone
577
     * @param int|null $secondBirthDate
578
     * @param string|null $secondFirstname
579
     * @param string|null $secondLastname
580
     * @param string|null $secondFullname
581
     * @param string|null $secondState
582
     * @param string|null $secondCity
583
     * @param string|null $secondAddress
584
     * @param string|null $secondZip
585
     * @param string|null $secondGender
586
     * @param string|null $secondCountry
587
     * @param string|null $productDescription
588
     * @param string|null $productName
589
     * @param int|float|null $productQuantity
590
     * @param string|null $iban
591
     * @param string|null $secondIban
592
     * @param string|null $bic
593
     * @param string|null $source
594
     * @param string|null $groupId
595
     *
596
     * @return Builder
597
     */
598
    public static function transferEvent(
599
        $sequenceId,
600
        $eventId,
601
        $amount,
602
        $currency,
603
        $accountId,
604
        $secondAccountId,
605
        $accountSystem,
606
        $userId,
607
        $method = null,
608
        $eventTimestamp = null,
609
        $amountConverted = null,
610
        $email = null,
611
        $phone = null,
612
        $birthDate = null,
613
        $firstname = null,
614
        $lastname = null,
615
        $fullname = null,
616
        $state = null,
617
        $city = null,
618
        $address = null,
619
        $zip = null,
620
        $gender = null,
621
        $country = null,
622
        $operation = null,
623
        $secondEmail = null,
624
        $secondPhone = null,
625
        $secondBirthDate = null,
626
        $secondFirstname = null,
627
        $secondLastname = null,
628
        $secondFullname = null,
629
        $secondState = null,
630
        $secondCity = null,
631
        $secondAddress = null,
632
        $secondZip = null,
633
        $secondGender = null,
634
        $secondCountry = null,
635
        $productDescription = null,
636
        $productName = null,
637
        $productQuantity = null,
638
        $iban = null,
639
        $secondIban = null,
640
        $bic = null,
641
        $source = null,
642
        $groupId = null
643
    ) {
644
        $builder = new self('transfer', $sequenceId);
645
        if ($eventTimestamp === null) {
646
            $eventTimestamp = time();
647
        }
648
649
        return $builder
650
            ->addTransferData(
651
               $eventId,
652
               $eventTimestamp,
653
               $amount,
654
               $currency,
655
               $accountId,
656
               $secondAccountId,
657
               $accountSystem,
658
               $amountConverted,
659
               $method,
660
               $operation,
661
               $secondEmail,
662
               $secondPhone,
663
               $secondBirthDate,
664
               $secondFirstname,
665
               $secondLastname,
666
               $secondFullname,
667
               $secondState,
668
               $secondCity,
669
               $secondAddress,
670
               $secondZip,
671
               $secondGender,
672
               $secondCountry,
673
               $iban,
674
               $secondIban,
675
               $bic,
676
               $source
677
            )
678
            ->addUserData(
679
                $email,
680
                $userId,
681
                $phone,
682
                null,
683
                $firstname,
684
                $lastname,
685
                $gender,
686
                null,
687
                $country,
688
                null,
689
                null,
690
                null,
691
                null,
692
                null,
693
                null,
694
                null,
695
                $birthDate,
696
                $fullname,
697
                $state,
698
                $city,
699
                $address,
700
                $zip,
701
                null
702
            )
703
            ->addProductData($productQuantity, $productName, $productDescription)->addGroupId($groupId);
704
    }
705
706
    /**
707
     * Returns builder for kyc_profile request
708
     *
709
     * @param string $sequenceId
710
     * @param string $eventId
711
     * @param string $userId
712
     * @param int|null $eventTimestamp
713
     * @param string|null $groupId
714
     * @param string|null $status
715
     * @param string|null $code
716
     * @param string|null $reason
717
     * @param string|null $providerResult
718
     * @param string|null $providerCode
719
     * @param string|null $providerReason
720
     * @param string|null $profileId
721
     * @param string|null $profileType
722
     * @param string|null $profileSubType
723
     * @param string|null $firstName
724
     * @param string|null $lastName
725
     * @param string|null $fullName
726
     * @param string|null $industry
727
     * @param string|null $websiteUrl
728
     * @param string|null $description
729
     * @param int|null $birthDate
730
     * @param int|null $regDate
731
     * @param string|null $regNumber
732
     * @param string|null $vatNumber
733
     * @param string|null $email
734
     * @param bool|null $emailConfirmed
735
     * @param string|null $phone
736
     * @param bool|null $phoneConfirmed
737
     * @param string|null $country
738
     * @param string|null $state
739
     * @param string|null $city
740
     * @param string|null $address
741
     * @param string|null $zip
742
     * @param string|null $secondCountry
743
     * @param string|null $secondState
744
     * @param string|null $secondCity
745
     * @param string|null $secondAddress
746
     * @param string|null $secondZip
747
     * @param string|null $relatedProfiles
748
     *
749
     * @return Builder
750
     */
751
    public static function kycProfileEvent(
752
        $sequenceId,
753
        $eventId,
754
        $userId,
755
        $eventTimestamp = null,
756
        $groupId = null,
757
        $status = null,
758
        $code = null,
759
        $reason = null,
760
        $providerResult = null,
761
        $providerCode = null,
762
        $providerReason = null,
763
        $profileId = null,
764
        $profileType = null,
765
        $profileSubType = null,
766
        $firstName = null,
767
        $lastName = null,
768
        $fullName = null,
769
        $industry = null,
770
        $websiteUrl = null,
771
        $description = null,
772
        $birthDate = null,
773
        $regDate = null,
774
        $regNumber = null,
775
        $vatNumber = null,
776
        $email = null,
777
        $emailConfirmed = null,
778
        $phone = null,
779
        $phoneConfirmed = null,
780
        $country = null,
781
        $state = null,
782
        $city = null,
783
        $address = null,
784
        $zip = null,
785
        $secondCountry = null,
786
        $secondState = null,
787
        $secondCity = null,
788
        $secondAddress = null,
789
        $secondZip = null,
790
        $relatedProfiles = null
791
    ) {
792
        $builder = new self('kyc_profile', $sequenceId);
793
        if ($eventTimestamp === null) {
794
            $eventTimestamp = time();
795
        }
796
        return $builder
797
            ->addKycData(
798
                $eventId,
799
                $eventTimestamp,
800
                $groupId,
801
                $status,
802
                $code,
803
                $reason,
804
                $providerResult,
805
                $providerCode,
806
                $providerReason,
807
                $profileId,
808
                $profileType,
809
                $profileSubType,
810
                $industry,
811
                $description,
812
                $regDate,
813
                $regNumber,
814
                $vatNumber,
815
                $secondCountry,
816
                $secondState,
817
                $secondCity,
818
                $secondAddress,
819
                $secondZip,
820
                $relatedProfiles
821
            )
822
            ->addUserData(
823
                $email,
824
                $userId,
825
                $phone,
826
                null,
827
                $firstName,
828
                $lastName,
829
                null,
830
                null,
831
                $country,
832
                null,
833
                null,
834
                null,
835
                null,
836
                $emailConfirmed,
837
                $phoneConfirmed,
838
                null,
839
                $birthDate,
840
                $fullName,
841
                $state,
842
                $city,
843
                $address,
844
                $zip,
845
                null
846
            )
847
            ->addWebsiteData($websiteUrl);
848
    }
849
850
    /**
851
     * Returns builder for kyc_submit request
852
     *
853
     * @param string $sequenceId
854
     * @param string $eventId
855
     * @param string $userId
856
     * @param int|null $eventTimestamp
857
     * @param string|null $groupId
858
     * @param string|null $status
859
     * @param string|null $code
860
     * @param string|null $reason
861
     * @param string|null $providerResult
862
     * @param string|null $providerCode
863
     * @param string|null $providerReason
864
     *
865
     * @return Builder
866
     */
867
    public static function kycSubmitEvent(
868
        $sequenceId,
869
        $eventId,
870
        $userId,
871
        $eventTimestamp = null,
872
        $groupId = null,
873
        $status = null,
874
        $code = null,
875
        $reason = null,
876
        $providerResult = null,
877
        $providerCode = null,
878
        $providerReason = null
879
    ) {
880
        $builder = new self('kyc_submit', $sequenceId);
881
        if ($eventTimestamp === null) {
882
            $eventTimestamp = time();
883
        }
884
        return $builder
885
            ->addKycData(
886
                $eventId,
887
                $eventTimestamp,
888
                $groupId,
889
                $status,
890
                $code,
891
                $reason,
892
                $providerResult,
893
                $providerCode,
894
                $providerReason
895
            )
896
            ->addUserData(
897
                null,
898
                $userId
899
            );
900
    }
901
902
    /**
903
     * Returns builder for order_item request
904
     *
905
     * @param string $sequenceId
906
     * @param float $amount
907
     * @param string $currency
908
     * @param string $eventId
909
     * @param int $eventTimestamp
910
     * @param string $orderType
911
     * @param string|null $transactionId
912
     * @param string|null $groupId
913
     * @param string|null $affiliateId
914
     * @param float|null $amountConverted
915
     * @param string|null $campaign
916
     * @param string|null $carrier
917
     * @param string|null $carrierShippingId
918
     * @param string|null $carrierUrl
919
     * @param string|null $carrierPhone
920
     * @param int|null $couponStartDate
921
     * @param int|null $couponEndDate
922
     * @param string|null $couponId
923
     * @param string|null $couponName
924
     * @param string|null $customerComment
925
     * @param int|null $deliveryEstimate
926
     * @param string|null $email
927
     * @param string|null $firstName
928
     * @param string|null $lastName
929
     * @param string|null $phone
930
     * @param string|null $productDescription
931
     * @param string|null $productName
932
     * @param int|null $productQuantity
933
     * @param string|null $shippingAddress
934
     * @param string|null $shippingCity
935
     * @param string|null $shippingCountry
936
     * @param string|null $shippingCurrency
937
     * @param float|null $shippingFee
938
     * @param float|null $shippingFeeConverted
939
     * @param string|null $shippingState
940
     * @param string|null $shippingZip
941
     * @param string|null $socialType
942
     * @param string|null $source
943
     * @param string|null $sourceFeeCurrency
944
     * @param float|null $sourceFee
945
     * @param float|null $sourceFeeConverted
946
     * @param string|null $taxCurrency
947
     * @param float|null $taxFee
948
     * @param float|null $taxFeeConverted
949
     * @param string|null $userMerchantId
950
     * @param string|null $websiteUrl
951
     * @param string|null $productUrl
952
     * @param string|null $productImageUrl
953
     * @return Builder
954
     */
955
    public static function orderItemEvent(
956
        $sequenceId,
957
        $amount,
958
        $currency,
959
        $eventId,
960
        $eventTimestamp,
961
        $orderType,
962
        $transactionId = null,
963
        $groupId = null,
964
        $affiliateId = null,
965
        $amountConverted = null,
966
        $campaign = null,
967
        $carrier = null,
968
        $carrierShippingId = null,
969
        $carrierUrl = null,
970
        $carrierPhone = null,
971
        $couponStartDate = null,
972
        $couponEndDate = null,
973
        $couponId = null,
974
        $couponName = null,
975
        $customerComment = null,
976
        $deliveryEstimate = null,
977
        $email = null,
978
        $firstName = null,
979
        $lastName = null,
980
        $phone = null,
981
        $productDescription = null,
982
        $productName = null,
983
        $productQuantity = null,
984
        $shippingAddress = null,
985
        $shippingCity = null,
986
        $shippingCountry = null,
987
        $shippingCurrency = null,
988
        $shippingFee = null,
989
        $shippingFeeConverted = null,
990
        $shippingState = null,
991
        $shippingZip = null,
992
        $socialType = null,
993
        $source = null,
994
        $sourceFeeCurrency = null,
995
        $sourceFee = null,
996
        $sourceFeeConverted = null,
997
        $taxCurrency = null,
998
        $taxFee = null,
999
        $taxFeeConverted = null,
1000
        $userMerchantId = null,
1001
        $websiteUrl = null,
1002
        $productUrl = null,
1003
        $productImageUrl = null
1004
    ) {
1005
        $envelopeType = 'order_item';
1006
        $builder = new self($envelopeType, $sequenceId);
1007
        if ($eventTimestamp === null) {
1008
            $eventTimestamp = time();
1009
        }
1010
        return $builder
1011
            ->addOrderData(
1012
                $envelopeType,
1013
                $amount,
1014
                $currency,
1015
                $eventId,
1016
                $eventTimestamp,
1017
                $transactionId,
1018
                $groupId,
1019
                null,
1020
                $orderType,
1021
                $amountConverted,
1022
                $campaign,
1023
                $carrier,
1024
                $carrierShippingId,
1025
                $carrierUrl,
1026
                $carrierPhone,
1027
                $couponStartDate,
1028
                $couponEndDate,
1029
                $couponId,
1030
                $couponName,
1031
                $customerComment,
1032
                $deliveryEstimate,
1033
                $shippingAddress,
1034
                $shippingCity,
1035
                $shippingCountry,
1036
                $shippingCurrency,
1037
                $shippingFee,
1038
                $shippingFeeConverted,
1039
                $shippingState,
1040
                $shippingZip,
1041
                $source,
1042
                $sourceFee,
1043
                $sourceFeeCurrency,
1044
                $sourceFeeConverted,
1045
                $taxCurrency,
1046
                $taxFee,
1047
                $taxFeeConverted,
1048
                $productUrl,
1049
                $productImageUrl
1050
            )
1051
            ->addUserData(
1052
                $email,
1053
                $userMerchantId,
1054
                $phone,
1055
                '',
1056
                $firstName,
1057
                $lastName,
1058
                '',
1059
                0,
1060
                '',
1061
                $socialType
1062
            )
1063
            -> addProductData(
1064
                $productQuantity,
1065
                $productName,
1066
                $productDescription
1067
            )
1068
            ->addWebsiteData(
1069
                $websiteUrl,
1070
                null,
1071
                $affiliateId
1072
            );
1073
    }
1074
1075
    /**
1076
     * Returns builder for order_submit request
1077
     *
1078
     * @param string $sequenceId
1079
     * @param float $amount
1080
     * @param string $currency
1081
     * @param string $eventId
1082
     * @param int $eventTimestamp
1083
     * @param int $itemsQuantity
1084
     * @param string|null $transactionId
1085
     * @param string|null $groupId
1086
     * @param string|null $affiliateId
1087
     * @param float|null $amountConverted
1088
     * @param string|null $campaign
1089
     * @param string|null $carrier
1090
     * @param string|null $carrierShippingId
1091
     * @param string|null $carrierUrl
1092
     * @param string|null $carrierPhone
1093
     * @param int|null $couponStartDate
1094
     * @param int|null $couponEndDate
1095
     * @param string|null $couponId
1096
     * @param string|null $couponName
1097
     * @param string|null $customerComment
1098
     * @param int|null $deliveryEstimate
1099
     * @param string|null $email
1100
     * @param string|null $firstName
1101
     * @param string|null $lastName
1102
     * @param string|null $phone
1103
     * @param string|null $shippingAddress
1104
     * @param string|null $shippingCity
1105
     * @param string|null $shippingCountry
1106
     * @param string|null $shippingCurrency
1107
     * @param float|null $shippingFee
1108
     * @param float|null $shippingFeeConverted
1109
     * @param string|null $shippingState
1110
     * @param string|null $shippingZip
1111
     * @param string|null $socialType
1112
     * @param string|null $source
1113
     * @param string|null $sourceFeeCurrency
1114
     * @param float|null $sourceFee
1115
     * @param float|null $sourceFeeConverted
1116
     * @param string|null $taxCurrency
1117
     * @param float|null $taxFee
1118
     * @param float|null $taxFeeConverted
1119
     * @param string|null $userMerchantId
1120
     * @param string|null $websiteUrl
1121
     * @param string|null $productUrl
1122
     * @param string|null $productImageUrl
1123
     * @return Builder
1124
     */
1125
    public static function orderSubmitEvent(
1126
        $sequenceId,
1127
        $amount,
1128
        $currency,
1129
        $eventId,
1130
        $eventTimestamp,
1131
        $itemsQuantity,
1132
        $transactionId = null,
1133
        $groupId = null,
1134
        $affiliateId = null,
1135
        $amountConverted = null,
1136
        $campaign = null,
1137
        $carrier = null,
1138
        $carrierShippingId = null,
1139
        $carrierUrl = null,
1140
        $carrierPhone = null,
1141
        $couponStartDate = null,
1142
        $couponEndDate = null,
1143
        $couponId = null,
1144
        $couponName = null,
1145
        $customerComment = null,
1146
        $deliveryEstimate = null,
1147
        $email = null,
1148
        $firstName = null,
1149
        $lastName = null,
1150
        $phone = null,
1151
        $shippingAddress = null,
1152
        $shippingCity = null,
1153
        $shippingCountry = null,
1154
        $shippingCurrency = null,
1155
        $shippingFee = null,
1156
        $shippingFeeConverted = null,
1157
        $shippingState = null,
1158
        $shippingZip = null,
1159
        $socialType = null,
1160
        $source = null,
1161
        $sourceFeeCurrency = null,
1162
        $sourceFee = null,
1163
        $sourceFeeConverted = null,
1164
        $taxCurrency = null,
1165
        $taxFee = null,
1166
        $taxFeeConverted = null,
1167
        $userMerchantId = null,
1168
        $websiteUrl = null,
1169
        $productUrl = null,
1170
        $productImageUrl = null
1171
    ) {
1172
        $envelopeType = 'order_submit';
1173
        $builder = new self($envelopeType, $sequenceId);
1174
        if ($eventTimestamp === null) {
1175
            $eventTimestamp = time();
1176
        }
1177
        return $builder
1178
            ->addOrderData(
1179
                $envelopeType,
1180
                $amount,
1181
                $currency,
1182
                $eventId,
1183
                $eventTimestamp,
1184
                $transactionId,
1185
                $groupId,
1186
                $itemsQuantity,
1187
                null,
1188
                $amountConverted,
1189
                $campaign,
1190
                $carrier,
1191
                $carrierShippingId,
1192
                $carrierUrl,
1193
                $carrierPhone,
1194
                $couponStartDate,
1195
                $couponEndDate,
1196
                $couponId,
1197
                $couponName,
1198
                $customerComment,
1199
                $deliveryEstimate,
1200
                $shippingAddress,
1201
                $shippingCity,
1202
                $shippingCountry,
1203
                $shippingCurrency,
1204
                $shippingFee,
1205
                $shippingFeeConverted,
1206
                $shippingState,
1207
                $shippingZip,
1208
                $source,
1209
                $sourceFee,
1210
                $sourceFeeCurrency,
1211
                $sourceFeeConverted,
1212
                $taxCurrency,
1213
                $taxFee,
1214
                $taxFeeConverted,
1215
                $productUrl,
1216
                $productImageUrl
1217
            )
1218
            ->addUserData(
1219
                $email,
1220
                $userMerchantId,
1221
                $phone,
1222
                '',
1223
                $firstName,
1224
                $lastName,
1225
                '',
1226
                0,
1227
                '',
1228
                $socialType
1229
            )
1230
            ->addWebsiteData(
1231
                $websiteUrl,
1232
                null,
1233
                $affiliateId
1234
            );
1235
    }
1236
1237
    /**
1238
     * Returns builder for postback request
1239
     *
1240
     * @param int|null $requestId
1241
     * @param string|null $transactionId
1242
     * @param string|null $transactionStatus
1243
     * @param string|null $code
1244
     * @param string|null $reason
1245
     * @param string|null $secure3d
1246
     * @param string|null $avsResult
1247
     * @param string|null $cvvResult
1248
     * @param string|null $pspCode
1249
     * @param string|null $pspReason
1250
     * @param string|null $arn
1251
     * @param string|null $paymentAccountId
1252
     * @return Builder
1253
     */
1254
    public static function postBackEvent(
1255
        $requestId =  null,
1256
        $transactionId = null,
1257
        $transactionStatus = null,
1258
        $code = null,
1259
        $reason = null,
1260
        $secure3d = null,
1261
        $avsResult = null,
1262
        $cvvResult = null,
1263
        $pspCode = null,
1264
        $pspReason = null,
1265
        $arn = null,
1266
        $paymentAccountId = null
1267
    ) {
1268
        $builder = new self('postback', '');
1269
        return $builder->addPostBackData(
1270
            $requestId,
1271
            $transactionId,
1272
            $transactionStatus,
1273
            $code,
1274
            $reason,
1275
            $secure3d,
1276
            $avsResult,
1277
            $cvvResult,
1278
            $pspCode,
1279
            $pspReason,
1280
            $arn,
1281
            $paymentAccountId
1282
       );
1283
    }
1284
1285
    /**
1286
     * Builder constructor.
1287
     *
1288
     * @param string $envelopeType
1289
     * @param string $sequenceId
1290
     */
1291
    public function __construct($envelopeType, $sequenceId)
1292
    {
1293
        if (!is_string($envelopeType)) {
1294
            throw new \InvalidArgumentException('Envelope type must be string');
1295
        }
1296
        if (!is_string($sequenceId)) {
1297
            throw new \InvalidArgumentException('Sequence ID must be string');
1298
        }
1299
1300
        $this->type = $envelopeType;
1301
        $this->sequenceId = $sequenceId;
1302
    }
1303
1304
    /**
1305
     * Returns built envelope
1306
     *
1307
     * @return EnvelopeInterface
1308
     */
1309
    public function build()
1310
    {
1311
        return new Envelope(
1312
            $this->type,
1313
            $this->sequenceId,
1314
            $this->identities,
1315
            array_filter($this->data, function ($data) {
1316
                return $data !== null;
1317
            })
1318
        );
1319
    }
1320
1321
    /**
1322
     * Replaces value in internal array if provided value not empty
1323
     *
1324
     * @param string $key
1325
     * @param string|int|float|bool|null $value
1326
     */
1327
    private function replace($key, $value)
1328
    {
1329
        if ($value !== null && $value !== '' && $value !== 0 && $value !== 0.0) {
1330
            $this->data[$key] = $value;
1331
        }
1332
    }
1333
1334
    /**
1335
     * Adds identity node
1336
     *
1337
     * @param IdentityNodeInterface $identity
1338
     *
1339
     * @return $this
1340
     */
1341
    public function addIdentity(IdentityNodeInterface $identity)
1342
    {
1343
        $this->identities[] = $identity;
1344
        return $this;
1345
    }
1346
1347
    /**
1348
     * Provides website URL to envelope
1349
     *
1350
     * @param string|null $websiteUrl
1351
     * @param string|null $traffic_source
1352
     * @param string|null $affiliate_id
1353
     * @param string|null $campaign
1354
     *
1355
     * @return $this
1356
     */
1357
    public function addWebsiteData($websiteUrl = null, $traffic_source = null, $affiliate_id = null, $campaign = null)
1358
    {
1359
        if ($websiteUrl !== null && !is_string($websiteUrl)) {
1360
            throw new \InvalidArgumentException('Website URL must be string');
1361
        }
1362
        if ($traffic_source !== null && !is_string($traffic_source)) {
1363
            throw new \InvalidArgumentException('Traffic source must be string');
1364
        }
1365
        if ($affiliate_id !== null && !is_string($affiliate_id)) {
1366
            throw new \InvalidArgumentException('Affiliate ID must be string');
1367
        }
1368
        if ($campaign !== null && !is_string($campaign)) {
1369
            throw new \InvalidArgumentException('Campaign must be string');
1370
        }
1371
1372
        $this->replace('website_url', $websiteUrl);
1373
        $this->replace('traffic_source', $traffic_source);
1374
        $this->replace('affiliate_id', $affiliate_id);
1375
        $this->replace('campaign', $campaign);
1376
        return $this;
1377
    }
1378
1379
    /**
1380
     * Provides IP information for envelope
1381
     *
1382
     * @param string|null $ip User's IP address
1383
     * @param string|null $realIp User's real IP address, if available
1384
     * @param string|null $merchantIp Your website's IP address
1385
     *
1386
     * @return $this
1387
     */
1388
    public function addIpData($ip = '', $realIp = '', $merchantIp = '')
1389
    {
1390
        if ($ip !== null && !is_string($ip)) {
1391
            throw new \InvalidArgumentException('IP must be string');
1392
        }
1393
        if ($realIp !== null && !is_string($realIp)) {
1394
            throw new \InvalidArgumentException('Real IP must be string');
1395
        }
1396
        if ($merchantIp !== null && !is_string($merchantIp)) {
1397
            throw new \InvalidArgumentException('Merchant IP must be string');
1398
        }
1399
1400
        $this->replace('ip', $ip);
1401
        $this->replace('real_ip', $realIp);
1402
        $this->replace('merchant_ip', $merchantIp);
1403
1404
        return $this;
1405
    }
1406
1407
    /**
1408
     * Provides browser information for envelope
1409
     *
1410
     * @param string|null $deviceFingerprint
1411
     * @param string|null $userAgent
1412
     * @param string|null $cpuClass
1413
     * @param string|null $screenOrientation
1414
     * @param string|null $screenResolution
1415
     * @param string|null $os
1416
     * @param int|null $timezoneOffset
1417
     * @param string|null $languages
1418
     * @param string|null $language
1419
     * @param string|null $languageBrowser
1420
     * @param string|null $languageUser
1421
     * @param string|null $languageSystem
1422
     * @param bool|null $cookieEnabled
1423
     * @param bool|null $doNotTrack
1424
     * @param bool|null $ajaxValidation
1425
     * @param string|null $deviceId
1426
     * @param string|null $ipList
1427
     * @param string|null $plugins
1428
     * @param string|null $refererUrl
1429
     * @param string|null $originUrl
1430
     * @param string|null $clientResolution
1431
     * @return $this
1432
     */
1433
    public function addBrowserData(
1434
        $deviceFingerprint = '',
1435
        $userAgent = '',
1436
        $cpuClass = '',
1437
        $screenOrientation = '',
1438
        $screenResolution = '',
1439
        $os = '',
1440
        $timezoneOffset = null,
1441
        $languages = '',
1442
        $language = '',
1443
        $languageBrowser = '',
1444
        $languageUser = '',
1445
        $languageSystem = '',
1446
        $cookieEnabled = null,
1447
        $doNotTrack = null,
1448
        $ajaxValidation = null,
1449
        $deviceId = '',
1450
        $ipList = null,
1451
        $plugins = null,
1452
        $refererUrl = null,
1453
        $originUrl = null,
1454
        $clientResolution = null
1455
    ) {
1456
        if ($deviceFingerprint !== null && !is_string($deviceFingerprint)) {
1457
            throw new \InvalidArgumentException('Device fingerprint must be string');
1458
        }
1459
        if ($userAgent !== null && !is_string($userAgent)) {
1460
            throw new \InvalidArgumentException('User agent must be string');
1461
        }
1462
        if ($cpuClass !== null && !is_string($cpuClass)) {
1463
            throw new \InvalidArgumentException('CPU class must be string');
1464
        }
1465
        if ($screenOrientation !== null && !is_string($screenOrientation)) {
1466
            throw new \InvalidArgumentException('Screen orientation must be string');
1467
        }
1468
        if ($screenResolution !== null && !is_string($screenResolution)) {
1469
            throw new \InvalidArgumentException('Screen resolution must be string');
1470
        }
1471
        if ($os !== null && !is_string($os)) {
1472
            throw new \InvalidArgumentException('OS must be string');
1473
        }
1474
        if ($timezoneOffset !== null && $timezoneOffset !== null && !is_int($timezoneOffset)) {
1475
            throw new \InvalidArgumentException('Timezone offset must be integer or null');
1476
        }
1477
        if ($languages !== null && !is_string($languages)) {
1478
            throw new \InvalidArgumentException('Languages must be string');
1479
        }
1480
        if ($language !== null && !is_string($language)) {
1481
            throw new \InvalidArgumentException('Language must be string');
1482
        }
1483
        if ($languageBrowser !== null && !is_string($languageBrowser)) {
1484
            throw new \InvalidArgumentException('Browser language must be string');
1485
        }
1486
        if ($languageUser !== null && !is_string($languageUser)) {
1487
            throw new \InvalidArgumentException('User language must be string');
1488
        }
1489
        if ($languageSystem !== null && !is_string($languageSystem)) {
1490
            throw new \InvalidArgumentException('System language must be string');
1491
        }
1492
        if ($cookieEnabled !== null && !is_bool($cookieEnabled)) {
1493
            throw new \InvalidArgumentException('Cookie enabled flag must be boolean');
1494
        }
1495
        if ($doNotTrack !== null && !is_bool($doNotTrack)) {
1496
            throw new \InvalidArgumentException('DNT flag must be boolean');
1497
        }
1498
        if ($ajaxValidation !== null && !is_bool($ajaxValidation)) {
1499
            throw new \InvalidArgumentException('AJAX validation flag must be boolean');
1500
        }
1501
        if ($deviceId !== null && !is_string($deviceId)) {
1502
            throw new \InvalidArgumentException('Device id must be string');
1503
        }
1504
        if ($ipList !== null && !is_string($ipList)) {
1505
            throw new \InvalidArgumentException('Ip list must be string');
1506
        }
1507
        if ($plugins !== null && !is_string($plugins)) {
1508
            throw new \InvalidArgumentException('Plugins must be string');
1509
        }
1510
        if ($refererUrl !== null && !is_string($refererUrl)) {
1511
            throw new \InvalidArgumentException('Referer url must be string');
1512
        }
1513
        if ($originUrl !== null && !is_string($originUrl)) {
1514
            throw new \InvalidArgumentException('Origin url must be string');
1515
        }
1516
        if ($clientResolution !== null && !is_string($clientResolution)) {
1517
            throw new \InvalidArgumentException('Client resolution must be string');
1518
        }
1519
1520
        $this->replace('device_fingerprint', $deviceFingerprint);
1521
        $this->replace('user_agent', $userAgent);
1522
        $this->replace('cpu_class', $cpuClass);
1523
        $this->replace('screen_orientation', $screenOrientation);
1524
        $this->replace('screen_resolution', $screenResolution);
1525
        $this->replace('os', $os);
1526
        $this->replace('timezone_offset', $timezoneOffset);
1527
        $this->replace('languages', $languages);
1528
        $this->replace('language', $language);
1529
        $this->replace('language_browser', $languageBrowser);
1530
        $this->replace('language_system', $languageSystem);
1531
        $this->replace('language_user', $languageUser);
1532
        $this->replace('cookie_enabled', $cookieEnabled);
1533
        $this->replace('do_not_track', $doNotTrack);
1534
        $this->replace('ajax_validation', $ajaxValidation);
1535
        $this->replace('device_id', $deviceId);
1536
        $this->replace('local_ip_list', $ipList);
1537
        $this->replace('plugins', $plugins);
1538
        $this->replace('referer_url', $refererUrl);
1539
        $this->replace('origin_url', $originUrl);
1540
        $this->replace('client_resolution', $clientResolution);
1541
1542
        return $this;
1543
    }
1544
1545
    /**
1546
     * Provides user data for envelope
1547
     *
1548
     * @param string|null $email
1549
     * @param string|null $userId
1550
     * @param string|null $phone
1551
     * @param string|null $userName
1552
     * @param string|null $firstName
1553
     * @param string|null $lastName
1554
     * @param string|null $gender
1555
     * @param int|null $age
1556
     * @param string|null $country
1557
     * @param string|null $socialType
1558
     * @param int|null $registrationTimestamp
1559
     * @param int|null $loginTimeStamp
1560
     * @param int|null $confirmationTimeStamp
1561
     * @param bool|null $emailConfirmed
1562
     * @param bool|null $phoneConfirmed
1563
     * @param bool|null $loginFailed
1564
     * @param int|null $birthDate
1565
     * @param string|null $fullname
1566
     * @param string|null $state
1567
     * @param string|null $city
1568
     * @param string|null $address
1569
     * @param string|null $zip
1570
     * @param string|null $password
1571
     *
1572
     * @return $this
1573
     */
1574
    public function addUserData(
1575
        $email = '',
1576
        $userId = '',
1577
        $phone = '',
1578
        $userName = '',
1579
        $firstName = '',
1580
        $lastName = '',
1581
        $gender = '',
1582
        $age = 0,
1583
        $country = '',
1584
        $socialType = '',
1585
        $registrationTimestamp = 0,
1586
        $loginTimeStamp = 0,
1587
        $confirmationTimeStamp = 0,
1588
        $emailConfirmed = null,
1589
        $phoneConfirmed = null,
1590
        $loginFailed = null,
1591
        $birthDate = null,
1592
        $fullname = null,
1593
        $state = null,
1594
        $city = null,
1595
        $address = null,
1596
        $zip = null,
1597
        $password = ''
1598
    )
1599
    {
1600
        if ($userName !== null && !is_string($userName)) {
1601
            throw new \InvalidArgumentException('User name must be string');
1602
        }
1603
        if ($password !== null && !is_string($password)) {
1604
            throw new \InvalidArgumentException('Password must be string');
1605
        }
1606
        if ($gender !== null && !is_string($gender)) {
1607
            throw new \InvalidArgumentException('Gender must be string');
1608
        }
1609
        if ($age !== null && !is_int($age)) {
1610
            throw new \InvalidArgumentException('Age must be integer');
1611
        }
1612
        if ($socialType !== null && !is_string($socialType)) {
1613
            throw new \InvalidArgumentException('Social type must be string');
1614
        }
1615
        if ($registrationTimestamp !== null && !is_int($registrationTimestamp)) {
1616
            throw new \InvalidArgumentException('Registration timestamp must be integer');
1617
        }
1618
        if ($loginTimeStamp !== null && !is_int($loginTimeStamp)) {
1619
            throw new \InvalidArgumentException('Login timestamp must be integer');
1620
        }
1621
        if ($confirmationTimeStamp !== null && !is_int($confirmationTimeStamp)) {
1622
            throw new \InvalidArgumentException('Confirmation timestamp must be integer');
1623
        }
1624
        if ($birthDate !== null && !is_int($birthDate)) {
1625
            throw new \InvalidArgumentException('Birthdate timestamp must be integer');
1626
        }
1627
        if ($emailConfirmed !== null && !is_bool($emailConfirmed)) {
1628
            throw new \InvalidArgumentException('Email confirmed flag must be boolean');
1629
        }
1630
        if ($phoneConfirmed !== null && !is_bool($phoneConfirmed)) {
1631
            throw new \InvalidArgumentException('Phone confirmed flag must be boolean');
1632
        }
1633
        if ($loginFailed !== null && !is_bool($loginFailed)) {
1634
            throw new \InvalidArgumentException('Login failed flag must be boolean');
1635
        }
1636
        if ($fullname !== null && !is_string($fullname)) {
1637
            throw new \InvalidArgumentException('Fullname must be string');
1638
        }
1639
        if ($state !== null && !is_string($state)) {
1640
            throw new \InvalidArgumentException('State must be string');
1641
        }
1642
        if ($city !== null && !is_string($city)) {
1643
            throw new \InvalidArgumentException('City must be string');
1644
        }
1645
        if ($address !== null && !is_string($address)) {
1646
            throw new \InvalidArgumentException('Address must be string');
1647
        }
1648
        if ($zip !== null && !is_string($zip)) {
1649
            throw new \InvalidArgumentException('Zip must be string');
1650
        }
1651
1652
        $this->addShortUserData($email, $userId, $phone, $firstName, $lastName, $country);
1653
1654
        $this->replace('user_name', $userName);
1655
        $this->replace('gender', $gender);
1656
        $this->replace('age', $age);
1657
        $this->replace('social_type', $socialType);
1658
        $this->replace('registration_timestamp', $registrationTimestamp);
1659
        $this->replace('login_timestamp', $loginTimeStamp);
1660
        $this->replace('confirmation_timestamp', $confirmationTimeStamp);
1661
        $this->replace('email_confirmed', $emailConfirmed);
1662
        $this->replace('phone_confirmed', $phoneConfirmed);
1663
        $this->replace('login_failed', $loginFailed);
1664
        $this->replace('birth_date', $birthDate);
1665
        $this->replace('fullname', $fullname);
1666
        $this->replace('state', $state);
1667
        $this->replace('city', $city);
1668
        $this->replace('address', $address);
1669
        $this->replace('zip', $zip);
1670
        $this->replace('password', $password);
1671
1672
        return $this;
1673
    }
1674
1675
    /**
1676
     * Provides user data for envelope
1677
     *
1678
     * @param string|null $email
1679
     * @param string|null $userId
1680
     * @param string|null $phone
1681
     * @param string|null $firstName
1682
     * @param string|null $lastName
1683
     * @param string|null $country
1684
     *
1685
     * @return $this
1686
     */
1687
    public function addShortUserData(
1688
        $email = '',
1689
        $userId = '',
1690
        $phone = '',
1691
        $firstName = '',
1692
        $lastName = '',
1693
        $country = ''
1694
    ) {
1695
        if ($email !== null && !is_string($email)) {
1696
            throw new \InvalidArgumentException('Email must be string');
1697
        }
1698
        if (is_int($userId)) {
1699
            $userId = strval($userId);
1700
        }
1701
        if ($userId !== null && !is_string($userId)) {
1702
            throw new \InvalidArgumentException('UserId must be string or integer');
1703
        }
1704
        if ($phone !== null && !is_string($phone)) {
1705
            throw new \InvalidArgumentException('Phone must be string');
1706
        }
1707
        if ($firstName !== null && !is_string($firstName)) {
1708
            throw new \InvalidArgumentException('First name must be string');
1709
        }
1710
        if ($lastName !== null && !is_string($lastName)) {
1711
            throw new \InvalidArgumentException('Last name must be string');
1712
        }
1713
        if ($country !== null && !is_string($country)) {
1714
            throw new \InvalidArgumentException('Country must be string');
1715
        }
1716
1717
        $this->replace('email', $email);
1718
        $this->replace('user_merchant_id', $userId);
1719
        $this->replace('phone', $phone);
1720
        $this->replace('firstname', $firstName);
1721
        $this->replace('lastname', $lastName);
1722
        $this->replace('country', $country);
1723
1724
        return $this;
1725
    }
1726
1727
    /**
1728
     * Provides credit card data to envelope
1729
     *
1730
     * @param string|null $transactionId
1731
     * @param string|null $transactionSource
1732
     * @param string|null $transactionType
1733
     * @param string|null $transactionMode
1734
     * @param string|null $transactionTimestamp
1735
     * @param string|null $transactionCurrency
1736
     * @param string|null $transactionAmount
1737
     * @param float|null $amountConverted
1738
     * @param string|null $paymentMethod
1739
     * @param string|null $paymentSystem
1740
     * @param string|null $paymentMidName
1741
     * @param string|null $paymentAccountId
1742
     * @param string|null $merchantCountry
1743
     * @param string|null $mcc
1744
     * @param string|null $acquirerMerchantId
1745
     * @return $this
1746
     */
1747
    public function addCCTransactionData(
1748
        $transactionId,
1749
        $transactionSource,
1750
        $transactionType,
1751
        $transactionMode,
1752
        $transactionTimestamp,
1753
        $transactionCurrency,
1754
        $transactionAmount,
1755
        $amountConverted = null,
1756
        $paymentMethod = null,
1757
        $paymentSystem = null,
1758
        $paymentMidName = null,
1759
        $paymentAccountId = null,
1760
        $merchantCountry = null,
1761
        $mcc = null,
1762
        $acquirerMerchantId = null
1763
    ) {
1764
        if ($transactionId !== null && !is_string($transactionId)) {
1765
            throw new \InvalidArgumentException('Transaction ID must be string');
1766
        }
1767
        if ($transactionSource !== null && !is_string($transactionSource)) {
1768
            throw new \InvalidArgumentException('Transaction source must be string');
1769
        }
1770
        if ($transactionType !== null && !is_string($transactionType)) {
1771
            throw new \InvalidArgumentException('Transaction type must be string');
1772
        }
1773
        if ($transactionMode !== null && !is_string($transactionMode)) {
1774
            throw new \InvalidArgumentException('Transaction mode must be string');
1775
        }
1776
        if ($transactionTimestamp !== null && !is_int($transactionTimestamp)) {
1777
            throw new \InvalidArgumentException('Transaction timestamp must be integer');
1778
        }
1779
        if ($transactionAmount !== null && !is_int($transactionAmount) && !is_float($transactionAmount)) {
1780
            throw new \InvalidArgumentException('Transaction amount must be float');
1781
        }
1782
        if ($transactionCurrency !== null && !is_string($transactionCurrency)) {
1783
            throw new \InvalidArgumentException('Transaction currency must be string');
1784
        }
1785
        if ($paymentMethod !== null && !is_string($paymentMethod)) {
1786
            throw new \InvalidArgumentException('Payment method must be string');
1787
        }
1788
        if ($paymentSystem !== null && !is_string($paymentSystem)) {
1789
            throw new \InvalidArgumentException('Payment system must be string');
1790
        }
1791
        if ($paymentMidName !== null && !is_string($paymentMidName)) {
1792
            throw new \InvalidArgumentException('Payment MID name must be string');
1793
        }
1794
        if ($paymentAccountId !== null && !is_string($paymentAccountId)) {
1795
            throw new \InvalidArgumentException('Payment account id must be string');
1796
        }
1797 View Code Duplication
        if ($amountConverted !== null && !is_int($amountConverted) && !is_float($amountConverted)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1798
            throw new \InvalidArgumentException('Transaction amount converted must be float');
1799
        }
1800
1801
        if ($merchantCountry !== null && !is_string($merchantCountry)) {
1802
            throw new \InvalidArgumentException('Merchant country must be string');
1803
        }
1804
        if ($mcc !== null && !is_string($mcc)) {
1805
            throw new \InvalidArgumentException('MCC must be string');
1806
        }
1807
        if ($acquirerMerchantId !== null && !is_string($acquirerMerchantId)) {
1808
            throw new \InvalidArgumentException('Acquirer merchant id be string');
1809
        }
1810
        $this->replace('transaction_id', $transactionId);
1811
        $this->replace('transaction_source', $transactionSource);
1812
        $this->replace('transaction_type', $transactionType);
1813
        $this->replace('transaction_mode', $transactionMode);
1814
        $this->replace('transaction_timestamp', $transactionTimestamp);
1815
        $this->replace('transaction_amount', floatval($transactionAmount));
1816
        $this->replace('transaction_amount_converted', floatval($amountConverted));
1817
        $this->replace('transaction_currency', $transactionCurrency);
1818
        $this->replace('payment_method', $paymentMethod);
1819
        $this->replace('payment_system', $paymentSystem);
1820
        $this->replace('payment_mid', $paymentMidName);
1821
        $this->replace('payment_account_id', $paymentAccountId);
1822
        $this->replace('merchant_country', $merchantCountry);
1823
        $this->replace('mcc', $mcc);
1824
        $this->replace('acquirer_merchant_id', $acquirerMerchantId);
1825
1826
        return $this;
1827
    }
1828
1829
    /**
1830
     * Provides Card data to envelope
1831
     *
1832
     * @param string|null $cardId
1833
     * @param int|null $cardBin
1834
     * @param string|null $cardLast4
1835
     * @param int|null $expirationMonth
1836
     * @param int|null $expirationYear
1837
     *
1838
     * @return $this
1839
     */
1840
    public function addCardData(
1841
        $cardBin,
1842
        $cardLast4,
1843
        $expirationMonth,
1844
        $expirationYear,
1845
        $cardId = null
1846
    ) {
1847
        if ($cardId !== null && !is_string($cardId)) {
1848
            throw new \InvalidArgumentException('Card ID must be string');
1849
        }
1850
        if ($cardBin !== null && !is_int($cardBin)) {
1851
            throw new \InvalidArgumentException('Card BIN must be integer');
1852
        }
1853
        if ($cardLast4 !== null && !is_string($cardLast4)) {
1854
            throw new \InvalidArgumentException('Card last4  must be string');
1855
        }
1856
        if ($expirationMonth !== null && !is_int($expirationMonth)) {
1857
            throw new \InvalidArgumentException('Expiration month must be integer');
1858
        }
1859
        if ($expirationYear !== null && !is_int($expirationYear)) {
1860
            throw new \InvalidArgumentException('Expiration year must be integer');
1861
        }
1862
1863
        $this->replace('card_id', $cardId);
1864
        $this->replace('card_bin', $cardBin);
1865
        $this->replace('card_last4', $cardLast4);
1866
        $this->replace('expiration_month', $expirationMonth);
1867
        $this->replace('expiration_year', $expirationYear);
1868
1869
        return $this;
1870
    }
1871
1872
    /**
1873
     * Provides billing data to envelope
1874
     *
1875
     * @param string|null $billingFirstName
1876
     * @param string|null $billingLastName
1877
     * @param string|null $billingFullName
1878
     * @param string|null $billingCountry
1879
     * @param string|null $billingState
1880
     * @param string|null $billingCity
1881
     * @param string|null $billingAddress
1882
     * @param string|null $billingZip
1883
     *
1884
     * @return $this
1885
     */
1886
    public function addBillingData(
1887
        $billingFirstName = null,
1888
        $billingLastName = null,
1889
        $billingFullName = null,
1890
        $billingCountry = null,
1891
        $billingState = null,
1892
        $billingCity = null,
1893
        $billingAddress = null,
1894
        $billingZip = null
1895
    ) {
1896
        if ($billingFirstName !== null && !is_string($billingFirstName)) {
1897
            throw new \InvalidArgumentException('Billing first name must be string');
1898
        }
1899
        if ($billingLastName !== null && !is_string($billingLastName)) {
1900
            throw new \InvalidArgumentException('Billing last name must be string');
1901
        }
1902
        if ($billingFullName !== null && !is_string($billingFullName)) {
1903
            throw new \InvalidArgumentException('Billing full name must be string');
1904
        }
1905
        if ($billingCountry !== null && !is_string($billingCountry)) {
1906
            throw new \InvalidArgumentException('Billing country name must be string');
1907
        }
1908
        if ($billingState !== null && !is_string($billingState)) {
1909
            throw new \InvalidArgumentException('Billing state must be string');
1910
        }
1911
        if ($billingCity !== null && !is_string($billingCity)) {
1912
            throw new \InvalidArgumentException('Billing city must be string');
1913
        }
1914
        if ($billingAddress !== null && !is_string($billingAddress)) {
1915
            throw new \InvalidArgumentException('Billing address must be string');
1916
        }
1917
        if ($billingZip !== null && !is_string($billingZip)) {
1918
            throw new \InvalidArgumentException('Billing zip must be string');
1919
        }
1920
1921
        $this->replace('billing_firstname', $billingFirstName);
1922
        $this->replace('billing_lastname', $billingLastName);
1923
        $this->replace('billing_fullname', $billingFullName);
1924
        $this->replace('billing_country', $billingCountry);
1925
        $this->replace('billing_state', $billingState);
1926
        $this->replace('billing_city', $billingCity);
1927
        $this->replace('billing_address', $billingAddress);
1928
        $this->replace('billing_zip', $billingZip);
1929
1930
        return $this;
1931
    }
1932
1933
    /**
1934
     * Provides product information to envelope
1935
     *
1936
     * @param float|null $productQuantity
1937
     * @param string|null $productName
1938
     * @param string|null $productDescription
1939
     *
1940
     * @return $this
1941
     */
1942
    public function addProductData(
1943
        $productQuantity = null,
1944
        $productName = null,
1945
        $productDescription = null
1946
    ) {
1947
        if ($productQuantity !== null && !is_int($productQuantity) && !is_float($productQuantity)) {
1948
            throw new \InvalidArgumentException('Product quantity must be int or float');
1949
        }
1950
        if ($productName !== null && !is_string($productName)) {
1951
            throw new \InvalidArgumentException('Product name must be string');
1952
        }
1953
        if ($productDescription !== null && !is_string($productDescription)) {
1954
            throw new \InvalidArgumentException('Product description must be string');
1955
        }
1956
1957
        $this->replace('product_quantity', $productQuantity);
1958
        $this->replace('product_name', $productName);
1959
        $this->replace('product_description', $productDescription);
1960
1961
        return $this;
1962
    }
1963
1964
    /**
1965
     * Provides payout information to envelope
1966
     *
1967
     * @param string $payoutId
1968
     * @param int $payoutTimestamp
1969
     * @param int|float $payoutAmount
1970
     * @param string $payoutCurrency
1971
     * @param string|null $payoutCardId
1972
     * @param string|null $payoutAccountId
1973
     * @param string|null $payoutMethod
1974
     * @param string|null $payoutSystem
1975
     * @param string|null $payoutMid
1976
     * @param int|float|null $amountConverted
1977
     * @param int|null $payoutCardBin
1978
     * @param string|null $payoutCardLast4
1979
     * @param int|null $payoutExpirationMonth
1980
     * @param int|null $payoutExpirationYear
1981
     *
1982
     * @return $this
1983
     */
1984
    public function addPayoutData(
1985
        $payoutId,
1986
        $payoutTimestamp,
1987
        $payoutAmount,
1988
        $payoutCurrency,
1989
        $payoutCardId =  null,
1990
        $payoutAccountId = null,
1991
        $payoutMethod = null,
1992
        $payoutSystem = null,
1993
        $payoutMid = null,
1994
        $amountConverted = null,
1995
        $payoutCardBin = null,
1996
        $payoutCardLast4 = null,
1997
        $payoutExpirationMonth = null,
1998
        $payoutExpirationYear = null
1999
    ) {
2000
        if (!is_string($payoutId)) {
2001
            throw new \InvalidArgumentException('Payout ID must be string');
2002
        }
2003
        if (!is_int($payoutTimestamp)) {
2004
            throw new \InvalidArgumentException('Payout timestamp must be int');
2005
        }
2006
        if (!is_float($payoutAmount) && !is_int($payoutAmount)) {
2007
            throw new \InvalidArgumentException('Amount must be number');
2008
        }
2009
        if (!is_string($payoutCurrency)) {
2010
            throw new \InvalidArgumentException('Payout currency must be string');
2011
        }
2012
        if ($payoutAccountId !== null && !is_string($payoutAccountId)) {
2013
            throw new \InvalidArgumentException('Account ID must be string');
2014
        }
2015
        if ($payoutCardId !== null && !is_string($payoutCardId)) {
2016
            throw new \InvalidArgumentException('Card ID must be string');
2017
        }
2018
        if ($payoutMethod !== null && !is_string($payoutMethod)) {
2019
            throw new \InvalidArgumentException('Payout method must be string');
2020
        }
2021
        if ($payoutSystem !== null && !is_string($payoutSystem)) {
2022
            throw new \InvalidArgumentException('Payout system must be string');
2023
        }
2024
        if ($payoutMid !== null && !is_string($payoutMid)) {
2025
            throw new \InvalidArgumentException('Payout MID must be string');
2026
        }
2027 View Code Duplication
        if ($amountConverted !== null && !is_float($amountConverted) && !is_int($amountConverted)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2028
            throw new \InvalidArgumentException('Payout converted amount must be number');
2029
        }
2030
        if ($payoutCardBin !== null && !is_int($payoutCardBin)) {
2031
            throw new \InvalidArgumentException('Payout card BIN must be integer');
2032
        }
2033
        if ($payoutCardLast4 !== null && !is_string($payoutCardLast4)) {
2034
            throw new \InvalidArgumentException('Payout last 4 must be string');
2035
        }
2036
        if ($payoutExpirationMonth !== null && !is_int($payoutExpirationMonth)) {
2037
            throw new \InvalidArgumentException('Payout card expiration month must be integer');
2038
        }
2039
        if ($payoutExpirationYear !== null && !is_int($payoutExpirationYear)) {
2040
            throw new \InvalidArgumentException('Payout card expiration year must be integer');
2041
        }
2042
2043
        $this->replace('payout_id', $payoutId);
2044
        $this->replace('payout_timestamp', $payoutTimestamp);
2045
        $this->replace('payout_card_id', $payoutCardId);
2046
        $this->replace('payout_account_id', $payoutAccountId);
2047
        $this->replace('payout_amount', (float) $payoutAmount);
2048
        $this->replace('payout_currency', $payoutCurrency);
2049
        $this->replace('payout_method', $payoutMethod);
2050
        $this->replace('payout_system', $payoutSystem);
2051
        $this->replace('payout_mid', $payoutMid);
2052
        $this->replace('payout_amount_converted', (float) $amountConverted);
2053
        $this->replace('payout_card_bin', $payoutCardBin);
2054
        $this->replace('payout_card_last4', $payoutCardLast4);
2055
        $this->replace('payout_expiration_month', $payoutExpirationMonth);
2056
        $this->replace('payout_expiration_year', $payoutExpirationYear);
2057
2058
        return $this;
2059
    }
2060
2061
    /**
2062
     * Provides install information to envelope
2063
     *
2064
     * @param int $installTimestamp
2065
     *
2066
     * @return $this
2067
     */
2068
    public function addInstallData($installTimestamp)
2069
    {
2070
        if (!is_int($installTimestamp)) {
2071
            throw new \InvalidArgumentException('Install timestamp must be int');
2072
        }
2073
2074
        $this->replace('install_timestamp', $installTimestamp);
2075
2076
        return $this;
2077
    }
2078
2079
    /**
2080
     * Provides refund information to envelope
2081
     *
2082
     * @param string $refundId
2083
     * @param int|float $refundAmount
2084
     * @param string $refundCurrency
2085
     * @param int|null $refundTimestamp
2086
     * @param int|float|null $refundAmountConverted
2087
     * @param string|null $refundSource
2088
     * @param string|null $refundType
2089
     * @param string|null $refundCode
2090
     * @param string|null $refundReason
2091
     * @param string|null $agentId
2092
     * @param string|null $refundMethod
2093
     * @param string|null $refundSystem
2094
     * @param string|null $refundMid
2095
     *
2096
     * @return $this
2097
     */
2098
    public function addRefundData(
2099
        $refundId,
2100
        $refundTimestamp,
2101
        $refundAmount,
2102
        $refundCurrency,
2103
        $refundAmountConverted = null,
2104
        $refundSource = null,
2105
        $refundType = null,
2106
        $refundCode = null,
2107
        $refundReason = null,
2108
        $agentId = null,
2109
        $refundMethod = null,
2110
        $refundSystem = null,
2111
        $refundMid = null
2112
    ) {
2113
        if (!is_string($refundId)) {
2114
            throw new \InvalidArgumentException('Refund ID must be string');
2115
        }
2116
        if (!is_int($refundTimestamp)) {
2117
            throw new \InvalidArgumentException('Refund timestamp must be int');
2118
        }
2119
        if (!is_float($refundAmount) && !is_int($refundAmount)) {
2120
            throw new \InvalidArgumentException('Amount must be number');
2121
        }
2122
        if (!is_string($refundCurrency)) {
2123
            throw new \InvalidArgumentException('Refund currency must be string');
2124
        }
2125
        if ($refundAmountConverted !== null && !is_float($refundAmountConverted) && !is_int($refundAmountConverted)) {
2126
            throw new \InvalidArgumentException('Refund converted amount must be number');
2127
        }
2128
        if ($refundSource !== null && !is_string($refundSource)) {
2129
            throw new \InvalidArgumentException('Refund source must be string');
2130
        }
2131
        if ($refundType !== null && !is_string($refundType)) {
2132
            throw new \InvalidArgumentException('Refund type must be string');
2133
        }
2134
        if ($refundCode !== null && !is_string($refundCode)) {
2135
            throw new \InvalidArgumentException('Refund code must be string');
2136
        }
2137
        if ($refundReason !== null && !is_string($refundReason)) {
2138
            throw new \InvalidArgumentException('Refund reason must be string');
2139
        }
2140
        if ($agentId !== null && !is_string($agentId)) {
2141
            throw new \InvalidArgumentException('Agent id must be string');
2142
        }
2143
        if ($refundMethod !== null && !is_string($refundMethod)) {
2144
            throw new \InvalidArgumentException('Refund method must be string');
2145
        }
2146
        if ($refundSystem !== null && !is_string($refundSystem)) {
2147
            throw new \InvalidArgumentException('Refund system must be string');
2148
        }
2149
        if ($refundMid !== null && !is_string($refundMid)) {
2150
            throw new \InvalidArgumentException('Refund mid must be string');
2151
        }
2152
2153
        $this->replace('refund_id', $refundId);
2154
        $this->replace('refund_timestamp', $refundTimestamp);
2155
        $this->replace('refund_amount', $refundAmount);
2156
        $this->replace('refund_currency', $refundCurrency);
2157
        $this->replace('refund_amount_converted', $refundAmountConverted);
2158
        $this->replace('refund_source', $refundSource);
2159
        $this->replace('refund_type', $refundType);
2160
        $this->replace('refund_code', $refundCode);
2161
        $this->replace('refund_reason', $refundReason);
2162
        $this->replace('agent_id', $agentId);
2163
        $this->replace('refund_method', $refundMethod);
2164
        $this->replace('refund_system', $refundSystem);
2165
        $this->replace('refund_mid', $refundMid);
2166
2167
        return $this;
2168
    }
2169
2170
    /**
2171
     * Provides transfer information to envelope
2172
     *
2173
     * @param string $eventId
2174
     * @param int $eventTimestamp
2175
     * @param float $amount
2176
     * @param string $currency
2177
     * @param string $accountId
2178
     * @param string $secondAccountId
2179
     * @param string $accountSystem
2180
     * @param float|null $amountConverted
2181
     * @param string|null $method
2182
     * @param string|null $operation
2183
     * @param string|null $secondEmail
2184
     * @param string|null $secondPhone
2185
     * @param string|int $secondBirthDate
2186
     * @param string|null $secondFirstname
2187
     * @param string|null $secondLastname
2188
     * @param string|null $secondFullname
2189
     * @param string|null $secondState
2190
     * @param string|null $secondCity
2191
     * @param string|null $secondAddress
2192
     * @param string|null $secondZip
2193
     * @param string|null $secondGender
2194
     * @param string|null $secondCountry
2195
     * @param string|null $iban
2196
     * @param string|null $secondIban
2197
     * @param string|null $bic
2198
     * @param string|null $source
2199
     *
2200
     * @return $this
2201
     */
2202
    public function addTransferData(
2203
        $eventId,
2204
        $eventTimestamp,
2205
        $amount,
2206
        $currency,
2207
        $accountId,
2208
        $secondAccountId,
2209
        $accountSystem,
2210
        $amountConverted = null,
2211
        $method = null,
2212
        $operation = null,
2213
        $secondEmail = null,
2214
        $secondPhone = null,
2215
        $secondBirthDate = null,
2216
        $secondFirstname = null,
2217
        $secondLastname = null,
2218
        $secondFullname = null,
2219
        $secondState = null,
2220
        $secondCity = null,
2221
        $secondAddress = null,
2222
        $secondZip = null,
2223
        $secondGender = null,
2224
        $secondCountry = null,
2225
        $iban = null,
2226
        $secondIban = null,
2227
        $bic = null,
2228
        $source = null
2229
    ) {
2230
        if (!is_string($eventId)) {
2231
            throw new \InvalidArgumentException('Event ID must be string');
2232
        }
2233
        if (!is_int($eventTimestamp)) {
2234
            throw new \InvalidArgumentException('Event timestamp must be int');
2235
        }
2236
        if (!is_int($amount) && !is_float($amount)) {
2237
            throw new \InvalidArgumentException('Amount must be number');
2238
        }
2239
        if (!is_string($currency)) {
2240
            throw new \InvalidArgumentException('Currency must be string');
2241
        }
2242
        if (!is_string($accountId)) {
2243
            throw new \InvalidArgumentException('Account id must be string');
2244
        }
2245
        if (!is_string($secondAccountId)) {
2246
            throw new \InvalidArgumentException('Second account id must be string');
2247
        }
2248
        if (!is_string($accountSystem)) {
2249
            throw new \InvalidArgumentException('Account system must be string');
2250
        }
2251 View Code Duplication
        if ($amountConverted !== null && !is_int($amountConverted) && !is_float($amountConverted)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2252
            throw new \InvalidArgumentException('Amount converted must be number');
2253
        }
2254
        if ($method !== null && !is_string($method)) {
2255
            throw new \InvalidArgumentException('Method must be string');
2256
        }
2257
        if ($operation !== null && !is_string($operation)) {
2258
            throw new \InvalidArgumentException('Operation must be string');
2259
        }
2260
        if ($secondPhone !== null && !is_string($secondPhone)) {
2261
            throw new \InvalidArgumentException('Second phone must be string');
2262
        }
2263
        if ($secondEmail !== null && !is_string($secondEmail)) {
2264
            throw new \InvalidArgumentException('Second email must be string');
2265
        }
2266
        if ($secondBirthDate !== null && !is_int($secondBirthDate)) {
2267
            throw new \InvalidArgumentException('Second birth date must be int');
2268
        }
2269
        if ($secondFirstname !== null && !is_string($secondFirstname)) {
2270
            throw new \InvalidArgumentException('Second firstname must be string');
2271
        }
2272
        if ($secondLastname !== null && !is_string($secondLastname)) {
2273
            throw new \InvalidArgumentException('Second lastname must be string');
2274
        }
2275
        if ($secondFullname !== null && !is_string($secondFullname)) {
2276
            throw new \InvalidArgumentException('Second fullname must be string');
2277
        }
2278
        if ($secondState !== null && !is_string($secondState)) {
2279
            throw new \InvalidArgumentException('Second state must be string');
2280
        }
2281
        if ($secondCity !== null && !is_string($secondCity)) {
2282
            throw new \InvalidArgumentException('Second city must be string');
2283
        }
2284
        if ($secondAddress !== null && !is_string($secondAddress)) {
2285
            throw new \InvalidArgumentException('Second address must be string');
2286
        }
2287
        if ($secondZip !== null && !is_string($secondZip)) {
2288
            throw new \InvalidArgumentException('Second zip must be string');
2289
        }
2290
        if ($secondGender !== null && !is_string($secondGender)) {
2291
            throw new \InvalidArgumentException('Second gender must be string');
2292
        }
2293
        if ($secondCountry !== null && !is_string($secondCountry)) {
2294
            throw new \InvalidArgumentException('Second country must be string');
2295
        }
2296
        if ($iban !== null && !is_string($iban)) {
2297
            throw new \InvalidArgumentException('Iban must be string');
2298
        }
2299
        if ($secondIban !== null && !is_string($secondIban)) {
2300
            throw new \InvalidArgumentException('Second iban must be string');
2301
        }
2302
        if ($bic !== null && !is_string($bic)) {
2303
            throw new \InvalidArgumentException('Bic must be string');
2304
        }
2305
        if ($source !== null && !is_string($source)) {
2306
            throw new \InvalidArgumentException('Transfer source must be string');
2307
        }
2308
2309
        $this->replace('event_id', $eventId);
2310
        $this->replace('event_timestamp', $eventTimestamp);
2311
        $this->replace('amount', $amount);
2312
        $this->replace('currency', $currency);
2313
        $this->replace('account_id', $accountId);
2314
        $this->replace('second_account_id', $secondAccountId);
2315
        $this->replace('account_system', $accountSystem);
2316
        $this->replace('amount_converted', $amountConverted);
2317
        $this->replace('method', $method);
2318
        $this->replace('operation', $operation);
2319
        $this->replace('second_email', $secondEmail);
2320
        $this->replace('second_phone', $secondPhone);
2321
        $this->replace('second_birth_date', $secondBirthDate);
2322
        $this->replace('second_firstname', $secondFirstname);
2323
        $this->replace('second_lastname', $secondLastname);
2324
        $this->replace('second_fullname', $secondFullname);
2325
        $this->replace('second_state', $secondState);
2326
        $this->replace('second_city', $secondCity);
2327
        $this->replace('second_address', $secondAddress);
2328
        $this->replace('second_zip', $secondZip);
2329
        $this->replace('second_gender', $secondGender);
2330
        $this->replace('second_country', $secondCountry);
2331
        $this->replace('iban', $iban);
2332
        $this->replace('second_iban', $secondIban);
2333
        $this->replace('bic', $bic);
2334
        $this->replace('transfer_source', $source);
2335
2336
        return $this;
2337
    }
2338
2339
    /**
2340
     * Provides kyc information to envelope
2341
     *
2342
     * @param string $eventId
2343
     * @param int $eventTimestamp
2344
     * @param string|null $groupId
2345
     * @param string|null $status
2346
     * @param string|null $code
2347
     * @param string|null $reason
2348
     * @param string|null $providerResult
2349
     * @param string|null $providerCode
2350
     * @param string|null $providerReason
2351
     * @param string|null $profileId
2352
     * @param string|null $profileType
2353
     * @param string|null $profileSubType
2354
     * @param string|null $industry
2355
     * @param string|null $description
2356
     * @param int|null $regDate
2357
     * @param string|null $regNumber
2358
     * @param string|null $vatNumber
2359
     * @param string|null $secondCountry
2360
     * @param string|null $secondState
2361
     * @param string|null $secondCity
2362
     * @param string|null $secondAddress
2363
     * @param string|null $secondZip
2364
     * @param string|null $relatedProfiles
2365
     *
2366
     * @return $this
2367
     */
2368
    public function addKycData(
2369
        $eventId,
2370
        $eventTimestamp,
2371
        $groupId = null,
2372
        $status = null,
2373
        $code = null,
2374
        $reason = null,
2375
        $providerResult = null,
2376
        $providerCode = null,
2377
        $providerReason = null,
2378
        $profileId = null,
2379
        $profileType = null,
2380
        $profileSubType = null,
2381
        $industry = null,
2382
        $description = null,
2383
        $regDate = null,
2384
        $regNumber = null,
2385
        $vatNumber = null,
2386
        $secondCountry = null,
2387
        $secondState = null,
2388
        $secondCity = null,
2389
        $secondAddress = null,
2390
        $secondZip = null,
2391
        $relatedProfiles = null
2392
    ) {
2393
        if (!is_string($eventId)) {
2394
            throw new \InvalidArgumentException('Event ID must be string');
2395
        }
2396
        if (!is_int($eventTimestamp)) {
2397
            throw new \InvalidArgumentException('Event timestamp must be int');
2398
        }
2399
        if ($groupId !== null && !is_string($groupId)) {
2400
            throw new \InvalidArgumentException('Group id must be string');
2401
        }
2402
        if ($status !== null && !is_string($status)) {
2403
            throw new \InvalidArgumentException('Status must be string');
2404
        }
2405
        if ($code !== null && !is_string($code)) {
2406
            throw new \InvalidArgumentException('Code must be string');
2407
        }
2408
        if ($reason !== null && !is_string($reason)) {
2409
            throw new \InvalidArgumentException('Reason must be string');
2410
        }
2411
        if ($providerResult !== null && !is_string($providerResult)) {
2412
            throw new \InvalidArgumentException('Provider result must be string');
2413
        }
2414
        if ($providerCode !== null && !is_string($providerCode)) {
2415
            throw new \InvalidArgumentException('Provider code must be string');
2416
        }
2417
        if ($providerReason !== null && !is_string($providerReason)) {
2418
            throw new \InvalidArgumentException('Provider reason must be string');
2419
        }
2420
        if ($profileId !== null && !is_string($profileId)) {
2421
            throw new \InvalidArgumentException('Profile id must be string');
2422
        }
2423
        if ($profileType !== null && !is_string($profileType)) {
2424
            throw new \InvalidArgumentException('Profile type must be string');
2425
        }
2426
        if ($profileSubType !== null && !is_string($profileSubType)) {
2427
            throw new \InvalidArgumentException('Profile sub type must be string');
2428
        }
2429
        if ($industry !== null && !is_string($industry)) {
2430
            throw new \InvalidArgumentException('Industry must be string');
2431
        }
2432
        if ($description !== null && !is_string($description)) {
2433
            throw new \InvalidArgumentException('Description must be string');
2434
        }
2435
        if ($regDate !== null && !is_int($regDate)) {
2436
            throw new \InvalidArgumentException('Reg date must be integer');
2437
        }
2438
        if ($regNumber !== null && !is_string($regNumber)) {
2439
            throw new \InvalidArgumentException('Reg number must be string');
2440
        }
2441
        if ($vatNumber !== null && !is_string($vatNumber)) {
2442
            throw new \InvalidArgumentException('Vat number must be string');
2443
        }
2444
        if ($secondCountry !== null && !is_string($secondCountry)) {
2445
            throw new \InvalidArgumentException('Secondary country must be string');
2446
        }
2447
        if ($secondState !== null && !is_string($secondState)) {
2448
            throw new \InvalidArgumentException('Second state must be string');
2449
        }
2450
        if ($secondCity !== null && !is_string($secondCity)) {
2451
            throw new \InvalidArgumentException('Second city must be string');
2452
        }
2453
        if ($secondAddress !== null && !is_string($secondAddress)) {
2454
            throw new \InvalidArgumentException('Second address must be string');
2455
        }
2456
        if ($secondZip !== null && !is_string($secondZip)) {
2457
            throw new \InvalidArgumentException('Second zip must be string');
2458
        }
2459
        if ($relatedProfiles !== null && !is_string($relatedProfiles)) {
2460
            throw new \InvalidArgumentException('Related profiles must be string');
2461
        }
2462
2463
        $this->replace('event_id', $eventId);
2464
        $this->replace('event_timestamp', $eventTimestamp);
2465
        $this->replace('group_id', $groupId);
2466
        $this->replace('status', $status);
2467
        $this->replace('code', $code);
2468
        $this->replace('reason', $reason);
2469
        $this->replace('provider_result', $providerResult);
2470
        $this->replace('provider_code', $providerCode);
2471
        $this->replace('provider_reason', $providerReason);
2472
        $this->replace('profile_id', $profileId);
2473
        $this->replace('profile_type', $profileType);
2474
        $this->replace('profile_sub_type', $profileSubType);
2475
        $this->replace('industry', $industry);
2476
        $this->replace('description', $description);
2477
        $this->replace('reg_date', $regDate);
2478
        $this->replace('reg_number', $regNumber);
2479
        $this->replace('vat_number', $vatNumber);
2480
        $this->replace('second_country', $secondCountry);
2481
        $this->replace('second_state', $secondState);
2482
        $this->replace('second_city', $secondCity);
2483
        $this->replace('second_address', $secondAddress);
2484
        $this->replace('second_zip', $secondZip);
2485
        $this->replace('related_profiles', $relatedProfiles);
2486
2487
        return $this;
2488
    }
2489
2490
    /**
2491
     * Provides order information to envelope
2492
     *
2493
     * @param string $envelopeType
2494
     * @param float $amount
2495
     * @param string $currency
2496
     * @param string $eventId
2497
     * @param int $eventTimestamp
2498
     * @param string|null $transactionId
2499
     * @param string|null $groupId
2500
     * @param int|null $itemsQuantity
2501
     * @param string|null $orderType
2502
     * @param float|null $amountConverted
2503
     * @param string|null $campaign
2504
     * @param string|null $carrier
2505
     * @param string|null $carrierShippingId
2506
     * @param string|null $carrierUrl
2507
     * @param string|null $carrierPhone
2508
     * @param int|null $couponStartDate
2509
     * @param int|null $couponEndDate
2510
     * @param string|null $couponId
2511
     * @param string|null $couponName
2512
     * @param string|null $customerComment
2513
     * @param int|null $deliveryEstimate
2514
     * @param string|null $shippingAddress
2515
     * @param string|null $shippingCity
2516
     * @param string|null $shippingCountry
2517
     * @param string|null $shippingCurrency
2518
     * @param float|null $shippingFee
2519
     * @param float|null $shippingFeeConverted
2520
     * @param string|null $shippingState
2521
     * @param string|null $shippingZip
2522
     * @param string|null $source
2523
     * @param float|null $sourceFee
2524
     * @param string|null $sourceFeeCurrency
2525
     * @param float|null $sourceFeeConverted
2526
     * @param string|null $taxCurrency
2527
     * @param float|null $taxFee
2528
     * @param float|null $taxFeeConverted
2529
     * @param string|null $productUrl
2530
     * @param string|null $productImageUrl
2531
     * @return Builder
2532
     */
2533
    public function addOrderData(
2534
        $envelopeType,
2535
        $amount,
2536
        $currency,
2537
        $eventId,
2538
        $eventTimestamp,
2539
        $transactionId = null,
2540
        $groupId = null,
2541
        $itemsQuantity = null,
2542
        $orderType = null,
2543
        $amountConverted = null,
2544
        $campaign = null,
2545
        $carrier = null,
2546
        $carrierShippingId = null,
2547
        $carrierUrl = null,
2548
        $carrierPhone = null,
2549
        $couponStartDate = null,
2550
        $couponEndDate = null,
2551
        $couponId = null,
2552
        $couponName = null,
2553
        $customerComment = null,
2554
        $deliveryEstimate = null,
2555
        $shippingAddress = null,
2556
        $shippingCity = null,
2557
        $shippingCountry = null,
2558
        $shippingCurrency = null,
2559
        $shippingFee = null,
2560
        $shippingFeeConverted = null,
2561
        $shippingState = null,
2562
        $shippingZip = null,
2563
        $source = null,
2564
        $sourceFee = null,
2565
        $sourceFeeCurrency = null,
2566
        $sourceFeeConverted = null,
2567
        $taxCurrency = null,
2568
        $taxFee = null,
2569
        $taxFeeConverted = null,
2570
        $productUrl = null,
2571
        $productImageUrl = null
2572
    ) {
2573
        if (!is_string($envelopeType)) {
2574
            throw new \InvalidArgumentException('Envelope type must be string');
2575
        }
2576
        if (!is_int($amount) && !is_float($amount)) {
2577
            throw new \InvalidArgumentException('Amount must be number');
2578
        }
2579
        if (!is_string($currency)) {
2580
            throw new \InvalidArgumentException('Currency must be string');
2581
        }
2582
        if (!is_string($eventId)) {
2583
            throw new \InvalidArgumentException('Event ID must be string');
2584
        }
2585
        if (!is_int($eventTimestamp)) {
2586
            throw new \InvalidArgumentException('Event timestamp must be int');
2587
        }
2588
        if ($envelopeType === 'order_submit' && !is_int($itemsQuantity)) {
2589
            throw new \InvalidArgumentException('Items quantity must be int');
2590
        }
2591
        if ($envelopeType === 'order_item' && !is_string($orderType)) {
2592
            throw new \InvalidArgumentException('Order type must be string');
2593
        }
2594
        if ($transactionId !== null && !is_string($transactionId)) {
2595
            throw new \InvalidArgumentException('Transaction id must be string');
2596
        }
2597
        if ($groupId !== null && !is_string($groupId)) {
2598
            throw new \InvalidArgumentException('Group id must be string');
2599
        }
2600 View Code Duplication
        if ($amountConverted !== null && !is_int($amountConverted) && !is_float($amountConverted)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2601
            throw new \InvalidArgumentException('Amount converted must be number');
2602
        }
2603
        if ($campaign !== null && !is_string($campaign)) {
2604
            throw new \InvalidArgumentException('Campaign must be string');
2605
        }
2606
        if ($carrier !== null && !is_string($carrier)) {
2607
            throw new \InvalidArgumentException('Carrier must be string');
2608
        }
2609
        if ($carrierShippingId !== null && !is_string($carrierShippingId)) {
2610
            throw new \InvalidArgumentException('Carrier shipping id must be string');
2611
        }
2612
        if ($carrierUrl !== null && !is_string($carrierUrl)) {
2613
            throw new \InvalidArgumentException('Carrier url must be string');
2614
        }
2615
        if ($carrierPhone !== null && !is_string($carrierPhone)) {
2616
            throw new \InvalidArgumentException('Carrier phone must be string');
2617
        }
2618
        if ($couponStartDate !== null && !is_int($couponStartDate)) {
2619
            throw new \InvalidArgumentException('Coupon start date must be int');
2620
        }
2621
        if ($couponEndDate !== null && !is_int($couponEndDate)) {
2622
            throw new \InvalidArgumentException('Coupon end date must be int');
2623
        }
2624
        if ($couponId !== null && !is_string($couponId)) {
2625
            throw new \InvalidArgumentException('Coupon id must be string');
2626
        }
2627
        if ($couponName !== null && !is_string($couponName)) {
2628
            throw new \InvalidArgumentException('Coupon name must be string');
2629
        }
2630
        if ($customerComment !== null && !is_string($customerComment)) {
2631
            throw new \InvalidArgumentException('Customer comment must be string');
2632
        }
2633
        if ($deliveryEstimate !== null && !is_int($deliveryEstimate)) {
2634
            throw new \InvalidArgumentException('Delivery estimate must be int');
2635
        }
2636
        if ($shippingAddress !== null && !is_string($shippingAddress)) {
2637
            throw new \InvalidArgumentException('Shipping address must be string');
2638
        }
2639
        if ($shippingCity !== null && !is_string($shippingCity)) {
2640
            throw new \InvalidArgumentException('Shipping city must be string');
2641
        }
2642
        if ($shippingCountry !== null && !is_string($shippingCountry)) {
2643
            throw new \InvalidArgumentException('Shipping country must be string');
2644
        }
2645
        if ($shippingCurrency !== null && !is_string($shippingCurrency)) {
2646
            throw new \InvalidArgumentException('Shipping currency must be string');
2647
        }
2648
        if ($shippingFee !== null && !is_int($shippingFee) && !is_float($shippingFee)) {
2649
            throw new \InvalidArgumentException('Shipping fee must be number');
2650
        }
2651
        if ($shippingFeeConverted !== null && !is_int($shippingFeeConverted) && !is_float($shippingFeeConverted)) {
2652
            throw new \InvalidArgumentException('Shipping fee converted must be number');
2653
        }
2654
        if ($shippingState !== null && !is_string($shippingState)) {
2655
            throw new \InvalidArgumentException('Shipping state must be string');
2656
        }
2657
        if ($shippingZip !== null && !is_string($shippingZip)) {
2658
            throw new \InvalidArgumentException('Shipping zip must be string');
2659
        }
2660
        if ($source !== null && !is_string($source)) {
2661
            throw new \InvalidArgumentException('Order source must be string');
2662
        }
2663
        if ($sourceFee !== null && !is_int($sourceFee) && !is_float($sourceFee)) {
2664
            throw new \InvalidArgumentException('Source fee must be number');
2665
        }
2666
        if ($sourceFeeConverted !== null && !is_int($sourceFeeConverted) && !is_float($sourceFeeConverted)) {
2667
            throw new \InvalidArgumentException('Source fee converted must be number');
2668
        }
2669
        if ($sourceFeeCurrency !== null && !is_string($sourceFeeCurrency)) {
2670
            throw new \InvalidArgumentException('Source fee currency must be string');
2671
        }
2672
        if ($taxCurrency !== null && !is_string($taxCurrency)) {
2673
            throw new \InvalidArgumentException('Tax currency must be string');
2674
        }
2675
        if ($taxFee !== null && !is_int($taxFee) && !is_float($taxFee)) {
2676
            throw new \InvalidArgumentException('Tax fee must be number');
2677
        }
2678
        if ($taxFeeConverted !== null && !is_int($taxFeeConverted) && !is_float($taxFeeConverted)) {
2679
            throw new \InvalidArgumentException('Tax fee converted must be number');
2680
        }
2681
        if ($productUrl !== null && !is_string($productUrl)) {
2682
            throw new \InvalidArgumentException('Product url must be string');
2683
        }
2684
        if ($productImageUrl !== null && !is_string($productImageUrl)) {
2685
            throw new \InvalidArgumentException('Product image url must be string');
2686
        }
2687
        if ($productImageUrl !== null && !is_string($productImageUrl)) {
2688
            throw new \InvalidArgumentException('Product image url must be string');
2689
        }
2690
        $this->replace('amount', $amount);
2691
        $this->replace('currency', $currency);
2692
        $this->replace('event_id', $eventId);
2693
        $this->replace('event_timestamp', $eventTimestamp);
2694
        $this->replace('items_quantity', $itemsQuantity);
2695
        $this->replace('order_type', $orderType);
2696
        $this->replace('transaction_id', $transactionId);
2697
        $this->replace('group_id', $groupId);
2698
        $this->replace('amount_converted', $amountConverted);
2699
        $this->replace('campaign', $campaign);
2700
        $this->replace('carrier', $carrier);
2701
        $this->replace('carrier_shipping_id', $carrierShippingId);
2702
        $this->replace('carrier_url', $carrierUrl);
2703
        $this->replace('carrier_phone', $carrierPhone);
2704
        $this->replace('coupon_start_date', $couponStartDate);
2705
        $this->replace('coupon_end_date', $couponEndDate);
2706
        $this->replace('coupon_id', $couponId);
2707
        $this->replace('coupon_name', $couponName);
2708
        $this->replace('customer_comment', $customerComment);
2709
        $this->replace('delivery_estimate', $deliveryEstimate);
2710
        $this->replace('shipping_address', $shippingAddress);
2711
        $this->replace('shipping_city', $shippingCity);
2712
        $this->replace('shipping_country', $shippingCountry);
2713
        $this->replace('shipping_currency', $shippingCurrency);
2714
        $this->replace('shipping_fee', $shippingFee);
2715
        $this->replace('shipping_fee_converted', $shippingFeeConverted);
2716
        $this->replace('shipping_state', $shippingState);
2717
        $this->replace('shipping_zip', $shippingZip);
2718
        $this->replace('order_source', $source);
2719
        $this->replace('source_fee', $sourceFee);
2720
        $this->replace('source_fee_currency', $sourceFeeCurrency);
2721
        $this->replace('source_fee_converted', $sourceFeeConverted);
2722
        $this->replace('tax_currency', $taxCurrency);
2723
        $this->replace('tax_fee', $taxFee);
2724
        $this->replace('tax_fee_converted', $taxFeeConverted);
2725
        $this->replace('product_url', $productUrl);
2726
        $this->replace('product_image_url', $productImageUrl);
2727
2728
        return $this;
2729
    }
2730
2731
    /**
2732
     * Provides postback information to envelope
2733
     *
2734
     * @param int|null $requestId
2735
     * @param string|null $transactionId
2736
     * @param string|null $transactionStatus
2737
     * @param string|null $code
2738
     * @param string|null $reason
2739
     * @param string|null $secure3d
2740
     * @param string|null $avsResult
2741
     * @param string|null $cvvResult
2742
     * @param string|null $pspCode
2743
     * @param string|null $pspReason
2744
     * @param string|null $arn
2745
     * @param string|null $paymentAccountId
2746
     * @return $this
2747
     */
2748
    public function addPostbackData(
2749
        $requestId = null,
2750
        $transactionId = null,
2751
        $transactionStatus = null,
2752
        $code = null,
2753
        $reason = null,
2754
        $secure3d = null,
2755
        $avsResult = null,
2756
        $cvvResult = null,
2757
        $pspCode = null,
2758
        $pspReason = null,
2759
        $arn = null,
2760
        $paymentAccountId = null
2761
    ) {
2762
        if ($requestId === null && $transactionId === null) {
2763
            throw new \InvalidArgumentException('request_id or transaction_id should be provided');
2764
        }
2765
        if ($transactionId !== null && !is_string($transactionId)) {
2766
            throw new \InvalidArgumentException('TransactionId must be string');
2767
        }
2768
        if ($requestId !== null && !is_int($requestId)) {
2769
            throw new \InvalidArgumentException('RequestId must be int');
2770
        }
2771
        if ($transactionStatus !== null && !is_string($transactionStatus)) {
2772
            throw new \InvalidArgumentException('Transaction status must be string');
2773
        }
2774
        if ($code !== null && !is_string($code)) {
2775
            throw new \InvalidArgumentException('Code must be string');
2776
        }
2777
        if ($reason !== null && !is_string($reason)) {
2778
            throw new \InvalidArgumentException('Reason must be string');
2779
        }
2780
        if ($secure3d !== null && !is_string($secure3d)) {
2781
            throw new \InvalidArgumentException('Secure3d must be string');
2782
        }
2783
        if ($avsResult !== null && !is_string($avsResult)) {
2784
            throw new \InvalidArgumentException('AvsResult must be string');
2785
        }
2786
        if ($cvvResult !== null && !is_string($cvvResult)) {
2787
            throw new \InvalidArgumentException('CvvResult must be string');
2788
        }
2789
        if ($pspCode !== null && !is_string($pspCode)) {
2790
            throw new \InvalidArgumentException('PspCode must be string');
2791
        }
2792
        if ($pspReason !== null && !is_string($pspReason)) {
2793
            throw new \InvalidArgumentException('PspReason must be string');
2794
        }
2795
        if ($arn !== null && !is_string($arn)) {
2796
            throw new \InvalidArgumentException('Arn must be string');
2797
        }
2798
        if ($paymentAccountId !== null && !is_string($paymentAccountId)) {
2799
            throw new \InvalidArgumentException('PaymentAccoutId must be string');
2800
        }
2801
2802
        $this->replace('request_id', $requestId);
2803
        $this->replace('transaction_id', $transactionId);
2804
        $this->replace('transaction_status', $transactionStatus);
2805
        $this->replace('code', $code);
2806
        $this->replace('reason', $reason);
2807
        $this->replace('secure3d', $secure3d);
2808
        $this->replace('avs_result', $avsResult);
2809
        $this->replace('cvv_result', $cvvResult);
2810
        $this->replace('psp_code', $pspCode);
2811
        $this->replace('psp_reason', $pspReason);
2812
        $this->replace('arn', $arn);
2813
        $this->replace('payment_account_id', $paymentAccountId);
2814
2815
        return $this;
2816
    }
2817
2818
    /**
2819
     * Adds custom data field to envelope
2820
     *
2821
     * @param string $name
2822
     * @param string $value
2823
     *
2824
     * @return $this
2825
     */
2826
    public function addCustomField($name, $value)
2827
    {
2828
        if (!is_string($name)) {
2829
            throw new \InvalidArgumentException('Custom field name must be string');
2830
        }
2831
        if (!is_string($value)) {
2832
            throw new \InvalidArgumentException('Custom field value must be string');
2833
        }
2834
2835
        if (strlen($name) < 8 || substr($name, 0, 7) !== 'custom_') {
2836
            $name = 'custom_' . $name;
2837
        }
2838
2839
        $this->replace($name, $value);
2840
        return $this;
2841
    }
2842
2843
    /**
2844
     * Provides group id value to envelope
2845
     *
2846
     * @param string|null $groupId
2847
     * @return $this
2848
     */
2849
    public function addGroupId($groupId = null)
2850
    {
2851
        if ($groupId !== null && !is_string($groupId)) {
2852
            throw new \InvalidArgumentException('Group id must be string');
2853
        }
2854
        $this->replace('group_id', $groupId);
2855
2856
        return $this;
2857
    }
2858
2859
}
2860