Skip to content

Commit

Permalink
Merge pull request #96 from sreejithKExalture/verification_api_impl
Browse files Browse the repository at this point in the history
Support of Verification API
  • Loading branch information
viaskal-sift authored Sep 1, 2023
2 parents 09c2f3a + 7178cbd commit a2dde04
Show file tree
Hide file tree
Showing 17 changed files with 843 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/main/java/com/siftscience/SiftClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import com.siftscience.model.CreateMerchantFieldSet;
import com.siftscience.model.UpdateMerchantFieldSet;
import com.siftscience.model.GetMerchantsFieldSet;
import com.siftscience.model.VerificationSendFieldSet;
import com.siftscience.model.VerificationResendFieldSet;
import com.siftscience.model.VerificationCheckFieldSet;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;

Expand Down Expand Up @@ -142,6 +145,21 @@ public UpdateMerchantRequest buildRequest(UpdateMerchantFieldSet fields, String
return new UpdateMerchantRequest(baseUrl, getAccountId(), okClient, fields, merchantId);
}

public VerificationSendRequest buildRequest(VerificationSendFieldSet fields) {
setupApiKey(fields);
return new VerificationSendRequest(baseUrl, getAccountId(), okClient, fields);
}

public VerificationResendRequest buildRequest(VerificationResendFieldSet fields) {
setupApiKey(fields);
return new VerificationResendRequest(baseUrl, getAccountId(), okClient, fields);
}

public VerificationCheckRequest buildRequest(VerificationCheckFieldSet fields) {
setupApiKey(fields);
return new VerificationCheckRequest(baseUrl, getAccountId(), okClient, fields);
}

private void setupApiKey(FieldSet fields) {
fields.setApiKey(getApiKey());
}
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/com/siftscience/VerificationCheckRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.siftscience;

import com.siftscience.model.VerificationCheckFieldSet;
import okhttp3.OkHttpClient;
import okhttp3.HttpUrl;
import okhttp3.Response;
import okhttp3.Request;
import okhttp3.Credentials;
import okhttp3.MediaType;
import okhttp3.RequestBody;

import java.io.IOException;


/**
* The check call is used for verifying the OTP provided by the end user to Sift.
* Check out https://sift.com/developers/docs/java/verification-api/check for more information on our request/response structure.
*/
public class VerificationCheckRequest extends SiftRequest<VerificationCheckResponse> {

VerificationCheckRequest(HttpUrl baseUrl, String accountId, OkHttpClient okClient, VerificationCheckFieldSet fields) {
super(baseUrl, accountId, okClient, fields);
}

@Override
protected HttpUrl path(HttpUrl baseUrl) {
return baseUrl.newBuilder()
.addPathSegment("v1")
.addPathSegment("verification")
.addPathSegment("check").build();
}

@Override
VerificationCheckResponse buildResponse(Response response, FieldSet requestFields) throws IOException {
return new VerificationCheckResponse(response, requestFields);
}

@Override
protected void modifyRequestBuilder(Request.Builder builder) {
super.modifyRequestBuilder(builder);
builder.header("Authorization", Credentials.basic(fieldSet.getApiKey(), "")).get();
builder.post(RequestBody.create(MediaType.parse("application/json"), fieldSet.toJson()));
}
}
17 changes: 17 additions & 0 deletions src/main/java/com/siftscience/VerificationCheckResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.siftscience;

import com.siftscience.model.VerificationCheckResponseBody;
import okhttp3.Response;

import java.io.IOException;

public class VerificationCheckResponse extends SiftResponse<VerificationCheckResponseBody> {
VerificationCheckResponse(Response okResponse, FieldSet requestBody) throws IOException {
super(okResponse, requestBody);
}

@Override
public void populateBodyFromJson(String jsonBody) {
body = VerificationCheckResponseBody.fromJson(jsonBody);
}
}
43 changes: 43 additions & 0 deletions src/main/java/com/siftscience/VerificationResendRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.siftscience;

import com.siftscience.model.VerificationResendFieldSet;
import okhttp3.OkHttpClient;
import okhttp3.HttpUrl;
import okhttp3.Response;
import okhttp3.Request;
import okhttp3.Credentials;
import okhttp3.MediaType;
import okhttp3.RequestBody;

import java.io.IOException;

/**
* The resend call generates a new OTP and sends it to the original recipient with the same settings.
* Check out https://sift.com/developers/docs/java/verification-api/resend for more information on our request/response structuree.
* */
public class VerificationResendRequest extends SiftRequest<VerificationResendResponse> {

VerificationResendRequest(HttpUrl baseUrl, String accountId, OkHttpClient okClient, VerificationResendFieldSet fields) {
super(baseUrl, accountId, okClient, fields);
}

@Override
protected HttpUrl path(HttpUrl baseUrl) {
return baseUrl.newBuilder()
.addPathSegment("v1")
.addPathSegment("verification")
.addPathSegment("resend").build();
}

@Override
VerificationResendResponse buildResponse(Response response, FieldSet requestFields) throws IOException {
return new VerificationResendResponse(response, requestFields);
}

@Override
protected void modifyRequestBuilder(Request.Builder builder) {
super.modifyRequestBuilder(builder);
builder.header("Authorization", Credentials.basic(fieldSet.getApiKey(), "")).get();
builder.post(RequestBody.create(MediaType.parse("application/json"), fieldSet.toJson()));
}
}
17 changes: 17 additions & 0 deletions src/main/java/com/siftscience/VerificationResendResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.siftscience;

import com.siftscience.model.VerificationResendResponseBody;
import okhttp3.Response;

import java.io.IOException;

public class VerificationResendResponse extends SiftResponse<VerificationResendResponseBody> {
VerificationResendResponse(Response okResponse, FieldSet requestBody) throws IOException {
super(okResponse, requestBody);
}

@Override
public void populateBodyFromJson(String jsonBody) {
body = VerificationResendResponseBody.fromJson(jsonBody);
}
}
44 changes: 44 additions & 0 deletions src/main/java/com/siftscience/VerificationSendRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.siftscience;

import com.siftscience.model.VerificationSendFieldSet;
import okhttp3.OkHttpClient;
import okhttp3.HttpUrl;
import okhttp3.Response;
import okhttp3.Request;
import okhttp3.Credentials;
import okhttp3.MediaType;
import okhttp3.RequestBody;

import java.io.IOException;

/**
*The send call triggers the generation of an OTP code that is stored by Sift
* and email/sms the code to the user.
* Check out https://sift.com/developers/docs/java/verification-api/send for more information on our request/response structure.
* */
public class VerificationSendRequest extends SiftRequest<VerificationSendResponse> {

VerificationSendRequest(HttpUrl baseUrl, String accountId, OkHttpClient okClient, VerificationSendFieldSet fields) {
super(baseUrl, accountId, okClient, fields);
}

@Override
protected HttpUrl path(HttpUrl baseUrl) {
return baseUrl.newBuilder()
.addPathSegment("v1")
.addPathSegment("verification")
.addPathSegment("send").build();
}

@Override
VerificationSendResponse buildResponse(Response response, FieldSet requestFields) throws IOException {
return new VerificationSendResponse(response, requestFields);
}

@Override
protected void modifyRequestBuilder(Request.Builder builder) {
super.modifyRequestBuilder(builder);
builder.header("Authorization", Credentials.basic(fieldSet.getApiKey(), "")).get();
builder.post(RequestBody.create(MediaType.parse("application/json"), fieldSet.toJson()));
}
}
17 changes: 17 additions & 0 deletions src/main/java/com/siftscience/VerificationSendResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.siftscience;

import com.siftscience.model.VerificationSendResponseBody;
import okhttp3.Response;

import java.io.IOException;

public class VerificationSendResponse extends SiftResponse<VerificationSendResponseBody> {
VerificationSendResponse(Response okResponse, FieldSet requestBody) throws IOException {
super(okResponse, requestBody);
}

@Override
public void populateBodyFromJson(String jsonBody) {
body = VerificationSendResponseBody.fromJson(jsonBody);
}
}
70 changes: 70 additions & 0 deletions src/main/java/com/siftscience/model/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.siftscience.model;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class Event {

@Expose @SerializedName("$session_id") private String sessionId;
@Expose @SerializedName("$verified_event") private String verifiedEvent;
@Expose @SerializedName("$reason") private String reason;
@Expose @SerializedName("$ip") private String ip;

@Expose @SerializedName("$browser") private Browser browser;

@Expose @SerializedName("$app") private App app;

public String getSessionId() {
return sessionId;
}

public Event setSessionId(String sessionId) {
this.sessionId = sessionId;
return this;
}

public String getVerifiedEvent() {
return verifiedEvent;
}

public Event setVerifiedEvent(String verifiedEvent) {
this.verifiedEvent = verifiedEvent;
return this;
}

public String getReason() {
return reason;
}

public Event setReason(String reason) {
this.reason = reason;
return this;
}

public String getIp() {
return ip;
}

public Event setIp(String ip) {
this.ip = ip;
return this;
}

public Browser getBrowser() {
return browser;
}

public Event setBrowser(Browser browser) {
this.browser = browser;
return this;
}

public App getApp() {
return app;
}

public Event setApp(App app) {
this.app = app;
return this;
}
}
52 changes: 52 additions & 0 deletions src/main/java/com/siftscience/model/VerificationCheckFieldSet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.siftscience.model;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import com.siftscience.FieldSet;

public class VerificationCheckFieldSet extends FieldSet<VerificationCheckFieldSet> {

public static VerificationCheckFieldSet fromJson(String json) {
return gson.fromJson(json, VerificationCheckFieldSet.class);
}
@Expose @SerializedName(USER_ID) private String userId;
@Expose @SerializedName("$code") private String code;
@Expose @SerializedName("$verified_event") private String verifiedEvent;
@Expose @SerializedName("$verified_entity_id") private String verifiedEntityId;

public String getUserId() {
return userId;
}

public VerificationCheckFieldSet setUserId(String userId) {
this.userId = userId;
return this;
}

public String getVerifiedEvent() {
return verifiedEvent;
}

public VerificationCheckFieldSet setVerifiedEvent(String verifiedEvent) {
this.verifiedEvent = verifiedEvent;
return this;
}

public String getVerifiedEntityId() {
return verifiedEntityId;
}

public VerificationCheckFieldSet setVerifiedEntityId(String verifiedEntityId) {
this.verifiedEntityId = verifiedEntityId;
return this;
}

public String getCode() {
return code;
}

public VerificationCheckFieldSet setCode(String code) {
this.code = code;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.siftscience.model;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class VerificationCheckResponseBody extends BaseResponseBody<VerificationCheckResponseBody> {

@Expose @SerializedName("checked_at") private Long checkedAt;

public static VerificationCheckResponseBody fromJson(String json) {
return gson.fromJson(json, VerificationCheckResponseBody.class);
}

public Long getCheckedAt() {
return checkedAt;
}

public VerificationCheckResponseBody setCheckedAt(Long checkedAt) {
this.checkedAt = checkedAt;
return this;
}
}

Loading

0 comments on commit a2dde04

Please sign in to comment.