Skip to content

Commit 9f6c569

Browse files
authored
Merge pull request #177 from maxmind/greg/phone-data
Add new phone outputs
2 parents 55c4377 + 2a6868e commit 9f6c569

8 files changed

Lines changed: 195 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ CHANGELOG
88
parameter optional. Now the `tag` and at least one of the following
99
parameters must be supplied: `ipAddress`, `maxmindId`, `minfraudId`,
1010
`transactionId`.
11+
* Added `billingPhone` and `shippingPhone` properties to the minFraud Insights
12+
and Factors response models. These contain objects with information about
13+
the respective phone numbers. Please see [our developer
14+
site](https://dev.maxmind.com/minfraud/api-documentation/responses/) for
15+
more information.
1116

1217
3.0.1 (2024-05-02)
1318
------------------

src/MinFraud/Model/Insights.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ class Insights implements \JsonSerializable
1515
*/
1616
public readonly BillingAddress $billingAddress;
1717

18+
/**
19+
* @var Phone an object containing minFraud data related to the billing
20+
* phone used in the transaction
21+
*/
22+
public readonly Phone $billingPhone;
23+
1824
/**
1925
* @var CreditCard an object containing minFraud data about the credit
2026
* card used in the transaction
@@ -81,6 +87,12 @@ class Insights implements \JsonSerializable
8187
*/
8288
public readonly ShippingAddress $shippingAddress;
8389

90+
/**
91+
* @var Phone an object containing minFraud data related to the shipping
92+
* phone used in the transaction
93+
*/
94+
public readonly Phone $shippingPhone;
95+
8496
/**
8597
* @var array This array contains \MaxMind\MinFraud\Model\Warning objects
8698
* detailing issues with the request that was sent, such as
@@ -108,11 +120,13 @@ public function __construct(array $response, array $locales = ['en'])
108120
$this->warnings = $warnings;
109121

110122
$this->billingAddress = new BillingAddress($response['billing_address'] ?? []);
123+
$this->billingPhone = new Phone($response['billing_phone'] ?? []);
111124
$this->creditCard = new CreditCard($response['credit_card'] ?? []);
112125
$this->device = new Device($response['device'] ?? []);
113126
$this->email = new Email($response['email'] ?? []);
114127
$this->ipAddress = new IpAddress($response['ip_address'] ?? [], $locales);
115128
$this->shippingAddress = new ShippingAddress($response['shipping_address'] ?? []);
129+
$this->shippingPhone = new Phone($response['shipping_phone'] ?? []);
116130
}
117131

118132
public function jsonSerialize(): array
@@ -124,6 +138,11 @@ public function jsonSerialize(): array
124138
$js['billing_address'] = $billingAddress;
125139
}
126140

141+
$billingPhone = $this->billingPhone->jsonSerialize();
142+
if (!empty($billingPhone)) {
143+
$js['billing_phone'] = $billingPhone;
144+
}
145+
127146
$creditCard = $this->creditCard->jsonSerialize();
128147
if (!empty($creditCard)) {
129148
$js['credit_card'] = $creditCard;
@@ -163,6 +182,11 @@ public function jsonSerialize(): array
163182
$js['shipping_address'] = $shippingAddress;
164183
}
165184

185+
$shippingPhone = $this->shippingPhone->jsonSerialize();
186+
if (!empty($shippingPhone)) {
187+
$js['shipping_phone'] = $shippingPhone;
188+
}
189+
166190
if (!empty($this->warnings)) {
167191
$warnings = [];
168192
foreach ($this->warnings as $warning) {

src/MinFraud/Model/Phone.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace MaxMind\MinFraud\Model;
6+
7+
/**
8+
* Model containing information about the billing or shipping phone number.
9+
*/
10+
class Phone implements \JsonSerializable
11+
{
12+
/**
13+
* @var string|null the two-character ISO 3166-1 country code for the
14+
* country associated with the phone number
15+
*/
16+
public readonly ?string $country;
17+
18+
/**
19+
* @var bool|null This is `true` if the phone number is a Voice over
20+
* Internet Protocol (VoIP) number allocated by a regulator.
21+
* It is `false` if the phone number is not a VoIP number
22+
* allocated by a regulator. It is `null` if a valid number
23+
* was not provided or if we do not have data for the number.
24+
*/
25+
public readonly ?bool $isVoip;
26+
27+
/**
28+
* @var string|null The name of the original network operator associated with
29+
* the phone number. This property does not reflect phone numbers
30+
* that have been ported from the original operator to another,
31+
* nor does it identify mobile virtual network operators.
32+
*/
33+
public readonly ?string $networkOperator;
34+
35+
/**
36+
* @var string|null One of the following values: `fixed` or `mobile`. Additional
37+
* values may be added in the future.
38+
*/
39+
public readonly ?string $numberType;
40+
41+
public function __construct(?array $response)
42+
{
43+
$this->country = $response['country'] ?? null;
44+
$this->isVoip = $response['is_voip'] ?? null;
45+
$this->networkOperator = $response['network_operator'] ?? null;
46+
$this->numberType = $response['number_type'] ?? null;
47+
}
48+
49+
public function jsonSerialize(): array
50+
{
51+
$js = [];
52+
53+
if ($this->country !== null) {
54+
$js['country'] = $this->country;
55+
}
56+
57+
if ($this->isVoip !== null) {
58+
$js['is_voip'] = $this->isVoip;
59+
}
60+
61+
if ($this->networkOperator !== null) {
62+
$js['network_operator'] = $this->networkOperator;
63+
}
64+
65+
if ($this->numberType !== null) {
66+
$js['number_type'] = $this->numberType;
67+
}
68+
69+
return $js;
70+
}
71+
}

tests/MaxMind/Test/MinFraud/Model/InsightsTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,17 @@ public function testInsightsProperties(): void
123123
$insights->ipAddress->traits->mobileNetworkCode,
124124
'correct mobile network code'
125125
);
126+
127+
$this->assertSame(
128+
$array['billing_phone']['country'],
129+
$insights->billingPhone->country,
130+
'correct billing phone country'
131+
);
132+
133+
$this->assertSame(
134+
$array['shipping_phone']['country'],
135+
$insights->shippingPhone->country,
136+
'correct shipping phone country'
137+
);
126138
}
127139
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace MaxMind\Test\MinFraud\Model;
6+
7+
use MaxMind\MinFraud\Model\Phone;
8+
use PHPUnit\Framework\TestCase;
9+
10+
/**
11+
* @coversNothing
12+
*
13+
* @internal
14+
*/
15+
class PhoneTest extends TestCase
16+
{
17+
public function testPhone(): void
18+
{
19+
$array = [
20+
'country' => 'US',
21+
'is_voip' => true,
22+
'network_operator' => 'Verizon/1',
23+
'number_type' => 'fixed',
24+
];
25+
$phone = new Phone($array);
26+
27+
$this->assertSame(
28+
$array['country'],
29+
$phone->country,
30+
'country'
31+
);
32+
33+
$this->assertSame(
34+
$array['is_voip'],
35+
$phone->isVoip,
36+
'isVoip'
37+
);
38+
39+
$this->assertSame(
40+
$array['network_operator'],
41+
$phone->networkOperator,
42+
'networkOperator'
43+
);
44+
45+
$this->assertSame(
46+
$array['number_type'],
47+
$phone->numberType,
48+
'numberType'
49+
);
50+
51+
$this->assertSame(
52+
$array,
53+
$phone->jsonSerialize(),
54+
'correctly implements JsonSerializable'
55+
);
56+
}
57+
}

tests/MaxMind/Test/MinFraud/ReportTransaction/ReportTransactionTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ public function testRequestsWithNulls(): void
6464

6565
public function testRequiredFields(): void
6666
{
67-
$this->expectNotToPerformAssertions();
68-
6967
$req = [
7068
'ip_address' => '1.1.1.1',
7169
'tag' => 'not_fraud',

tests/data/minfraud/factors-response.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@
120120
"distance_to_ip_location": 5465,
121121
"is_in_ip_country": false
122122
},
123+
"billing_phone": {
124+
"country": "US",
125+
"is_voip": true,
126+
"network_operator": "Verizon/1",
127+
"number_type": "fixed"
128+
},
123129
"credit_card": {
124130
"issuer": {
125131
"name": "Bank of No Hope",
@@ -157,6 +163,12 @@
157163
"latitude": 35.704729,
158164
"longitude": -97.568619
159165
},
166+
"shipping_phone": {
167+
"country": "CA",
168+
"is_voip": true,
169+
"network_operator": "Telus Mobility-SVR/2",
170+
"number_type": "mobile"
171+
},
160172
"subscores": {
161173
"avs_result": 0.01,
162174
"billing_address": 0.02,
@@ -189,4 +201,4 @@
189201
"warning": "Encountered value at /account/username_md5 that does meet the required constraints"
190202
}
191203
]
192-
}
204+
}

tests/data/minfraud/insights-response.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@
120120
"distance_to_ip_location": 5465,
121121
"is_in_ip_country": false
122122
},
123+
"billing_phone": {
124+
"country": "US",
125+
"is_voip": true,
126+
"network_operator": "Verizon/1",
127+
"number_type": "fixed"
128+
},
123129
"credit_card": {
124130
"issuer": {
125131
"name": "Bank of No Hope",
@@ -157,6 +163,12 @@
157163
"latitude": 35.704729,
158164
"longitude": -97.568619
159165
},
166+
"shipping_phone": {
167+
"country": "CA",
168+
"is_voip": true,
169+
"network_operator": "Telus Mobility-SVR/2",
170+
"number_type": "mobile"
171+
},
160172
"warnings": [
161173
{
162174
"code": "INPUT_INVALID",
@@ -169,4 +181,4 @@
169181
"warning": "Encountered value at /account/username_md5 that does meet the required constraints"
170182
}
171183
]
172-
}
184+
}

0 commit comments

Comments
 (0)