-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathInsights.php
More file actions
207 lines (172 loc) · 6.64 KB
/
Copy pathInsights.php
File metadata and controls
207 lines (172 loc) · 6.64 KB
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
<?php
declare(strict_types=1);
namespace MaxMind\MinFraud\Model;
/**
* Model of the Insights response.
*/
class Insights implements \JsonSerializable
{
/**
* @var BillingAddress an object containing minFraud data related to the
* billing address used in the transaction
*/
public readonly BillingAddress $billingAddress;
/**
* @var Phone an object containing minFraud data related to the billing
* phone used in the transaction
*/
public readonly Phone $billingPhone;
/**
* @var CreditCard an object containing minFraud data about the credit
* card used in the transaction
*/
public readonly CreditCard $creditCard;
/**
* @var Device this object contains information about the device that
* MaxMind believes is associated with the IP address passed
* in the request
*/
public readonly Device $device;
/**
* @var Disposition an object containing the disposition set by custom
* rules
*/
public readonly Disposition $disposition;
/**
* @var Email this object contains information about the email address
* passed in the request
*/
public readonly Email $email;
/**
* @var float the approximate US dollar value of the funds remaining on
* your MaxMind account
*/
public readonly float $fundsRemaining;
/**
* @var string This is a UUID that identifies the minFraud request. Please
* use this ID in bug reports or support requests to MaxMind
* so that we can easily identify a particular request.
*/
public readonly string $id;
/**
* @var IpAddress an object containing GeoIP and minFraud Insights
* information about the geolocated IP address
*/
public readonly IpAddress $ipAddress;
/**
* @var int the approximate number of queries remaining for this service
* before your account runs out of funds
*/
public readonly int $queriesRemaining;
/**
* @var float This property contains the risk score, from 0.01 to 99. A
* higher score indicates a higher risk of fraud. For example, a
* score of 20 indicates a 20% chance that a transaction is
* fraudulent. We never return a risk score of 0, since all
* transactions have the possibility of being fraudulent.
* Likewise we never return a risk score of 100.
*/
public readonly float $riskScore;
/**
* @var ShippingAddress an object containing minFraud data related to the
* shipping address used in the transaction
*/
public readonly ShippingAddress $shippingAddress;
/**
* @var Phone an object containing minFraud data related to the shipping
* phone used in the transaction
*/
public readonly Phone $shippingPhone;
/**
* @var array<Warning> This array contains \MaxMind\MinFraud\Model\Warning objects
* detailing issues with the request that was sent, such as
* invalid or unknown inputs. It is highly recommended that
* you check this array for issues when integrating the web
* service.
*/
public readonly array $warnings;
/**
* @param array<string, mixed> $response
* @param list<string> $locales
*/
public function __construct(array $response, array $locales = ['en'])
{
$this->disposition
= new Disposition($response['disposition'] ?? []);
$this->fundsRemaining = $response['funds_remaining'];
$this->queriesRemaining = $response['queries_remaining'];
$this->id = $response['id'];
$this->riskScore = $response['risk_score'];
$warnings = [];
if (isset($response['warnings'])) {
foreach ($response['warnings'] as $warning) {
$warnings[] = new Warning($warning);
}
}
$this->warnings = $warnings;
$this->billingAddress = new BillingAddress($response['billing_address'] ?? []);
$this->billingPhone = new Phone($response['billing_phone'] ?? []);
$this->creditCard = new CreditCard($response['credit_card'] ?? []);
$this->device = new Device($response['device'] ?? []);
$this->email = new Email($response['email'] ?? []);
$this->ipAddress = new IpAddress($response['ip_address'] ?? [], $locales);
$this->shippingAddress = new ShippingAddress($response['shipping_address'] ?? []);
$this->shippingPhone = new Phone($response['shipping_phone'] ?? []);
}
/**
* @return array<string, mixed>
*/
public function jsonSerialize(): array
{
$js = [];
$billingAddress = $this->billingAddress->jsonSerialize();
if (!empty($billingAddress)) {
$js['billing_address'] = $billingAddress;
}
$billingPhone = $this->billingPhone->jsonSerialize();
if (!empty($billingPhone)) {
$js['billing_phone'] = $billingPhone;
}
$creditCard = $this->creditCard->jsonSerialize();
if (!empty($creditCard)) {
$js['credit_card'] = $creditCard;
}
$device
= $this->device->jsonSerialize();
if (!empty($device)) {
$js['device'] = $device;
}
$disposition = $this->disposition->jsonSerialize();
if (!empty($disposition)) {
$js['disposition'] = $disposition;
}
$email = $this->email->jsonSerialize();
if (!empty($email)) {
$js['email'] = $email;
}
$js['funds_remaining'] = $this->fundsRemaining;
$ipAddress = $this->ipAddress->jsonSerialize();
if (!empty($ipAddress)) {
$js['ip_address'] = $ipAddress;
}
$js['id'] = $this->id;
$js['queries_remaining'] = $this->queriesRemaining;
$js['risk_score'] = $this->riskScore;
$shippingAddress = $this->shippingAddress->jsonSerialize();
if (!empty($shippingAddress)) {
$js['shipping_address'] = $shippingAddress;
}
$shippingPhone = $this->shippingPhone->jsonSerialize();
if (!empty($shippingPhone)) {
$js['shipping_phone'] = $shippingPhone;
}
if (!empty($this->warnings)) {
$warnings = [];
foreach ($this->warnings as $warning) {
$warnings[] = $warning->jsonSerialize();
}
$js['warnings'] = $warnings;
}
return $js;
}
}