Completed
Pull Request — master (#3)
by
unknown
01:54
created

Builder::installEvent()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 19
rs 9.4285
cc 2
eloc 15
nc 2
nop 7
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 View Code Duplication
    public static function confirmationEvent(
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...
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
     *
84
     * @return Builder
85
     */
86 View Code Duplication
    public static function loginEvent(
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...
87
        $sequenceId,
88
        $userId,
89
        $timestamp = null,
90
        $email = null,
91
        $failed = null,
92
        $gender = null
93
    ) {
94
        $builder = new self('login', $sequenceId);
95
        if ($timestamp === null) {
96
            $timestamp = time();
97
        }
98
99
        return $builder->addUserData(
100
            $email,
101
            $userId,
102
            null,
103
            null,
104
            null,
105
            null,
106
            $gender,
107
            null,
108
            null,
109
            null,
110
            null,
111
            $timestamp,
112
            null,
113
            null,
114
            null,
115
            $failed
116
        );
117
    }
118
119
    /**
120
     * Returns builder for registration event
121
     *
122
     * @param string $sequenceId
123
     * @param string $userId
124
     * @param int|null $timestamp
125
     * @param string|null $email
126
     * @param string|null $userName
127
     * @param string|null $firstName
128
     * @param string|null $lastName
129
     * @param int|null $age
130
     * @param string|null $gender
131
     * @param string|null $phone
132
     * @param string|null $country
133
     * @param string|null $socialType
134
     * @param string|null $websiteUrl
135
     * @param string|null $trafficSource
136
     * @param string|null $affiliateId
137
     *
138
     * @return Builder
139
     */
140
    public static function registrationEvent(
141
        $sequenceId,
142
        $userId,
143
        $timestamp = null,
144
        $email = null,
145
        $userName = null,
146
        $firstName = null,
147
        $lastName = null,
148
        $age = null,
149
        $gender = null,
150
        $phone = null,
151
        $country = null,
152
        $socialType = null,
153
        $websiteUrl = null,
154
        $trafficSource = null,
155
        $affiliateId = null
156
    ) {
157
        $builder = new self('registration', $sequenceId);
158
        if ($timestamp === null) {
159
            $timestamp = time();
160
        }
161
162
        return $builder->addWebsiteData(
163
            $websiteUrl,
164
            $trafficSource,
165
            $affiliateId
166
        )->addUserData(
167
            $email,
168
            $userId,
169
            $phone,
170
            $userName,
171
            $firstName,
172
            $lastName,
173
            $gender,
174
            $age,
175
            $country,
176
            $socialType,
177
            $timestamp,
178
            null,
179
            null,
180
            null,
181
            null,
182
            null
183
        );
184
    }
185
186
    /**
187
     * Returns builder for payout request
188
     *
189
     * @param string $sequenceId
190
     * @param string $userId
191
     * @param string $payoutId
192
     * @param string $currency
193
     * @param int|float $amount
194
     * @param int|null $payoutTimestamp
195
     * @param string|null $cardId
196
     * @param string|null $accountId
197
     * @param string|null $method
198
     * @param string|null $system
199
     * @param string|null $mid
200
     * @param int|float $amountConverted
201
     * @param string|null $firstName
202
     * @param string|null $lastName
203
     * @param string|null $country
204
     * @param string|null $email
205
     * @param string|null $phone
206
     * @param int|null $cardBin
207
     * @param string|null $cardLast4
208
     * @param int|null $cardExpirationMonth
209
     * @param int|null $cardExpirationYear
210
     *
211
     * @return Builder
212
     */
213
    public static function payoutEvent(
214
        $sequenceId,
215
        $userId,
216
        $payoutId,
217
        $currency,
218
        $amount,
219
        $payoutTimestamp = null,
220
        $cardId = null,
221
        $accountId = null,
222
        $method = null,
223
        $system = null,
224
        $mid = null,
225
        $amountConverted = null,
226
        $firstName = null,
227
        $lastName = null,
228
        $country = null,
229
        $email = null,
230
        $phone = null,
231
        $cardBin = null,
232
        $cardLast4 = null,
233
        $cardExpirationMonth = null,
234
        $cardExpirationYear = null
235
    ) {
236
        $builder = new self('payout', $sequenceId);
237
        if ($payoutTimestamp === null) {
238
            $payoutTimestamp = time();
239
        }
240
        return $builder->addPayoutData(
241
            $payoutId,
242
            $payoutTimestamp,
243
            $amount,
244
            $currency,
245
            $cardId,
246
            $accountId,
247
            $method,
248
            $system,
249
            $mid,
250
            $amountConverted,
251
            $cardBin,
252
            $cardLast4,
253
            $cardExpirationMonth,
254
            $cardExpirationYear
255
        )->addShortUserData($email, $userId, $phone, $firstName, $lastName, $country);
256
    }
257
258
    /**
259
     * Returns builder for transaction request
260
     *
261
     * @param string $sequenceId
262
     * @param string $userId
263
     * @param string $transactionId
264
     * @param int|float $transactionAmount
265
     * @param string $transactionCurrency
266
     * @param int|null $transactionTimestamp
267
     * @param string|null $transactionMode
268
     * @param string|null $transactionType
269
     * @param int|null $cardBin
270
     * @param string|null $cardId
271
     * @param string|null $cardLast4
272
     * @param int|null $expirationMonth
273
     * @param int|null $expirationYear
274
     * @param int|null $age
275
     * @param string|null $country
276
     * @param string|null $email
277
     * @param string|null $gender
278
     * @param string|null $firstName
279
     * @param string|null $lastName
280
     * @param string|null $phone
281
     * @param string|null $userName
282
     * @param string|null $paymentAccountId
283
     * @param string|null $paymentMethod
284
     * @param string|null $paymentMidName
285
     * @param string|null $paymentSystem
286
     * @param int|float|null $transactionAmountConverted
287
     * @param string|null $transactionSource
288
     * @param string|null $billingAddress
289
     * @param string|null $billingCity
290
     * @param string|null $billingCountry
291
     * @param string|null $billingFirstName
292
     * @param string|null $billingLastName
293
     * @param string|null $billingFullName
294
     * @param string|null $billingState
295
     * @param string|null $billingZip
296
     * @param string|null $productDescription
297
     * @param string|null $productName
298
     * @param int|float|null $productQuantity
299
     * @param string|null $websiteUrl
300
     * @param string|null $merchantIp
301
     * @param string|null $affiliateId
302
     *
303
     * @return Builder
304
     */
305
    public static function transactionEvent(
306
        $sequenceId,
307
        $userId,
308
        $transactionId,
309
        $transactionAmount,
310
        $transactionCurrency,
311
        $transactionTimestamp = null,
312
        $transactionMode = null,
313
        $transactionType = null,
314
        $cardBin = null,
315
        $cardId = null,
316
        $cardLast4 = null,
317
        $expirationMonth = null,
318
        $expirationYear = null,
319
        $age = null,
320
        $country = null,
321
        $email = null,
322
        $gender = null,
323
        $firstName = null,
324
        $lastName = null,
325
        $phone = null,
326
        $userName = null,
327
        $paymentAccountId = null,
328
        $paymentMethod = null,
329
        $paymentMidName = null,
330
        $paymentSystem = null,
331
        $transactionAmountConverted = null,
332
        $transactionSource = null,
333
        $billingAddress = null,
334
        $billingCity = null,
335
        $billingCountry = null,
336
        $billingFirstName = null,
337
        $billingLastName = null,
338
        $billingFullName = null,
339
        $billingState = null,
340
        $billingZip = null,
341
        $productDescription = null,
342
        $productName = null,
343
        $productQuantity = null,
344
        $websiteUrl = null,
345
        $merchantIp = null,
346
        $affiliateId = null
347
    ) {
348
        $builder = new self('transaction', $sequenceId);
349
        if ($transactionTimestamp === null) {
350
            $transactionTimestamp = time();
351
        }
352
353
        return $builder
354
            ->addCCTransactionData(
355
                $transactionId,
356
                $transactionSource,
357
                $transactionType,
358
                $transactionMode,
359
                $transactionTimestamp,
360
                $transactionCurrency,
361
                $transactionAmount,
362
                $transactionAmountConverted,
363
                $paymentMethod,
364
                $paymentSystem,
365
                $paymentMidName,
366
                $paymentAccountId
367
            )
368
            ->addBillingData(
369
                $billingFirstName,
370
                $billingLastName,
371
                $billingFullName,
372
                $billingCountry,
373
                $billingState,
374
                $billingCity,
375
                $billingAddress,
376
                $billingZip
377
            )
378
            ->addCardData($cardBin, $cardLast4, $expirationMonth, $expirationYear, $cardId)
379
            ->addUserData(
380
                $email,
381
                $userId,
382
                $phone,
383
                $userName,
384
                $firstName,
385
                $lastName,
386
                $gender,
387
                $age,
388
                $country
389
            )
390
            ->addProductData($productQuantity, $productName, $productDescription)
391
            ->addWebsiteData($websiteUrl, null, $affiliateId)
392
            ->addIpData(null, null, $merchantIp);
393
394
    }
395
396
    /**
397
     * Returns builder for install request
398
     *
399
     * @param string $sequenceId
400
     * @param string|null $userId
401
     * @param int|null $installTimestamp
402
     * @param string|null $country
403
     * @param string|null $websiteUrl
404
     * @param string|null $trafficSource
405
     * @param string|null $affiliateId
406
     *
407
     * @return Builder
408
     */
409
    public static function installEvent(
410
        $sequenceId,
411
        $userId = null,
412
        $installTimestamp = null,
413
        $country = null,
414
        $websiteUrl = null,
415
        $trafficSource = null,
416
        $affiliateId = null
417
    ) {
418
        $builder = new self('install', $sequenceId);
419
        if ($installTimestamp === null) {
420
            $installTimestamp = time();
421
        }
422
423
        return $builder->addInstallData(
424
            $installTimestamp
425
        )->addWebsiteData($websiteUrl, $trafficSource, $affiliateId)
426
        ->addShortUserData(null, $userId, null, null, null, $country);
427
    }
428
429
    /**
430
     * Returns builder for refund request
431
     *
432
     * @param string $sequenceId
433
     * @param string $refundId
434
     * @param int|float $refundAmount
435
     * @param string $refundCurrency
436
     * @param int|null $refundTimestamp
437
     * @param int|float|null $refundAmountConverted
438
     * @param string|null $refundSource
439
     * @param string|null $refundType
440
     * @param string|null $refundCode
441
     * @param string|null $refundReason
442
     * @param string|null $agentId
443
     * @param string|null $refundMethod
444
     * @param string|null $refundSystem
445
     * @param string|null $refundMid
446
     *
447
     * @return Builder
448
     */
449
    public static function refundEvent(
450
        $sequenceId,
451
        $refundId,
452
        $refundAmount,
453
        $refundCurrency,
454
        $refundTimestamp = null,
455
        $refundAmountConverted = null,
456
        $refundSource = null,
457
        $refundType = null,
458
        $refundCode = null,
459
        $refundReason = null,
460
        $agentId = null,
461
        $refundMethod = null,
462
        $refundSystem = null,
463
        $refundMid = null
464
    ) {
465
        $builder = new self('refund', $sequenceId);
466
        if ($refundTimestamp === null) {
467
            $refundTimestamp = time();
468
        }
469
470
        return $builder->addRefundData(
471
            $refundId,
472
            $refundTimestamp,
473
            $refundAmount,
474
            $refundCurrency,
475
            $refundAmountConverted,
476
            $refundSource,
477
            $refundType,
478
            $refundCode,
479
            $refundReason,
480
            $agentId,
481
            $refundMethod,
482
            $refundSystem,
483
            $refundMid
484
        );
485
    }
486
487
    /**
488
     * Returns builder for postback request
489
     *
490
     * @param $sequenceId
491
     * @param string|null $transactionStatus
492
     * @param string|null $code
493
     * @param string|null $reason
494
     * @param string|null $secure3d
495
     * @param string|null $avsResult
496
     * @param string|null $cvvResult
497
     * @param string|null $pspCode
498
     * @param string|null $pspReason
499
     * @param string|null $arn
500
     * @param string|null $paymentAccountId
501
     * @return Builder
502
     */
503
    public static function postBackEvent(
504
        $sequenceId,
505
        $transactionStatus = null,
506
        $code = null,
507
        $reason = null,
508
        $secure3d = null,
509
        $avsResult = null,
510
        $cvvResult = null,
511
        $pspCode = null,
512
        $pspReason = null,
513
        $arn = null,
514
        $paymentAccountId = null
515
    ) {
516
        $builder = new self('postback', $sequenceId);
517
        return $builder->addPostBackData(
518
            $transactionStatus,
519
            $code,
520
            $reason,
521
            $secure3d,
522
            $avsResult,
523
            $cvvResult,
524
            $pspCode,
525
            $pspReason,
526
            $arn,
527
            $paymentAccountId
528
       );
529
    }
530
531
    /**
532
     * Builder constructor.
533
     *
534
     * @param string $envelopeType
535
     * @param string $sequenceId
536
     */
537
    public function __construct($envelopeType, $sequenceId)
538
    {
539
        if (!is_string($envelopeType)) {
540
            throw new \InvalidArgumentException('Envelope type must be string');
541
        }
542
        if (!is_string($sequenceId)) {
543
            throw new \InvalidArgumentException('Sequence ID must be string');
544
        }
545
546
        $this->type = $envelopeType;
547
        $this->sequenceId = $sequenceId;
548
    }
549
550
    /**
551
     * Returns built envelope
552
     *
553
     * @return EnvelopeInterface
554
     */
555
    public function build()
556
    {
557
        return new Envelope(
558
            $this->type,
559
            $this->sequenceId,
560
            $this->identities,
561
            array_filter($this->data, function ($data) {
562
                return $data !== null;
563
            })
564
        );
565
    }
566
567
    /**
568
     * Replaces value in internal array if provided value not empty
569
     *
570
     * @param string $key
571
     * @param string|int|float|bool|null $value
572
     */
573
    private function replace($key, $value)
574
    {
575
        if ($value !== null && $value !== '' && $value !== 0 && $value !== 0.0) {
576
            $this->data[$key] = $value;
577
        }
578
    }
579
580
    /**
581
     * Adds identity node
582
     *
583
     * @param IdentityNodeInterface $identity
584
     *
585
     * @return $this
586
     */
587
    public function addIdentity(IdentityNodeInterface $identity)
588
    {
589
        $this->identities[] = $identity;
590
        return $this;
591
    }
592
593
    /**
594
     * Provides website URL to envelope
595
     *
596
     * @param string|null $websiteUrl
597
     * @param string|null $traffic_source
598
     * @param string|null $affiliate_id
599
     *
600
     * @return $this
601
     */
602 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...
603
    {
604
        if ($websiteUrl !== null && !is_string($websiteUrl)) {
605
            throw new \InvalidArgumentException('Website URL must be string');
606
        }
607
        if ($traffic_source !== null && !is_string($traffic_source)) {
608
            throw new \InvalidArgumentException('Traffic source must be string');
609
        }
610
        if ($affiliate_id !== null && !is_string($affiliate_id)) {
611
            throw new \InvalidArgumentException('Affiliate ID must be string');
612
        }
613
614
        $this->replace('website_url', $websiteUrl);
615
        $this->replace('traffic_source', $traffic_source);
616
        $this->replace('affiliate_id', $affiliate_id);
617
        return $this;
618
    }
619
620
    /**
621
     * Provides IP information for envelope
622
     *
623
     * @param string|null $ip User's IP address
624
     * @param string|null $realIp User's real IP address, if available
625
     * @param string|null $merchantIp Your website's IP address
626
     *
627
     * @return $this
628
     */
629
    public function addIpData($ip = '', $realIp = '', $merchantIp = '')
630
    {
631
        if ($ip !== null && !is_string($ip)) {
632
            throw new \InvalidArgumentException('IP must be string');
633
        }
634
        if ($realIp !== null && !is_string($realIp)) {
635
            throw new \InvalidArgumentException('Real IP must be string');
636
        }
637
        if ($merchantIp !== null && !is_string($merchantIp)) {
638
            throw new \InvalidArgumentException('Merchant IP must be string');
639
        }
640
641
        $this->replace('ip', $ip);
642
        $this->replace('real_ip', $realIp);
643
        $this->replace('merchant_ip', $merchantIp);
644
645
        return $this;
646
    }
647
648
    /**
649
     * Provides browser information for envelope
650
     *
651
     * @param string|null $deviceFingerprint
652
     * @param string|null $userAgent
653
     * @param string|null $cpuClass
654
     * @param string|null $screenOrientation
655
     * @param string|null $screenResolution
656
     * @param string|null $os
657
     * @param int|null $timezoneOffset
658
     * @param string|null $languages
659
     * @param string|null $language
660
     * @param string|null $languageBrowser
661
     * @param string|null $languageUser
662
     * @param string|null $languageSystem
663
     * @param bool|null $cookieEnabled
664
     * @param bool|null $doNotTrack
665
     * @param bool|null $ajaxValidation
666
     * @param string|null $deviceId
667
     *
668
     * @return $this
669
     */
670
    public function addBrowserData(
671
        $deviceFingerprint = '',
672
        $userAgent = '',
673
        $cpuClass = '',
674
        $screenOrientation = '',
675
        $screenResolution = '',
676
        $os = '',
677
        $timezoneOffset = null,
678
        $languages = '',
679
        $language = '',
680
        $languageBrowser = '',
681
        $languageUser = '',
682
        $languageSystem = '',
683
        $cookieEnabled = null,
684
        $doNotTrack = null,
685
        $ajaxValidation = null,
686
        $deviceId = ''
687
    ) {
688
        if ($deviceFingerprint !== null && !is_string($deviceFingerprint)) {
689
            throw new \InvalidArgumentException('Device fingerprint must be string');
690
        }
691
        if ($userAgent !== null && !is_string($userAgent)) {
692
            throw new \InvalidArgumentException('User agent must be string');
693
        }
694
        if ($cpuClass !== null && !is_string($cpuClass)) {
695
            throw new \InvalidArgumentException('CPU class must be string');
696
        }
697
        if ($screenOrientation !== null && !is_string($screenOrientation)) {
698
            throw new \InvalidArgumentException('Screen orientation must be string');
699
        }
700
        if ($screenResolution !== null && !is_string($screenResolution)) {
701
            throw new \InvalidArgumentException('Screen resolution must be string');
702
        }
703
        if ($os !== null && !is_string($os)) {
704
            throw new \InvalidArgumentException('OS must be string');
705
        }
706
        if ($timezoneOffset !== null && $timezoneOffset !== null && !is_int($timezoneOffset)) {
707
            throw new \InvalidArgumentException('Timezone offset must be integer or null');
708
        }
709
        if ($languages !== null && !is_string($languages)) {
710
            throw new \InvalidArgumentException('Languages must be string');
711
        }
712
        if ($language !== null && !is_string($language)) {
713
            throw new \InvalidArgumentException('Language must be string');
714
        }
715
        if ($languageBrowser !== null && !is_string($languageBrowser)) {
716
            throw new \InvalidArgumentException('Browser language must be string');
717
        }
718
        if ($languageUser !== null && !is_string($languageUser)) {
719
            throw new \InvalidArgumentException('User language must be string');
720
        }
721
        if ($languageSystem !== null && !is_string($languageSystem)) {
722
            throw new \InvalidArgumentException('System language must be string');
723
        }
724
        if ($cookieEnabled !== null && !is_bool($cookieEnabled)) {
725
            throw new \InvalidArgumentException('Cookie enabled flag must be boolean');
726
        }
727
        if ($doNotTrack !== null && !is_bool($doNotTrack)) {
728
            throw new \InvalidArgumentException('DNT flag must be boolean');
729
        }
730
        if ($ajaxValidation !== null && !is_bool($ajaxValidation)) {
731
            throw new \InvalidArgumentException('AJAX validation flag must be boolean');
732
        }
733
        if ($deviceId !== null && !is_string($deviceId)) {
734
            throw new \InvalidArgumentException('Device id must be string');
735
        }
736
737
        $this->replace('device_fingerprint', $deviceFingerprint);
738
        $this->replace('user_agent', $userAgent);
739
        $this->replace('cpu_class', $cpuClass);
740
        $this->replace('screen_orientation', $screenOrientation);
741
        $this->replace('screen_resolution', $screenResolution);
742
        $this->replace('os', $os);
743
        $this->replace('timezone_offset', $timezoneOffset);
744
        $this->replace('languages', $languages);
745
        $this->replace('language', $language);
746
        $this->replace('language_browser', $languageBrowser);
747
        $this->replace('language_system', $languageSystem);
748
        $this->replace('language_user', $languageUser);
749
        $this->replace('cookie_enabled', $cookieEnabled);
750
        $this->replace('do_not_track', $doNotTrack);
751
        $this->replace('ajax_validation', $ajaxValidation);
752
        $this->replace('device_id', $deviceId);
753
754
        return $this;
755
    }
756
757
    /**
758
     * Provides user data for envelope
759
     *
760
     * @param string|null $email
761
     * @param string|null $userId
762
     * @param string|null $phone
763
     * @param string|null $userName
764
     * @param string|null $firstName
765
     * @param string|null $lastName
766
     * @param string|null $gender
767
     * @param int|null $age
768
     * @param string|null $country
769
     * @param string|null $socialType
770
     * @param int|null $registrationTimestamp
771
     * @param int|null $loginTimeStamp
772
     * @param int|null $confirmationTimeStamp
773
     * @param bool|null $emailConfirmed
774
     * @param bool|null $phoneConfirmed
775
     * @param bool|null $loginFailed
776
     *
777
     * @return $this
778
     */
779
    public function addUserData(
780
        $email = '',
781
        $userId = '',
782
        $phone = '',
783
        $userName = '',
784
        $firstName = '',
785
        $lastName = '',
786
        $gender = '',
787
        $age = 0,
788
        $country = '',
789
        $socialType = '',
790
        $registrationTimestamp = 0,
791
        $loginTimeStamp = 0,
792
        $confirmationTimeStamp = 0,
793
        $emailConfirmed = null,
794
        $phoneConfirmed = null,
795
        $loginFailed = null
796
    ) {
797
        if ($userName !== null && !is_string($userName)) {
798
            throw new \InvalidArgumentException('User name must be string');
799
        }
800
        if ($gender !== null && !is_string($gender)) {
801
            throw new \InvalidArgumentException('Gender must be string');
802
        }
803
        if ($age !== null && !is_int($age)) {
804
            throw new \InvalidArgumentException('Age must be integer');
805
        }
806
        if ($socialType !== null && !is_string($socialType)) {
807
            throw new \InvalidArgumentException('Social type must be string');
808
        }
809
        if ($registrationTimestamp !== null && !is_int($registrationTimestamp)) {
810
            throw new \InvalidArgumentException('Registration timestamp must be integer');
811
        }
812
        if ($loginTimeStamp !== null && !is_int($loginTimeStamp)) {
813
            throw new \InvalidArgumentException('Login timestamp must be integer');
814
        }
815
        if ($confirmationTimeStamp !== null && !is_int($confirmationTimeStamp)) {
816
            throw new \InvalidArgumentException('Confirmation timestamp must be integer');
817
        }
818
        if ($emailConfirmed !== null && !is_bool($emailConfirmed)) {
819
            throw new \InvalidArgumentException('Email confirmed flag must be boolean');
820
        }
821
        if ($phoneConfirmed !== null && !is_bool($phoneConfirmed)) {
822
            throw new \InvalidArgumentException('Phone confirmed flag must be boolean');
823
        }
824
        if ($loginFailed !== null && !is_bool($loginFailed)) {
825
            throw new \InvalidArgumentException('Login failed flag must be boolean');
826
        }
827
828
        $this->addShortUserData($email, $userId, $phone, $firstName, $lastName, $country);
829
830
        $this->replace('user_name', $userName);
831
        $this->replace('gender', $gender);
832
        $this->replace('age', $age);
833
        $this->replace('social_type', $socialType);
834
        $this->replace('registration_timestamp', $registrationTimestamp);
835
        $this->replace('login_timestamp', $loginTimeStamp);
836
        $this->replace('confirmation_timestamp', $confirmationTimeStamp);
837
        $this->replace('email_confirmed', $emailConfirmed);
838
        $this->replace('phone_confirmed', $phoneConfirmed);
839
        $this->replace('login_failed', $loginFailed);
840
841
        return $this;
842
    }
843
844
    /**
845
     * Provides user data for envelope
846
     *
847
     * @param string|null $email
848
     * @param string|null $userId
849
     * @param string|null $phone
850
     * @param string|null $firstName
851
     * @param string|null $lastName
852
     * @param string|null $country
853
     *
854
     * @return $this
855
     */
856
    public function addShortUserData(
857
        $email = '',
858
        $userId = '',
859
        $phone = '',
860
        $firstName = '',
861
        $lastName = '',
862
        $country = ''
863
    ) {
864
        if ($email !== null && !is_string($email)) {
865
            throw new \InvalidArgumentException('Email must be string');
866
        }
867
        if (is_int($userId)) {
868
            $userId = strval($userId);
869
        }
870
        if ($userId !== null && !is_string($userId)) {
871
            throw new \InvalidArgumentException('UserId must be string or integer');
872
        }
873
        if ($phone !== null && !is_string($phone)) {
874
            throw new \InvalidArgumentException('Phone must be string');
875
        }
876
        if ($firstName !== null && !is_string($firstName)) {
877
            throw new \InvalidArgumentException('First name must be string');
878
        }
879
        if ($lastName !== null && !is_string($lastName)) {
880
            throw new \InvalidArgumentException('Last name must be string');
881
        }
882
        if ($country !== null && !is_string($country)) {
883
            throw new \InvalidArgumentException('Country must be string');
884
        }
885
886
        $this->replace('email', $email);
887
        $this->replace('user_merchant_id', $userId);
888
        $this->replace('phone', $phone);
889
        $this->replace('firstname', $firstName);
890
        $this->replace('lastname', $lastName);
891
        $this->replace('country', $country);
892
893
        return $this;
894
    }
895
896
    /**
897
     * Provides credit card data to envelope
898
     *
899
     * @param string|null $transactionId
900
     * @param string|null $transactionSource
901
     * @param string|null $transactionType
902
     * @param string|null $transactionMode
903
     * @param string|null $transactionTimestamp
904
     * @param string|null $transactionCurrency
905
     * @param string|null $transactionAmount
906
     * @param float|null $amountConverted
907
     * @param string|null $paymentMethod
908
     * @param string|null $paymentSystem
909
     * @param string|null $paymentMidName
910
     * @param string|null $paymentAccountId
911
     *
912
     * @return $this
913
     */
914
    public function addCCTransactionData(
915
        $transactionId,
916
        $transactionSource,
917
        $transactionType,
918
        $transactionMode,
919
        $transactionTimestamp,
920
        $transactionCurrency,
921
        $transactionAmount,
922
        $amountConverted = null,
923
        $paymentMethod = null,
924
        $paymentSystem = null,
925
        $paymentMidName = null,
926
        $paymentAccountId = null
927
    ) {
928
        if ($transactionId !== null && !is_string($transactionId)) {
929
            throw new \InvalidArgumentException('Transaction ID must be string');
930
        }
931
        if ($transactionSource !== null && !is_string($transactionSource)) {
932
            throw new \InvalidArgumentException('Transaction source must be string');
933
        }
934
        if ($transactionType !== null && !is_string($transactionType)) {
935
            throw new \InvalidArgumentException('Transaction type must be string');
936
        }
937
        if ($transactionMode !== null && !is_string($transactionMode)) {
938
            throw new \InvalidArgumentException('Transaction mode must be string');
939
        }
940
        if ($transactionTimestamp !== null && !is_int($transactionTimestamp)) {
941
            throw new \InvalidArgumentException('Transaction timestamp must be integer');
942
        }
943
        if ($transactionAmount !== null && !is_int($transactionAmount) && !is_float($transactionAmount)) {
944
            throw new \InvalidArgumentException('Transaction amount must be float');
945
        }
946
        if ($transactionCurrency !== null && !is_string($transactionCurrency)) {
947
            throw new \InvalidArgumentException('Transaction currency must be string');
948
        }
949
        if ($paymentMethod !== null && !is_string($paymentMethod)) {
950
            throw new \InvalidArgumentException('Payment method must be string');
951
        }
952
        if ($paymentSystem !== null && !is_string($paymentSystem)) {
953
            throw new \InvalidArgumentException('Payment system must be string');
954
        }
955
        if ($paymentMidName !== null && !is_string($paymentMidName)) {
956
            throw new \InvalidArgumentException('Payment MID name must be string');
957
        }
958
        if ($paymentAccountId !== null && !is_string($paymentAccountId)) {
959
            throw new \InvalidArgumentException('Payment account id must be string');
960
        }
961 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...
962
            throw new \InvalidArgumentException('Transaction amount converted must be float');
963
        }
964
965
        $this->replace('transaction_id', $transactionId);
966
        $this->replace('transaction_source', $transactionSource);
967
        $this->replace('transaction_type', $transactionType);
968
        $this->replace('transaction_mode', $transactionMode);
969
        $this->replace('transaction_timestamp', $transactionTimestamp);
970
        $this->replace('transaction_amount', floatval($transactionAmount));
971
        $this->replace('transaction_amount_converted', floatval($amountConverted));
972
        $this->replace('transaction_currency', $transactionCurrency);
973
        $this->replace('payment_method', $paymentMethod);
974
        $this->replace('payment_system', $paymentSystem);
975
        $this->replace('payment_mid', $paymentMidName);
976
        $this->replace('payment_account_id', $paymentAccountId);
977
978
        return $this;
979
    }
980
981
    /**
982
     * Provides Card data to envelope
983
     *
984
     * @param string|null $cardId
985
     * @param int|null $cardBin
986
     * @param string|null $cardLast4
987
     * @param int|null $expirationMonth
988
     * @param int|null $expirationYear
989
     *
990
     * @return $this
991
     */
992
    public function addCardData(
993
        $cardBin,
994
        $cardLast4,
995
        $expirationMonth,
996
        $expirationYear,
997
        $cardId = null
998
    ) {
999
        if ($cardId !== null && !is_string($cardId)) {
1000
            throw new \InvalidArgumentException('Card ID must be string');
1001
        }
1002
        if ($cardBin !== null && !is_int($cardBin)) {
1003
            throw new \InvalidArgumentException('Card BIN must be integer');
1004
        }
1005
        if ($cardLast4 !== null && !is_string($cardLast4)) {
1006
            throw new \InvalidArgumentException('Card last4  must be string');
1007
        }
1008
        if ($expirationMonth !== null && !is_int($expirationMonth)) {
1009
            throw new \InvalidArgumentException('Expiration month must be integer');
1010
        }
1011
        if ($expirationYear !== null && !is_int($expirationYear)) {
1012
            throw new \InvalidArgumentException('Expiration year must be integer');
1013
        }
1014
1015
        $this->replace('card_id', $cardId);
1016
        $this->replace('card_bin', $cardBin);
1017
        $this->replace('card_last4', $cardLast4);
1018
        $this->replace('expiration_month', $expirationMonth);
1019
        $this->replace('expiration_year', $expirationYear);
1020
1021
        return $this;
1022
    }
1023
1024
    /**
1025
     * Provides billing data to envelope
1026
     *
1027
     * @param string|null $billingFirstName
1028
     * @param string|null $billingLastName
1029
     * @param string|null $billingFullName
1030
     * @param string|null $billingCountry
1031
     * @param string|null $billingState
1032
     * @param string|null $billingCity
1033
     * @param string|null $billingAddress
1034
     * @param string|null $billingZip
1035
     *
1036
     * @return $this
1037
     */
1038
    public function addBillingData(
1039
        $billingFirstName = null,
1040
        $billingLastName = null,
1041
        $billingFullName = null,
1042
        $billingCountry = null,
1043
        $billingState = null,
1044
        $billingCity = null,
1045
        $billingAddress = null,
1046
        $billingZip = null
1047
    ) {
1048
        if ($billingFirstName !== null && !is_string($billingFirstName)) {
1049
            throw new \InvalidArgumentException('Billing first name must be string');
1050
        }
1051
        if ($billingLastName !== null && !is_string($billingLastName)) {
1052
            throw new \InvalidArgumentException('Billing last name must be string');
1053
        }
1054
        if ($billingFullName !== null && !is_string($billingFullName)) {
1055
            throw new \InvalidArgumentException('Billing full name must be string');
1056
        }
1057
        if ($billingCountry !== null && !is_string($billingCountry)) {
1058
            throw new \InvalidArgumentException('Billing country name must be string');
1059
        }
1060
        if ($billingState !== null && !is_string($billingState)) {
1061
            throw new \InvalidArgumentException('Billing state must be string');
1062
        }
1063
        if ($billingCity !== null && !is_string($billingCity)) {
1064
            throw new \InvalidArgumentException('Billing city must be string');
1065
        }
1066
        if ($billingAddress !== null && !is_string($billingAddress)) {
1067
            throw new \InvalidArgumentException('Billing address must be string');
1068
        }
1069
        if ($billingZip !== null && !is_string($billingZip)) {
1070
            throw new \InvalidArgumentException('Billing zip must be string');
1071
        }
1072
1073
        $this->replace('billing_firstname', $billingFirstName);
1074
        $this->replace('billing_lastname', $billingLastName);
1075
        $this->replace('billing_fullname', $billingFullName);
1076
        $this->replace('billing_country', $billingCountry);
1077
        $this->replace('billing_state', $billingState);
1078
        $this->replace('billing_city', $billingCity);
1079
        $this->replace('billing_address', $billingAddress);
1080
        $this->replace('billing_zip', $billingZip);
1081
1082
        return $this;
1083
    }
1084
1085
    /**
1086
     * Provides product information to envelope
1087
     *
1088
     * @param float|null $productQuantity
1089
     * @param string|null $productName
1090
     * @param string|null $productDescription
1091
     *
1092
     * @return $this
1093
     */
1094 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...
1095
        $productQuantity = null,
1096
        $productName = null,
1097
        $productDescription = null
1098
    ) {
1099
        if ($productQuantity !== null && !is_int($productQuantity) && !is_float($productQuantity)) {
1100
            throw new \InvalidArgumentException('Product quantity must be int or float');
1101
        }
1102
        if ($productName !== null && !is_string($productName)) {
1103
            throw new \InvalidArgumentException('Product name must be string');
1104
        }
1105
        if ($productDescription !== null && !is_string($productDescription)) {
1106
            throw new \InvalidArgumentException('Product description must be string');
1107
        }
1108
1109
        $this->replace('product_quantity', $productQuantity);
1110
        $this->replace('product_name', $productName);
1111
        $this->replace('product_description', $productDescription);
1112
1113
        return $this;
1114
    }
1115
1116
    /**
1117
     * Provides payout information to envelope
1118
     *
1119
     * @param string $payoutId
1120
     * @param int $payoutTimestamp
1121
     * @param int|float $payoutAmount
1122
     * @param string $payoutCurrency
1123
     * @param string|null $payoutCardId
1124
     * @param string|null $payoutAccountId
1125
     * @param string|null $payoutMethod
1126
     * @param string|null $payoutSystem
1127
     * @param string|null $payoutMid
1128
     * @param int|float|null $amountConverted
1129
     * @param int|null $payoutCardBin
1130
     * @param string|null $payoutCardLast4
1131
     * @param int|null $payoutExpirationMonth
1132
     * @param int|null $payoutExpirationYear
1133
     *
1134
     * @return $this
1135
     */
1136
    public function addPayoutData(
1137
        $payoutId,
1138
        $payoutTimestamp,
1139
        $payoutAmount,
1140
        $payoutCurrency,
1141
        $payoutCardId =  null,
1142
        $payoutAccountId = null,
1143
        $payoutMethod = null,
1144
        $payoutSystem = null,
1145
        $payoutMid = null,
1146
        $amountConverted = null,
1147
        $payoutCardBin = null,
1148
        $payoutCardLast4 = null,
1149
        $payoutExpirationMonth = null,
1150
        $payoutExpirationYear = null
1151
    ) {
1152
        if (!is_string($payoutId)) {
1153
            throw new \InvalidArgumentException('Payout ID must be string');
1154
        }
1155
        if (!is_int($payoutTimestamp)) {
1156
            throw new \InvalidArgumentException('Payout timestamp must be int');
1157
        }
1158
        if (!is_float($payoutAmount) && !is_int($payoutAmount)) {
1159
            throw new \InvalidArgumentException('Amount must be number');
1160
        }
1161
        if (!is_string($payoutCurrency)) {
1162
            throw new \InvalidArgumentException('Payout currency must be string');
1163
        }
1164
        if ($payoutAccountId !== null && !is_string($payoutAccountId)) {
1165
            throw new \InvalidArgumentException('Account ID must be string');
1166
        }
1167
        if ($payoutCardId !== null && !is_string($payoutCardId)) {
1168
            throw new \InvalidArgumentException('Card ID must be string');
1169
        }
1170
        if ($payoutMethod !== null && !is_string($payoutMethod)) {
1171
            throw new \InvalidArgumentException('Payout method must be string');
1172
        }
1173
        if ($payoutSystem !== null && !is_string($payoutSystem)) {
1174
            throw new \InvalidArgumentException('Payout system must be string');
1175
        }
1176
        if ($payoutMid !== null && !is_string($payoutMid)) {
1177
            throw new \InvalidArgumentException('Payout MID must be string');
1178
        }
1179 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...
1180
            throw new \InvalidArgumentException('Payout converted amount must be number');
1181
        }
1182
        if ($payoutCardBin !== null && !is_int($payoutCardBin)) {
1183
            throw new \InvalidArgumentException('Payout card BIN must be integer');
1184
        }
1185
        if ($payoutCardLast4 !== null && !is_string($payoutCardLast4)) {
1186
            throw new \InvalidArgumentException('Payout last 4 must be string');
1187
        }
1188
        if ($payoutExpirationMonth !== null && !is_int($payoutExpirationMonth)) {
1189
            throw new \InvalidArgumentException('Payout card expiration month must be integer');
1190
        }
1191
        if ($payoutExpirationYear !== null && !is_int($payoutExpirationYear)) {
1192
            throw new \InvalidArgumentException('Payout card expiration year must be integer');
1193
        }
1194
1195
        $this->replace('payout_id', $payoutId);
1196
        $this->replace('payout_timestamp', $payoutTimestamp);
1197
        $this->replace('payout_card_id', $payoutCardId);
1198
        $this->replace('payout_account_id', $payoutAccountId);
1199
        $this->replace('payout_amount', (float) $payoutAmount);
1200
        $this->replace('payout_currency', $payoutCurrency);
1201
        $this->replace('payout_method', $payoutMethod);
1202
        $this->replace('payout_system', $payoutSystem);
1203
        $this->replace('payout_mid', $payoutMid);
1204
        $this->replace('payout_amount_converted', (float) $amountConverted);
1205
        $this->replace('payout_card_bin', $payoutCardBin);
1206
        $this->replace('payout_card_last4', $payoutCardLast4);
1207
        $this->replace('payout_expiration_month', $payoutExpirationMonth);
1208
        $this->replace('payout_expiration_year', $payoutExpirationYear);
1209
1210
        return $this;
1211
    }
1212
1213
    /**
1214
     * Provides install information to envelope
1215
     *
1216
     * @param int $installTimestamp
1217
     *
1218
     * @return $this
1219
     */
1220
    public function addInstallData($installTimestamp)
1221
    {
1222
        if (!is_int($installTimestamp)) {
1223
            throw new \InvalidArgumentException('Install timestamp must be int');
1224
        }
1225
1226
        $this->replace('install_timestamp', $installTimestamp);
1227
1228
        return $this;
1229
    }
1230
1231
    /**
1232
     * Provides refund information to envelope
1233
     *
1234
     * @param string $refundId
1235
     * @param int|float $refundAmount
1236
     * @param string $refundCurrency
1237
     * @param int|null $refundTimestamp
1238
     * @param int|float|null $refundAmountConverted
1239
     * @param string|null $refundSource
1240
     * @param string|null $refundType
1241
     * @param string|null $refundCode
1242
     * @param string|null $refundReason
1243
     * @param string|null $agentId
1244
     * @param string|null $refundMethod
1245
     * @param string|null $refundSystem
1246
     * @param string|null $refundMid
1247
     *
1248
     * @return $this
1249
     */
1250
    public function addRefundData(
1251
        $refundId,
1252
        $refundTimestamp,
1253
        $refundAmount,
1254
        $refundCurrency,
1255
        $refundAmountConverted = null,
1256
        $refundSource = null,
1257
        $refundType = null,
1258
        $refundCode = null,
1259
        $refundReason = null,
1260
        $agentId = null,
1261
        $refundMethod = null,
1262
        $refundSystem = null,
1263
        $refundMid = null
1264
    ) {
1265
        if (!is_string($refundId)) {
1266
            throw new \InvalidArgumentException('Refund ID must be string');
1267
        }
1268
        if (!is_int($refundTimestamp)) {
1269
            throw new \InvalidArgumentException('Refund timestamp must be int');
1270
        }
1271
        if (!is_float($refundAmount) && !is_int($refundAmount)) {
1272
            throw new \InvalidArgumentException('Amount must be number');
1273
        }
1274
        if (!is_string($refundCurrency)) {
1275
            throw new \InvalidArgumentException('Refund currency must be string');
1276
        }
1277
        if ($refundAmountConverted !== null && !is_float($refundAmountConverted) && !is_int($refundAmountConverted)) {
1278
            throw new \InvalidArgumentException('Refund converted amount must be number');
1279
        }
1280
        if ($refundSource !== null && !is_string($refundSource)) {
1281
            throw new \InvalidArgumentException('Refund source must be string');
1282
        }
1283
        if ($refundType !== null && !is_string($refundType)) {
1284
            throw new \InvalidArgumentException('Refund type must be string');
1285
        }
1286
        if ($refundCode !== null && !is_string($refundCode)) {
1287
            throw new \InvalidArgumentException('Refund code must be string');
1288
        }
1289
        if ($refundReason !== null && !is_string($refundReason)) {
1290
            throw new \InvalidArgumentException('Refund reason must be string');
1291
        }
1292
        if ($agentId !== null && !is_string($agentId)) {
1293
            throw new \InvalidArgumentException('Agent id must be string');
1294
        }
1295
        if ($refundMethod !== null && !is_string($refundMethod)) {
1296
            throw new \InvalidArgumentException('Refund method must be string');
1297
        }
1298
        if ($refundSystem !== null && !is_string($refundSystem)) {
1299
            throw new \InvalidArgumentException('Refund system must be string');
1300
        }
1301
        if ($refundMid !== null && !is_string($refundMid)) {
1302
            throw new \InvalidArgumentException('Refund mid must be string');
1303
        }
1304
1305
        $this->replace('refund_id', $refundId);
1306
        $this->replace('refund_timestamp', $refundTimestamp);
1307
        $this->replace('refund_amount', $refundAmount);
1308
        $this->replace('refund_currency', $refundCurrency);
1309
        $this->replace('refund_amount_converted', $refundAmountConverted);
1310
        $this->replace('refund_source', $refundSource);
1311
        $this->replace('refund_type', $refundType);
1312
        $this->replace('refund_code', $refundCode);
1313
        $this->replace('refund_reason', $refundReason);
1314
        $this->replace('agent_id', $agentId);
1315
        $this->replace('refund_method', $refundMethod);
1316
        $this->replace('refund_system', $refundSystem);
1317
        $this->replace('refund_mid', $refundMid);
1318
1319
        return $this;
1320
    }
1321
1322
    /**
1323
     * Provides postback information to envelope
1324
     *
1325
     * @param string|null $transactionStatus
1326
     * @param string|null $code
1327
     * @param string|null $reason
1328
     * @param string|null $secure3d
1329
     * @param string|null $avsResult
1330
     * @param string|null $cvvResult
1331
     * @param string|null $pspCode
1332
     * @param string|null $pspReason
1333
     * @param string|null $arn
1334
     * @param string|null $paymentAccountId
1335
     * @return $this
1336
     */
1337
    public function addPostbackData(
1338
        $transactionStatus = null,
1339
        $code = null,
1340
        $reason = null,
1341
        $secure3d = null,
1342
        $avsResult = null,
1343
        $cvvResult = null,
1344
        $pspCode = null,
1345
        $pspReason = null,
1346
        $arn = null,
1347
        $paymentAccountId = null
1348
    ) {
1349
        if ($transactionStatus !== null && !is_string($transactionStatus)) {
1350
            throw new \InvalidArgumentException('Transaction status must be string');
1351
        }
1352
        if ($code !== null && !is_string($code)) {
1353
            throw new \InvalidArgumentException('Code must be string');
1354
        }
1355
        if ($reason !== null && !is_string($reason)) {
1356
            throw new \InvalidArgumentException('Reason must be string');
1357
        }
1358
        if ($secure3d !== null && !is_string($secure3d)) {
1359
            throw new \InvalidArgumentException('Secure3d must be string');
1360
        }
1361
        if ($avsResult !== null && !is_string($avsResult)) {
1362
            throw new \InvalidArgumentException('AvsResult must be string');
1363
        }
1364
        if ($cvvResult !== null && !is_string($cvvResult)) {
1365
            throw new \InvalidArgumentException('CvvResult must be string');
1366
        }
1367
        if ($pspCode !== null && !is_string($pspCode)) {
1368
            throw new \InvalidArgumentException('PspCode must be string');
1369
        }
1370
        if ($pspReason !== null && !is_string($pspReason)) {
1371
            throw new \InvalidArgumentException('PspReason must be string');
1372
        }
1373
        if ($arn !== null && !is_string($arn)) {
1374
            throw new \InvalidArgumentException('Arn must be string');
1375
        }
1376
        if ($paymentAccountId !== null && !is_string($paymentAccountId)) {
1377
            throw new \InvalidArgumentException('PaymentAccoutId must be string');
1378
        }
1379
1380
1381
        $this->replace('transaction_status', $transactionStatus);
1382
        $this->replace('code', $code);
1383
        $this->replace('reason', $reason);
1384
        $this->replace('secure3d', $secure3d);
1385
        $this->replace('avs_result', $avsResult);
1386
        $this->replace('cvv_result', $cvvResult);
1387
        $this->replace('psp_code', $pspCode);
1388
        $this->replace('psp_reason', $pspReason);
1389
        $this->replace('arn', $arn);
1390
        $this->replace('payment_account_id', $paymentAccountId);
1391
1392
        return $this;
1393
    }
1394
1395
    /**
1396
     * Adds custom data field to envelope
1397
     *
1398
     * @param string $name
1399
     * @param string $value
1400
     *
1401
     * @return $this
1402
     */
1403
    public function addCustomField($name, $value)
1404
    {
1405
        if (!is_string($name)) {
1406
            throw new \InvalidArgumentException('Custom field name must be string');
1407
        }
1408
        if (!is_string($value)) {
1409
            throw new \InvalidArgumentException('Custom field value must be string');
1410
        }
1411
1412
        if (strlen($name) < 8 || substr($name, 0, 7) !== 'custom_') {
1413
            $name = 'custom_' . $name;
1414
        }
1415
1416
        $this->replace($name, $value);
1417
        return $this;
1418
    }
1419
}
1420