Completed
Push — master ( 7d77ac...7bab5f )
by
unknown
11s
created

Builder::addUserData()   F

Complexity

Conditions 35
Paths 18

Size

Total Lines 100

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 100
rs 3.3333
c 0
b 0
f 0
cc 35
nc 18
nop 23

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