From cbece9d54c738a2561941f532795c7d2f1f759ef Mon Sep 17 00:00:00 2001 From: Rafael Acevedo Date: Fri, 17 Nov 2023 08:39:34 -0300 Subject: [PATCH] Support web login --- README.md | 23 ++++++++ .../java/com/incognia/api/IncogniaAPI.java | 56 +++++++++++++++++++ .../PostTransactionRequestBody.java | 1 + .../login/RegisterWebLoginRequest.java | 22 ++++++++ 4 files changed, 102 insertions(+) create mode 100644 src/main/java/com/incognia/transaction/login/RegisterWebLoginRequest.java diff --git a/README.md b/README.md index 2bc8afc..a0a2407 100644 --- a/README.md +++ b/README.md @@ -141,6 +141,29 @@ try { } ``` +#### Registering Web Login + +This method registers a new web login for the given installation and account, returning a `TransactionAssessment`, containing the risk assessment and supporting evidence. + +```java +IncogniaAPI api = new IncogniaAPI("client-id", "client-secret"); +try { + RegisterLoginRequest registerLoginRequest = + RegisterLoginRequest.builder() + .installationId("installation id") + .accountId("account id") + .externalId("external id") + .sessionToken("session-token") + .evaluateTransaction(true) // can be omitted as it uses true as the default value + .build(); + TransactionAssessment assessment = api.registerWebLogin(registerLoginRequest); +} catch (IncogniaAPIException e) { + //Some api error happened (invalid data, invalid credentials) +} catch (IncogniaException e) { + //Something unexpected happened +} +``` + #### Registering Payment This method registers a new payment for the given installation and account, returning a `TransactionAssessment`, containing the risk assessment and supporting evidence. diff --git a/src/main/java/com/incognia/api/IncogniaAPI.java b/src/main/java/com/incognia/api/IncogniaAPI.java index 9567274..e7ebb27 100644 --- a/src/main/java/com/incognia/api/IncogniaAPI.java +++ b/src/main/java/com/incognia/api/IncogniaAPI.java @@ -16,6 +16,7 @@ import com.incognia.transaction.TransactionAddress; import com.incognia.transaction.TransactionAssessment; import com.incognia.transaction.login.RegisterLoginRequest; +import com.incognia.transaction.login.RegisterWebLoginRequest; import com.incognia.transaction.payment.RegisterPaymentRequest; import java.time.Instant; import java.util.HashMap; @@ -199,6 +200,61 @@ public TransactionAssessment registerLogin(RegisterLoginRequest request) queryParameters); } + /** + * Registers a web login to obtain a risk assessment. Check the docs
+ * Example: + * + *
{@code
+   * IncogniaAPI api = new IncogniaAPI("client-id", "client-secret", Region.BR);
+   * try {
+   *     RegisterLoginRequest loginRequest = RegisterLoginRequest.builder()
+   *         .installationId("installation-id")
+   *         .accountId("account-id")
+   *         .externalId("external-id")
+   *         .sessionToken("session-token")
+   *         .evaluateTransaction(true) // can be omitted as it uses true as the default value
+   *         .build();
+   *      TransactionAssessment assessment = api.registerLogin(loginRequest);
+   * } catch (IncogniaAPIException e) {
+   *      //Some api error happened (invalid data, invalid credentials)
+   * } catch (IncogniaException e) {
+   *      //Something unexpected happened
+   * }
+   * }
+ * + * @param request the {@link RegisterWebLoginRequest} model with the properties we need to make + * the assessment + * @return the assessment for the login + * @throws IncogniaAPIException in case of api errors + * @throws IncogniaException in case of unexpected errors + */ + public TransactionAssessment registerWebLogin(RegisterWebLoginRequest request) + throws IncogniaException { + Asserts.assertNotNull(request, "register login request"); + Asserts.assertNotEmpty(request.getInstallationId(), "installation id"); + Asserts.assertNotEmpty(request.getAccountId(), "account id"); + Asserts.assertNotEmpty(request.getSessionToken(), "session token"); + PostTransactionRequestBody requestBody = + PostTransactionRequestBody.builder() + .installationId(request.getInstallationId()) + .accountId(request.getAccountId()) + .externalId(request.getExternalId()) + .sessionToken(request.getSessionToken()) + .type("login") + .build(); + + Map queryParameters = new HashMap<>(); + if (request.shouldEvaluateTransaction() != null) { + queryParameters.put(EVALUATION_PARAMETER, request.shouldEvaluateTransaction().toString()); + } + return tokenAwareNetworkingClient.doPost( + "api/v2/authentication/transactions", + requestBody, + TransactionAssessment.class, + queryParameters); + } + /** * Registers a payment to obtain a risk assessment. Check the docs
diff --git a/src/main/java/com/incognia/transaction/PostTransactionRequestBody.java b/src/main/java/com/incognia/transaction/PostTransactionRequestBody.java index 56f1251..e36d416 100644 --- a/src/main/java/com/incognia/transaction/PostTransactionRequestBody.java +++ b/src/main/java/com/incognia/transaction/PostTransactionRequestBody.java @@ -13,6 +13,7 @@ public class PostTransactionRequestBody { String installationId; String accountId; + String sessionToken; String type; String externalId; diff --git a/src/main/java/com/incognia/transaction/login/RegisterWebLoginRequest.java b/src/main/java/com/incognia/transaction/login/RegisterWebLoginRequest.java new file mode 100644 index 0000000..3c43b1a --- /dev/null +++ b/src/main/java/com/incognia/transaction/login/RegisterWebLoginRequest.java @@ -0,0 +1,22 @@ +package com.incognia.transaction.login; + +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.Value; + +@Value +@Builder +public class RegisterWebLoginRequest { + String installationId; + String accountId; + String externalId; + String sessionToken; + + @Getter(AccessLevel.NONE) + Boolean evaluateTransaction; + + public Boolean shouldEvaluateTransaction() { + return this.evaluateTransaction; + } +}