Completed
Push — master ( 80b3a7...c051f5 )
by
unknown
01:48
created

Builder::postBackEvent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 9.488
c 0
b 0
f 0
cc 1
nc 1
nop 11

How to fix   Many Parameters   

Many Parameters

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

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace Covery\Client\Envelopes;
4
5
use Covery\Client\EnvelopeInterface;
6
use Covery\Client\IdentityNodeInterface;
7
8
class Builder
9
{
10
    /**
11
     * @var string
12
     */
13
    private $type;
14
    /**
15
     * @var string
16
     */
17
    private $sequenceId;
18
    /**
19
     * @var IdentityNodeInterface[]
20
     */
21
    private $identities = array();
22
    /**
23
     * @var array
24
     */
25
    private $data = array();
26
27
    /**
28
     * Returns builder for confirmation event
29
     *
30
     * @param string $sequenceId
31
     * @param string $userId
32
     * @param int|null $timestamp If null provided, takes current time
33
     * @param bool|null $isEmailConfirmed
34
     * @param bool|null $idPhoneConfirmed
35
     * @param string|null $email
36
     * @param string|null $phone
37
     *
38
     * @return Builder
39
     */
40
    public static function confirmationEvent(
41
        $sequenceId,
42
        $userId,
43
        $timestamp = null,
44
        $isEmailConfirmed = null,
45
        $idPhoneConfirmed = null,
46
        $email = null,
47
        $phone = null
48
    ) {
49
        $builder = new self('confirmation', $sequenceId);
50
        if ($timestamp === null) {
51
            $timestamp = time();
52
        }
53
54
        return $builder->addUserData(
55
            $email,
56
            $userId,
57
            $phone,
58
            null,
59
            null,
60
            null,
61
            null,
62
            null,
63
            null,
64
            null,
65
            null,
66
            null,
67
            $timestamp,
68
            $isEmailConfirmed,
69
            $idPhoneConfirmed,
70
            null
71
        );
72
    }
73
74
    /**
75
     * Returns builder for login event
76
     *
77
     * @param string $sequenceId
78
     * @param string $userId
79
     * @param int|null $timestamp
80
     * @param string|null $email
81
     * @param bool|null $failed
82
     * @param string|null $gender
83
     * @param string|null $trafficSource
84
     * @param string|null $affiliateId
85
     *
86
     * @return Builder
87
     */
88
    public static function loginEvent(
89
        $sequenceId,
90
        $userId,
91
        $timestamp = null,
92
        $email = null,
93
        $failed = null,
94
        $gender = null,
95
        $trafficSource = null,
96
        $affiliateId = null
97
    ) {
98
        $builder = new self('login', $sequenceId);
99
        if ($timestamp === null) {
100
            $timestamp = time();
101
        }
102
103
        return $builder->addUserData(
104
            $email,
105
            $userId,
106
            null,
107
            null,
108
            null,
109
            null,
110
            $gender,
111
            null,
112
            null,
113
            null,
114
            null,
115
            $timestamp,
116
            null,
117
            null,
118
            null,
119
            $failed
120
        )->addWebsiteData(null, $trafficSource, $affiliateId);
121
    }
122
123
    /**
124
     * Returns builder for registration event
125
     *
126
     * @param string $sequenceId
127
     * @param string $userId
128
     * @param int|null $timestamp
129
     * @param string|null $email
130
     * @param string|null $userName
131
     * @param string|null $firstName
132
     * @param string|null $lastName
133
     * @param int|null $age
134
     * @param string|null $gender
135
     * @param string|null $phone
136
     * @param string|null $country
137
     * @param string|null $socialType
138
     * @param string|null $websiteUrl
139
     * @param string|null $trafficSource
140
     * @param string|null $affiliateId
141
     *
142
     * @return Builder
143
     */
144
    public static function registrationEvent(
145
        $sequenceId,
146
        $userId,
147
        $timestamp = null,
148
        $email = null,
149
        $userName = null,
150
        $firstName = null,
151
        $lastName = null,
152
        $age = null,
153
        $gender = null,
154
        $phone = null,
155
        $country = null,
156
        $socialType = null,
157
        $websiteUrl = null,
158
        $trafficSource = null,
159
        $affiliateId = null
160
    ) {
161
        $builder = new self('registration', $sequenceId);
162
        if ($timestamp === null) {
163
            $timestamp = time();
164
        }
165
166
        return $builder->addWebsiteData(
167
            $websiteUrl,
168
            $trafficSource,
169
            $affiliateId
170
        )->addUserData(
171
            $email,
172
            $userId,
173
            $phone,
174
            $userName,
175
            $firstName,
176
            $lastName,
177
            $gender,
178
            $age,
179
            $country,
180
            $socialType,
181
            $timestamp,
182
            null,
183
            null,
184
            null,
185
            null,
186
            null
187
        );
188
    }
189
190
    /**
191
     * Returns builder for payout request
192
     *
193
     * @param string $sequenceId
194
     * @param string $userId
195
     * @param string $payoutId
196
     * @param string $currency
197
     * @param int|float $amount
198
     * @param int|null $payoutTimestamp
199
     * @param string|null $cardId
200
     * @param string|null $accountId
201
     * @param string|null $method
202
     * @param string|null $system
203
     * @param string|null $mid
204
     * @param int|float $amountConverted
205
     * @param string|null $firstName
206
     * @param string|null $lastName
207
     * @param string|null $country
208
     * @param string|null $email
209
     * @param string|null $phone
210
     * @param int|null $cardBin
211
     * @param string|null $cardLast4
212
     * @param int|null $cardExpirationMonth
213
     * @param int|null $cardExpirationYear
214
     *
215
     * @return Builder
216
     */
217
    public static function payoutEvent(
218
        $sequenceId,
219
        $userId,
220
        $payoutId,
221
        $currency,
222
        $amount,
223
        $payoutTimestamp = null,
224
        $cardId = null,
225
        $accountId = null,
226
        $method = null,
227
        $system = null,
228
        $mid = null,
229
        $amountConverted = null,
230
        $firstName = null,
231
        $lastName = null,
232
        $country = null,
233
        $email = null,
234
        $phone = null,
235
        $cardBin = null,
236
        $cardLast4 = null,
237
        $cardExpirationMonth = null,
238
        $cardExpirationYear = null
239
    ) {
240
        $builder = new self('payout', $sequenceId);
241
        if ($payoutTimestamp === null) {
242
            $payoutTimestamp = time();
243
        }
244
        return $builder->addPayoutData(
245
            $payoutId,
246
            $payoutTimestamp,
247
            $amount,
248
            $currency,
249
            $cardId,
250
            $accountId,
251
            $method,
252
            $system,
253
            $mid,
254
            $amountConverted,
255
            $cardBin,
256
            $cardLast4,
257
            $cardExpirationMonth,
258
            $cardExpirationYear
259
        )->addShortUserData($email, $userId, $phone, $firstName, $lastName, $country);
260
    }
261
262
    /**
263
     * Returns builder for transaction request
264
     *
265
     * @param string $sequenceId
266
     * @param string $userId
267
     * @param string $transactionId
268
     * @param int|float $transactionAmount
269
     * @param string $transactionCurrency
270
     * @param int|null $transactionTimestamp
271
     * @param string|null $transactionMode
272
     * @param string|null $transactionType
273
     * @param int|null $cardBin
274
     * @param string|null $cardId
275
     * @param string|null $cardLast4
276
     * @param int|null $expirationMonth
277
     * @param int|null $expirationYear
278
     * @param int|null $age
279
     * @param string|null $country
280
     * @param string|null $email
281
     * @param string|null $gender
282
     * @param string|null $firstName
283
     * @param string|null $lastName
284
     * @param string|null $phone
285
     * @param string|null $userName
286
     * @param string|null $paymentAccountId
287
     * @param string|null $paymentMethod
288
     * @param string|null $paymentMidName
289
     * @param string|null $paymentSystem
290
     * @param int|float|null $transactionAmountConverted
291
     * @param string|null $transactionSource
292
     * @param string|null $billingAddress
293
     * @param string|null $billingCity
294
     * @param string|null $billingCountry
295
     * @param string|null $billingFirstName
296
     * @param string|null $billingLastName
297
     * @param string|null $billingFullName
298
     * @param string|null $billingState
299
     * @param string|null $billingZip
300
     * @param string|null $productDescription
301
     * @param string|null $productName
302
     * @param int|float|null $productQuantity
303
     * @param string|null $websiteUrl
304
     * @param string|null $merchantIp
305
     * @param string|null $affiliateId
306
     *
307
     * @return Builder
308
     */
309
    public static function transactionEvent(
310
        $sequenceId,
311
        $userId,
312
        $transactionId,
313
        $transactionAmount,
314
        $transactionCurrency,
315
        $transactionTimestamp = null,
316
        $transactionMode = null,
317
        $transactionType = null,
318
        $cardBin = null,
319
        $cardId = null,
320
        $cardLast4 = null,
321
        $expirationMonth = null,
322
        $expirationYear = null,
323
        $age = null,
324
        $country = null,
325
        $email = null,
326
        $gender = null,
327
        $firstName = null,
328
        $lastName = null,
329
        $phone = null,
330
        $userName = null,
331
        $paymentAccountId = null,
332
        $paymentMethod = null,
333
        $paymentMidName = null,
334
        $paymentSystem = null,
335
        $transactionAmountConverted = null,
336
        $transactionSource = null,
337
        $billingAddress = null,
338
        $billingCity = null,
339
        $billingCountry = null,
340
        $billingFirstName = null,
341
        $billingLastName = null,
342
        $billingFullName = null,
343
        $billingState = null,
344
        $billingZip = null,
345
        $productDescription = null,
346
        $productName = null,
347
        $productQuantity = null,
348
        $websiteUrl = null,
349
        $merchantIp = null,
350
        $affiliateId = null
351
    ) {
352
        $builder = new self('transaction', $sequenceId);
353
        if ($transactionTimestamp === null) {
354
            $transactionTimestamp = time();
355
        }
356
357
        return $builder
358
            ->addCCTransactionData(
359
                $transactionId,
360
                $transactionSource,
361
                $transactionType,
362
                $transactionMode,
363
                $transactionTimestamp,
364
                $transactionCurrency,
365
                $transactionAmount,
366
                $transactionAmountConverted,
367
                $paymentMethod,
368
                $paymentSystem,
369
                $paymentMidName,
370
                $paymentAccountId
371
            )
372
            ->addBillingData(
373
                $billingFirstName,
374
                $billingLastName,
375
                $billingFullName,
376
                $billingCountry,
377
                $billingState,
378
                $billingCity,
379
                $billingAddress,
380
                $billingZip
381
            )
382
            ->addCardData($cardBin, $cardLast4, $expirationMonth, $expirationYear, $cardId)
383
            ->addUserData(
384
                $email,
385
                $userId,
386
                $phone,
387
                $userName,
388
                $firstName,
389
                $lastName,
390
                $gender,
391
                $age,
392
                $country
393
            )
394
            ->addProductData($productQuantity, $productName, $productDescription)
395
            ->addWebsiteData($websiteUrl, null, $affiliateId)
396
            ->addIpData(null, null, $merchantIp);
397
398
    }
399
400
    /**
401
     * Returns builder for install request
402
     *
403
     * @param string $sequenceId
404
     * @param string|null $userId
405
     * @param int|null $installTimestamp
406
     * @param string|null $country
407
     * @param string|null $websiteUrl
408
     * @param string|null $trafficSource
409
     * @param string|null $affiliateId
410
     *
411
     * @return Builder
412
     */
413
    public static function installEvent(
414
        $sequenceId,
415
        $userId = null,
416
        $installTimestamp = null,
417
        $country = null,
418
        $websiteUrl = null,
419
        $trafficSource = null,
420
        $affiliateId = null
421
    ) {
422
        $builder = new self('install', $sequenceId);
423
        if ($installTimestamp === null) {
424
            $installTimestamp = time();
425
        }
426
427
        return $builder->addInstallData(
428
            $installTimestamp
429
        )->addWebsiteData($websiteUrl, $trafficSource, $affiliateId)
430
        ->addShortUserData(null, $userId, null, null, null, $country);
431
    }
432
433
    /**
434
     * Returns builder for refund request
435
     *
436
     * @param string $sequenceId
437
     * @param string $refundId
438
     * @param int|float $refundAmount
439
     * @param string $refundCurrency
440
     * @param int|null $refundTimestamp
441
     * @param int|float|null $refundAmountConverted
442
     * @param string|null $refundSource
443
     * @param string|null $refundType
444
     * @param string|null $refundCode
445
     * @param string|null $refundReason
446
     * @param string|null $agentId
447
     * @param string|null $refundMethod
448
     * @param string|null $refundSystem
449
     * @param string|null $refundMid
450
     *
451
     * @return Builder
452
     */
453
    public static function refundEvent(
454
        $sequenceId,
455
        $refundId,
456
        $refundAmount,
457
        $refundCurrency,
458
        $refundTimestamp = null,
459
        $refundAmountConverted = null,
460
        $refundSource = null,
461
        $refundType = null,
462
        $refundCode = null,
463
        $refundReason = null,
464
        $agentId = null,
465
        $refundMethod = null,
466
        $refundSystem = null,
467
        $refundMid = null,
468
        $email = null,
469
        $phone = null,
470
        $userId = null
471
    ) {
472
        $builder = new self('refund', $sequenceId);
473
        if ($refundTimestamp === null) {
474
            $refundTimestamp = time();
475
        }
476
477
        return $builder->addRefundData(
478
            $refundId,
479
            $refundTimestamp,
480
            $refundAmount,
481
            $refundCurrency,
482
            $refundAmountConverted,
483
            $refundSource,
484
            $refundType,
485
            $refundCode,
486
            $refundReason,
487
            $agentId,
488
            $refundMethod,
489
            $refundSystem,
490
            $refundMid
491
        )->addUserData($email, $userId, $phone);
492
    }
493
494
    /**
495
     * Returns builder for transfer request
496
     *
497
     * @param string $sequenceId
498
     * @param string $eventId
499
     * @param float $amount
500
     * @param string $currency
501
     * @param string $accountId
502
     * @param string $secondAccountId
503
     * @param string $accountSystem
504
     * @param string $userId
505
     * @param int|null $eventTimestamp
506
     * @param float|null $amountConverted
507
     * @param string|null $method
508
     * @param string|null $email
509
     * @param string|null $phone
510
     * @param int|null $birthDate
511
     * @param string|null $firstname
512
     * @param string|null $lastname
513
     * @param string|null $fullname
514
     * @param string|null $state
515
     * @param string|null $city
516
     * @param string|null $address
517
     * @param string|null $zip
518
     * @param string|null $gender
519
     * @param string|null $country
520
     * @param string|null $operation
521
     * @param string|null $secondEmail
522
     * @param string|null $secondPhone
523
     * @param int|null $secondBirthDate
524
     * @param string|null $secondFirstname
525
     * @param string|null $secondLastname
526
     * @param string|null $secondFullname
527
     * @param string|null $secondState
528
     * @param string|null $secondCity
529
     * @param string|null $secondAddress
530
     * @param string|null $secondZip
531
     * @param string|null $secondGender
532
     * @param string|null $secondCountry
533
     * @param string|null $productDescription
534
     * @param string|null $productName
535
     * @param int|float|null $productQuantity
536
     *
537
     * @return Builder
538
     */
539
    public static function transferEvent(
540
        $sequenceId,
541
        $eventId,
542
        $amount,
543
        $currency,
544
        $accountId,
545
        $secondAccountId,
546
        $accountSystem,
547
        $userId,
548
        $method = null,
549
        $eventTimestamp = null,
550
        $amountConverted = null,
551
        $email = null,
552
        $phone = null,
553
        $birthDate = null,
554
        $firstname = null,
555
        $lastname = null,
556
        $fullname = null,
557
        $state = null,
558
        $city = null,
559
        $address = null,
560
        $zip = null,
561
        $gender = null,
562
        $country = null,
563
        $operation = null,
564
        $secondEmail = null,
565
        $secondPhone = null,
566
        $secondBirthDate = null,
567
        $secondFirstname = null,
568
        $secondLastname = null,
569
        $secondFullname = null,
570
        $secondState = null,
571
        $secondCity = null,
572
        $secondAddress = null,
573
        $secondZip = null,
574
        $secondGender = null,
575
        $secondCountry = null,
576
        $productDescription = null,
577
        $productName = null,
578
        $productQuantity = null
579
580
    ) {
581
        $builder = new self('transfer', $sequenceId);
582
        if ($eventTimestamp === null) {
583
            $eventTimestamp = time();
584
        }
585
586
        return $builder
587
            ->addTransferData(
588
               $eventId,
589
               $eventTimestamp,
590
               $amount,
591
               $currency,
592
               $accountId,
593
               $secondAccountId,
594
               $accountSystem,
595
               $amountConverted,
596
               $method,
597
               $operation,
598
               $secondEmail,
599
               $secondPhone,
600
               $secondBirthDate,
601
               $secondFirstname,
602
               $secondLastname,
603
               $secondFullname,
604
               $secondState,
605
               $secondCity,
606
               $secondAddress,
607
               $secondZip,
608
               $secondGender,
609
               $secondCountry
610
            )
611
            ->addUserData(
612
                $email,
613
                $userId,
614
                $phone,
615
                null,
616
                $firstname,
617
                $lastname,
618
                $gender,
619
                null,
620
                $country,
621
                null,
622
                null,
623
                null,
624
                null,
625
                null,
626
                null,
627
                null,
628
                $birthDate,
629
                $fullname,
630
                $state,
631
                $city,
632
                $address,
633
                $zip
634
            )
635
            ->addProductData($productQuantity, $productName, $productDescription);
636
    }
637
638
    /**
639
     * Returns builder for postback request
640
     *
641
     * @param $sequenceId
642
     * @param string|null $transactionStatus
643
     * @param string|null $code
644
     * @param string|null $reason
645
     * @param string|null $secure3d
646
     * @param string|null $avsResult
647
     * @param string|null $cvvResult
648
     * @param string|null $pspCode
649
     * @param string|null $pspReason
650
     * @param string|null $arn
651
     * @param string|null $paymentAccountId
652
     * @return Builder
653
     */
654
    public static function postBackEvent(
655
        $sequenceId,
656
        $transactionStatus = null,
657
        $code = null,
658
        $reason = null,
659
        $secure3d = null,
660
        $avsResult = null,
661
        $cvvResult = null,
662
        $pspCode = null,
663
        $pspReason = null,
664
        $arn = null,
665
        $paymentAccountId = null
666
    ) {
667
        $builder = new self('postback', $sequenceId);
668
        return $builder->addPostBackData(
669
            $transactionStatus,
670
            $code,
671
            $reason,
672
            $secure3d,
673
            $avsResult,
674
            $cvvResult,
675
            $pspCode,
676
            $pspReason,
677
            $arn,
678
            $paymentAccountId
679
       );
680
    }
681
682
    /**
683
     * Builder constructor.
684
     *
685
     * @param string $envelopeType
686
     * @param string $sequenceId
687
     */
688
    public function __construct($envelopeType, $sequenceId)
689
    {
690
        if (!is_string($envelopeType)) {
691
            throw new \InvalidArgumentException('Envelope type must be string');
692
        }
693
        if (!is_string($sequenceId)) {
694
            throw new \InvalidArgumentException('Sequence ID must be string');
695
        }
696
697
        $this->type = $envelopeType;
698
        $this->sequenceId = $sequenceId;
699
    }
700
701
    /**
702
     * Returns built envelope
703
     *
704
     * @return EnvelopeInterface
705
     */
706
    public function build()
707
    {
708
        return new Envelope(
709
            $this->type,
710
            $this->sequenceId,
711
            $this->identities,
712
            array_filter($this->data, function ($data) {
713
                return $data !== null;
714
            })
715
        );
716
    }
717
718
    /**
719
     * Replaces value in internal array if provided value not empty
720
     *
721
     * @param string $key
722
     * @param string|int|float|bool|null $value
723
     */
724
    private function replace($key, $value)
725
    {
726
        if ($value !== null && $value !== '' && $value !== 0 && $value !== 0.0) {
727
            $this->data[$key] = $value;
728
        }
729
    }
730
731
    /**
732
     * Adds identity node
733
     *
734
     * @param IdentityNodeInterface $identity
735
     *
736
     * @return $this
737
     */
738
    public function addIdentity(IdentityNodeInterface $identity)
739
    {
740
        $this->identities[] = $identity;
741
        return $this;
742
    }
743
744
    /**
745
     * Provides website URL to envelope
746
     *
747
     * @param string|null $websiteUrl
748
     * @param string|null $traffic_source
749
     * @param string|null $affiliate_id
750
     *
751
     * @return $this
752
     */
753 View Code Duplication
    public function addWebsiteData($websiteUrl = null, $traffic_source = null, $affiliate_id = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
754
    {
755
        if ($websiteUrl !== null && !is_string($websiteUrl)) {
756
            throw new \InvalidArgumentException('Website URL must be string');
757
        }
758
        if ($traffic_source !== null && !is_string($traffic_source)) {
759
            throw new \InvalidArgumentException('Traffic source must be string');
760
        }
761
        if ($affiliate_id !== null && !is_string($affiliate_id)) {
762
            throw new \InvalidArgumentException('Affiliate ID must be string');
763
        }
764
765
        $this->replace('website_url', $websiteUrl);
766
        $this->replace('traffic_source', $traffic_source);
767
        $this->replace('affiliate_id', $affiliate_id);
768
        return $this;
769
    }
770
771
    /**
772
     * Provides IP information for envelope
773
     *
774
     * @param string|null $ip User's IP address
775
     * @param string|null $realIp User's real IP address, if available
776
     * @param string|null $merchantIp Your website's IP address
777
     *
778
     * @return $this
779
     */
780
    public function addIpData($ip = '', $realIp = '', $merchantIp = '')
781
    {
782
        if ($ip !== null && !is_string($ip)) {
783
            throw new \InvalidArgumentException('IP must be string');
784
        }
785
        if ($realIp !== null && !is_string($realIp)) {
786
            throw new \InvalidArgumentException('Real IP must be string');
787
        }
788
        if ($merchantIp !== null && !is_string($merchantIp)) {
789
            throw new \InvalidArgumentException('Merchant IP must be string');
790
        }
791
792
        $this->replace('ip', $ip);
793
        $this->replace('real_ip', $realIp);
794
        $this->replace('merchant_ip', $merchantIp);
795
796
        return $this;
797
    }
798
799
    /**
800
     * Provides browser information for envelope
801
     *
802
     * @param string|null $deviceFingerprint
803
     * @param string|null $userAgent
804
     * @param string|null $cpuClass
805
     * @param string|null $screenOrientation
806
     * @param string|null $screenResolution
807
     * @param string|null $os
808
     * @param int|null $timezoneOffset
809
     * @param string|null $languages
810
     * @param string|null $language
811
     * @param string|null $languageBrowser
812
     * @param string|null $languageUser
813
     * @param string|null $languageSystem
814
     * @param bool|null $cookieEnabled
815
     * @param bool|null $doNotTrack
816
     * @param bool|null $ajaxValidation
817
     * @param string|null $deviceId
818
     * @param string|null $ipList
819
     * @param string|null $plugins
820
     * @param string|null $refererUrl
821
     * @param string|null $originUrl
822
     * @param string|null $clientResolution
823
     * @return $this
824
     */
825
    public function addBrowserData(
826
        $deviceFingerprint = '',
827
        $userAgent = '',
828
        $cpuClass = '',
829
        $screenOrientation = '',
830
        $screenResolution = '',
831
        $os = '',
832
        $timezoneOffset = null,
833
        $languages = '',
834
        $language = '',
835
        $languageBrowser = '',
836
        $languageUser = '',
837
        $languageSystem = '',
838
        $cookieEnabled = null,
839
        $doNotTrack = null,
840
        $ajaxValidation = null,
841
        $deviceId = '',
842
        $ipList = null,
843
        $plugins = null,
844
        $refererUrl = null,
845
        $originUrl = null,
846
        $clientResolution = null
847
    ) {
848
        if ($deviceFingerprint !== null && !is_string($deviceFingerprint)) {
849
            throw new \InvalidArgumentException('Device fingerprint must be string');
850
        }
851
        if ($userAgent !== null && !is_string($userAgent)) {
852
            throw new \InvalidArgumentException('User agent must be string');
853
        }
854
        if ($cpuClass !== null && !is_string($cpuClass)) {
855
            throw new \InvalidArgumentException('CPU class must be string');
856
        }
857
        if ($screenOrientation !== null && !is_string($screenOrientation)) {
858
            throw new \InvalidArgumentException('Screen orientation must be string');
859
        }
860
        if ($screenResolution !== null && !is_string($screenResolution)) {
861
            throw new \InvalidArgumentException('Screen resolution must be string');
862
        }
863
        if ($os !== null && !is_string($os)) {
864
            throw new \InvalidArgumentException('OS must be string');
865
        }
866
        if ($timezoneOffset !== null && $timezoneOffset !== null && !is_int($timezoneOffset)) {
867
            throw new \InvalidArgumentException('Timezone offset must be integer or null');
868
        }
869
        if ($languages !== null && !is_string($languages)) {
870
            throw new \InvalidArgumentException('Languages must be string');
871
        }
872
        if ($language !== null && !is_string($language)) {
873
            throw new \InvalidArgumentException('Language must be string');
874
        }
875
        if ($languageBrowser !== null && !is_string($languageBrowser)) {
876
            throw new \InvalidArgumentException('Browser language must be string');
877
        }
878
        if ($languageUser !== null && !is_string($languageUser)) {
879
            throw new \InvalidArgumentException('User language must be string');
880
        }
881
        if ($languageSystem !== null && !is_string($languageSystem)) {
882
            throw new \InvalidArgumentException('System language must be string');
883
        }
884
        if ($cookieEnabled !== null && !is_bool($cookieEnabled)) {
885
            throw new \InvalidArgumentException('Cookie enabled flag must be boolean');
886
        }
887
        if ($doNotTrack !== null && !is_bool($doNotTrack)) {
888
            throw new \InvalidArgumentException('DNT flag must be boolean');
889
        }
890
        if ($ajaxValidation !== null && !is_bool($ajaxValidation)) {
891
            throw new \InvalidArgumentException('AJAX validation flag must be boolean');
892
        }
893
        if ($deviceId !== null && !is_string($deviceId)) {
894
            throw new \InvalidArgumentException('Device id must be string');
895
        }
896
        if ($ipList !== null && !is_string($ipList)) {
897
            throw new \InvalidArgumentException('Ip list must be string');
898
        }
899
        if ($plugins !== null && !is_string($plugins)) {
900
            throw new \InvalidArgumentException('Plugins must be string');
901
        }
902
        if ($refererUrl !== null && !is_string($refererUrl)) {
903
            throw new \InvalidArgumentException('Referer url must be string');
904
        }
905
        if ($originUrl !== null && !is_string($originUrl)) {
906
            throw new \InvalidArgumentException('Origin url must be string');
907
        }
908
        if ($clientResolution !== null && !is_string($clientResolution)) {
909
            throw new \InvalidArgumentException('Client resolution must be string');
910
        }
911
912
        $this->replace('device_fingerprint', $deviceFingerprint);
913
        $this->replace('user_agent', $userAgent);
914
        $this->replace('cpu_class', $cpuClass);
915
        $this->replace('screen_orientation', $screenOrientation);
916
        $this->replace('screen_resolution', $screenResolution);
917
        $this->replace('os', $os);
918
        $this->replace('timezone_offset', $timezoneOffset);
919
        $this->replace('languages', $languages);
920
        $this->replace('language', $language);
921
        $this->replace('language_browser', $languageBrowser);
922
        $this->replace('language_system', $languageSystem);
923
        $this->replace('language_user', $languageUser);
924
        $this->replace('cookie_enabled', $cookieEnabled);
925
        $this->replace('do_not_track', $doNotTrack);
926
        $this->replace('ajax_validation', $ajaxValidation);
927
        $this->replace('device_id', $deviceId);
928
        $this->replace('local_ip_list', $ipList);
929
        $this->replace('plugins', $plugins);
930
        $this->replace('refererUrl', $refererUrl);
931
        $this->replace('originUrl', $originUrl);
932
        $this->replace('clientResolution', $clientResolution);
933
934
        return $this;
935
    }
936
937
    /**
938
     * Provides user data for envelope
939
     *
940
     * @param string|null $email
941
     * @param string|null $userId
942
     * @param string|null $phone
943
     * @param string|null $userName
944
     * @param string|null $firstName
945
     * @param string|null $lastName
946
     * @param string|null $gender
947
     * @param int|null $age
948
     * @param string|null $country
949
     * @param string|null $socialType
950
     * @param int|null $registrationTimestamp
951
     * @param int|null $loginTimeStamp
952
     * @param int|null $confirmationTimeStamp
953
     * @param bool|null $emailConfirmed
954
     * @param bool|null $phoneConfirmed
955
     * @param bool|null $loginFailed
956
     * @param int|null $birthDate
957
     * @param string|null $fullname
958
     * @param string|null $state
959
     * @param string|null $city
960
     * @param string|null $address
961
     * @param string|null $zip
962
     *
963
     * @return $this
964
     */
965
    public function addUserData(
966
        $email = '',
967
        $userId = '',
968
        $phone = '',
969
        $userName = '',
970
        $firstName = '',
971
        $lastName = '',
972
        $gender = '',
973
        $age = 0,
974
        $country = '',
975
        $socialType = '',
976
        $registrationTimestamp = 0,
977
        $loginTimeStamp = 0,
978
        $confirmationTimeStamp = 0,
979
        $emailConfirmed = null,
980
        $phoneConfirmed = null,
981
        $loginFailed = null,
982
        $birthDate = null,
983
        $fullname = null,
984
        $state = null,
985
        $city = null,
986
        $address = null,
987
        $zip = null
988
    )
989
    {
990
        if ($userName !== null && !is_string($userName)) {
991
            throw new \InvalidArgumentException('User name must be string');
992
        }
993
        if ($gender !== null && !is_string($gender)) {
994
            throw new \InvalidArgumentException('Gender must be string');
995
        }
996
        if ($age !== null && !is_int($age)) {
997
            throw new \InvalidArgumentException('Age must be integer');
998
        }
999
        if ($socialType !== null && !is_string($socialType)) {
1000
            throw new \InvalidArgumentException('Social type must be string');
1001
        }
1002
        if ($registrationTimestamp !== null && !is_int($registrationTimestamp)) {
1003
            throw new \InvalidArgumentException('Registration timestamp must be integer');
1004
        }
1005
        if ($loginTimeStamp !== null && !is_int($loginTimeStamp)) {
1006
            throw new \InvalidArgumentException('Login timestamp must be integer');
1007
        }
1008
        if ($confirmationTimeStamp !== null && !is_int($confirmationTimeStamp)) {
1009
            throw new \InvalidArgumentException('Confirmation timestamp must be integer');
1010
        }
1011
        if ($birthDate !== null && !is_int($birthDate)) {
1012
            throw new \InvalidArgumentException('Birthdate timestamp must be integer');
1013
        }
1014
        if ($emailConfirmed !== null && !is_bool($emailConfirmed)) {
1015
            throw new \InvalidArgumentException('Email confirmed flag must be boolean');
1016
        }
1017
        if ($phoneConfirmed !== null && !is_bool($phoneConfirmed)) {
1018
            throw new \InvalidArgumentException('Phone confirmed flag must be boolean');
1019
        }
1020
        if ($loginFailed !== null && !is_bool($loginFailed)) {
1021
            throw new \InvalidArgumentException('Login failed flag must be boolean');
1022
        }
1023
        if ($fullname !== null && !is_string($fullname)) {
1024
            throw new \InvalidArgumentException('Fullname must be string');
1025
        }
1026
        if ($state !== null && !is_string($state)) {
1027
            throw new \InvalidArgumentException('State must be string');
1028
        }
1029
        if ($city !== null && !is_string($city)) {
1030
            throw new \InvalidArgumentException('City must be string');
1031
        }
1032
        if ($address !== null && !is_string($address)) {
1033
            throw new \InvalidArgumentException('Address must be string');
1034
        }
1035
        if ($zip !== null && !is_string($zip)) {
1036
            throw new \InvalidArgumentException('Zip must be string');
1037
        }
1038
1039
        $this->addShortUserData($email, $userId, $phone, $firstName, $lastName, $country);
1040
1041
        $this->replace('user_name', $userName);
1042
        $this->replace('gender', $gender);
1043
        $this->replace('age', $age);
1044
        $this->replace('social_type', $socialType);
1045
        $this->replace('registration_timestamp', $registrationTimestamp);
1046
        $this->replace('login_timestamp', $loginTimeStamp);
1047
        $this->replace('confirmation_timestamp', $confirmationTimeStamp);
1048
        $this->replace('email_confirmed', $emailConfirmed);
1049
        $this->replace('phone_confirmed', $phoneConfirmed);
1050
        $this->replace('login_failed', $loginFailed);
1051
        $this->replace('birth_date', $birthDate);
1052
        $this->replace('fullname', $fullname);
1053
        $this->replace('state', $state);
1054
        $this->replace('city', $city);
1055
        $this->replace('address', $address);
1056
        $this->replace('zip', $zip);
1057
1058
        return $this;
1059
    }
1060
1061
    /**
1062
     * Provides user data for envelope
1063
     *
1064
     * @param string|null $email
1065
     * @param string|null $userId
1066
     * @param string|null $phone
1067
     * @param string|null $firstName
1068
     * @param string|null $lastName
1069
     * @param string|null $country
1070
     *
1071
     * @return $this
1072
     */
1073
    public function addShortUserData(
1074
        $email = '',
1075
        $userId = '',
1076
        $phone = '',
1077
        $firstName = '',
1078
        $lastName = '',
1079
        $country = ''
1080
    ) {
1081
        if ($email !== null && !is_string($email)) {
1082
            throw new \InvalidArgumentException('Email must be string');
1083
        }
1084
        if (is_int($userId)) {
1085
            $userId = strval($userId);
1086
        }
1087
        if ($userId !== null && !is_string($userId)) {
1088
            throw new \InvalidArgumentException('UserId must be string or integer');
1089
        }
1090
        if ($phone !== null && !is_string($phone)) {
1091
            throw new \InvalidArgumentException('Phone must be string');
1092
        }
1093
        if ($firstName !== null && !is_string($firstName)) {
1094
            throw new \InvalidArgumentException('First name must be string');
1095
        }
1096
        if ($lastName !== null && !is_string($lastName)) {
1097
            throw new \InvalidArgumentException('Last name must be string');
1098
        }
1099
        if ($country !== null && !is_string($country)) {
1100
            throw new \InvalidArgumentException('Country must be string');
1101
        }
1102
1103
        $this->replace('email', $email);
1104
        $this->replace('user_merchant_id', $userId);
1105
        $this->replace('phone', $phone);
1106
        $this->replace('firstname', $firstName);
1107
        $this->replace('lastname', $lastName);
1108
        $this->replace('country', $country);
1109
1110
        return $this;
1111
    }
1112
1113
    /**
1114
     * Provides credit card data to envelope
1115
     *
1116
     * @param string|null $transactionId
1117
     * @param string|null $transactionSource
1118
     * @param string|null $transactionType
1119
     * @param string|null $transactionMode
1120
     * @param string|null $transactionTimestamp
1121
     * @param string|null $transactionCurrency
1122
     * @param string|null $transactionAmount
1123
     * @param float|null $amountConverted
1124
     * @param string|null $paymentMethod
1125
     * @param string|null $paymentSystem
1126
     * @param string|null $paymentMidName
1127
     * @param string|null $paymentAccountId
1128
     *
1129
     * @return $this
1130
     */
1131
    public function addCCTransactionData(
1132
        $transactionId,
1133
        $transactionSource,
1134
        $transactionType,
1135
        $transactionMode,
1136
        $transactionTimestamp,
1137
        $transactionCurrency,
1138
        $transactionAmount,
1139
        $amountConverted = null,
1140
        $paymentMethod = null,
1141
        $paymentSystem = null,
1142
        $paymentMidName = null,
1143
        $paymentAccountId = null
1144
    ) {
1145
        if ($transactionId !== null && !is_string($transactionId)) {
1146
            throw new \InvalidArgumentException('Transaction ID must be string');
1147
        }
1148
        if ($transactionSource !== null && !is_string($transactionSource)) {
1149
            throw new \InvalidArgumentException('Transaction source must be string');
1150
        }
1151
        if ($transactionType !== null && !is_string($transactionType)) {
1152
            throw new \InvalidArgumentException('Transaction type must be string');
1153
        }
1154
        if ($transactionMode !== null && !is_string($transactionMode)) {
1155
            throw new \InvalidArgumentException('Transaction mode must be string');
1156
        }
1157
        if ($transactionTimestamp !== null && !is_int($transactionTimestamp)) {
1158
            throw new \InvalidArgumentException('Transaction timestamp must be integer');
1159
        }
1160
        if ($transactionAmount !== null && !is_int($transactionAmount) && !is_float($transactionAmount)) {
1161
            throw new \InvalidArgumentException('Transaction amount must be float');
1162
        }
1163
        if ($transactionCurrency !== null && !is_string($transactionCurrency)) {
1164
            throw new \InvalidArgumentException('Transaction currency must be string');
1165
        }
1166
        if ($paymentMethod !== null && !is_string($paymentMethod)) {
1167
            throw new \InvalidArgumentException('Payment method must be string');
1168
        }
1169
        if ($paymentSystem !== null && !is_string($paymentSystem)) {
1170
            throw new \InvalidArgumentException('Payment system must be string');
1171
        }
1172
        if ($paymentMidName !== null && !is_string($paymentMidName)) {
1173
            throw new \InvalidArgumentException('Payment MID name must be string');
1174
        }
1175
        if ($paymentAccountId !== null && !is_string($paymentAccountId)) {
1176
            throw new \InvalidArgumentException('Payment account id must be string');
1177
        }
1178 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...
1179
            throw new \InvalidArgumentException('Transaction amount converted must be float');
1180
        }
1181
1182
        $this->replace('transaction_id', $transactionId);
1183
        $this->replace('transaction_source', $transactionSource);
1184
        $this->replace('transaction_type', $transactionType);
1185
        $this->replace('transaction_mode', $transactionMode);
1186
        $this->replace('transaction_timestamp', $transactionTimestamp);
1187
        $this->replace('transaction_amount', floatval($transactionAmount));
1188
        $this->replace('transaction_amount_converted', floatval($amountConverted));
1189
        $this->replace('transaction_currency', $transactionCurrency);
1190
        $this->replace('payment_method', $paymentMethod);
1191
        $this->replace('payment_system', $paymentSystem);
1192
        $this->replace('payment_mid', $paymentMidName);
1193
        $this->replace('payment_account_id', $paymentAccountId);
1194
1195
        return $this;
1196
    }
1197
1198
    /**
1199
     * Provides Card data to envelope
1200
     *
1201
     * @param string|null $cardId
1202
     * @param int|null $cardBin
1203
     * @param string|null $cardLast4
1204
     * @param int|null $expirationMonth
1205
     * @param int|null $expirationYear
1206
     *
1207
     * @return $this
1208
     */
1209
    public function addCardData(
1210
        $cardBin,
1211
        $cardLast4,
1212
        $expirationMonth,
1213
        $expirationYear,
1214
        $cardId = null
1215
    ) {
1216
        if ($cardId !== null && !is_string($cardId)) {
1217
            throw new \InvalidArgumentException('Card ID must be string');
1218
        }
1219
        if ($cardBin !== null && !is_int($cardBin)) {
1220
            throw new \InvalidArgumentException('Card BIN must be integer');
1221
        }
1222
        if ($cardLast4 !== null && !is_string($cardLast4)) {
1223
            throw new \InvalidArgumentException('Card last4  must be string');
1224
        }
1225
        if ($expirationMonth !== null && !is_int($expirationMonth)) {
1226
            throw new \InvalidArgumentException('Expiration month must be integer');
1227
        }
1228
        if ($expirationYear !== null && !is_int($expirationYear)) {
1229
            throw new \InvalidArgumentException('Expiration year must be integer');
1230
        }
1231
1232
        $this->replace('card_id', $cardId);
1233
        $this->replace('card_bin', $cardBin);
1234
        $this->replace('card_last4', $cardLast4);
1235
        $this->replace('expiration_month', $expirationMonth);
1236
        $this->replace('expiration_year', $expirationYear);
1237
1238
        return $this;
1239
    }
1240
1241
    /**
1242
     * Provides billing data to envelope
1243
     *
1244
     * @param string|null $billingFirstName
1245
     * @param string|null $billingLastName
1246
     * @param string|null $billingFullName
1247
     * @param string|null $billingCountry
1248
     * @param string|null $billingState
1249
     * @param string|null $billingCity
1250
     * @param string|null $billingAddress
1251
     * @param string|null $billingZip
1252
     *
1253
     * @return $this
1254
     */
1255
    public function addBillingData(
1256
        $billingFirstName = null,
1257
        $billingLastName = null,
1258
        $billingFullName = null,
1259
        $billingCountry = null,
1260
        $billingState = null,
1261
        $billingCity = null,
1262
        $billingAddress = null,
1263
        $billingZip = null
1264
    ) {
1265
        if ($billingFirstName !== null && !is_string($billingFirstName)) {
1266
            throw new \InvalidArgumentException('Billing first name must be string');
1267
        }
1268
        if ($billingLastName !== null && !is_string($billingLastName)) {
1269
            throw new \InvalidArgumentException('Billing last name must be string');
1270
        }
1271
        if ($billingFullName !== null && !is_string($billingFullName)) {
1272
            throw new \InvalidArgumentException('Billing full name must be string');
1273
        }
1274
        if ($billingCountry !== null && !is_string($billingCountry)) {
1275
            throw new \InvalidArgumentException('Billing country name must be string');
1276
        }
1277
        if ($billingState !== null && !is_string($billingState)) {
1278
            throw new \InvalidArgumentException('Billing state must be string');
1279
        }
1280
        if ($billingCity !== null && !is_string($billingCity)) {
1281
            throw new \InvalidArgumentException('Billing city must be string');
1282
        }
1283
        if ($billingAddress !== null && !is_string($billingAddress)) {
1284
            throw new \InvalidArgumentException('Billing address must be string');
1285
        }
1286
        if ($billingZip !== null && !is_string($billingZip)) {
1287
            throw new \InvalidArgumentException('Billing zip must be string');
1288
        }
1289
1290
        $this->replace('billing_firstname', $billingFirstName);
1291
        $this->replace('billing_lastname', $billingLastName);
1292
        $this->replace('billing_fullname', $billingFullName);
1293
        $this->replace('billing_country', $billingCountry);
1294
        $this->replace('billing_state', $billingState);
1295
        $this->replace('billing_city', $billingCity);
1296
        $this->replace('billing_address', $billingAddress);
1297
        $this->replace('billing_zip', $billingZip);
1298
1299
        return $this;
1300
    }
1301
1302
    /**
1303
     * Provides product information to envelope
1304
     *
1305
     * @param float|null $productQuantity
1306
     * @param string|null $productName
1307
     * @param string|null $productDescription
1308
     *
1309
     * @return $this
1310
     */
1311 View Code Duplication
    public function addProductData(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
1312
        $productQuantity = null,
1313
        $productName = null,
1314
        $productDescription = null
1315
    ) {
1316
        if ($productQuantity !== null && !is_int($productQuantity) && !is_float($productQuantity)) {
1317
            throw new \InvalidArgumentException('Product quantity must be int or float');
1318
        }
1319
        if ($productName !== null && !is_string($productName)) {
1320
            throw new \InvalidArgumentException('Product name must be string');
1321
        }
1322
        if ($productDescription !== null && !is_string($productDescription)) {
1323
            throw new \InvalidArgumentException('Product description must be string');
1324
        }
1325
1326
        $this->replace('product_quantity', $productQuantity);
1327
        $this->replace('product_name', $productName);
1328
        $this->replace('product_description', $productDescription);
1329
1330
        return $this;
1331
    }
1332
1333
    /**
1334
     * Provides payout information to envelope
1335
     *
1336
     * @param string $payoutId
1337
     * @param int $payoutTimestamp
1338
     * @param int|float $payoutAmount
1339
     * @param string $payoutCurrency
1340
     * @param string|null $payoutCardId
1341
     * @param string|null $payoutAccountId
1342
     * @param string|null $payoutMethod
1343
     * @param string|null $payoutSystem
1344
     * @param string|null $payoutMid
1345
     * @param int|float|null $amountConverted
1346
     * @param int|null $payoutCardBin
1347
     * @param string|null $payoutCardLast4
1348
     * @param int|null $payoutExpirationMonth
1349
     * @param int|null $payoutExpirationYear
1350
     *
1351
     * @return $this
1352
     */
1353
    public function addPayoutData(
1354
        $payoutId,
1355
        $payoutTimestamp,
1356
        $payoutAmount,
1357
        $payoutCurrency,
1358
        $payoutCardId =  null,
1359
        $payoutAccountId = null,
1360
        $payoutMethod = null,
1361
        $payoutSystem = null,
1362
        $payoutMid = null,
1363
        $amountConverted = null,
1364
        $payoutCardBin = null,
1365
        $payoutCardLast4 = null,
1366
        $payoutExpirationMonth = null,
1367
        $payoutExpirationYear = null
1368
    ) {
1369
        if (!is_string($payoutId)) {
1370
            throw new \InvalidArgumentException('Payout ID must be string');
1371
        }
1372
        if (!is_int($payoutTimestamp)) {
1373
            throw new \InvalidArgumentException('Payout timestamp must be int');
1374
        }
1375
        if (!is_float($payoutAmount) && !is_int($payoutAmount)) {
1376
            throw new \InvalidArgumentException('Amount must be number');
1377
        }
1378
        if (!is_string($payoutCurrency)) {
1379
            throw new \InvalidArgumentException('Payout currency must be string');
1380
        }
1381
        if ($payoutAccountId !== null && !is_string($payoutAccountId)) {
1382
            throw new \InvalidArgumentException('Account ID must be string');
1383
        }
1384
        if ($payoutCardId !== null && !is_string($payoutCardId)) {
1385
            throw new \InvalidArgumentException('Card ID must be string');
1386
        }
1387
        if ($payoutMethod !== null && !is_string($payoutMethod)) {
1388
            throw new \InvalidArgumentException('Payout method must be string');
1389
        }
1390
        if ($payoutSystem !== null && !is_string($payoutSystem)) {
1391
            throw new \InvalidArgumentException('Payout system must be string');
1392
        }
1393
        if ($payoutMid !== null && !is_string($payoutMid)) {
1394
            throw new \InvalidArgumentException('Payout MID must be string');
1395
        }
1396 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...
1397
            throw new \InvalidArgumentException('Payout converted amount must be number');
1398
        }
1399
        if ($payoutCardBin !== null && !is_int($payoutCardBin)) {
1400
            throw new \InvalidArgumentException('Payout card BIN must be integer');
1401
        }
1402
        if ($payoutCardLast4 !== null && !is_string($payoutCardLast4)) {
1403
            throw new \InvalidArgumentException('Payout last 4 must be string');
1404
        }
1405
        if ($payoutExpirationMonth !== null && !is_int($payoutExpirationMonth)) {
1406
            throw new \InvalidArgumentException('Payout card expiration month must be integer');
1407
        }
1408
        if ($payoutExpirationYear !== null && !is_int($payoutExpirationYear)) {
1409
            throw new \InvalidArgumentException('Payout card expiration year must be integer');
1410
        }
1411
1412
        $this->replace('payout_id', $payoutId);
1413
        $this->replace('payout_timestamp', $payoutTimestamp);
1414
        $this->replace('payout_card_id', $payoutCardId);
1415
        $this->replace('payout_account_id', $payoutAccountId);
1416
        $this->replace('payout_amount', (float) $payoutAmount);
1417
        $this->replace('payout_currency', $payoutCurrency);
1418
        $this->replace('payout_method', $payoutMethod);
1419
        $this->replace('payout_system', $payoutSystem);
1420
        $this->replace('payout_mid', $payoutMid);
1421
        $this->replace('payout_amount_converted', (float) $amountConverted);
1422
        $this->replace('payout_card_bin', $payoutCardBin);
1423
        $this->replace('payout_card_last4', $payoutCardLast4);
1424
        $this->replace('payout_expiration_month', $payoutExpirationMonth);
1425
        $this->replace('payout_expiration_year', $payoutExpirationYear);
1426
1427
        return $this;
1428
    }
1429
1430
    /**
1431
     * Provides install information to envelope
1432
     *
1433
     * @param int $installTimestamp
1434
     *
1435
     * @return $this
1436
     */
1437
    public function addInstallData($installTimestamp)
1438
    {
1439
        if (!is_int($installTimestamp)) {
1440
            throw new \InvalidArgumentException('Install timestamp must be int');
1441
        }
1442
1443
        $this->replace('install_timestamp', $installTimestamp);
1444
1445
        return $this;
1446
    }
1447
1448
    /**
1449
     * Provides refund information to envelope
1450
     *
1451
     * @param string $refundId
1452
     * @param int|float $refundAmount
1453
     * @param string $refundCurrency
1454
     * @param int|null $refundTimestamp
1455
     * @param int|float|null $refundAmountConverted
1456
     * @param string|null $refundSource
1457
     * @param string|null $refundType
1458
     * @param string|null $refundCode
1459
     * @param string|null $refundReason
1460
     * @param string|null $agentId
1461
     * @param string|null $refundMethod
1462
     * @param string|null $refundSystem
1463
     * @param string|null $refundMid
1464
     *
1465
     * @return $this
1466
     */
1467
    public function addRefundData(
1468
        $refundId,
1469
        $refundTimestamp,
1470
        $refundAmount,
1471
        $refundCurrency,
1472
        $refundAmountConverted = null,
1473
        $refundSource = null,
1474
        $refundType = null,
1475
        $refundCode = null,
1476
        $refundReason = null,
1477
        $agentId = null,
1478
        $refundMethod = null,
1479
        $refundSystem = null,
1480
        $refundMid = null
1481
    ) {
1482
        if (!is_string($refundId)) {
1483
            throw new \InvalidArgumentException('Refund ID must be string');
1484
        }
1485
        if (!is_int($refundTimestamp)) {
1486
            throw new \InvalidArgumentException('Refund timestamp must be int');
1487
        }
1488
        if (!is_float($refundAmount) && !is_int($refundAmount)) {
1489
            throw new \InvalidArgumentException('Amount must be number');
1490
        }
1491
        if (!is_string($refundCurrency)) {
1492
            throw new \InvalidArgumentException('Refund currency must be string');
1493
        }
1494
        if ($refundAmountConverted !== null && !is_float($refundAmountConverted) && !is_int($refundAmountConverted)) {
1495
            throw new \InvalidArgumentException('Refund converted amount must be number');
1496
        }
1497
        if ($refundSource !== null && !is_string($refundSource)) {
1498
            throw new \InvalidArgumentException('Refund source must be string');
1499
        }
1500
        if ($refundType !== null && !is_string($refundType)) {
1501
            throw new \InvalidArgumentException('Refund type must be string');
1502
        }
1503
        if ($refundCode !== null && !is_string($refundCode)) {
1504
            throw new \InvalidArgumentException('Refund code must be string');
1505
        }
1506
        if ($refundReason !== null && !is_string($refundReason)) {
1507
            throw new \InvalidArgumentException('Refund reason must be string');
1508
        }
1509
        if ($agentId !== null && !is_string($agentId)) {
1510
            throw new \InvalidArgumentException('Agent id must be string');
1511
        }
1512
        if ($refundMethod !== null && !is_string($refundMethod)) {
1513
            throw new \InvalidArgumentException('Refund method must be string');
1514
        }
1515
        if ($refundSystem !== null && !is_string($refundSystem)) {
1516
            throw new \InvalidArgumentException('Refund system must be string');
1517
        }
1518
        if ($refundMid !== null && !is_string($refundMid)) {
1519
            throw new \InvalidArgumentException('Refund mid must be string');
1520
        }
1521
1522
        $this->replace('refund_id', $refundId);
1523
        $this->replace('refund_timestamp', $refundTimestamp);
1524
        $this->replace('refund_amount', $refundAmount);
1525
        $this->replace('refund_currency', $refundCurrency);
1526
        $this->replace('refund_amount_converted', $refundAmountConverted);
1527
        $this->replace('refund_source', $refundSource);
1528
        $this->replace('refund_type', $refundType);
1529
        $this->replace('refund_code', $refundCode);
1530
        $this->replace('refund_reason', $refundReason);
1531
        $this->replace('agent_id', $agentId);
1532
        $this->replace('refund_method', $refundMethod);
1533
        $this->replace('refund_system', $refundSystem);
1534
        $this->replace('refund_mid', $refundMid);
1535
1536
        return $this;
1537
    }
1538
1539
    /**
1540
     * Provides transfer information to envelope
1541
     *
1542
     * @param string $eventId
1543
     * @param int $eventTimestamp
1544
     * @param float $amount
1545
     * @param string $currency
1546
     * @param string $accountId
1547
     * @param string $secondAccountId
1548
     * @param string $accountSystem
1549
     * @param float|null $amountConverted
1550
     * @param string|null $method
1551
     * @param string|null $operation
1552
     * @param string|null $secondEmail
1553
     * @param string|null $secondPhone
1554
     * @param string|int $secondBirthDate
1555
     * @param string|null $secondFirstname
1556
     * @param string|null $secondLastname
1557
     * @param string|null $secondFullname
1558
     * @param string|null $secondState
1559
     * @param string|null $secondCity
1560
     * @param string|null $secondAddress
1561
     * @param string|null $secondZip
1562
     * @param string|null $secondGender
1563
     * @param string|null $secondCountry
1564
     *
1565
     * @return $this
1566
     */
1567
    public function addTransferData(
1568
        $eventId,
1569
        $eventTimestamp,
1570
        $amount,
1571
        $currency,
1572
        $accountId,
1573
        $secondAccountId,
1574
        $accountSystem,
1575
        $amountConverted = null,
1576
        $method = null,
1577
        $operation = null,
1578
        $secondEmail = null,
1579
        $secondPhone = null,
1580
        $secondBirthDate = null,
1581
        $secondFirstname = null,
1582
        $secondLastname = null,
1583
        $secondFullname = null,
1584
        $secondState = null,
1585
        $secondCity = null,
1586
        $secondAddress = null,
1587
        $secondZip = null,
1588
        $secondGender = null,
1589
        $secondCountry = null
1590
    ) {
1591
        if (!is_string($eventId)) {
1592
            throw new \InvalidArgumentException('Event ID must be string');
1593
        }
1594
        if (!is_int($eventTimestamp)) {
1595
            throw new \InvalidArgumentException('Event timestamp must be int');
1596
        }
1597
        if (!is_int($amount) && !is_float($amount)) {
1598
            throw new \InvalidArgumentException('Amount must be number');
1599
        }
1600
        if (!is_string($currency)) {
1601
            throw new \InvalidArgumentException('Currency must be string');
1602
        }
1603
        if (!is_string($accountId)) {
1604
            throw new \InvalidArgumentException('Account id must be string');
1605
        }
1606
        if (!is_string($secondAccountId)) {
1607
            throw new \InvalidArgumentException('Second account id must be string');
1608
        }
1609
        if (!is_string($accountSystem)) {
1610
            throw new \InvalidArgumentException('Account system must be string');
1611
        }
1612 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...
1613
            throw new \InvalidArgumentException('Amount converted must be number');
1614
        }
1615
        if ($method !== null && !is_string($method)) {
1616
            throw new \InvalidArgumentException('Method must be string');
1617
        }
1618
        if ($operation !== null && !is_string($operation)) {
1619
            throw new \InvalidArgumentException('Operation must be string');
1620
        }
1621
        if ($secondPhone !== null && !is_string($secondPhone)) {
1622
            throw new \InvalidArgumentException('Second phone must be string');
1623
        }
1624
        if ($secondEmail !== null && !is_string($secondEmail)) {
1625
            throw new \InvalidArgumentException('Second email must be string');
1626
        }
1627
        if ($secondBirthDate !== null && !is_int($secondBirthDate)) {
1628
            throw new \InvalidArgumentException('Second birth date must be int');
1629
        }
1630
        if ($secondFirstname !== null && !is_string($secondFirstname)) {
1631
            throw new \InvalidArgumentException('Second firstname must be string');
1632
        }
1633
        if ($secondLastname !== null && !is_string($secondLastname)) {
1634
            throw new \InvalidArgumentException('Second lastname must be string');
1635
        }
1636
        if ($secondFullname !== null && !is_string($secondFullname)) {
1637
            throw new \InvalidArgumentException('Second fullname must be string');
1638
        }
1639
        if ($secondState !== null && !is_string($secondState)) {
1640
            throw new \InvalidArgumentException('Second state must be string');
1641
        }
1642
        if ($secondCity !== null && !is_string($secondCity)) {
1643
            throw new \InvalidArgumentException('Second city must be string');
1644
        }
1645
        if ($secondAddress !== null && !is_string($secondAddress)) {
1646
            throw new \InvalidArgumentException('Second address must be string');
1647
        }
1648
        if ($secondZip !== null && !is_string($secondZip)) {
1649
            throw new \InvalidArgumentException('Second zip must be string');
1650
        }
1651
        if ($secondGender !== null && !is_string($secondGender)) {
1652
            throw new \InvalidArgumentException('Second gender must be string');
1653
        }
1654
        if ($secondCountry !== null && !is_string($secondCountry)) {
1655
            throw new \InvalidArgumentException('Second country must be string');
1656
        }
1657
1658
1659
        $this->replace('event_id', $eventId);
1660
        $this->replace('event_timestamp', $eventTimestamp);
1661
        $this->replace('amount', $amount);
1662
        $this->replace('currency', $currency);
1663
        $this->replace('account_id', $accountId);
1664
        $this->replace('second_account_id', $secondAccountId);
1665
        $this->replace('account_system', $accountSystem);
1666
        $this->replace('amount_converted', $amountConverted);
1667
        $this->replace('method', $method);
1668
        $this->replace('operation', $operation);
1669
        $this->replace('second_email', $secondEmail);
1670
        $this->replace('second_phone', $secondPhone);
1671
        $this->replace('second_birth_date', $secondBirthDate);
1672
        $this->replace('second_firstname', $secondFirstname);
1673
        $this->replace('second_lastname', $secondLastname);
1674
        $this->replace('second_fullname', $secondFullname);
1675
        $this->replace('second_state', $secondState);
1676
        $this->replace('second_city', $secondCity);
1677
        $this->replace('second_address', $secondAddress);
1678
        $this->replace('second_zip', $secondZip);
1679
        $this->replace('second_gender', $secondGender);
1680
        $this->replace('second_country', $secondCountry);
1681
        return $this;
1682
    }
1683
1684
    /**
1685
     * Provides postback information to envelope
1686
     *
1687
     * @param string|null $transactionStatus
1688
     * @param string|null $code
1689
     * @param string|null $reason
1690
     * @param string|null $secure3d
1691
     * @param string|null $avsResult
1692
     * @param string|null $cvvResult
1693
     * @param string|null $pspCode
1694
     * @param string|null $pspReason
1695
     * @param string|null $arn
1696
     * @param string|null $paymentAccountId
1697
     * @return $this
1698
     */
1699
    public function addPostbackData(
1700
        $transactionStatus = null,
1701
        $code = null,
1702
        $reason = null,
1703
        $secure3d = null,
1704
        $avsResult = null,
1705
        $cvvResult = null,
1706
        $pspCode = null,
1707
        $pspReason = null,
1708
        $arn = null,
1709
        $paymentAccountId = null
1710
    ) {
1711
        if ($transactionStatus !== null && !is_string($transactionStatus)) {
1712
            throw new \InvalidArgumentException('Transaction status must be string');
1713
        }
1714
        if ($code !== null && !is_string($code)) {
1715
            throw new \InvalidArgumentException('Code must be string');
1716
        }
1717
        if ($reason !== null && !is_string($reason)) {
1718
            throw new \InvalidArgumentException('Reason must be string');
1719
        }
1720
        if ($secure3d !== null && !is_string($secure3d)) {
1721
            throw new \InvalidArgumentException('Secure3d must be string');
1722
        }
1723
        if ($avsResult !== null && !is_string($avsResult)) {
1724
            throw new \InvalidArgumentException('AvsResult must be string');
1725
        }
1726
        if ($cvvResult !== null && !is_string($cvvResult)) {
1727
            throw new \InvalidArgumentException('CvvResult must be string');
1728
        }
1729
        if ($pspCode !== null && !is_string($pspCode)) {
1730
            throw new \InvalidArgumentException('PspCode must be string');
1731
        }
1732
        if ($pspReason !== null && !is_string($pspReason)) {
1733
            throw new \InvalidArgumentException('PspReason must be string');
1734
        }
1735
        if ($arn !== null && !is_string($arn)) {
1736
            throw new \InvalidArgumentException('Arn must be string');
1737
        }
1738
        if ($paymentAccountId !== null && !is_string($paymentAccountId)) {
1739
            throw new \InvalidArgumentException('PaymentAccoutId must be string');
1740
        }
1741
1742
1743
        $this->replace('transaction_status', $transactionStatus);
1744
        $this->replace('code', $code);
1745
        $this->replace('reason', $reason);
1746
        $this->replace('secure3d', $secure3d);
1747
        $this->replace('avs_result', $avsResult);
1748
        $this->replace('cvv_result', $cvvResult);
1749
        $this->replace('psp_code', $pspCode);
1750
        $this->replace('psp_reason', $pspReason);
1751
        $this->replace('arn', $arn);
1752
        $this->replace('payment_account_id', $paymentAccountId);
1753
1754
        return $this;
1755
    }
1756
1757
    /**
1758
     * Adds custom data field to envelope
1759
     *
1760
     * @param string $name
1761
     * @param string $value
1762
     *
1763
     * @return $this
1764
     */
1765
    public function addCustomField($name, $value)
1766
    {
1767
        if (!is_string($name)) {
1768
            throw new \InvalidArgumentException('Custom field name must be string');
1769
        }
1770
        if (!is_string($value)) {
1771
            throw new \InvalidArgumentException('Custom field value must be string');
1772
        }
1773
1774
        if (strlen($name) < 8 || substr($name, 0, 7) !== 'custom_') {
1775
            $name = 'custom_' . $name;
1776
        }
1777
1778
        $this->replace($name, $value);
1779
        return $this;
1780
    }
1781
}
1782