Skip to content

Commit

Permalink
feat: allow to pass feedback event type as string
Browse files Browse the repository at this point in the history
  • Loading branch information
figueredo committed Jul 17, 2024
1 parent deedcf3 commit 1cff117
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 43 deletions.
137 changes: 125 additions & 12 deletions src/main/java/com/incognia/api/IncogniaAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public IncogniaAPI(String clientId, String clientSecret) {
* Example:
*
* <pre>{@code
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret", Region.BR);
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret");
* try {
* Address address = Address address =
* Address.builder()
Expand Down Expand Up @@ -128,7 +128,7 @@ public SignupAssessment registerSignup(RegisterSignupRequest request) throws Inc
* Example:
*
* <pre>{@code
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret", Region.BR);
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret");
* try {
* RegisterLoginRequest loginRequest = RegisterLoginRequest.builder()
* .installationId("installation-id")
Expand Down Expand Up @@ -183,7 +183,7 @@ public TransactionAssessment registerLogin(RegisterLoginRequest request)
* Example:
*
* <pre>{@code
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret", Region.BR);
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret");
* try {
* RegisterLoginRequest loginRequest = RegisterLoginRequest.builder()
* .accountId("account-id")
Expand Down Expand Up @@ -237,7 +237,7 @@ public TransactionAssessment registerWebLogin(RegisterWebLoginRequest request)
* Example:
*
* <pre>{@code
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret", Region.BR);
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret");
* try {
* RegisterWebSignupRequest webSignupRequest = RegisterWebSignupRequest.builder().sessionToken(sessionToken).address(address).build();
* SignupAssessment assessment = api.registerSignup(webSignupRequest);
Expand Down Expand Up @@ -275,7 +275,7 @@ public SignupAssessment registerWebSignup(RegisterWebSignupRequest request)
* Example:
*
* <pre>{@code
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret", Region.BR);
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret");
* try {
* Address address = Address address =
* Address.builder()
Expand Down Expand Up @@ -374,19 +374,19 @@ public TransactionAssessment registerPayment(RegisterPaymentRequest request)
* Example:
*
* <pre>{@code
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret", Region.BR);
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret");
* try {
* Instant timestamp = Instant.now();
* Instant occurredAt = Instant.now();
* client.registerFeedback(
* FeedbackEvent.ACCOUNT_TAKEOVER,
* timestamp,
* occurredAt,
* FeedbackIdentifiers.builder()
* .installationId("installation-id")
* .sessionToken("session-token")
* .accountId("account-id")
* .externalId("external-id")
* .signupId("c9ac2803-c868-4b7a-8323-8a6b96298ebe")
* .build();
* .build());
* } catch (IncogniaAPIException e) {
* //Some api error happened (invalid data, invalid credentials)
* } catch (IncogniaException e) {
Expand All @@ -395,23 +395,136 @@ public TransactionAssessment registerPayment(RegisterPaymentRequest request)
* }</pre>
*
* @param feedbackEvent type of feedback event
* @param timestamp Instant when the fraud or event happened
* @param occurredAt Instant when the fraud or event happened
* @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 timestamp, FeedbackIdentifiers identifiers)
FeedbackEvent feedbackEvent, Instant occurredAt, FeedbackIdentifiers identifiers)
throws IncogniaException {
registerFeedback(feedbackEvent, timestamp, identifiers, false);
registerFeedback(feedbackEvent, occurredAt, 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 timestamp = Instant.now();
* client.registerFeedback(
* FeedbackEvent.ACCOUNT_TAKEOVER,
* timestamp,
* FeedbackIdentifiers.builder()
* .installationId("installation-id")
* .sessionToken("session-token")
* .accountId("account-id")
* .externalId("external-id")
* .signupId("c9ac2803-c868-4b7a-8323-8a6b96298ebe")
* .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 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,
FeedbackIdentifiers identifiers,
boolean dryRun)
throws IncogniaException {
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 timestamp = Instant.now();
* client.registerFeedback(
* "account_takeover",
* timestamp,
* FeedbackIdentifiers.builder()
* .installationId("installation-id")
* .sessionToken("session-token")
* .accountId("account-id")
* .externalId("external-id")
* .signupId("c9ac2803-c868-4b7a-8323-8a6b96298ebe")
* .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 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, FeedbackIdentifiers identifiers)
throws IncogniaException {
registerFeedback(feedbackEvent, occurredAt, 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 timestamp = Instant.now();
* client.registerFeedback(
* "account_takeover",
* timestamp,
* FeedbackIdentifiers.builder()
* .installationId("installation-id")
* .sessionToken("session-token")
* .accountId("account-id")
* .externalId("external-id")
* .signupId("c9ac2803-c868-4b7a-8323-8a6b96298ebe")
* .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 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, FeedbackIdentifiers identifiers, boolean dryRun)
throws IncogniaException {
PostFeedbackRequestBody requestBody =
PostFeedbackRequestBody.builder()
.event(feedbackEvent)
Expand Down
33 changes: 5 additions & 28 deletions src/main/java/com/incognia/feedback/FeedbackEvent.java
Original file line number Diff line number Diff line change
@@ -1,56 +1,33 @@
package com.incognia.feedback;

import com.fasterxml.jackson.annotation.JsonProperty;

public enum FeedbackEvent {
@JsonProperty("signup_accepted")
SIGNUP_ACCEPTED,
@JsonProperty("signup_declined")
SIGNUP_DECLINED,
@JsonProperty("payment_accepted")
PAYMENT_ACCEPTED,
@JsonProperty("payment_accepted_by_third_party")
PAYMENT_ACCEPTED_BY_THIRD_PARTY,
@JsonProperty("payment_accepted_by_control_group")
PAYMENT_ACCEPTED_BY_CONTROL_GROUP,
@JsonProperty("payment_declined")
PAYMENT_DECLINED,
@JsonProperty("payment_declined_by_risk_analysis")
PAYMENT_DECLINED_BY_RISK_ANALYSIS,
@JsonProperty("payment_declined_by_manual_review")
PAYMENT_DECLINED_BY_MANUAL_REVIEW,
@JsonProperty("payment_declined_by_business")
PAYMENT_DECLINED_BY_BUSINESS,
@JsonProperty("payment_declined_by_acquirer")
PAYMENT_DECLINED_BY_ACQUIRER,
@JsonProperty("login_accepted")
LOGIN_ACCEPTED,
@JsonProperty("login_accepted_by_device_verification")
LOGIN_ACCEPTED_BY_DEVICE_VERIFICATION,
@JsonProperty("login_accepted_by_facial_biometrics")
LOGIN_ACCEPTED_BY_FACIAL_BIOMETRICS,
@JsonProperty("login_accepted_by_manual_review")
LOGIN_ACCEPTED_BY_MANUAL_REVIEW,
@JsonProperty("login_declined")
LOGIN_DECLINED,
@JsonProperty("login_declined_by_facial_biometrics")
LOGIN_DECLINED_BY_FACIAL_BIOMETRICS,
@JsonProperty("login_declined_by_manual_review")
LOGIN_DECLINED_BY_MANUAL_REVIEW,
@JsonProperty("account_allowed")
ACCOUNT_ALLOWED,
@JsonProperty("device_allowed")
DEVICE_ALLOWED,
@JsonProperty("verified")
VERIFIED,
@JsonProperty("identity_fraud")
IDENTITY_FRAUD,
@JsonProperty("account_takeover")
ACCOUNT_TAKEOVER,
@JsonProperty("chargeback_notification")
CHARGEBACK_NOTIFICATION,
@JsonProperty("chargeback")
CHARGEBACK,
@JsonProperty("reset")
RESET,
RESET;

public String getEventName() {
return this.name().toLowerCase();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@Value
@Builder
public class PostFeedbackRequestBody {
FeedbackEvent event;
String event;
Instant occurredAt;
String accountId;
String externalId;
Expand Down
42 changes: 40 additions & 2 deletions src/test/java/com/incognia/api/IncogniaAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ void testRegisterPayment_whenEvalIsFalse() {
@ValueSource(booleans = {true, false})
@DisplayName("should be successful")
@SneakyThrows
void testRegisterFeedback_whenDataIsValid(boolean dryRun) {
void testRegisterFeedback_whenUsingFeedbackEventEnum_andDataIsValid(boolean dryRun) {
String token = TokenCreationFixture.createToken();
String installationId = "installation-id";
String sessionToken = "session-token";
Expand All @@ -555,7 +555,7 @@ void testRegisterFeedback_whenDataIsValid(boolean dryRun) {
.externalId(externalId)
.signupId(signupId)
.accountId(accountId)
.event(FeedbackEvent.ACCOUNT_TAKEOVER)
.event(FeedbackEvent.ACCOUNT_TAKEOVER.getEventName())
.occurredAt(timestamp)
.build());
mockServer.setDispatcher(dispatcher);
Expand All @@ -572,6 +572,44 @@ void testRegisterFeedback_whenDataIsValid(boolean dryRun) {
dryRun);
}

@ParameterizedTest
@ValueSource(booleans = {true, false})
@DisplayName("should be successful")
@SneakyThrows
void testRegisterFeedback_whenUsingFeedbackEventAsString_andDataIsValid(boolean dryRun) {
String token = TokenCreationFixture.createToken();
String installationId = "installation-id";
String sessionToken = "session-token";
String accountId = "account-id";
String externalId = "external-id";
String signupId = UUID.randomUUID().toString();
Instant timestamp = Instant.now();

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

@Test
@DisplayName("should throw illegal argument exception with correct message")
@SneakyThrows
Expand Down

0 comments on commit 1cff117

Please sign in to comment.