Skip to content

Commit

Permalink
Update to use APIv3.4 (#67)
Browse files Browse the repository at this point in the history
* Update to use APIv3.4
  • Loading branch information
dvacca authored May 24, 2022
1 parent 3e47ffa commit 7a5a76b
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The official Java library for integrating with the Onfido API. Refer to the full [API documentation](https://documentation.onfido.com) for details of expected requests and responses for all resources.

This version uses Onfido API v3.3. Refer to our [API versioning guide](https://developers.onfido.com/guide/api-versioning-policy#client-libraries) for details of which client library versions use which versions of the API.
This version uses Onfido API v3.4. Refer to our [API versioning guide](https://developers.onfido.com/guide/api-versioning-policy#client-libraries) for details of which client library versions use which versions of the API.

## Installation

Expand Down
2 changes: 1 addition & 1 deletion onfido-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.onfido</groupId>
<artifactId>onfido-api-java</artifactId>
<version>2.5.0</version>
<version>2.6.0</version>

<name>Onfido API Java Client</name>
<description>Official Java API client library for the Onfido API</description>
Expand Down
1 change: 1 addition & 0 deletions onfido-java/src/main/java/com/onfido/DocumentManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public Document upload(InputStream inputStream, String fileName, Document.Reques
addFormDataParam(builder, "side", request.getSide());
addFormDataParam(builder, "issuing_country", request.getIssuingCountry());
addFormDataParam(builder, "validate_image_quality", request.getValidateImageQuality());
addFormDataParam(builder, "location", request.getLocation());

builder.addFormDataPart(
"file",
Expand Down
6 changes: 3 additions & 3 deletions onfido-java/src/main/java/com/onfido/Onfido.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
public final class Onfido {
private static final OkHttpClient CLIENT = new OkHttpClient();

private static final String EU_API_URL = "https://api.eu.onfido.com/v3.3/";
private static final String US_API_URL = "https://api.us.onfido.com/v3.3/";
private static final String CA_API_URL = "https://api.ca.onfido.com/v3.3/";
private static final String EU_API_URL = "https://api.eu.onfido.com/v3.4/";
private static final String US_API_URL = "https://api.us.onfido.com/v3.4/";
private static final String CA_API_URL = "https://api.ca.onfido.com/v3.4/";

/** The Configuration for the instance. */
public final Config config;
Expand Down
16 changes: 16 additions & 0 deletions onfido-java/src/main/models/applicant.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@
"$ref": "id_number.yaml"
},
"description": "The applicants ID numbers"
},
"phone_number": {
"type": "string",
"description": "The applicant’s phone number"
},
"location": {
"$ref": "../location/location.yaml",
"description": "The applicant's location"
},
"consents": {
"type": "array",
"items": {
"type": "string"
},
"description": "The applicant’s consents",
"writeOnly": true
}
}
}
5 changes: 5 additions & 0 deletions onfido-java/src/main/models/document.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
"type": "boolean",
"description": "When true the submitted image will undergo an image quality validation",
"writeOnly": true
},
"location": {
"$ref": "../location/location.yaml",
"description": "The applicant's location",
"writeOnly": true
}
}
}
13 changes: 13 additions & 0 deletions onfido-java/src/main/models/location.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"title": "Location",
"properties": {
"ip_address": {
"type": "string",
"description": "The applicant's ip address"
},
"country_of_residence": {
"type": "string",
"description": "The applicant's country of residence"
}
}
}
6 changes: 3 additions & 3 deletions onfido-java/src/test/java/com/onfido/OnfidoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ public void throwsExceptionForMissingRegion() {
@Test()
public void usesEURegionApiUrl() {
Onfido onfido = Onfido.builder().apiToken("token").regionEU().build();
assertEquals("https://api.eu.onfido.com/v3.3/", onfido.config.getApiUrl());
assertEquals("https://api.eu.onfido.com/v3.4/", onfido.config.getApiUrl());
}

@Test()
public void usesUSRegionApiUrl() {
Onfido onfido = Onfido.builder().apiToken("token").regionUS().build();
assertEquals("https://api.us.onfido.com/v3.3/", onfido.config.getApiUrl());
assertEquals("https://api.us.onfido.com/v3.4/", onfido.config.getApiUrl());
}

@Test()
public void usesCanadaRegionApiUrl() {
Onfido onfido = Onfido.builder().apiToken("token").regionCA().build();
assertEquals("https://api.ca.onfido.com/v3.3/", onfido.config.getApiUrl());
assertEquals("https://api.ca.onfido.com/v3.4/", onfido.config.getApiUrl());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.onfido.api.FileDownload;
import com.onfido.exceptions.ApiException;
import com.onfido.models.Document;
import com.onfido.models.Location;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Arrays;
Expand All @@ -28,12 +29,20 @@ public void uploadDocument() throws Exception {
Onfido.builder().apiToken("token").unknownApiUrl(server.url("/").toString()).build();

InputStream inputStream = new ByteArrayInputStream("testing testing 1 2".getBytes());

Location.Request locationRequest =
Location.request()
.ipAddress("127.0.0.1")
.countryOfResidence("GBR");

Document.Request documentRequest =
Document.request()
.applicantId("test id")
.issuingCountry("USA")
.side("front")
.type("passport");
.type("passport")
.location(locationRequest);

Document document = onfido.document.upload(inputStream, "file.png", documentRequest);

// Correct path
Expand All @@ -51,6 +60,7 @@ public void uploadDocument() throws Exception {
Assert.assertTrue(requestBody.contains("type"));
Assert.assertTrue(requestBody.contains("passport"));
Assert.assertTrue(requestBody.contains("testing testing 1 2"));
Assert.assertTrue(requestBody.contains("{\"country_of_residence\":\"GBR\",\"ip_address\":\"127.0.0.1\"}"));

// Correct response body
assertEquals("file.png", document.getFileName());
Expand Down

0 comments on commit 7a5a76b

Please sign in to comment.