Skip to content

Commit ba17c27

Browse files
committed
Add IP risk field
1 parent ea25fbb commit ba17c27

12 files changed

Lines changed: 42 additions & 29 deletions

File tree

src/main/java/com/maxmind/minfraud/request/Billing.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* The billing information for the transaction.
55
*/
6-
public class Billing extends AbstractLocation {
6+
public final class Billing extends AbstractLocation {
77
private Billing(Billing.Builder builder) {
88
super(builder);
99
}

src/main/java/com/maxmind/minfraud/request/Device.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/**
88
* The device information for the transaction.
99
*/
10-
public class Device {
10+
public final class Device {
1111
@JsonProperty("ip_address")
1212
private final InetAddress ipAddress;
1313

src/main/java/com/maxmind/minfraud/request/Event.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import java.util.Date;
99
import java.util.TimeZone;
1010

11-
public class Event {
11+
public final class Event {
1212

1313
@JsonProperty("transaction_id")
1414
private final String transactionId;
@@ -119,7 +119,7 @@ public final String getShopId() {
119119
*/
120120
@JsonIgnore
121121
public final Date getTime() throws ParseException {
122-
return time == null ? null : this.dateFormat.parse(time);
122+
return (time == null) ? null : this.dateFormat.parse(time);
123123
}
124124

125125
/**

src/main/java/com/maxmind/minfraud/request/Payment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/**
66
* The payment information for the transaction.
77
*/
8-
public class Payment {
8+
public final class Payment {
99
@JsonProperty("processor")
1010
private final Processor processor;
1111
@JsonProperty("was_authorized")

src/main/java/com/maxmind/minfraud/request/ShoppingCartItem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/**
88
* An item in the shopping cart.
99
*/
10-
public class ShoppingCartItem {
10+
public final class ShoppingCartItem {
1111
@JsonProperty
1212
private final String category;
1313

src/main/java/com/maxmind/minfraud/request/Transaction.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public final class Transaction {
4343
@JsonProperty("shopping_cart")
4444
private final List<ShoppingCartItem> shoppingCart;
4545

46-
@SuppressWarnings("unchecked")
4746
protected Transaction(Transaction.Builder builder) {
4847
account = builder.account;
4948
billing = builder.billing;
@@ -61,7 +60,6 @@ protected Transaction(Transaction.Builder builder) {
6160
* {@code Builder} creates instances of the parent class from values set
6261
* by the builder's methods.
6362
*/
64-
@SuppressWarnings("unchecked")
6563
public static class Builder {
6664
Account account;
6765
Billing billing;

src/main/java/com/maxmind/minfraud/response/InsightsResponse.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* This class provides a model for the minFraud Insights response.
77
*/
88
public final class InsightsResponse extends ScoreResponse {
9-
@JsonProperty("ip_location")
10-
protected IpLocation ipLocation;
9+
@JsonProperty("ip_address")
10+
protected IpAddress ipAddress;
1111

1212
@JsonProperty("credit_card")
1313
protected CreditCard creditCard = new CreditCard();
@@ -19,10 +19,10 @@ public final class InsightsResponse extends ScoreResponse {
1919
protected BillingAddress billingAddress = new BillingAddress();
2020

2121
/**
22-
* @return The {@code IpLocation} model object.
22+
* @return The {@code IpAddress} model object.
2323
*/
24-
public final IpLocation getIpLocation() {
25-
return ipLocation;
24+
public final IpAddress getIpAddress() {
25+
return ipAddress;
2626
}
2727

2828
/**
@@ -53,7 +53,7 @@ public String toString() {
5353
sb.append(", id='").append(this.id).append('\'');
5454
sb.append(", riskScore=").append(this.riskScore);
5555
sb.append(", warnings=").append(this.warnings);
56-
sb.append(", ipLocation=").append(this.ipLocation);
56+
sb.append(", ipAddress=").append(this.ipAddress);
5757
sb.append(", creditCard=").append(this.creditCard);
5858
sb.append(", shippingAddress=").append(this.shippingAddress);
5959
sb.append(", billingAddress=").append(this.billingAddress);

src/main/java/com/maxmind/minfraud/response/IpLocation.java renamed to src/main/java/com/maxmind/minfraud/response/IpAddress.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
/**
77
* This class contains minFraud response data related to the IP location
88
*/
9-
public final class IpLocation extends InsightsResponse {
9+
public final class IpAddress extends InsightsResponse {
1010
@JsonProperty("country")
1111
private final GeoIp2Country country = new GeoIp2Country();
1212
@JsonProperty("location")
1313
private final GeoIp2Location location = new GeoIp2Location();
14+
@JsonProperty("risk")
15+
protected Double risk;
1416

1517
/**
1618
* @return Country record for the requested IP address. This object
@@ -28,10 +30,21 @@ public final GeoIp2Location getLocation() {
2830
return location;
2931
}
3032

33+
34+
/**
35+
* @return The risk associated with the IP address. The value ranges from
36+
* 0.01 to 99. A higher score indicates a higher risk.
37+
*/
38+
public Double getRisk() {
39+
return risk;
40+
}
41+
42+
3143
@Override
3244
public String toString() {
33-
StringBuilder sb = new StringBuilder("IpLocation{");
34-
sb.append("country=").append(this.country);
45+
StringBuilder sb = new StringBuilder("IpAddress{");
46+
sb.append("risk=").append(this.risk);
47+
sb.append(", country=").append(this.country);
3548
sb.append(", location=").append(this.location);
3649
sb.append(", super:").append(super.toString());
3750
sb.append('}');

src/test/java/com/maxmind/minfraud/response/InsightsResponseTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public void testInsights() throws Exception {
1616
JSON.std
1717
.composeString()
1818
.startObject()
19-
.startObjectField("ip_location")
19+
.startObjectField("ip_address")
2020
.startObjectField("country")
2121
.put("iso_code", "US")
2222
.end()
@@ -42,7 +42,7 @@ public void testInsights() throws Exception {
4242
.finish()
4343
);
4444

45-
assertEquals("correct country ISO", "US", insights.getIpLocation().getCountry().getIsoCode());
45+
assertEquals("correct country ISO", "US", insights.getIpAddress().getCountry().getIsoCode());
4646
assertTrue("correct credit card prepaid", insights.getCreditCard().isPrepaid());
4747
assertTrue("correct shipping address is in IP country", insights.getShippingAddress().isInIpCountry());
4848
assertTrue("correct billing address is in IP country", insights.getBillingAddress().isInIpCountry());

src/test/java/com/maxmind/minfraud/response/IpLocationTest.java renamed to src/test/java/com/maxmind/minfraud/response/IpAddressTest.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@
66
import static org.junit.Assert.assertEquals;
77
import static org.junit.Assert.assertTrue;
88

9-
public class IpLocationTest extends AbstractOutputTest {
9+
public class IpAddressTest extends AbstractOutputTest {
1010

1111
@Test
12-
public void testIpLocation() throws Exception {
12+
public void testIpAddress() throws Exception {
1313
String time = "2015-04-19T12:59:23-01:00";
1414

15-
IpLocation loc = this.deserialize(
16-
IpLocation.class,
15+
IpAddress address = this.deserialize(
16+
IpAddress.class,
1717
JSON.std
1818
.composeString()
1919
.startObject()
20+
.put("risk", 99)
2021
.startObjectField("country")
2122
.put("is_high_risk", true)
2223
.end()
@@ -27,8 +28,8 @@ public void testIpLocation() throws Exception {
2728
.finish()
2829
);
2930

30-
assertEquals("correct local time", time, loc.getLocation().getLocalTime());
31-
assertTrue("isHighRisk", loc.getCountry().isHighRisk());
31+
assertEquals("IP risk", new Double(99), address.getRisk());
32+
assertEquals("correct local time", time, address.getLocation().getLocalTime());
33+
assertTrue("isHighRisk", address.getCountry().isHighRisk());
3234
}
33-
3435
}

0 commit comments

Comments
 (0)