Skip to content

Commit

Permalink
feat: add support to missing fields on RegisterFeedback
Browse files Browse the repository at this point in the history
Adds support to expires_at and request_token.
  • Loading branch information
figueredo committed Jul 24, 2024
1 parent 38f2459 commit e539a0d
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 6 deletions.
169 changes: 169 additions & 0 deletions src/main/java/com/incognia/api/IncogniaAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,91 @@ public void registerFeedback(
registerFeedback(feedbackEvent.getEventName(), occurredAt, identifiers, dryRun);
}

/**
* Shares feedback about a risk decision, improving the quality of risk assessments. Check <a
* href="https://dash.incognia.com/api-reference#operation/feedbacks-post">the docs</a><br>
* Example:
*
* <pre>{@code
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret");
* try {
* Instant occurredAt = Instant.parse("2024-07-22T15:20:00Z");
* Instant expiresAt = Instant.parse("2024-07-30T15:20:00Z");
* api.registerFeedback(
* FeedbackEvent.ACCOUNT_TAKEOVER,
* occurredAt,
* expiresAt,
* FeedbackIdentifiers.builder()
* .installationId("installation-id")
* .accountId("account-id")
* .build());
* } catch (IncogniaAPIException e) {
* //Some api error happened (invalid data, invalid credentials)
* } catch (IncogniaException e) {
* //Something unexpected happened
* }
* }</pre>
*
* @param feedbackEvent type of feedback event
* @param occurredAt Instant when the fraud or event happened
* @param expiresAt Instant when the effects of this feedback expires (valid for specific events)
* @param identifiers the user's identifiers
* @throws IncogniaAPIException in case of api errors
* @throws IncogniaException in case of unexpected errors
*/
public void registerFeedback(
FeedbackEvent feedbackEvent,
Instant occurredAt,
Instant expiresAt,
FeedbackIdentifiers identifiers)
throws IncogniaException {
registerFeedback(feedbackEvent, occurredAt, expiresAt, identifiers, false);
}

/**
* Shares feedback about a risk decision, improving the quality of risk assessments. Check <a
* href="https://dash.incognia.com/api-reference#operation/feedbacks-post">the docs</a><br>
* Example:
*
* <pre>{@code
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret");
* try {
* Instant occurredAt = Instant.parse("2024-07-22T15:20:00Z");
* Instant expiresAt = Instant.parse("2024-07-30T15:20:00Z");
* api.registerFeedback(
* FeedbackEvent.ACCOUNT_TAKEOVER,
* occurredAt,
* expiresAt,
* FeedbackIdentifiers.builder()
* .installationId("installation-id")
* .accountId("account-id")
* .build(),
* false);
* } catch (IncogniaAPIException e) {
* //Some api error happened (invalid data, invalid credentials)
* } catch (IncogniaException e) {
* //Something unexpected happened
* }
* }</pre>
*
* @param feedbackEvent type of feedback event
* @param occurredAt Instant when the fraud or event happened
* @param expiresAt Instant when the effects of this feedback expires (valid for specific events)
* @param identifiers the user's identifiers
* @param dryRun whether this request is a dry-run
* @throws IncogniaAPIException in case of api errors
* @throws IncogniaException in case of unexpected errors
*/
public void registerFeedback(
FeedbackEvent feedbackEvent,
Instant occurredAt,
Instant expiresAt,
FeedbackIdentifiers identifiers,
boolean dryRun)
throws IncogniaException {
registerFeedback(feedbackEvent.getEventName(), occurredAt, expiresAt, identifiers, dryRun);
}

/**
* Shares feedback about a risk decision, improving the quality of risk assessments. Check <a
* href="https://dash.incognia.com/api-reference#operation/feedbacks-post">the docs</a><br>
Expand Down Expand Up @@ -512,12 +597,96 @@ public void registerFeedback(
public void registerFeedback(
String feedbackEvent, Instant occurredAt, FeedbackIdentifiers identifiers, boolean dryRun)
throws IncogniaException {
registerFeedback(feedbackEvent, occurredAt, null, identifiers, dryRun);
}

/**
* Shares feedback about a risk decision, improving the quality of risk assessments. Check <a
* href="https://dash.incognia.com/api-reference#operation/feedbacks-post">the docs</a><br>
* Example:
*
* <pre>{@code
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret");
* try {
* Instant occurredAt = Instant.parse("2024-07-22T15:20:00Z");
* Instant expiresAt = Instant.parse("2024-07-30T15:20:00Z");
* api.registerFeedback(
* "account_takeover",
* occurredAt,
* expiresAt,
* FeedbackIdentifiers.builder()
* .installationId("installation-id")
* .accountId("account-id")
* .build());
* } catch (IncogniaAPIException e) {
* //Some api error happened (invalid data, invalid credentials)
* } catch (IncogniaException e) {
* //Something unexpected happened
* }
* }</pre>
*
* @param feedbackEvent type of feedback event
* @param occurredAt Instant when the fraud or event happened
* @param expiresAt Instant when the effects of this feedback expires (valid for specific events)
* @param identifiers the user's identifiers
* @throws IncogniaAPIException in case of api errors
* @throws IncogniaException in case of unexpected errors
*/
public void registerFeedback(
String feedbackEvent, Instant occurredAt, Instant expiresAt, FeedbackIdentifiers identifiers)
throws IncogniaException {
registerFeedback(feedbackEvent, occurredAt, expiresAt, identifiers, false);
}

/**
* Shares feedback about a risk decision, improving the quality of risk assessments. Check <a
* href="https://dash.incognia.com/api-reference#operation/feedbacks-post">the docs</a><br>
* Example:
*
* <pre>{@code
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret");
* try {
* Instant occurredAt = Instant.parse("2024-07-22T15:20:00Z");
* Instant expiresAt = Instant.parse("2024-07-30T15:20:00Z");
* api.registerFeedback(
* "account_takeover",
* occurredAt,
* expiresAt,
* FeedbackIdentifiers.builder()
* .installationId("installation-id")
* .accountId("account-id")
* .build(),
* false);
* } catch (IncogniaAPIException e) {
* //Some api error happened (invalid data, invalid credentials)
* } catch (IncogniaException e) {
* //Something unexpected happened
* }
* }</pre>
*
* @param feedbackEvent type of feedback event
* @param occurredAt Instant when the fraud or event happened
* @param expiresAt Instant when the effects of this feedback expires (valid for specific events)
* @param identifiers the user's identifiers
* @param dryRun whether this request is a dry-run
* @throws IncogniaAPIException in case of api errors
* @throws IncogniaException in case of unexpected errors
*/
public void registerFeedback(
String feedbackEvent,
Instant occurredAt,
Instant expiresAt,
FeedbackIdentifiers identifiers,
boolean dryRun)
throws IncogniaException {
PostFeedbackRequestBody requestBody =
PostFeedbackRequestBody.builder()
.event(feedbackEvent)
.occurredAt(occurredAt)
.expiresAt(expiresAt)
.installationId(identifiers.getInstallationId())
.sessionToken(identifiers.getSessionToken())
.requestToken(identifiers.getRequestToken())
.accountId(identifiers.getAccountId())
.loginId(identifiers.getLoginId())
.paymentId(identifiers.getPaymentId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
public class FeedbackIdentifiers {
String installationId;
String sessionToken;
String requestToken;
String loginId;
String paymentId;
String signupId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ public class PostFeedbackRequestBody {
String event;
@Deprecated Long timestamp;
Instant occurredAt;
Instant expiresAt;
String accountId;
String externalId;
String installationId;
String sessionToken;
String requestToken;
String paymentId;
String loginId;
String signupId;
Expand Down
25 changes: 19 additions & 6 deletions src/test/java/com/incognia/api/IncogniaAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.incognia.transaction.payment.RegisterPaymentRequest;
import java.io.IOException;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -542,29 +543,35 @@ void testRegisterFeedback_whenUsingFeedbackEventEnum_andDataIsValid(boolean dryR
String token = TokenCreationFixture.createToken();
String installationId = "installation-id";
String sessionToken = "session-token";
String requestToken = "request-token";
String accountId = "account-id";
String externalId = "external-id";
String signupId = UUID.randomUUID().toString();
Instant timestamp = Instant.now();
Instant occurredAt = Instant.now();
Instant expiresAt = occurredAt.plus(30, ChronoUnit.DAYS);

TokenAwareDispatcher dispatcher = new TokenAwareDispatcher(token, CLIENT_ID, CLIENT_SECRET);
dispatcher.setExpectedFeedbackRequestBody(
PostFeedbackRequestBody.builder()
.installationId(installationId)
.sessionToken(sessionToken)
.requestToken(requestToken)
.externalId(externalId)
.signupId(signupId)
.accountId(accountId)
.event(FeedbackEvent.ACCOUNT_TAKEOVER.getEventName())
.occurredAt(timestamp)
.occurredAt(occurredAt)
.expiresAt(expiresAt)
.build());
mockServer.setDispatcher(dispatcher);
client.registerFeedback(
FeedbackEvent.ACCOUNT_TAKEOVER,
timestamp,
occurredAt,
expiresAt,
FeedbackIdentifiers.builder()
.installationId(installationId)
.sessionToken(sessionToken)
.requestToken(requestToken)
.accountId(accountId)
.externalId(externalId)
.signupId(signupId)
Expand All @@ -580,29 +587,35 @@ void testRegisterFeedback_whenUsingFeedbackEventAsString_andDataIsValid(boolean
String token = TokenCreationFixture.createToken();
String installationId = "installation-id";
String sessionToken = "session-token";
String requestToken = "request-token";
String accountId = "account-id";
String externalId = "external-id";
String signupId = UUID.randomUUID().toString();
Instant timestamp = Instant.now();
Instant occurredAt = Instant.now();
Instant expiresAt = occurredAt.plus(30, ChronoUnit.DAYS);

TokenAwareDispatcher dispatcher = new TokenAwareDispatcher(token, CLIENT_ID, CLIENT_SECRET);
dispatcher.setExpectedFeedbackRequestBody(
PostFeedbackRequestBody.builder()
.installationId(installationId)
.sessionToken(sessionToken)
.requestToken(requestToken)
.externalId(externalId)
.signupId(signupId)
.accountId(accountId)
.event("custom_feedback_type")
.occurredAt(timestamp)
.occurredAt(occurredAt)
.expiresAt(expiresAt)
.build());
mockServer.setDispatcher(dispatcher);
client.registerFeedback(
"custom_feedback_type",
timestamp,
occurredAt,
expiresAt,
FeedbackIdentifiers.builder()
.installationId(installationId)
.sessionToken(sessionToken)
.requestToken(requestToken)
.accountId(accountId)
.externalId(externalId)
.signupId(signupId)
Expand Down

0 comments on commit e539a0d

Please sign in to comment.