Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Riskified JAVA SDK
=================

version: 5.0.1
version: 5.0.2
------------------

See http://apiref.riskified.com for full API documentation
Expand Down Expand Up @@ -104,7 +104,7 @@ curl -H "Content-Type: application/json" -H "X-RISKIFIED-HMAC-SHA256: 071ef80d5
<dependency>
<groupId>com.riskified</groupId>
<artifactId>riskified-sdk</artifactId>
<version>5.0.1</version>
<version>5.0.2</version>
</dependency>
```

2 changes: 1 addition & 1 deletion riskified-sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<dependency>
<groupId>com.riskified</groupId>
<artifactId>riskified-sdk</artifactId>
<version>5.0.1</version>
<version>5.0.2</version>
</dependency>

<dependency>
Expand Down
2 changes: 1 addition & 1 deletion riskified-sdk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.riskified</groupId>
<artifactId>riskified-sdk</artifactId>
<version>5.0.1</version>
<version>5.0.2</version>
<name>Riskified SDK</name>
<description>Riskified rest api SDK for java</description>
<url>https://www.riskified.com</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ private HttpPost createPostRequest(String url) {
postRequest.setHeader(HttpHeaders.ACCEPT, "application/vnd.riskified.com; version=2");
postRequest.setHeader(HttpHeaders.ACCEPT, "application/json");
postRequest.setHeader("X-RISKIFIED-SHOP-DOMAIN", shopUrl);
postRequest.setHeader("User-Agent","riskified_java_sdk/5.0.1"); // TODO: take the version automatically
postRequest.setHeader("User-Agent","riskified_java_sdk/5.0.2"); // TODO: take the version automatically
postRequest.setHeader("Version",versionHeaderValue);
return postRequest;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import org.apache.http.conn.util.InetAddressUtils;

import java.util.Locale;
import java.util.Arrays;

public class Validate {
public static void notNull(Object source, Object obj, String fieldName) throws FieldBadFormatException {
if (obj == null) {
Expand Down Expand Up @@ -34,13 +37,13 @@ public static void currencyCode(Object source, String currency, String fieldName
}

public static void countryCode(Object source, String countryCode, String fieldName) throws FieldBadFormatException {
if (countryCode == null || countryCode.length() != 2 || !countryCode.matches("[A-Z]+")) {
throw new FieldBadFormatException(source, "in " + fieldName + " field, value of " + countryCode + " is not a valid country code (should be 2 capital letters).");
if (countryCode == null || !Arrays.asList(Locale.getISOCountries()).contains(countryCode)) {
throw new FieldBadFormatException(source, "in " + fieldName + " field, value of " + countryCode + " is not a valid country code.");
}
}

public static void provinceCode(Object source, String provinceCode, String fieldName) throws FieldBadFormatException {
if (provinceCode == null || provinceCode.length() < 2 || provinceCode.length() > 3 || !provinceCode.matches("[A-Z]+")) {
if (provinceCode == null || !provinceCode.matches("^[A-Z0-9]{1,3}")) {
throw new FieldBadFormatException(source, "in " + fieldName + " field, value of " + provinceCode + " is not a valid province code (should be 2 or 3 capital letters).");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,21 @@ public void testCountryCode() {
try {
Validate.countryCode(this, "US", fieldName);
} catch (FieldBadFormatException e) {
caughtException = true;
caughtException = false;
}
assertFalse("Should not have caught any exception as 'US' is a valid code.", caughtException);

caughtException = false;

try {
Validate.countryCode(this, "USA", fieldName);
} catch (FieldBadFormatException ignore) {
caughtException = true;
}
assertTrue("Should have caught any exception as 'USA' is not a valid country code.", caughtException);
}

@Ignore("need to align with server") @Test
@Test
public void testProvinceCode() {
boolean caughtException = false;
try {
Expand Down Expand Up @@ -170,9 +179,9 @@ public void testProvinceCode() {
try {
Validate.provinceCode(this, "CAW", fieldName);
} catch (FieldBadFormatException e) {
caughtException = true;
caughtException = false;
}
assertTrue("Should have caught an exception as we are sending invalid province code", caughtException);
assertFalse("Should not have caught an exception as we are sending invalid province code", caughtException);

caughtException = false;
try {
Expand All @@ -181,5 +190,13 @@ public void testProvinceCode() {
caughtException = true;
}
assertFalse("Should not have caught an exception as 'CA' is a valid province code.", caughtException);

caughtException = false;
try {
Validate.provinceCode(this, "CA2", fieldName);
} catch (FieldBadFormatException e) {
caughtException = true;
}
assertFalse("Should not have caught an exception as 'CA2' is a valid province code.", caughtException);
}
}