Skip to content

Commit

Permalink
Support web login
Browse files Browse the repository at this point in the history
  • Loading branch information
racevedoo committed Nov 17, 2023
1 parent 4257503 commit cbece9d
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
56 changes: 56 additions & 0 deletions src/main/java/com/incognia/api/IncogniaAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -199,6 +200,61 @@ public TransactionAssessment registerLogin(RegisterLoginRequest request)
queryParameters);
}

/**
* Registers a web login to obtain a risk assessment. Check <a
* href="https://dash.incognia.com/api-reference#operation/transactions-post">the docs</a><br>
* Example:
*
* <pre>{@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
* }
* }</pre>
*
* @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<String, String> 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 <a
* href="https://dash.incognia.com/api-reference#operation/transactions-post">the docs</a><br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
public class PostTransactionRequestBody {
String installationId;
String accountId;
String sessionToken;

String type;
String externalId;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit cbece9d

Please sign in to comment.