Skip to content

Commit 63912b2

Browse files
committed
Merge pull request #4 from maxmind/dave/new-minfraud-outputs
Updates for the upcoming new Insights outputs
2 parents d99880b + 93462b6 commit 63912b2

15 files changed

Lines changed: 255 additions & 56 deletions

File tree

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
CHANGELOG
22
=========
33

4+
0.3.0 ()
5+
6+
* Added support for new minFraud Insights outputs. These are:
7+
* `/credit_card/brand`
8+
* `/credit_card/type`
9+
* `/device/id`
10+
* `/email/is_free`
11+
* `/emai/is_high_risk`
12+
* The `Warning.getInput` getter has been replaced by
13+
`Warning.getInputPointer`, which returns a JSON Pointer rather than array.
14+
* The `ScoreResponse.getId` and `InsightsResponse.getId` getters now return
15+
`UUID` objects instead of strings.
16+
417
0.2.0 (2016-01-15)
518
------------------
619

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

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,38 @@
11
package com.maxmind.minfraud.response;
22

3-
import com.fasterxml.jackson.annotation.JsonIgnore;
3+
import com.fasterxml.jackson.annotation.JsonCreator;
44
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import com.fasterxml.jackson.annotation.JsonValue;
56

67
/**
78
* This class contains minFraud response data related to the credit card.
89
*/
910
public final class CreditCard {
1011
private final Issuer issuer;
12+
private final String brand;
1113
private final String country;
1214
private final Boolean isIssuedInBillingAddressCountry;
1315
private final Boolean isPrepaid;
16+
private final String type;
1417

1518
public CreditCard(
19+
@JsonProperty("brand") String brand,
1620
@JsonProperty("country") String country,
1721
@JsonProperty("is_issued_in_billing_address_country") Boolean isIssuedInBillingAddressCountry,
1822
@JsonProperty("is_prepaid") Boolean isPrepaid,
19-
@JsonProperty("issuer") Issuer issuer
23+
@JsonProperty("issuer") Issuer issuer,
24+
@JsonProperty("type") String type
2025
) {
26+
this.brand = brand;
2127
this.country = country;
2228
this.isIssuedInBillingAddressCountry = isIssuedInBillingAddressCountry;
2329
this.isPrepaid = isPrepaid;
2430
this.issuer = issuer == null ? new Issuer() : issuer;
31+
this.type = type;
2532
}
2633

2734
public CreditCard() {
28-
this(null, null, null, null);
35+
this(null, null, null, null, null, null);
2936
}
3037

3138
/**
@@ -35,6 +42,13 @@ public Issuer getIssuer() {
3542
return issuer;
3643
}
3744

45+
/**
46+
* @return The credit card brand.
47+
*/
48+
public String getBrand() {
49+
return brand;
50+
}
51+
3852
/**
3953
* @return The two letter <a href="http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2">
4054
* ISO 3166-1 alpha-2</a> country code associated with the location
@@ -67,13 +81,22 @@ public Boolean isPrepaid() {
6781
return isPrepaid;
6882
}
6983

84+
/**
85+
* @return The credit card type.
86+
*/
87+
public String getType() {
88+
return type;
89+
}
90+
7091
@Override
7192
public String toString() {
7293
StringBuilder sb = new StringBuilder("CreditCard{");
7394
sb.append("issuer=").append(this.issuer);
95+
sb.append(", brand='").append(this.brand).append('\'');
7496
sb.append(", country='").append(this.country).append('\'');
7597
sb.append(", isIssuedInBillingAddressCountry=").append(this.isIssuedInBillingAddressCountry);
7698
sb.append(", isPrepaid=").append(this.isPrepaid);
99+
sb.append(", type='").append(this.type).append('\'');
77100
sb.append('}');
78101
return sb.toString();
79102
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.maxmind.minfraud.response;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
import java.util.UUID;
6+
7+
/**
8+
* This class contains minFraud response data related to the device.
9+
*/
10+
public final class Device {
11+
private final UUID id;
12+
13+
public Device(
14+
@JsonProperty("id") UUID id
15+
) {
16+
this.id = id;
17+
}
18+
19+
public Device() {
20+
this(null);
21+
}
22+
23+
/**
24+
* @return The device id.
25+
*/
26+
public UUID getId() {
27+
return id;
28+
}
29+
30+
@Override
31+
public String toString() {
32+
StringBuilder sb = new StringBuilder("Device{");
33+
sb.append("id=").append(this.id);
34+
sb.append('}');
35+
return sb.toString();
36+
}
37+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.maxmind.minfraud.response;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
/**
6+
* This class contains minFraud response data related to the email address.
7+
*/
8+
public final class Email {
9+
private final Boolean isFree;
10+
private final Boolean isHighRisk;
11+
12+
public Email(
13+
@JsonProperty("is_free") Boolean isFree,
14+
@JsonProperty("is_high_risk") Boolean isHighRisk
15+
) {
16+
this.isFree = isFree;
17+
this.isHighRisk = isHighRisk;
18+
}
19+
20+
public Email() {
21+
this(null, null);
22+
}
23+
24+
/**
25+
* @return True if the email address is for a free email service provider.
26+
*/
27+
@JsonProperty("is_free")
28+
public Boolean isFree() {
29+
return isFree;
30+
}
31+
32+
/**
33+
* @return True if the email address is associated with fraud.
34+
*/
35+
@JsonProperty("is_high_risk")
36+
public Boolean isHighRisk() {
37+
return isHighRisk;
38+
}
39+
40+
@Override
41+
public String toString() {
42+
StringBuilder sb = new StringBuilder("Email{");
43+
sb.append("is_free=").append(this.isFree);
44+
sb.append(", is_high_risk=").append(this.isHighRisk);
45+
sb.append('}');
46+
return sb.toString();
47+
}
48+
}

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,26 @@
33
import com.fasterxml.jackson.annotation.JsonProperty;
44

55
import java.util.List;
6+
import java.util.UUID;
67

78
/**
89
* This class provides a model for the minFraud Insights response.
910
*/
1011
public final class InsightsResponse extends ScoreResponse {
1112
private final IpAddress ipAddress;
1213
private final CreditCard creditCard;
14+
private final Device device;
15+
private final Email email;
1316
private final ShippingAddress shippingAddress;
1417
private final BillingAddress billingAddress;
1518

1619
public InsightsResponse(
1720
@JsonProperty("billing_address") BillingAddress billingAddress,
1821
@JsonProperty("credit_card") CreditCard creditCard,
22+
@JsonProperty("device") Device device,
23+
@JsonProperty("email") Email email,
1924
@JsonProperty("credits_remaining") Integer creditsRemaining,
20-
@JsonProperty("id") String id,
25+
@JsonProperty("id") UUID id,
2126
@JsonProperty("ip_address") IpAddress ipAddress,
2227
@JsonProperty("risk_score") Double riskScore,
2328
@JsonProperty("shipping_address") ShippingAddress shippingAddress,
@@ -27,6 +32,8 @@ public InsightsResponse(
2732
super(creditsRemaining, id, riskScore, warnings);
2833
this.billingAddress = billingAddress == null ? new BillingAddress() : billingAddress;
2934
this.creditCard = creditCard == null ? new CreditCard() : creditCard;
35+
this.device = device == null ? new Device() : device;
36+
this.email = email == null ? new Email() : email;
3037
this.ipAddress = ipAddress == null ? new IpAddress() : ipAddress;
3138
this.shippingAddress = shippingAddress == null ? new ShippingAddress() : shippingAddress;
3239
}
@@ -47,6 +54,20 @@ public CreditCard getCreditCard() {
4754
return creditCard;
4855
}
4956

57+
/**
58+
* @return The {@code Device} model object.
59+
*/
60+
public Device getDevice() {
61+
return device;
62+
}
63+
64+
/**
65+
* @return The {@code Email} model object.
66+
*/
67+
public Email getEmail() {
68+
return email;
69+
}
70+
5071
/**
5172
* @return The {@code ShippingAddress} model object.
5273
*/
@@ -72,6 +93,8 @@ public String toString() {
7293
sb.append(", warnings=").append(this.warnings);
7394
sb.append(", ipAddress=").append(this.ipAddress);
7495
sb.append(", creditCard=").append(this.creditCard);
96+
sb.append(", device=").append(this.device);
97+
sb.append(", email=").append(this.email);
7598
sb.append(", shippingAddress=").append(this.shippingAddress);
7699
sb.append(", billingAddress=").append(this.billingAddress);
77100
sb.append('}');

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,20 @@
99
import java.util.ArrayList;
1010
import java.util.Collections;
1111
import java.util.List;
12+
import java.util.UUID;
1213

1314
/**
1415
* This class represents the minFraud Score response.
1516
*/
1617
public class ScoreResponse {
1718
protected final Integer creditsRemaining;
18-
protected final String id;
19+
protected final UUID id;
1920
protected final Double riskScore;
2021
protected final List<Warning> warnings;
2122

2223
public ScoreResponse(
2324
@JsonProperty("credits_remaining") Integer creditsRemaining,
24-
@JsonProperty("id") String id,
25+
@JsonProperty("id") UUID id,
2526
@JsonProperty("risk_score") Double riskScore,
2627
@JsonProperty("warnings") List<Warning> warnings
2728
) {
@@ -43,7 +44,7 @@ public final Integer getCreditsRemaining() {
4344
/**
4445
* @return This is a UUID that identifies the minFraud request.
4546
*/
46-
public final String getId() {
47+
public final UUID getId() {
4748
return id;
4849
}
4950

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
public final class Warning {
1414
private final String code;
1515
private final String warning;
16-
private final List<String> input;
16+
private final String inputPointer;
1717

1818
public Warning(
1919
@JsonProperty("code") String code,
20-
@JsonProperty("input") List<String> input,
21-
@JsonProperty("warning") String warning
20+
@JsonProperty("warning") String warning,
21+
@JsonProperty("input_pointer") String inputPointer
2222
) {
2323
this.code = code;
24-
this.input = Collections.unmodifiableList(input == null ? new ArrayList<String>() : input);
2524
this.warning = warning;
25+
this.inputPointer = inputPointer;
2626
}
2727

2828
/**
@@ -66,21 +66,22 @@ public String getWarning() {
6666
}
6767

6868
/**
69-
* @return This is a list of keys representing the path to the input that
70-
* the warning is associated with. For instance, if the warning was about
71-
* the billing city, the list would contain "billing" followed by "city".
72-
* The key is used for object and the index number for an array.
69+
* @return This is a JSON Pointer to the input that the warning is
70+
* associated with. For instance, if the warning was about the billing
71+
* city, the value would be "/billing/city". See
72+
* https://tools.ietf.org/html/rfc6901 for the JSON Pointer spec.
7373
*/
74-
public List<String> getInput() {
75-
return new ArrayList<>(this.input);
74+
@JsonProperty("input_pointer")
75+
public String getInputPointer() {
76+
return this.inputPointer;
7677
}
7778

7879
@Override
7980
public String toString() {
8081
final StringBuilder sb = new StringBuilder("Warning{");
8182
sb.append("code='").append(code).append('\'');
8283
sb.append(", warning='").append(warning).append('\'');
83-
sb.append(", input=").append(input);
84+
sb.append(", inputPointer=").append(inputPointer);
8485
sb.append('}');
8586
return sb.toString();
8687
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,21 @@ public void testCreditCard() throws Exception {
1818
.startObjectField("issuer")
1919
.put("name", "Bank")
2020
.end()
21+
.put("brand", "Visa")
2122
.put("country", "US")
2223
.put("is_issued_in_billing_address_country", true)
2324
.put("is_prepaid", true)
25+
.put("type", "credit")
2426
.end()
2527
.finish()
2628
);
2729

2830
assertEquals("Bank", cc.getIssuer().getName());
2931
assertEquals("US", cc.getCountry());
32+
assertEquals("Visa", cc.getBrand());
33+
assertEquals("credit", cc.getType());
3034
assertTrue(cc.isPrepaid());
3135
assertTrue(cc.isIssuedInBillingAddressCountry());
3236
}
33-
}
37+
38+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.maxmind.minfraud.response;
2+
3+
import com.fasterxml.jackson.jr.ob.JSON;
4+
import org.junit.Test;
5+
6+
import java.util.UUID;
7+
8+
import static org.junit.Assert.assertEquals;
9+
10+
public class DeviceTest extends AbstractOutputTest {
11+
12+
@Test
13+
public void testDevice() throws Exception {
14+
Device device = this.deserialize(
15+
Device.class,
16+
JSON.std
17+
.composeString()
18+
.startObject()
19+
.put("id", "C8D3BE1A-BE26-11E5-8C50-1B575C37265F")
20+
.end()
21+
.finish()
22+
);
23+
24+
assertEquals(UUID.fromString("C8D3BE1A-BE26-11E5-8C50-1B575C37265F"), device.getId());
25+
}
26+
}

0 commit comments

Comments
 (0)