Completed
Push — master ( b808c3...4b0294 )
by Anton
13s queued 10s
created

Builder::kycSubmitEvent()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 34
rs 9.376
c 0
b 0
f 0
cc 2
nc 2
nop 11

How to fix   Many Parameters   

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
     *
38
     * @return Builder
39
     */
40
    public static function confirmationEvent(
41
        $sequenceId,
42
        $userId,
43
        $timestamp = null,
44
        $isEmailConfirmed = null,
45
        $idPhoneConfirmed = null,
46
        $email = null,
47
        $phone = null
48
    ) {
49
        $builder = new self('confirmation', $sequenceId);
50
        if ($timestamp === null) {
51
            $timestamp = time();
52
        }
53
54
        return $builder->addUserData(
55
            $email,
56
            $userId,
57
            $phone,
58
            null,
59
            null,
60
            null,
61
            null,
62
            null,
63
            null,
64
            null,
65
            null,
66
            null,
67
            $timestamp,
68
            $isEmailConfirmed,
69
            $idPhoneConfirmed,
70
            null
71
        );
72
    }
73
74
    /**
75
     * Returns builder for login event
76
     *
77
     * @param string $sequenceId
78
     * @param string $userId
79
     * @param int|null $timestamp
80
     * @param string|null $email
81
     * @param bool|null $failed
82
     * @param string|null $gender
83
     * @param string|null $trafficSource
84
     * @param string|null $affiliateId
85
     * @param string|null $password
86
     *
87
     * @return Builder
88
     */
89
    public static function loginEvent(
90
        $sequenceId,
91
        $userId,
92
        $timestamp = null,
93
        $email = null,
94
        $failed = null,
95
        $gender = null,
96
        $trafficSource = null,
97
        $affiliateId = null,
98
        $password = null
99
    ) {
100
        $builder = new self('login', $sequenceId);
101
        if ($timestamp === null) {
102
            $timestamp = time();
103
        }
104
105
        return $builder->addUserData(
106
            $email,
107
            $userId,
108
            null,
109
            null,
110
            null,
111
            null,
112
            $gender,
113
            null,
114
            null,
115
            null,
116
            null,
117
            $timestamp,
118
            null,
119
            null,
120
            null,
121
            $failed,
122
            null,
123
            null,
124
            null,
125
            null,
126
            null,
127
            null,
128
            $password
129
        )->addWebsiteData(null, $trafficSource, $affiliateId);
130
    }
131
132
    /**
133
     * Returns builder for registration event
134
     *
135
     * @param string $sequenceId
136
     * @param string $userId
137
     * @param int|null $timestamp
138
     * @param string|null $email
139
     * @param string|null $userName
140
     * @param string|null $firstName
141
     * @param string|null $lastName
142
     * @param int|null $age
143
     * @param string|null $gender
144
     * @param string|null $phone
145
     * @param string|null $country
146
     * @param string|null $socialType
147
     * @param string|null $websiteUrl
148
     * @param string|null $trafficSource
149
     * @param string|null $affiliateId
150
     * @param string|null $password
151
     *
152
     * @return Builder
153
     */
154
    public static function registrationEvent(
155
        $sequenceId,
156
        $userId,
157
        $timestamp = null,
158
        $email = null,
159
        $userName = null,
160
        $firstName = null,
161
        $lastName = null,
162
        $age = null,
163
        $gender = null,
164
        $phone = null,
165
        $country = null,
166
        $socialType = null,
167
        $websiteUrl = null,
168
        $trafficSource = null,
169
        $affiliateId = null,
170
        $password = null
171
    ) {
172
        $builder = new self('registration', $sequenceId);
173
        if ($timestamp === null) {
174
            $timestamp = time();
175
        }
176
177
        return $builder->addWebsiteData(
178
            $websiteUrl,
179
            $trafficSource,
180
            $affiliateId
181
        )->addUserData(
182
            $email,
183
            $userId,
184
            $phone,
185
            $userName,
186
            $firstName,
187
            $lastName,
188
            $gender,
189
            $age,
190
            $country,
191
            $socialType,
192
            $timestamp,
193
            null,
194
            null,
195
            null,
196
            null,
197
            null,
198
            null,
199
            null,
200
            null,
201
            null,
202
            null,
203
            null,
204
            $password
205
206
        );
207
    }
208
209
    /**
210
     * Returns builder for payout request
211
     *
212
     * @param string $sequenceId
213
     * @param string $userId
214
     * @param string $payoutId
215
     * @param string $currency
216
     * @param int|float $amount
217
     * @param int|null $payoutTimestamp
218
     * @param string|null $cardId
219
     * @param string|null $accountId
220
     * @param string|null $method
221
     * @param string|null $system
222
     * @param string|null $mid
223
     * @param int|float $amountConverted
224
     * @param string|null $firstName
225
     * @param string|null $lastName
226
     * @param string|null $country
227
     * @param string|null $email
228
     * @param string|null $phone
229
     * @param int|null $cardBin
230
     * @param string|null $cardLast4
231
     * @param int|null $cardExpirationMonth
232
     * @param int|null $cardExpirationYear
233
     *
234
     * @return Builder
235
     */
236
    public static function payoutEvent(
237
        $sequenceId,
238
        $userId,
239
        $payoutId,
240
        $currency,
241
        $amount,
242
        $payoutTimestamp = null,
243
        $cardId = null,
244
        $accountId = null,
245
        $method = null,
246
        $system = null,
247
        $mid = null,
248
        $amountConverted = null,
249
        $firstName = null,
250
        $lastName = null,
251
        $country = null,
252
        $email = null,
253
        $phone = null,
254
        $cardBin = null,
255
        $cardLast4 = null,
256
        $cardExpirationMonth = null,
257
        $cardExpirationYear = null
258
    ) {
259
        $builder = new self('payout', $sequenceId);
260
        if ($payoutTimestamp === null) {
261
            $payoutTimestamp = time();
262
        }
263
        return $builder->addPayoutData(
264
            $payoutId,
265
            $payoutTimestamp,
266
            $amount,
267
            $currency,
268
            $cardId,
269
            $accountId,
270
            $method,
271
            $system,
272
            $mid,
273
            $amountConverted,
274
            $cardBin,
275
            $cardLast4,
276
            $cardExpirationMonth,
277
            $cardExpirationYear
278
        )->addShortUserData($email, $userId, $phone, $firstName, $lastName, $country);
279
    }
280
281
    /**
282
     * Returns builder for transaction request
283
     *
284
     * @param string $sequenceId
285
     * @param string $userId
286
     * @param string $transactionId
287
     * @param int|float $transactionAmount
288
     * @param string $transactionCurrency
289
     * @param int|null $transactionTimestamp
290
     * @param string|null $transactionMode
291
     * @param string|null $transactionType
292
     * @param int|null $cardBin
293
     * @param string|null $cardId
294
     * @param string|null $cardLast4
295
     * @param int|null $expirationMonth
296
     * @param int|null $expirationYear
297
     * @param int|null $age
298
     * @param string|null $country
299
     * @param string|null $email
300
     * @param string|null $gender
301
     * @param string|null $firstName
302
     * @param string|null $lastName
303
     * @param string|null $phone
304
     * @param string|null $userName
305
     * @param string|null $paymentAccountId
306
     * @param string|null $paymentMethod
307
     * @param string|null $paymentMidName
308
     * @param string|null $paymentSystem
309
     * @param int|float|null $transactionAmountConverted
310
     * @param string|null $transactionSource
311
     * @param string|null $billingAddress
312
     * @param string|null $billingCity
313
     * @param string|null $billingCountry
314
     * @param string|null $billingFirstName
315
     * @param string|null $billingLastName
316
     * @param string|null $billingFullName
317
     * @param string|null $billingState
318
     * @param string|null $billingZip
319
     * @param string|null $productDescription
320
     * @param string|null $productName
321
     * @param int|float|null $productQuantity
322
     * @param string|null $websiteUrl
323
     * @param string|null $merchantIp
324
     * @param string|null $affiliateId
325
     *
326
     * @return Builder
327
     */
328
    public static function transactionEvent(
329
        $sequenceId,
330
        $userId,
331
        $transactionId,
332
        $transactionAmount,
333
        $transactionCurrency,
334
        $transactionTimestamp = null,
335
        $transactionMode = null,
336
        $transactionType = null,
337
        $cardBin = null,
338
        $cardId = null,
339
        $cardLast4 = null,
340
        $expirationMonth = null,
341
        $expirationYear = null,
342
        $age = null,
343
        $country = null,
344
        $email = null,
345
        $gender = null,
346
        $firstName = null,
347
        $lastName = null,
348
        $phone = null,
349
        $userName = null,
350
        $paymentAccountId = null,
351
        $paymentMethod = null,
352
        $paymentMidName = null,
353
        $paymentSystem = null,
354
        $transactionAmountConverted = null,
355
        $transactionSource = null,
356
        $billingAddress = null,
357
        $billingCity = null,
358
        $billingCountry = null,
359
        $billingFirstName = null,
360
        $billingLastName = null,
361
        $billingFullName = null,
362
        $billingState = null,
363
        $billingZip = null,
364
        $productDescription = null,
365
        $productName = null,
366
        $productQuantity = null,
367
        $websiteUrl = null,
368
        $merchantIp = null,
369
        $affiliateId = null
370
    ) {
371
        $builder = new self('transaction', $sequenceId);
372
        if ($transactionTimestamp === null) {
373
            $transactionTimestamp = time();
374
        }
375
376
        return $builder
377
            ->addCCTransactionData(
378
                $transactionId,
379
                $transactionSource,
380
                $transactionType,
381
                $transactionMode,
382
                $transactionTimestamp,
383
                $transactionCurrency,
384
                $transactionAmount,
385
                $transactionAmountConverted,
386
                $paymentMethod,
387
                $paymentSystem,
388
                $paymentMidName,
389
                $paymentAccountId
390
            )
391
            ->addBillingData(
392
                $billingFirstName,
393
                $billingLastName,
394
                $billingFullName,
395
                $billingCountry,
396
                $billingState,
397
                $billingCity,
398
                $billingAddress,
399
                $billingZip
400
            )
401
            ->addCardData($cardBin, $cardLast4, $expirationMonth, $expirationYear, $cardId)
402
            ->addUserData(
403
                $email,
404
                $userId,
405
                $phone,
406
                $userName,
407
                $firstName,
408
                $lastName,
409
                $gender,
410
                $age,
411
                $country
412
            )
413
            ->addProductData($productQuantity, $productName, $productDescription)
414
            ->addWebsiteData($websiteUrl, null, $affiliateId)
415
            ->addIpData(null, null, $merchantIp);
416
417
    }
418
419
    /**
420
     * Returns builder for install request
421
     *
422
     * @param string $sequenceId
423
     * @param string|null $userId
424
     * @param int|null $installTimestamp
425
     * @param string|null $country
426
     * @param string|null $websiteUrl
427
     * @param string|null $trafficSource
428
     * @param string|null $affiliateId
429
     *
430
     * @return Builder
431
     */
432
    public static function installEvent(
433
        $sequenceId,
434
        $userId = null,
435
        $installTimestamp = null,
436
        $country = null,
437
        $websiteUrl = null,
438
        $trafficSource = null,
439
        $affiliateId = null
440
    ) {
441
        $builder = new self('install', $sequenceId);
442
        if ($installTimestamp === null) {
443
            $installTimestamp = time();
444
        }
445
446
        return $builder->addInstallData(
447
            $installTimestamp
448
        )->addWebsiteData($websiteUrl, $trafficSource, $affiliateId)
449
        ->addShortUserData(null, $userId, null, null, null, $country);
450
    }
451
452
    /**
453
     * Returns builder for refund request
454
     *
455
     * @param string $sequenceId
456
     * @param string $refundId
457
     * @param int|float $refundAmount
458
     * @param string $refundCurrency
459
     * @param int|null $refundTimestamp
460
     * @param int|float|null $refundAmountConverted
461
     * @param string|null $refundSource
462
     * @param string|null $refundType
463
     * @param string|null $refundCode
464
     * @param string|null $refundReason
465
     * @param string|null $agentId
466
     * @param string|null $refundMethod
467
     * @param string|null $refundSystem
468
     * @param string|null $refundMid
469
     *
470
     * @return Builder
471
     */
472
    public static function refundEvent(
473
        $sequenceId,
474
        $refundId,
475
        $refundAmount,
476
        $refundCurrency,
477
        $refundTimestamp = null,
478
        $refundAmountConverted = null,
479
        $refundSource = null,
480
        $refundType = null,
481
        $refundCode = null,
482
        $refundReason = null,
483
        $agentId = null,
484
        $refundMethod = null,
485
        $refundSystem = null,
486
        $refundMid = null,
487
        $email = null,
488
        $phone = null,
489
        $userId = null
490
    ) {
491
        $builder = new self('refund', $sequenceId);
492
        if ($refundTimestamp === null) {
493
            $refundTimestamp = time();
494
        }
495
496
        return $builder->addRefundData(
497
            $refundId,
498
            $refundTimestamp,
499
            $refundAmount,
500
            $refundCurrency,
501
            $refundAmountConverted,
502
            $refundSource,
503
            $refundType,
504
            $refundCode,
505
            $refundReason,
506
            $agentId,
507
            $refundMethod,
508
            $refundSystem,
509
            $refundMid
510
        )->addUserData($email, $userId, $phone);
511
    }
512
513
    /**
514
     * Returns builder for transfer request
515
     *
516
     * @param string $sequenceId
517
     * @param string $eventId
518
     * @param float $amount
519
     * @param string $currency
520
     * @param string $accountId
521
     * @param string $secondAccountId
522
     * @param string $accountSystem
523
     * @param string $userId
524
     * @param int|null $eventTimestamp
525
     * @param float|null $amountConverted
526
     * @param string|null $method
527
     * @param string|null $email
528
     * @param string|null $phone
529
     * @param int|null $birthDate
530
     * @param string|null $firstname
531
     * @param string|null $lastname
532
     * @param string|null $fullname
533
     * @param string|null $state
534
     * @param string|null $city
535
     * @param string|null $address
536
     * @param string|null $zip
537
     * @param string|null $gender
538
     * @param string|null $country
539
     * @param string|null $operation
540
     * @param string|null $secondEmail
541
     * @param string|null $secondPhone
542
     * @param int|null $secondBirthDate
543
     * @param string|null $secondFirstname
544
     * @param string|null $secondLastname
545
     * @param string|null $secondFullname
546
     * @param string|null $secondState
547
     * @param string|null $secondCity
548
     * @param string|null $secondAddress
549
     * @param string|null $secondZip
550
     * @param string|null $secondGender
551
     * @param string|null $secondCountry
552
     * @param string|null $productDescription
553
     * @param string|null $productName
554
     * @param int|float|null $productQuantity
555
     * @param string|null $iban
556
     * @param string|null $secondIban
557
     *
558
     * @return Builder
559
     */
560
    public static function transferEvent(
561
        $sequenceId,
562
        $eventId,
563
        $amount,
564
        $currency,
565
        $accountId,
566
        $secondAccountId,
567
        $accountSystem,
568
        $userId,
569
        $method = null,
570
        $eventTimestamp = null,
571
        $amountConverted = null,
572
        $email = null,
573
        $phone = null,
574
        $birthDate = null,
575
        $firstname = null,
576
        $lastname = null,
577
        $fullname = null,
578
        $state = null,
579
        $city = null,
580
        $address = null,
581
        $zip = null,
582
        $gender = null,
583
        $country = null,
584
        $operation = null,
585
        $secondEmail = null,
586
        $secondPhone = null,
587
        $secondBirthDate = null,
588
        $secondFirstname = null,
589
        $secondLastname = null,
590
        $secondFullname = null,
591
        $secondState = null,
592
        $secondCity = null,
593
        $secondAddress = null,
594
        $secondZip = null,
595
        $secondGender = null,
596
        $secondCountry = null,
597
        $productDescription = null,
598
        $productName = null,
599
        $productQuantity = null,
600
        $iban = null,
601
        $secondIban = null
602
603
    ) {
604
        $builder = new self('transfer', $sequenceId);
605
        if ($eventTimestamp === null) {
606
            $eventTimestamp = time();
607
        }
608
609
        return $builder
610
            ->addTransferData(
611
               $eventId,
612
               $eventTimestamp,
613
               $amount,
614
               $currency,
615
               $accountId,
616
               $secondAccountId,
617
               $accountSystem,
618
               $amountConverted,
619
               $method,
620
               $operation,
621
               $secondEmail,
622
               $secondPhone,
623
               $secondBirthDate,
624
               $secondFirstname,
625
               $secondLastname,
626
               $secondFullname,
627
               $secondState,
628
               $secondCity,
629
               $secondAddress,
630
               $secondZip,
631
               $secondGender,
632
               $secondCountry,
633
               $iban,
634
               $secondIban
635
            )
636
            ->addUserData(
637
                $email,
638
                $userId,
639
                $phone,
640
                null,
641
                $firstname,
642
                $lastname,
643
                $gender,
644
                null,
645
                $country,
646
                null,
647
                null,
648
                null,
649
                null,
650
                null,
651
                null,
652
                null,
653
                $birthDate,
654
                $fullname,
655
                $state,
656
                $city,
657
                $address,
658
                $zip,
659
                null
660
            )
661
            ->addProductData($productQuantity, $productName, $productDescription);
662
    }
663
664
    /**
665
     * Returns builder for kyc_profile request
666
     *
667
     * @param string $sequenceId
668
     * @param string $eventId
669
     * @param string $userId
670
     * @param int|null $eventTimestamp
671
     * @param string|null $groupId
672
     * @param string|null $status
673
     * @param string|null $code
674
     * @param string|null $reason
675
     * @param string|null $providerResult
676
     * @param string|null $providerCode
677
     * @param string|null $providerReason
678
     * @param string|null $profileId
679
     * @param string|null $profileType
680
     * @param string|null $profileSubType
681
     * @param string|null $firstName
682
     * @param string|null $lastName
683
     * @param string|null $fullName
684
     * @param string|null $industry
685
     * @param string|null $websiteUrl
686
     * @param string|null $description
687
     * @param int|null $birthDate
688
     * @param int|null $regDate
689
     * @param string|null $regNumber
690
     * @param string|null $vatNumber
691
     * @param string|null $email
692
     * @param bool|null $emailConfirmed
693
     * @param string|null $phone
694
     * @param bool|null $phoneConfirmed
695
     * @param string|null $country
696
     * @param string|null $state
697
     * @param string|null $city
698
     * @param string|null $address
699
     * @param string|null $zip
700
     * @param string|null $secondCountry
701
     * @param string|null $secondState
702
     * @param string|null $secondCity
703
     * @param string|null $secondAddress
704
     * @param string|null $secondZip
705
     * @param string|null $relatedProfiles
706
     *
707
     * @return Builder
708
     */
709
    public static function kycProfileEvent(
710
        $sequenceId,
711
        $eventId,
712
        $userId,
713
        $eventTimestamp = null,
714
        $groupId = null,
715
        $status = null,
716
        $code = null,
717
        $reason = null,
718
        $providerResult = null,
719
        $providerCode = null,
720
        $providerReason = null,
721
        $profileId = null,
722
        $profileType = null,
723
        $profileSubType = null,
724
        $firstName = null,
725
        $lastName = null,
726
        $fullName = null,
727
        $industry = null,
728
        $websiteUrl = null,
729
        $description = null,
730
        $birthDate = null,
731
        $regDate = null,
732
        $regNumber = null,
733
        $vatNumber = null,
734
        $email = null,
735
        $emailConfirmed = null,
736
        $phone = null,
737
        $phoneConfirmed = null,
738
        $country = null,
739
        $state = null,
740
        $city = null,
741
        $address = null,
742
        $zip = null,
743
        $secondCountry = null,
744
        $secondState = null,
745
        $secondCity = null,
746
        $secondAddress = null,
747
        $secondZip = null,
748
        $relatedProfiles = null
749
    ) {
750
        $builder = new self('kyc_profile', $sequenceId);
751
        if ($eventTimestamp === null) {
752
            $eventTimestamp = time();
753
        }
754
        return $builder
755
            ->addKycData(
756
                $eventId,
757
                $eventTimestamp,
758
                $groupId,
759
                $status,
760
                $code,
761
                $reason,
762
                $providerResult,
763
                $providerCode,
764
                $providerReason,
765
                $profileId,
766
                $profileType,
767
                $profileSubType,
768
                $industry,
769
                $description,
770
                $regDate,
771
                $regNumber,
772
                $vatNumber,
773
                $secondCountry,
774
                $secondState,
775
                $secondCity,
776
                $secondAddress,
777
                $secondZip,
778
                $relatedProfiles
779
            )
780
            ->addUserData(
781
                $email,
782
                $userId,
783
                $phone,
784
                null,
785
                $firstName,
786
                $lastName,
787
                null,
788
                null,
789
                $country,
790
                null,
791
                null,
792
                null,
793
                null,
794
                $emailConfirmed,
795
                $phoneConfirmed,
796
                null,
797
                $birthDate,
798
                $fullName,
799
                $state,
800
                $city,
801
                $address,
802
                $zip,
803
                null
804
            )
805
            ->addWebsiteData($websiteUrl);
806
    }
807
808
    /**
809
     * Returns builder for kyc_submit request
810
     *
811
     * @param string $sequenceId
812
     * @param string $eventId
813
     * @param string $userId
814
     * @param int|null $eventTimestamp
815
     * @param string|null $groupId
816
     * @param string|null $status
817
     * @param string|null $code
818
     * @param string|null $reason
819
     * @param string|null $providerResult
820
     * @param string|null $providerCode
821
     * @param string|null $providerReason
822
     *
823
     * @return Builder
824
     */
825
    public static function kycSubmitEvent(
826
        $sequenceId,
827
        $eventId,
828
        $userId,
829
        $eventTimestamp = null,
830
        $groupId = null,
831
        $status = null,
832
        $code = null,
833
        $reason = null,
834
        $providerResult = null,
835
        $providerCode = null,
836
        $providerReason = null
837
    ) {
838
        $builder = new self('kyc_submit', $sequenceId);
839
        if ($eventTimestamp === null) {
840
            $eventTimestamp = time();
841
        }
842
        return $builder
843
            ->addKycData(
844
                $eventId,
845
                $eventTimestamp,
846
                $groupId,
847
                $status,
848
                $code,
849
                $reason,
850
                $providerResult,
851
                $providerCode,
852
                $providerReason
853
            )
854
            ->addUserData(
855
                null,
856
                $userId
857
            );
858
    }
859
860
    /**
861
     * Returns builder for postback request
862
     *
863
     * @param int|null $requestId
864
     * @param string|null $transactionId
865
     * @param string|null $transactionStatus
866
     * @param string|null $code
867
     * @param string|null $reason
868
     * @param string|null $secure3d
869
     * @param string|null $avsResult
870
     * @param string|null $cvvResult
871
     * @param string|null $pspCode
872
     * @param string|null $pspReason
873
     * @param string|null $arn
874
     * @param string|null $paymentAccountId
875
     * @return Builder
876
     */
877
    public static function postBackEvent(
878
        $requestId =  null,
879
        $transactionId = null,
880
        $transactionStatus = null,
881
        $code = null,
882
        $reason = null,
883
        $secure3d = null,
884
        $avsResult = null,
885
        $cvvResult = null,
886
        $pspCode = null,
887
        $pspReason = null,
888
        $arn = null,
889
        $paymentAccountId = null
890
    ) {
891
        $builder = new self('postback', '');
892
        return $builder->addPostBackData(
893
            $requestId,
894
            $transactionId,
895
            $transactionStatus,
896
            $code,
897
            $reason,
898
            $secure3d,
899
            $avsResult,
900
            $cvvResult,
901
            $pspCode,
902
            $pspReason,
903
            $arn,
904
            $paymentAccountId
905
       );
906
    }
907
908
    /**
909
     * Builder constructor.
910
     *
911
     * @param string $envelopeType
912
     * @param string $sequenceId
913
     */
914
    public function __construct($envelopeType, $sequenceId)
915
    {
916
        if (!is_string($envelopeType)) {
917
            throw new \InvalidArgumentException('Envelope type must be string');
918
        }
919
        if (!is_string($sequenceId)) {
920
            throw new \InvalidArgumentException('Sequence ID must be string');
921
        }
922
923
        $this->type = $envelopeType;
924
        $this->sequenceId = $sequenceId;
925
    }
926
927
    /**
928
     * Returns built envelope
929
     *
930
     * @return EnvelopeInterface
931
     */
932
    public function build()
933
    {
934
        return new Envelope(
935
            $this->type,
936
            $this->sequenceId,
937
            $this->identities,
938
            array_filter($this->data, function ($data) {
939
                return $data !== null;
940
            })
941
        );
942
    }
943
944
    /**
945
     * Replaces value in internal array if provided value not empty
946
     *
947
     * @param string $key
948
     * @param string|int|float|bool|null $value
949
     */
950
    private function replace($key, $value)
951
    {
952
        if ($value !== null && $value !== '' && $value !== 0 && $value !== 0.0) {
953
            $this->data[$key] = $value;
954
        }
955
    }
956
957
    /**
958
     * Adds identity node
959
     *
960
     * @param IdentityNodeInterface $identity
961
     *
962
     * @return $this
963
     */
964
    public function addIdentity(IdentityNodeInterface $identity)
965
    {
966
        $this->identities[] = $identity;
967
        return $this;
968
    }
969
970
    /**
971
     * Provides website URL to envelope
972
     *
973
     * @param string|null $websiteUrl
974
     * @param string|null $traffic_source
975
     * @param string|null $affiliate_id
976
     *
977
     * @return $this
978
     */
979 View Code Duplication
    public function addWebsiteData($websiteUrl = null, $traffic_source = null, $affiliate_id = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
980
    {
981
        if ($websiteUrl !== null && !is_string($websiteUrl)) {
982
            throw new \InvalidArgumentException('Website URL must be string');
983
        }
984
        if ($traffic_source !== null && !is_string($traffic_source)) {
985
            throw new \InvalidArgumentException('Traffic source must be string');
986
        }
987
        if ($affiliate_id !== null && !is_string($affiliate_id)) {
988
            throw new \InvalidArgumentException('Affiliate ID must be string');
989
        }
990
991
        $this->replace('website_url', $websiteUrl);
992
        $this->replace('traffic_source', $traffic_source);
993
        $this->replace('affiliate_id', $affiliate_id);
994
        return $this;
995
    }
996
997
    /**
998
     * Provides IP information for envelope
999
     *
1000
     * @param string|null $ip User's IP address
1001
     * @param string|null $realIp User's real IP address, if available
1002
     * @param string|null $merchantIp Your website's IP address
1003
     *
1004
     * @return $this
1005
     */
1006
    public function addIpData($ip = '', $realIp = '', $merchantIp = '')
1007
    {
1008
        if ($ip !== null && !is_string($ip)) {
1009
            throw new \InvalidArgumentException('IP must be string');
1010
        }
1011
        if ($realIp !== null && !is_string($realIp)) {
1012
            throw new \InvalidArgumentException('Real IP must be string');
1013
        }
1014
        if ($merchantIp !== null && !is_string($merchantIp)) {
1015
            throw new \InvalidArgumentException('Merchant IP must be string');
1016
        }
1017
1018
        $this->replace('ip', $ip);
1019
        $this->replace('real_ip', $realIp);
1020
        $this->replace('merchant_ip', $merchantIp);
1021
1022
        return $this;
1023
    }
1024
1025
    /**
1026
     * Provides browser information for envelope
1027
     *
1028
     * @param string|null $deviceFingerprint
1029
     * @param string|null $userAgent
1030
     * @param string|null $cpuClass
1031
     * @param string|null $screenOrientation
1032
     * @param string|null $screenResolution
1033
     * @param string|null $os
1034
     * @param int|null $timezoneOffset
1035
     * @param string|null $languages
1036
     * @param string|null $language
1037
     * @param string|null $languageBrowser
1038
     * @param string|null $languageUser
1039
     * @param string|null $languageSystem
1040
     * @param bool|null $cookieEnabled
1041
     * @param bool|null $doNotTrack
1042
     * @param bool|null $ajaxValidation
1043
     * @param string|null $deviceId
1044
     * @param string|null $ipList
1045
     * @param string|null $plugins
1046
     * @param string|null $refererUrl
1047
     * @param string|null $originUrl
1048
     * @param string|null $clientResolution
1049
     * @return $this
1050
     */
1051
    public function addBrowserData(
1052
        $deviceFingerprint = '',
1053
        $userAgent = '',
1054
        $cpuClass = '',
1055
        $screenOrientation = '',
1056
        $screenResolution = '',
1057
        $os = '',
1058
        $timezoneOffset = null,
1059
        $languages = '',
1060
        $language = '',
1061
        $languageBrowser = '',
1062
        $languageUser = '',
1063
        $languageSystem = '',
1064
        $cookieEnabled = null,
1065
        $doNotTrack = null,
1066
        $ajaxValidation = null,
1067
        $deviceId = '',
1068
        $ipList = null,
1069
        $plugins = null,
1070
        $refererUrl = null,
1071
        $originUrl = null,
1072
        $clientResolution = null
1073
    ) {
1074
        if ($deviceFingerprint !== null && !is_string($deviceFingerprint)) {
1075
            throw new \InvalidArgumentException('Device fingerprint must be string');
1076
        }
1077
        if ($userAgent !== null && !is_string($userAgent)) {
1078
            throw new \InvalidArgumentException('User agent must be string');
1079
        }
1080
        if ($cpuClass !== null && !is_string($cpuClass)) {
1081
            throw new \InvalidArgumentException('CPU class must be string');
1082
        }
1083
        if ($screenOrientation !== null && !is_string($screenOrientation)) {
1084
            throw new \InvalidArgumentException('Screen orientation must be string');
1085
        }
1086
        if ($screenResolution !== null && !is_string($screenResolution)) {
1087
            throw new \InvalidArgumentException('Screen resolution must be string');
1088
        }
1089
        if ($os !== null && !is_string($os)) {
1090
            throw new \InvalidArgumentException('OS must be string');
1091
        }
1092
        if ($timezoneOffset !== null && $timezoneOffset !== null && !is_int($timezoneOffset)) {
1093
            throw new \InvalidArgumentException('Timezone offset must be integer or null');
1094
        }
1095
        if ($languages !== null && !is_string($languages)) {
1096
            throw new \InvalidArgumentException('Languages must be string');
1097
        }
1098
        if ($language !== null && !is_string($language)) {
1099
            throw new \InvalidArgumentException('Language must be string');
1100
        }
1101
        if ($languageBrowser !== null && !is_string($languageBrowser)) {
1102
            throw new \InvalidArgumentException('Browser language must be string');
1103
        }
1104
        if ($languageUser !== null && !is_string($languageUser)) {
1105
            throw new \InvalidArgumentException('User language must be string');
1106
        }
1107
        if ($languageSystem !== null && !is_string($languageSystem)) {
1108
            throw new \InvalidArgumentException('System language must be string');
1109
        }
1110
        if ($cookieEnabled !== null && !is_bool($cookieEnabled)) {
1111
            throw new \InvalidArgumentException('Cookie enabled flag must be boolean');
1112
        }
1113
        if ($doNotTrack !== null && !is_bool($doNotTrack)) {
1114
            throw new \InvalidArgumentException('DNT flag must be boolean');
1115
        }
1116
        if ($ajaxValidation !== null && !is_bool($ajaxValidation)) {
1117
            throw new \InvalidArgumentException('AJAX validation flag must be boolean');
1118
        }
1119
        if ($deviceId !== null && !is_string($deviceId)) {
1120
            throw new \InvalidArgumentException('Device id must be string');
1121
        }
1122
        if ($ipList !== null && !is_string($ipList)) {
1123
            throw new \InvalidArgumentException('Ip list must be string');
1124
        }
1125
        if ($plugins !== null && !is_string($plugins)) {
1126
            throw new \InvalidArgumentException('Plugins must be string');
1127
        }
1128
        if ($refererUrl !== null && !is_string($refererUrl)) {
1129
            throw new \InvalidArgumentException('Referer url must be string');
1130
        }
1131
        if ($originUrl !== null && !is_string($originUrl)) {
1132
            throw new \InvalidArgumentException('Origin url must be string');
1133
        }
1134
        if ($clientResolution !== null && !is_string($clientResolution)) {
1135
            throw new \InvalidArgumentException('Client resolution must be string');
1136
        }
1137
1138
        $this->replace('device_fingerprint', $deviceFingerprint);
1139
        $this->replace('user_agent', $userAgent);
1140
        $this->replace('cpu_class', $cpuClass);
1141
        $this->replace('screen_orientation', $screenOrientation);
1142
        $this->replace('screen_resolution', $screenResolution);
1143
        $this->replace('os', $os);
1144
        $this->replace('timezone_offset', $timezoneOffset);
1145
        $this->replace('languages', $languages);
1146
        $this->replace('language', $language);
1147
        $this->replace('language_browser', $languageBrowser);
1148
        $this->replace('language_system', $languageSystem);
1149
        $this->replace('language_user', $languageUser);
1150
        $this->replace('cookie_enabled', $cookieEnabled);
1151
        $this->replace('do_not_track', $doNotTrack);
1152
        $this->replace('ajax_validation', $ajaxValidation);
1153
        $this->replace('device_id', $deviceId);
1154
        $this->replace('local_ip_list', $ipList);
1155
        $this->replace('plugins', $plugins);
1156
        $this->replace('referer_url', $refererUrl);
1157
        $this->replace('origin_url', $originUrl);
1158
        $this->replace('client_resolution', $clientResolution);
1159
1160
        return $this;
1161
    }
1162
1163
    /**
1164
     * Provides user data for envelope
1165
     *
1166
     * @param string|null $email
1167
     * @param string|null $userId
1168
     * @param string|null $phone
1169
     * @param string|null $userName
1170
     * @param string|null $firstName
1171
     * @param string|null $lastName
1172
     * @param string|null $gender
1173
     * @param int|null $age
1174
     * @param string|null $country
1175
     * @param string|null $socialType
1176
     * @param int|null $registrationTimestamp
1177
     * @param int|null $loginTimeStamp
1178
     * @param int|null $confirmationTimeStamp
1179
     * @param bool|null $emailConfirmed
1180
     * @param bool|null $phoneConfirmed
1181
     * @param bool|null $loginFailed
1182
     * @param int|null $birthDate
1183
     * @param string|null $fullname
1184
     * @param string|null $state
1185
     * @param string|null $city
1186
     * @param string|null $address
1187
     * @param string|null $zip
1188
     * @param string|null $password
1189
     *
1190
     * @return $this
1191
     */
1192
    public function addUserData(
1193
        $email = '',
1194
        $userId = '',
1195
        $phone = '',
1196
        $userName = '',
1197
        $firstName = '',
1198
        $lastName = '',
1199
        $gender = '',
1200
        $age = 0,
1201
        $country = '',
1202
        $socialType = '',
1203
        $registrationTimestamp = 0,
1204
        $loginTimeStamp = 0,
1205
        $confirmationTimeStamp = 0,
1206
        $emailConfirmed = null,
1207
        $phoneConfirmed = null,
1208
        $loginFailed = null,
1209
        $birthDate = null,
1210
        $fullname = null,
1211
        $state = null,
1212
        $city = null,
1213
        $address = null,
1214
        $zip = null,
1215
        $password = ''
1216
    )
1217
    {
1218
        if ($userName !== null && !is_string($userName)) {
1219
            throw new \InvalidArgumentException('User name must be string');
1220
        }
1221
        if ($password !== null && !is_string($password)) {
1222
            throw new \InvalidArgumentException('Password must be string');
1223
        }
1224
        if ($gender !== null && !is_string($gender)) {
1225
            throw new \InvalidArgumentException('Gender must be string');
1226
        }
1227
        if ($age !== null && !is_int($age)) {
1228
            throw new \InvalidArgumentException('Age must be integer');
1229
        }
1230
        if ($socialType !== null && !is_string($socialType)) {
1231
            throw new \InvalidArgumentException('Social type must be string');
1232
        }
1233
        if ($registrationTimestamp !== null && !is_int($registrationTimestamp)) {
1234
            throw new \InvalidArgumentException('Registration timestamp must be integer');
1235
        }
1236
        if ($loginTimeStamp !== null && !is_int($loginTimeStamp)) {
1237
            throw new \InvalidArgumentException('Login timestamp must be integer');
1238
        }
1239
        if ($confirmationTimeStamp !== null && !is_int($confirmationTimeStamp)) {
1240
            throw new \InvalidArgumentException('Confirmation timestamp must be integer');
1241
        }
1242
        if ($birthDate !== null && !is_int($birthDate)) {
1243
            throw new \InvalidArgumentException('Birthdate timestamp must be integer');
1244
        }
1245
        if ($emailConfirmed !== null && !is_bool($emailConfirmed)) {
1246
            throw new \InvalidArgumentException('Email confirmed flag must be boolean');
1247
        }
1248
        if ($phoneConfirmed !== null && !is_bool($phoneConfirmed)) {
1249
            throw new \InvalidArgumentException('Phone confirmed flag must be boolean');
1250
        }
1251
        if ($loginFailed !== null && !is_bool($loginFailed)) {
1252
            throw new \InvalidArgumentException('Login failed flag must be boolean');
1253
        }
1254
        if ($fullname !== null && !is_string($fullname)) {
1255
            throw new \InvalidArgumentException('Fullname must be string');
1256
        }
1257
        if ($state !== null && !is_string($state)) {
1258
            throw new \InvalidArgumentException('State must be string');
1259
        }
1260
        if ($city !== null && !is_string($city)) {
1261
            throw new \InvalidArgumentException('City must be string');
1262
        }
1263
        if ($address !== null && !is_string($address)) {
1264
            throw new \InvalidArgumentException('Address must be string');
1265
        }
1266
        if ($zip !== null && !is_string($zip)) {
1267
            throw new \InvalidArgumentException('Zip must be string');
1268
        }
1269
1270
        $this->addShortUserData($email, $userId, $phone, $firstName, $lastName, $country);
1271
1272
        $this->replace('user_name', $userName);
1273
        $this->replace('gender', $gender);
1274
        $this->replace('age', $age);
1275
        $this->replace('social_type', $socialType);
1276
        $this->replace('registration_timestamp', $registrationTimestamp);
1277
        $this->replace('login_timestamp', $loginTimeStamp);
1278
        $this->replace('confirmation_timestamp', $confirmationTimeStamp);
1279
        $this->replace('email_confirmed', $emailConfirmed);
1280
        $this->replace('phone_confirmed', $phoneConfirmed);
1281
        $this->replace('login_failed', $loginFailed);
1282
        $this->replace('birth_date', $birthDate);
1283
        $this->replace('fullname', $fullname);
1284
        $this->replace('state', $state);
1285
        $this->replace('city', $city);
1286
        $this->replace('address', $address);
1287
        $this->replace('zip', $zip);
1288
        $this->replace('password', $password);
1289
1290
        return $this;
1291
    }
1292
1293
    /**
1294
     * Provides user data for envelope
1295
     *
1296
     * @param string|null $email
1297
     * @param string|null $userId
1298
     * @param string|null $phone
1299
     * @param string|null $firstName
1300
     * @param string|null $lastName
1301
     * @param string|null $country
1302
     *
1303
     * @return $this
1304
     */
1305
    public function addShortUserData(
1306
        $email = '',
1307
        $userId = '',
1308
        $phone = '',
1309
        $firstName = '',
1310
        $lastName = '',
1311
        $country = ''
1312
    ) {
1313
        if ($email !== null && !is_string($email)) {
1314
            throw new \InvalidArgumentException('Email must be string');
1315
        }
1316
        if (is_int($userId)) {
1317
            $userId = strval($userId);
1318
        }
1319
        if ($userId !== null && !is_string($userId)) {
1320
            throw new \InvalidArgumentException('UserId must be string or integer');
1321
        }
1322
        if ($phone !== null && !is_string($phone)) {
1323
            throw new \InvalidArgumentException('Phone must be string');
1324
        }
1325
        if ($firstName !== null && !is_string($firstName)) {
1326
            throw new \InvalidArgumentException('First name must be string');
1327
        }
1328
        if ($lastName !== null && !is_string($lastName)) {
1329
            throw new \InvalidArgumentException('Last name must be string');
1330
        }
1331
        if ($country !== null && !is_string($country)) {
1332
            throw new \InvalidArgumentException('Country must be string');
1333
        }
1334
1335
        $this->replace('email', $email);
1336
        $this->replace('user_merchant_id', $userId);
1337
        $this->replace('phone', $phone);
1338
        $this->replace('firstname', $firstName);
1339
        $this->replace('lastname', $lastName);
1340
        $this->replace('country', $country);
1341
1342
        return $this;
1343
    }
1344
1345
    /**
1346
     * Provides credit card data to envelope
1347
     *
1348
     * @param string|null $transactionId
1349
     * @param string|null $transactionSource
1350
     * @param string|null $transactionType
1351
     * @param string|null $transactionMode
1352
     * @param string|null $transactionTimestamp
1353
     * @param string|null $transactionCurrency
1354
     * @param string|null $transactionAmount
1355
     * @param float|null $amountConverted
1356
     * @param string|null $paymentMethod
1357
     * @param string|null $paymentSystem
1358
     * @param string|null $paymentMidName
1359
     * @param string|null $paymentAccountId
1360
     *
1361
     * @return $this
1362
     */
1363
    public function addCCTransactionData(
1364
        $transactionId,
1365
        $transactionSource,
1366
        $transactionType,
1367
        $transactionMode,
1368
        $transactionTimestamp,
1369
        $transactionCurrency,
1370
        $transactionAmount,
1371
        $amountConverted = null,
1372
        $paymentMethod = null,
1373
        $paymentSystem = null,
1374
        $paymentMidName = null,
1375
        $paymentAccountId = null
1376
    ) {
1377
        if ($transactionId !== null && !is_string($transactionId)) {
1378
            throw new \InvalidArgumentException('Transaction ID must be string');
1379
        }
1380
        if ($transactionSource !== null && !is_string($transactionSource)) {
1381
            throw new \InvalidArgumentException('Transaction source must be string');
1382
        }
1383
        if ($transactionType !== null && !is_string($transactionType)) {
1384
            throw new \InvalidArgumentException('Transaction type must be string');
1385
        }
1386
        if ($transactionMode !== null && !is_string($transactionMode)) {
1387
            throw new \InvalidArgumentException('Transaction mode must be string');
1388
        }
1389
        if ($transactionTimestamp !== null && !is_int($transactionTimestamp)) {
1390
            throw new \InvalidArgumentException('Transaction timestamp must be integer');
1391
        }
1392
        if ($transactionAmount !== null && !is_int($transactionAmount) && !is_float($transactionAmount)) {
1393
            throw new \InvalidArgumentException('Transaction amount must be float');
1394
        }
1395
        if ($transactionCurrency !== null && !is_string($transactionCurrency)) {
1396
            throw new \InvalidArgumentException('Transaction currency must be string');
1397
        }
1398
        if ($paymentMethod !== null && !is_string($paymentMethod)) {
1399
            throw new \InvalidArgumentException('Payment method must be string');
1400
        }
1401
        if ($paymentSystem !== null && !is_string($paymentSystem)) {
1402
            throw new \InvalidArgumentException('Payment system must be string');
1403
        }
1404
        if ($paymentMidName !== null && !is_string($paymentMidName)) {
1405
            throw new \InvalidArgumentException('Payment MID name must be string');
1406
        }
1407
        if ($paymentAccountId !== null && !is_string($paymentAccountId)) {
1408
            throw new \InvalidArgumentException('Payment account id must be string');
1409
        }
1410 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...
1411
            throw new \InvalidArgumentException('Transaction amount converted must be float');
1412
        }
1413
1414
        $this->replace('transaction_id', $transactionId);
1415
        $this->replace('transaction_source', $transactionSource);
1416
        $this->replace('transaction_type', $transactionType);
1417
        $this->replace('transaction_mode', $transactionMode);
1418
        $this->replace('transaction_timestamp', $transactionTimestamp);
1419
        $this->replace('transaction_amount', floatval($transactionAmount));
1420
        $this->replace('transaction_amount_converted', floatval($amountConverted));
1421
        $this->replace('transaction_currency', $transactionCurrency);
1422
        $this->replace('payment_method', $paymentMethod);
1423
        $this->replace('payment_system', $paymentSystem);
1424
        $this->replace('payment_mid', $paymentMidName);
1425
        $this->replace('payment_account_id', $paymentAccountId);
1426
1427
        return $this;
1428
    }
1429
1430
    /**
1431
     * Provides Card data to envelope
1432
     *
1433
     * @param string|null $cardId
1434
     * @param int|null $cardBin
1435
     * @param string|null $cardLast4
1436
     * @param int|null $expirationMonth
1437
     * @param int|null $expirationYear
1438
     *
1439
     * @return $this
1440
     */
1441
    public function addCardData(
1442
        $cardBin,
1443
        $cardLast4,
1444
        $expirationMonth,
1445
        $expirationYear,
1446
        $cardId = null
1447
    ) {
1448
        if ($cardId !== null && !is_string($cardId)) {
1449
            throw new \InvalidArgumentException('Card ID must be string');
1450
        }
1451
        if ($cardBin !== null && !is_int($cardBin)) {
1452
            throw new \InvalidArgumentException('Card BIN must be integer');
1453
        }
1454
        if ($cardLast4 !== null && !is_string($cardLast4)) {
1455
            throw new \InvalidArgumentException('Card last4  must be string');
1456
        }
1457
        if ($expirationMonth !== null && !is_int($expirationMonth)) {
1458
            throw new \InvalidArgumentException('Expiration month must be integer');
1459
        }
1460
        if ($expirationYear !== null && !is_int($expirationYear)) {
1461
            throw new \InvalidArgumentException('Expiration year must be integer');
1462
        }
1463
1464
        $this->replace('card_id', $cardId);
1465
        $this->replace('card_bin', $cardBin);
1466
        $this->replace('card_last4', $cardLast4);
1467
        $this->replace('expiration_month', $expirationMonth);
1468
        $this->replace('expiration_year', $expirationYear);
1469
1470
        return $this;
1471
    }
1472
1473
    /**
1474
     * Provides billing data to envelope
1475
     *
1476
     * @param string|null $billingFirstName
1477
     * @param string|null $billingLastName
1478
     * @param string|null $billingFullName
1479
     * @param string|null $billingCountry
1480
     * @param string|null $billingState
1481
     * @param string|null $billingCity
1482
     * @param string|null $billingAddress
1483
     * @param string|null $billingZip
1484
     *
1485
     * @return $this
1486
     */
1487
    public function addBillingData(
1488
        $billingFirstName = null,
1489
        $billingLastName = null,
1490
        $billingFullName = null,
1491
        $billingCountry = null,
1492
        $billingState = null,
1493
        $billingCity = null,
1494
        $billingAddress = null,
1495
        $billingZip = null
1496
    ) {
1497
        if ($billingFirstName !== null && !is_string($billingFirstName)) {
1498
            throw new \InvalidArgumentException('Billing first name must be string');
1499
        }
1500
        if ($billingLastName !== null && !is_string($billingLastName)) {
1501
            throw new \InvalidArgumentException('Billing last name must be string');
1502
        }
1503
        if ($billingFullName !== null && !is_string($billingFullName)) {
1504
            throw new \InvalidArgumentException('Billing full name must be string');
1505
        }
1506
        if ($billingCountry !== null && !is_string($billingCountry)) {
1507
            throw new \InvalidArgumentException('Billing country name must be string');
1508
        }
1509
        if ($billingState !== null && !is_string($billingState)) {
1510
            throw new \InvalidArgumentException('Billing state must be string');
1511
        }
1512
        if ($billingCity !== null && !is_string($billingCity)) {
1513
            throw new \InvalidArgumentException('Billing city must be string');
1514
        }
1515
        if ($billingAddress !== null && !is_string($billingAddress)) {
1516
            throw new \InvalidArgumentException('Billing address must be string');
1517
        }
1518
        if ($billingZip !== null && !is_string($billingZip)) {
1519
            throw new \InvalidArgumentException('Billing zip must be string');
1520
        }
1521
1522
        $this->replace('billing_firstname', $billingFirstName);
1523
        $this->replace('billing_lastname', $billingLastName);
1524
        $this->replace('billing_fullname', $billingFullName);
1525
        $this->replace('billing_country', $billingCountry);
1526
        $this->replace('billing_state', $billingState);
1527
        $this->replace('billing_city', $billingCity);
1528
        $this->replace('billing_address', $billingAddress);
1529
        $this->replace('billing_zip', $billingZip);
1530
1531
        return $this;
1532
    }
1533
1534
    /**
1535
     * Provides product information to envelope
1536
     *
1537
     * @param float|null $productQuantity
1538
     * @param string|null $productName
1539
     * @param string|null $productDescription
1540
     *
1541
     * @return $this
1542
     */
1543 View Code Duplication
    public function addProductData(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
1544
        $productQuantity = null,
1545
        $productName = null,
1546
        $productDescription = null
1547
    ) {
1548
        if ($productQuantity !== null && !is_int($productQuantity) && !is_float($productQuantity)) {
1549
            throw new \InvalidArgumentException('Product quantity must be int or float');
1550
        }
1551
        if ($productName !== null && !is_string($productName)) {
1552
            throw new \InvalidArgumentException('Product name must be string');
1553
        }
1554
        if ($productDescription !== null && !is_string($productDescription)) {
1555
            throw new \InvalidArgumentException('Product description must be string');
1556
        }
1557
1558
        $this->replace('product_quantity', $productQuantity);
1559
        $this->replace('product_name', $productName);
1560
        $this->replace('product_description', $productDescription);
1561
1562
        return $this;
1563
    }
1564
1565
    /**
1566
     * Provides payout information to envelope
1567
     *
1568
     * @param string $payoutId
1569
     * @param int $payoutTimestamp
1570
     * @param int|float $payoutAmount
1571
     * @param string $payoutCurrency
1572
     * @param string|null $payoutCardId
1573
     * @param string|null $payoutAccountId
1574
     * @param string|null $payoutMethod
1575
     * @param string|null $payoutSystem
1576
     * @param string|null $payoutMid
1577
     * @param int|float|null $amountConverted
1578
     * @param int|null $payoutCardBin
1579
     * @param string|null $payoutCardLast4
1580
     * @param int|null $payoutExpirationMonth
1581
     * @param int|null $payoutExpirationYear
1582
     *
1583
     * @return $this
1584
     */
1585
    public function addPayoutData(
1586
        $payoutId,
1587
        $payoutTimestamp,
1588
        $payoutAmount,
1589
        $payoutCurrency,
1590
        $payoutCardId =  null,
1591
        $payoutAccountId = null,
1592
        $payoutMethod = null,
1593
        $payoutSystem = null,
1594
        $payoutMid = null,
1595
        $amountConverted = null,
1596
        $payoutCardBin = null,
1597
        $payoutCardLast4 = null,
1598
        $payoutExpirationMonth = null,
1599
        $payoutExpirationYear = null
1600
    ) {
1601
        if (!is_string($payoutId)) {
1602
            throw new \InvalidArgumentException('Payout ID must be string');
1603
        }
1604
        if (!is_int($payoutTimestamp)) {
1605
            throw new \InvalidArgumentException('Payout timestamp must be int');
1606
        }
1607
        if (!is_float($payoutAmount) && !is_int($payoutAmount)) {
1608
            throw new \InvalidArgumentException('Amount must be number');
1609
        }
1610
        if (!is_string($payoutCurrency)) {
1611
            throw new \InvalidArgumentException('Payout currency must be string');
1612
        }
1613
        if ($payoutAccountId !== null && !is_string($payoutAccountId)) {
1614
            throw new \InvalidArgumentException('Account ID must be string');
1615
        }
1616
        if ($payoutCardId !== null && !is_string($payoutCardId)) {
1617
            throw new \InvalidArgumentException('Card ID must be string');
1618
        }
1619
        if ($payoutMethod !== null && !is_string($payoutMethod)) {
1620
            throw new \InvalidArgumentException('Payout method must be string');
1621
        }
1622
        if ($payoutSystem !== null && !is_string($payoutSystem)) {
1623
            throw new \InvalidArgumentException('Payout system must be string');
1624
        }
1625
        if ($payoutMid !== null && !is_string($payoutMid)) {
1626
            throw new \InvalidArgumentException('Payout MID must be string');
1627
        }
1628 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...
1629
            throw new \InvalidArgumentException('Payout converted amount must be number');
1630
        }
1631
        if ($payoutCardBin !== null && !is_int($payoutCardBin)) {
1632
            throw new \InvalidArgumentException('Payout card BIN must be integer');
1633
        }
1634
        if ($payoutCardLast4 !== null && !is_string($payoutCardLast4)) {
1635
            throw new \InvalidArgumentException('Payout last 4 must be string');
1636
        }
1637
        if ($payoutExpirationMonth !== null && !is_int($payoutExpirationMonth)) {
1638
            throw new \InvalidArgumentException('Payout card expiration month must be integer');
1639
        }
1640
        if ($payoutExpirationYear !== null && !is_int($payoutExpirationYear)) {
1641
            throw new \InvalidArgumentException('Payout card expiration year must be integer');
1642
        }
1643
1644
        $this->replace('payout_id', $payoutId);
1645
        $this->replace('payout_timestamp', $payoutTimestamp);
1646
        $this->replace('payout_card_id', $payoutCardId);
1647
        $this->replace('payout_account_id', $payoutAccountId);
1648
        $this->replace('payout_amount', (float) $payoutAmount);
1649
        $this->replace('payout_currency', $payoutCurrency);
1650
        $this->replace('payout_method', $payoutMethod);
1651
        $this->replace('payout_system', $payoutSystem);
1652
        $this->replace('payout_mid', $payoutMid);
1653
        $this->replace('payout_amount_converted', (float) $amountConverted);
1654
        $this->replace('payout_card_bin', $payoutCardBin);
1655
        $this->replace('payout_card_last4', $payoutCardLast4);
1656
        $this->replace('payout_expiration_month', $payoutExpirationMonth);
1657
        $this->replace('payout_expiration_year', $payoutExpirationYear);
1658
1659
        return $this;
1660
    }
1661
1662
    /**
1663
     * Provides install information to envelope
1664
     *
1665
     * @param int $installTimestamp
1666
     *
1667
     * @return $this
1668
     */
1669
    public function addInstallData($installTimestamp)
1670
    {
1671
        if (!is_int($installTimestamp)) {
1672
            throw new \InvalidArgumentException('Install timestamp must be int');
1673
        }
1674
1675
        $this->replace('install_timestamp', $installTimestamp);
1676
1677
        return $this;
1678
    }
1679
1680
    /**
1681
     * Provides refund information to envelope
1682
     *
1683
     * @param string $refundId
1684
     * @param int|float $refundAmount
1685
     * @param string $refundCurrency
1686
     * @param int|null $refundTimestamp
1687
     * @param int|float|null $refundAmountConverted
1688
     * @param string|null $refundSource
1689
     * @param string|null $refundType
1690
     * @param string|null $refundCode
1691
     * @param string|null $refundReason
1692
     * @param string|null $agentId
1693
     * @param string|null $refundMethod
1694
     * @param string|null $refundSystem
1695
     * @param string|null $refundMid
1696
     *
1697
     * @return $this
1698
     */
1699
    public function addRefundData(
1700
        $refundId,
1701
        $refundTimestamp,
1702
        $refundAmount,
1703
        $refundCurrency,
1704
        $refundAmountConverted = null,
1705
        $refundSource = null,
1706
        $refundType = null,
1707
        $refundCode = null,
1708
        $refundReason = null,
1709
        $agentId = null,
1710
        $refundMethod = null,
1711
        $refundSystem = null,
1712
        $refundMid = null
1713
    ) {
1714
        if (!is_string($refundId)) {
1715
            throw new \InvalidArgumentException('Refund ID must be string');
1716
        }
1717
        if (!is_int($refundTimestamp)) {
1718
            throw new \InvalidArgumentException('Refund timestamp must be int');
1719
        }
1720
        if (!is_float($refundAmount) && !is_int($refundAmount)) {
1721
            throw new \InvalidArgumentException('Amount must be number');
1722
        }
1723
        if (!is_string($refundCurrency)) {
1724
            throw new \InvalidArgumentException('Refund currency must be string');
1725
        }
1726
        if ($refundAmountConverted !== null && !is_float($refundAmountConverted) && !is_int($refundAmountConverted)) {
1727
            throw new \InvalidArgumentException('Refund converted amount must be number');
1728
        }
1729
        if ($refundSource !== null && !is_string($refundSource)) {
1730
            throw new \InvalidArgumentException('Refund source must be string');
1731
        }
1732
        if ($refundType !== null && !is_string($refundType)) {
1733
            throw new \InvalidArgumentException('Refund type must be string');
1734
        }
1735
        if ($refundCode !== null && !is_string($refundCode)) {
1736
            throw new \InvalidArgumentException('Refund code must be string');
1737
        }
1738
        if ($refundReason !== null && !is_string($refundReason)) {
1739
            throw new \InvalidArgumentException('Refund reason must be string');
1740
        }
1741
        if ($agentId !== null && !is_string($agentId)) {
1742
            throw new \InvalidArgumentException('Agent id must be string');
1743
        }
1744
        if ($refundMethod !== null && !is_string($refundMethod)) {
1745
            throw new \InvalidArgumentException('Refund method must be string');
1746
        }
1747
        if ($refundSystem !== null && !is_string($refundSystem)) {
1748
            throw new \InvalidArgumentException('Refund system must be string');
1749
        }
1750
        if ($refundMid !== null && !is_string($refundMid)) {
1751
            throw new \InvalidArgumentException('Refund mid must be string');
1752
        }
1753
1754
        $this->replace('refund_id', $refundId);
1755
        $this->replace('refund_timestamp', $refundTimestamp);
1756
        $this->replace('refund_amount', $refundAmount);
1757
        $this->replace('refund_currency', $refundCurrency);
1758
        $this->replace('refund_amount_converted', $refundAmountConverted);
1759
        $this->replace('refund_source', $refundSource);
1760
        $this->replace('refund_type', $refundType);
1761
        $this->replace('refund_code', $refundCode);
1762
        $this->replace('refund_reason', $refundReason);
1763
        $this->replace('agent_id', $agentId);
1764
        $this->replace('refund_method', $refundMethod);
1765
        $this->replace('refund_system', $refundSystem);
1766
        $this->replace('refund_mid', $refundMid);
1767
1768
        return $this;
1769
    }
1770
1771
    /**
1772
     * Provides transfer information to envelope
1773
     *
1774
     * @param string $eventId
1775
     * @param int $eventTimestamp
1776
     * @param float $amount
1777
     * @param string $currency
1778
     * @param string $accountId
1779
     * @param string $secondAccountId
1780
     * @param string $accountSystem
1781
     * @param float|null $amountConverted
1782
     * @param string|null $method
1783
     * @param string|null $operation
1784
     * @param string|null $secondEmail
1785
     * @param string|null $secondPhone
1786
     * @param string|int $secondBirthDate
1787
     * @param string|null $secondFirstname
1788
     * @param string|null $secondLastname
1789
     * @param string|null $secondFullname
1790
     * @param string|null $secondState
1791
     * @param string|null $secondCity
1792
     * @param string|null $secondAddress
1793
     * @param string|null $secondZip
1794
     * @param string|null $secondGender
1795
     * @param string|null $secondCountry
1796
     * @param string|null $iban
1797
     * @param string|null $secondIban
1798
     *
1799
     * @return $this
1800
     */
1801
    public function addTransferData(
1802
        $eventId,
1803
        $eventTimestamp,
1804
        $amount,
1805
        $currency,
1806
        $accountId,
1807
        $secondAccountId,
1808
        $accountSystem,
1809
        $amountConverted = null,
1810
        $method = null,
1811
        $operation = null,
1812
        $secondEmail = null,
1813
        $secondPhone = null,
1814
        $secondBirthDate = null,
1815
        $secondFirstname = null,
1816
        $secondLastname = null,
1817
        $secondFullname = null,
1818
        $secondState = null,
1819
        $secondCity = null,
1820
        $secondAddress = null,
1821
        $secondZip = null,
1822
        $secondGender = null,
1823
        $secondCountry = null,
1824
        $iban = null,
1825
        $secondIban = null
1826
    ) {
1827
        if (!is_string($eventId)) {
1828
            throw new \InvalidArgumentException('Event ID must be string');
1829
        }
1830
        if (!is_int($eventTimestamp)) {
1831
            throw new \InvalidArgumentException('Event timestamp must be int');
1832
        }
1833
        if (!is_int($amount) && !is_float($amount)) {
1834
            throw new \InvalidArgumentException('Amount must be number');
1835
        }
1836
        if (!is_string($currency)) {
1837
            throw new \InvalidArgumentException('Currency must be string');
1838
        }
1839
        if (!is_string($accountId)) {
1840
            throw new \InvalidArgumentException('Account id must be string');
1841
        }
1842
        if (!is_string($secondAccountId)) {
1843
            throw new \InvalidArgumentException('Second account id must be string');
1844
        }
1845
        if (!is_string($accountSystem)) {
1846
            throw new \InvalidArgumentException('Account system must be string');
1847
        }
1848 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...
1849
            throw new \InvalidArgumentException('Amount converted must be number');
1850
        }
1851
        if ($method !== null && !is_string($method)) {
1852
            throw new \InvalidArgumentException('Method must be string');
1853
        }
1854
        if ($operation !== null && !is_string($operation)) {
1855
            throw new \InvalidArgumentException('Operation must be string');
1856
        }
1857
        if ($secondPhone !== null && !is_string($secondPhone)) {
1858
            throw new \InvalidArgumentException('Second phone must be string');
1859
        }
1860
        if ($secondEmail !== null && !is_string($secondEmail)) {
1861
            throw new \InvalidArgumentException('Second email must be string');
1862
        }
1863
        if ($secondBirthDate !== null && !is_int($secondBirthDate)) {
1864
            throw new \InvalidArgumentException('Second birth date must be int');
1865
        }
1866
        if ($secondFirstname !== null && !is_string($secondFirstname)) {
1867
            throw new \InvalidArgumentException('Second firstname must be string');
1868
        }
1869
        if ($secondLastname !== null && !is_string($secondLastname)) {
1870
            throw new \InvalidArgumentException('Second lastname must be string');
1871
        }
1872
        if ($secondFullname !== null && !is_string($secondFullname)) {
1873
            throw new \InvalidArgumentException('Second fullname must be string');
1874
        }
1875
        if ($secondState !== null && !is_string($secondState)) {
1876
            throw new \InvalidArgumentException('Second state must be string');
1877
        }
1878
        if ($secondCity !== null && !is_string($secondCity)) {
1879
            throw new \InvalidArgumentException('Second city must be string');
1880
        }
1881
        if ($secondAddress !== null && !is_string($secondAddress)) {
1882
            throw new \InvalidArgumentException('Second address must be string');
1883
        }
1884
        if ($secondZip !== null && !is_string($secondZip)) {
1885
            throw new \InvalidArgumentException('Second zip must be string');
1886
        }
1887
        if ($secondGender !== null && !is_string($secondGender)) {
1888
            throw new \InvalidArgumentException('Second gender must be string');
1889
        }
1890
        if ($secondCountry !== null && !is_string($secondCountry)) {
1891
            throw new \InvalidArgumentException('Second country must be string');
1892
        }
1893
        if ($iban !== null && !is_string($iban)) {
1894
            throw new \InvalidArgumentException('Iban must be string');
1895
        }
1896
        if ($secondIban !== null && !is_string($secondIban)) {
1897
            throw new \InvalidArgumentException('Second iban must be string');
1898
        }
1899
1900
        $this->replace('event_id', $eventId);
1901
        $this->replace('event_timestamp', $eventTimestamp);
1902
        $this->replace('amount', $amount);
1903
        $this->replace('currency', $currency);
1904
        $this->replace('account_id', $accountId);
1905
        $this->replace('second_account_id', $secondAccountId);
1906
        $this->replace('account_system', $accountSystem);
1907
        $this->replace('amount_converted', $amountConverted);
1908
        $this->replace('method', $method);
1909
        $this->replace('operation', $operation);
1910
        $this->replace('second_email', $secondEmail);
1911
        $this->replace('second_phone', $secondPhone);
1912
        $this->replace('second_birth_date', $secondBirthDate);
1913
        $this->replace('second_firstname', $secondFirstname);
1914
        $this->replace('second_lastname', $secondLastname);
1915
        $this->replace('second_fullname', $secondFullname);
1916
        $this->replace('second_state', $secondState);
1917
        $this->replace('second_city', $secondCity);
1918
        $this->replace('second_address', $secondAddress);
1919
        $this->replace('second_zip', $secondZip);
1920
        $this->replace('second_gender', $secondGender);
1921
        $this->replace('second_country', $secondCountry);
1922
        $this->replace('iban', $iban);
1923
        $this->replace('second_iban', $secondIban);
1924
1925
        return $this;
1926
    }
1927
1928
    /**
1929
     * Provides kyc information to envelope
1930
     *
1931
     * @param string $eventId
1932
     * @param int $eventTimestamp
1933
     * @param string|null $groupId
1934
     * @param string|null $status
1935
     * @param string|null $code
1936
     * @param string|null $reason
1937
     * @param string|null $providerResult
1938
     * @param string|null $providerCode
1939
     * @param string|null $providerReason
1940
     * @param string|null $profileId
1941
     * @param string|null $profileType
1942
     * @param string|null $profileSubType
1943
     * @param string|null $industry
1944
     * @param string|null $description
1945
     * @param int|null $regDate
1946
     * @param string|null $regNumber
1947
     * @param string|null $vatNumber
1948
     * @param string|null $secondCountry
1949
     * @param string|null $secondState
1950
     * @param string|null $secondCity
1951
     * @param string|null $secondAddress
1952
     * @param string|null $secondZip
1953
     * @param string|null $relatedProfiles
1954
     *
1955
     * @return $this
1956
     */
1957
    public function addKycData(
1958
        $eventId,
1959
        $eventTimestamp,
1960
        $groupId = null,
1961
        $status = null,
1962
        $code = null,
1963
        $reason = null,
1964
        $providerResult = null,
1965
        $providerCode = null,
1966
        $providerReason = null,
1967
        $profileId = null,
1968
        $profileType = null,
1969
        $profileSubType = null,
1970
        $industry = null,
1971
        $description = null,
1972
        $regDate = null,
1973
        $regNumber = null,
1974
        $vatNumber = null,
1975
        $secondCountry = null,
1976
        $secondState = null,
1977
        $secondCity = null,
1978
        $secondAddress = null,
1979
        $secondZip = null,
1980
        $relatedProfiles = null
1981
    ) {
1982
        if (!is_string($eventId)) {
1983
            throw new \InvalidArgumentException('Event ID must be string');
1984
        }
1985
        if (!is_int($eventTimestamp)) {
1986
            throw new \InvalidArgumentException('Event timestamp must be int');
1987
        }
1988
        if ($groupId !== null && !is_string($groupId)) {
1989
            throw new \InvalidArgumentException('Group id must be string');
1990
        }
1991
        if ($status !== null && !is_string($status)) {
1992
            throw new \InvalidArgumentException('Status must be string');
1993
        }
1994
        if ($code !== null && !is_string($code)) {
1995
            throw new \InvalidArgumentException('Code must be string');
1996
        }
1997
        if ($reason !== null && !is_string($reason)) {
1998
            throw new \InvalidArgumentException('Reason must be string');
1999
        }
2000
        if ($providerResult !== null && !is_string($providerResult)) {
2001
            throw new \InvalidArgumentException('Provider result must be string');
2002
        }
2003
        if ($providerCode !== null && !is_string($providerCode)) {
2004
            throw new \InvalidArgumentException('Provider code must be string');
2005
        }
2006
        if ($providerReason !== null && !is_string($providerReason)) {
2007
            throw new \InvalidArgumentException('Provider reason must be string');
2008
        }
2009
        if ($profileId !== null && !is_string($profileId)) {
2010
            throw new \InvalidArgumentException('Profile id must be string');
2011
        }
2012
        if ($profileType !== null && !is_string($profileType)) {
2013
            throw new \InvalidArgumentException('Profile type must be string');
2014
        }
2015
        if ($profileSubType !== null && !is_string($profileSubType)) {
2016
            throw new \InvalidArgumentException('Profile sub type must be string');
2017
        }
2018
        if ($industry !== null && !is_string($industry)) {
2019
            throw new \InvalidArgumentException('Industry must be string');
2020
        }
2021
        if ($description !== null && !is_string($description)) {
2022
            throw new \InvalidArgumentException('Description must be string');
2023
        }
2024
        if ($regDate !== null && !is_int($regDate)) {
2025
            throw new \InvalidArgumentException('Reg date must be integer');
2026
        }
2027
        if ($regNumber !== null && !is_string($regNumber)) {
2028
            throw new \InvalidArgumentException('Reg number must be string');
2029
        }
2030
        if ($vatNumber !== null && !is_string($vatNumber)) {
2031
            throw new \InvalidArgumentException('Vat number must be string');
2032
        }
2033
        if ($secondCountry !== null && !is_string($secondCountry)) {
2034
            throw new \InvalidArgumentException('Secondary country must be string');
2035
        }
2036
        if ($secondState !== null && !is_string($secondState)) {
2037
            throw new \InvalidArgumentException('Second state must be string');
2038
        }
2039
        if ($secondCity !== null && !is_string($secondCity)) {
2040
            throw new \InvalidArgumentException('Second city must be string');
2041
        }
2042
        if ($secondAddress !== null && !is_string($secondAddress)) {
2043
            throw new \InvalidArgumentException('Second address must be string');
2044
        }
2045
        if ($secondZip !== null && !is_string($secondZip)) {
2046
            throw new \InvalidArgumentException('Second zip must be string');
2047
        }
2048
        if ($relatedProfiles !== null && !is_string($relatedProfiles)) {
2049
            throw new \InvalidArgumentException('Related profiles must be string');
2050
        }
2051
2052
        $this->replace('event_id', $eventId);
2053
        $this->replace('event_timestamp', $eventTimestamp);
2054
        $this->replace('group_id', $groupId);
2055
        $this->replace('status', $status);
2056
        $this->replace('code', $code);
2057
        $this->replace('reason', $reason);
2058
        $this->replace('provider_result', $providerResult);
2059
        $this->replace('provider_code', $providerCode);
2060
        $this->replace('provider_reason', $providerReason);
2061
        $this->replace('profile_id', $profileId);
2062
        $this->replace('profile_type', $profileType);
2063
        $this->replace('profile_sub_type', $profileSubType);
2064
        $this->replace('industry', $industry);
2065
        $this->replace('description', $description);
2066
        $this->replace('reg_date', $regDate);
2067
        $this->replace('reg_number', $regNumber);
2068
        $this->replace('vat_number', $vatNumber);
2069
        $this->replace('second_country', $secondCountry);
2070
        $this->replace('second_state', $secondState);
2071
        $this->replace('second_city', $secondCity);
2072
        $this->replace('second_address', $secondAddress);
2073
        $this->replace('second_zip', $secondZip);
2074
        $this->replace('related_profiles', $relatedProfiles);
2075
2076
        return $this;
2077
    }
2078
2079
    /**
2080
     * Provides postback information to envelope
2081
     *
2082
     * @param int|null $requestId
2083
     * @param string|null $transactionId
2084
     * @param string|null $transactionStatus
2085
     * @param string|null $code
2086
     * @param string|null $reason
2087
     * @param string|null $secure3d
2088
     * @param string|null $avsResult
2089
     * @param string|null $cvvResult
2090
     * @param string|null $pspCode
2091
     * @param string|null $pspReason
2092
     * @param string|null $arn
2093
     * @param string|null $paymentAccountId
2094
     * @return $this
2095
     */
2096
    public function addPostbackData(
2097
        $requestId = null,
2098
        $transactionId = null,
2099
        $transactionStatus = null,
2100
        $code = null,
2101
        $reason = null,
2102
        $secure3d = null,
2103
        $avsResult = null,
2104
        $cvvResult = null,
2105
        $pspCode = null,
2106
        $pspReason = null,
2107
        $arn = null,
2108
        $paymentAccountId = null
2109
    ) {
2110
        if ($requestId === null && $transactionId === null) {
2111
            throw new \InvalidArgumentException('request_id or transaction_id should be provided');
2112
        }
2113
        if ($transactionId !== null && !is_string($transactionId)) {
2114
            throw new \InvalidArgumentException('TransactionId must be string');
2115
        }
2116
        if ($requestId !== null && !is_int($requestId)) {
2117
            throw new \InvalidArgumentException('RequestId must be int');
2118
        }
2119
        if ($transactionStatus !== null && !is_string($transactionStatus)) {
2120
            throw new \InvalidArgumentException('Transaction status must be string');
2121
        }
2122
        if ($code !== null && !is_string($code)) {
2123
            throw new \InvalidArgumentException('Code must be string');
2124
        }
2125
        if ($reason !== null && !is_string($reason)) {
2126
            throw new \InvalidArgumentException('Reason must be string');
2127
        }
2128
        if ($secure3d !== null && !is_string($secure3d)) {
2129
            throw new \InvalidArgumentException('Secure3d must be string');
2130
        }
2131
        if ($avsResult !== null && !is_string($avsResult)) {
2132
            throw new \InvalidArgumentException('AvsResult must be string');
2133
        }
2134
        if ($cvvResult !== null && !is_string($cvvResult)) {
2135
            throw new \InvalidArgumentException('CvvResult must be string');
2136
        }
2137
        if ($pspCode !== null && !is_string($pspCode)) {
2138
            throw new \InvalidArgumentException('PspCode must be string');
2139
        }
2140
        if ($pspReason !== null && !is_string($pspReason)) {
2141
            throw new \InvalidArgumentException('PspReason must be string');
2142
        }
2143
        if ($arn !== null && !is_string($arn)) {
2144
            throw new \InvalidArgumentException('Arn must be string');
2145
        }
2146
        if ($paymentAccountId !== null && !is_string($paymentAccountId)) {
2147
            throw new \InvalidArgumentException('PaymentAccoutId must be string');
2148
        }
2149
2150
        $this->replace('request_id', $requestId);
2151
        $this->replace('transaction_id', $transactionId);
2152
        $this->replace('transaction_status', $transactionStatus);
2153
        $this->replace('code', $code);
2154
        $this->replace('reason', $reason);
2155
        $this->replace('secure3d', $secure3d);
2156
        $this->replace('avs_result', $avsResult);
2157
        $this->replace('cvv_result', $cvvResult);
2158
        $this->replace('psp_code', $pspCode);
2159
        $this->replace('psp_reason', $pspReason);
2160
        $this->replace('arn', $arn);
2161
        $this->replace('payment_account_id', $paymentAccountId);
2162
2163
        return $this;
2164
    }
2165
2166
    /**
2167
     * Adds custom data field to envelope
2168
     *
2169
     * @param string $name
2170
     * @param string $value
2171
     *
2172
     * @return $this
2173
     */
2174
    public function addCustomField($name, $value)
2175
    {
2176
        if (!is_string($name)) {
2177
            throw new \InvalidArgumentException('Custom field name must be string');
2178
        }
2179
        if (!is_string($value)) {
2180
            throw new \InvalidArgumentException('Custom field value must be string');
2181
        }
2182
2183
        if (strlen($name) < 8 || substr($name, 0, 7) !== 'custom_') {
2184
            $name = 'custom_' . $name;
2185
        }
2186
2187
        $this->replace($name, $value);
2188
        return $this;
2189
    }
2190
}
2191