Completed
Pull Request — master (#29)
by
unknown
01:23
created

Builder::addIpData()   B

Complexity

Conditions 7
Paths 4

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 8.8333
c 0
b 0
f 0
cc 7
nc 4
nop 3
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 $providerId
748
     * @param string|null $contactEmail
749
     * @param string|null $contactPhone
750
     * @param string|null $walletType
751
     * @param string|null $nationality
752
     * @param bool|null $finalBeneficiary
753
     * @param string|null $employmentStatus
754
     * @param string|null $sourceOfFunds
755
     * @param int|null $issueDate
756
     * @param int|null $expiryDate
757
     * @param string|null $gender
758
     * @return Builder
759
     */
760
    public static function kycProfileEvent(
761
        $sequenceId,
762
        $eventId,
763
        $userId,
764
        $eventTimestamp = null,
765
        $groupId = null,
766
        $status = null,
767
        $code = null,
768
        $reason = null,
769
        $providerResult = null,
770
        $providerCode = null,
771
        $providerReason = null,
772
        $profileId = null,
773
        $profileType = null,
774
        $profileSubType = null,
775
        $firstName = null,
776
        $lastName = null,
777
        $fullName = null,
778
        $industry = null,
779
        $websiteUrl = null,
780
        $description = null,
781
        $birthDate = null,
782
        $regDate = null,
783
        $regNumber = null,
784
        $vatNumber = null,
785
        $email = null,
786
        $emailConfirmed = null,
787
        $phone = null,
788
        $phoneConfirmed = null,
789
        $country = null,
790
        $state = null,
791
        $city = null,
792
        $address = null,
793
        $zip = null,
794
        $secondCountry = null,
795
        $secondState = null,
796
        $secondCity = null,
797
        $secondAddress = null,
798
        $secondZip = null,
799
        $providerId = null,
800
        $contactEmail = null,
801
        $contactPhone = null,
802
        $walletType = null,
803
        $nationality = null,
804
        $finalBeneficiary = null,
805
        $employmentStatus = null,
806
        $sourceOfFunds = null,
807
        $issueDate = null,
808
        $expiryDate = null,
809
        $gender = null
810
    ) {
811
        $builder = new self('kyc_profile', $sequenceId);
812
        if ($eventTimestamp === null) {
813
            $eventTimestamp = time();
814
        }
815
        return $builder
816
            ->addKycData(
817
                $eventId,
818
                $eventTimestamp,
819
                $groupId,
820
                $status,
821
                $code,
822
                $reason,
823
                $providerResult,
824
                $providerCode,
825
                $providerReason,
826
                $profileId,
827
                $profileType,
828
                $profileSubType,
829
                $industry,
830
                $description,
831
                $regDate,
832
                $regNumber,
833
                $vatNumber,
834
                $secondCountry,
835
                $secondState,
836
                $secondCity,
837
                $secondAddress,
838
                $secondZip,
839
                $providerId,
840
                $contactEmail,
841
                $contactPhone,
842
                $walletType,
843
                $nationality,
844
                $finalBeneficiary,
845
                $employmentStatus,
846
                $sourceOfFunds,
847
                $issueDate,
848
                $expiryDate
849
            )
850
            ->addUserData(
851
                $email,
852
                $userId,
853
                $phone,
854
                null,
855
                $firstName,
856
                $lastName,
857
                $gender,
858
                null,
859
                $country,
860
                null,
861
                null,
862
                null,
863
                null,
864
                $emailConfirmed,
865
                $phoneConfirmed,
866
                null,
867
                $birthDate,
868
                $fullName,
869
                $state,
870
                $city,
871
                $address,
872
                $zip,
873
                null
874
            )
875
            ->addWebsiteData($websiteUrl);
876
    }
877
878
    /**
879
     * Returns builder for kyc_submit request
880
     *
881
     * @param string $sequenceId
882
     * @param string $eventId
883
     * @param string $userId
884
     * @param int|null $eventTimestamp
885
     * @param string|null $groupId
886
     * @param string|null $status
887
     * @param string|null $code
888
     * @param string|null $reason
889
     * @param string|null $providerResult
890
     * @param string|null $providerCode
891
     * @param string|null $providerReason
892
     *
893
     * @return Builder
894
     */
895
    public static function kycSubmitEvent(
896
        $sequenceId,
897
        $eventId,
898
        $userId,
899
        $eventTimestamp = null,
900
        $groupId = null,
901
        $status = null,
902
        $code = null,
903
        $reason = null,
904
        $providerResult = null,
905
        $providerCode = null,
906
        $providerReason = null
907
    ) {
908
        $builder = new self('kyc_submit', $sequenceId);
909
        if ($eventTimestamp === null) {
910
            $eventTimestamp = time();
911
        }
912
        return $builder
913
            ->addKycData(
914
                $eventId,
915
                $eventTimestamp,
916
                $groupId,
917
                $status,
918
                $code,
919
                $reason,
920
                $providerResult,
921
                $providerCode,
922
                $providerReason
923
            )
924
            ->addUserData(
925
                null,
926
                $userId
927
            );
928
    }
929
930
    /**
931
     * Returns builder for kyc_start request
932
     *
933
     * @param string $sequenceId
934
     * @param string $eventId
935
     * @param string $userMerchantId
936
     * @param string $verificationMode
937
     * @param string $verificationSource
938
     * @param bool $consent
939
     * @param null|int $eventTimestamp
940
     * @param bool|null $allowNaOcrInputs
941
     * @param bool|null $declineOnSingleStep
942
     * @param bool|null $backsideProof
943
     * @param string|null $groupId
944
     * @param string|null $country
945
     * @param string|null $kycLanguage
946
     * @param string|null $redirectUrl
947
     * @param string|null $email
948
     * @param string|null $firstName
949
     * @param string|null $lastName
950
     * @param string|null $profileId
951
     * @param string|null $phone
952
     * @param string|null $birthDate
953
     * @param string|null $regNumber
954
     * @param int|null $issueDate
955
     * @param int|null $expiryDate
956
     * @return Builder
957
     */
958
    public static function kycStartEvent(
959
        $sequenceId,
960
        $eventId,
961
        $userMerchantId,
962
        $verificationMode,
963
        $verificationSource,
964
        $consent,
965
        $eventTimestamp = null,
966
        $allowNaOcrInputs = null,
967
        $declineOnSingleStep = null,
968
        $backsideProof = null,
969
        $groupId = null,
970
        $country = null,
971
        $kycLanguage = null,
972
        $redirectUrl = null,
973
        $email = null,
974
        $firstName = null,
975
        $lastName = null,
976
        $profileId = null,
977
        $phone = null,
978
        $birthDate = null,
979
        $regNumber = null,
980
        $issueDate = null,
981
        $expiryDate = null
982
    ) {
983
        $envelopeType = 'kyc_start';
984
        $builder = new self($envelopeType, $sequenceId);
985
        if ($eventTimestamp === null) {
986
            $eventTimestamp = time();
987
        }
988
        return $builder
989
            ->addKycData(
990
                $eventId,
991
                $eventTimestamp,
992
                $groupId,
993
                null,
994
                null,
995
                null,
996
                null,
997
                null,
998
                null,
999
                $profileId,
1000
                null,
1001
                null,
1002
                null,
1003
                null,
1004
                null,
1005
                $regNumber,
1006
                null,
1007
                null,
1008
                null,
1009
                null,
1010
                null,
1011
                null,
1012
                null,
1013
                null,
1014
                null,
1015
                null,
1016
                null,
1017
                null,
1018
                null,
1019
                null,
1020
                $issueDate,
1021
                $expiryDate,
1022
                $verificationMode,
1023
                $verificationSource,
1024
                $consent,
1025
                $allowNaOcrInputs,
1026
                $declineOnSingleStep,
1027
                $backsideProof,
1028
                $kycLanguage,
1029
                $redirectUrl
1030
            )
1031
            ->addUserData(
1032
                $email,
1033
                $userMerchantId,
1034
                $phone,
1035
                null,
1036
                $firstName,
1037
                $lastName,
1038
                null,
1039
                null,
1040
                $country,
1041
                null,
1042
                null,
1043
                null,
1044
                null,
1045
                null,
1046
                null,
1047
                null,
1048
                $birthDate,
1049
                null,
1050
                null,
1051
                null,
1052
                null,
1053
                null,
1054
                null
1055
            );
1056
    }
1057
1058
    /**
1059
     * Returns builder for order_item request
1060
     *
1061
     * @param string $sequenceId
1062
     * @param float $amount
1063
     * @param string $currency
1064
     * @param string $eventId
1065
     * @param int $eventTimestamp
1066
     * @param string $orderType
1067
     * @param string|null $transactionId
1068
     * @param string|null $groupId
1069
     * @param string|null $affiliateId
1070
     * @param float|null $amountConverted
1071
     * @param string|null $campaign
1072
     * @param string|null $carrier
1073
     * @param string|null $carrierShippingId
1074
     * @param string|null $carrierUrl
1075
     * @param string|null $carrierPhone
1076
     * @param int|null $couponStartDate
1077
     * @param int|null $couponEndDate
1078
     * @param string|null $couponId
1079
     * @param string|null $couponName
1080
     * @param string|null $customerComment
1081
     * @param int|null $deliveryEstimate
1082
     * @param string|null $email
1083
     * @param string|null $firstName
1084
     * @param string|null $lastName
1085
     * @param string|null $phone
1086
     * @param string|null $productDescription
1087
     * @param string|null $productName
1088
     * @param int|null $productQuantity
1089
     * @param string|null $shippingAddress
1090
     * @param string|null $shippingCity
1091
     * @param string|null $shippingCountry
1092
     * @param string|null $shippingCurrency
1093
     * @param float|null $shippingFee
1094
     * @param float|null $shippingFeeConverted
1095
     * @param string|null $shippingState
1096
     * @param string|null $shippingZip
1097
     * @param string|null $socialType
1098
     * @param string|null $source
1099
     * @param string|null $sourceFeeCurrency
1100
     * @param float|null $sourceFee
1101
     * @param float|null $sourceFeeConverted
1102
     * @param string|null $taxCurrency
1103
     * @param float|null $taxFee
1104
     * @param float|null $taxFeeConverted
1105
     * @param string|null $userMerchantId
1106
     * @param string|null $websiteUrl
1107
     * @param string|null $productUrl
1108
     * @param string|null $productImageUrl
1109
     * @return Builder
1110
     */
1111
    public static function orderItemEvent(
1112
        $sequenceId,
1113
        $amount,
1114
        $currency,
1115
        $eventId,
1116
        $eventTimestamp,
1117
        $orderType,
1118
        $transactionId = null,
1119
        $groupId = null,
1120
        $affiliateId = null,
1121
        $amountConverted = null,
1122
        $campaign = null,
1123
        $carrier = null,
1124
        $carrierShippingId = null,
1125
        $carrierUrl = null,
1126
        $carrierPhone = null,
1127
        $couponStartDate = null,
1128
        $couponEndDate = null,
1129
        $couponId = null,
1130
        $couponName = null,
1131
        $customerComment = null,
1132
        $deliveryEstimate = null,
1133
        $email = null,
1134
        $firstName = null,
1135
        $lastName = null,
1136
        $phone = null,
1137
        $productDescription = null,
1138
        $productName = null,
1139
        $productQuantity = null,
1140
        $shippingAddress = null,
1141
        $shippingCity = null,
1142
        $shippingCountry = null,
1143
        $shippingCurrency = null,
1144
        $shippingFee = null,
1145
        $shippingFeeConverted = null,
1146
        $shippingState = null,
1147
        $shippingZip = null,
1148
        $socialType = null,
1149
        $source = null,
1150
        $sourceFeeCurrency = null,
1151
        $sourceFee = null,
1152
        $sourceFeeConverted = null,
1153
        $taxCurrency = null,
1154
        $taxFee = null,
1155
        $taxFeeConverted = null,
1156
        $userMerchantId = null,
1157
        $websiteUrl = null,
1158
        $productUrl = null,
1159
        $productImageUrl = null
1160
    ) {
1161
        $envelopeType = 'order_item';
1162
        $builder = new self($envelopeType, $sequenceId);
1163
        if ($eventTimestamp === null) {
1164
            $eventTimestamp = time();
1165
        }
1166
        return $builder
1167
            ->addOrderData(
1168
                $envelopeType,
1169
                $amount,
1170
                $currency,
1171
                $eventId,
1172
                $eventTimestamp,
1173
                $transactionId,
1174
                $groupId,
1175
                null,
1176
                $orderType,
1177
                $amountConverted,
1178
                $campaign,
1179
                $carrier,
1180
                $carrierShippingId,
1181
                $carrierUrl,
1182
                $carrierPhone,
1183
                $couponStartDate,
1184
                $couponEndDate,
1185
                $couponId,
1186
                $couponName,
1187
                $customerComment,
1188
                $deliveryEstimate,
1189
                $shippingAddress,
1190
                $shippingCity,
1191
                $shippingCountry,
1192
                $shippingCurrency,
1193
                $shippingFee,
1194
                $shippingFeeConverted,
1195
                $shippingState,
1196
                $shippingZip,
1197
                $source,
1198
                $sourceFee,
1199
                $sourceFeeCurrency,
1200
                $sourceFeeConverted,
1201
                $taxCurrency,
1202
                $taxFee,
1203
                $taxFeeConverted,
1204
                $productUrl,
1205
                $productImageUrl
1206
            )
1207
            ->addUserData(
1208
                $email,
1209
                $userMerchantId,
1210
                $phone,
1211
                '',
1212
                $firstName,
1213
                $lastName,
1214
                '',
1215
                0,
1216
                '',
1217
                $socialType
1218
            )
1219
            -> addProductData(
1220
                $productQuantity,
1221
                $productName,
1222
                $productDescription
1223
            )
1224
            ->addWebsiteData(
1225
                $websiteUrl,
1226
                null,
1227
                $affiliateId
1228
            );
1229
    }
1230
1231
    /**
1232
     * Returns builder for order_submit request
1233
     *
1234
     * @param string $sequenceId
1235
     * @param float $amount
1236
     * @param string $currency
1237
     * @param string $eventId
1238
     * @param int $eventTimestamp
1239
     * @param int $itemsQuantity
1240
     * @param string|null $transactionId
1241
     * @param string|null $groupId
1242
     * @param string|null $affiliateId
1243
     * @param float|null $amountConverted
1244
     * @param string|null $campaign
1245
     * @param string|null $carrier
1246
     * @param string|null $carrierShippingId
1247
     * @param string|null $carrierUrl
1248
     * @param string|null $carrierPhone
1249
     * @param int|null $couponStartDate
1250
     * @param int|null $couponEndDate
1251
     * @param string|null $couponId
1252
     * @param string|null $couponName
1253
     * @param string|null $customerComment
1254
     * @param int|null $deliveryEstimate
1255
     * @param string|null $email
1256
     * @param string|null $firstName
1257
     * @param string|null $lastName
1258
     * @param string|null $phone
1259
     * @param string|null $shippingAddress
1260
     * @param string|null $shippingCity
1261
     * @param string|null $shippingCountry
1262
     * @param string|null $shippingCurrency
1263
     * @param float|null $shippingFee
1264
     * @param float|null $shippingFeeConverted
1265
     * @param string|null $shippingState
1266
     * @param string|null $shippingZip
1267
     * @param string|null $socialType
1268
     * @param string|null $source
1269
     * @param string|null $sourceFeeCurrency
1270
     * @param float|null $sourceFee
1271
     * @param float|null $sourceFeeConverted
1272
     * @param string|null $taxCurrency
1273
     * @param float|null $taxFee
1274
     * @param float|null $taxFeeConverted
1275
     * @param string|null $userMerchantId
1276
     * @param string|null $websiteUrl
1277
     * @param string|null $productUrl
1278
     * @param string|null $productImageUrl
1279
     * @return Builder
1280
     */
1281
    public static function orderSubmitEvent(
1282
        $sequenceId,
1283
        $amount,
1284
        $currency,
1285
        $eventId,
1286
        $eventTimestamp,
1287
        $itemsQuantity,
1288
        $transactionId = null,
1289
        $groupId = null,
1290
        $affiliateId = null,
1291
        $amountConverted = null,
1292
        $campaign = null,
1293
        $carrier = null,
1294
        $carrierShippingId = null,
1295
        $carrierUrl = null,
1296
        $carrierPhone = null,
1297
        $couponStartDate = null,
1298
        $couponEndDate = null,
1299
        $couponId = null,
1300
        $couponName = null,
1301
        $customerComment = null,
1302
        $deliveryEstimate = null,
1303
        $email = null,
1304
        $firstName = null,
1305
        $lastName = null,
1306
        $phone = null,
1307
        $shippingAddress = null,
1308
        $shippingCity = null,
1309
        $shippingCountry = null,
1310
        $shippingCurrency = null,
1311
        $shippingFee = null,
1312
        $shippingFeeConverted = null,
1313
        $shippingState = null,
1314
        $shippingZip = null,
1315
        $socialType = null,
1316
        $source = null,
1317
        $sourceFeeCurrency = null,
1318
        $sourceFee = null,
1319
        $sourceFeeConverted = null,
1320
        $taxCurrency = null,
1321
        $taxFee = null,
1322
        $taxFeeConverted = null,
1323
        $userMerchantId = null,
1324
        $websiteUrl = null,
1325
        $productUrl = null,
1326
        $productImageUrl = null
1327
    ) {
1328
        $envelopeType = 'order_submit';
1329
        $builder = new self($envelopeType, $sequenceId);
1330
        if ($eventTimestamp === null) {
1331
            $eventTimestamp = time();
1332
        }
1333
        return $builder
1334
            ->addOrderData(
1335
                $envelopeType,
1336
                $amount,
1337
                $currency,
1338
                $eventId,
1339
                $eventTimestamp,
1340
                $transactionId,
1341
                $groupId,
1342
                $itemsQuantity,
1343
                null,
1344
                $amountConverted,
1345
                $campaign,
1346
                $carrier,
1347
                $carrierShippingId,
1348
                $carrierUrl,
1349
                $carrierPhone,
1350
                $couponStartDate,
1351
                $couponEndDate,
1352
                $couponId,
1353
                $couponName,
1354
                $customerComment,
1355
                $deliveryEstimate,
1356
                $shippingAddress,
1357
                $shippingCity,
1358
                $shippingCountry,
1359
                $shippingCurrency,
1360
                $shippingFee,
1361
                $shippingFeeConverted,
1362
                $shippingState,
1363
                $shippingZip,
1364
                $source,
1365
                $sourceFee,
1366
                $sourceFeeCurrency,
1367
                $sourceFeeConverted,
1368
                $taxCurrency,
1369
                $taxFee,
1370
                $taxFeeConverted,
1371
                $productUrl,
1372
                $productImageUrl
1373
            )
1374
            ->addUserData(
1375
                $email,
1376
                $userMerchantId,
1377
                $phone,
1378
                '',
1379
                $firstName,
1380
                $lastName,
1381
                '',
1382
                0,
1383
                '',
1384
                $socialType
1385
            )
1386
            ->addWebsiteData(
1387
                $websiteUrl,
1388
                null,
1389
                $affiliateId
1390
            );
1391
    }
1392
1393
    /**
1394
     * Returns builder for postback request
1395
     *
1396
     * @param int|null $requestId
1397
     * @param string|null $transactionId
1398
     * @param string|null $transactionStatus
1399
     * @param string|null $code
1400
     * @param string|null $reason
1401
     * @param string|null $secure3d
1402
     * @param string|null $avsResult
1403
     * @param string|null $cvvResult
1404
     * @param string|null $pspCode
1405
     * @param string|null $pspReason
1406
     * @param string|null $arn
1407
     * @param string|null $paymentAccountId
1408
     * @return Builder
1409
     */
1410
    public static function postBackEvent(
1411
        $requestId =  null,
1412
        $transactionId = null,
1413
        $transactionStatus = null,
1414
        $code = null,
1415
        $reason = null,
1416
        $secure3d = null,
1417
        $avsResult = null,
1418
        $cvvResult = null,
1419
        $pspCode = null,
1420
        $pspReason = null,
1421
        $arn = null,
1422
        $paymentAccountId = null
1423
    ) {
1424
        $builder = new self('postback', '');
1425
        return $builder->addPostBackData(
1426
            $requestId,
1427
            $transactionId,
1428
            $transactionStatus,
1429
            $code,
1430
            $reason,
1431
            $secure3d,
1432
            $avsResult,
1433
            $cvvResult,
1434
            $pspCode,
1435
            $pspReason,
1436
            $arn,
1437
            $paymentAccountId
1438
       );
1439
    }
1440
1441
    /**
1442
     * Builder constructor.
1443
     *
1444
     * @param string $envelopeType
1445
     * @param string $sequenceId
1446
     */
1447
    public function __construct($envelopeType, $sequenceId)
1448
    {
1449
        if (!is_string($envelopeType)) {
1450
            throw new \InvalidArgumentException('Envelope type must be string');
1451
        }
1452
        if (!is_string($sequenceId)) {
1453
            throw new \InvalidArgumentException('Sequence ID must be string');
1454
        }
1455
1456
        $this->type = $envelopeType;
1457
        $this->sequenceId = $sequenceId;
1458
    }
1459
1460
    /**
1461
     * Returns built envelope
1462
     *
1463
     * @return EnvelopeInterface
1464
     */
1465
    public function build()
1466
    {
1467
        return new Envelope(
1468
            $this->type,
1469
            $this->sequenceId,
1470
            $this->identities,
1471
            array_filter($this->data, function ($data) {
1472
                return $data !== null;
1473
            })
1474
        );
1475
    }
1476
1477
    /**
1478
     * Replaces value in internal array if provided value not empty
1479
     *
1480
     * @param string $key
1481
     * @param string|int|float|bool|null $value
1482
     */
1483
    private function replace($key, $value)
1484
    {
1485
        if ($value !== null && $value !== '' && $value !== 0 && $value !== 0.0) {
1486
            $this->data[$key] = $value;
1487
        }
1488
    }
1489
1490
    /**
1491
     * Adds identity node
1492
     *
1493
     * @param IdentityNodeInterface $identity
1494
     *
1495
     * @return $this
1496
     */
1497
    public function addIdentity(IdentityNodeInterface $identity)
1498
    {
1499
        $this->identities[] = $identity;
1500
        return $this;
1501
    }
1502
1503
    /**
1504
     * Provides website URL to envelope
1505
     *
1506
     * @param string|null $websiteUrl
1507
     * @param string|null $traffic_source
1508
     * @param string|null $affiliate_id
1509
     * @param string|null $campaign
1510
     *
1511
     * @return $this
1512
     */
1513
    public function addWebsiteData($websiteUrl = null, $traffic_source = null, $affiliate_id = null, $campaign = null)
1514
    {
1515
        if ($websiteUrl !== null && !is_string($websiteUrl)) {
1516
            throw new \InvalidArgumentException('Website URL must be string');
1517
        }
1518
        if ($traffic_source !== null && !is_string($traffic_source)) {
1519
            throw new \InvalidArgumentException('Traffic source must be string');
1520
        }
1521
        if ($affiliate_id !== null && !is_string($affiliate_id)) {
1522
            throw new \InvalidArgumentException('Affiliate ID must be string');
1523
        }
1524
        if ($campaign !== null && !is_string($campaign)) {
1525
            throw new \InvalidArgumentException('Campaign must be string');
1526
        }
1527
1528
        $this->replace('website_url', $websiteUrl);
1529
        $this->replace('traffic_source', $traffic_source);
1530
        $this->replace('affiliate_id', $affiliate_id);
1531
        $this->replace('campaign', $campaign);
1532
        return $this;
1533
    }
1534
1535
    /**
1536
     * Provides IP information for envelope
1537
     *
1538
     * @param string|null $ip User's IP address
1539
     * @param string|null $realIp User's real IP address, if available
1540
     * @param string|null $merchantIp Your website's IP address
1541
     *
1542
     * @return $this
1543
     */
1544
    public function addIpData($ip = '', $realIp = '', $merchantIp = '')
1545
    {
1546
        if ($ip !== null && !is_string($ip)) {
1547
            throw new \InvalidArgumentException('IP must be string');
1548
        }
1549
        if ($realIp !== null && !is_string($realIp)) {
1550
            throw new \InvalidArgumentException('Real IP must be string');
1551
        }
1552
        if ($merchantIp !== null && !is_string($merchantIp)) {
1553
            throw new \InvalidArgumentException('Merchant IP must be string');
1554
        }
1555
1556
        $this->replace('ip', $ip);
1557
        $this->replace('real_ip', $realIp);
1558
        $this->replace('merchant_ip', $merchantIp);
1559
1560
        return $this;
1561
    }
1562
1563
    /**
1564
     * Provides browser information for envelope
1565
     *
1566
     * @param string|null $deviceFingerprint
1567
     * @param string|null $userAgent
1568
     * @param string|null $cpuClass
1569
     * @param string|null $screenOrientation
1570
     * @param string|null $screenResolution
1571
     * @param string|null $os
1572
     * @param int|null $timezoneOffset
1573
     * @param string|null $languages
1574
     * @param string|null $language
1575
     * @param string|null $languageBrowser
1576
     * @param string|null $languageUser
1577
     * @param string|null $languageSystem
1578
     * @param bool|null $cookieEnabled
1579
     * @param bool|null $doNotTrack
1580
     * @param bool|null $ajaxValidation
1581
     * @param string|null $deviceId
1582
     * @param string|null $ipList
1583
     * @param string|null $plugins
1584
     * @param string|null $refererUrl
1585
     * @param string|null $originUrl
1586
     * @param string|null $clientResolution
1587
     * @return $this
1588
     */
1589
    public function addBrowserData(
1590
        $deviceFingerprint = '',
1591
        $userAgent = '',
1592
        $cpuClass = '',
1593
        $screenOrientation = '',
1594
        $screenResolution = '',
1595
        $os = '',
1596
        $timezoneOffset = null,
1597
        $languages = '',
1598
        $language = '',
1599
        $languageBrowser = '',
1600
        $languageUser = '',
1601
        $languageSystem = '',
1602
        $cookieEnabled = null,
1603
        $doNotTrack = null,
1604
        $ajaxValidation = null,
1605
        $deviceId = '',
1606
        $ipList = null,
1607
        $plugins = null,
1608
        $refererUrl = null,
1609
        $originUrl = null,
1610
        $clientResolution = null
1611
    ) {
1612
        if ($deviceFingerprint !== null && !is_string($deviceFingerprint)) {
1613
            throw new \InvalidArgumentException('Device fingerprint must be string');
1614
        }
1615
        if ($userAgent !== null && !is_string($userAgent)) {
1616
            throw new \InvalidArgumentException('User agent must be string');
1617
        }
1618
        if ($cpuClass !== null && !is_string($cpuClass)) {
1619
            throw new \InvalidArgumentException('CPU class must be string');
1620
        }
1621
        if ($screenOrientation !== null && !is_string($screenOrientation)) {
1622
            throw new \InvalidArgumentException('Screen orientation must be string');
1623
        }
1624
        if ($screenResolution !== null && !is_string($screenResolution)) {
1625
            throw new \InvalidArgumentException('Screen resolution must be string');
1626
        }
1627
        if ($os !== null && !is_string($os)) {
1628
            throw new \InvalidArgumentException('OS must be string');
1629
        }
1630
        if ($timezoneOffset !== null && $timezoneOffset !== null && !is_int($timezoneOffset)) {
1631
            throw new \InvalidArgumentException('Timezone offset must be integer or null');
1632
        }
1633
        if ($languages !== null && !is_string($languages)) {
1634
            throw new \InvalidArgumentException('Languages must be string');
1635
        }
1636
        if ($language !== null && !is_string($language)) {
1637
            throw new \InvalidArgumentException('Language must be string');
1638
        }
1639
        if ($languageBrowser !== null && !is_string($languageBrowser)) {
1640
            throw new \InvalidArgumentException('Browser language must be string');
1641
        }
1642
        if ($languageUser !== null && !is_string($languageUser)) {
1643
            throw new \InvalidArgumentException('User language must be string');
1644
        }
1645
        if ($languageSystem !== null && !is_string($languageSystem)) {
1646
            throw new \InvalidArgumentException('System language must be string');
1647
        }
1648
        if ($cookieEnabled !== null && !is_bool($cookieEnabled)) {
1649
            throw new \InvalidArgumentException('Cookie enabled flag must be boolean');
1650
        }
1651
        if ($doNotTrack !== null && !is_bool($doNotTrack)) {
1652
            throw new \InvalidArgumentException('DNT flag must be boolean');
1653
        }
1654
        if ($ajaxValidation !== null && !is_bool($ajaxValidation)) {
1655
            throw new \InvalidArgumentException('AJAX validation flag must be boolean');
1656
        }
1657
        if ($deviceId !== null && !is_string($deviceId)) {
1658
            throw new \InvalidArgumentException('Device id must be string');
1659
        }
1660
        if ($ipList !== null && !is_string($ipList)) {
1661
            throw new \InvalidArgumentException('Ip list must be string');
1662
        }
1663
        if ($plugins !== null && !is_string($plugins)) {
1664
            throw new \InvalidArgumentException('Plugins must be string');
1665
        }
1666
        if ($refererUrl !== null && !is_string($refererUrl)) {
1667
            throw new \InvalidArgumentException('Referer url must be string');
1668
        }
1669
        if ($originUrl !== null && !is_string($originUrl)) {
1670
            throw new \InvalidArgumentException('Origin url must be string');
1671
        }
1672
        if ($clientResolution !== null && !is_string($clientResolution)) {
1673
            throw new \InvalidArgumentException('Client resolution must be string');
1674
        }
1675
1676
        $this->replace('device_fingerprint', $deviceFingerprint);
1677
        $this->replace('user_agent', $userAgent);
1678
        $this->replace('cpu_class', $cpuClass);
1679
        $this->replace('screen_orientation', $screenOrientation);
1680
        $this->replace('screen_resolution', $screenResolution);
1681
        $this->replace('os', $os);
1682
        $this->replace('timezone_offset', $timezoneOffset);
1683
        $this->replace('languages', $languages);
1684
        $this->replace('language', $language);
1685
        $this->replace('language_browser', $languageBrowser);
1686
        $this->replace('language_system', $languageSystem);
1687
        $this->replace('language_user', $languageUser);
1688
        $this->replace('cookie_enabled', $cookieEnabled);
1689
        $this->replace('do_not_track', $doNotTrack);
1690
        $this->replace('ajax_validation', $ajaxValidation);
1691
        $this->replace('device_id', $deviceId);
1692
        $this->replace('local_ip_list', $ipList);
1693
        $this->replace('plugins', $plugins);
1694
        $this->replace('referer_url', $refererUrl);
1695
        $this->replace('origin_url', $originUrl);
1696
        $this->replace('client_resolution', $clientResolution);
1697
1698
        return $this;
1699
    }
1700
1701
    /**
1702
     * Provides user data for envelope
1703
     *
1704
     * @param string|null $email
1705
     * @param string|null $userId
1706
     * @param string|null $phone
1707
     * @param string|null $userName
1708
     * @param string|null $firstName
1709
     * @param string|null $lastName
1710
     * @param string|null $gender
1711
     * @param int|null $age
1712
     * @param string|null $country
1713
     * @param string|null $socialType
1714
     * @param int|null $registrationTimestamp
1715
     * @param int|null $loginTimeStamp
1716
     * @param int|null $confirmationTimeStamp
1717
     * @param bool|null $emailConfirmed
1718
     * @param bool|null $phoneConfirmed
1719
     * @param bool|null $loginFailed
1720
     * @param int|null $birthDate
1721
     * @param string|null $fullname
1722
     * @param string|null $state
1723
     * @param string|null $city
1724
     * @param string|null $address
1725
     * @param string|null $zip
1726
     * @param string|null $password
1727
     *
1728
     * @return $this
1729
     */
1730
    public function addUserData(
1731
        $email = '',
1732
        $userId = '',
1733
        $phone = '',
1734
        $userName = '',
1735
        $firstName = '',
1736
        $lastName = '',
1737
        $gender = '',
1738
        $age = 0,
1739
        $country = '',
1740
        $socialType = '',
1741
        $registrationTimestamp = 0,
1742
        $loginTimeStamp = 0,
1743
        $confirmationTimeStamp = 0,
1744
        $emailConfirmed = null,
1745
        $phoneConfirmed = null,
1746
        $loginFailed = null,
1747
        $birthDate = null,
1748
        $fullname = null,
1749
        $state = null,
1750
        $city = null,
1751
        $address = null,
1752
        $zip = null,
1753
        $password = ''
1754
    )
1755
    {
1756
        if ($userName !== null && !is_string($userName)) {
1757
            throw new \InvalidArgumentException('User name must be string');
1758
        }
1759
        if ($password !== null && !is_string($password)) {
1760
            throw new \InvalidArgumentException('Password must be string');
1761
        }
1762
        if ($gender !== null && !is_string($gender)) {
1763
            throw new \InvalidArgumentException('Gender must be string');
1764
        }
1765
        if ($age !== null && !is_int($age)) {
1766
            throw new \InvalidArgumentException('Age must be integer');
1767
        }
1768
        if ($socialType !== null && !is_string($socialType)) {
1769
            throw new \InvalidArgumentException('Social type must be string');
1770
        }
1771
        if ($registrationTimestamp !== null && !is_int($registrationTimestamp)) {
1772
            throw new \InvalidArgumentException('Registration timestamp must be integer');
1773
        }
1774
        if ($loginTimeStamp !== null && !is_int($loginTimeStamp)) {
1775
            throw new \InvalidArgumentException('Login timestamp must be integer');
1776
        }
1777
        if ($confirmationTimeStamp !== null && !is_int($confirmationTimeStamp)) {
1778
            throw new \InvalidArgumentException('Confirmation timestamp must be integer');
1779
        }
1780
        if ($birthDate !== null && !is_int($birthDate)) {
1781
            throw new \InvalidArgumentException('Birthdate timestamp must be integer');
1782
        }
1783
        if ($emailConfirmed !== null && !is_bool($emailConfirmed)) {
1784
            throw new \InvalidArgumentException('Email confirmed flag must be boolean');
1785
        }
1786
        if ($phoneConfirmed !== null && !is_bool($phoneConfirmed)) {
1787
            throw new \InvalidArgumentException('Phone confirmed flag must be boolean');
1788
        }
1789
        if ($loginFailed !== null && !is_bool($loginFailed)) {
1790
            throw new \InvalidArgumentException('Login failed flag must be boolean');
1791
        }
1792
        if ($fullname !== null && !is_string($fullname)) {
1793
            throw new \InvalidArgumentException('Fullname must be string');
1794
        }
1795
        if ($state !== null && !is_string($state)) {
1796
            throw new \InvalidArgumentException('State must be string');
1797
        }
1798
        if ($city !== null && !is_string($city)) {
1799
            throw new \InvalidArgumentException('City must be string');
1800
        }
1801
        if ($address !== null && !is_string($address)) {
1802
            throw new \InvalidArgumentException('Address must be string');
1803
        }
1804
        if ($zip !== null && !is_string($zip)) {
1805
            throw new \InvalidArgumentException('Zip must be string');
1806
        }
1807
1808
        $this->addShortUserData($email, $userId, $phone, $firstName, $lastName, $country);
1809
1810
        $this->replace('user_name', $userName);
1811
        $this->replace('gender', $gender);
1812
        $this->replace('age', $age);
1813
        $this->replace('social_type', $socialType);
1814
        $this->replace('registration_timestamp', $registrationTimestamp);
1815
        $this->replace('login_timestamp', $loginTimeStamp);
1816
        $this->replace('confirmation_timestamp', $confirmationTimeStamp);
1817
        $this->replace('email_confirmed', $emailConfirmed);
1818
        $this->replace('phone_confirmed', $phoneConfirmed);
1819
        $this->replace('login_failed', $loginFailed);
1820
        $this->replace('birth_date', $birthDate);
1821
        $this->replace('fullname', $fullname);
1822
        $this->replace('state', $state);
1823
        $this->replace('city', $city);
1824
        $this->replace('address', $address);
1825
        $this->replace('zip', $zip);
1826
        $this->replace('password', $password);
1827
1828
        return $this;
1829
    }
1830
1831
    /**
1832
     * Provides user data for envelope
1833
     *
1834
     * @param string|null $email
1835
     * @param string|null $userId
1836
     * @param string|null $phone
1837
     * @param string|null $firstName
1838
     * @param string|null $lastName
1839
     * @param string|null $country
1840
     *
1841
     * @return $this
1842
     */
1843
    public function addShortUserData(
1844
        $email = '',
1845
        $userId = '',
1846
        $phone = '',
1847
        $firstName = '',
1848
        $lastName = '',
1849
        $country = ''
1850
    ) {
1851
        if ($email !== null && !is_string($email)) {
1852
            throw new \InvalidArgumentException('Email must be string');
1853
        }
1854
        if (is_int($userId)) {
1855
            $userId = strval($userId);
1856
        }
1857
        if ($userId !== null && !is_string($userId)) {
1858
            throw new \InvalidArgumentException('UserId must be string or integer');
1859
        }
1860
        if ($phone !== null && !is_string($phone)) {
1861
            throw new \InvalidArgumentException('Phone must be string');
1862
        }
1863
        if ($firstName !== null && !is_string($firstName)) {
1864
            throw new \InvalidArgumentException('First name must be string');
1865
        }
1866
        if ($lastName !== null && !is_string($lastName)) {
1867
            throw new \InvalidArgumentException('Last name must be string');
1868
        }
1869
        if ($country !== null && !is_string($country)) {
1870
            throw new \InvalidArgumentException('Country must be string');
1871
        }
1872
1873
        $this->replace('email', $email);
1874
        $this->replace('user_merchant_id', $userId);
1875
        $this->replace('phone', $phone);
1876
        $this->replace('firstname', $firstName);
1877
        $this->replace('lastname', $lastName);
1878
        $this->replace('country', $country);
1879
1880
        return $this;
1881
    }
1882
1883
    /**
1884
     * Provides credit card data to envelope
1885
     *
1886
     * @param string|null $transactionId
1887
     * @param string|null $transactionSource
1888
     * @param string|null $transactionType
1889
     * @param string|null $transactionMode
1890
     * @param string|null $transactionTimestamp
1891
     * @param string|null $transactionCurrency
1892
     * @param string|null $transactionAmount
1893
     * @param float|null $amountConverted
1894
     * @param string|null $paymentMethod
1895
     * @param string|null $paymentSystem
1896
     * @param string|null $paymentMidName
1897
     * @param string|null $paymentAccountId
1898
     * @param string|null $merchantCountry
1899
     * @param string|null $mcc
1900
     * @param string|null $acquirerMerchantId
1901
     * @return $this
1902
     */
1903
    public function addCCTransactionData(
1904
        $transactionId,
1905
        $transactionSource,
1906
        $transactionType,
1907
        $transactionMode,
1908
        $transactionTimestamp,
1909
        $transactionCurrency,
1910
        $transactionAmount,
1911
        $amountConverted = null,
1912
        $paymentMethod = null,
1913
        $paymentSystem = null,
1914
        $paymentMidName = null,
1915
        $paymentAccountId = null,
1916
        $merchantCountry = null,
1917
        $mcc = null,
1918
        $acquirerMerchantId = null
1919
    ) {
1920
        if ($transactionId !== null && !is_string($transactionId)) {
1921
            throw new \InvalidArgumentException('Transaction ID must be string');
1922
        }
1923
        if ($transactionSource !== null && !is_string($transactionSource)) {
1924
            throw new \InvalidArgumentException('Transaction source must be string');
1925
        }
1926
        if ($transactionType !== null && !is_string($transactionType)) {
1927
            throw new \InvalidArgumentException('Transaction type must be string');
1928
        }
1929
        if ($transactionMode !== null && !is_string($transactionMode)) {
1930
            throw new \InvalidArgumentException('Transaction mode must be string');
1931
        }
1932
        if ($transactionTimestamp !== null && !is_int($transactionTimestamp)) {
1933
            throw new \InvalidArgumentException('Transaction timestamp must be integer');
1934
        }
1935
        if ($transactionAmount !== null && !is_int($transactionAmount) && !is_float($transactionAmount)) {
1936
            throw new \InvalidArgumentException('Transaction amount must be float');
1937
        }
1938
        if ($transactionCurrency !== null && !is_string($transactionCurrency)) {
1939
            throw new \InvalidArgumentException('Transaction currency must be string');
1940
        }
1941
        if ($paymentMethod !== null && !is_string($paymentMethod)) {
1942
            throw new \InvalidArgumentException('Payment method must be string');
1943
        }
1944
        if ($paymentSystem !== null && !is_string($paymentSystem)) {
1945
            throw new \InvalidArgumentException('Payment system must be string');
1946
        }
1947
        if ($paymentMidName !== null && !is_string($paymentMidName)) {
1948
            throw new \InvalidArgumentException('Payment MID name must be string');
1949
        }
1950
        if ($paymentAccountId !== null && !is_string($paymentAccountId)) {
1951
            throw new \InvalidArgumentException('Payment account id must be string');
1952
        }
1953 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...
1954
            throw new \InvalidArgumentException('Transaction amount converted must be float');
1955
        }
1956
1957
        if ($merchantCountry !== null && !is_string($merchantCountry)) {
1958
            throw new \InvalidArgumentException('Merchant country must be string');
1959
        }
1960
        if ($mcc !== null && !is_string($mcc)) {
1961
            throw new \InvalidArgumentException('MCC must be string');
1962
        }
1963
        if ($acquirerMerchantId !== null && !is_string($acquirerMerchantId)) {
1964
            throw new \InvalidArgumentException('Acquirer merchant id be string');
1965
        }
1966
        $this->replace('transaction_id', $transactionId);
1967
        $this->replace('transaction_source', $transactionSource);
1968
        $this->replace('transaction_type', $transactionType);
1969
        $this->replace('transaction_mode', $transactionMode);
1970
        $this->replace('transaction_timestamp', $transactionTimestamp);
1971
        $this->replace('transaction_amount', floatval($transactionAmount));
1972
        $this->replace('transaction_amount_converted', floatval($amountConverted));
1973
        $this->replace('transaction_currency', $transactionCurrency);
1974
        $this->replace('payment_method', $paymentMethod);
1975
        $this->replace('payment_system', $paymentSystem);
1976
        $this->replace('payment_mid', $paymentMidName);
1977
        $this->replace('payment_account_id', $paymentAccountId);
1978
        $this->replace('merchant_country', $merchantCountry);
1979
        $this->replace('mcc', $mcc);
1980
        $this->replace('acquirer_merchant_id', $acquirerMerchantId);
1981
1982
        return $this;
1983
    }
1984
1985
    /**
1986
     * Provides Card data to envelope
1987
     *
1988
     * @param string|null $cardId
1989
     * @param int|null $cardBin
1990
     * @param string|null $cardLast4
1991
     * @param int|null $expirationMonth
1992
     * @param int|null $expirationYear
1993
     *
1994
     * @return $this
1995
     */
1996
    public function addCardData(
1997
        $cardBin,
1998
        $cardLast4,
1999
        $expirationMonth,
2000
        $expirationYear,
2001
        $cardId = null
2002
    ) {
2003
        if ($cardId !== null && !is_string($cardId)) {
2004
            throw new \InvalidArgumentException('Card ID must be string');
2005
        }
2006
        if ($cardBin !== null && !is_int($cardBin)) {
2007
            throw new \InvalidArgumentException('Card BIN must be integer');
2008
        }
2009
        if ($cardLast4 !== null && !is_string($cardLast4)) {
2010
            throw new \InvalidArgumentException('Card last4  must be string');
2011
        }
2012
        if ($expirationMonth !== null && !is_int($expirationMonth)) {
2013
            throw new \InvalidArgumentException('Expiration month must be integer');
2014
        }
2015
        if ($expirationYear !== null && !is_int($expirationYear)) {
2016
            throw new \InvalidArgumentException('Expiration year must be integer');
2017
        }
2018
2019
        $this->replace('card_id', $cardId);
2020
        $this->replace('card_bin', $cardBin);
2021
        $this->replace('card_last4', $cardLast4);
2022
        $this->replace('expiration_month', $expirationMonth);
2023
        $this->replace('expiration_year', $expirationYear);
2024
2025
        return $this;
2026
    }
2027
2028
    /**
2029
     * Provides billing data to envelope
2030
     *
2031
     * @param string|null $billingFirstName
2032
     * @param string|null $billingLastName
2033
     * @param string|null $billingFullName
2034
     * @param string|null $billingCountry
2035
     * @param string|null $billingState
2036
     * @param string|null $billingCity
2037
     * @param string|null $billingAddress
2038
     * @param string|null $billingZip
2039
     *
2040
     * @return $this
2041
     */
2042
    public function addBillingData(
2043
        $billingFirstName = null,
2044
        $billingLastName = null,
2045
        $billingFullName = null,
2046
        $billingCountry = null,
2047
        $billingState = null,
2048
        $billingCity = null,
2049
        $billingAddress = null,
2050
        $billingZip = null
2051
    ) {
2052
        if ($billingFirstName !== null && !is_string($billingFirstName)) {
2053
            throw new \InvalidArgumentException('Billing first name must be string');
2054
        }
2055
        if ($billingLastName !== null && !is_string($billingLastName)) {
2056
            throw new \InvalidArgumentException('Billing last name must be string');
2057
        }
2058
        if ($billingFullName !== null && !is_string($billingFullName)) {
2059
            throw new \InvalidArgumentException('Billing full name must be string');
2060
        }
2061
        if ($billingCountry !== null && !is_string($billingCountry)) {
2062
            throw new \InvalidArgumentException('Billing country name must be string');
2063
        }
2064
        if ($billingState !== null && !is_string($billingState)) {
2065
            throw new \InvalidArgumentException('Billing state must be string');
2066
        }
2067
        if ($billingCity !== null && !is_string($billingCity)) {
2068
            throw new \InvalidArgumentException('Billing city must be string');
2069
        }
2070
        if ($billingAddress !== null && !is_string($billingAddress)) {
2071
            throw new \InvalidArgumentException('Billing address must be string');
2072
        }
2073
        if ($billingZip !== null && !is_string($billingZip)) {
2074
            throw new \InvalidArgumentException('Billing zip must be string');
2075
        }
2076
2077
        $this->replace('billing_firstname', $billingFirstName);
2078
        $this->replace('billing_lastname', $billingLastName);
2079
        $this->replace('billing_fullname', $billingFullName);
2080
        $this->replace('billing_country', $billingCountry);
2081
        $this->replace('billing_state', $billingState);
2082
        $this->replace('billing_city', $billingCity);
2083
        $this->replace('billing_address', $billingAddress);
2084
        $this->replace('billing_zip', $billingZip);
2085
2086
        return $this;
2087
    }
2088
2089
    /**
2090
     * Provides product information to envelope
2091
     *
2092
     * @param float|null $productQuantity
2093
     * @param string|null $productName
2094
     * @param string|null $productDescription
2095
     *
2096
     * @return $this
2097
     */
2098
    public function addProductData(
2099
        $productQuantity = null,
2100
        $productName = null,
2101
        $productDescription = null
2102
    ) {
2103
        if ($productQuantity !== null && !is_int($productQuantity) && !is_float($productQuantity)) {
2104
            throw new \InvalidArgumentException('Product quantity must be int or float');
2105
        }
2106
        if ($productName !== null && !is_string($productName)) {
2107
            throw new \InvalidArgumentException('Product name must be string');
2108
        }
2109
        if ($productDescription !== null && !is_string($productDescription)) {
2110
            throw new \InvalidArgumentException('Product description must be string');
2111
        }
2112
2113
        $this->replace('product_quantity', $productQuantity);
2114
        $this->replace('product_name', $productName);
2115
        $this->replace('product_description', $productDescription);
2116
2117
        return $this;
2118
    }
2119
2120
    /**
2121
     * Provides payout information to envelope
2122
     *
2123
     * @param string $payoutId
2124
     * @param int $payoutTimestamp
2125
     * @param int|float $payoutAmount
2126
     * @param string $payoutCurrency
2127
     * @param string|null $payoutCardId
2128
     * @param string|null $payoutAccountId
2129
     * @param string|null $payoutMethod
2130
     * @param string|null $payoutSystem
2131
     * @param string|null $payoutMid
2132
     * @param int|float|null $amountConverted
2133
     * @param int|null $payoutCardBin
2134
     * @param string|null $payoutCardLast4
2135
     * @param int|null $payoutExpirationMonth
2136
     * @param int|null $payoutExpirationYear
2137
     *
2138
     * @return $this
2139
     */
2140
    public function addPayoutData(
2141
        $payoutId,
2142
        $payoutTimestamp,
2143
        $payoutAmount,
2144
        $payoutCurrency,
2145
        $payoutCardId =  null,
2146
        $payoutAccountId = null,
2147
        $payoutMethod = null,
2148
        $payoutSystem = null,
2149
        $payoutMid = null,
2150
        $amountConverted = null,
2151
        $payoutCardBin = null,
2152
        $payoutCardLast4 = null,
2153
        $payoutExpirationMonth = null,
2154
        $payoutExpirationYear = null
2155
    ) {
2156
        if (!is_string($payoutId)) {
2157
            throw new \InvalidArgumentException('Payout ID must be string');
2158
        }
2159
        if (!is_int($payoutTimestamp)) {
2160
            throw new \InvalidArgumentException('Payout timestamp must be int');
2161
        }
2162
        if (!is_float($payoutAmount) && !is_int($payoutAmount)) {
2163
            throw new \InvalidArgumentException('Amount must be number');
2164
        }
2165
        if (!is_string($payoutCurrency)) {
2166
            throw new \InvalidArgumentException('Payout currency must be string');
2167
        }
2168
        if ($payoutAccountId !== null && !is_string($payoutAccountId)) {
2169
            throw new \InvalidArgumentException('Account ID must be string');
2170
        }
2171
        if ($payoutCardId !== null && !is_string($payoutCardId)) {
2172
            throw new \InvalidArgumentException('Card ID must be string');
2173
        }
2174
        if ($payoutMethod !== null && !is_string($payoutMethod)) {
2175
            throw new \InvalidArgumentException('Payout method must be string');
2176
        }
2177
        if ($payoutSystem !== null && !is_string($payoutSystem)) {
2178
            throw new \InvalidArgumentException('Payout system must be string');
2179
        }
2180
        if ($payoutMid !== null && !is_string($payoutMid)) {
2181
            throw new \InvalidArgumentException('Payout MID must be string');
2182
        }
2183 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...
2184
            throw new \InvalidArgumentException('Payout converted amount must be number');
2185
        }
2186
        if ($payoutCardBin !== null && !is_int($payoutCardBin)) {
2187
            throw new \InvalidArgumentException('Payout card BIN must be integer');
2188
        }
2189
        if ($payoutCardLast4 !== null && !is_string($payoutCardLast4)) {
2190
            throw new \InvalidArgumentException('Payout last 4 must be string');
2191
        }
2192
        if ($payoutExpirationMonth !== null && !is_int($payoutExpirationMonth)) {
2193
            throw new \InvalidArgumentException('Payout card expiration month must be integer');
2194
        }
2195
        if ($payoutExpirationYear !== null && !is_int($payoutExpirationYear)) {
2196
            throw new \InvalidArgumentException('Payout card expiration year must be integer');
2197
        }
2198
2199
        $this->replace('payout_id', $payoutId);
2200
        $this->replace('payout_timestamp', $payoutTimestamp);
2201
        $this->replace('payout_card_id', $payoutCardId);
2202
        $this->replace('payout_account_id', $payoutAccountId);
2203
        $this->replace('payout_amount', (float) $payoutAmount);
2204
        $this->replace('payout_currency', $payoutCurrency);
2205
        $this->replace('payout_method', $payoutMethod);
2206
        $this->replace('payout_system', $payoutSystem);
2207
        $this->replace('payout_mid', $payoutMid);
2208
        $this->replace('payout_amount_converted', (float) $amountConverted);
2209
        $this->replace('payout_card_bin', $payoutCardBin);
2210
        $this->replace('payout_card_last4', $payoutCardLast4);
2211
        $this->replace('payout_expiration_month', $payoutExpirationMonth);
2212
        $this->replace('payout_expiration_year', $payoutExpirationYear);
2213
2214
        return $this;
2215
    }
2216
2217
    /**
2218
     * Provides install information to envelope
2219
     *
2220
     * @param int $installTimestamp
2221
     *
2222
     * @return $this
2223
     */
2224
    public function addInstallData($installTimestamp)
2225
    {
2226
        if (!is_int($installTimestamp)) {
2227
            throw new \InvalidArgumentException('Install timestamp must be int');
2228
        }
2229
2230
        $this->replace('install_timestamp', $installTimestamp);
2231
2232
        return $this;
2233
    }
2234
2235
    /**
2236
     * Provides refund information to envelope
2237
     *
2238
     * @param string $refundId
2239
     * @param int|float $refundAmount
2240
     * @param string $refundCurrency
2241
     * @param int|null $refundTimestamp
2242
     * @param int|float|null $refundAmountConverted
2243
     * @param string|null $refundSource
2244
     * @param string|null $refundType
2245
     * @param string|null $refundCode
2246
     * @param string|null $refundReason
2247
     * @param string|null $agentId
2248
     * @param string|null $refundMethod
2249
     * @param string|null $refundSystem
2250
     * @param string|null $refundMid
2251
     *
2252
     * @return $this
2253
     */
2254
    public function addRefundData(
2255
        $refundId,
2256
        $refundTimestamp,
2257
        $refundAmount,
2258
        $refundCurrency,
2259
        $refundAmountConverted = null,
2260
        $refundSource = null,
2261
        $refundType = null,
2262
        $refundCode = null,
2263
        $refundReason = null,
2264
        $agentId = null,
2265
        $refundMethod = null,
2266
        $refundSystem = null,
2267
        $refundMid = null
2268
    ) {
2269
        if (!is_string($refundId)) {
2270
            throw new \InvalidArgumentException('Refund ID must be string');
2271
        }
2272
        if (!is_int($refundTimestamp)) {
2273
            throw new \InvalidArgumentException('Refund timestamp must be int');
2274
        }
2275
        if (!is_float($refundAmount) && !is_int($refundAmount)) {
2276
            throw new \InvalidArgumentException('Amount must be number');
2277
        }
2278
        if (!is_string($refundCurrency)) {
2279
            throw new \InvalidArgumentException('Refund currency must be string');
2280
        }
2281
        if ($refundAmountConverted !== null && !is_float($refundAmountConverted) && !is_int($refundAmountConverted)) {
2282
            throw new \InvalidArgumentException('Refund converted amount must be number');
2283
        }
2284
        if ($refundSource !== null && !is_string($refundSource)) {
2285
            throw new \InvalidArgumentException('Refund source must be string');
2286
        }
2287
        if ($refundType !== null && !is_string($refundType)) {
2288
            throw new \InvalidArgumentException('Refund type must be string');
2289
        }
2290
        if ($refundCode !== null && !is_string($refundCode)) {
2291
            throw new \InvalidArgumentException('Refund code must be string');
2292
        }
2293
        if ($refundReason !== null && !is_string($refundReason)) {
2294
            throw new \InvalidArgumentException('Refund reason must be string');
2295
        }
2296
        if ($agentId !== null && !is_string($agentId)) {
2297
            throw new \InvalidArgumentException('Agent id must be string');
2298
        }
2299
        if ($refundMethod !== null && !is_string($refundMethod)) {
2300
            throw new \InvalidArgumentException('Refund method must be string');
2301
        }
2302
        if ($refundSystem !== null && !is_string($refundSystem)) {
2303
            throw new \InvalidArgumentException('Refund system must be string');
2304
        }
2305
        if ($refundMid !== null && !is_string($refundMid)) {
2306
            throw new \InvalidArgumentException('Refund mid must be string');
2307
        }
2308
2309
        $this->replace('refund_id', $refundId);
2310
        $this->replace('refund_timestamp', $refundTimestamp);
2311
        $this->replace('refund_amount', $refundAmount);
2312
        $this->replace('refund_currency', $refundCurrency);
2313
        $this->replace('refund_amount_converted', $refundAmountConverted);
2314
        $this->replace('refund_source', $refundSource);
2315
        $this->replace('refund_type', $refundType);
2316
        $this->replace('refund_code', $refundCode);
2317
        $this->replace('refund_reason', $refundReason);
2318
        $this->replace('agent_id', $agentId);
2319
        $this->replace('refund_method', $refundMethod);
2320
        $this->replace('refund_system', $refundSystem);
2321
        $this->replace('refund_mid', $refundMid);
2322
2323
        return $this;
2324
    }
2325
2326
    /**
2327
     * Provides transfer information to envelope
2328
     *
2329
     * @param string $eventId
2330
     * @param int $eventTimestamp
2331
     * @param float $amount
2332
     * @param string $currency
2333
     * @param string $accountId
2334
     * @param string $secondAccountId
2335
     * @param string $accountSystem
2336
     * @param float|null $amountConverted
2337
     * @param string|null $method
2338
     * @param string|null $operation
2339
     * @param string|null $secondEmail
2340
     * @param string|null $secondPhone
2341
     * @param string|int $secondBirthDate
2342
     * @param string|null $secondFirstname
2343
     * @param string|null $secondLastname
2344
     * @param string|null $secondFullname
2345
     * @param string|null $secondState
2346
     * @param string|null $secondCity
2347
     * @param string|null $secondAddress
2348
     * @param string|null $secondZip
2349
     * @param string|null $secondGender
2350
     * @param string|null $secondCountry
2351
     * @param string|null $iban
2352
     * @param string|null $secondIban
2353
     * @param string|null $bic
2354
     * @param string|null $source
2355
     *
2356
     * @return $this
2357
     */
2358
    public function addTransferData(
2359
        $eventId,
2360
        $eventTimestamp,
2361
        $amount,
2362
        $currency,
2363
        $accountId,
2364
        $secondAccountId,
2365
        $accountSystem,
2366
        $amountConverted = null,
2367
        $method = null,
2368
        $operation = null,
2369
        $secondEmail = null,
2370
        $secondPhone = null,
2371
        $secondBirthDate = null,
2372
        $secondFirstname = null,
2373
        $secondLastname = null,
2374
        $secondFullname = null,
2375
        $secondState = null,
2376
        $secondCity = null,
2377
        $secondAddress = null,
2378
        $secondZip = null,
2379
        $secondGender = null,
2380
        $secondCountry = null,
2381
        $iban = null,
2382
        $secondIban = null,
2383
        $bic = null,
2384
        $source = null
2385
    ) {
2386
        if (!is_string($eventId)) {
2387
            throw new \InvalidArgumentException('Event ID must be string');
2388
        }
2389
        if (!is_int($eventTimestamp)) {
2390
            throw new \InvalidArgumentException('Event timestamp must be int');
2391
        }
2392
        if (!is_int($amount) && !is_float($amount)) {
2393
            throw new \InvalidArgumentException('Amount must be number');
2394
        }
2395
        if (!is_string($currency)) {
2396
            throw new \InvalidArgumentException('Currency must be string');
2397
        }
2398
        if (!is_string($accountId)) {
2399
            throw new \InvalidArgumentException('Account id must be string');
2400
        }
2401
        if (!is_string($secondAccountId)) {
2402
            throw new \InvalidArgumentException('Second account id must be string');
2403
        }
2404
        if (!is_string($accountSystem)) {
2405
            throw new \InvalidArgumentException('Account system must be string');
2406
        }
2407 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...
2408
            throw new \InvalidArgumentException('Amount converted must be number');
2409
        }
2410
        if ($method !== null && !is_string($method)) {
2411
            throw new \InvalidArgumentException('Method must be string');
2412
        }
2413
        if ($operation !== null && !is_string($operation)) {
2414
            throw new \InvalidArgumentException('Operation must be string');
2415
        }
2416
        if ($secondPhone !== null && !is_string($secondPhone)) {
2417
            throw new \InvalidArgumentException('Second phone must be string');
2418
        }
2419
        if ($secondEmail !== null && !is_string($secondEmail)) {
2420
            throw new \InvalidArgumentException('Second email must be string');
2421
        }
2422
        if ($secondBirthDate !== null && !is_int($secondBirthDate)) {
2423
            throw new \InvalidArgumentException('Second birth date must be int');
2424
        }
2425
        if ($secondFirstname !== null && !is_string($secondFirstname)) {
2426
            throw new \InvalidArgumentException('Second firstname must be string');
2427
        }
2428
        if ($secondLastname !== null && !is_string($secondLastname)) {
2429
            throw new \InvalidArgumentException('Second lastname must be string');
2430
        }
2431
        if ($secondFullname !== null && !is_string($secondFullname)) {
2432
            throw new \InvalidArgumentException('Second fullname must be string');
2433
        }
2434
        if ($secondState !== null && !is_string($secondState)) {
2435
            throw new \InvalidArgumentException('Second state must be string');
2436
        }
2437
        if ($secondCity !== null && !is_string($secondCity)) {
2438
            throw new \InvalidArgumentException('Second city must be string');
2439
        }
2440
        if ($secondAddress !== null && !is_string($secondAddress)) {
2441
            throw new \InvalidArgumentException('Second address must be string');
2442
        }
2443
        if ($secondZip !== null && !is_string($secondZip)) {
2444
            throw new \InvalidArgumentException('Second zip must be string');
2445
        }
2446
        if ($secondGender !== null && !is_string($secondGender)) {
2447
            throw new \InvalidArgumentException('Second gender must be string');
2448
        }
2449
        if ($secondCountry !== null && !is_string($secondCountry)) {
2450
            throw new \InvalidArgumentException('Second country must be string');
2451
        }
2452
        if ($iban !== null && !is_string($iban)) {
2453
            throw new \InvalidArgumentException('Iban must be string');
2454
        }
2455
        if ($secondIban !== null && !is_string($secondIban)) {
2456
            throw new \InvalidArgumentException('Second iban must be string');
2457
        }
2458
        if ($bic !== null && !is_string($bic)) {
2459
            throw new \InvalidArgumentException('Bic must be string');
2460
        }
2461
        if ($source !== null && !is_string($source)) {
2462
            throw new \InvalidArgumentException('Transfer source must be string');
2463
        }
2464
2465
        $this->replace('event_id', $eventId);
2466
        $this->replace('event_timestamp', $eventTimestamp);
2467
        $this->replace('amount', $amount);
2468
        $this->replace('currency', $currency);
2469
        $this->replace('account_id', $accountId);
2470
        $this->replace('second_account_id', $secondAccountId);
2471
        $this->replace('account_system', $accountSystem);
2472
        $this->replace('amount_converted', $amountConverted);
2473
        $this->replace('method', $method);
2474
        $this->replace('operation', $operation);
2475
        $this->replace('second_email', $secondEmail);
2476
        $this->replace('second_phone', $secondPhone);
2477
        $this->replace('second_birth_date', $secondBirthDate);
2478
        $this->replace('second_firstname', $secondFirstname);
2479
        $this->replace('second_lastname', $secondLastname);
2480
        $this->replace('second_fullname', $secondFullname);
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('second_gender', $secondGender);
2486
        $this->replace('second_country', $secondCountry);
2487
        $this->replace('iban', $iban);
2488
        $this->replace('second_iban', $secondIban);
2489
        $this->replace('bic', $bic);
2490
        $this->replace('transfer_source', $source);
2491
2492
        return $this;
2493
    }
2494
2495
    /**
2496
     * Provides kyc information to envelope
2497
     *
2498
     * @param string $eventId
2499
     * @param int $eventTimestamp
2500
     * @param string|null $groupId
2501
     * @param string|null $status
2502
     * @param string|null $code
2503
     * @param string|null $reason
2504
     * @param string|null $providerResult
2505
     * @param string|null $providerCode
2506
     * @param string|null $providerReason
2507
     * @param string|null $profileId
2508
     * @param string|null $profileType
2509
     * @param string|null $profileSubType
2510
     * @param string|null $industry
2511
     * @param string|null $description
2512
     * @param int|null $regDate
2513
     * @param string|null $regNumber
2514
     * @param string|null $vatNumber
2515
     * @param string|null $secondCountry
2516
     * @param string|null $secondState
2517
     * @param string|null $secondCity
2518
     * @param string|null $secondAddress
2519
     * @param string|null $secondZip
2520
     * @param string|null $providerId
2521
     * @param string|null $contactEmail
2522
     * @param string|null $contactPhone
2523
     * @param string|null $walletType
2524
     * @param string|null $nationality
2525
     * @param bool|null $finalBeneficiary
2526
     * @param string|null $employmentStatus
2527
     * @param string|null $sourceOfFunds
2528
     * @param int|null $issueDate
2529
     * @param int|null $expiryDate
2530
     * @param string|null $verificationMode
2531
     * @param string|null $verificationSource
2532
     * @param bool|null $consent
2533
     * @param bool|null $allowNaOcrInputs
2534
     * @param bool|null $declineOnSingleStep
2535
     * @param bool|null $backsideProof
2536
     * @param string|null $kycLanguage
2537
     * @param string|null $redirectUrl
2538
     * @return $this
2539
     */
2540
    public function addKycData(
2541
        $eventId,
2542
        $eventTimestamp,
2543
        $groupId = null,
2544
        $status = null,
2545
        $code = null,
2546
        $reason = null,
2547
        $providerResult = null,
2548
        $providerCode = null,
2549
        $providerReason = null,
2550
        $profileId = null,
2551
        $profileType = null,
2552
        $profileSubType = null,
2553
        $industry = null,
2554
        $description = null,
2555
        $regDate = null,
2556
        $regNumber = null,
2557
        $vatNumber = null,
2558
        $secondCountry = null,
2559
        $secondState = null,
2560
        $secondCity = null,
2561
        $secondAddress = null,
2562
        $secondZip = null,
2563
        $providerId = null,
2564
        $contactEmail = null,
2565
        $contactPhone = null,
2566
        $walletType = null,
2567
        $nationality = null,
2568
        $finalBeneficiary = null,
2569
        $employmentStatus = null,
2570
        $sourceOfFunds = null,
2571
        $issueDate = null,
2572
        $expiryDate = null,
2573
        $verificationMode = null,
2574
        $verificationSource = null,
2575
        $consent = null,
2576
        $allowNaOcrInputs = null,
2577
        $declineOnSingleStep = null,
2578
        $backsideProof = null,
2579
        $kycLanguage = null,
2580
        $redirectUrl = null
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 ($groupId !== null && !is_string($groupId)) {
2589
            throw new \InvalidArgumentException('Group id must be string');
2590
        }
2591
        if ($status !== null && !is_string($status)) {
2592
            throw new \InvalidArgumentException('Status must be string');
2593
        }
2594
        if ($code !== null && !is_string($code)) {
2595
            throw new \InvalidArgumentException('Code must be string');
2596
        }
2597
        if ($reason !== null && !is_string($reason)) {
2598
            throw new \InvalidArgumentException('Reason must be string');
2599
        }
2600
        if ($providerResult !== null && !is_string($providerResult)) {
2601
            throw new \InvalidArgumentException('Provider result must be string');
2602
        }
2603
        if ($providerCode !== null && !is_string($providerCode)) {
2604
            throw new \InvalidArgumentException('Provider code must be string');
2605
        }
2606
        if ($providerReason !== null && !is_string($providerReason)) {
2607
            throw new \InvalidArgumentException('Provider reason must be string');
2608
        }
2609
        if ($profileId !== null && !is_string($profileId)) {
2610
            throw new \InvalidArgumentException('Profile id must be string');
2611
        }
2612
        if ($profileType !== null && !is_string($profileType)) {
2613
            throw new \InvalidArgumentException('Profile type must be string');
2614
        }
2615
        if ($profileSubType !== null && !is_string($profileSubType)) {
2616
            throw new \InvalidArgumentException('Profile sub type must be string');
2617
        }
2618
        if ($industry !== null && !is_string($industry)) {
2619
            throw new \InvalidArgumentException('Industry must be string');
2620
        }
2621
        if ($description !== null && !is_string($description)) {
2622
            throw new \InvalidArgumentException('Description must be string');
2623
        }
2624
        if ($regDate !== null && !is_int($regDate)) {
2625
            throw new \InvalidArgumentException('Reg date must be integer');
2626
        }
2627
        if ($regNumber !== null && !is_string($regNumber)) {
2628
            throw new \InvalidArgumentException('Reg number must be string');
2629
        }
2630
        if ($vatNumber !== null && !is_string($vatNumber)) {
2631
            throw new \InvalidArgumentException('Vat number must be string');
2632
        }
2633
        if ($secondCountry !== null && !is_string($secondCountry)) {
2634
            throw new \InvalidArgumentException('Secondary country must be string');
2635
        }
2636
        if ($secondState !== null && !is_string($secondState)) {
2637
            throw new \InvalidArgumentException('Second state must be string');
2638
        }
2639
        if ($secondCity !== null && !is_string($secondCity)) {
2640
            throw new \InvalidArgumentException('Second city must be string');
2641
        }
2642
        if ($secondAddress !== null && !is_string($secondAddress)) {
2643
            throw new \InvalidArgumentException('Second address must be string');
2644
        }
2645
        if ($secondZip !== null && !is_string($secondZip)) {
2646
            throw new \InvalidArgumentException('Second zip must be string');
2647
        }
2648
        if ($providerId !== null && !is_string($providerId)) {
2649
            throw new \InvalidArgumentException('Provider id must be string');
2650
        }
2651
        if ($contactEmail !== null && !is_string($contactEmail)) {
2652
            throw new \InvalidArgumentException('Contact email must be string');
2653
        }
2654
        if ($contactPhone !== null && !is_string($contactPhone)) {
2655
            throw new \InvalidArgumentException('Contact phone must be string');
2656
        }
2657
        if ($walletType !== null && !is_string($walletType)) {
2658
            throw new \InvalidArgumentException('Wallet type must be string');
2659
        }
2660
        if ($nationality !== null && !is_string($nationality)) {
2661
            throw new \InvalidArgumentException('Nationality must be string');
2662
        }
2663
        if ($finalBeneficiary !== null && !is_bool($finalBeneficiary)) {
2664
            throw new \InvalidArgumentException('Final beneficiary must be boolean');
2665
        }
2666
        if ($employmentStatus !== null && !is_string($employmentStatus)) {
2667
            throw new \InvalidArgumentException('Employment status must be string');
2668
        }
2669
        if ($sourceOfFunds !== null && !is_string($sourceOfFunds)) {
2670
            throw new \InvalidArgumentException('Source of funds must be string');
2671
        }
2672
        if ($issueDate !== null && !is_int($issueDate)) {
2673
            throw new \InvalidArgumentException('Issue date must be integer');
2674
        }
2675
        if ($expiryDate !== null && !is_int($expiryDate)) {
2676
            throw new \InvalidArgumentException('Expiry date must be integer');
2677
        }
2678
        if ($verificationMode !== null && !is_string($verificationMode)) {
2679
            throw new \InvalidArgumentException('Verification mode must be string');
2680
        }
2681
        if ($verificationSource !== null && !is_string($verificationSource)) {
2682
            throw new \InvalidArgumentException('Verification source must be string');
2683
        }
2684
        if ($consent !== null && !is_bool($consent)) {
2685
            throw new \InvalidArgumentException('Consent must be boolean');
2686
        }
2687
        if ($allowNaOcrInputs !== null && !is_bool($allowNaOcrInputs)) {
2688
            throw new \InvalidArgumentException('Allow na ocr inputs must be boolean');
2689
        }
2690
        if ($declineOnSingleStep !== null && !is_bool($declineOnSingleStep)) {
2691
            throw new \InvalidArgumentException('Decline on single step must be boolean');
2692
        }
2693
        if ($backsideProof !== null && !is_bool($backsideProof)) {
2694
            throw new \InvalidArgumentException('Backside proof must be boolean');
2695
        }
2696
        if ($kycLanguage !== null && !is_string($kycLanguage)) {
2697
            throw new \InvalidArgumentException('Kyc language must be string');
2698
        }
2699
        if ($redirectUrl !== null && !is_string($redirectUrl)) {
2700
            throw new \InvalidArgumentException('Redirect url must be string');
2701
        }
2702
        $this->replace('event_id', $eventId);
2703
        $this->replace('event_timestamp', $eventTimestamp);
2704
        $this->replace('group_id', $groupId);
2705
        $this->replace('status', $status);
2706
        $this->replace('code', $code);
2707
        $this->replace('reason', $reason);
2708
        $this->replace('provider_result', $providerResult);
2709
        $this->replace('provider_code', $providerCode);
2710
        $this->replace('provider_reason', $providerReason);
2711
        $this->replace('profile_id', $profileId);
2712
        $this->replace('profile_type', $profileType);
2713
        $this->replace('profile_sub_type', $profileSubType);
2714
        $this->replace('industry', $industry);
2715
        $this->replace('description', $description);
2716
        $this->replace('reg_date', $regDate);
2717
        $this->replace('reg_number', $regNumber);
2718
        $this->replace('vat_number', $vatNumber);
2719
        $this->replace('second_country', $secondCountry);
2720
        $this->replace('second_state', $secondState);
2721
        $this->replace('second_city', $secondCity);
2722
        $this->replace('second_address', $secondAddress);
2723
        $this->replace('second_zip', $secondZip);
2724
        $this->replace('provider_id', $providerId);
2725
        $this->replace('contact_email', $contactEmail);
2726
        $this->replace('contact_phone', $contactPhone);
2727
        $this->replace('wallet_type', $walletType);
2728
        $this->replace('nationality', $nationality);
2729
        $this->replace('final_beneficiary', $finalBeneficiary);
2730
        $this->replace('employment_status', $employmentStatus);
2731
        $this->replace('source_of_funds', $sourceOfFunds);
2732
        $this->replace('issue_date', $issueDate);
2733
        $this->replace('expiry_date', $expiryDate);
2734
        $this->replace('verification_mode', $verificationMode);
2735
        $this->replace('verification_source', $verificationSource);
2736
        $this->replace('consent', $consent);
2737
        $this->replace('allow_na_ocr_inputs', $allowNaOcrInputs);
2738
        $this->replace('decline_on_single_step', $declineOnSingleStep);
2739
        $this->replace('backside_proof', $backsideProof);
2740
        $this->replace('kyc_language', $kycLanguage);
2741
        $this->replace('redirect_url', $redirectUrl);
2742
2743
        return $this;
2744
    }
2745
2746
    /**
2747
     * Provides order information to envelope
2748
     *
2749
     * @param string $envelopeType
2750
     * @param float $amount
2751
     * @param string $currency
2752
     * @param string $eventId
2753
     * @param int $eventTimestamp
2754
     * @param string|null $transactionId
2755
     * @param string|null $groupId
2756
     * @param int|null $itemsQuantity
2757
     * @param string|null $orderType
2758
     * @param float|null $amountConverted
2759
     * @param string|null $campaign
2760
     * @param string|null $carrier
2761
     * @param string|null $carrierShippingId
2762
     * @param string|null $carrierUrl
2763
     * @param string|null $carrierPhone
2764
     * @param int|null $couponStartDate
2765
     * @param int|null $couponEndDate
2766
     * @param string|null $couponId
2767
     * @param string|null $couponName
2768
     * @param string|null $customerComment
2769
     * @param int|null $deliveryEstimate
2770
     * @param string|null $shippingAddress
2771
     * @param string|null $shippingCity
2772
     * @param string|null $shippingCountry
2773
     * @param string|null $shippingCurrency
2774
     * @param float|null $shippingFee
2775
     * @param float|null $shippingFeeConverted
2776
     * @param string|null $shippingState
2777
     * @param string|null $shippingZip
2778
     * @param string|null $source
2779
     * @param float|null $sourceFee
2780
     * @param string|null $sourceFeeCurrency
2781
     * @param float|null $sourceFeeConverted
2782
     * @param string|null $taxCurrency
2783
     * @param float|null $taxFee
2784
     * @param float|null $taxFeeConverted
2785
     * @param string|null $productUrl
2786
     * @param string|null $productImageUrl
2787
     * @return Builder
2788
     */
2789
    public function addOrderData(
2790
        $envelopeType,
2791
        $amount,
2792
        $currency,
2793
        $eventId,
2794
        $eventTimestamp,
2795
        $transactionId = null,
2796
        $groupId = null,
2797
        $itemsQuantity = null,
2798
        $orderType = null,
2799
        $amountConverted = null,
2800
        $campaign = null,
2801
        $carrier = null,
2802
        $carrierShippingId = null,
2803
        $carrierUrl = null,
2804
        $carrierPhone = null,
2805
        $couponStartDate = null,
2806
        $couponEndDate = null,
2807
        $couponId = null,
2808
        $couponName = null,
2809
        $customerComment = null,
2810
        $deliveryEstimate = null,
2811
        $shippingAddress = null,
2812
        $shippingCity = null,
2813
        $shippingCountry = null,
2814
        $shippingCurrency = null,
2815
        $shippingFee = null,
2816
        $shippingFeeConverted = null,
2817
        $shippingState = null,
2818
        $shippingZip = null,
2819
        $source = null,
2820
        $sourceFee = null,
2821
        $sourceFeeCurrency = null,
2822
        $sourceFeeConverted = null,
2823
        $taxCurrency = null,
2824
        $taxFee = null,
2825
        $taxFeeConverted = null,
2826
        $productUrl = null,
2827
        $productImageUrl = null
2828
    ) {
2829
        if (!is_string($envelopeType)) {
2830
            throw new \InvalidArgumentException('Envelope type must be string');
2831
        }
2832
        if (!is_int($amount) && !is_float($amount)) {
2833
            throw new \InvalidArgumentException('Amount must be number');
2834
        }
2835
        if (!is_string($currency)) {
2836
            throw new \InvalidArgumentException('Currency must be string');
2837
        }
2838
        if (!is_string($eventId)) {
2839
            throw new \InvalidArgumentException('Event ID must be string');
2840
        }
2841
        if (!is_int($eventTimestamp)) {
2842
            throw new \InvalidArgumentException('Event timestamp must be int');
2843
        }
2844
        if ($envelopeType === 'order_submit' && !is_int($itemsQuantity)) {
2845
            throw new \InvalidArgumentException('Items quantity must be int');
2846
        }
2847
        if ($envelopeType === 'order_item' && !is_string($orderType)) {
2848
            throw new \InvalidArgumentException('Order type must be string');
2849
        }
2850
        if ($transactionId !== null && !is_string($transactionId)) {
2851
            throw new \InvalidArgumentException('Transaction id must be string');
2852
        }
2853
        if ($groupId !== null && !is_string($groupId)) {
2854
            throw new \InvalidArgumentException('Group id must be string');
2855
        }
2856 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...
2857
            throw new \InvalidArgumentException('Amount converted must be number');
2858
        }
2859
        if ($campaign !== null && !is_string($campaign)) {
2860
            throw new \InvalidArgumentException('Campaign must be string');
2861
        }
2862
        if ($carrier !== null && !is_string($carrier)) {
2863
            throw new \InvalidArgumentException('Carrier must be string');
2864
        }
2865
        if ($carrierShippingId !== null && !is_string($carrierShippingId)) {
2866
            throw new \InvalidArgumentException('Carrier shipping id must be string');
2867
        }
2868
        if ($carrierUrl !== null && !is_string($carrierUrl)) {
2869
            throw new \InvalidArgumentException('Carrier url must be string');
2870
        }
2871
        if ($carrierPhone !== null && !is_string($carrierPhone)) {
2872
            throw new \InvalidArgumentException('Carrier phone must be string');
2873
        }
2874
        if ($couponStartDate !== null && !is_int($couponStartDate)) {
2875
            throw new \InvalidArgumentException('Coupon start date must be int');
2876
        }
2877
        if ($couponEndDate !== null && !is_int($couponEndDate)) {
2878
            throw new \InvalidArgumentException('Coupon end date must be int');
2879
        }
2880
        if ($couponId !== null && !is_string($couponId)) {
2881
            throw new \InvalidArgumentException('Coupon id must be string');
2882
        }
2883
        if ($couponName !== null && !is_string($couponName)) {
2884
            throw new \InvalidArgumentException('Coupon name must be string');
2885
        }
2886
        if ($customerComment !== null && !is_string($customerComment)) {
2887
            throw new \InvalidArgumentException('Customer comment must be string');
2888
        }
2889
        if ($deliveryEstimate !== null && !is_int($deliveryEstimate)) {
2890
            throw new \InvalidArgumentException('Delivery estimate must be int');
2891
        }
2892
        if ($shippingAddress !== null && !is_string($shippingAddress)) {
2893
            throw new \InvalidArgumentException('Shipping address must be string');
2894
        }
2895
        if ($shippingCity !== null && !is_string($shippingCity)) {
2896
            throw new \InvalidArgumentException('Shipping city must be string');
2897
        }
2898
        if ($shippingCountry !== null && !is_string($shippingCountry)) {
2899
            throw new \InvalidArgumentException('Shipping country must be string');
2900
        }
2901
        if ($shippingCurrency !== null && !is_string($shippingCurrency)) {
2902
            throw new \InvalidArgumentException('Shipping currency must be string');
2903
        }
2904
        if ($shippingFee !== null && !is_int($shippingFee) && !is_float($shippingFee)) {
2905
            throw new \InvalidArgumentException('Shipping fee must be number');
2906
        }
2907
        if ($shippingFeeConverted !== null && !is_int($shippingFeeConverted) && !is_float($shippingFeeConverted)) {
2908
            throw new \InvalidArgumentException('Shipping fee converted must be number');
2909
        }
2910
        if ($shippingState !== null && !is_string($shippingState)) {
2911
            throw new \InvalidArgumentException('Shipping state must be string');
2912
        }
2913
        if ($shippingZip !== null && !is_string($shippingZip)) {
2914
            throw new \InvalidArgumentException('Shipping zip must be string');
2915
        }
2916
        if ($source !== null && !is_string($source)) {
2917
            throw new \InvalidArgumentException('Order source must be string');
2918
        }
2919
        if ($sourceFee !== null && !is_int($sourceFee) && !is_float($sourceFee)) {
2920
            throw new \InvalidArgumentException('Source fee must be number');
2921
        }
2922
        if ($sourceFeeConverted !== null && !is_int($sourceFeeConverted) && !is_float($sourceFeeConverted)) {
2923
            throw new \InvalidArgumentException('Source fee converted must be number');
2924
        }
2925
        if ($sourceFeeCurrency !== null && !is_string($sourceFeeCurrency)) {
2926
            throw new \InvalidArgumentException('Source fee currency must be string');
2927
        }
2928
        if ($taxCurrency !== null && !is_string($taxCurrency)) {
2929
            throw new \InvalidArgumentException('Tax currency must be string');
2930
        }
2931
        if ($taxFee !== null && !is_int($taxFee) && !is_float($taxFee)) {
2932
            throw new \InvalidArgumentException('Tax fee must be number');
2933
        }
2934
        if ($taxFeeConverted !== null && !is_int($taxFeeConverted) && !is_float($taxFeeConverted)) {
2935
            throw new \InvalidArgumentException('Tax fee converted must be number');
2936
        }
2937
        if ($productUrl !== null && !is_string($productUrl)) {
2938
            throw new \InvalidArgumentException('Product url must be string');
2939
        }
2940
        if ($productImageUrl !== null && !is_string($productImageUrl)) {
2941
            throw new \InvalidArgumentException('Product image url must be string');
2942
        }
2943
        if ($productImageUrl !== null && !is_string($productImageUrl)) {
2944
            throw new \InvalidArgumentException('Product image url must be string');
2945
        }
2946
        $this->replace('amount', $amount);
2947
        $this->replace('currency', $currency);
2948
        $this->replace('event_id', $eventId);
2949
        $this->replace('event_timestamp', $eventTimestamp);
2950
        $this->replace('items_quantity', $itemsQuantity);
2951
        $this->replace('order_type', $orderType);
2952
        $this->replace('transaction_id', $transactionId);
2953
        $this->replace('group_id', $groupId);
2954
        $this->replace('amount_converted', $amountConverted);
2955
        $this->replace('campaign', $campaign);
2956
        $this->replace('carrier', $carrier);
2957
        $this->replace('carrier_shipping_id', $carrierShippingId);
2958
        $this->replace('carrier_url', $carrierUrl);
2959
        $this->replace('carrier_phone', $carrierPhone);
2960
        $this->replace('coupon_start_date', $couponStartDate);
2961
        $this->replace('coupon_end_date', $couponEndDate);
2962
        $this->replace('coupon_id', $couponId);
2963
        $this->replace('coupon_name', $couponName);
2964
        $this->replace('customer_comment', $customerComment);
2965
        $this->replace('delivery_estimate', $deliveryEstimate);
2966
        $this->replace('shipping_address', $shippingAddress);
2967
        $this->replace('shipping_city', $shippingCity);
2968
        $this->replace('shipping_country', $shippingCountry);
2969
        $this->replace('shipping_currency', $shippingCurrency);
2970
        $this->replace('shipping_fee', $shippingFee);
2971
        $this->replace('shipping_fee_converted', $shippingFeeConverted);
2972
        $this->replace('shipping_state', $shippingState);
2973
        $this->replace('shipping_zip', $shippingZip);
2974
        $this->replace('order_source', $source);
2975
        $this->replace('source_fee', $sourceFee);
2976
        $this->replace('source_fee_currency', $sourceFeeCurrency);
2977
        $this->replace('source_fee_converted', $sourceFeeConverted);
2978
        $this->replace('tax_currency', $taxCurrency);
2979
        $this->replace('tax_fee', $taxFee);
2980
        $this->replace('tax_fee_converted', $taxFeeConverted);
2981
        $this->replace('product_url', $productUrl);
2982
        $this->replace('product_image_url', $productImageUrl);
2983
2984
        return $this;
2985
    }
2986
2987
    /**
2988
     * Provides postback information to envelope
2989
     *
2990
     * @param int|null $requestId
2991
     * @param string|null $transactionId
2992
     * @param string|null $transactionStatus
2993
     * @param string|null $code
2994
     * @param string|null $reason
2995
     * @param string|null $secure3d
2996
     * @param string|null $avsResult
2997
     * @param string|null $cvvResult
2998
     * @param string|null $pspCode
2999
     * @param string|null $pspReason
3000
     * @param string|null $arn
3001
     * @param string|null $paymentAccountId
3002
     * @return $this
3003
     */
3004
    public function addPostbackData(
3005
        $requestId = null,
3006
        $transactionId = null,
3007
        $transactionStatus = null,
3008
        $code = null,
3009
        $reason = null,
3010
        $secure3d = null,
3011
        $avsResult = null,
3012
        $cvvResult = null,
3013
        $pspCode = null,
3014
        $pspReason = null,
3015
        $arn = null,
3016
        $paymentAccountId = null
3017
    ) {
3018
        if ($requestId === null && $transactionId === null) {
3019
            throw new \InvalidArgumentException('request_id or transaction_id should be provided');
3020
        }
3021
        if ($transactionId !== null && !is_string($transactionId)) {
3022
            throw new \InvalidArgumentException('TransactionId must be string');
3023
        }
3024
        if ($requestId !== null && !is_int($requestId)) {
3025
            throw new \InvalidArgumentException('RequestId must be int');
3026
        }
3027
        if ($transactionStatus !== null && !is_string($transactionStatus)) {
3028
            throw new \InvalidArgumentException('Transaction status must be string');
3029
        }
3030
        if ($code !== null && !is_string($code)) {
3031
            throw new \InvalidArgumentException('Code must be string');
3032
        }
3033
        if ($reason !== null && !is_string($reason)) {
3034
            throw new \InvalidArgumentException('Reason must be string');
3035
        }
3036
        if ($secure3d !== null && !is_string($secure3d)) {
3037
            throw new \InvalidArgumentException('Secure3d must be string');
3038
        }
3039
        if ($avsResult !== null && !is_string($avsResult)) {
3040
            throw new \InvalidArgumentException('AvsResult must be string');
3041
        }
3042
        if ($cvvResult !== null && !is_string($cvvResult)) {
3043
            throw new \InvalidArgumentException('CvvResult must be string');
3044
        }
3045
        if ($pspCode !== null && !is_string($pspCode)) {
3046
            throw new \InvalidArgumentException('PspCode must be string');
3047
        }
3048
        if ($pspReason !== null && !is_string($pspReason)) {
3049
            throw new \InvalidArgumentException('PspReason must be string');
3050
        }
3051
        if ($arn !== null && !is_string($arn)) {
3052
            throw new \InvalidArgumentException('Arn must be string');
3053
        }
3054
        if ($paymentAccountId !== null && !is_string($paymentAccountId)) {
3055
            throw new \InvalidArgumentException('PaymentAccoutId must be string');
3056
        }
3057
3058
        $this->replace('request_id', $requestId);
3059
        $this->replace('transaction_id', $transactionId);
3060
        $this->replace('transaction_status', $transactionStatus);
3061
        $this->replace('code', $code);
3062
        $this->replace('reason', $reason);
3063
        $this->replace('secure3d', $secure3d);
3064
        $this->replace('avs_result', $avsResult);
3065
        $this->replace('cvv_result', $cvvResult);
3066
        $this->replace('psp_code', $pspCode);
3067
        $this->replace('psp_reason', $pspReason);
3068
        $this->replace('arn', $arn);
3069
        $this->replace('payment_account_id', $paymentAccountId);
3070
3071
        return $this;
3072
    }
3073
3074
    /**
3075
     * Adds custom data field to envelope
3076
     *
3077
     * @param string $name
3078
     * @param string $value
3079
     *
3080
     * @return $this
3081
     */
3082
    public function addCustomField($name, $value)
3083
    {
3084
        if (!is_string($name)) {
3085
            throw new \InvalidArgumentException('Custom field name must be string');
3086
        }
3087
        if (!is_string($value)) {
3088
            throw new \InvalidArgumentException('Custom field value must be string');
3089
        }
3090
3091
        if (strlen($name) < 8 || substr($name, 0, 7) !== 'custom_') {
3092
            $name = 'custom_' . $name;
3093
        }
3094
3095
        $this->replace($name, $value);
3096
        return $this;
3097
    }
3098
3099
    /**
3100
     * Provides group id value to envelope
3101
     *
3102
     * @param string|null $groupId
3103
     * @return $this
3104
     */
3105
    public function addGroupId($groupId = null)
3106
    {
3107
        if ($groupId !== null && !is_string($groupId)) {
3108
            throw new \InvalidArgumentException('Group id must be string');
3109
        }
3110
        $this->replace('group_id', $groupId);
3111
3112
        return $this;
3113
    }
3114
3115
}
3116