Skip to content

Commit 4b748b4

Browse files
authored
Merge pull request #552 from maxmind/greg/eng-3230
Modernize API in preparation for major release
2 parents 98e3ad4 + 9b50369 commit 4b748b4

78 files changed

Lines changed: 2053 additions & 1354 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,50 @@ CHANGELOG
77
* BREAKING: Removed deprecated `TransactionReport.Builder(InetAddress, Tag)`
88
constructor. Use `Builder(Tag)` and `ipAddress(InetAddress)` instead.
99
* BREAKING: Removed deprecated `getUrl()` methods from `HttpException` and
10-
`InvalidRequestException`. Use `getUri()` instead.
10+
`InvalidRequestException`. Use `uri()` instead.
1111
* BREAKING: Removed deprecated constructors from `FactorsResponse`,
1212
`InsightsResponse`, and `Phone` classes.
1313
* BREAKING: Removed deprecated `Subscores` class and
1414
`FactorsResponse.getSubscores()` method. Use `getRiskScoreReasons()`
1515
instead.
1616
* BREAKING: Java 17 is now required (previously Java 11).
17+
* BREAKING: Updated `geoip2` dependency to 5.0.0-SNAPSHOT. This introduces
18+
several breaking changes due to changes in the geoip2 library:
19+
* The `IpAddress` class no longer extends `InsightsResponse` from geoip2.
20+
It now uses composition instead. All public methods remain the same, but
21+
code relying on `IpAddress` being an `InsightsResponse` will need to be
22+
updated.
23+
* The `GeoIp2Location` class no longer extends `Location` from geoip2. It
24+
now stores location data directly. All public methods remain the same, but
25+
code relying on `GeoIp2Location` being a `Location` will need to be
26+
updated.
27+
* Removed the `getMaxMind()` method from the `IpAddress` class as this data
28+
is not populated in minFraud responses.
29+
* BREAKING: Converted all response classes to Java records. This change makes
30+
these classes more concise and provides better immutability guarantees.
31+
* All `get*()` accessor methods in response classes are now deprecated and
32+
will be removed in 5.0.0. Use the automatically generated record accessor
33+
methods instead (e.g., use `riskScore()` instead of `getRiskScore()`).
34+
* The response class hierarchy has been flattened. `InsightsResponse` no
35+
longer extends `ScoreResponse`, and `FactorsResponse` no longer extends
36+
`InsightsResponse`. Instead, `InsightsResponse` and `FactorsResponse` now
37+
include all fields from their former parent classes directly.
38+
* All response classes now implement `JsonSerializable` instead of extending
39+
`AbstractModel`. The `toJson()` method remains available for serialization.
40+
* Removed the `AbstractAddress` interface.
41+
* BREAKING: Updated all request classes to use record-style method naming. The
42+
`get` prefix has been removed from all accessor methods (e.g., use `userId()`
43+
instead of `getUserId()`). This applies to all request classes including
44+
`Account`, `Billing`, `CreditCard`, `CustomInputs`, `Device`, `Email`,
45+
`Event`, `Order`, `Payment`, `Shipping`, `ShoppingCartItem`, `Transaction`,
46+
and `TransactionReport`. Unlike response classes, no deprecated helper methods
47+
were added as these methods are primarily used for serialization.
48+
* BREAKING: Updated exception classes to use record-style method naming. The
49+
`get` prefix has been removed from all accessor methods. For `HttpException`,
50+
use `httpStatus()` and `uri()` instead of `getHttpStatus()` and `getUri()`.
51+
For `InvalidRequestException`, use `code()`, `httpStatus()`, and `uri()`
52+
instead of `getCode()`, `getHttpStatus()`, and `getUri()`. No deprecated
53+
helper methods were added.
1754
* Added `CREDIT_APPLICATION` and `FUND_TRANSFER` to the `Event.Type` enum.
1855
* Added the input `/event/party`. This is the party submitting the
1956
transaction. You may provide this using the `party` method on

pom.xml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@
3636
<email>goschwald@maxmind.com</email>
3737
</developer>
3838
</developers>
39+
<repositories>
40+
<repository>
41+
<name>Central Portal Snapshots</name>
42+
<id>central-portal-snapshots</id>
43+
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
44+
<releases>
45+
<enabled>false</enabled>
46+
</releases>
47+
<snapshots>
48+
<enabled>true</enabled>
49+
</snapshots>
50+
</repository>
51+
</repositories>
3952
<dependencies>
4053
<dependency>
4154
<groupId>com.fasterxml.jackson.core</groupId>
@@ -60,7 +73,7 @@
6073
<dependency>
6174
<groupId>com.maxmind.geoip2</groupId>
6275
<artifactId>geoip2</artifactId>
63-
<version>4.4.0</version>
76+
<version>5.0.0-SNAPSHOT</version>
6477
</dependency>
6578
<dependency>
6679
<groupId>org.junit.jupiter</groupId>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.maxmind.minfraud;
2+
3+
import java.io.IOException;
4+
5+
/**
6+
* Interface for classes that can be serialized to JSON.
7+
* Provides default implementation for toJson() method.
8+
*/
9+
public interface JsonSerializable {
10+
11+
/**
12+
* @return JSON representation of this object.
13+
* @throws IOException if there is an error serializing the object to JSON.
14+
*/
15+
default String toJson() throws IOException {
16+
return Mapper.get().writeValueAsString(this);
17+
}
18+
}

src/main/java/com/maxmind/minfraud/WebServiceClient.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public static final class Builder {
103103
Duration connectTimeout;
104104
Duration requestTimeout;
105105

106-
List<String> locales = Collections.singletonList("en");
106+
List<String> locales = List.of("en");
107107
private ProxySelector proxy;
108108
private HttpClient httpClient;
109109

@@ -306,8 +306,8 @@ public void reportTransaction(TransactionReport transaction) throws IOException,
306306
if (transaction == null) {
307307
throw new IllegalArgumentException("transaction report must not be null");
308308
}
309-
URI uri = createUri(WebServiceClient.pathBase + "transactions/report");
310-
HttpRequest request = requestFor(transaction, uri);
309+
var uri = createUri(WebServiceClient.pathBase + "transactions/report");
310+
var request = requestFor(transaction, uri);
311311

312312
HttpResponse<InputStream> response = null;
313313
try {
@@ -328,8 +328,8 @@ private <T> T responseFor(String service, AbstractModel transaction, Class<T> cl
328328
if (transaction == null) {
329329
throw new IllegalArgumentException("transaction must not be null");
330330
}
331-
URI uri = createUri(WebServiceClient.pathBase + service);
332-
HttpRequest request = requestFor(transaction, uri);
331+
var uri = createUri(WebServiceClient.pathBase + service);
332+
var request = requestFor(transaction, uri);
333333

334334
HttpResponse<InputStream> response = null;
335335
try {
@@ -346,7 +346,7 @@ private <T> T responseFor(String service, AbstractModel transaction, Class<T> cl
346346

347347
private HttpRequest requestFor(AbstractModel transaction, URI uri)
348348
throws MinFraudException, IOException {
349-
HttpRequest.Builder builder = HttpRequest.newBuilder()
349+
var builder = HttpRequest.newBuilder()
350350
.uri(uri)
351351
.header("Accept", "application/json")
352352
.header("Authorization", authHeader)
@@ -365,7 +365,7 @@ private HttpRequest requestFor(AbstractModel transaction, URI uri)
365365

366366
private void maybeThrowException(HttpResponse<InputStream> response, URI uri)
367367
throws IOException, MinFraudException {
368-
int status = response.statusCode();
368+
var status = response.statusCode();
369369
if (status >= 400 && status < 500) {
370370
this.handle4xxStatus(response, uri);
371371
} else if (status >= 500 && status < 600) {
@@ -383,7 +383,7 @@ private <T> T handleResponse(HttpResponse<InputStream> response, URI uri, Class<
383383
throws MinFraudException, IOException {
384384
maybeThrowException(response, uri);
385385

386-
InjectableValues inject = new Std().addValue(
386+
var inject = new Std().addValue(
387387
"locales", locales);
388388

389389
try (InputStream stream = response.body()) {
@@ -398,7 +398,7 @@ private void handle4xxStatus(HttpResponse<InputStream> response, URI uri)
398398
throws IOException, InsufficientFundsException,
399399
InvalidRequestException, AuthenticationException,
400400
PermissionRequiredException {
401-
int status = response.statusCode();
401+
var status = response.statusCode();
402402

403403
String body;
404404
try (InputStream stream = response.body()) {
@@ -425,8 +425,8 @@ private void handleErrorWithJsonBody(Map<String, String> content,
425425
throws HttpException, InsufficientFundsException,
426426
InvalidRequestException, AuthenticationException,
427427
PermissionRequiredException {
428-
String error = content.get("error");
429-
String code = content.get("code");
428+
var error = content.get("error");
429+
var code = content.get("code");
430430

431431
if (error == null || code == null) {
432432
throw new HttpException(

src/main/java/com/maxmind/minfraud/exception/HttpException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ public HttpException(String message, int httpStatus, URI uri,
3838
/**
3939
* @return the HTTP status of the query that caused the exception.
4040
*/
41-
public int getHttpStatus() {
41+
public int httpStatus() {
4242
return httpStatus;
4343
}
4444

4545
/**
4646
* @return the URI queried.
4747
*/
48-
public URI getUri() {
48+
public URI uri() {
4949
return this.uri;
5050
}
5151

src/main/java/com/maxmind/minfraud/exception/InvalidRequestException.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,22 @@ public InvalidRequestException(String message, String code, int httpStatus,
4242
/**
4343
* @return The error code returned by the MaxMind web service.
4444
*/
45-
public final String getCode() {
45+
public final String code() {
4646
return code;
4747
}
4848

4949
/**
5050
* @return The integer HTTP status returned by the MaxMind web service. Will be 0 if it was not
5151
* set at throw time.
5252
*/
53-
public final int getHttpStatus() {
53+
public final int httpStatus() {
5454
return httpStatus;
5555
}
5656

5757
/**
5858
* @return the URI queried.
5959
*/
60-
public URI getUri() {
60+
public URI uri() {
6161
return this.uri;
6262
}
6363

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
/**
88
* This class represents the shared location behavior between Billing and Shipping.
99
*/
10-
public abstract class AbstractLocation extends AbstractModel {
10+
public abstract sealed class AbstractLocation extends AbstractModel
11+
permits Billing, Shipping {
1112
private final String firstName;
1213
private final String lastName;
1314
private final String company;
@@ -168,23 +169,23 @@ public final T phoneNumber(String number) {
168169
* @return The first name associated with the address
169170
*/
170171
@JsonProperty("first_name")
171-
public final String getFirstName() {
172+
public final String firstName() {
172173
return firstName;
173174
}
174175

175176
/**
176177
* @return The last name associated with the address
177178
*/
178179
@JsonProperty("last_name")
179-
public final String getLastName() {
180+
public final String lastName() {
180181
return lastName;
181182
}
182183

183184
/**
184185
* @return The company name associated with the address
185186
*/
186187
@JsonProperty("company")
187-
public final String getCompany() {
188+
public final String company() {
188189
return company;
189190
}
190191

@@ -193,7 +194,7 @@ public final String getCompany() {
193194
* @return The first line of the address
194195
*/
195196
@JsonProperty("address")
196-
public final String getAddress() {
197+
public final String address() {
197198
return address;
198199
}
199200

@@ -202,7 +203,7 @@ public final String getAddress() {
202203
* @return The second line of the address
203204
*/
204205
@JsonProperty("address_2")
205-
public final String getAddress2() {
206+
public final String address2() {
206207
return address2;
207208
}
208209

@@ -211,7 +212,7 @@ public final String getAddress2() {
211212
* @return The city associated with the address
212213
*/
213214
@JsonProperty("city")
214-
public final String getCity() {
215+
public final String city() {
215216
return city;
216217
}
217218

@@ -220,7 +221,7 @@ public final String getCity() {
220221
* @return The region code associated with the address
221222
*/
222223
@JsonProperty("region")
223-
public final String getRegion() {
224+
public final String region() {
224225
return region;
225226
}
226227

@@ -229,31 +230,31 @@ public final String getRegion() {
229230
* @return The country associated with the address
230231
*/
231232
@JsonProperty("country")
232-
public final String getCountry() {
233+
public final String country() {
233234
return country;
234235
}
235236

236237
/**
237238
* @return The postal code associated with the address
238239
*/
239240
@JsonProperty("postal")
240-
public final String getPostal() {
241+
public final String postal() {
241242
return postal;
242243
}
243244

244245
/**
245246
* @return The phone number associated with the address
246247
*/
247248
@JsonProperty("phone_number")
248-
public final String getPhoneNumber() {
249+
public final String phoneNumber() {
249250
return phoneNumber;
250251
}
251252

252253
/**
253254
* @return The phone number country code associated with the address
254255
*/
255256
@JsonProperty("phone_country_code")
256-
public final String getPhoneCountryCode() {
257+
public final String phoneCountryCode() {
257258
return phoneCountryCode;
258259
}
259260
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ public Account build() {
7070
* @return The user ID.
7171
*/
7272
@JsonProperty("user_id")
73-
public String getUserId() {
73+
public String userId() {
7474
return userId;
7575
}
7676

7777
/**
7878
* @return The MD5 of the username passed to the builder.
7979
*/
8080
@JsonProperty("username_md5")
81-
public String getUsernameMd5() {
81+
public String usernameMd5() {
8282
return usernameMd5;
8383
}
8484
}

0 commit comments

Comments
 (0)