Skip to content

Commit e539a0d

Browse files
committed
feat: add support to missing fields on RegisterFeedback
Adds support to expires_at and request_token.
1 parent 38f2459 commit e539a0d

File tree

4 files changed

+191
-6
lines changed

4 files changed

+191
-6
lines changed

src/main/java/com/incognia/api/IncogniaAPI.java

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,91 @@ public void registerFeedback(
443443
registerFeedback(feedbackEvent.getEventName(), occurredAt, identifiers, dryRun);
444444
}
445445

446+
/**
447+
* Shares feedback about a risk decision, improving the quality of risk assessments. Check <a
448+
* href="https://dash.incognia.com/api-reference#operation/feedbacks-post">the docs</a><br>
449+
* Example:
450+
*
451+
* <pre>{@code
452+
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret");
453+
* try {
454+
* Instant occurredAt = Instant.parse("2024-07-22T15:20:00Z");
455+
* Instant expiresAt = Instant.parse("2024-07-30T15:20:00Z");
456+
* api.registerFeedback(
457+
* FeedbackEvent.ACCOUNT_TAKEOVER,
458+
* occurredAt,
459+
* expiresAt,
460+
* FeedbackIdentifiers.builder()
461+
* .installationId("installation-id")
462+
* .accountId("account-id")
463+
* .build());
464+
* } catch (IncogniaAPIException e) {
465+
* //Some api error happened (invalid data, invalid credentials)
466+
* } catch (IncogniaException e) {
467+
* //Something unexpected happened
468+
* }
469+
* }</pre>
470+
*
471+
* @param feedbackEvent type of feedback event
472+
* @param occurredAt Instant when the fraud or event happened
473+
* @param expiresAt Instant when the effects of this feedback expires (valid for specific events)
474+
* @param identifiers the user's identifiers
475+
* @throws IncogniaAPIException in case of api errors
476+
* @throws IncogniaException in case of unexpected errors
477+
*/
478+
public void registerFeedback(
479+
FeedbackEvent feedbackEvent,
480+
Instant occurredAt,
481+
Instant expiresAt,
482+
FeedbackIdentifiers identifiers)
483+
throws IncogniaException {
484+
registerFeedback(feedbackEvent, occurredAt, expiresAt, identifiers, false);
485+
}
486+
487+
/**
488+
* Shares feedback about a risk decision, improving the quality of risk assessments. Check <a
489+
* href="https://dash.incognia.com/api-reference#operation/feedbacks-post">the docs</a><br>
490+
* Example:
491+
*
492+
* <pre>{@code
493+
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret");
494+
* try {
495+
* Instant occurredAt = Instant.parse("2024-07-22T15:20:00Z");
496+
* Instant expiresAt = Instant.parse("2024-07-30T15:20:00Z");
497+
* api.registerFeedback(
498+
* FeedbackEvent.ACCOUNT_TAKEOVER,
499+
* occurredAt,
500+
* expiresAt,
501+
* FeedbackIdentifiers.builder()
502+
* .installationId("installation-id")
503+
* .accountId("account-id")
504+
* .build(),
505+
* false);
506+
* } catch (IncogniaAPIException e) {
507+
* //Some api error happened (invalid data, invalid credentials)
508+
* } catch (IncogniaException e) {
509+
* //Something unexpected happened
510+
* }
511+
* }</pre>
512+
*
513+
* @param feedbackEvent type of feedback event
514+
* @param occurredAt Instant when the fraud or event happened
515+
* @param expiresAt Instant when the effects of this feedback expires (valid for specific events)
516+
* @param identifiers the user's identifiers
517+
* @param dryRun whether this request is a dry-run
518+
* @throws IncogniaAPIException in case of api errors
519+
* @throws IncogniaException in case of unexpected errors
520+
*/
521+
public void registerFeedback(
522+
FeedbackEvent feedbackEvent,
523+
Instant occurredAt,
524+
Instant expiresAt,
525+
FeedbackIdentifiers identifiers,
526+
boolean dryRun)
527+
throws IncogniaException {
528+
registerFeedback(feedbackEvent.getEventName(), occurredAt, expiresAt, identifiers, dryRun);
529+
}
530+
446531
/**
447532
* Shares feedback about a risk decision, improving the quality of risk assessments. Check <a
448533
* href="https://dash.incognia.com/api-reference#operation/feedbacks-post">the docs</a><br>
@@ -512,12 +597,96 @@ public void registerFeedback(
512597
public void registerFeedback(
513598
String feedbackEvent, Instant occurredAt, FeedbackIdentifiers identifiers, boolean dryRun)
514599
throws IncogniaException {
600+
registerFeedback(feedbackEvent, occurredAt, null, identifiers, dryRun);
601+
}
602+
603+
/**
604+
* Shares feedback about a risk decision, improving the quality of risk assessments. Check <a
605+
* href="https://dash.incognia.com/api-reference#operation/feedbacks-post">the docs</a><br>
606+
* Example:
607+
*
608+
* <pre>{@code
609+
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret");
610+
* try {
611+
* Instant occurredAt = Instant.parse("2024-07-22T15:20:00Z");
612+
* Instant expiresAt = Instant.parse("2024-07-30T15:20:00Z");
613+
* api.registerFeedback(
614+
* "account_takeover",
615+
* occurredAt,
616+
* expiresAt,
617+
* FeedbackIdentifiers.builder()
618+
* .installationId("installation-id")
619+
* .accountId("account-id")
620+
* .build());
621+
* } catch (IncogniaAPIException e) {
622+
* //Some api error happened (invalid data, invalid credentials)
623+
* } catch (IncogniaException e) {
624+
* //Something unexpected happened
625+
* }
626+
* }</pre>
627+
*
628+
* @param feedbackEvent type of feedback event
629+
* @param occurredAt Instant when the fraud or event happened
630+
* @param expiresAt Instant when the effects of this feedback expires (valid for specific events)
631+
* @param identifiers the user's identifiers
632+
* @throws IncogniaAPIException in case of api errors
633+
* @throws IncogniaException in case of unexpected errors
634+
*/
635+
public void registerFeedback(
636+
String feedbackEvent, Instant occurredAt, Instant expiresAt, FeedbackIdentifiers identifiers)
637+
throws IncogniaException {
638+
registerFeedback(feedbackEvent, occurredAt, expiresAt, identifiers, false);
639+
}
640+
641+
/**
642+
* Shares feedback about a risk decision, improving the quality of risk assessments. Check <a
643+
* href="https://dash.incognia.com/api-reference#operation/feedbacks-post">the docs</a><br>
644+
* Example:
645+
*
646+
* <pre>{@code
647+
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret");
648+
* try {
649+
* Instant occurredAt = Instant.parse("2024-07-22T15:20:00Z");
650+
* Instant expiresAt = Instant.parse("2024-07-30T15:20:00Z");
651+
* api.registerFeedback(
652+
* "account_takeover",
653+
* occurredAt,
654+
* expiresAt,
655+
* FeedbackIdentifiers.builder()
656+
* .installationId("installation-id")
657+
* .accountId("account-id")
658+
* .build(),
659+
* false);
660+
* } catch (IncogniaAPIException e) {
661+
* //Some api error happened (invalid data, invalid credentials)
662+
* } catch (IncogniaException e) {
663+
* //Something unexpected happened
664+
* }
665+
* }</pre>
666+
*
667+
* @param feedbackEvent type of feedback event
668+
* @param occurredAt Instant when the fraud or event happened
669+
* @param expiresAt Instant when the effects of this feedback expires (valid for specific events)
670+
* @param identifiers the user's identifiers
671+
* @param dryRun whether this request is a dry-run
672+
* @throws IncogniaAPIException in case of api errors
673+
* @throws IncogniaException in case of unexpected errors
674+
*/
675+
public void registerFeedback(
676+
String feedbackEvent,
677+
Instant occurredAt,
678+
Instant expiresAt,
679+
FeedbackIdentifiers identifiers,
680+
boolean dryRun)
681+
throws IncogniaException {
515682
PostFeedbackRequestBody requestBody =
516683
PostFeedbackRequestBody.builder()
517684
.event(feedbackEvent)
518685
.occurredAt(occurredAt)
686+
.expiresAt(expiresAt)
519687
.installationId(identifiers.getInstallationId())
520688
.sessionToken(identifiers.getSessionToken())
689+
.requestToken(identifiers.getRequestToken())
521690
.accountId(identifiers.getAccountId())
522691
.loginId(identifiers.getLoginId())
523692
.paymentId(identifiers.getPaymentId())

src/main/java/com/incognia/feedback/FeedbackIdentifiers.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
public class FeedbackIdentifiers {
99
String installationId;
1010
String sessionToken;
11+
String requestToken;
1112
String loginId;
1213
String paymentId;
1314
String signupId;

src/main/java/com/incognia/feedback/PostFeedbackRequestBody.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ public class PostFeedbackRequestBody {
1010
String event;
1111
@Deprecated Long timestamp;
1212
Instant occurredAt;
13+
Instant expiresAt;
1314
String accountId;
1415
String externalId;
1516
String installationId;
1617
String sessionToken;
18+
String requestToken;
1719
String paymentId;
1820
String loginId;
1921
String signupId;

src/test/java/com/incognia/api/IncogniaAPITest.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.incognia.transaction.payment.RegisterPaymentRequest;
3232
import java.io.IOException;
3333
import java.time.Instant;
34+
import java.time.temporal.ChronoUnit;
3435
import java.util.ArrayList;
3536
import java.util.Collections;
3637
import java.util.HashMap;
@@ -542,29 +543,35 @@ void testRegisterFeedback_whenUsingFeedbackEventEnum_andDataIsValid(boolean dryR
542543
String token = TokenCreationFixture.createToken();
543544
String installationId = "installation-id";
544545
String sessionToken = "session-token";
546+
String requestToken = "request-token";
545547
String accountId = "account-id";
546548
String externalId = "external-id";
547549
String signupId = UUID.randomUUID().toString();
548-
Instant timestamp = Instant.now();
550+
Instant occurredAt = Instant.now();
551+
Instant expiresAt = occurredAt.plus(30, ChronoUnit.DAYS);
549552

550553
TokenAwareDispatcher dispatcher = new TokenAwareDispatcher(token, CLIENT_ID, CLIENT_SECRET);
551554
dispatcher.setExpectedFeedbackRequestBody(
552555
PostFeedbackRequestBody.builder()
553556
.installationId(installationId)
554557
.sessionToken(sessionToken)
558+
.requestToken(requestToken)
555559
.externalId(externalId)
556560
.signupId(signupId)
557561
.accountId(accountId)
558562
.event(FeedbackEvent.ACCOUNT_TAKEOVER.getEventName())
559-
.occurredAt(timestamp)
563+
.occurredAt(occurredAt)
564+
.expiresAt(expiresAt)
560565
.build());
561566
mockServer.setDispatcher(dispatcher);
562567
client.registerFeedback(
563568
FeedbackEvent.ACCOUNT_TAKEOVER,
564-
timestamp,
569+
occurredAt,
570+
expiresAt,
565571
FeedbackIdentifiers.builder()
566572
.installationId(installationId)
567573
.sessionToken(sessionToken)
574+
.requestToken(requestToken)
568575
.accountId(accountId)
569576
.externalId(externalId)
570577
.signupId(signupId)
@@ -580,29 +587,35 @@ void testRegisterFeedback_whenUsingFeedbackEventAsString_andDataIsValid(boolean
580587
String token = TokenCreationFixture.createToken();
581588
String installationId = "installation-id";
582589
String sessionToken = "session-token";
590+
String requestToken = "request-token";
583591
String accountId = "account-id";
584592
String externalId = "external-id";
585593
String signupId = UUID.randomUUID().toString();
586-
Instant timestamp = Instant.now();
594+
Instant occurredAt = Instant.now();
595+
Instant expiresAt = occurredAt.plus(30, ChronoUnit.DAYS);
587596

588597
TokenAwareDispatcher dispatcher = new TokenAwareDispatcher(token, CLIENT_ID, CLIENT_SECRET);
589598
dispatcher.setExpectedFeedbackRequestBody(
590599
PostFeedbackRequestBody.builder()
591600
.installationId(installationId)
592601
.sessionToken(sessionToken)
602+
.requestToken(requestToken)
593603
.externalId(externalId)
594604
.signupId(signupId)
595605
.accountId(accountId)
596606
.event("custom_feedback_type")
597-
.occurredAt(timestamp)
607+
.occurredAt(occurredAt)
608+
.expiresAt(expiresAt)
598609
.build());
599610
mockServer.setDispatcher(dispatcher);
600611
client.registerFeedback(
601612
"custom_feedback_type",
602-
timestamp,
613+
occurredAt,
614+
expiresAt,
603615
FeedbackIdentifiers.builder()
604616
.installationId(installationId)
605617
.sessionToken(sessionToken)
618+
.requestToken(requestToken)
606619
.accountId(accountId)
607620
.externalId(externalId)
608621
.signupId(signupId)

0 commit comments

Comments
 (0)