Completed
Pull Request — master (#9)
by
unknown
03:44
created

Builder::addTransferData()   D

Complexity

Conditions 40
Paths 23

Size

Total Lines 116
Code Lines 90

Duplication

Lines 3
Ratio 2.59 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 3
loc 116
rs 4.1818
cc 40
eloc 90
nc 23
nop 22

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
     *
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
    ) {
469
        $builder = new self('refund', $sequenceId);
470
        if ($refundTimestamp === null) {
471
            $refundTimestamp = time();
472
        }
473
474
        return $builder->addRefundData(
475
            $refundId,
476
            $refundTimestamp,
477
            $refundAmount,
478
            $refundCurrency,
479
            $refundAmountConverted,
480
            $refundSource,
481
            $refundType,
482
            $refundCode,
483
            $refundReason,
484
            $agentId,
485
            $refundMethod,
486
            $refundSystem,
487
            $refundMid
488
        );
489
    }
490
491
    /**
492
     * Returns builder for transfer request
493
     *
494
     * @param string $sequenceId
495
     * @param string $eventId
496
     * @param float $amount
497
     * @param string $currency
498
     * @param string $accountId
499
     * @param string $secondAccountId
500
     * @param string $accountSystem
501
     * @param string $userId
502
     * @param int|null $eventTimestamp
503
     * @param float|null $amountConverted
504
     * @param string|null $method
505
     * @param string|null $email
506
     * @param string|null $phone
507
     * @param int|null $birthDate
508
     * @param string|null $firstname
509
     * @param string|null $lastname
510
     * @param string|null $fullname
511
     * @param string|null $state
512
     * @param string|null $city
513
     * @param string|null $address
514
     * @param string|null $zip
515
     * @param string|null $gender
516
     * @param string|null $country
517
     * @param string|null $operation
518
     * @param string|null $secondEmail
519
     * @param string|null $secondPhone
520
     * @param int|null $secondBirthDate
521
     * @param string|null $secondFirstname
522
     * @param string|null $secondLastname
523
     * @param string|null $secondFullname
524
     * @param string|null $secondState
525
     * @param string|null $secondCity
526
     * @param string|null $secondAddress
527
     * @param string|null $secondZip
528
     * @param string|null $secondGender
529
     * @param string|null $secondCountry
530
     * @param string|null $productDescription
531
     * @param string|null $productName
532
     * @param int|float|null $productQuantity
533
     *
534
     * @return Builder
535
     */
536
    public static function transferEvent(
537
        $sequenceId,
538
        $eventId,
539
        $amount,
540
        $currency,
541
        $accountId,
542
        $secondAccountId,
543
        $accountSystem,
544
        $userId,
545
        $method = null,
546
        $eventTimestamp = null,
547
        $amountConverted = null,
548
        $email = null,
549
        $phone = null,
550
        $birthDate = null,
551
        $firstname = null,
552
        $lastname = null,
553
        $fullname = null,
554
        $state = null,
555
        $city = null,
556
        $address = null,
557
        $zip = null,
558
        $gender = null,
559
        $country = null,
560
        $operation = null,
561
        $secondEmail = null,
562
        $secondPhone = null,
563
        $secondBirthDate = null,
564
        $secondFirstname = null,
565
        $secondLastname = null,
566
        $secondFullname = null,
567
        $secondState = null,
568
        $secondCity = null,
569
        $secondAddress = null,
570
        $secondZip = null,
571
        $secondGender = null,
572
        $secondCountry = null,
573
        $productDescription = null,
574
        $productName = null,
575
        $productQuantity = null
576
577
    ) {
578
        $builder = new self('transfer', $sequenceId);
579
        if ($eventTimestamp === null) {
580
            $eventTimestamp = time();
581
        }
582
583
        return $builder
584
            ->addTransferData(
585
               $eventId,
586
               $eventTimestamp,
587
               $amount,
588
               $currency,
589
               $accountId,
590
               $secondAccountId,
591
               $accountSystem,
592
               $amountConverted,
593
               $method,
594
               $operation,
595
               $secondEmail,
596
               $secondPhone,
597
               $secondBirthDate,
598
               $secondFirstname,
599
               $secondLastname,
600
               $secondFullname,
601
               $secondState,
602
               $secondCity,
603
               $secondAddress,
604
               $secondZip,
605
               $secondGender,
606
               $secondCountry
607
            )
608
            ->addUserData(
609
                $email,
610
                $userId,
611
                $phone,
612
                null,
613
                $firstname,
614
                $lastname,
615
                $gender,
616
                null,
617
                $country,
618
                null,
619
                null,
620
                null,
621
                null,
622
                null,
623
                null,
624
                null,
625
                $birthDate,
626
                $fullname,
627
                $state,
628
                $city,
629
                $address,
630
                $zip
631
            )
632
            ->addProductData($productQuantity, $productName, $productDescription);
633
    }
634
635
    /**
636
     * Returns builder for postback request
637
     *
638
     * @param $sequenceId
639
     * @param string|null $transactionStatus
640
     * @param string|null $code
641
     * @param string|null $reason
642
     * @param string|null $secure3d
643
     * @param string|null $avsResult
644
     * @param string|null $cvvResult
645
     * @param string|null $pspCode
646
     * @param string|null $pspReason
647
     * @param string|null $arn
648
     * @param string|null $paymentAccountId
649
     * @return Builder
650
     */
651
    public static function postBackEvent(
652
        $sequenceId,
653
        $transactionStatus = null,
654
        $code = null,
655
        $reason = null,
656
        $secure3d = null,
657
        $avsResult = null,
658
        $cvvResult = null,
659
        $pspCode = null,
660
        $pspReason = null,
661
        $arn = null,
662
        $paymentAccountId = null
663
    ) {
664
        $builder = new self('postback', $sequenceId);
665
        return $builder->addPostBackData(
666
            $transactionStatus,
667
            $code,
668
            $reason,
669
            $secure3d,
670
            $avsResult,
671
            $cvvResult,
672
            $pspCode,
673
            $pspReason,
674
            $arn,
675
            $paymentAccountId
676
       );
677
    }
678
679
    /**
680
     * Builder constructor.
681
     *
682
     * @param string $envelopeType
683
     * @param string $sequenceId
684
     */
685
    public function __construct($envelopeType, $sequenceId)
686
    {
687
        if (!is_string($envelopeType)) {
688
            throw new \InvalidArgumentException('Envelope type must be string');
689
        }
690
        if (!is_string($sequenceId)) {
691
            throw new \InvalidArgumentException('Sequence ID must be string');
692
        }
693
694
        $this->type = $envelopeType;
695
        $this->sequenceId = $sequenceId;
696
    }
697
698
    /**
699
     * Returns built envelope
700
     *
701
     * @return EnvelopeInterface
702
     */
703
    public function build()
704
    {
705
        return new Envelope(
706
            $this->type,
707
            $this->sequenceId,
708
            $this->identities,
709
            array_filter($this->data, function ($data) {
710
                return $data !== null;
711
            })
712
        );
713
    }
714
715
    /**
716
     * Replaces value in internal array if provided value not empty
717
     *
718
     * @param string $key
719
     * @param string|int|float|bool|null $value
720
     */
721
    private function replace($key, $value)
722
    {
723
        if ($value !== null && $value !== '' && $value !== 0 && $value !== 0.0) {
724
            $this->data[$key] = $value;
725
        }
726
    }
727
728
    /**
729
     * Adds identity node
730
     *
731
     * @param IdentityNodeInterface $identity
732
     *
733
     * @return $this
734
     */
735
    public function addIdentity(IdentityNodeInterface $identity)
736
    {
737
        $this->identities[] = $identity;
738
        return $this;
739
    }
740
741
    /**
742
     * Provides website URL to envelope
743
     *
744
     * @param string|null $websiteUrl
745
     * @param string|null $traffic_source
746
     * @param string|null $affiliate_id
747
     *
748
     * @return $this
749
     */
750 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...
751
    {
752
        if ($websiteUrl !== null && !is_string($websiteUrl)) {
753
            throw new \InvalidArgumentException('Website URL must be string');
754
        }
755
        if ($traffic_source !== null && !is_string($traffic_source)) {
756
            throw new \InvalidArgumentException('Traffic source must be string');
757
        }
758
        if ($affiliate_id !== null && !is_string($affiliate_id)) {
759
            throw new \InvalidArgumentException('Affiliate ID must be string');
760
        }
761
762
        $this->replace('website_url', $websiteUrl);
763
        $this->replace('traffic_source', $traffic_source);
764
        $this->replace('affiliate_id', $affiliate_id);
765
        return $this;
766
    }
767
768
    /**
769
     * Provides IP information for envelope
770
     *
771
     * @param string|null $ip User's IP address
772
     * @param string|null $realIp User's real IP address, if available
773
     * @param string|null $merchantIp Your website's IP address
774
     *
775
     * @return $this
776
     */
777
    public function addIpData($ip = '', $realIp = '', $merchantIp = '')
778
    {
779
        if ($ip !== null && !is_string($ip)) {
780
            throw new \InvalidArgumentException('IP must be string');
781
        }
782
        if ($realIp !== null && !is_string($realIp)) {
783
            throw new \InvalidArgumentException('Real IP must be string');
784
        }
785
        if ($merchantIp !== null && !is_string($merchantIp)) {
786
            throw new \InvalidArgumentException('Merchant IP must be string');
787
        }
788
789
        $this->replace('ip', $ip);
790
        $this->replace('real_ip', $realIp);
791
        $this->replace('merchant_ip', $merchantIp);
792
793
        return $this;
794
    }
795
796
    /**
797
     * Provides browser information for envelope
798
     *
799
     * @param string|null $deviceFingerprint
800
     * @param string|null $userAgent
801
     * @param string|null $cpuClass
802
     * @param string|null $screenOrientation
803
     * @param string|null $screenResolution
804
     * @param string|null $os
805
     * @param int|null $timezoneOffset
806
     * @param string|null $languages
807
     * @param string|null $language
808
     * @param string|null $languageBrowser
809
     * @param string|null $languageUser
810
     * @param string|null $languageSystem
811
     * @param bool|null $cookieEnabled
812
     * @param bool|null $doNotTrack
813
     * @param bool|null $ajaxValidation
814
     * @param string|null $deviceId
815
     *
816
     * @return $this
817
     */
818
    public function addBrowserData(
819
        $deviceFingerprint = '',
820
        $userAgent = '',
821
        $cpuClass = '',
822
        $screenOrientation = '',
823
        $screenResolution = '',
824
        $os = '',
825
        $timezoneOffset = null,
826
        $languages = '',
827
        $language = '',
828
        $languageBrowser = '',
829
        $languageUser = '',
830
        $languageSystem = '',
831
        $cookieEnabled = null,
832
        $doNotTrack = null,
833
        $ajaxValidation = null,
834
        $deviceId = ''
835
    ) {
836
        if ($deviceFingerprint !== null && !is_string($deviceFingerprint)) {
837
            throw new \InvalidArgumentException('Device fingerprint must be string');
838
        }
839
        if ($userAgent !== null && !is_string($userAgent)) {
840
            throw new \InvalidArgumentException('User agent must be string');
841
        }
842
        if ($cpuClass !== null && !is_string($cpuClass)) {
843
            throw new \InvalidArgumentException('CPU class must be string');
844
        }
845
        if ($screenOrientation !== null && !is_string($screenOrientation)) {
846
            throw new \InvalidArgumentException('Screen orientation must be string');
847
        }
848
        if ($screenResolution !== null && !is_string($screenResolution)) {
849
            throw new \InvalidArgumentException('Screen resolution must be string');
850
        }
851
        if ($os !== null && !is_string($os)) {
852
            throw new \InvalidArgumentException('OS must be string');
853
        }
854
        if ($timezoneOffset !== null && $timezoneOffset !== null && !is_int($timezoneOffset)) {
855
            throw new \InvalidArgumentException('Timezone offset must be integer or null');
856
        }
857
        if ($languages !== null && !is_string($languages)) {
858
            throw new \InvalidArgumentException('Languages must be string');
859
        }
860
        if ($language !== null && !is_string($language)) {
861
            throw new \InvalidArgumentException('Language must be string');
862
        }
863
        if ($languageBrowser !== null && !is_string($languageBrowser)) {
864
            throw new \InvalidArgumentException('Browser language must be string');
865
        }
866
        if ($languageUser !== null && !is_string($languageUser)) {
867
            throw new \InvalidArgumentException('User language must be string');
868
        }
869
        if ($languageSystem !== null && !is_string($languageSystem)) {
870
            throw new \InvalidArgumentException('System language must be string');
871
        }
872
        if ($cookieEnabled !== null && !is_bool($cookieEnabled)) {
873
            throw new \InvalidArgumentException('Cookie enabled flag must be boolean');
874
        }
875
        if ($doNotTrack !== null && !is_bool($doNotTrack)) {
876
            throw new \InvalidArgumentException('DNT flag must be boolean');
877
        }
878
        if ($ajaxValidation !== null && !is_bool($ajaxValidation)) {
879
            throw new \InvalidArgumentException('AJAX validation flag must be boolean');
880
        }
881
        if ($deviceId !== null && !is_string($deviceId)) {
882
            throw new \InvalidArgumentException('Device id must be string');
883
        }
884
885
        $this->replace('device_fingerprint', $deviceFingerprint);
886
        $this->replace('user_agent', $userAgent);
887
        $this->replace('cpu_class', $cpuClass);
888
        $this->replace('screen_orientation', $screenOrientation);
889
        $this->replace('screen_resolution', $screenResolution);
890
        $this->replace('os', $os);
891
        $this->replace('timezone_offset', $timezoneOffset);
892
        $this->replace('languages', $languages);
893
        $this->replace('language', $language);
894
        $this->replace('language_browser', $languageBrowser);
895
        $this->replace('language_system', $languageSystem);
896
        $this->replace('language_user', $languageUser);
897
        $this->replace('cookie_enabled', $cookieEnabled);
898
        $this->replace('do_not_track', $doNotTrack);
899
        $this->replace('ajax_validation', $ajaxValidation);
900
        $this->replace('device_id', $deviceId);
901
902
        return $this;
903
    }
904
905
    /**
906
     * Provides user data for envelope
907
     *
908
     * @param string|null $email
909
     * @param string|null $userId
910
     * @param string|null $phone
911
     * @param string|null $userName
912
     * @param string|null $firstName
913
     * @param string|null $lastName
914
     * @param string|null $gender
915
     * @param int|null $age
916
     * @param string|null $country
917
     * @param string|null $socialType
918
     * @param int|null $registrationTimestamp
919
     * @param int|null $loginTimeStamp
920
     * @param int|null $confirmationTimeStamp
921
     * @param bool|null $emailConfirmed
922
     * @param bool|null $phoneConfirmed
923
     * @param bool|null $loginFailed
924
     * @param int|null $birthDate
925
     * @param string|null $fullname
926
     * @param string|null $state
927
     * @param string|null $city
928
     * @param string|null $address
929
     * @param string|null $zip
930
     *
931
     * @return $this
932
     */
933
    public function addUserData(
934
        $email = '',
935
        $userId = '',
936
        $phone = '',
937
        $userName = '',
938
        $firstName = '',
939
        $lastName = '',
940
        $gender = '',
941
        $age = 0,
942
        $country = '',
943
        $socialType = '',
944
        $registrationTimestamp = 0,
945
        $loginTimeStamp = 0,
946
        $confirmationTimeStamp = 0,
947
        $emailConfirmed = null,
948
        $phoneConfirmed = null,
949
        $loginFailed = null,
950
        $birthDate = null,
951
        $fullname = null,
952
        $state = null,
953
        $city = null,
954
        $address = null,
955
        $zip = null
956
    )
957
    {
958
        if ($userName !== null && !is_string($userName)) {
959
            throw new \InvalidArgumentException('User name must be string');
960
        }
961
        if ($gender !== null && !is_string($gender)) {
962
            throw new \InvalidArgumentException('Gender must be string');
963
        }
964
        if ($age !== null && !is_int($age)) {
965
            throw new \InvalidArgumentException('Age must be integer');
966
        }
967
        if ($socialType !== null && !is_string($socialType)) {
968
            throw new \InvalidArgumentException('Social type must be string');
969
        }
970
        if ($registrationTimestamp !== null && !is_int($registrationTimestamp)) {
971
            throw new \InvalidArgumentException('Registration timestamp must be integer');
972
        }
973
        if ($loginTimeStamp !== null && !is_int($loginTimeStamp)) {
974
            throw new \InvalidArgumentException('Login timestamp must be integer');
975
        }
976
        if ($confirmationTimeStamp !== null && !is_int($confirmationTimeStamp)) {
977
            throw new \InvalidArgumentException('Confirmation timestamp must be integer');
978
        }
979
        if ($birthDate !== null && !is_int($birthDate)) {
980
            throw new \InvalidArgumentException('Birthdate timestamp must be integer');
981
        }
982
        if ($emailConfirmed !== null && !is_bool($emailConfirmed)) {
983
            throw new \InvalidArgumentException('Email confirmed flag must be boolean');
984
        }
985
        if ($phoneConfirmed !== null && !is_bool($phoneConfirmed)) {
986
            throw new \InvalidArgumentException('Phone confirmed flag must be boolean');
987
        }
988
        if ($loginFailed !== null && !is_bool($loginFailed)) {
989
            throw new \InvalidArgumentException('Login failed flag must be boolean');
990
        }
991
        if ($fullname !== null && !is_string($fullname)) {
992
            throw new \InvalidArgumentException('Fullname must be string');
993
        }
994
        if ($state !== null && !is_string($state)) {
995
            throw new \InvalidArgumentException('State must be string');
996
        }
997
        if ($city !== null && !is_string($city)) {
998
            throw new \InvalidArgumentException('City must be string');
999
        }
1000
        if ($address !== null && !is_string($address)) {
1001
            throw new \InvalidArgumentException('Address must be string');
1002
        }
1003
        if ($zip !== null && !is_string($zip)) {
1004
            throw new \InvalidArgumentException('Zip must be string');
1005
        }
1006
1007
        $this->addShortUserData($email, $userId, $phone, $firstName, $lastName, $country);
1008
1009
        $this->replace('user_name', $userName);
1010
        $this->replace('gender', $gender);
1011
        $this->replace('age', $age);
1012
        $this->replace('social_type', $socialType);
1013
        $this->replace('registration_timestamp', $registrationTimestamp);
1014
        $this->replace('login_timestamp', $loginTimeStamp);
1015
        $this->replace('confirmation_timestamp', $confirmationTimeStamp);
1016
        $this->replace('email_confirmed', $emailConfirmed);
1017
        $this->replace('phone_confirmed', $phoneConfirmed);
1018
        $this->replace('login_failed', $loginFailed);
1019
        $this->replace('birth_date', $birthDate);
1020
        $this->replace('fullname', $fullname);
1021
        $this->replace('state', $state);
1022
        $this->replace('city', $city);
1023
        $this->replace('address', $address);
1024
        $this->replace('zip', $zip);
1025
1026
        return $this;
1027
    }
1028
1029
    /**
1030
     * Provides user data for envelope
1031
     *
1032
     * @param string|null $email
1033
     * @param string|null $userId
1034
     * @param string|null $phone
1035
     * @param string|null $firstName
1036
     * @param string|null $lastName
1037
     * @param string|null $country
1038
     *
1039
     * @return $this
1040
     */
1041
    public function addShortUserData(
1042
        $email = '',
1043
        $userId = '',
1044
        $phone = '',
1045
        $firstName = '',
1046
        $lastName = '',
1047
        $country = ''
1048
    ) {
1049
        if ($email !== null && !is_string($email)) {
1050
            throw new \InvalidArgumentException('Email must be string');
1051
        }
1052
        if (is_int($userId)) {
1053
            $userId = strval($userId);
1054
        }
1055
        if ($userId !== null && !is_string($userId)) {
1056
            throw new \InvalidArgumentException('UserId must be string or integer');
1057
        }
1058
        if ($phone !== null && !is_string($phone)) {
1059
            throw new \InvalidArgumentException('Phone must be string');
1060
        }
1061
        if ($firstName !== null && !is_string($firstName)) {
1062
            throw new \InvalidArgumentException('First name must be string');
1063
        }
1064
        if ($lastName !== null && !is_string($lastName)) {
1065
            throw new \InvalidArgumentException('Last name must be string');
1066
        }
1067
        if ($country !== null && !is_string($country)) {
1068
            throw new \InvalidArgumentException('Country must be string');
1069
        }
1070
1071
        $this->replace('email', $email);
1072
        $this->replace('user_merchant_id', $userId);
1073
        $this->replace('phone', $phone);
1074
        $this->replace('firstname', $firstName);
1075
        $this->replace('lastname', $lastName);
1076
        $this->replace('country', $country);
1077
1078
        return $this;
1079
    }
1080
1081
    /**
1082
     * Provides credit card data to envelope
1083
     *
1084
     * @param string|null $transactionId
1085
     * @param string|null $transactionSource
1086
     * @param string|null $transactionType
1087
     * @param string|null $transactionMode
1088
     * @param string|null $transactionTimestamp
1089
     * @param string|null $transactionCurrency
1090
     * @param string|null $transactionAmount
1091
     * @param float|null $amountConverted
1092
     * @param string|null $paymentMethod
1093
     * @param string|null $paymentSystem
1094
     * @param string|null $paymentMidName
1095
     * @param string|null $paymentAccountId
1096
     *
1097
     * @return $this
1098
     */
1099
    public function addCCTransactionData(
1100
        $transactionId,
1101
        $transactionSource,
1102
        $transactionType,
1103
        $transactionMode,
1104
        $transactionTimestamp,
1105
        $transactionCurrency,
1106
        $transactionAmount,
1107
        $amountConverted = null,
1108
        $paymentMethod = null,
1109
        $paymentSystem = null,
1110
        $paymentMidName = null,
1111
        $paymentAccountId = null
1112
    ) {
1113
        if ($transactionId !== null && !is_string($transactionId)) {
1114
            throw new \InvalidArgumentException('Transaction ID must be string');
1115
        }
1116
        if ($transactionSource !== null && !is_string($transactionSource)) {
1117
            throw new \InvalidArgumentException('Transaction source must be string');
1118
        }
1119
        if ($transactionType !== null && !is_string($transactionType)) {
1120
            throw new \InvalidArgumentException('Transaction type must be string');
1121
        }
1122
        if ($transactionMode !== null && !is_string($transactionMode)) {
1123
            throw new \InvalidArgumentException('Transaction mode must be string');
1124
        }
1125
        if ($transactionTimestamp !== null && !is_int($transactionTimestamp)) {
1126
            throw new \InvalidArgumentException('Transaction timestamp must be integer');
1127
        }
1128
        if ($transactionAmount !== null && !is_int($transactionAmount) && !is_float($transactionAmount)) {
1129
            throw new \InvalidArgumentException('Transaction amount must be float');
1130
        }
1131
        if ($transactionCurrency !== null && !is_string($transactionCurrency)) {
1132
            throw new \InvalidArgumentException('Transaction currency must be string');
1133
        }
1134
        if ($paymentMethod !== null && !is_string($paymentMethod)) {
1135
            throw new \InvalidArgumentException('Payment method must be string');
1136
        }
1137
        if ($paymentSystem !== null && !is_string($paymentSystem)) {
1138
            throw new \InvalidArgumentException('Payment system must be string');
1139
        }
1140
        if ($paymentMidName !== null && !is_string($paymentMidName)) {
1141
            throw new \InvalidArgumentException('Payment MID name must be string');
1142
        }
1143
        if ($paymentAccountId !== null && !is_string($paymentAccountId)) {
1144
            throw new \InvalidArgumentException('Payment account id must be string');
1145
        }
1146 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...
1147
            throw new \InvalidArgumentException('Transaction amount converted must be float');
1148
        }
1149
1150
        $this->replace('transaction_id', $transactionId);
1151
        $this->replace('transaction_source', $transactionSource);
1152
        $this->replace('transaction_type', $transactionType);
1153
        $this->replace('transaction_mode', $transactionMode);
1154
        $this->replace('transaction_timestamp', $transactionTimestamp);
1155
        $this->replace('transaction_amount', floatval($transactionAmount));
1156
        $this->replace('transaction_amount_converted', floatval($amountConverted));
1157
        $this->replace('transaction_currency', $transactionCurrency);
1158
        $this->replace('payment_method', $paymentMethod);
1159
        $this->replace('payment_system', $paymentSystem);
1160
        $this->replace('payment_mid', $paymentMidName);
1161
        $this->replace('payment_account_id', $paymentAccountId);
1162
1163
        return $this;
1164
    }
1165
1166
    /**
1167
     * Provides Card data to envelope
1168
     *
1169
     * @param string|null $cardId
1170
     * @param int|null $cardBin
1171
     * @param string|null $cardLast4
1172
     * @param int|null $expirationMonth
1173
     * @param int|null $expirationYear
1174
     *
1175
     * @return $this
1176
     */
1177
    public function addCardData(
1178
        $cardBin,
1179
        $cardLast4,
1180
        $expirationMonth,
1181
        $expirationYear,
1182
        $cardId = null
1183
    ) {
1184
        if ($cardId !== null && !is_string($cardId)) {
1185
            throw new \InvalidArgumentException('Card ID must be string');
1186
        }
1187
        if ($cardBin !== null && !is_int($cardBin)) {
1188
            throw new \InvalidArgumentException('Card BIN must be integer');
1189
        }
1190
        if ($cardLast4 !== null && !is_string($cardLast4)) {
1191
            throw new \InvalidArgumentException('Card last4  must be string');
1192
        }
1193
        if ($expirationMonth !== null && !is_int($expirationMonth)) {
1194
            throw new \InvalidArgumentException('Expiration month must be integer');
1195
        }
1196
        if ($expirationYear !== null && !is_int($expirationYear)) {
1197
            throw new \InvalidArgumentException('Expiration year must be integer');
1198
        }
1199
1200
        $this->replace('card_id', $cardId);
1201
        $this->replace('card_bin', $cardBin);
1202
        $this->replace('card_last4', $cardLast4);
1203
        $this->replace('expiration_month', $expirationMonth);
1204
        $this->replace('expiration_year', $expirationYear);
1205
1206
        return $this;
1207
    }
1208
1209
    /**
1210
     * Provides billing data to envelope
1211
     *
1212
     * @param string|null $billingFirstName
1213
     * @param string|null $billingLastName
1214
     * @param string|null $billingFullName
1215
     * @param string|null $billingCountry
1216
     * @param string|null $billingState
1217
     * @param string|null $billingCity
1218
     * @param string|null $billingAddress
1219
     * @param string|null $billingZip
1220
     *
1221
     * @return $this
1222
     */
1223
    public function addBillingData(
1224
        $billingFirstName = null,
1225
        $billingLastName = null,
1226
        $billingFullName = null,
1227
        $billingCountry = null,
1228
        $billingState = null,
1229
        $billingCity = null,
1230
        $billingAddress = null,
1231
        $billingZip = null
1232
    ) {
1233
        if ($billingFirstName !== null && !is_string($billingFirstName)) {
1234
            throw new \InvalidArgumentException('Billing first name must be string');
1235
        }
1236
        if ($billingLastName !== null && !is_string($billingLastName)) {
1237
            throw new \InvalidArgumentException('Billing last name must be string');
1238
        }
1239
        if ($billingFullName !== null && !is_string($billingFullName)) {
1240
            throw new \InvalidArgumentException('Billing full name must be string');
1241
        }
1242
        if ($billingCountry !== null && !is_string($billingCountry)) {
1243
            throw new \InvalidArgumentException('Billing country name must be string');
1244
        }
1245
        if ($billingState !== null && !is_string($billingState)) {
1246
            throw new \InvalidArgumentException('Billing state must be string');
1247
        }
1248
        if ($billingCity !== null && !is_string($billingCity)) {
1249
            throw new \InvalidArgumentException('Billing city must be string');
1250
        }
1251
        if ($billingAddress !== null && !is_string($billingAddress)) {
1252
            throw new \InvalidArgumentException('Billing address must be string');
1253
        }
1254
        if ($billingZip !== null && !is_string($billingZip)) {
1255
            throw new \InvalidArgumentException('Billing zip must be string');
1256
        }
1257
1258
        $this->replace('billing_firstname', $billingFirstName);
1259
        $this->replace('billing_lastname', $billingLastName);
1260
        $this->replace('billing_fullname', $billingFullName);
1261
        $this->replace('billing_country', $billingCountry);
1262
        $this->replace('billing_state', $billingState);
1263
        $this->replace('billing_city', $billingCity);
1264
        $this->replace('billing_address', $billingAddress);
1265
        $this->replace('billing_zip', $billingZip);
1266
1267
        return $this;
1268
    }
1269
1270
    /**
1271
     * Provides product information to envelope
1272
     *
1273
     * @param float|null $productQuantity
1274
     * @param string|null $productName
1275
     * @param string|null $productDescription
1276
     *
1277
     * @return $this
1278
     */
1279 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...
1280
        $productQuantity = null,
1281
        $productName = null,
1282
        $productDescription = null
1283
    ) {
1284
        if ($productQuantity !== null && !is_int($productQuantity) && !is_float($productQuantity)) {
1285
            throw new \InvalidArgumentException('Product quantity must be int or float');
1286
        }
1287
        if ($productName !== null && !is_string($productName)) {
1288
            throw new \InvalidArgumentException('Product name must be string');
1289
        }
1290
        if ($productDescription !== null && !is_string($productDescription)) {
1291
            throw new \InvalidArgumentException('Product description must be string');
1292
        }
1293
1294
        $this->replace('product_quantity', $productQuantity);
1295
        $this->replace('product_name', $productName);
1296
        $this->replace('product_description', $productDescription);
1297
1298
        return $this;
1299
    }
1300
1301
    /**
1302
     * Provides payout information to envelope
1303
     *
1304
     * @param string $payoutId
1305
     * @param int $payoutTimestamp
1306
     * @param int|float $payoutAmount
1307
     * @param string $payoutCurrency
1308
     * @param string|null $payoutCardId
1309
     * @param string|null $payoutAccountId
1310
     * @param string|null $payoutMethod
1311
     * @param string|null $payoutSystem
1312
     * @param string|null $payoutMid
1313
     * @param int|float|null $amountConverted
1314
     * @param int|null $payoutCardBin
1315
     * @param string|null $payoutCardLast4
1316
     * @param int|null $payoutExpirationMonth
1317
     * @param int|null $payoutExpirationYear
1318
     *
1319
     * @return $this
1320
     */
1321
    public function addPayoutData(
1322
        $payoutId,
1323
        $payoutTimestamp,
1324
        $payoutAmount,
1325
        $payoutCurrency,
1326
        $payoutCardId =  null,
1327
        $payoutAccountId = null,
1328
        $payoutMethod = null,
1329
        $payoutSystem = null,
1330
        $payoutMid = null,
1331
        $amountConverted = null,
1332
        $payoutCardBin = null,
1333
        $payoutCardLast4 = null,
1334
        $payoutExpirationMonth = null,
1335
        $payoutExpirationYear = null
1336
    ) {
1337
        if (!is_string($payoutId)) {
1338
            throw new \InvalidArgumentException('Payout ID must be string');
1339
        }
1340
        if (!is_int($payoutTimestamp)) {
1341
            throw new \InvalidArgumentException('Payout timestamp must be int');
1342
        }
1343
        if (!is_float($payoutAmount) && !is_int($payoutAmount)) {
1344
            throw new \InvalidArgumentException('Amount must be number');
1345
        }
1346
        if (!is_string($payoutCurrency)) {
1347
            throw new \InvalidArgumentException('Payout currency must be string');
1348
        }
1349
        if ($payoutAccountId !== null && !is_string($payoutAccountId)) {
1350
            throw new \InvalidArgumentException('Account ID must be string');
1351
        }
1352
        if ($payoutCardId !== null && !is_string($payoutCardId)) {
1353
            throw new \InvalidArgumentException('Card ID must be string');
1354
        }
1355
        if ($payoutMethod !== null && !is_string($payoutMethod)) {
1356
            throw new \InvalidArgumentException('Payout method must be string');
1357
        }
1358
        if ($payoutSystem !== null && !is_string($payoutSystem)) {
1359
            throw new \InvalidArgumentException('Payout system must be string');
1360
        }
1361
        if ($payoutMid !== null && !is_string($payoutMid)) {
1362
            throw new \InvalidArgumentException('Payout MID must be string');
1363
        }
1364 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...
1365
            throw new \InvalidArgumentException('Payout converted amount must be number');
1366
        }
1367
        if ($payoutCardBin !== null && !is_int($payoutCardBin)) {
1368
            throw new \InvalidArgumentException('Payout card BIN must be integer');
1369
        }
1370
        if ($payoutCardLast4 !== null && !is_string($payoutCardLast4)) {
1371
            throw new \InvalidArgumentException('Payout last 4 must be string');
1372
        }
1373
        if ($payoutExpirationMonth !== null && !is_int($payoutExpirationMonth)) {
1374
            throw new \InvalidArgumentException('Payout card expiration month must be integer');
1375
        }
1376
        if ($payoutExpirationYear !== null && !is_int($payoutExpirationYear)) {
1377
            throw new \InvalidArgumentException('Payout card expiration year must be integer');
1378
        }
1379
1380
        $this->replace('payout_id', $payoutId);
1381
        $this->replace('payout_timestamp', $payoutTimestamp);
1382
        $this->replace('payout_card_id', $payoutCardId);
1383
        $this->replace('payout_account_id', $payoutAccountId);
1384
        $this->replace('payout_amount', (float) $payoutAmount);
1385
        $this->replace('payout_currency', $payoutCurrency);
1386
        $this->replace('payout_method', $payoutMethod);
1387
        $this->replace('payout_system', $payoutSystem);
1388
        $this->replace('payout_mid', $payoutMid);
1389
        $this->replace('payout_amount_converted', (float) $amountConverted);
1390
        $this->replace('payout_card_bin', $payoutCardBin);
1391
        $this->replace('payout_card_last4', $payoutCardLast4);
1392
        $this->replace('payout_expiration_month', $payoutExpirationMonth);
1393
        $this->replace('payout_expiration_year', $payoutExpirationYear);
1394
1395
        return $this;
1396
    }
1397
1398
    /**
1399
     * Provides install information to envelope
1400
     *
1401
     * @param int $installTimestamp
1402
     *
1403
     * @return $this
1404
     */
1405
    public function addInstallData($installTimestamp)
1406
    {
1407
        if (!is_int($installTimestamp)) {
1408
            throw new \InvalidArgumentException('Install timestamp must be int');
1409
        }
1410
1411
        $this->replace('install_timestamp', $installTimestamp);
1412
1413
        return $this;
1414
    }
1415
1416
    /**
1417
     * Provides refund information to envelope
1418
     *
1419
     * @param string $refundId
1420
     * @param int|float $refundAmount
1421
     * @param string $refundCurrency
1422
     * @param int|null $refundTimestamp
1423
     * @param int|float|null $refundAmountConverted
1424
     * @param string|null $refundSource
1425
     * @param string|null $refundType
1426
     * @param string|null $refundCode
1427
     * @param string|null $refundReason
1428
     * @param string|null $agentId
1429
     * @param string|null $refundMethod
1430
     * @param string|null $refundSystem
1431
     * @param string|null $refundMid
1432
     *
1433
     * @return $this
1434
     */
1435
    public function addRefundData(
1436
        $refundId,
1437
        $refundTimestamp,
1438
        $refundAmount,
1439
        $refundCurrency,
1440
        $refundAmountConverted = null,
1441
        $refundSource = null,
1442
        $refundType = null,
1443
        $refundCode = null,
1444
        $refundReason = null,
1445
        $agentId = null,
1446
        $refundMethod = null,
1447
        $refundSystem = null,
1448
        $refundMid = null
1449
    ) {
1450
        if (!is_string($refundId)) {
1451
            throw new \InvalidArgumentException('Refund ID must be string');
1452
        }
1453
        if (!is_int($refundTimestamp)) {
1454
            throw new \InvalidArgumentException('Refund timestamp must be int');
1455
        }
1456
        if (!is_float($refundAmount) && !is_int($refundAmount)) {
1457
            throw new \InvalidArgumentException('Amount must be number');
1458
        }
1459
        if (!is_string($refundCurrency)) {
1460
            throw new \InvalidArgumentException('Refund currency must be string');
1461
        }
1462
        if ($refundAmountConverted !== null && !is_float($refundAmountConverted) && !is_int($refundAmountConverted)) {
1463
            throw new \InvalidArgumentException('Refund converted amount must be number');
1464
        }
1465
        if ($refundSource !== null && !is_string($refundSource)) {
1466
            throw new \InvalidArgumentException('Refund source must be string');
1467
        }
1468
        if ($refundType !== null && !is_string($refundType)) {
1469
            throw new \InvalidArgumentException('Refund type must be string');
1470
        }
1471
        if ($refundCode !== null && !is_string($refundCode)) {
1472
            throw new \InvalidArgumentException('Refund code must be string');
1473
        }
1474
        if ($refundReason !== null && !is_string($refundReason)) {
1475
            throw new \InvalidArgumentException('Refund reason must be string');
1476
        }
1477
        if ($agentId !== null && !is_string($agentId)) {
1478
            throw new \InvalidArgumentException('Agent id must be string');
1479
        }
1480
        if ($refundMethod !== null && !is_string($refundMethod)) {
1481
            throw new \InvalidArgumentException('Refund method must be string');
1482
        }
1483
        if ($refundSystem !== null && !is_string($refundSystem)) {
1484
            throw new \InvalidArgumentException('Refund system must be string');
1485
        }
1486
        if ($refundMid !== null && !is_string($refundMid)) {
1487
            throw new \InvalidArgumentException('Refund mid must be string');
1488
        }
1489
1490
        $this->replace('refund_id', $refundId);
1491
        $this->replace('refund_timestamp', $refundTimestamp);
1492
        $this->replace('refund_amount', $refundAmount);
1493
        $this->replace('refund_currency', $refundCurrency);
1494
        $this->replace('refund_amount_converted', $refundAmountConverted);
1495
        $this->replace('refund_source', $refundSource);
1496
        $this->replace('refund_type', $refundType);
1497
        $this->replace('refund_code', $refundCode);
1498
        $this->replace('refund_reason', $refundReason);
1499
        $this->replace('agent_id', $agentId);
1500
        $this->replace('refund_method', $refundMethod);
1501
        $this->replace('refund_system', $refundSystem);
1502
        $this->replace('refund_mid', $refundMid);
1503
1504
        return $this;
1505
    }
1506
1507
    /**
1508
     * Provides transfer information to envelope
1509
     *
1510
     * @param string $eventId
1511
     * @param int $eventTimestamp
1512
     * @param float $amount
1513
     * @param string $currency
1514
     * @param string $accountId
1515
     * @param string $secondAccountId
1516
     * @param string $accountSystem
1517
     * @param float|null $amountConverted
1518
     * @param string|null $method
1519
     * @param string|null $operation
1520
     * @param string|null $secondEmail
1521
     * @param string|null $secondPhone
1522
     * @param string|int $secondBirthDate
1523
     * @param string|null $secondFirstname
1524
     * @param string|null $secondLastname
1525
     * @param string|null $secondFullname
1526
     * @param string|null $secondState
1527
     * @param string|null $secondCity
1528
     * @param string|null $secondAddress
1529
     * @param string|null $secondZip
1530
     * @param string|null $secondGender
1531
     * @param string|null $secondCountry
1532
     *
1533
     * @return $this
1534
     */
1535
    public function addTransferData(
1536
        $eventId,
1537
        $eventTimestamp,
1538
        $amount,
1539
        $currency,
1540
        $accountId,
1541
        $secondAccountId,
1542
        $accountSystem,
1543
        $amountConverted = null,
1544
        $method = null,
1545
        $operation = null,
1546
        $secondEmail = null,
1547
        $secondPhone = null,
1548
        $secondBirthDate = null,
1549
        $secondFirstname = null,
1550
        $secondLastname = null,
1551
        $secondFullname = null,
1552
        $secondState = null,
1553
        $secondCity = null,
1554
        $secondAddress = null,
1555
        $secondZip = null,
1556
        $secondGender = null,
1557
        $secondCountry = null
1558
    ) {
1559
        if (!is_string($eventId)) {
1560
            throw new \InvalidArgumentException('Event ID must be string');
1561
        }
1562
        if (!is_int($eventTimestamp)) {
1563
            throw new \InvalidArgumentException('Event timestamp must be int');
1564
        }
1565
        if (!is_int($amount) && !is_float($amount)) {
1566
            throw new \InvalidArgumentException('Amount must be number');
1567
        }
1568
        if (!is_string($currency)) {
1569
            throw new \InvalidArgumentException('Currency must be string');
1570
        }
1571
        if (!is_string($accountId)) {
1572
            throw new \InvalidArgumentException('Account id must be string');
1573
        }
1574
        if (!is_string($secondAccountId)) {
1575
            throw new \InvalidArgumentException('Second account id must be string');
1576
        }
1577
        if (!is_string($accountSystem)) {
1578
            throw new \InvalidArgumentException('Account system must be string');
1579
        }
1580 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...
1581
            throw new \InvalidArgumentException('Amount converted must be number');
1582
        }
1583
        if ($method !== null && !is_string($method)) {
1584
            throw new \InvalidArgumentException('Method must be string');
1585
        }
1586
        if ($operation !== null && !is_string($operation)) {
1587
            throw new \InvalidArgumentException('Operation must be string');
1588
        }
1589
        if ($secondPhone !== null && !is_string($secondPhone)) {
1590
            throw new \InvalidArgumentException('Second phone must be string');
1591
        }
1592
        if ($secondEmail !== null && !is_string($secondEmail)) {
1593
            throw new \InvalidArgumentException('Second email must be string');
1594
        }
1595
        if ($secondBirthDate !== null && !is_int($secondBirthDate)) {
1596
            throw new \InvalidArgumentException('Second birth date must be int');
1597
        }
1598
        if ($secondFirstname !== null && !is_string($secondFirstname)) {
1599
            throw new \InvalidArgumentException('Second firstname must be string');
1600
        }
1601
        if ($secondLastname !== null && !is_string($secondLastname)) {
1602
            throw new \InvalidArgumentException('Second lastname must be string');
1603
        }
1604
        if ($secondFullname !== null && !is_string($secondFullname)) {
1605
            throw new \InvalidArgumentException('Second fullname must be string');
1606
        }
1607
        if ($secondState !== null && !is_string($secondState)) {
1608
            throw new \InvalidArgumentException('Second state must be string');
1609
        }
1610
        if ($secondCity !== null && !is_string($secondCity)) {
1611
            throw new \InvalidArgumentException('Second city must be string');
1612
        }
1613
        if ($secondAddress !== null && !is_string($secondAddress)) {
1614
            throw new \InvalidArgumentException('Second address must be string');
1615
        }
1616
        if ($secondZip !== null && !is_string($secondZip)) {
1617
            throw new \InvalidArgumentException('Second zip must be string');
1618
        }
1619
        if ($secondGender !== null && !is_string($secondGender)) {
1620
            throw new \InvalidArgumentException('Second gender must be string');
1621
        }
1622
        if ($secondCountry !== null && !is_string($secondCountry)) {
1623
            throw new \InvalidArgumentException('Second country must be string');
1624
        }
1625
1626
1627
        $this->replace('event_id', $eventId);
1628
        $this->replace('event_timestamp', $eventTimestamp);
1629
        $this->replace('amount', $amount);
1630
        $this->replace('currency', $currency);
1631
        $this->replace('account_id', $accountId);
1632
        $this->replace('second_account_id', $secondAccountId);
1633
        $this->replace('account_system', $accountSystem);
1634
        $this->replace('amount_converted', $amountConverted);
1635
        $this->replace('method', $method);
1636
        $this->replace('operation', $operation);
1637
        $this->replace('second_email', $secondEmail);
1638
        $this->replace('second_phone', $secondPhone);
1639
        $this->replace('second_birth_date', $secondBirthDate);
1640
        $this->replace('second_firstname', $secondFirstname);
1641
        $this->replace('second_lastname', $secondLastname);
1642
        $this->replace('second_fullname', $secondFullname);
1643
        $this->replace('second_state', $secondState);
1644
        $this->replace('second_city', $secondCity);
1645
        $this->replace('second_address', $secondAddress);
1646
        $this->replace('second_zip', $secondZip);
1647
        $this->replace('second_gender', $secondGender);
1648
        $this->replace('second_country', $secondCountry);
1649
        return $this;
1650
    }
1651
1652
    /**
1653
     * Provides postback information to envelope
1654
     *
1655
     * @param string|null $transactionStatus
1656
     * @param string|null $code
1657
     * @param string|null $reason
1658
     * @param string|null $secure3d
1659
     * @param string|null $avsResult
1660
     * @param string|null $cvvResult
1661
     * @param string|null $pspCode
1662
     * @param string|null $pspReason
1663
     * @param string|null $arn
1664
     * @param string|null $paymentAccountId
1665
     * @return $this
1666
     */
1667
    public function addPostbackData(
1668
        $transactionStatus = null,
1669
        $code = null,
1670
        $reason = null,
1671
        $secure3d = null,
1672
        $avsResult = null,
1673
        $cvvResult = null,
1674
        $pspCode = null,
1675
        $pspReason = null,
1676
        $arn = null,
1677
        $paymentAccountId = null
1678
    ) {
1679
        if ($transactionStatus !== null && !is_string($transactionStatus)) {
1680
            throw new \InvalidArgumentException('Transaction status must be string');
1681
        }
1682
        if ($code !== null && !is_string($code)) {
1683
            throw new \InvalidArgumentException('Code must be string');
1684
        }
1685
        if ($reason !== null && !is_string($reason)) {
1686
            throw new \InvalidArgumentException('Reason must be string');
1687
        }
1688
        if ($secure3d !== null && !is_string($secure3d)) {
1689
            throw new \InvalidArgumentException('Secure3d must be string');
1690
        }
1691
        if ($avsResult !== null && !is_string($avsResult)) {
1692
            throw new \InvalidArgumentException('AvsResult must be string');
1693
        }
1694
        if ($cvvResult !== null && !is_string($cvvResult)) {
1695
            throw new \InvalidArgumentException('CvvResult must be string');
1696
        }
1697
        if ($pspCode !== null && !is_string($pspCode)) {
1698
            throw new \InvalidArgumentException('PspCode must be string');
1699
        }
1700
        if ($pspReason !== null && !is_string($pspReason)) {
1701
            throw new \InvalidArgumentException('PspReason must be string');
1702
        }
1703
        if ($arn !== null && !is_string($arn)) {
1704
            throw new \InvalidArgumentException('Arn must be string');
1705
        }
1706
        if ($paymentAccountId !== null && !is_string($paymentAccountId)) {
1707
            throw new \InvalidArgumentException('PaymentAccoutId must be string');
1708
        }
1709
1710
1711
        $this->replace('transaction_status', $transactionStatus);
1712
        $this->replace('code', $code);
1713
        $this->replace('reason', $reason);
1714
        $this->replace('secure3d', $secure3d);
1715
        $this->replace('avs_result', $avsResult);
1716
        $this->replace('cvv_result', $cvvResult);
1717
        $this->replace('psp_code', $pspCode);
1718
        $this->replace('psp_reason', $pspReason);
1719
        $this->replace('arn', $arn);
1720
        $this->replace('payment_account_id', $paymentAccountId);
1721
1722
        return $this;
1723
    }
1724
1725
    /**
1726
     * Adds custom data field to envelope
1727
     *
1728
     * @param string $name
1729
     * @param string $value
1730
     *
1731
     * @return $this
1732
     */
1733
    public function addCustomField($name, $value)
1734
    {
1735
        if (!is_string($name)) {
1736
            throw new \InvalidArgumentException('Custom field name must be string');
1737
        }
1738
        if (!is_string($value)) {
1739
            throw new \InvalidArgumentException('Custom field value must be string');
1740
        }
1741
1742
        if (strlen($name) < 8 || substr($name, 0, 7) !== 'custom_') {
1743
            $name = 'custom_' . $name;
1744
        }
1745
1746
        $this->replace($name, $value);
1747
        return $this;
1748
    }
1749
}
1750