Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Knet Updates. Workflow updates #436

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/main/java/com/checkout/payments/PaymentMethodsDetails.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.checkout.payments;

import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

@Data
@Builder
@AllArgsConstructor
public final class PaymentMethodsDetails {

@SerializedName("display_name")
private String displayName;

private String type;

private String network;

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.checkout.payments.previous.request.source.apm;

import com.checkout.common.PaymentSourceType;
import com.checkout.payments.PaymentMethodsDetails;
import com.checkout.payments.previous.request.source.AbstractRequestSource;
import com.checkout.tokens.ApplePayTokenData;
import com.google.gson.annotations.SerializedName;
import lombok.Builder;
import lombok.EqualsAndHashCode;
Expand Down Expand Up @@ -37,15 +39,27 @@ public final class RequestKnetSource extends AbstractRequestSource {

private String ptlf;

@SerializedName("token_type")
private String tokenType;

@SerializedName("token_data")
private ApplePayTokenData tokenData;

@SerializedName("payment_method_details")
private PaymentMethodsDetails paymentMethodsDetails;

@Builder
private RequestKnetSource(final String language,
final String userDefinedField1,
final String userDefinedField2,
final String userDefinedField3,
final String userDefinedField4,
final String userDefinedField5,
final String cardToken,
final String ptlf) {
final String userDefinedField1,
final String userDefinedField2,
final String userDefinedField3,
final String userDefinedField4,
final String userDefinedField5,
final String cardToken,
final String ptlf,
final String tokenType,
final ApplePayTokenData tokenData,
final PaymentMethodsDetails paymentMethodsDetails) {
super(PaymentSourceType.KNET);
this.language = language;
this.userDefinedField1 = userDefinedField1;
Expand All @@ -55,6 +69,9 @@ private RequestKnetSource(final String language,
this.userDefinedField5 = userDefinedField5;
this.cardToken = cardToken;
this.ptlf = ptlf;
this.tokenType = tokenType;
this.tokenData = tokenData;
this.paymentMethodsDetails = paymentMethodsDetails;
}

public RequestKnetSource() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.checkout.payments.request.source.apm;

import com.checkout.common.PaymentSourceType;
import com.checkout.payments.PaymentMethodsDetails;
import com.checkout.payments.request.source.AbstractRequestSource;
import com.checkout.tokens.ApplePayTokenData;
import com.google.gson.annotations.SerializedName;
import lombok.Builder;
import lombok.EqualsAndHashCode;
Expand Down Expand Up @@ -37,6 +39,15 @@ public final class RequestKnetSource extends AbstractRequestSource {

private String ptlf;

@SerializedName("token_type")
private String tokenType;

@SerializedName("token_data")
private ApplePayTokenData tokenData;

@SerializedName("payment_method_details")
private PaymentMethodsDetails paymentMethodsDetails;

@Builder
private RequestKnetSource(final String language,
final String userDefinedField1,
Expand All @@ -45,7 +56,10 @@ private RequestKnetSource(final String language,
final String userDefinedField4,
final String userDefinedField5,
final String cardToken,
final String ptlf) {
final String ptlf,
final String tokenType,
final ApplePayTokenData tokenData,
final PaymentMethodsDetails paymentMethodsDetails) {
super(PaymentSourceType.KNET);
this.language = language;
this.userDefinedField1 = userDefinedField1;
Expand All @@ -55,6 +69,9 @@ private RequestKnetSource(final String language,
this.userDefinedField5 = userDefinedField5;
this.cardToken = cardToken;
this.ptlf = ptlf;
this.tokenType = tokenType;
this.tokenData = tokenData;
this.paymentMethodsDetails = paymentMethodsDetails;
}

public RequestKnetSource() {
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/checkout/workflows/UpdateWorkflowRequest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.checkout.workflows;

import com.checkout.workflows.actions.request.WorkflowActionRequest;
import com.checkout.workflows.conditions.request.WorkflowConditionRequest;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
@Builder
@AllArgsConstructor
Expand All @@ -13,4 +18,10 @@ public final class UpdateWorkflowRequest {

private Boolean active;

@Builder.Default
private List<WorkflowConditionRequest> conditions = new ArrayList<>();

@Builder.Default
private List<WorkflowActionRequest> actions = new ArrayList<>();

}
17 changes: 15 additions & 2 deletions src/main/java/com/checkout/workflows/UpdateWorkflowResponse.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
package com.checkout.workflows;

import com.checkout.HttpMetadata;
import com.checkout.common.Resource;
import com.checkout.workflows.actions.response.WorkflowActionResponse;
import com.checkout.workflows.conditions.response.WorkflowConditionResponse;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import java.util.ArrayList;
import java.util.List;

@Data
@EqualsAndHashCode(callSuper = true)
public final class UpdateWorkflowResponse extends HttpMetadata {
@ToString(callSuper = true)
public final class UpdateWorkflowResponse extends Resource {

private String id;

private String name;

private Boolean active;

private List<WorkflowConditionResponse> conditions = new ArrayList<>();

private List<WorkflowActionResponse> actions = new ArrayList<>();

}
3 changes: 3 additions & 0 deletions src/main/java/com/checkout/workflows/WorkflowsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.checkout.workflows.actions.request.WorkflowActionRequest;
import com.checkout.workflows.actions.response.WorkflowActionInvocationsResponse;
import com.checkout.workflows.conditions.request.WorkflowConditionRequest;
import com.checkout.workflows.events.EventTypesRequest;
import com.checkout.workflows.events.GetEventResponse;
import com.checkout.workflows.events.SubjectEventsResponse;
import com.checkout.workflows.events.WorkflowEventTypes;
Expand Down Expand Up @@ -38,6 +39,8 @@ public interface WorkflowsClient {

CompletableFuture<EmptyResponse> removeWorkflowCondition(String workflowId, String conditionId);

CompletableFuture<EmptyResponse> testWorkflow(String workflowId, EventTypesRequest eventTypesRequest);

CompletableFuture<ItemsResponse<WorkflowEventTypes>> getEventTypes();

CompletableFuture<GetEventResponse> getEvent(String eventId);
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/checkout/workflows/WorkflowsClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.checkout.workflows.actions.request.WorkflowActionRequest;
import com.checkout.workflows.actions.response.WorkflowActionInvocationsResponse;
import com.checkout.workflows.conditions.request.WorkflowConditionRequest;
import com.checkout.workflows.events.EventTypesRequest;
import com.checkout.workflows.events.GetEventResponse;
import com.checkout.workflows.events.SubjectEventsResponse;
import com.checkout.workflows.events.WorkflowEventTypes;
Expand All @@ -33,6 +34,7 @@ public class WorkflowsClientImpl extends AbstractClient implements WorkflowsClie
private static final String REFLOW_PATH = "reflow";
private static final String SUBJECT_PATH = "subject";
private static final String WORKFLOW_ID = "workflowId";
private static final String TEST_PATH = "test";

private static final Type WORKFLOWS_EVENT_TYPES_TYPE = new TypeToken<ItemsResponse<WorkflowEventTypes>>() {
}.getType();
Expand Down Expand Up @@ -151,6 +153,17 @@ public CompletableFuture<EmptyResponse> removeWorkflowCondition(final String wor
sdkAuthorization());
}

@Override
public CompletableFuture<EmptyResponse> testWorkflow(String workflowId, EventTypesRequest eventTypesRequest) {
validateParams(WORKFLOW_ID, workflowId, "eventTypesRequest", eventTypesRequest);
return apiClient.postAsync(
buildPath(WORKFLOWS_PATH, workflowId, TEST_PATH),
sdkAuthorization(),
EmptyResponse.class,
eventTypesRequest,
null);
}

@Override
public CompletableFuture<ItemsResponse<WorkflowEventTypes>> getEventTypes() {
return apiClient.getAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ public final class WorkflowActionInvocation {
@SerializedName("final")
private Boolean finalAttempt;

@SerializedName("result_details")
private Map<String, Object> result;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.checkout.workflows.events;

import com.checkout.common.Resource;
import com.checkout.workflows.actions.WorkflowActionStatus;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

@Data
@EqualsAndHashCode(callSuper = true)
github-advanced-security[bot] marked this conversation as resolved.
Dismissed
Show resolved Hide resolved
@ToString(callSuper = true)
public final class EventActionInvocation extends Resource {

@SerializedName("workflow_id")
private String workflowId;

@SerializedName("workflow_action_id")
private String workflowActionId;

private WorkflowActionStatus status;
}
17 changes: 17 additions & 0 deletions src/main/java/com/checkout/workflows/events/EventTypesRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.checkout.workflows.events;

import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

import java.util.List;

@Data
@Builder
@AllArgsConstructor
public final class EventTypesRequest {

@SerializedName("event_types")
private List<String> eventTypes;
}
12 changes: 10 additions & 2 deletions src/main/java/com/checkout/workflows/events/GetEventResponse.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package com.checkout.workflows.events;

import com.checkout.HttpMetadata;
import com.checkout.common.Resource;
import com.checkout.workflows.actions.response.WorkflowActionInvocation;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import java.util.List;
import java.util.Map;

@Data
@EqualsAndHashCode(callSuper = true)
public final class GetEventResponse extends HttpMetadata {
@ToString(callSuper = true)
public final class GetEventResponse extends Resource {

private String id;

Expand All @@ -22,4 +27,7 @@ public final class GetEventResponse extends HttpMetadata {

private Map<String, Object> data;

@SerializedName("action_invocations")
private List<WorkflowActionInvocation> actionInvocations;

}
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,11 @@ void shouldMakeKnetPayment() {
final PaymentRequest paymentRequest = PaymentRequest.builder()
.source(RequestKnetSource.builder()
.language("en")
.paymentMethodsDetails(PaymentMethodsDetails.builder()
.displayName("name")
.type("type")
.network("card_network")
.build())
.build())
.currency(Currency.KWD)
.amount(1000L)
Expand All @@ -373,7 +378,7 @@ void shouldMakeKnetPayment() {
.failureUrl("https://testing.checkout.com/failure")
.build();

checkErrorItem(() -> paymentsClient.requestPayment(paymentRequest), APM_SERVICE_UNAVAILABLE);
checkErrorItem(() -> paymentsClient.requestPayment(paymentRequest), PAYEE_NOT_ONBOARDED);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.checkout.common.CountryCode;
import com.checkout.common.Currency;
import com.checkout.common.PaymentSourceType;
import com.checkout.payments.PaymentMethodsDetails;
import com.checkout.payments.previous.request.PaymentRequest;
import com.checkout.payments.previous.request.source.apm.IntegrationType;
import com.checkout.payments.previous.request.source.apm.RequestAlipaySource;
Expand Down Expand Up @@ -278,12 +279,17 @@ void shouldMakeSofortPayment() {
assertEquals(PaymentSourceType.SOFORT, paymentDetails.getSource().getType());
}

@Disabled("not available")
//@Disabled("not available")
@Test
void shouldMakeKnetPayment() {
final PaymentRequest paymentRequest = PaymentRequest.builder()
.source(RequestKnetSource.builder()
.language("en")
.paymentMethodsDetails(PaymentMethodsDetails.builder()
.displayName("name")
.type("type")
.network("card_network")
.build())
.build())
.currency(Currency.KWD)
.amount(1000L)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
import com.checkout.workflows.actions.request.WorkflowActionRequest;
import com.checkout.workflows.actions.response.WorkflowActionInvocationsResponse;
import com.checkout.workflows.conditions.request.WorkflowConditionRequest;
import com.checkout.workflows.events.EventTypesRequest;
import com.checkout.workflows.events.GetEventResponse;
import com.checkout.workflows.events.SubjectEventsResponse;
import com.checkout.workflows.events.WorkflowEventTypes;
import com.checkout.workflows.reflow.ReflowBySubjectsRequest;
import com.checkout.workflows.reflow.ReflowResponse;
import com.google.gson.reflect.TypeToken;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
Expand Down Expand Up @@ -356,6 +356,25 @@ void shouldRemoveWorkflowCondition() throws ExecutionException, InterruptedExcep

}

@Test
void shouldTestWorkflow() throws ExecutionException, InterruptedException {

when(sdkCredentials.getAuthorization(SdkAuthorizationType.SECRET_KEY_OR_OAUTH)).thenReturn(authorization);
when(configuration.getSdkCredentials()).thenReturn(sdkCredentials);

final EmptyResponse response = Mockito.mock(EmptyResponse.class);
final EventTypesRequest eventTypesRequest = Mockito.mock(EventTypesRequest.class);

when(apiClient.postAsync("workflows/workflow_id/test", authorization, EmptyResponse.class, eventTypesRequest, null))
.thenReturn(CompletableFuture.completedFuture(response));

final CompletableFuture<EmptyResponse> future = workflowsClient.testWorkflow("workflow_id", eventTypesRequest);

assertNotNull(future.get());
assertEquals(response, future.get());

}

@Test
void shouldFailUpdateWorkflowCondition_invalidParams() {
try {
Expand Down
Loading
Loading