Skip to content

Commit 416299d

Browse files
committed
feat: allow to pass feedback event type as string
1 parent 3ad6b4c commit 416299d

File tree

4 files changed

+170
-46
lines changed

4 files changed

+170
-46
lines changed

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

Lines changed: 125 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public IncogniaAPI(String clientId, String clientSecret) {
6868
* Example:
6969
*
7070
* <pre>{@code
71-
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret", Region.BR);
71+
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret");
7272
* try {
7373
* Address address = Address address =
7474
* Address.builder()
@@ -128,7 +128,7 @@ public SignupAssessment registerSignup(RegisterSignupRequest request) throws Inc
128128
* Example:
129129
*
130130
* <pre>{@code
131-
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret", Region.BR);
131+
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret");
132132
* try {
133133
* RegisterLoginRequest loginRequest = RegisterLoginRequest.builder()
134134
* .installationId("installation-id")
@@ -183,7 +183,7 @@ public TransactionAssessment registerLogin(RegisterLoginRequest request)
183183
* Example:
184184
*
185185
* <pre>{@code
186-
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret", Region.BR);
186+
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret");
187187
* try {
188188
* RegisterLoginRequest loginRequest = RegisterLoginRequest.builder()
189189
* .accountId("account-id")
@@ -237,7 +237,7 @@ public TransactionAssessment registerWebLogin(RegisterWebLoginRequest request)
237237
* Example:
238238
*
239239
* <pre>{@code
240-
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret", Region.BR);
240+
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret");
241241
* try {
242242
* RegisterWebSignupRequest webSignupRequest = RegisterWebSignupRequest.builder().sessionToken(sessionToken).address(address).build();
243243
* SignupAssessment assessment = api.registerSignup(webSignupRequest);
@@ -275,7 +275,7 @@ public SignupAssessment registerWebSignup(RegisterWebSignupRequest request)
275275
* Example:
276276
*
277277
* <pre>{@code
278-
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret", Region.BR);
278+
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret");
279279
* try {
280280
* Address address = Address address =
281281
* Address.builder()
@@ -374,19 +374,19 @@ public TransactionAssessment registerPayment(RegisterPaymentRequest request)
374374
* Example:
375375
*
376376
* <pre>{@code
377-
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret", Region.BR);
377+
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret");
378378
* try {
379-
* Instant timestamp = Instant.now();
379+
* Instant occurredAt = Instant.now();
380380
* client.registerFeedback(
381381
* FeedbackEvent.ACCOUNT_TAKEOVER,
382-
* timestamp,
382+
* occurredAt,
383383
* FeedbackIdentifiers.builder()
384384
* .installationId("installation-id")
385385
* .sessionToken("session-token")
386386
* .accountId("account-id")
387387
* .externalId("external-id")
388388
* .signupId("c9ac2803-c868-4b7a-8323-8a6b96298ebe")
389-
* .build();
389+
* .build());
390390
* } catch (IncogniaAPIException e) {
391391
* //Some api error happened (invalid data, invalid credentials)
392392
* } catch (IncogniaException e) {
@@ -395,23 +395,136 @@ public TransactionAssessment registerPayment(RegisterPaymentRequest request)
395395
* }</pre>
396396
*
397397
* @param feedbackEvent type of feedback event
398-
* @param timestamp Instant when the fraud or event happened
398+
* @param occurredAt Instant when the fraud or event happened
399399
* @param identifiers the user's identifiers
400400
* @throws IncogniaAPIException in case of api errors
401401
* @throws IncogniaException in case of unexpected errors
402402
*/
403403
public void registerFeedback(
404-
FeedbackEvent feedbackEvent, Instant timestamp, FeedbackIdentifiers identifiers)
404+
FeedbackEvent feedbackEvent, Instant occurredAt, FeedbackIdentifiers identifiers)
405405
throws IncogniaException {
406-
registerFeedback(feedbackEvent, timestamp, identifiers, false);
406+
registerFeedback(feedbackEvent, occurredAt, identifiers, false);
407407
}
408408

409+
/**
410+
* Shares feedback about a risk decision, improving the quality of risk assessments. Check <a
411+
* href="https://dash.incognia.com/api-reference#operation/feedbacks-post">the docs</a><br>
412+
* Example:
413+
*
414+
* <pre>{@code
415+
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret");
416+
* try {
417+
* Instant timestamp = Instant.now();
418+
* client.registerFeedback(
419+
* FeedbackEvent.ACCOUNT_TAKEOVER,
420+
* timestamp,
421+
* FeedbackIdentifiers.builder()
422+
* .installationId("installation-id")
423+
* .sessionToken("session-token")
424+
* .accountId("account-id")
425+
* .externalId("external-id")
426+
* .signupId("c9ac2803-c868-4b7a-8323-8a6b96298ebe")
427+
* .build(),
428+
* false);
429+
* } catch (IncogniaAPIException e) {
430+
* //Some api error happened (invalid data, invalid credentials)
431+
* } catch (IncogniaException e) {
432+
* //Something unexpected happened
433+
* }
434+
* }</pre>
435+
*
436+
* @param feedbackEvent type of feedback event
437+
* @param occurredAt Instant when the fraud or event happened
438+
* @param identifiers the user's identifiers
439+
* @param dryRun whether this request is a dry-run
440+
* @throws IncogniaAPIException in case of api errors
441+
* @throws IncogniaException in case of unexpected errors
442+
*/
409443
public void registerFeedback(
410444
FeedbackEvent feedbackEvent,
411445
Instant occurredAt,
412446
FeedbackIdentifiers identifiers,
413447
boolean dryRun)
414448
throws IncogniaException {
449+
registerFeedback(feedbackEvent.getEventName(), occurredAt, identifiers, dryRun);
450+
}
451+
452+
/**
453+
* Shares feedback about a risk decision, improving the quality of risk assessments. Check <a
454+
* href="https://dash.incognia.com/api-reference#operation/feedbacks-post">the docs</a><br>
455+
* Example:
456+
*
457+
* <pre>{@code
458+
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret");
459+
* try {
460+
* Instant timestamp = Instant.now();
461+
* client.registerFeedback(
462+
* "account_takeover",
463+
* timestamp,
464+
* FeedbackIdentifiers.builder()
465+
* .installationId("installation-id")
466+
* .sessionToken("session-token")
467+
* .accountId("account-id")
468+
* .externalId("external-id")
469+
* .signupId("c9ac2803-c868-4b7a-8323-8a6b96298ebe")
470+
* .build(),
471+
* false);
472+
* } catch (IncogniaAPIException e) {
473+
* //Some api error happened (invalid data, invalid credentials)
474+
* } catch (IncogniaException e) {
475+
* //Something unexpected happened
476+
* }
477+
* }</pre>
478+
*
479+
* @param feedbackEvent type of feedback event
480+
* @param occurredAt Instant when the fraud or event happened
481+
* @param identifiers the user's identifiers
482+
* @throws IncogniaAPIException in case of api errors
483+
* @throws IncogniaException in case of unexpected errors
484+
*/
485+
public void registerFeedback(
486+
String feedbackEvent, Instant occurredAt, FeedbackIdentifiers identifiers)
487+
throws IncogniaException {
488+
registerFeedback(feedbackEvent, occurredAt, identifiers, false);
489+
}
490+
491+
/**
492+
* Shares feedback about a risk decision, improving the quality of risk assessments. Check <a
493+
* href="https://dash.incognia.com/api-reference#operation/feedbacks-post">the docs</a><br>
494+
* Example:
495+
*
496+
* <pre>{@code
497+
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret");
498+
* try {
499+
* Instant timestamp = Instant.now();
500+
* client.registerFeedback(
501+
* "account_takeover",
502+
* timestamp,
503+
* FeedbackIdentifiers.builder()
504+
* .installationId("installation-id")
505+
* .sessionToken("session-token")
506+
* .accountId("account-id")
507+
* .externalId("external-id")
508+
* .signupId("c9ac2803-c868-4b7a-8323-8a6b96298ebe")
509+
* .build(),
510+
* false);
511+
* } catch (IncogniaAPIException e) {
512+
* //Some api error happened (invalid data, invalid credentials)
513+
* } catch (IncogniaException e) {
514+
* //Something unexpected happened
515+
* }
516+
* }</pre>
517+
*
518+
* @param feedbackEvent type of feedback event
519+
* @param occurredAt Instant when the fraud or event happened
520+
* @param identifiers the user's identifiers
521+
* @param dryRun whether this request is a dry-run
522+
* @throws IncogniaAPIException in case of api errors
523+
* @throws IncogniaException in case of unexpected errors
524+
*/
525+
public void registerFeedback(
526+
String feedbackEvent, Instant occurredAt, FeedbackIdentifiers identifiers, boolean dryRun)
527+
throws IncogniaException {
415528
PostFeedbackRequestBody requestBody =
416529
PostFeedbackRequestBody.builder()
417530
.event(feedbackEvent)
Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,37 @@
11
package com.incognia.feedback;
22

3-
import com.fasterxml.jackson.annotation.JsonProperty;
4-
53
public enum FeedbackEvent {
6-
@JsonProperty("signup_accepted")
74
SIGNUP_ACCEPTED,
8-
@JsonProperty("signup_declined")
95
SIGNUP_DECLINED,
10-
@JsonProperty("payment_accepted")
116
PAYMENT_ACCEPTED,
12-
@JsonProperty("payment_accepted_by_third_party")
137
PAYMENT_ACCEPTED_BY_THIRD_PARTY,
14-
@JsonProperty("payment_accepted_by_control_group")
158
PAYMENT_ACCEPTED_BY_CONTROL_GROUP,
16-
@JsonProperty("payment_declined")
179
PAYMENT_DECLINED,
18-
@JsonProperty("payment_declined_by_risk_analysis")
1910
PAYMENT_DECLINED_BY_RISK_ANALYSIS,
20-
@JsonProperty("payment_declined_by_manual_review")
2111
PAYMENT_DECLINED_BY_MANUAL_REVIEW,
22-
@JsonProperty("payment_declined_by_business")
2312
PAYMENT_DECLINED_BY_BUSINESS,
24-
@JsonProperty("payment_declined_by_acquirer")
2513
PAYMENT_DECLINED_BY_ACQUIRER,
26-
@JsonProperty("login_accepted")
2714
LOGIN_ACCEPTED,
28-
@JsonProperty("login_declined")
2915
LOGIN_DECLINED,
30-
@JsonProperty("verified")
3116
VERIFIED,
32-
@JsonProperty("identity_fraud")
3317
IDENTITY_FRAUD,
34-
@JsonProperty("account_takeover")
3518
ACCOUNT_TAKEOVER,
36-
@JsonProperty("chargeback_notification")
3719
CHARGEBACK_NOTIFICATION,
38-
@JsonProperty("chargeback")
3920
CHARGEBACK,
40-
@JsonProperty("mpos_fraud")
4121
MPOS_FRAUD,
42-
@JsonProperty("challenge_passed")
4322
CHALLENGE_PASSED,
44-
@JsonProperty("challenge_failed")
4523
CHALLENGE_FAILED,
46-
@JsonProperty("password_changed_successfully")
4724
PASSWORD_CHANGED_SUCCESSFULLY,
48-
@JsonProperty("password_change_failed")
4925
PASSWORD_CHANGE_FAILED,
50-
@JsonProperty("promotion_abuse")
5126
PROMOTION_ABUSE,
52-
@JsonProperty("custom_other_fraud")
5327
CUSTOM_OTHER_FRAUD,
54-
@JsonProperty("custom_discipline_block")
5528
CUSTOM_DISCIPLINE_BLOCK,
56-
@JsonProperty("custom_pos_atm_fraud")
5729
CUSTOM_POS_ATM_FRAUD,
58-
@JsonProperty("custom_collusion_fraud")
5930
CUSTOM_COLLUSION_FRAUD,
60-
@JsonProperty("custom_cargo_fraud")
6131
CUSTOM_CARGO_FRAUD,
62-
@JsonProperty("custom_debt_churn_20d")
6332
CUSTOM_DEBT_CHURN_20D;
33+
34+
public String getEventName() {
35+
return this.name().toLowerCase();
36+
}
6437
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@Value
88
@Builder
99
public class PostFeedbackRequestBody {
10-
FeedbackEvent event;
10+
String event;
1111
Instant occurredAt;
1212
String accountId;
1313
String externalId;

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

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ void testRegisterPayment_whenEvalIsFalse() {
538538
@ValueSource(booleans = {true, false})
539539
@DisplayName("should be successful")
540540
@SneakyThrows
541-
void testRegisterFeedback_whenDataIsValid(boolean dryRun) {
541+
void testRegisterFeedback_whenUsingFeedbackEventEnum_andDataIsValid(boolean dryRun) {
542542
String token = TokenCreationFixture.createToken();
543543
String installationId = "installation-id";
544544
String sessionToken = "session-token";
@@ -555,7 +555,7 @@ void testRegisterFeedback_whenDataIsValid(boolean dryRun) {
555555
.externalId(externalId)
556556
.signupId(signupId)
557557
.accountId(accountId)
558-
.event(FeedbackEvent.ACCOUNT_TAKEOVER)
558+
.event(FeedbackEvent.ACCOUNT_TAKEOVER.getEventName())
559559
.occurredAt(timestamp)
560560
.build());
561561
mockServer.setDispatcher(dispatcher);
@@ -572,6 +572,44 @@ void testRegisterFeedback_whenDataIsValid(boolean dryRun) {
572572
dryRun);
573573
}
574574

575+
@ParameterizedTest
576+
@ValueSource(booleans = {true, false})
577+
@DisplayName("should be successful")
578+
@SneakyThrows
579+
void testRegisterFeedback_whenUsingFeedbackEventAsString_andDataIsValid(boolean dryRun) {
580+
String token = TokenCreationFixture.createToken();
581+
String installationId = "installation-id";
582+
String sessionToken = "session-token";
583+
String accountId = "account-id";
584+
String externalId = "external-id";
585+
String signupId = UUID.randomUUID().toString();
586+
Instant timestamp = Instant.now();
587+
588+
TokenAwareDispatcher dispatcher = new TokenAwareDispatcher(token, CLIENT_ID, CLIENT_SECRET);
589+
dispatcher.setExpectedFeedbackRequestBody(
590+
PostFeedbackRequestBody.builder()
591+
.installationId(installationId)
592+
.sessionToken(sessionToken)
593+
.externalId(externalId)
594+
.signupId(signupId)
595+
.accountId(accountId)
596+
.event("custom_feedback_type")
597+
.occurredAt(timestamp)
598+
.build());
599+
mockServer.setDispatcher(dispatcher);
600+
client.registerFeedback(
601+
"custom_feedback_type",
602+
timestamp,
603+
FeedbackIdentifiers.builder()
604+
.installationId(installationId)
605+
.sessionToken(sessionToken)
606+
.accountId(accountId)
607+
.externalId(externalId)
608+
.signupId(signupId)
609+
.build(),
610+
dryRun);
611+
}
612+
575613
@Test
576614
@DisplayName("should throw illegal argument exception with correct message")
577615
@SneakyThrows

0 commit comments

Comments
 (0)