-
Notifications
You must be signed in to change notification settings - Fork 19
/
MinFraud.php
1436 lines (1297 loc) · 57.3 KB
/
MinFraud.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
declare(strict_types=1);
namespace MaxMind;
use MaxMind\Exception\AuthenticationException;
use MaxMind\Exception\HttpException;
use MaxMind\Exception\InsufficientFundsException;
use MaxMind\Exception\InvalidInputException;
use MaxMind\Exception\InvalidRequestException;
use MaxMind\Exception\WebServiceException;
use MaxMind\MinFraud\Model\Factors;
use MaxMind\MinFraud\Model\Insights;
use MaxMind\MinFraud\Model\Score;
use MaxMind\MinFraud\Util;
/**
* This class provides a client API for accessing MaxMind minFraud Score,
* Insights and Factors.
*
* ## Usage ##
*
* The constructor takes your MaxMind account ID and license key. The object
* returned is immutable. To build up a request, call the `->with*()` methods.
* Each of these returns a new object (a clone of the original) with the
* additional data. These can be chained together:
*
* ```
* $client = new MinFraud(6, 'LICENSE_KEY');
*
* $score = $client->withDevice(['ip_address' => '1.1.1.1',
* 'session_age' => 3600.5,
* 'session_id' => 'foobar',
* 'accept_language' => 'en-US'])
* ->withEmail(['domain' => 'maxmind.com'])
* ->score();
* ```
*
* If the request fails, an exception is thrown.
*/
class MinFraud extends MinFraud\ServiceClient
{
/**
* @var array
*/
private $content;
/**
* @var bool
*/
private $hashEmail;
/**
* @var array<string>
*/
private $locales;
/**
* @param int $accountId Your MaxMind account ID
* @param string $licenseKey Your MaxMind license key
* @param array $options An array of options. Possible keys:
*
* - `host` - The host to use when connecting to the web service.
* By default, the client connects to the production host. However,
* during testing and development, you can set this option to
* 'sandbox.maxmind.com' to use the Sandbox environment's host. The
* sandbox allows you to experiment with the API without affecting your
* production data.
* - `userAgent` - The prefix for the User-Agent header to use in the
* request.
* - `caBundle` - The bundle of CA root certificates to use in the request.
* - `connectTimeout` - The connect timeout to use for the request.
* - `hashEmail` - By default, the email address is sent in plain text.
* If this is set to `true`, the email address will be normalized and
* converted to an MD5 hash before the request is sent. The email domain
* will continue to be sent in plain text.
* - `timeout` - The timeout to use for the request.
* - `proxy` - The HTTP proxy to use. May include a schema, port,
* username, and password, e.g., `http://username:[email protected]:10`.
* - `locales` - An array of locale codes to use for the location name
* properties.
* - `validateInput` - Default is `true`. Determines whether values passed
* to the `with*()` methods are validated. It is recommended that you
* leave validation on while developing and only (optionally) disable it
* before deployment.
*/
public function __construct(
int $accountId,
string $licenseKey,
array $options = []
) {
$this->hashEmail = isset($options['hashEmail']) && $options['hashEmail'];
if (isset($options['locales'])) {
$this->locales = $options['locales'];
} else {
$this->locales = ['en'];
}
parent::__construct($accountId, $licenseKey, $options);
}
/**
* This returns a `MinFraud` object with the array to be sent to the web
* service set to `$values`. Existing values will be replaced.
*
* @link https://dev.maxmind.com/minfraud/api-documentation?lang=en
* minFraud API docs
*
* @return MinFraud A new immutable MinFraud object. This object is
* a clone of the original with additional data.
*/
public function with(array $values): self
{
$new = $this;
if (\array_key_exists('account', $values)) {
$new = $new->withAccount($this->remove($values, 'account', ['array']));
}
if (\array_key_exists('billing', $values)) {
$new = $new->withBilling($this->remove($values, 'billing', ['array']));
}
if (\array_key_exists('credit_card', $values)) {
$new = $new->withCreditCard($this->remove($values, 'credit_card', ['array']));
}
if (\array_key_exists('custom_inputs', $values)) {
$new = $new->withCustomInputs($this->remove($values, 'custom_inputs', ['array']));
}
if (\array_key_exists('device', $values)) {
$new = $new->withDevice($this->remove($values, 'device', ['array']));
}
if (\array_key_exists('email', $values)) {
$new = $new->withEmail($this->remove($values, 'email', ['array']));
}
if (\array_key_exists('event', $values)) {
$new = $new->withEvent($this->remove($values, 'event', ['array']));
}
if (\array_key_exists('order', $values)) {
$new = $new->withOrder($this->remove($values, 'order', ['array']));
}
if (\array_key_exists('payment', $values)) {
$new = $new->withPayment($this->remove($values, 'payment', ['array']));
}
if (\array_key_exists('shipping', $values)) {
$new = $new->withShipping($this->remove($values, 'shipping', ['array']));
}
if (\array_key_exists('shopping_cart', $values)) {
foreach ($this->remove($values, 'shopping_cart', ['array']) as $item) {
$new = $new->withShoppingCartItem($item);
}
}
$this->verifyEmpty($values);
return $new;
}
/**
* This returns a `MinFraud` object with the `device` array set to
* the values provided. Existing `device` data will be replaced.
*
* @param array $values An array of device data. The keys are the same as
* the JSON keys. You may use either this or the named
* arguments, but not both.
* @param string|null $ipAddress The IP address associated with the device
* used by the customer in the transaction.
* The IP address must be in IPv4 or IPv6
* presentation format, i.e., dotted-quad
* notation or the IPv6 hexadecimal-colon
* notation.
* @param string|null $userAgent The HTTP `User-Agent` header of the browser
* used in the transaction
* @param string|null $acceptLanguage The HTTP `Accept-Language` header of
* the device used in the transaction
* @param float|null $sessionAge The number of seconds between the creation
* of the user's session and the time of the
* transaction. Note that `session_age` is not
* the duration of the current visit, but the
* time since the start of the first visit.
* @param string|null $sessionId An ID that uniquely identifies a visitor's
* session on the site
*
* @return MinFraud A new immutable MinFraud object. This object is a clone
* of the original with additional data.
*
* @link https://dev.maxmind.com/minfraud/api-documentation/requests?lang=en#schema--request--device
* minFraud device API docs
*/
public function withDevice(
array $values = [],
?string $acceptLanguage = null,
?string $ipAddress = null,
?float $sessionAge = null,
?string $sessionId = null,
?string $userAgent = null,
): self {
if (\count($values) !== 0) {
if (\func_num_args() !== 1) {
throw new \InvalidArgumentException(
'You may only provide the $values array or named arguments, not both.',
);
}
$acceptLanguage = $this->remove($values, 'accept_language');
$ipAddress = $this->remove($values, 'ip_address');
if (($v = $this->remove($values, 'session_age', ['double', 'float', 'integer', 'string'])) && $v !== null) {
if (!is_numeric($v)) {
$this->maybeThrowInvalidInputException('Expected session_age to be a number');
}
$sessionAge = (float) $v;
}
if (isset($values['session_id'])) {
if (($v = $this->remove($values, 'session_id', ['integer', 'string'])) && $v !== null) {
$sessionId = (string) $v;
}
}
if ($sessionId) {
$userAgent = $this->remove($values, 'user_agent');
}
$this->verifyEmpty($values);
}
if ($acceptLanguage !== null) {
$values['accept_language'] = $acceptLanguage;
}
if ($ipAddress !== null) {
if (!filter_var($ipAddress, \FILTER_VALIDATE_IP)) {
$this->maybeThrowInvalidInputException("$ipAddress is an invalid IP address");
}
$values['ip_address'] = $ipAddress;
}
if ($sessionAge !== null) {
if ($sessionAge < 0) {
$this->maybeThrowInvalidInputException("Session age ($sessionAge) must be greater than or equal to 0");
}
$values['session_age'] = $sessionAge;
}
if ($sessionId !== null) {
if (!\is_string($sessionId)
|| $sessionId === ''
|| \strlen($sessionId) > 255) {
$this->maybeThrowInvalidInputException(
"Session ID ($sessionId) must be a string with length between 1 and 255",
);
}
$values['session_id'] = $sessionId;
}
if ($userAgent !== null) {
$values['user_agent'] = $userAgent;
}
$new = clone $this;
$new->content['device'] = $values;
return $new;
}
/**
* This returns a `MinFraud` object with the `event` array set to
* the values provided. Existing `event` data will be replaced.
*
* @param array $values An array of event data. The keys are the same as
* the JSON keys. You may use either this or the named
* arguments, but not both.
* @param string|null $shopId Your internal ID for the shop, affiliate, or
* merchant this order is coming from. Required for
* minFraud users who are resellers, payment
* providers, gateways and affiliate networks. No
* specific format is required.
* @param string|null $time The date and time the event occurred. The string
* must be in the RFC 3339 date-time format. The time
* must be within the past year. If this field is not
* in the request, the current time will be used.
* @param string|null $transactionId Your internal ID for the transaction. We
* can use this to locate a specific
* transaction in our logs, and it will also
* show up in email alerts and notifications
* from us to you. No specific format is
* required.
* @param string|null $type The type of event being scored. The valid types
* are:
* - `account_creation`
* - `account_login`
* - `email_change`
* - `password_reset`
* - `payout_change`
* - `purchase`
* - `recurring_purchase`
* - `referral`
* - `survey`
*
* @return MinFraud A new immutable MinFraud object. This object is a clone of
* the original with additional data.
*
* @link https://dev.maxmind.com/minfraud/api-documentation/requests?lang=en#schema--request--event
* minFraud event API docs
*/
public function withEvent(
array $values = [],
?string $shopId = null,
?string $time = null,
?string $transactionId = null,
?string $type = null,
): self {
if (\count($values) !== 0) {
if (\func_num_args() !== 1) {
throw new \InvalidArgumentException(
'You may only provide the $values array or named arguments, not both.',
);
}
$shopId = $this->remove($values, 'shop_id');
$time = $this->remove($values, 'time');
$transactionId = $this->remove($values, 'transaction_id');
$type = $this->remove($values, 'type');
$this->verifyEmpty($values);
}
if ($shopId !== null) {
$values['shop_id'] = $shopId;
}
if ($time !== null) {
if (\DateTime::createFromFormat(\DateTime::RFC3339, $time) === false
&& \DateTime::createFromFormat(\DateTime::RFC3339_EXTENDED, $time) === false
) {
$this->maybeThrowInvalidInputException("$time is not a valid RFC 3339 formatted datetime string");
}
$values['time'] = $time;
}
if ($transactionId !== null) {
$values['transaction_id'] = $transactionId;
}
if ($type !== null) {
if (!\in_array($type, [
'account_creation',
'account_login',
'email_change',
'password_reset',
'payout_change',
'purchase',
'recurring_purchase',
'referral',
'survey',
], true)) {
$this->maybeThrowInvalidInputException("$type is not a valid event type");
}
$values['type'] = $type;
}
$new = clone $this;
$new->content['event'] = $values;
return $new;
}
/**
* This returns a `MinFraud` object with the `account` array set to
* the values provided. Existing `` data will be replaced.
*
* @link https://dev.maxmind.com/minfraud/api-documentation/requests?lang=en#schema--request--account
* minFraud account API docs
*
* @param array $values An array of account data. The keys are the same as
* the JSON keys. You may use either this or the named
* arguments, but not both.
* @param string|null $userId a unique user ID associated with the end-user
* in your system
* @param string|null $usernameMd5 an MD5 hash as a hexadecimal string of
* the username or login name associated
* with the account
*
* @return MinFraud A new immutable MinFraud object. This object is a clone
* of the original with additional data.
*/
public function withAccount(
array $values = [],
?string $userId = null,
?string $usernameMd5 = null,
): self {
if (\count($values) !== 0) {
if (\func_num_args() !== 1) {
throw new \InvalidArgumentException(
'You may only provide the $values array or named arguments, not both.',
);
}
$userId = $this->remove($values, 'user_id');
$usernameMd5 = $this->remove($values, 'username_md5');
$this->verifyEmpty($values);
}
if ($userId !== null) {
$values['user_id'] = $userId;
}
if ($usernameMd5 !== null) {
if (!preg_match('/^[a-fA-F0-9]{32}$/', $usernameMd5)) {
$this->maybeThrowInvalidInputException("$usernameMd5 must be an MD5");
}
$values['username_md5'] = $usernameMd5;
}
$new = clone $this;
$new->content['account'] = $values;
return $new;
}
/**
* This returns a `MinFraud` object with the `email` array set to
* values provided. Existing `email` data will be replaced.
*
* @link https://dev.maxmind.com/minfraud/api-documentation/requests?lang=en#schema--request--email
* minFraud email API docs
*
* @param array $values An array of email data. The keys are the same as
* the JSON keys. You may use either this or the named
* arguments, but not both.
* @param string|null $address The email address used in the transaction.
* This field must be a valid email address.
* @param string|null $domain The domain of the email address used in the
* transaction. Do not include the `@` in this
* field.
*
* @return MinFraud A new immutable MinFraud object. This object is a clone
* of the original with additional data.
*/
public function withEmail(
array $values = [],
?string $address = null,
?string $domain = null,
): self {
if (\count($values) !== 0) {
if (\func_num_args() !== 1) {
throw new \InvalidArgumentException(
'You may only provide the $values array or named arguments, not both.',
);
}
$address = $this->remove($values, 'address');
$domain = $this->remove($values, 'domain');
$this->verifyEmpty($values);
}
if ($address !== null) {
if (!filter_var($address, \FILTER_VALIDATE_EMAIL)
&& !preg_match('/^[a-fA-F0-9]{32}$/', $address)) {
$this->maybeThrowInvalidInputException("$address is an invalid email address or MD5");
}
$values['address'] = $address;
}
if ($domain !== null) {
if (!filter_var($domain, \FILTER_VALIDATE_DOMAIN, \FILTER_FLAG_HOSTNAME) || !str_contains($domain, '.')) {
$this->maybeThrowInvalidInputException("$domain is an invalid domain name");
}
$values['domain'] = $domain;
}
$new = clone $this;
$new->content['email'] = $values;
if ($this->hashEmail) {
$new->content = Util::maybeHashEmail($new->content);
}
return $new;
}
/**
* This returns a `MinFraud` object with the `billing` array set to
* `$values`. Existing `billing` data will be replaced.
*
* @link https://dev.maxmind.com/minfraud/api-documentation/requests?lang=en#schema--request--billing
* minFraud billing API docs
*
* @param array $values An array of billing data. The keys are the same as
* the JSON keys. You may use either this or the named
* arguments, but not both.
* @param string|null $address The first line of the user's billing address
* @param string|null $address2 The second line of the user's billing address
* @param string|null $city The city of the user's billing address
* @param string|null $company The company of the end user as provided in
* their billing information
* @param string|null $country The two character ISO 3166-1 alpha-2 country
* code of the user's billing address
* @param string|null $firstName The first name of the end user as provided
* in their billing information
* @param string|null $lastName The last name of the end user as provided
* in their billing information
* @param string|null $phoneCountryCode The country code for phone number
* associated with the user's billing
* address. If you provide this
* information then you must provide
* at least one digit.
* @param string|null $phoneNumber The phone number without the country code
* for the user's billing address. Punctuation
* characters will be stripped. After
* stripping punctuation characters, the
* number must contain only digits.
* @param string|null $postal The postal code of the user's billing address
* @param string|null $region The ISO 3166-2 subdivision code for the user's
* billing address
*
* @return MinFraud A new immutable MinFraud object. This object is a clone
* of the original with additional data.
*/
public function withBilling(
array $values = [],
?string $address = null,
?string $address2 = null,
?string $city = null,
?string $company = null,
?string $country = null,
?string $firstName = null,
?string $lastName = null,
?string $phoneCountryCode = null,
?string $phoneNumber = null,
?string $postal = null,
?string $region = null,
): self {
if (\count($values) !== 0) {
if (\func_num_args() !== 1) {
throw new \InvalidArgumentException(
'You may only provide the $values array or named arguments, not both.',
);
}
$address = $this->remove($values, 'address');
$address2 = $this->remove($values, 'address_2');
$city = $this->remove($values, 'city');
$company = $this->remove($values, 'company');
$country = $this->remove($values, 'country');
$firstName = $this->remove($values, 'first_name');
$lastName = $this->remove($values, 'last_name');
$phoneCountryCode = $this->remove($values, 'phone_country_code');
$phoneNumber = $this->remove($values, 'phone_number');
$postal = $this->remove($values, 'postal');
$region = $this->remove($values, 'region');
$this->verifyEmpty($values);
}
if ($address !== null) {
$values['address'] = $address;
}
if ($address2 !== null) {
$values['address_2'] = $address2;
}
if ($city !== null) {
$values['city'] = $city;
}
if ($company !== null) {
$values['company'] = $company;
}
if ($country !== null) {
$this->verifyCountryCode($country);
$values['country'] = $country;
}
if ($firstName !== null) {
$values['first_name'] = $firstName;
}
if ($lastName !== null) {
$values['last_name'] = $lastName;
}
if ($phoneCountryCode !== null) {
$this->verifyPhoneCountryCode($phoneCountryCode);
$values['phone_country_code'] = $phoneCountryCode;
}
if ($phoneNumber !== null) {
$values['phone_number'] = $phoneNumber;
}
if ($postal !== null) {
$values['postal'] = $postal;
}
if ($region !== null) {
$this->verifyRegionCode($region);
$values['region'] = $region;
}
$new = clone $this;
$new->content['billing'] = $values;
return $new;
}
/**
* This returns a `MinFraud` object with the `shipping` array set to
* the values provided. Existing `shipping` data will be replaced.
*
* @link https://dev.maxmind.com/minfraud/api-documentation/requests?lang=en#schema--request--shipping
* minFraud shipping API docs
*
* @param array $values An array of shipping data. The keys are the same as
* the JSON keys. You may use either this or the named
* arguments, but not both.
* @param string|null $company The company of the end user as provided in
* their shipping information
* @param string|null $address The first line of the user's shipping address
* @param string|null $city The city of the user's shipping address
* @param string|null $region The ISO 3166-2 subdivision code for the user's
* shipping address
* @param string|null $country The two character ISO 3166-1 alpha-2 country
* code of the user's shipping address
* @param string|null $postal The postal code of the user's shipping address
*
* @return MinFraud A new immutable MinFraud object. This object is
* a clone of the original with additional data.
*/
public function withShipping(
array $values = [],
?string $address = null,
?string $address2 = null,
?string $city = null,
?string $company = null,
?string $country = null,
?string $deliverySpeed = null,
?string $firstName = null,
?string $lastName = null,
?string $phoneCountryCode = null,
?string $phoneNumber = null,
?string $postal = null,
?string $region = null,
): self {
if (\count($values) !== 0) {
if (\func_num_args() !== 1) {
throw new \InvalidArgumentException(
'You may only provide the $values array or named arguments, not both.',
);
}
$address = $this->remove($values, 'address');
$address2 = $this->remove($values, 'address_2');
$city = $this->remove($values, 'city');
$company = $this->remove($values, 'company');
$country = $this->remove($values, 'country');
$deliverySpeed = $this->remove($values, 'delivery_speed');
$firstName = $this->remove($values, 'first_name');
$lastName = $this->remove($values, 'last_name');
$phoneCountryCode = $this->remove($values, 'phone_country_code');
$phoneNumber = $this->remove($values, 'phone_number');
$postal = $this->remove($values, 'postal');
$region = $this->remove($values, 'region');
$this->verifyEmpty($values);
}
if ($address !== null) {
$values['address'] = $address;
}
if ($address2 !== null) {
$values['address_2'] = $address2;
}
if ($city !== null) {
$values['city'] = $city;
}
if ($company !== null) {
$values['company'] = $company;
}
if ($country !== null) {
$this->verifyCountryCode($country);
$values['country'] = $country;
}
if ($deliverySpeed !== null) {
if (!\in_array($deliverySpeed, ['same_day', 'overnight', 'expedited', 'standard'], true)) {
$this->maybeThrowInvalidInputException("$deliverySpeed is not a valid delivery speed");
}
$values['delivery_speed'] = $deliverySpeed;
}
if ($firstName !== null) {
$values['first_name'] = $firstName;
}
if ($lastName !== null) {
$values['last_name'] = $lastName;
}
if ($phoneCountryCode !== null) {
$this->verifyPhoneCountryCode($phoneCountryCode);
$values['phone_country_code'] = $phoneCountryCode;
}
if ($phoneNumber !== null) {
$values['phone_number'] = $phoneNumber;
}
if ($postal !== null) {
$values['postal'] = $postal;
}
if ($region !== null) {
$this->verifyRegionCode($region);
$values['region'] = $region;
}
$new = clone $this;
$new->content['shipping'] = $values;
return $new;
}
/**
* This returns a `MinFraud` object with the `payment` array set to
* the values provided. Existing `payment` data will be replaced.
*
* @link https://dev.maxmind.com/minfraud/api-documentation/requests?lang=en#schema--request--payment
* minFraud payment API docs
*
* @param array $values An array of payment data. The keys are the same as
* the JSON keys. You may use either this or the named
* arguments, but not both.
* @param string|null $declineCode The decline code as provided by your
* payment processor. If the transaction
* was not declined, do not include this field.
* @param string|null $processor The payment processor used for the transaction
* @param bool|null $wasAuthorized The authorization outcome from the payment
* processor. If the transaction has not yet been
* approved or denied, do not include this field.
*
* @return MinFraud A new immutable MinFraud object. This object is
* a clone of the original with additional data.
*/
public function withPayment(
array $values = [],
?string $declineCode = null,
?string $processor = null,
?bool $wasAuthorized = null,
): self {
if (\count($values) !== 0) {
if (\func_num_args() !== 1) {
throw new \InvalidArgumentException(
'You may only provide the $values array or named arguments, not both.',
);
}
$declineCode = $this->remove($values, 'decline_code');
$processor = $this->remove($values, 'processor');
$wasAuthorized = $this->remove($values, 'was_authorized', ['boolean']);
$this->verifyEmpty($values);
}
if ($declineCode !== null) {
$values['decline_code'] = $declineCode;
}
if ($processor !== null) {
if (!\in_array($processor, [
'adyen',
'affirm',
'afterpay',
'altapay',
'amazon_payments',
'american_express_payment_gateway',
'apple_pay',
'aps_payments',
'authorizenet',
'balanced',
'beanstream',
'bluepay',
'bluesnap',
'boacompra',
'boku',
'bpoint',
'braintree',
'cardknox',
'cardpay',
'cashfree',
'ccavenue',
'ccnow',
'cetelem',
'chase_paymentech',
'checkout_com',
'cielo',
'collector',
'commdoo',
'compropago',
'concept_payments',
'conekta',
'coregateway',
'creditguard',
'credorax',
'ct_payments',
'cuentadigital',
'curopayments',
'cybersource',
'dalenys',
'dalpay',
'datacap',
'datacash',
'dibs',
'digital_river',
'dlocal',
'dotpay',
'ebs',
'ecomm365',
'ecommpay',
'elavon',
'emerchantpay',
'epay',
'eprocessing_network',
'epx',
'eway',
'exact',
'first_atlantic_commerce',
'first_data',
'fiserv',
'g2a_pay',
'global_payments',
'gocardless',
'google_pay',
'heartland',
'hipay',
'ingenico',
'interac',
'internetsecure',
'intuit_quickbooks_payments',
'iugu',
'klarna',
'komoju',
'lemon_way',
'mastercard_payment_gateway',
'mercadopago',
'mercanet',
'merchant_esolutions',
'mirjeh',
'mollie',
'moneris_solutions',
'neopay',
'neosurf',
'nmi',
'oceanpayment',
'oney',
'onpay',
'openbucks',
'openpaymx',
'optimal_payments',
'orangepay',
'other',
'pacnet_services',
'payeezy',
'payfast',
'paygate',
'paylike',
'payment_express',
'paymentwall',
'payone',
'paypal',
'payplus',
'paysafecard',
'paysera',
'paystation',
'paytm',
'paytrace',
'paytrail',
'payture',
'payu',
'payulatam',
'payvision',
'payway',
'payza',
'pinpayments',
'placetopay',
'posconnect',
'princeton_payment_solutions',
'psigate',
'pxp_financial',
'qiwi',
'quickpay',
'raberil',
'razorpay',
'rede',
'redpagos',
'rewardspay',
'safecharge',
'sagepay',
'securetrading',
'shopify_payments',
'simplify_commerce',
'skrill',
'smartcoin',
'smartdebit',
'solidtrust_pay',
'sps_decidir',
'stripe',
'synapsefi',
'systempay',
'telerecargas',
'towah',
'transact_pro',
'trustly',
'trustpay',
'tsys',
'usa_epay',
'vantiv',
'verepay',
'vericheck',
'vindicia',
'virtual_card_services',
'vme',
'vpos',
'windcave',
'wirecard',
'worldpay',
], true)) {
$this->maybeThrowInvalidInputException("$processor is not a valid payment processor");
}
$values['processor'] = $processor;
}
if ($wasAuthorized !== null) {
$values['was_authorized'] = $wasAuthorized;
}
$new = clone $this;
$new->content['payment'] = $values;
return $new;
}
/**
* This returns a `MinFraud` object with the `credit_card` array set to
* provided values. Existing `credit_card` data will be replaced.
*
* @link https://dev.maxmind.com/minfraud/api-documentation/requests?lang=en#schema--request--credit-card
* minFraud credit_card API docs
*
* @param array $values An array of credit card data. The keys are the same as
* the JSON keys. You may use either this or the named
* arguments, but not both.
* @param string|null $avsResult The address verification system (AVS) check
* result, as returned to you by the credit card
* processor
* @param string|null $bankName The name of the issuing bank as provided by the
* end user
* @param string|null $bankPhoneCountryCode The phone country code for the
* issuing bank as provided by the end
* user
* @param string|null $bankPhoneNumber The phone number, without the country
* code, for the issuing bank as provided by
* the end user
* @param string|null $country The two character ISO 3166-1 alpha-2 country
* code where the issuer of the card is located
* @param string|null $cvvResult The card verification value (CVV) code as
* provided by the payment processor
* @param string|null $issuerIdNumber The issuer ID number for the credit card.
* This is the first six or eight digits of
* the credit card number. It identifies the
* issuing bank.
* @param string|null $lastDigits The last digits of the credit card number.
* In most cases, you should send the last four
* digits for `lastDigits`.
* @param string|null $token A token uniquely identifying the card
* @param bool|null $was3dSecureSuccessful Whether the outcome of 3-D Secure
* verification was successful
*
* @return MinFraud A new immutable MinFraud object. This object is a clone of
* the original with additional data.
*/
public function withCreditCard(
array $values = [],
?string $avsResult = null,
?string $bankName = null,
?string $bankPhoneCountryCode = null,
?string $bankPhoneNumber = null,
?string $country = null,
?string $cvvResult = null,
?string $issuerIdNumber = null,
?string $lastDigits = null,
?string $token = null,
?bool $was3dSecureSuccessful = null,
): self {
if (\count($values) !== 0) {
if (\func_num_args() !== 1) {
throw new \InvalidArgumentException(