Completed
Push — master ( 30ef9c...66d5ad )
by
unknown
12s queued 11s
created

Builder::kycProfileEvent()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 117

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 117
rs 8
c 0
b 0
f 0
cc 2
nc 2
nop 49

How to fix   Long Method    Many Parameters   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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