Java

io.github.mosesmmoisebidth:verisec-java is the official library for Java 17 and later. Maven Central

Install#

// Gradle (Kotlin)
implementation("io.github.mosesmmoisebidth:verisec-java:1.0.0")

Create a client#

Java
import dev.verisec.VeriSec;

VeriSec client = VeriSec.builder().apiKey(System.getenv("VERISEC_API_KEY")).build(); // sk_test_…

Every setting falls back to the environment (VERISEC_API_KEY). Builder options include timeout(Duration) and maxRetries(int).

Make a call#

Every endpoint is a method on its group: face.verify is client.face().verify(...). Each takes a params object built with a builder.

Java
FaceVerify result = client.face().verify(FaceVerifyParams.builder()
    .image1(Image.fromPath(Path.of("selfie.jpg")))
    .image2(Image.fromPath(Path.of("id-photo.jpg")))
    .threshold(0.8)
    .build());

ChequeDeepRead cheque = client.cheques().read(ChequeReadParams.builder()
    .image(FileInput.of(Path.of("cheque.jpg")))
    .build());

Errors#

Java
try {
    client.face().verify(params);
} catch (InsufficientCreditsException e) {
    System.out.println("Top up credits. Nothing was charged.");
} catch (InvalidRequestException e) {
    System.out.println(e.code() + " " + e.param() + ": " + e.getMessage());
} catch (RateLimitException e) {
    System.out.println("Wait " + e.retryAfter());
} catch (ApiException e) {
    System.out.println(e.status() + " " + e.code() + " (request " + e.requestId() + ")");
} catch (ApiConnectionException e) {
    System.out.println(e.getMessage()); // ApiTimeoutException too
}

Every exception is unchecked and extends VeriSecException. ApiException has one subclass per status: InvalidRequestException, AuthenticationException, InsufficientCreditsException, PermissionException, NotFoundException, RateLimitException and ApiServerException.

Webhooks#

Java
WebhookEvent event = Webhooks.constructEvent(payload, headers, System.getenv("VERISEC_WEBHOOK_SECRET"));

See Webhooks for a full handler.