From e539a0d674676e40ce507de75b8a0bca76ad8d67 Mon Sep 17 00:00:00 2001 From: Thiago Cardoso Date: Thu, 18 Jul 2024 17:03:59 -0300 Subject: [PATCH] feat: add support to missing fields on RegisterFeedback Adds support to expires_at and request_token. --- .../java/com/incognia/api/IncogniaAPI.java | 169 ++++++++++++++++++ .../feedback/FeedbackIdentifiers.java | 1 + .../feedback/PostFeedbackRequestBody.java | 2 + .../com/incognia/api/IncogniaAPITest.java | 25 ++- 4 files changed, 191 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/incognia/api/IncogniaAPI.java b/src/main/java/com/incognia/api/IncogniaAPI.java index 8e9f1da..a04e384 100644 --- a/src/main/java/com/incognia/api/IncogniaAPI.java +++ b/src/main/java/com/incognia/api/IncogniaAPI.java @@ -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 the docs
+ * Example: + * + *
{@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
+   * }
+   * }
+ * + * @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 the docs
+ * Example: + * + *
{@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
+   * }
+   * }
+ * + * @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 the docs
@@ -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 the docs
+ * Example: + * + *
{@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
+   * }
+   * }
+ * + * @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 the docs
+ * Example: + * + *
{@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
+   * }
+   * }
+ * + * @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()) diff --git a/src/main/java/com/incognia/feedback/FeedbackIdentifiers.java b/src/main/java/com/incognia/feedback/FeedbackIdentifiers.java index 18a2764..7e0cef0 100644 --- a/src/main/java/com/incognia/feedback/FeedbackIdentifiers.java +++ b/src/main/java/com/incognia/feedback/FeedbackIdentifiers.java @@ -8,6 +8,7 @@ public class FeedbackIdentifiers { String installationId; String sessionToken; + String requestToken; String loginId; String paymentId; String signupId; diff --git a/src/main/java/com/incognia/feedback/PostFeedbackRequestBody.java b/src/main/java/com/incognia/feedback/PostFeedbackRequestBody.java index 26f646f..3d51db2 100644 --- a/src/main/java/com/incognia/feedback/PostFeedbackRequestBody.java +++ b/src/main/java/com/incognia/feedback/PostFeedbackRequestBody.java @@ -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; diff --git a/src/test/java/com/incognia/api/IncogniaAPITest.java b/src/test/java/com/incognia/api/IncogniaAPITest.java index c243f7f..e0a0448 100644 --- a/src/test/java/com/incognia/api/IncogniaAPITest.java +++ b/src/test/java/com/incognia/api/IncogniaAPITest.java @@ -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; @@ -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) @@ -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)