Completed
Push — master ( 83cf5f...bbee1f )
by
unknown
19s queued 12s
created

Builder::orderSubmitEvent()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 111

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 111
rs 8
c 0
b 0
f 0
cc 2
nc 2
nop 45

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
     *
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
     * @param string|null $campaign
87
     *
88
     * @return Builder
89
     */
90
    public static function loginEvent(
91
        $sequenceId,
92
        $userId,
93
        $timestamp = null,
94
        $email = null,
95
        $failed = null,
96
        $gender = null,
97
        $trafficSource = null,
98
        $affiliateId = null,
99
        $password = null,
100
        $campaign = null
101
    ) {
102
        $builder = new self('login', $sequenceId);
103
        if ($timestamp === null) {
104
            $timestamp = time();
105
        }
106
107
        return $builder->addUserData(
108
            $email,
109
            $userId,
110
            null,
111
            null,
112
            null,
113
            null,
114
            $gender,
115
            null,
116
            null,
117
            null,
118
            null,
119
            $timestamp,
120
            null,
121
            null,
122
            null,
123
            $failed,
124
            null,
125
            null,
126
            null,
127
            null,
128
            null,
129
            null,
130
            $password
131
        )->addWebsiteData(null, $trafficSource, $affiliateId, $campaign);
132
    }
133
134
    /**
135
     * Returns builder for registration event
136
     *
137
     * @param string $sequenceId
138
     * @param string $userId
139
     * @param int|null $timestamp
140
     * @param string|null $email
141
     * @param string|null $userName
142
     * @param string|null $firstName
143
     * @param string|null $lastName
144
     * @param int|null $age
145
     * @param string|null $gender
146
     * @param string|null $phone
147
     * @param string|null $country
148
     * @param string|null $socialType
149
     * @param string|null $websiteUrl
150
     * @param string|null $trafficSource
151
     * @param string|null $affiliateId
152
     * @param string|null $password
153
     * @param string|null $campaign
154
     *
155
     * @return Builder
156
     */
157
    public static function registrationEvent(
158
        $sequenceId,
159
        $userId,
160
        $timestamp = null,
161
        $email = null,
162
        $userName = null,
163
        $firstName = null,
164
        $lastName = null,
165
        $age = null,
166
        $gender = null,
167
        $phone = null,
168
        $country = null,
169
        $socialType = null,
170
        $websiteUrl = null,
171
        $trafficSource = null,
172
        $affiliateId = null,
173
        $password = null,
174
        $campaign = null
175
    ) {
176
        $builder = new self('registration', $sequenceId);
177
        if ($timestamp === null) {
178
            $timestamp = time();
179
        }
180
181
        return $builder->addWebsiteData(
182
            $websiteUrl,
183
            $trafficSource,
184
            $affiliateId,
185
            $campaign
186
        )->addUserData(
187
            $email,
188
            $userId,
189
            $phone,
190
            $userName,
191
            $firstName,
192
            $lastName,
193
            $gender,
194
            $age,
195
            $country,
196
            $socialType,
197
            $timestamp,
198
            null,
199
            null,
200
            null,
201
            null,
202
            null,
203
            null,
204
            null,
205
            null,
206
            null,
207
            null,
208
            null,
209
            $password
210
211
        );
212
    }
213
214
    /**
215
     * Returns builder for payout request
216
     *
217
     * @param string $sequenceId
218
     * @param string $userId
219
     * @param string $payoutId
220
     * @param string $currency
221
     * @param int|float $amount
222
     * @param int|null $payoutTimestamp
223
     * @param string|null $cardId
224
     * @param string|null $accountId
225
     * @param string|null $method
226
     * @param string|null $system
227
     * @param string|null $mid
228
     * @param int|float $amountConverted
229
     * @param string|null $firstName
230
     * @param string|null $lastName
231
     * @param string|null $country
232
     * @param string|null $email
233
     * @param string|null $phone
234
     * @param int|null $cardBin
235
     * @param string|null $cardLast4
236
     * @param int|null $cardExpirationMonth
237
     * @param int|null $cardExpirationYear
238
     *
239
     * @return Builder
240
     */
241
    public static function payoutEvent(
242
        $sequenceId,
243
        $userId,
244
        $payoutId,
245
        $currency,
246
        $amount,
247
        $payoutTimestamp = null,
248
        $cardId = null,
249
        $accountId = null,
250
        $method = null,
251
        $system = null,
252
        $mid = null,
253
        $amountConverted = null,
254
        $firstName = null,
255
        $lastName = null,
256
        $country = null,
257
        $email = null,
258
        $phone = null,
259
        $cardBin = null,
260
        $cardLast4 = null,
261
        $cardExpirationMonth = null,
262
        $cardExpirationYear = null
263
    ) {
264
        $builder = new self('payout', $sequenceId);
265
        if ($payoutTimestamp === null) {
266
            $payoutTimestamp = time();
267
        }
268
        return $builder->addPayoutData(
269
            $payoutId,
270
            $payoutTimestamp,
271
            $amount,
272
            $currency,
273
            $cardId,
274
            $accountId,
275
            $method,
276
            $system,
277
            $mid,
278
            $amountConverted,
279
            $cardBin,
280
            $cardLast4,
281
            $cardExpirationMonth,
282
            $cardExpirationYear
283
        )->addShortUserData($email, $userId, $phone, $firstName, $lastName, $country);
284
    }
285
286
    /**
287
     * Returns builder for transaction request
288
     *
289
     * @param string $sequenceId
290
     * @param string $userId
291
     * @param string $transactionId
292
     * @param int|float $transactionAmount
293
     * @param string $transactionCurrency
294
     * @param int|null $transactionTimestamp
295
     * @param string|null $transactionMode
296
     * @param string|null $transactionType
297
     * @param int|null $cardBin
298
     * @param string|null $cardId
299
     * @param string|null $cardLast4
300
     * @param int|null $expirationMonth
301
     * @param int|null $expirationYear
302
     * @param int|null $age
303
     * @param string|null $country
304
     * @param string|null $email
305
     * @param string|null $gender
306
     * @param string|null $firstName
307
     * @param string|null $lastName
308
     * @param string|null $phone
309
     * @param string|null $userName
310
     * @param string|null $paymentAccountId
311
     * @param string|null $paymentMethod
312
     * @param string|null $paymentMidName
313
     * @param string|null $paymentSystem
314
     * @param int|float|null $transactionAmountConverted
315
     * @param string|null $transactionSource
316
     * @param string|null $billingAddress
317
     * @param string|null $billingCity
318
     * @param string|null $billingCountry
319
     * @param string|null $billingFirstName
320
     * @param string|null $billingLastName
321
     * @param string|null $billingFullName
322
     * @param string|null $billingState
323
     * @param string|null $billingZip
324
     * @param string|null $productDescription
325
     * @param string|null $productName
326
     * @param int|float|null $productQuantity
327
     * @param string|null $websiteUrl
328
     * @param string|null $merchantIp
329
     * @param string|null $affiliateId
330
     * @param string|null $campaign
331
     *
332
     * @return Builder
333
     */
334
    public static function transactionEvent(
335
        $sequenceId,
336
        $userId,
337
        $transactionId,
338
        $transactionAmount,
339
        $transactionCurrency,
340
        $transactionTimestamp = null,
341
        $transactionMode = null,
342
        $transactionType = null,
343
        $cardBin = null,
344
        $cardId = null,
345
        $cardLast4 = null,
346
        $expirationMonth = null,
347
        $expirationYear = null,
348
        $age = null,
349
        $country = null,
350
        $email = null,
351
        $gender = null,
352
        $firstName = null,
353
        $lastName = null,
354
        $phone = null,
355
        $userName = null,
356
        $paymentAccountId = null,
357
        $paymentMethod = null,
358
        $paymentMidName = null,
359
        $paymentSystem = null,
360
        $transactionAmountConverted = null,
361
        $transactionSource = null,
362
        $billingAddress = null,
363
        $billingCity = null,
364
        $billingCountry = null,
365
        $billingFirstName = null,
366
        $billingLastName = null,
367
        $billingFullName = null,
368
        $billingState = null,
369
        $billingZip = null,
370
        $productDescription = null,
371
        $productName = null,
372
        $productQuantity = null,
373
        $websiteUrl = null,
374
        $merchantIp = null,
375
        $affiliateId = null,
376
        $campaign = null
377
    ) {
378
        $builder = new self('transaction', $sequenceId);
379
        if ($transactionTimestamp === null) {
380
            $transactionTimestamp = time();
381
        }
382
383
        return $builder
384
            ->addCCTransactionData(
385
                $transactionId,
386
                $transactionSource,
387
                $transactionType,
388
                $transactionMode,
389
                $transactionTimestamp,
390
                $transactionCurrency,
391
                $transactionAmount,
392
                $transactionAmountConverted,
393
                $paymentMethod,
394
                $paymentSystem,
395
                $paymentMidName,
396
                $paymentAccountId
397
            )
398
            ->addBillingData(
399
                $billingFirstName,
400
                $billingLastName,
401
                $billingFullName,
402
                $billingCountry,
403
                $billingState,
404
                $billingCity,
405
                $billingAddress,
406
                $billingZip
407
            )
408
            ->addCardData($cardBin, $cardLast4, $expirationMonth, $expirationYear, $cardId)
409
            ->addUserData(
410
                $email,
411
                $userId,
412
                $phone,
413
                $userName,
414
                $firstName,
415
                $lastName,
416
                $gender,
417
                $age,
418
                $country
419
            )
420
            ->addProductData($productQuantity, $productName, $productDescription)
421
            ->addWebsiteData($websiteUrl, null, $affiliateId, $campaign)
422
            ->addIpData(null, null, $merchantIp);
423
424
    }
425
426
    /**
427
     * Returns builder for install request
428
     *
429
     * @param string $sequenceId
430
     * @param string|null $userId
431
     * @param int|null $installTimestamp
432
     * @param string|null $country
433
     * @param string|null $websiteUrl
434
     * @param string|null $trafficSource
435
     * @param string|null $affiliateId
436
     * @param string|null $campaign
437
     *
438
     * @return Builder
439
     */
440
    public static function installEvent(
441
        $sequenceId,
442
        $userId = null,
443
        $installTimestamp = null,
444
        $country = null,
445
        $websiteUrl = null,
446
        $trafficSource = null,
447
        $affiliateId = null,
448
        $campaign = null
449
    ) {
450
        $builder = new self('install', $sequenceId);
451
        if ($installTimestamp === null) {
452
            $installTimestamp = time();
453
        }
454
455
        return $builder->addInstallData(
456
            $installTimestamp
457
        )->addWebsiteData($websiteUrl, $trafficSource, $affiliateId, $campaign)
458
        ->addShortUserData(null, $userId, null, null, null, $country);
459
    }
460
461
    /**
462
     * Returns builder for refund request
463
     *
464
     * @param string $sequenceId
465
     * @param string $refundId
466
     * @param int|float $refundAmount
467
     * @param string $refundCurrency
468
     * @param int|null $refundTimestamp
469
     * @param int|float|null $refundAmountConverted
470
     * @param string|null $refundSource
471
     * @param string|null $refundType
472
     * @param string|null $refundCode
473
     * @param string|null $refundReason
474
     * @param string|null $agentId
475
     * @param string|null $refundMethod
476
     * @param string|null $refundSystem
477
     * @param string|null $refundMid
478
     *
479
     * @return Builder
480
     */
481
    public static function refundEvent(
482
        $sequenceId,
483
        $refundId,
484
        $refundAmount,
485
        $refundCurrency,
486
        $refundTimestamp = null,
487
        $refundAmountConverted = null,
488
        $refundSource = null,
489
        $refundType = null,
490
        $refundCode = null,
491
        $refundReason = null,
492
        $agentId = null,
493
        $refundMethod = null,
494
        $refundSystem = null,
495
        $refundMid = null,
496
        $email = null,
497
        $phone = null,
498
        $userId = null
499
    ) {
500
        $builder = new self('refund', $sequenceId);
501
        if ($refundTimestamp === null) {
502
            $refundTimestamp = time();
503
        }
504
505
        return $builder->addRefundData(
506
            $refundId,
507
            $refundTimestamp,
508
            $refundAmount,
509
            $refundCurrency,
510
            $refundAmountConverted,
511
            $refundSource,
512
            $refundType,
513
            $refundCode,
514
            $refundReason,
515
            $agentId,
516
            $refundMethod,
517
            $refundSystem,
518
            $refundMid
519
        )->addUserData($email, $userId, $phone);
520
    }
521
522
    /**
523
     * Returns builder for transfer request
524
     *
525
     * @param string $sequenceId
526
     * @param string $eventId
527
     * @param float $amount
528
     * @param string $currency
529
     * @param string $accountId
530
     * @param string $secondAccountId
531
     * @param string $accountSystem
532
     * @param string $userId
533
     * @param string|null $method
534
     * @param int|null $eventTimestamp
535
     * @param float|null $amountConverted
536
     * @param string|null $email
537
     * @param string|null $phone
538
     * @param int|null $birthDate
539
     * @param string|null $firstname
540
     * @param string|null $lastname
541
     * @param string|null $fullname
542
     * @param string|null $state
543
     * @param string|null $city
544
     * @param string|null $address
545
     * @param string|null $zip
546
     * @param string|null $gender
547
     * @param string|null $country
548
     * @param string|null $operation
549
     * @param string|null $secondEmail
550
     * @param string|null $secondPhone
551
     * @param int|null $secondBirthDate
552
     * @param string|null $secondFirstname
553
     * @param string|null $secondLastname
554
     * @param string|null $secondFullname
555
     * @param string|null $secondState
556
     * @param string|null $secondCity
557
     * @param string|null $secondAddress
558
     * @param string|null $secondZip
559
     * @param string|null $secondGender
560
     * @param string|null $secondCountry
561
     * @param string|null $productDescription
562
     * @param string|null $productName
563
     * @param int|float|null $productQuantity
564
     * @param string|null $iban
565
     * @param string|null $secondIban
566
     * @param string|null $bic
567
     * @param string|null $source
568
     *
569
     * @return Builder
570
     */
571
    public static function transferEvent(
572
        $sequenceId,
573
        $eventId,
574
        $amount,
575
        $currency,
576
        $accountId,
577
        $secondAccountId,
578
        $accountSystem,
579
        $userId,
580
        $method = null,
581
        $eventTimestamp = null,
582
        $amountConverted = null,
583
        $email = null,
584
        $phone = null,
585
        $birthDate = null,
586
        $firstname = null,
587
        $lastname = null,
588
        $fullname = null,
589
        $state = null,
590
        $city = null,
591
        $address = null,
592
        $zip = null,
593
        $gender = null,
594
        $country = null,
595
        $operation = null,
596
        $secondEmail = null,
597
        $secondPhone = null,
598
        $secondBirthDate = null,
599
        $secondFirstname = null,
600
        $secondLastname = null,
601
        $secondFullname = null,
602
        $secondState = null,
603
        $secondCity = null,
604
        $secondAddress = null,
605
        $secondZip = null,
606
        $secondGender = null,
607
        $secondCountry = null,
608
        $productDescription = null,
609
        $productName = null,
610
        $productQuantity = null,
611
        $iban = null,
612
        $secondIban = null,
613
        $bic = null,
614
        $source = null
615
    ) {
616
        $builder = new self('transfer', $sequenceId);
617
        if ($eventTimestamp === null) {
618
            $eventTimestamp = time();
619
        }
620
621
        return $builder
622
            ->addTransferData(
623
               $eventId,
624
               $eventTimestamp,
625
               $amount,
626
               $currency,
627
               $accountId,
628
               $secondAccountId,
629
               $accountSystem,
630
               $amountConverted,
631
               $method,
632
               $operation,
633
               $secondEmail,
634
               $secondPhone,
635
               $secondBirthDate,
636
               $secondFirstname,
637
               $secondLastname,
638
               $secondFullname,
639
               $secondState,
640
               $secondCity,
641
               $secondAddress,
642
               $secondZip,
643
               $secondGender,
644
               $secondCountry,
645
               $iban,
646
               $secondIban,
647
               $bic,
648
               $source
649
            )
650
            ->addUserData(
651
                $email,
652
                $userId,
653
                $phone,
654
                null,
655
                $firstname,
656
                $lastname,
657
                $gender,
658
                null,
659
                $country,
660
                null,
661
                null,
662
                null,
663
                null,
664
                null,
665
                null,
666
                null,
667
                $birthDate,
668
                $fullname,
669
                $state,
670
                $city,
671
                $address,
672
                $zip,
673
                null
674
            )
675
            ->addProductData($productQuantity, $productName, $productDescription);
676
    }
677
678
    /**
679
     * Returns builder for kyc_profile request
680
     *
681
     * @param string $sequenceId
682
     * @param string $eventId
683
     * @param string $userId
684
     * @param int|null $eventTimestamp
685
     * @param string|null $groupId
686
     * @param string|null $status
687
     * @param string|null $code
688
     * @param string|null $reason
689
     * @param string|null $providerResult
690
     * @param string|null $providerCode
691
     * @param string|null $providerReason
692
     * @param string|null $profileId
693
     * @param string|null $profileType
694
     * @param string|null $profileSubType
695
     * @param string|null $firstName
696
     * @param string|null $lastName
697
     * @param string|null $fullName
698
     * @param string|null $industry
699
     * @param string|null $websiteUrl
700
     * @param string|null $description
701
     * @param int|null $birthDate
702
     * @param int|null $regDate
703
     * @param string|null $regNumber
704
     * @param string|null $vatNumber
705
     * @param string|null $email
706
     * @param bool|null $emailConfirmed
707
     * @param string|null $phone
708
     * @param bool|null $phoneConfirmed
709
     * @param string|null $country
710
     * @param string|null $state
711
     * @param string|null $city
712
     * @param string|null $address
713
     * @param string|null $zip
714
     * @param string|null $secondCountry
715
     * @param string|null $secondState
716
     * @param string|null $secondCity
717
     * @param string|null $secondAddress
718
     * @param string|null $secondZip
719
     * @param string|null $relatedProfiles
720
     *
721
     * @return Builder
722
     */
723
    public static function kycProfileEvent(
724
        $sequenceId,
725
        $eventId,
726
        $userId,
727
        $eventTimestamp = null,
728
        $groupId = null,
729
        $status = null,
730
        $code = null,
731
        $reason = null,
732
        $providerResult = null,
733
        $providerCode = null,
734
        $providerReason = null,
735
        $profileId = null,
736
        $profileType = null,
737
        $profileSubType = null,
738
        $firstName = null,
739
        $lastName = null,
740
        $fullName = null,
741
        $industry = null,
742
        $websiteUrl = null,
743
        $description = null,
744
        $birthDate = null,
745
        $regDate = null,
746
        $regNumber = null,
747
        $vatNumber = null,
748
        $email = null,
749
        $emailConfirmed = null,
750
        $phone = null,
751
        $phoneConfirmed = null,
752
        $country = null,
753
        $state = null,
754
        $city = null,
755
        $address = null,
756
        $zip = null,
757
        $secondCountry = null,
758
        $secondState = null,
759
        $secondCity = null,
760
        $secondAddress = null,
761
        $secondZip = null,
762
        $relatedProfiles = null
763
    ) {
764
        $builder = new self('kyc_profile', $sequenceId);
765
        if ($eventTimestamp === null) {
766
            $eventTimestamp = time();
767
        }
768
        return $builder
769
            ->addKycData(
770
                $eventId,
771
                $eventTimestamp,
772
                $groupId,
773
                $status,
774
                $code,
775
                $reason,
776
                $providerResult,
777
                $providerCode,
778
                $providerReason,
779
                $profileId,
780
                $profileType,
781
                $profileSubType,
782
                $industry,
783
                $description,
784
                $regDate,
785
                $regNumber,
786
                $vatNumber,
787
                $secondCountry,
788
                $secondState,
789
                $secondCity,
790
                $secondAddress,
791
                $secondZip,
792
                $relatedProfiles
793
            )
794
            ->addUserData(
795
                $email,
796
                $userId,
797
                $phone,
798
                null,
799
                $firstName,
800
                $lastName,
801
                null,
802
                null,
803
                $country,
804
                null,
805
                null,
806
                null,
807
                null,
808
                $emailConfirmed,
809
                $phoneConfirmed,
810
                null,
811
                $birthDate,
812
                $fullName,
813
                $state,
814
                $city,
815
                $address,
816
                $zip,
817
                null
818
            )
819
            ->addWebsiteData($websiteUrl);
820
    }
821
822
    /**
823
     * Returns builder for kyc_submit request
824
     *
825
     * @param string $sequenceId
826
     * @param string $eventId
827
     * @param string $userId
828
     * @param int|null $eventTimestamp
829
     * @param string|null $groupId
830
     * @param string|null $status
831
     * @param string|null $code
832
     * @param string|null $reason
833
     * @param string|null $providerResult
834
     * @param string|null $providerCode
835
     * @param string|null $providerReason
836
     *
837
     * @return Builder
838
     */
839
    public static function kycSubmitEvent(
840
        $sequenceId,
841
        $eventId,
842
        $userId,
843
        $eventTimestamp = null,
844
        $groupId = null,
845
        $status = null,
846
        $code = null,
847
        $reason = null,
848
        $providerResult = null,
849
        $providerCode = null,
850
        $providerReason = null
851
    ) {
852
        $builder = new self('kyc_submit', $sequenceId);
853
        if ($eventTimestamp === null) {
854
            $eventTimestamp = time();
855
        }
856
        return $builder
857
            ->addKycData(
858
                $eventId,
859
                $eventTimestamp,
860
                $groupId,
861
                $status,
862
                $code,
863
                $reason,
864
                $providerResult,
865
                $providerCode,
866
                $providerReason
867
            )
868
            ->addUserData(
869
                null,
870
                $userId
871
            );
872
    }
873
874
    /**
875
     * Returns builder for order_item request
876
     *
877
     * @param string $sequenceId
878
     * @param float $amount
879
     * @param string $currency
880
     * @param string $eventId
881
     * @param int $eventTimestamp
882
     * @param string $orderType
883
     * @param string|null $transactionId
884
     * @param string|null $groupId
885
     * @param string|null $affiliateId
886
     * @param float|null $amountConverted
887
     * @param string|null $campaign
888
     * @param string|null $carrier
889
     * @param string|null $carrierShippingId
890
     * @param string|null $carrierUrl
891
     * @param string|null $carrierPhone
892
     * @param int|null $couponStartDate
893
     * @param int|null $couponEndDate
894
     * @param string|null $couponId
895
     * @param string|null $couponName
896
     * @param string|null $customerComment
897
     * @param int|null $deliveryEstimate
898
     * @param string|null $email
899
     * @param string|null $firstName
900
     * @param string|null $lastName
901
     * @param string|null $phone
902
     * @param string|null $productDescription
903
     * @param string|null $productName
904
     * @param int|null $productQuantity
905
     * @param string|null $shippingAddress
906
     * @param string|null $shippingCity
907
     * @param string|null $shippingCountry
908
     * @param string|null $shippingCurrency
909
     * @param float|null $shippingFee
910
     * @param float|null $shippingFeeConverted
911
     * @param string|null $shippingState
912
     * @param string|null $shippingZip
913
     * @param string|null $socialType
914
     * @param string|null $source
915
     * @param string|null $sourceFeeCurrency
916
     * @param float|null $sourceFee
917
     * @param float|null $sourceFeeConverted
918
     * @param string|null $taxCurrency
919
     * @param float|null $taxFee
920
     * @param float|null $taxFeeConverted
921
     * @param string|null $userMerchantId
922
     * @param string|null $websiteUrl
923
     * @param string|null $productUrl
924
     * @param string|null $productImageUrl
925
     * @return Builder
926
     */
927
    public static function orderItemEvent(
928
        $sequenceId,
929
        $amount,
930
        $currency,
931
        $eventId,
932
        $eventTimestamp,
933
        $orderType,
934
        $transactionId = null,
935
        $groupId = null,
936
        $affiliateId = null,
937
        $amountConverted = null,
938
        $campaign = null,
939
        $carrier = null,
940
        $carrierShippingId = null,
941
        $carrierUrl = null,
942
        $carrierPhone = null,
943
        $couponStartDate = null,
944
        $couponEndDate = null,
945
        $couponId = null,
946
        $couponName = null,
947
        $customerComment = null,
948
        $deliveryEstimate = null,
949
        $email = null,
950
        $firstName = null,
951
        $lastName = null,
952
        $phone = null,
953
        $productDescription = null,
954
        $productName = null,
955
        $productQuantity = null,
956
        $shippingAddress = null,
957
        $shippingCity = null,
958
        $shippingCountry = null,
959
        $shippingCurrency = null,
960
        $shippingFee = null,
961
        $shippingFeeConverted = null,
962
        $shippingState = null,
963
        $shippingZip = null,
964
        $socialType = null,
965
        $source = null,
966
        $sourceFeeCurrency = null,
967
        $sourceFee = null,
968
        $sourceFeeConverted = null,
969
        $taxCurrency = null,
970
        $taxFee = null,
971
        $taxFeeConverted = null,
972
        $userMerchantId = null,
973
        $websiteUrl = null,
974
        $productUrl = null,
975
        $productImageUrl = null
976
    ) {
977
        $envelopeType = 'order_item';
978
        $builder = new self($envelopeType, $sequenceId);
979
        if ($eventTimestamp === null) {
980
            $eventTimestamp = time();
981
        }
982
        return $builder
983
            ->addOrderData(
984
                $envelopeType,
985
                $amount,
986
                $currency,
987
                $eventId,
988
                $eventTimestamp,
989
                $transactionId,
990
                $groupId,
991
                null,
992
                $orderType,
993
                $amountConverted,
994
                $campaign,
995
                $carrier,
996
                $carrierShippingId,
997
                $carrierUrl,
998
                $carrierPhone,
999
                $couponStartDate,
1000
                $couponEndDate,
1001
                $couponId,
1002
                $couponName,
1003
                $customerComment,
1004
                $deliveryEstimate,
1005
                $shippingAddress,
1006
                $shippingCity,
1007
                $shippingCountry,
1008
                $shippingCurrency,
1009
                $shippingFee,
1010
                $shippingFeeConverted,
1011
                $shippingState,
1012
                $shippingZip,
1013
                $source,
1014
                $sourceFee,
1015
                $sourceFeeCurrency,
1016
                $sourceFeeConverted,
1017
                $taxCurrency,
1018
                $taxFee,
1019
                $taxFeeConverted,
1020
                $productUrl,
1021
                $productImageUrl
1022
            )
1023
            ->addUserData(
1024
                $email,
1025
                $userMerchantId,
1026
                $phone,
1027
                '',
1028
                $firstName,
1029
                $lastName,
1030
                '',
1031
                0,
1032
                '',
1033
                $socialType
1034
            )
1035
            -> addProductData(
1036
                $productQuantity,
1037
                $productName,
1038
                $productDescription
1039
            )
1040
            ->addWebsiteData(
1041
                $websiteUrl,
1042
                null,
1043
                $affiliateId
1044
            );
1045
    }
1046
1047
    /**
1048
     * Returns builder for order_submit request
1049
     *
1050
     * @param string $sequenceId
1051
     * @param float $amount
1052
     * @param string $currency
1053
     * @param string $eventId
1054
     * @param int $eventTimestamp
1055
     * @param int $itemsQuantity
1056
     * @param string|null $transactionId
1057
     * @param string|null $groupId
1058
     * @param string|null $affiliateId
1059
     * @param float|null $amountConverted
1060
     * @param string|null $campaign
1061
     * @param string|null $carrier
1062
     * @param string|null $carrierShippingId
1063
     * @param string|null $carrierUrl
1064
     * @param string|null $carrierPhone
1065
     * @param int|null $couponStartDate
1066
     * @param int|null $couponEndDate
1067
     * @param string|null $couponId
1068
     * @param string|null $couponName
1069
     * @param string|null $customerComment
1070
     * @param int|null $deliveryEstimate
1071
     * @param string|null $email
1072
     * @param string|null $firstName
1073
     * @param string|null $lastName
1074
     * @param string|null $phone
1075
     * @param string|null $shippingAddress
1076
     * @param string|null $shippingCity
1077
     * @param string|null $shippingCountry
1078
     * @param string|null $shippingCurrency
1079
     * @param float|null $shippingFee
1080
     * @param float|null $shippingFeeConverted
1081
     * @param string|null $shippingState
1082
     * @param string|null $shippingZip
1083
     * @param string|null $socialType
1084
     * @param string|null $source
1085
     * @param string|null $sourceFeeCurrency
1086
     * @param float|null $sourceFee
1087
     * @param float|null $sourceFeeConverted
1088
     * @param string|null $taxCurrency
1089
     * @param float|null $taxFee
1090
     * @param float|null $taxFeeConverted
1091
     * @param string|null $userMerchantId
1092
     * @param string|null $websiteUrl
1093
     * @param string|null $productUrl
1094
     * @param string|null $productImageUrl
1095
     * @return Builder
1096
     */
1097
    public static function orderSubmitEvent(
1098
        $sequenceId,
1099
        $amount,
1100
        $currency,
1101
        $eventId,
1102
        $eventTimestamp,
1103
        $itemsQuantity,
1104
        $transactionId = null,
1105
        $groupId = null,
1106
        $affiliateId = null,
1107
        $amountConverted = null,
1108
        $campaign = null,
1109
        $carrier = null,
1110
        $carrierShippingId = null,
1111
        $carrierUrl = null,
1112
        $carrierPhone = null,
1113
        $couponStartDate = null,
1114
        $couponEndDate = null,
1115
        $couponId = null,
1116
        $couponName = null,
1117
        $customerComment = null,
1118
        $deliveryEstimate = null,
1119
        $email = null,
1120
        $firstName = null,
1121
        $lastName = null,
1122
        $phone = null,
1123
        $shippingAddress = null,
1124
        $shippingCity = null,
1125
        $shippingCountry = null,
1126
        $shippingCurrency = null,
1127
        $shippingFee = null,
1128
        $shippingFeeConverted = null,
1129
        $shippingState = null,
1130
        $shippingZip = null,
1131
        $socialType = null,
1132
        $source = null,
1133
        $sourceFeeCurrency = null,
1134
        $sourceFee = null,
1135
        $sourceFeeConverted = null,
1136
        $taxCurrency = null,
1137
        $taxFee = null,
1138
        $taxFeeConverted = null,
1139
        $userMerchantId = null,
1140
        $websiteUrl = null,
1141
        $productUrl = null,
1142
        $productImageUrl = null
1143
    ) {
1144
        $envelopeType = 'order_submit';
1145
        $builder = new self($envelopeType, $sequenceId);
1146
        if ($eventTimestamp === null) {
1147
            $eventTimestamp = time();
1148
        }
1149
        return $builder
1150
            ->addOrderData(
1151
                $envelopeType,
1152
                $amount,
1153
                $currency,
1154
                $eventId,
1155
                $eventTimestamp,
1156
                $transactionId,
1157
                $groupId,
1158
                $itemsQuantity,
1159
                null,
1160
                $amountConverted,
1161
                $campaign,
1162
                $carrier,
1163
                $carrierShippingId,
1164
                $carrierUrl,
1165
                $carrierPhone,
1166
                $couponStartDate,
1167
                $couponEndDate,
1168
                $couponId,
1169
                $couponName,
1170
                $customerComment,
1171
                $deliveryEstimate,
1172
                $shippingAddress,
1173
                $shippingCity,
1174
                $shippingCountry,
1175
                $shippingCurrency,
1176
                $shippingFee,
1177
                $shippingFeeConverted,
1178
                $shippingState,
1179
                $shippingZip,
1180
                $source,
1181
                $sourceFee,
1182
                $sourceFeeCurrency,
1183
                $sourceFeeConverted,
1184
                $taxCurrency,
1185
                $taxFee,
1186
                $taxFeeConverted,
1187
                $productUrl,
1188
                $productImageUrl
1189
            )
1190
            ->addUserData(
1191
                $email,
1192
                $userMerchantId,
1193
                $phone,
1194
                '',
1195
                $firstName,
1196
                $lastName,
1197
                '',
1198
                0,
1199
                '',
1200
                $socialType
1201
            )
1202
            ->addWebsiteData(
1203
                $websiteUrl,
1204
                null,
1205
                $affiliateId
1206
            );
1207
    }
1208
1209
    /**
1210
     * Returns builder for postback request
1211
     *
1212
     * @param int|null $requestId
1213
     * @param string|null $transactionId
1214
     * @param string|null $transactionStatus
1215
     * @param string|null $code
1216
     * @param string|null $reason
1217
     * @param string|null $secure3d
1218
     * @param string|null $avsResult
1219
     * @param string|null $cvvResult
1220
     * @param string|null $pspCode
1221
     * @param string|null $pspReason
1222
     * @param string|null $arn
1223
     * @param string|null $paymentAccountId
1224
     * @return Builder
1225
     */
1226
    public static function postBackEvent(
1227
        $requestId =  null,
1228
        $transactionId = null,
1229
        $transactionStatus = null,
1230
        $code = null,
1231
        $reason = null,
1232
        $secure3d = null,
1233
        $avsResult = null,
1234
        $cvvResult = null,
1235
        $pspCode = null,
1236
        $pspReason = null,
1237
        $arn = null,
1238
        $paymentAccountId = null
1239
    ) {
1240
        $builder = new self('postback', '');
1241
        return $builder->addPostBackData(
1242
            $requestId,
1243
            $transactionId,
1244
            $transactionStatus,
1245
            $code,
1246
            $reason,
1247
            $secure3d,
1248
            $avsResult,
1249
            $cvvResult,
1250
            $pspCode,
1251
            $pspReason,
1252
            $arn,
1253
            $paymentAccountId
1254
       );
1255
    }
1256
1257
    /**
1258
     * Builder constructor.
1259
     *
1260
     * @param string $envelopeType
1261
     * @param string $sequenceId
1262
     */
1263
    public function __construct($envelopeType, $sequenceId)
1264
    {
1265
        if (!is_string($envelopeType)) {
1266
            throw new \InvalidArgumentException('Envelope type must be string');
1267
        }
1268
        if (!is_string($sequenceId)) {
1269
            throw new \InvalidArgumentException('Sequence ID must be string');
1270
        }
1271
1272
        $this->type = $envelopeType;
1273
        $this->sequenceId = $sequenceId;
1274
    }
1275
1276
    /**
1277
     * Returns built envelope
1278
     *
1279
     * @return EnvelopeInterface
1280
     */
1281
    public function build()
1282
    {
1283
        return new Envelope(
1284
            $this->type,
1285
            $this->sequenceId,
1286
            $this->identities,
1287
            array_filter($this->data, function ($data) {
1288
                return $data !== null;
1289
            })
1290
        );
1291
    }
1292
1293
    /**
1294
     * Replaces value in internal array if provided value not empty
1295
     *
1296
     * @param string $key
1297
     * @param string|int|float|bool|null $value
1298
     */
1299
    private function replace($key, $value)
1300
    {
1301
        if ($value !== null && $value !== '' && $value !== 0 && $value !== 0.0) {
1302
            $this->data[$key] = $value;
1303
        }
1304
    }
1305
1306
    /**
1307
     * Adds identity node
1308
     *
1309
     * @param IdentityNodeInterface $identity
1310
     *
1311
     * @return $this
1312
     */
1313
    public function addIdentity(IdentityNodeInterface $identity)
1314
    {
1315
        $this->identities[] = $identity;
1316
        return $this;
1317
    }
1318
1319
    /**
1320
     * Provides website URL to envelope
1321
     *
1322
     * @param string|null $websiteUrl
1323
     * @param string|null $traffic_source
1324
     * @param string|null $affiliate_id
1325
     * @param string|null $campaign
1326
     *
1327
     * @return $this
1328
     */
1329
    public function addWebsiteData($websiteUrl = null, $traffic_source = null, $affiliate_id = null, $campaign = null)
1330
    {
1331
        if ($websiteUrl !== null && !is_string($websiteUrl)) {
1332
            throw new \InvalidArgumentException('Website URL must be string');
1333
        }
1334
        if ($traffic_source !== null && !is_string($traffic_source)) {
1335
            throw new \InvalidArgumentException('Traffic source must be string');
1336
        }
1337
        if ($affiliate_id !== null && !is_string($affiliate_id)) {
1338
            throw new \InvalidArgumentException('Affiliate ID must be string');
1339
        }
1340
        if ($campaign !== null && !is_string($campaign)) {
1341
            throw new \InvalidArgumentException('Campaign must be string');
1342
        }
1343
1344
        $this->replace('website_url', $websiteUrl);
1345
        $this->replace('traffic_source', $traffic_source);
1346
        $this->replace('affiliate_id', $affiliate_id);
1347
        $this->replace('campaign', $campaign);
1348
        return $this;
1349
    }
1350
1351
    /**
1352
     * Provides IP information for envelope
1353
     *
1354
     * @param string|null $ip User's IP address
1355
     * @param string|null $realIp User's real IP address, if available
1356
     * @param string|null $merchantIp Your website's IP address
1357
     *
1358
     * @return $this
1359
     */
1360
    public function addIpData($ip = '', $realIp = '', $merchantIp = '')
1361
    {
1362
        if ($ip !== null && !is_string($ip)) {
1363
            throw new \InvalidArgumentException('IP must be string');
1364
        }
1365
        if ($realIp !== null && !is_string($realIp)) {
1366
            throw new \InvalidArgumentException('Real IP must be string');
1367
        }
1368
        if ($merchantIp !== null && !is_string($merchantIp)) {
1369
            throw new \InvalidArgumentException('Merchant IP must be string');
1370
        }
1371
1372
        $this->replace('ip', $ip);
1373
        $this->replace('real_ip', $realIp);
1374
        $this->replace('merchant_ip', $merchantIp);
1375
1376
        return $this;
1377
    }
1378
1379
    /**
1380
     * Provides browser information for envelope
1381
     *
1382
     * @param string|null $deviceFingerprint
1383
     * @param string|null $userAgent
1384
     * @param string|null $cpuClass
1385
     * @param string|null $screenOrientation
1386
     * @param string|null $screenResolution
1387
     * @param string|null $os
1388
     * @param int|null $timezoneOffset
1389
     * @param string|null $languages
1390
     * @param string|null $language
1391
     * @param string|null $languageBrowser
1392
     * @param string|null $languageUser
1393
     * @param string|null $languageSystem
1394
     * @param bool|null $cookieEnabled
1395
     * @param bool|null $doNotTrack
1396
     * @param bool|null $ajaxValidation
1397
     * @param string|null $deviceId
1398
     * @param string|null $ipList
1399
     * @param string|null $plugins
1400
     * @param string|null $refererUrl
1401
     * @param string|null $originUrl
1402
     * @param string|null $clientResolution
1403
     * @return $this
1404
     */
1405
    public function addBrowserData(
1406
        $deviceFingerprint = '',
1407
        $userAgent = '',
1408
        $cpuClass = '',
1409
        $screenOrientation = '',
1410
        $screenResolution = '',
1411
        $os = '',
1412
        $timezoneOffset = null,
1413
        $languages = '',
1414
        $language = '',
1415
        $languageBrowser = '',
1416
        $languageUser = '',
1417
        $languageSystem = '',
1418
        $cookieEnabled = null,
1419
        $doNotTrack = null,
1420
        $ajaxValidation = null,
1421
        $deviceId = '',
1422
        $ipList = null,
1423
        $plugins = null,
1424
        $refererUrl = null,
1425
        $originUrl = null,
1426
        $clientResolution = null
1427
    ) {
1428
        if ($deviceFingerprint !== null && !is_string($deviceFingerprint)) {
1429
            throw new \InvalidArgumentException('Device fingerprint must be string');
1430
        }
1431
        if ($userAgent !== null && !is_string($userAgent)) {
1432
            throw new \InvalidArgumentException('User agent must be string');
1433
        }
1434
        if ($cpuClass !== null && !is_string($cpuClass)) {
1435
            throw new \InvalidArgumentException('CPU class must be string');
1436
        }
1437
        if ($screenOrientation !== null && !is_string($screenOrientation)) {
1438
            throw new \InvalidArgumentException('Screen orientation must be string');
1439
        }
1440
        if ($screenResolution !== null && !is_string($screenResolution)) {
1441
            throw new \InvalidArgumentException('Screen resolution must be string');
1442
        }
1443
        if ($os !== null && !is_string($os)) {
1444
            throw new \InvalidArgumentException('OS must be string');
1445
        }
1446
        if ($timezoneOffset !== null && $timezoneOffset !== null && !is_int($timezoneOffset)) {
1447
            throw new \InvalidArgumentException('Timezone offset must be integer or null');
1448
        }
1449
        if ($languages !== null && !is_string($languages)) {
1450
            throw new \InvalidArgumentException('Languages must be string');
1451
        }
1452
        if ($language !== null && !is_string($language)) {
1453
            throw new \InvalidArgumentException('Language must be string');
1454
        }
1455
        if ($languageBrowser !== null && !is_string($languageBrowser)) {
1456
            throw new \InvalidArgumentException('Browser language must be string');
1457
        }
1458
        if ($languageUser !== null && !is_string($languageUser)) {
1459
            throw new \InvalidArgumentException('User language must be string');
1460
        }
1461
        if ($languageSystem !== null && !is_string($languageSystem)) {
1462
            throw new \InvalidArgumentException('System language must be string');
1463
        }
1464
        if ($cookieEnabled !== null && !is_bool($cookieEnabled)) {
1465
            throw new \InvalidArgumentException('Cookie enabled flag must be boolean');
1466
        }
1467
        if ($doNotTrack !== null && !is_bool($doNotTrack)) {
1468
            throw new \InvalidArgumentException('DNT flag must be boolean');
1469
        }
1470
        if ($ajaxValidation !== null && !is_bool($ajaxValidation)) {
1471
            throw new \InvalidArgumentException('AJAX validation flag must be boolean');
1472
        }
1473
        if ($deviceId !== null && !is_string($deviceId)) {
1474
            throw new \InvalidArgumentException('Device id must be string');
1475
        }
1476
        if ($ipList !== null && !is_string($ipList)) {
1477
            throw new \InvalidArgumentException('Ip list must be string');
1478
        }
1479
        if ($plugins !== null && !is_string($plugins)) {
1480
            throw new \InvalidArgumentException('Plugins must be string');
1481
        }
1482
        if ($refererUrl !== null && !is_string($refererUrl)) {
1483
            throw new \InvalidArgumentException('Referer url must be string');
1484
        }
1485
        if ($originUrl !== null && !is_string($originUrl)) {
1486
            throw new \InvalidArgumentException('Origin url must be string');
1487
        }
1488
        if ($clientResolution !== null && !is_string($clientResolution)) {
1489
            throw new \InvalidArgumentException('Client resolution must be string');
1490
        }
1491
1492
        $this->replace('device_fingerprint', $deviceFingerprint);
1493
        $this->replace('user_agent', $userAgent);
1494
        $this->replace('cpu_class', $cpuClass);
1495
        $this->replace('screen_orientation', $screenOrientation);
1496
        $this->replace('screen_resolution', $screenResolution);
1497
        $this->replace('os', $os);
1498
        $this->replace('timezone_offset', $timezoneOffset);
1499
        $this->replace('languages', $languages);
1500
        $this->replace('language', $language);
1501
        $this->replace('language_browser', $languageBrowser);
1502
        $this->replace('language_system', $languageSystem);
1503
        $this->replace('language_user', $languageUser);
1504
        $this->replace('cookie_enabled', $cookieEnabled);
1505
        $this->replace('do_not_track', $doNotTrack);
1506
        $this->replace('ajax_validation', $ajaxValidation);
1507
        $this->replace('device_id', $deviceId);
1508
        $this->replace('local_ip_list', $ipList);
1509
        $this->replace('plugins', $plugins);
1510
        $this->replace('referer_url', $refererUrl);
1511
        $this->replace('origin_url', $originUrl);
1512
        $this->replace('client_resolution', $clientResolution);
1513
1514
        return $this;
1515
    }
1516
1517
    /**
1518
     * Provides user data for envelope
1519
     *
1520
     * @param string|null $email
1521
     * @param string|null $userId
1522
     * @param string|null $phone
1523
     * @param string|null $userName
1524
     * @param string|null $firstName
1525
     * @param string|null $lastName
1526
     * @param string|null $gender
1527
     * @param int|null $age
1528
     * @param string|null $country
1529
     * @param string|null $socialType
1530
     * @param int|null $registrationTimestamp
1531
     * @param int|null $loginTimeStamp
1532
     * @param int|null $confirmationTimeStamp
1533
     * @param bool|null $emailConfirmed
1534
     * @param bool|null $phoneConfirmed
1535
     * @param bool|null $loginFailed
1536
     * @param int|null $birthDate
1537
     * @param string|null $fullname
1538
     * @param string|null $state
1539
     * @param string|null $city
1540
     * @param string|null $address
1541
     * @param string|null $zip
1542
     * @param string|null $password
1543
     *
1544
     * @return $this
1545
     */
1546
    public function addUserData(
1547
        $email = '',
1548
        $userId = '',
1549
        $phone = '',
1550
        $userName = '',
1551
        $firstName = '',
1552
        $lastName = '',
1553
        $gender = '',
1554
        $age = 0,
1555
        $country = '',
1556
        $socialType = '',
1557
        $registrationTimestamp = 0,
1558
        $loginTimeStamp = 0,
1559
        $confirmationTimeStamp = 0,
1560
        $emailConfirmed = null,
1561
        $phoneConfirmed = null,
1562
        $loginFailed = null,
1563
        $birthDate = null,
1564
        $fullname = null,
1565
        $state = null,
1566
        $city = null,
1567
        $address = null,
1568
        $zip = null,
1569
        $password = ''
1570
    )
1571
    {
1572
        if ($userName !== null && !is_string($userName)) {
1573
            throw new \InvalidArgumentException('User name must be string');
1574
        }
1575
        if ($password !== null && !is_string($password)) {
1576
            throw new \InvalidArgumentException('Password must be string');
1577
        }
1578
        if ($gender !== null && !is_string($gender)) {
1579
            throw new \InvalidArgumentException('Gender must be string');
1580
        }
1581
        if ($age !== null && !is_int($age)) {
1582
            throw new \InvalidArgumentException('Age must be integer');
1583
        }
1584
        if ($socialType !== null && !is_string($socialType)) {
1585
            throw new \InvalidArgumentException('Social type must be string');
1586
        }
1587
        if ($registrationTimestamp !== null && !is_int($registrationTimestamp)) {
1588
            throw new \InvalidArgumentException('Registration timestamp must be integer');
1589
        }
1590
        if ($loginTimeStamp !== null && !is_int($loginTimeStamp)) {
1591
            throw new \InvalidArgumentException('Login timestamp must be integer');
1592
        }
1593
        if ($confirmationTimeStamp !== null && !is_int($confirmationTimeStamp)) {
1594
            throw new \InvalidArgumentException('Confirmation timestamp must be integer');
1595
        }
1596
        if ($birthDate !== null && !is_int($birthDate)) {
1597
            throw new \InvalidArgumentException('Birthdate timestamp must be integer');
1598
        }
1599
        if ($emailConfirmed !== null && !is_bool($emailConfirmed)) {
1600
            throw new \InvalidArgumentException('Email confirmed flag must be boolean');
1601
        }
1602
        if ($phoneConfirmed !== null && !is_bool($phoneConfirmed)) {
1603
            throw new \InvalidArgumentException('Phone confirmed flag must be boolean');
1604
        }
1605
        if ($loginFailed !== null && !is_bool($loginFailed)) {
1606
            throw new \InvalidArgumentException('Login failed flag must be boolean');
1607
        }
1608
        if ($fullname !== null && !is_string($fullname)) {
1609
            throw new \InvalidArgumentException('Fullname must be string');
1610
        }
1611
        if ($state !== null && !is_string($state)) {
1612
            throw new \InvalidArgumentException('State must be string');
1613
        }
1614
        if ($city !== null && !is_string($city)) {
1615
            throw new \InvalidArgumentException('City must be string');
1616
        }
1617
        if ($address !== null && !is_string($address)) {
1618
            throw new \InvalidArgumentException('Address must be string');
1619
        }
1620
        if ($zip !== null && !is_string($zip)) {
1621
            throw new \InvalidArgumentException('Zip must be string');
1622
        }
1623
1624
        $this->addShortUserData($email, $userId, $phone, $firstName, $lastName, $country);
1625
1626
        $this->replace('user_name', $userName);
1627
        $this->replace('gender', $gender);
1628
        $this->replace('age', $age);
1629
        $this->replace('social_type', $socialType);
1630
        $this->replace('registration_timestamp', $registrationTimestamp);
1631
        $this->replace('login_timestamp', $loginTimeStamp);
1632
        $this->replace('confirmation_timestamp', $confirmationTimeStamp);
1633
        $this->replace('email_confirmed', $emailConfirmed);
1634
        $this->replace('phone_confirmed', $phoneConfirmed);
1635
        $this->replace('login_failed', $loginFailed);
1636
        $this->replace('birth_date', $birthDate);
1637
        $this->replace('fullname', $fullname);
1638
        $this->replace('state', $state);
1639
        $this->replace('city', $city);
1640
        $this->replace('address', $address);
1641
        $this->replace('zip', $zip);
1642
        $this->replace('password', $password);
1643
1644
        return $this;
1645
    }
1646
1647
    /**
1648
     * Provides user data for envelope
1649
     *
1650
     * @param string|null $email
1651
     * @param string|null $userId
1652
     * @param string|null $phone
1653
     * @param string|null $firstName
1654
     * @param string|null $lastName
1655
     * @param string|null $country
1656
     *
1657
     * @return $this
1658
     */
1659
    public function addShortUserData(
1660
        $email = '',
1661
        $userId = '',
1662
        $phone = '',
1663
        $firstName = '',
1664
        $lastName = '',
1665
        $country = ''
1666
    ) {
1667
        if ($email !== null && !is_string($email)) {
1668
            throw new \InvalidArgumentException('Email must be string');
1669
        }
1670
        if (is_int($userId)) {
1671
            $userId = strval($userId);
1672
        }
1673
        if ($userId !== null && !is_string($userId)) {
1674
            throw new \InvalidArgumentException('UserId must be string or integer');
1675
        }
1676
        if ($phone !== null && !is_string($phone)) {
1677
            throw new \InvalidArgumentException('Phone must be string');
1678
        }
1679
        if ($firstName !== null && !is_string($firstName)) {
1680
            throw new \InvalidArgumentException('First name must be string');
1681
        }
1682
        if ($lastName !== null && !is_string($lastName)) {
1683
            throw new \InvalidArgumentException('Last name must be string');
1684
        }
1685
        if ($country !== null && !is_string($country)) {
1686
            throw new \InvalidArgumentException('Country must be string');
1687
        }
1688
1689
        $this->replace('email', $email);
1690
        $this->replace('user_merchant_id', $userId);
1691
        $this->replace('phone', $phone);
1692
        $this->replace('firstname', $firstName);
1693
        $this->replace('lastname', $lastName);
1694
        $this->replace('country', $country);
1695
1696
        return $this;
1697
    }
1698
1699
    /**
1700
     * Provides credit card data to envelope
1701
     *
1702
     * @param string|null $transactionId
1703
     * @param string|null $transactionSource
1704
     * @param string|null $transactionType
1705
     * @param string|null $transactionMode
1706
     * @param string|null $transactionTimestamp
1707
     * @param string|null $transactionCurrency
1708
     * @param string|null $transactionAmount
1709
     * @param float|null $amountConverted
1710
     * @param string|null $paymentMethod
1711
     * @param string|null $paymentSystem
1712
     * @param string|null $paymentMidName
1713
     * @param string|null $paymentAccountId
1714
     *
1715
     * @return $this
1716
     */
1717
    public function addCCTransactionData(
1718
        $transactionId,
1719
        $transactionSource,
1720
        $transactionType,
1721
        $transactionMode,
1722
        $transactionTimestamp,
1723
        $transactionCurrency,
1724
        $transactionAmount,
1725
        $amountConverted = null,
1726
        $paymentMethod = null,
1727
        $paymentSystem = null,
1728
        $paymentMidName = null,
1729
        $paymentAccountId = null
1730
    ) {
1731
        if ($transactionId !== null && !is_string($transactionId)) {
1732
            throw new \InvalidArgumentException('Transaction ID must be string');
1733
        }
1734
        if ($transactionSource !== null && !is_string($transactionSource)) {
1735
            throw new \InvalidArgumentException('Transaction source must be string');
1736
        }
1737
        if ($transactionType !== null && !is_string($transactionType)) {
1738
            throw new \InvalidArgumentException('Transaction type must be string');
1739
        }
1740
        if ($transactionMode !== null && !is_string($transactionMode)) {
1741
            throw new \InvalidArgumentException('Transaction mode must be string');
1742
        }
1743
        if ($transactionTimestamp !== null && !is_int($transactionTimestamp)) {
1744
            throw new \InvalidArgumentException('Transaction timestamp must be integer');
1745
        }
1746
        if ($transactionAmount !== null && !is_int($transactionAmount) && !is_float($transactionAmount)) {
1747
            throw new \InvalidArgumentException('Transaction amount must be float');
1748
        }
1749
        if ($transactionCurrency !== null && !is_string($transactionCurrency)) {
1750
            throw new \InvalidArgumentException('Transaction currency must be string');
1751
        }
1752
        if ($paymentMethod !== null && !is_string($paymentMethod)) {
1753
            throw new \InvalidArgumentException('Payment method must be string');
1754
        }
1755
        if ($paymentSystem !== null && !is_string($paymentSystem)) {
1756
            throw new \InvalidArgumentException('Payment system must be string');
1757
        }
1758
        if ($paymentMidName !== null && !is_string($paymentMidName)) {
1759
            throw new \InvalidArgumentException('Payment MID name must be string');
1760
        }
1761
        if ($paymentAccountId !== null && !is_string($paymentAccountId)) {
1762
            throw new \InvalidArgumentException('Payment account id must be string');
1763
        }
1764 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...
1765
            throw new \InvalidArgumentException('Transaction amount converted must be float');
1766
        }
1767
1768
        $this->replace('transaction_id', $transactionId);
1769
        $this->replace('transaction_source', $transactionSource);
1770
        $this->replace('transaction_type', $transactionType);
1771
        $this->replace('transaction_mode', $transactionMode);
1772
        $this->replace('transaction_timestamp', $transactionTimestamp);
1773
        $this->replace('transaction_amount', floatval($transactionAmount));
1774
        $this->replace('transaction_amount_converted', floatval($amountConverted));
1775
        $this->replace('transaction_currency', $transactionCurrency);
1776
        $this->replace('payment_method', $paymentMethod);
1777
        $this->replace('payment_system', $paymentSystem);
1778
        $this->replace('payment_mid', $paymentMidName);
1779
        $this->replace('payment_account_id', $paymentAccountId);
1780
1781
        return $this;
1782
    }
1783
1784
    /**
1785
     * Provides Card data to envelope
1786
     *
1787
     * @param string|null $cardId
1788
     * @param int|null $cardBin
1789
     * @param string|null $cardLast4
1790
     * @param int|null $expirationMonth
1791
     * @param int|null $expirationYear
1792
     *
1793
     * @return $this
1794
     */
1795
    public function addCardData(
1796
        $cardBin,
1797
        $cardLast4,
1798
        $expirationMonth,
1799
        $expirationYear,
1800
        $cardId = null
1801
    ) {
1802
        if ($cardId !== null && !is_string($cardId)) {
1803
            throw new \InvalidArgumentException('Card ID must be string');
1804
        }
1805
        if ($cardBin !== null && !is_int($cardBin)) {
1806
            throw new \InvalidArgumentException('Card BIN must be integer');
1807
        }
1808
        if ($cardLast4 !== null && !is_string($cardLast4)) {
1809
            throw new \InvalidArgumentException('Card last4  must be string');
1810
        }
1811
        if ($expirationMonth !== null && !is_int($expirationMonth)) {
1812
            throw new \InvalidArgumentException('Expiration month must be integer');
1813
        }
1814
        if ($expirationYear !== null && !is_int($expirationYear)) {
1815
            throw new \InvalidArgumentException('Expiration year must be integer');
1816
        }
1817
1818
        $this->replace('card_id', $cardId);
1819
        $this->replace('card_bin', $cardBin);
1820
        $this->replace('card_last4', $cardLast4);
1821
        $this->replace('expiration_month', $expirationMonth);
1822
        $this->replace('expiration_year', $expirationYear);
1823
1824
        return $this;
1825
    }
1826
1827
    /**
1828
     * Provides billing data to envelope
1829
     *
1830
     * @param string|null $billingFirstName
1831
     * @param string|null $billingLastName
1832
     * @param string|null $billingFullName
1833
     * @param string|null $billingCountry
1834
     * @param string|null $billingState
1835
     * @param string|null $billingCity
1836
     * @param string|null $billingAddress
1837
     * @param string|null $billingZip
1838
     *
1839
     * @return $this
1840
     */
1841
    public function addBillingData(
1842
        $billingFirstName = null,
1843
        $billingLastName = null,
1844
        $billingFullName = null,
1845
        $billingCountry = null,
1846
        $billingState = null,
1847
        $billingCity = null,
1848
        $billingAddress = null,
1849
        $billingZip = null
1850
    ) {
1851
        if ($billingFirstName !== null && !is_string($billingFirstName)) {
1852
            throw new \InvalidArgumentException('Billing first name must be string');
1853
        }
1854
        if ($billingLastName !== null && !is_string($billingLastName)) {
1855
            throw new \InvalidArgumentException('Billing last name must be string');
1856
        }
1857
        if ($billingFullName !== null && !is_string($billingFullName)) {
1858
            throw new \InvalidArgumentException('Billing full name must be string');
1859
        }
1860
        if ($billingCountry !== null && !is_string($billingCountry)) {
1861
            throw new \InvalidArgumentException('Billing country name must be string');
1862
        }
1863
        if ($billingState !== null && !is_string($billingState)) {
1864
            throw new \InvalidArgumentException('Billing state must be string');
1865
        }
1866
        if ($billingCity !== null && !is_string($billingCity)) {
1867
            throw new \InvalidArgumentException('Billing city must be string');
1868
        }
1869
        if ($billingAddress !== null && !is_string($billingAddress)) {
1870
            throw new \InvalidArgumentException('Billing address must be string');
1871
        }
1872
        if ($billingZip !== null && !is_string($billingZip)) {
1873
            throw new \InvalidArgumentException('Billing zip must be string');
1874
        }
1875
1876
        $this->replace('billing_firstname', $billingFirstName);
1877
        $this->replace('billing_lastname', $billingLastName);
1878
        $this->replace('billing_fullname', $billingFullName);
1879
        $this->replace('billing_country', $billingCountry);
1880
        $this->replace('billing_state', $billingState);
1881
        $this->replace('billing_city', $billingCity);
1882
        $this->replace('billing_address', $billingAddress);
1883
        $this->replace('billing_zip', $billingZip);
1884
1885
        return $this;
1886
    }
1887
1888
    /**
1889
     * Provides product information to envelope
1890
     *
1891
     * @param float|null $productQuantity
1892
     * @param string|null $productName
1893
     * @param string|null $productDescription
1894
     *
1895
     * @return $this
1896
     */
1897
    public function addProductData(
1898
        $productQuantity = null,
1899
        $productName = null,
1900
        $productDescription = null
1901
    ) {
1902
        if ($productQuantity !== null && !is_int($productQuantity) && !is_float($productQuantity)) {
1903
            throw new \InvalidArgumentException('Product quantity must be int or float');
1904
        }
1905
        if ($productName !== null && !is_string($productName)) {
1906
            throw new \InvalidArgumentException('Product name must be string');
1907
        }
1908
        if ($productDescription !== null && !is_string($productDescription)) {
1909
            throw new \InvalidArgumentException('Product description must be string');
1910
        }
1911
1912
        $this->replace('product_quantity', $productQuantity);
1913
        $this->replace('product_name', $productName);
1914
        $this->replace('product_description', $productDescription);
1915
1916
        return $this;
1917
    }
1918
1919
    /**
1920
     * Provides payout information to envelope
1921
     *
1922
     * @param string $payoutId
1923
     * @param int $payoutTimestamp
1924
     * @param int|float $payoutAmount
1925
     * @param string $payoutCurrency
1926
     * @param string|null $payoutCardId
1927
     * @param string|null $payoutAccountId
1928
     * @param string|null $payoutMethod
1929
     * @param string|null $payoutSystem
1930
     * @param string|null $payoutMid
1931
     * @param int|float|null $amountConverted
1932
     * @param int|null $payoutCardBin
1933
     * @param string|null $payoutCardLast4
1934
     * @param int|null $payoutExpirationMonth
1935
     * @param int|null $payoutExpirationYear
1936
     *
1937
     * @return $this
1938
     */
1939
    public function addPayoutData(
1940
        $payoutId,
1941
        $payoutTimestamp,
1942
        $payoutAmount,
1943
        $payoutCurrency,
1944
        $payoutCardId =  null,
1945
        $payoutAccountId = null,
1946
        $payoutMethod = null,
1947
        $payoutSystem = null,
1948
        $payoutMid = null,
1949
        $amountConverted = null,
1950
        $payoutCardBin = null,
1951
        $payoutCardLast4 = null,
1952
        $payoutExpirationMonth = null,
1953
        $payoutExpirationYear = null
1954
    ) {
1955
        if (!is_string($payoutId)) {
1956
            throw new \InvalidArgumentException('Payout ID must be string');
1957
        }
1958
        if (!is_int($payoutTimestamp)) {
1959
            throw new \InvalidArgumentException('Payout timestamp must be int');
1960
        }
1961
        if (!is_float($payoutAmount) && !is_int($payoutAmount)) {
1962
            throw new \InvalidArgumentException('Amount must be number');
1963
        }
1964
        if (!is_string($payoutCurrency)) {
1965
            throw new \InvalidArgumentException('Payout currency must be string');
1966
        }
1967
        if ($payoutAccountId !== null && !is_string($payoutAccountId)) {
1968
            throw new \InvalidArgumentException('Account ID must be string');
1969
        }
1970
        if ($payoutCardId !== null && !is_string($payoutCardId)) {
1971
            throw new \InvalidArgumentException('Card ID must be string');
1972
        }
1973
        if ($payoutMethod !== null && !is_string($payoutMethod)) {
1974
            throw new \InvalidArgumentException('Payout method must be string');
1975
        }
1976
        if ($payoutSystem !== null && !is_string($payoutSystem)) {
1977
            throw new \InvalidArgumentException('Payout system must be string');
1978
        }
1979
        if ($payoutMid !== null && !is_string($payoutMid)) {
1980
            throw new \InvalidArgumentException('Payout MID must be string');
1981
        }
1982 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...
1983
            throw new \InvalidArgumentException('Payout converted amount must be number');
1984
        }
1985
        if ($payoutCardBin !== null && !is_int($payoutCardBin)) {
1986
            throw new \InvalidArgumentException('Payout card BIN must be integer');
1987
        }
1988
        if ($payoutCardLast4 !== null && !is_string($payoutCardLast4)) {
1989
            throw new \InvalidArgumentException('Payout last 4 must be string');
1990
        }
1991
        if ($payoutExpirationMonth !== null && !is_int($payoutExpirationMonth)) {
1992
            throw new \InvalidArgumentException('Payout card expiration month must be integer');
1993
        }
1994
        if ($payoutExpirationYear !== null && !is_int($payoutExpirationYear)) {
1995
            throw new \InvalidArgumentException('Payout card expiration year must be integer');
1996
        }
1997
1998
        $this->replace('payout_id', $payoutId);
1999
        $this->replace('payout_timestamp', $payoutTimestamp);
2000
        $this->replace('payout_card_id', $payoutCardId);
2001
        $this->replace('payout_account_id', $payoutAccountId);
2002
        $this->replace('payout_amount', (float) $payoutAmount);
2003
        $this->replace('payout_currency', $payoutCurrency);
2004
        $this->replace('payout_method', $payoutMethod);
2005
        $this->replace('payout_system', $payoutSystem);
2006
        $this->replace('payout_mid', $payoutMid);
2007
        $this->replace('payout_amount_converted', (float) $amountConverted);
2008
        $this->replace('payout_card_bin', $payoutCardBin);
2009
        $this->replace('payout_card_last4', $payoutCardLast4);
2010
        $this->replace('payout_expiration_month', $payoutExpirationMonth);
2011
        $this->replace('payout_expiration_year', $payoutExpirationYear);
2012
2013
        return $this;
2014
    }
2015
2016
    /**
2017
     * Provides install information to envelope
2018
     *
2019
     * @param int $installTimestamp
2020
     *
2021
     * @return $this
2022
     */
2023
    public function addInstallData($installTimestamp)
2024
    {
2025
        if (!is_int($installTimestamp)) {
2026
            throw new \InvalidArgumentException('Install timestamp must be int');
2027
        }
2028
2029
        $this->replace('install_timestamp', $installTimestamp);
2030
2031
        return $this;
2032
    }
2033
2034
    /**
2035
     * Provides refund information to envelope
2036
     *
2037
     * @param string $refundId
2038
     * @param int|float $refundAmount
2039
     * @param string $refundCurrency
2040
     * @param int|null $refundTimestamp
2041
     * @param int|float|null $refundAmountConverted
2042
     * @param string|null $refundSource
2043
     * @param string|null $refundType
2044
     * @param string|null $refundCode
2045
     * @param string|null $refundReason
2046
     * @param string|null $agentId
2047
     * @param string|null $refundMethod
2048
     * @param string|null $refundSystem
2049
     * @param string|null $refundMid
2050
     *
2051
     * @return $this
2052
     */
2053
    public function addRefundData(
2054
        $refundId,
2055
        $refundTimestamp,
2056
        $refundAmount,
2057
        $refundCurrency,
2058
        $refundAmountConverted = null,
2059
        $refundSource = null,
2060
        $refundType = null,
2061
        $refundCode = null,
2062
        $refundReason = null,
2063
        $agentId = null,
2064
        $refundMethod = null,
2065
        $refundSystem = null,
2066
        $refundMid = null
2067
    ) {
2068
        if (!is_string($refundId)) {
2069
            throw new \InvalidArgumentException('Refund ID must be string');
2070
        }
2071
        if (!is_int($refundTimestamp)) {
2072
            throw new \InvalidArgumentException('Refund timestamp must be int');
2073
        }
2074
        if (!is_float($refundAmount) && !is_int($refundAmount)) {
2075
            throw new \InvalidArgumentException('Amount must be number');
2076
        }
2077
        if (!is_string($refundCurrency)) {
2078
            throw new \InvalidArgumentException('Refund currency must be string');
2079
        }
2080
        if ($refundAmountConverted !== null && !is_float($refundAmountConverted) && !is_int($refundAmountConverted)) {
2081
            throw new \InvalidArgumentException('Refund converted amount must be number');
2082
        }
2083
        if ($refundSource !== null && !is_string($refundSource)) {
2084
            throw new \InvalidArgumentException('Refund source must be string');
2085
        }
2086
        if ($refundType !== null && !is_string($refundType)) {
2087
            throw new \InvalidArgumentException('Refund type must be string');
2088
        }
2089
        if ($refundCode !== null && !is_string($refundCode)) {
2090
            throw new \InvalidArgumentException('Refund code must be string');
2091
        }
2092
        if ($refundReason !== null && !is_string($refundReason)) {
2093
            throw new \InvalidArgumentException('Refund reason must be string');
2094
        }
2095
        if ($agentId !== null && !is_string($agentId)) {
2096
            throw new \InvalidArgumentException('Agent id must be string');
2097
        }
2098
        if ($refundMethod !== null && !is_string($refundMethod)) {
2099
            throw new \InvalidArgumentException('Refund method must be string');
2100
        }
2101
        if ($refundSystem !== null && !is_string($refundSystem)) {
2102
            throw new \InvalidArgumentException('Refund system must be string');
2103
        }
2104
        if ($refundMid !== null && !is_string($refundMid)) {
2105
            throw new \InvalidArgumentException('Refund mid must be string');
2106
        }
2107
2108
        $this->replace('refund_id', $refundId);
2109
        $this->replace('refund_timestamp', $refundTimestamp);
2110
        $this->replace('refund_amount', $refundAmount);
2111
        $this->replace('refund_currency', $refundCurrency);
2112
        $this->replace('refund_amount_converted', $refundAmountConverted);
2113
        $this->replace('refund_source', $refundSource);
2114
        $this->replace('refund_type', $refundType);
2115
        $this->replace('refund_code', $refundCode);
2116
        $this->replace('refund_reason', $refundReason);
2117
        $this->replace('agent_id', $agentId);
2118
        $this->replace('refund_method', $refundMethod);
2119
        $this->replace('refund_system', $refundSystem);
2120
        $this->replace('refund_mid', $refundMid);
2121
2122
        return $this;
2123
    }
2124
2125
    /**
2126
     * Provides transfer information to envelope
2127
     *
2128
     * @param string $eventId
2129
     * @param int $eventTimestamp
2130
     * @param float $amount
2131
     * @param string $currency
2132
     * @param string $accountId
2133
     * @param string $secondAccountId
2134
     * @param string $accountSystem
2135
     * @param float|null $amountConverted
2136
     * @param string|null $method
2137
     * @param string|null $operation
2138
     * @param string|null $secondEmail
2139
     * @param string|null $secondPhone
2140
     * @param string|int $secondBirthDate
2141
     * @param string|null $secondFirstname
2142
     * @param string|null $secondLastname
2143
     * @param string|null $secondFullname
2144
     * @param string|null $secondState
2145
     * @param string|null $secondCity
2146
     * @param string|null $secondAddress
2147
     * @param string|null $secondZip
2148
     * @param string|null $secondGender
2149
     * @param string|null $secondCountry
2150
     * @param string|null $iban
2151
     * @param string|null $secondIban
2152
     * @param string|null $bic
2153
     * @param string|null $source
2154
     *
2155
     * @return $this
2156
     */
2157
    public function addTransferData(
2158
        $eventId,
2159
        $eventTimestamp,
2160
        $amount,
2161
        $currency,
2162
        $accountId,
2163
        $secondAccountId,
2164
        $accountSystem,
2165
        $amountConverted = null,
2166
        $method = null,
2167
        $operation = null,
2168
        $secondEmail = null,
2169
        $secondPhone = null,
2170
        $secondBirthDate = null,
2171
        $secondFirstname = null,
2172
        $secondLastname = null,
2173
        $secondFullname = null,
2174
        $secondState = null,
2175
        $secondCity = null,
2176
        $secondAddress = null,
2177
        $secondZip = null,
2178
        $secondGender = null,
2179
        $secondCountry = null,
2180
        $iban = null,
2181
        $secondIban = null,
2182
        $bic = null,
2183
        $source = null
2184
    ) {
2185
        if (!is_string($eventId)) {
2186
            throw new \InvalidArgumentException('Event ID must be string');
2187
        }
2188
        if (!is_int($eventTimestamp)) {
2189
            throw new \InvalidArgumentException('Event timestamp must be int');
2190
        }
2191
        if (!is_int($amount) && !is_float($amount)) {
2192
            throw new \InvalidArgumentException('Amount must be number');
2193
        }
2194
        if (!is_string($currency)) {
2195
            throw new \InvalidArgumentException('Currency must be string');
2196
        }
2197
        if (!is_string($accountId)) {
2198
            throw new \InvalidArgumentException('Account id must be string');
2199
        }
2200
        if (!is_string($secondAccountId)) {
2201
            throw new \InvalidArgumentException('Second account id must be string');
2202
        }
2203
        if (!is_string($accountSystem)) {
2204
            throw new \InvalidArgumentException('Account system must be string');
2205
        }
2206 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...
2207
            throw new \InvalidArgumentException('Amount converted must be number');
2208
        }
2209
        if ($method !== null && !is_string($method)) {
2210
            throw new \InvalidArgumentException('Method must be string');
2211
        }
2212
        if ($operation !== null && !is_string($operation)) {
2213
            throw new \InvalidArgumentException('Operation must be string');
2214
        }
2215
        if ($secondPhone !== null && !is_string($secondPhone)) {
2216
            throw new \InvalidArgumentException('Second phone must be string');
2217
        }
2218
        if ($secondEmail !== null && !is_string($secondEmail)) {
2219
            throw new \InvalidArgumentException('Second email must be string');
2220
        }
2221
        if ($secondBirthDate !== null && !is_int($secondBirthDate)) {
2222
            throw new \InvalidArgumentException('Second birth date must be int');
2223
        }
2224
        if ($secondFirstname !== null && !is_string($secondFirstname)) {
2225
            throw new \InvalidArgumentException('Second firstname must be string');
2226
        }
2227
        if ($secondLastname !== null && !is_string($secondLastname)) {
2228
            throw new \InvalidArgumentException('Second lastname must be string');
2229
        }
2230
        if ($secondFullname !== null && !is_string($secondFullname)) {
2231
            throw new \InvalidArgumentException('Second fullname must be string');
2232
        }
2233
        if ($secondState !== null && !is_string($secondState)) {
2234
            throw new \InvalidArgumentException('Second state must be string');
2235
        }
2236
        if ($secondCity !== null && !is_string($secondCity)) {
2237
            throw new \InvalidArgumentException('Second city must be string');
2238
        }
2239
        if ($secondAddress !== null && !is_string($secondAddress)) {
2240
            throw new \InvalidArgumentException('Second address must be string');
2241
        }
2242
        if ($secondZip !== null && !is_string($secondZip)) {
2243
            throw new \InvalidArgumentException('Second zip must be string');
2244
        }
2245
        if ($secondGender !== null && !is_string($secondGender)) {
2246
            throw new \InvalidArgumentException('Second gender must be string');
2247
        }
2248
        if ($secondCountry !== null && !is_string($secondCountry)) {
2249
            throw new \InvalidArgumentException('Second country must be string');
2250
        }
2251
        if ($iban !== null && !is_string($iban)) {
2252
            throw new \InvalidArgumentException('Iban must be string');
2253
        }
2254
        if ($secondIban !== null && !is_string($secondIban)) {
2255
            throw new \InvalidArgumentException('Second iban must be string');
2256
        }
2257
        if ($bic !== null && !is_string($bic)) {
2258
            throw new \InvalidArgumentException('Bic must be string');
2259
        }
2260
        if ($source !== null && !is_string($source)) {
2261
            throw new \InvalidArgumentException('Transfer source must be string');
2262
        }
2263
2264
        $this->replace('event_id', $eventId);
2265
        $this->replace('event_timestamp', $eventTimestamp);
2266
        $this->replace('amount', $amount);
2267
        $this->replace('currency', $currency);
2268
        $this->replace('account_id', $accountId);
2269
        $this->replace('second_account_id', $secondAccountId);
2270
        $this->replace('account_system', $accountSystem);
2271
        $this->replace('amount_converted', $amountConverted);
2272
        $this->replace('method', $method);
2273
        $this->replace('operation', $operation);
2274
        $this->replace('second_email', $secondEmail);
2275
        $this->replace('second_phone', $secondPhone);
2276
        $this->replace('second_birth_date', $secondBirthDate);
2277
        $this->replace('second_firstname', $secondFirstname);
2278
        $this->replace('second_lastname', $secondLastname);
2279
        $this->replace('second_fullname', $secondFullname);
2280
        $this->replace('second_state', $secondState);
2281
        $this->replace('second_city', $secondCity);
2282
        $this->replace('second_address', $secondAddress);
2283
        $this->replace('second_zip', $secondZip);
2284
        $this->replace('second_gender', $secondGender);
2285
        $this->replace('second_country', $secondCountry);
2286
        $this->replace('iban', $iban);
2287
        $this->replace('second_iban', $secondIban);
2288
        $this->replace('bic', $bic);
2289
        $this->replace('transfer_source', $source);
2290
2291
        return $this;
2292
    }
2293
2294
    /**
2295
     * Provides kyc information to envelope
2296
     *
2297
     * @param string $eventId
2298
     * @param int $eventTimestamp
2299
     * @param string|null $groupId
2300
     * @param string|null $status
2301
     * @param string|null $code
2302
     * @param string|null $reason
2303
     * @param string|null $providerResult
2304
     * @param string|null $providerCode
2305
     * @param string|null $providerReason
2306
     * @param string|null $profileId
2307
     * @param string|null $profileType
2308
     * @param string|null $profileSubType
2309
     * @param string|null $industry
2310
     * @param string|null $description
2311
     * @param int|null $regDate
2312
     * @param string|null $regNumber
2313
     * @param string|null $vatNumber
2314
     * @param string|null $secondCountry
2315
     * @param string|null $secondState
2316
     * @param string|null $secondCity
2317
     * @param string|null $secondAddress
2318
     * @param string|null $secondZip
2319
     * @param string|null $relatedProfiles
2320
     *
2321
     * @return $this
2322
     */
2323
    public function addKycData(
2324
        $eventId,
2325
        $eventTimestamp,
2326
        $groupId = null,
2327
        $status = null,
2328
        $code = null,
2329
        $reason = null,
2330
        $providerResult = null,
2331
        $providerCode = null,
2332
        $providerReason = null,
2333
        $profileId = null,
2334
        $profileType = null,
2335
        $profileSubType = null,
2336
        $industry = null,
2337
        $description = null,
2338
        $regDate = null,
2339
        $regNumber = null,
2340
        $vatNumber = null,
2341
        $secondCountry = null,
2342
        $secondState = null,
2343
        $secondCity = null,
2344
        $secondAddress = null,
2345
        $secondZip = null,
2346
        $relatedProfiles = null
2347
    ) {
2348
        if (!is_string($eventId)) {
2349
            throw new \InvalidArgumentException('Event ID must be string');
2350
        }
2351
        if (!is_int($eventTimestamp)) {
2352
            throw new \InvalidArgumentException('Event timestamp must be int');
2353
        }
2354
        if ($groupId !== null && !is_string($groupId)) {
2355
            throw new \InvalidArgumentException('Group id must be string');
2356
        }
2357
        if ($status !== null && !is_string($status)) {
2358
            throw new \InvalidArgumentException('Status must be string');
2359
        }
2360
        if ($code !== null && !is_string($code)) {
2361
            throw new \InvalidArgumentException('Code must be string');
2362
        }
2363
        if ($reason !== null && !is_string($reason)) {
2364
            throw new \InvalidArgumentException('Reason must be string');
2365
        }
2366
        if ($providerResult !== null && !is_string($providerResult)) {
2367
            throw new \InvalidArgumentException('Provider result must be string');
2368
        }
2369
        if ($providerCode !== null && !is_string($providerCode)) {
2370
            throw new \InvalidArgumentException('Provider code must be string');
2371
        }
2372
        if ($providerReason !== null && !is_string($providerReason)) {
2373
            throw new \InvalidArgumentException('Provider reason must be string');
2374
        }
2375
        if ($profileId !== null && !is_string($profileId)) {
2376
            throw new \InvalidArgumentException('Profile id must be string');
2377
        }
2378
        if ($profileType !== null && !is_string($profileType)) {
2379
            throw new \InvalidArgumentException('Profile type must be string');
2380
        }
2381
        if ($profileSubType !== null && !is_string($profileSubType)) {
2382
            throw new \InvalidArgumentException('Profile sub type must be string');
2383
        }
2384
        if ($industry !== null && !is_string($industry)) {
2385
            throw new \InvalidArgumentException('Industry must be string');
2386
        }
2387
        if ($description !== null && !is_string($description)) {
2388
            throw new \InvalidArgumentException('Description must be string');
2389
        }
2390
        if ($regDate !== null && !is_int($regDate)) {
2391
            throw new \InvalidArgumentException('Reg date must be integer');
2392
        }
2393
        if ($regNumber !== null && !is_string($regNumber)) {
2394
            throw new \InvalidArgumentException('Reg number must be string');
2395
        }
2396
        if ($vatNumber !== null && !is_string($vatNumber)) {
2397
            throw new \InvalidArgumentException('Vat number must be string');
2398
        }
2399
        if ($secondCountry !== null && !is_string($secondCountry)) {
2400
            throw new \InvalidArgumentException('Secondary country must be string');
2401
        }
2402
        if ($secondState !== null && !is_string($secondState)) {
2403
            throw new \InvalidArgumentException('Second state must be string');
2404
        }
2405
        if ($secondCity !== null && !is_string($secondCity)) {
2406
            throw new \InvalidArgumentException('Second city must be string');
2407
        }
2408
        if ($secondAddress !== null && !is_string($secondAddress)) {
2409
            throw new \InvalidArgumentException('Second address must be string');
2410
        }
2411
        if ($secondZip !== null && !is_string($secondZip)) {
2412
            throw new \InvalidArgumentException('Second zip must be string');
2413
        }
2414
        if ($relatedProfiles !== null && !is_string($relatedProfiles)) {
2415
            throw new \InvalidArgumentException('Related profiles must be string');
2416
        }
2417
2418
        $this->replace('event_id', $eventId);
2419
        $this->replace('event_timestamp', $eventTimestamp);
2420
        $this->replace('group_id', $groupId);
2421
        $this->replace('status', $status);
2422
        $this->replace('code', $code);
2423
        $this->replace('reason', $reason);
2424
        $this->replace('provider_result', $providerResult);
2425
        $this->replace('provider_code', $providerCode);
2426
        $this->replace('provider_reason', $providerReason);
2427
        $this->replace('profile_id', $profileId);
2428
        $this->replace('profile_type', $profileType);
2429
        $this->replace('profile_sub_type', $profileSubType);
2430
        $this->replace('industry', $industry);
2431
        $this->replace('description', $description);
2432
        $this->replace('reg_date', $regDate);
2433
        $this->replace('reg_number', $regNumber);
2434
        $this->replace('vat_number', $vatNumber);
2435
        $this->replace('second_country', $secondCountry);
2436
        $this->replace('second_state', $secondState);
2437
        $this->replace('second_city', $secondCity);
2438
        $this->replace('second_address', $secondAddress);
2439
        $this->replace('second_zip', $secondZip);
2440
        $this->replace('related_profiles', $relatedProfiles);
2441
2442
        return $this;
2443
    }
2444
2445
    /**
2446
     * Provides order information to envelope
2447
     *
2448
     * @param string $envelopeType
2449
     * @param float $amount
2450
     * @param string $currency
2451
     * @param string $eventId
2452
     * @param int $eventTimestamp
2453
     * @param string|null $transactionId
2454
     * @param string|null $groupId
2455
     * @param int|null $itemsQuantity
2456
     * @param string|null $orderType
2457
     * @param float|null $amountConverted
2458
     * @param string|null $campaign
2459
     * @param string|null $carrier
2460
     * @param string|null $carrierShippingId
2461
     * @param string|null $carrierUrl
2462
     * @param string|null $carrierPhone
2463
     * @param int|null $couponStartDate
2464
     * @param int|null $couponEndDate
2465
     * @param string|null $couponId
2466
     * @param string|null $couponName
2467
     * @param string|null $customerComment
2468
     * @param int|null $deliveryEstimate
2469
     * @param string|null $shippingAddress
2470
     * @param string|null $shippingCity
2471
     * @param string|null $shippingCountry
2472
     * @param string|null $shippingCurrency
2473
     * @param float|null $shippingFee
2474
     * @param float|null $shippingFeeConverted
2475
     * @param string|null $shippingState
2476
     * @param string|null $shippingZip
2477
     * @param string|null $source
2478
     * @param float|null $sourceFee
2479
     * @param string|null $sourceFeeCurrency
2480
     * @param float|null $sourceFeeConverted
2481
     * @param string|null $taxCurrency
2482
     * @param float|null $taxFee
2483
     * @param float|null $taxFeeConverted
2484
     * @param string|null $productUrl
2485
     * @param string|null $productImageUrl
2486
     * @return Builder
2487
     */
2488
    public function addOrderData(
2489
        $envelopeType,
2490
        $amount,
2491
        $currency,
2492
        $eventId,
2493
        $eventTimestamp,
2494
        $transactionId = null,
2495
        $groupId = null,
2496
        $itemsQuantity = null,
2497
        $orderType = null,
2498
        $amountConverted = null,
2499
        $campaign = null,
2500
        $carrier = null,
2501
        $carrierShippingId = null,
2502
        $carrierUrl = null,
2503
        $carrierPhone = null,
2504
        $couponStartDate = null,
2505
        $couponEndDate = null,
2506
        $couponId = null,
2507
        $couponName = null,
2508
        $customerComment = null,
2509
        $deliveryEstimate = null,
2510
        $shippingAddress = null,
2511
        $shippingCity = null,
2512
        $shippingCountry = null,
2513
        $shippingCurrency = null,
2514
        $shippingFee = null,
2515
        $shippingFeeConverted = null,
2516
        $shippingState = null,
2517
        $shippingZip = null,
2518
        $source = null,
2519
        $sourceFee = null,
2520
        $sourceFeeCurrency = null,
2521
        $sourceFeeConverted = null,
2522
        $taxCurrency = null,
2523
        $taxFee = null,
2524
        $taxFeeConverted = null,
2525
        $productUrl = null,
2526
        $productImageUrl = null
2527
    ) {
2528
        if (!is_string($envelopeType)) {
2529
            throw new \InvalidArgumentException('Envelope type must be string');
2530
        }
2531
        if (!is_int($amount) && !is_float($amount)) {
2532
            throw new \InvalidArgumentException('Amount must be number');
2533
        }
2534
        if (!is_string($currency)) {
2535
            throw new \InvalidArgumentException('Currency must be string');
2536
        }
2537
        if (!is_string($eventId)) {
2538
            throw new \InvalidArgumentException('Event ID must be string');
2539
        }
2540
        if (!is_int($eventTimestamp)) {
2541
            throw new \InvalidArgumentException('Event timestamp must be int');
2542
        }
2543
        if ($envelopeType === 'order_submit' && !is_int($itemsQuantity)) {
2544
            throw new \InvalidArgumentException('Items quantity must be int');
2545
        }
2546
        if ($envelopeType === 'order_item' && !is_string($orderType)) {
2547
            throw new \InvalidArgumentException('Order type must be string');
2548
        }
2549
        if ($transactionId !== null && !is_string($transactionId)) {
2550
            throw new \InvalidArgumentException('Transaction id must be string');
2551
        }
2552
        if ($groupId !== null && !is_string($groupId)) {
2553
            throw new \InvalidArgumentException('Group id must be string');
2554
        }
2555 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...
2556
            throw new \InvalidArgumentException('Amount converted must be number');
2557
        }
2558
        if ($campaign !== null && !is_string($campaign)) {
2559
            throw new \InvalidArgumentException('Campaign must be string');
2560
        }
2561
        if ($carrier !== null && !is_string($carrier)) {
2562
            throw new \InvalidArgumentException('Carrier must be string');
2563
        }
2564
        if ($carrierShippingId !== null && !is_string($carrierShippingId)) {
2565
            throw new \InvalidArgumentException('Carrier shipping id must be string');
2566
        }
2567
        if ($carrierUrl !== null && !is_string($carrierUrl)) {
2568
            throw new \InvalidArgumentException('Carrier url must be string');
2569
        }
2570
        if ($carrierPhone !== null && !is_string($carrierPhone)) {
2571
            throw new \InvalidArgumentException('Carrier phone must be string');
2572
        }
2573
        if ($couponStartDate !== null && !is_int($couponStartDate)) {
2574
            throw new \InvalidArgumentException('Coupon start date must be int');
2575
        }
2576
        if ($couponEndDate !== null && !is_int($couponEndDate)) {
2577
            throw new \InvalidArgumentException('Coupon end date must be int');
2578
        }
2579
        if ($couponId !== null && !is_string($couponId)) {
2580
            throw new \InvalidArgumentException('Coupon id must be string');
2581
        }
2582
        if ($couponName !== null && !is_string($couponName)) {
2583
            throw new \InvalidArgumentException('Coupon name must be string');
2584
        }
2585
        if ($customerComment !== null && !is_string($customerComment)) {
2586
            throw new \InvalidArgumentException('Customer comment must be string');
2587
        }
2588
        if ($deliveryEstimate !== null && !is_int($deliveryEstimate)) {
2589
            throw new \InvalidArgumentException('Delivery estimate must be int');
2590
        }
2591
        if ($shippingAddress !== null && !is_string($shippingAddress)) {
2592
            throw new \InvalidArgumentException('Shipping address must be string');
2593
        }
2594
        if ($shippingCity !== null && !is_string($shippingCity)) {
2595
            throw new \InvalidArgumentException('Shipping city must be string');
2596
        }
2597
        if ($shippingCountry !== null && !is_string($shippingCountry)) {
2598
            throw new \InvalidArgumentException('Shipping country must be string');
2599
        }
2600
        if ($shippingCurrency !== null && !is_string($shippingCurrency)) {
2601
            throw new \InvalidArgumentException('Shipping currency must be string');
2602
        }
2603
        if ($shippingFee !== null && !is_int($shippingFee) && !is_float($shippingFee)) {
2604
            throw new \InvalidArgumentException('Shipping fee must be number');
2605
        }
2606
        if ($shippingFeeConverted !== null && !is_int($shippingFeeConverted) && !is_float($shippingFeeConverted)) {
2607
            throw new \InvalidArgumentException('Shipping fee converted must be number');
2608
        }
2609
        if ($shippingState !== null && !is_string($shippingState)) {
2610
            throw new \InvalidArgumentException('Shipping state must be string');
2611
        }
2612
        if ($shippingZip !== null && !is_string($shippingZip)) {
2613
            throw new \InvalidArgumentException('Shipping zip must be string');
2614
        }
2615
        if ($source !== null && !is_string($source)) {
2616
            throw new \InvalidArgumentException('Order source must be string');
2617
        }
2618
        if ($sourceFee !== null && !is_int($sourceFee) && !is_float($sourceFee)) {
2619
            throw new \InvalidArgumentException('Source fee must be number');
2620
        }
2621
        if ($sourceFeeConverted !== null && !is_int($sourceFeeConverted) && !is_float($sourceFeeConverted)) {
2622
            throw new \InvalidArgumentException('Source fee converted must be number');
2623
        }
2624
        if ($sourceFeeCurrency !== null && !is_string($sourceFeeCurrency)) {
2625
            throw new \InvalidArgumentException('Source fee currency must be string');
2626
        }
2627
        if ($taxCurrency !== null && !is_string($taxCurrency)) {
2628
            throw new \InvalidArgumentException('Tax currency must be string');
2629
        }
2630
        if ($taxFee !== null && !is_int($taxFee) && !is_float($taxFee)) {
2631
            throw new \InvalidArgumentException('Tax fee must be number');
2632
        }
2633
        if ($taxFeeConverted !== null && !is_int($taxFeeConverted) && !is_float($taxFeeConverted)) {
2634
            throw new \InvalidArgumentException('Tax fee converted must be number');
2635
        }
2636
        if ($productUrl !== null && !is_string($productUrl)) {
2637
            throw new \InvalidArgumentException('Product url must be string');
2638
        }
2639
        if ($productImageUrl !== null && !is_string($productImageUrl)) {
2640
            throw new \InvalidArgumentException('Product image url must be string');
2641
        }
2642
        if ($productImageUrl !== null && !is_string($productImageUrl)) {
2643
            throw new \InvalidArgumentException('Product image url must be string');
2644
        }
2645
        $this->replace('amount', $amount);
2646
        $this->replace('currency', $currency);
2647
        $this->replace('event_id', $eventId);
2648
        $this->replace('event_timestamp', $eventTimestamp);
2649
        $this->replace('items_quantity', $itemsQuantity);
2650
        $this->replace('order_type', $orderType);
2651
        $this->replace('transaction_id', $transactionId);
2652
        $this->replace('group_id', $groupId);
2653
        $this->replace('amount_converted', $amountConverted);
2654
        $this->replace('campaign', $campaign);
2655
        $this->replace('carrier', $carrier);
2656
        $this->replace('carrier_shipping_id', $carrierShippingId);
2657
        $this->replace('carrier_url', $carrierUrl);
2658
        $this->replace('carrier_phone', $carrierPhone);
2659
        $this->replace('coupon_start_date', $couponStartDate);
2660
        $this->replace('coupon_end_date', $couponEndDate);
2661
        $this->replace('coupon_id', $couponId);
2662
        $this->replace('coupon_name', $couponName);
2663
        $this->replace('customer_comment', $customerComment);
2664
        $this->replace('delivery_estimate', $deliveryEstimate);
2665
        $this->replace('shipping_address', $shippingAddress);
2666
        $this->replace('shipping_city', $shippingCity);
2667
        $this->replace('shipping_country', $shippingCountry);
2668
        $this->replace('shipping_currency', $shippingCurrency);
2669
        $this->replace('shipping_fee', $shippingFee);
2670
        $this->replace('shipping_fee_converted', $shippingFeeConverted);
2671
        $this->replace('shipping_state', $shippingState);
2672
        $this->replace('shipping_zip', $shippingZip);
2673
        $this->replace('order_source', $source);
2674
        $this->replace('source_fee', $sourceFee);
2675
        $this->replace('source_fee_currency', $sourceFeeCurrency);
2676
        $this->replace('source_fee_converted', $sourceFeeConverted);
2677
        $this->replace('tax_currency', $taxCurrency);
2678
        $this->replace('tax_fee', $taxFee);
2679
        $this->replace('tax_fee_converted', $taxFeeConverted);
2680
        $this->replace('product_url', $productUrl);
2681
        $this->replace('product_image_url', $productImageUrl);
2682
2683
        return $this;
2684
    }
2685
2686
    /**
2687
     * Provides postback information to envelope
2688
     *
2689
     * @param int|null $requestId
2690
     * @param string|null $transactionId
2691
     * @param string|null $transactionStatus
2692
     * @param string|null $code
2693
     * @param string|null $reason
2694
     * @param string|null $secure3d
2695
     * @param string|null $avsResult
2696
     * @param string|null $cvvResult
2697
     * @param string|null $pspCode
2698
     * @param string|null $pspReason
2699
     * @param string|null $arn
2700
     * @param string|null $paymentAccountId
2701
     * @return $this
2702
     */
2703
    public function addPostbackData(
2704
        $requestId = null,
2705
        $transactionId = null,
2706
        $transactionStatus = null,
2707
        $code = null,
2708
        $reason = null,
2709
        $secure3d = null,
2710
        $avsResult = null,
2711
        $cvvResult = null,
2712
        $pspCode = null,
2713
        $pspReason = null,
2714
        $arn = null,
2715
        $paymentAccountId = null
2716
    ) {
2717
        if ($requestId === null && $transactionId === null) {
2718
            throw new \InvalidArgumentException('request_id or transaction_id should be provided');
2719
        }
2720
        if ($transactionId !== null && !is_string($transactionId)) {
2721
            throw new \InvalidArgumentException('TransactionId must be string');
2722
        }
2723
        if ($requestId !== null && !is_int($requestId)) {
2724
            throw new \InvalidArgumentException('RequestId must be int');
2725
        }
2726
        if ($transactionStatus !== null && !is_string($transactionStatus)) {
2727
            throw new \InvalidArgumentException('Transaction status must be string');
2728
        }
2729
        if ($code !== null && !is_string($code)) {
2730
            throw new \InvalidArgumentException('Code must be string');
2731
        }
2732
        if ($reason !== null && !is_string($reason)) {
2733
            throw new \InvalidArgumentException('Reason must be string');
2734
        }
2735
        if ($secure3d !== null && !is_string($secure3d)) {
2736
            throw new \InvalidArgumentException('Secure3d must be string');
2737
        }
2738
        if ($avsResult !== null && !is_string($avsResult)) {
2739
            throw new \InvalidArgumentException('AvsResult must be string');
2740
        }
2741
        if ($cvvResult !== null && !is_string($cvvResult)) {
2742
            throw new \InvalidArgumentException('CvvResult must be string');
2743
        }
2744
        if ($pspCode !== null && !is_string($pspCode)) {
2745
            throw new \InvalidArgumentException('PspCode must be string');
2746
        }
2747
        if ($pspReason !== null && !is_string($pspReason)) {
2748
            throw new \InvalidArgumentException('PspReason must be string');
2749
        }
2750
        if ($arn !== null && !is_string($arn)) {
2751
            throw new \InvalidArgumentException('Arn must be string');
2752
        }
2753
        if ($paymentAccountId !== null && !is_string($paymentAccountId)) {
2754
            throw new \InvalidArgumentException('PaymentAccoutId must be string');
2755
        }
2756
2757
        $this->replace('request_id', $requestId);
2758
        $this->replace('transaction_id', $transactionId);
2759
        $this->replace('transaction_status', $transactionStatus);
2760
        $this->replace('code', $code);
2761
        $this->replace('reason', $reason);
2762
        $this->replace('secure3d', $secure3d);
2763
        $this->replace('avs_result', $avsResult);
2764
        $this->replace('cvv_result', $cvvResult);
2765
        $this->replace('psp_code', $pspCode);
2766
        $this->replace('psp_reason', $pspReason);
2767
        $this->replace('arn', $arn);
2768
        $this->replace('payment_account_id', $paymentAccountId);
2769
2770
        return $this;
2771
    }
2772
2773
    /**
2774
     * Adds custom data field to envelope
2775
     *
2776
     * @param string $name
2777
     * @param string $value
2778
     *
2779
     * @return $this
2780
     */
2781
    public function addCustomField($name, $value)
2782
    {
2783
        if (!is_string($name)) {
2784
            throw new \InvalidArgumentException('Custom field name must be string');
2785
        }
2786
        if (!is_string($value)) {
2787
            throw new \InvalidArgumentException('Custom field value must be string');
2788
        }
2789
2790
        if (strlen($name) < 8 || substr($name, 0, 7) !== 'custom_') {
2791
            $name = 'custom_' . $name;
2792
        }
2793
2794
        $this->replace($name, $value);
2795
        return $this;
2796
    }
2797
}
2798