Skip to content

Commit

Permalink
Knet Updates. Workflow updates (#421)
Browse files Browse the repository at this point in the history
  • Loading branch information
armando-rodriguez-cko authored Sep 19, 2024
1 parent 06be307 commit 1146bb2
Show file tree
Hide file tree
Showing 16 changed files with 177 additions and 17 deletions.
11 changes: 11 additions & 0 deletions src/CheckoutSdk/Payments/PaymentMethodsDetails.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Checkout.Payments
{
public class PaymentMethodsDetails
{
public string DisplayName { get; set; }

public string Type { get; set; }

public string Network { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Checkout.Common;
using Checkout.Tokens;

namespace Checkout.Payments.Previous.Request.Source.Apm
{
Expand All @@ -20,6 +21,12 @@ public class RequestKnetSource : AbstractRequestSource

public string Ptlf { get; set; }

public string TokenType { get; set; }

public ApplePayTokenData TokenData { get; set; }

public PaymentMethodsDetails PaymentMethodsDetails { get; set; }

public RequestKnetSource() : base(PaymentSourceType.KNet)
{
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Checkout.Common;
using Checkout.Tokens;

namespace Checkout.Payments.Request.Source.Apm
{
Expand All @@ -19,6 +20,12 @@ public class RequestKnetSource : AbstractRequestSource
public string CardToken { get; set; }

public string Ptlf { get; set; }

public string TokenType { get; set; }

public ApplePayTokenData TokenData { get; set; }

public PaymentMethodsDetails PaymentMethodsDetails { get; set; }

public RequestKnetSource() : base(PaymentSourceType.KNet)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ public class WorkflowActionInvocation
public bool? Succeeded { get; set; }

public bool? Final { get; set; }


[Obsolete("This property will be removed in the future, and should not be used. Use ResultDetails instead.", false)]
public IDictionary<string, object> Result { get; set; }

public IDictionary<string, object> ResultDetails { get; set; }
}
}
14 changes: 14 additions & 0 deletions src/CheckoutSdk/Workflows/Events/EventActionInvocation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Checkout.Common;
using Checkout.Workflows.Actions;

namespace Checkout.Workflows.Events
{
public class EventActionInvocation : Resource
{
public string WorkflowId { get; set; }

public string WorkflowActionId { get; set; }

public WorkflowActionStatus? Status { get; set; }
}
}
9 changes: 9 additions & 0 deletions src/CheckoutSdk/Workflows/Events/EventTypesRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Collections.Generic;

namespace Checkout.Workflows.Events
{
public class EventTypesRequest
{
public IList<string> EventTypes { get; set; }
}
}
8 changes: 6 additions & 2 deletions src/CheckoutSdk/Workflows/Events/GetEventResponse.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System.Collections.Generic;
using Checkout.Common;
using Checkout.Workflows.Actions.Response;
using System.Collections.Generic;

namespace Checkout.Workflows.Events
{
public class GetEventResponse : HttpMetadata
public class GetEventResponse : Resource
{
public string Id { get; set; }

Expand All @@ -15,5 +17,7 @@ public class GetEventResponse : HttpMetadata
public string Version { get; set; }

public IDictionary<string, object> Data { get; set; }

public IList<WorkflowActionInvocation> ActionInvocations { get; set; }
}
}
2 changes: 2 additions & 0 deletions src/CheckoutSdk/Workflows/IWorkflowsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Task<EmptyResponse> UpdateWorkflowCondition(string workflowId, string conditionI
WorkflowConditionRequest workflowConditionRequest);

Task<EmptyResponse> RemoveWorkflowCondition(string workflowId, string conditionId);

Task<EmptyResponse> TestWorkflow(string workflowId, EventTypesRequest eventTypesRequest);

Task<ItemsResponse<EventTypesResponse>> GetEventTypes();

Expand Down
10 changes: 9 additions & 1 deletion src/CheckoutSdk/Workflows/UpdateWorkflowRequest.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
namespace Checkout.Workflows
using Checkout.Workflows.Actions.Request;
using Checkout.Workflows.Conditions.Request;
using System.Collections.Generic;

namespace Checkout.Workflows
{
public class UpdateWorkflowRequest
{
public string Name { get; set; }

public bool? Active { get; set; }

public IList<WorkflowConditionRequest> Conditions { get; set; }

public IList<WorkflowActionRequest> Actions { get; set; }
}
}
10 changes: 9 additions & 1 deletion src/CheckoutSdk/Workflows/UpdateWorkflowResponse.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
namespace Checkout.Workflows
using Checkout.Workflows.Actions.Response;
using Checkout.Workflows.Conditions.Response;
using System.Collections.Generic;

namespace Checkout.Workflows
{
public class UpdateWorkflowResponse : HttpMetadata
{
public string Name { get; set; }

public bool? Active { get; set; }

public IList<WorkflowConditionResponse> Conditions { get; set; } = new List<WorkflowConditionResponse>();

public IList<WorkflowActionResponse> Actions { get; set; } = new List<WorkflowActionResponse>();
}
}
12 changes: 12 additions & 0 deletions src/CheckoutSdk/Workflows/WorkflowsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class WorkflowsClient : AbstractClient, IWorkflowsClient
private const string ReflowPath = "reflow";
private const string SubjectPath = "subject";
private const string WorkflowId = "workflowId";
private const string TestPath = "test";

public WorkflowsClient(IApiClient apiClient, CheckoutConfiguration configuration) :
base(apiClient, configuration, SdkAuthorizationType.SecretKeyOrOAuth)
Expand Down Expand Up @@ -120,6 +121,17 @@ public Task<EmptyResponse> RemoveWorkflowCondition(string workflowId, string con
SdkAuthorization());
}

public Task<EmptyResponse> TestWorkflow(string workflowId, EventTypesRequest eventTypesRequest)
{
CheckoutUtils.ValidateParams(
WorkflowId,
workflowId,
"eventTypesRequest",
eventTypesRequest);
return ApiClient.Post<EmptyResponse>(BuildPath(WorkflowsPath, workflowId, TestPath),
SdkAuthorization(), eventTypesRequest);
}

public Task<ItemsResponse<EventTypesResponse>> GetEventTypes()
{
return ApiClient.Get<ItemsResponse<EventTypesResponse>>(BuildPath(WorkflowsPath, EventTypesPath),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,14 +508,20 @@ private async Task ShouldMakeSofortPayment()
source.Type().ShouldBe(PaymentSourceType.Sofort);
}

[Fact(Skip = "unavaolable")]
[Fact]
private async Task ShouldMakeKnetPayment()
{
var paymentRequest = new PaymentRequest
{
Source = new RequestKnetSource
{
Language = "en",
PaymentMethodsDetails = new PaymentMethodsDetails
{
DisplayName = "name",
Type = "type",
Network = "card_network"
}
},
Currency = Currency.KWD,
Amount = 100,
Expand Down
13 changes: 11 additions & 2 deletions test/CheckoutSdkTest/Payments/RequestApmPaymentsIntegrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,16 @@ private async Task ShouldMakeKnetPayment()
{
var request = new PaymentRequest
{
Source = new RequestKnetSource { Language = "en", },
Source = new RequestKnetSource
{
Language = "en",
PaymentMethodsDetails = new PaymentMethodsDetails
{
DisplayName = "name",
Type = "type",
Network = "card_network"
}
},
Currency = Currency.KWD,
Amount = 100,
Reference = Guid.NewGuid().ToString(),
Expand All @@ -377,7 +386,7 @@ private async Task ShouldMakeKnetPayment()
};

await CheckErrorItem(async () => await DefaultApi.PaymentsClient().RequestPayment(request),
ApmServiceUnavailable);
PayeeNotOnboarded);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public async Task ShouldGetActionInvocations()
actionInvocationsActionInvocation.Succeeded.ShouldNotBeNull();
actionInvocationsActionInvocation.Timestamp.ShouldNotBeNull();
actionInvocationsActionInvocation.InvocationId.ShouldNotBeNullOrEmpty();
actionInvocationsActionInvocation.Result.ShouldNotBeEmpty();
actionInvocationsActionInvocation.ResultDetails.ShouldNotBeEmpty();
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions test/CheckoutSdkTest/Workflows/WorkflowsClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,24 @@ public async Task ShouldFailRemoveWorkflowConditions_InvalidParams()
ex.Message.ShouldBe("workflowId cannot be blank");
}
}

[Fact]
public async Task ShouldTestWorkflow()
{
EventTypesRequest eventTypesRequest = new EventTypesRequest();
EmptyResponse createWorkflowResponse = new EmptyResponse();

_apiClient.Setup(apiClient =>
apiClient.Post<EmptyResponse>("workflows/workflow_id/test", _authorization,
eventTypesRequest, CancellationToken.None, null))
.ReturnsAsync(() => createWorkflowResponse);

IWorkflowsClient workflowsClient = new WorkflowsClient(_apiClient.Object, _configuration.Object);

var response = await workflowsClient.TestWorkflow("workflow_id", eventTypesRequest);

response.ShouldNotBeNull();
}

[Fact]
public async Task ShouldGetEventTypes()
Expand Down
58 changes: 50 additions & 8 deletions test/CheckoutSdkTest/Workflows/WorkflowsIntegrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Checkout.Workflows.Conditions;
using Checkout.Workflows.Conditions.Request;
using Checkout.Workflows.Conditions.Response;
using Checkout.Workflows.Events;
using Shouldly;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -20,7 +21,8 @@ public async Task ShouldCreateAndGetWorkflows()
{
var createdWorkflow = await CreateWorkflow();

GetWorkflowResponse getWorkflowResponse = await DefaultApi.WorkflowsClient().GetWorkflow(createdWorkflow.Id);
GetWorkflowResponse getWorkflowResponse =
await DefaultApi.WorkflowsClient().GetWorkflow(createdWorkflow.Id);

getWorkflowResponse.ShouldNotBeNull();
getWorkflowResponse.Id.ShouldNotBeNullOrEmpty();
Expand Down Expand Up @@ -52,7 +54,7 @@ public async Task ShouldCreateAndGetWorkflows()
eventCondition.Events.ShouldNotBeEmpty();
}
else if (workflowConditionResponse is ProcessingChannelWorkflowConditionResponse
processingChannelCondition)
processingChannelCondition)
{
processingChannelCondition.Type.ShouldBe(WorkflowConditionType.ProcessingChannel);
processingChannelCondition.ProcessingChannels.ShouldNotBeEmpty();
Expand Down Expand Up @@ -81,7 +83,7 @@ public async Task ShouldCreateAndUpdateWorkflow()
{
var workflow = await CreateWorkflow();

UpdateWorkflowRequest request = new UpdateWorkflowRequest {Name = "testing_2", Active = false};
UpdateWorkflowRequest request = new UpdateWorkflowRequest { Name = "testing_2", Active = false };

UpdateWorkflowResponse updateWorkflowResponse =
await DefaultApi.WorkflowsClient().UpdateWorkflow(workflow.Id, request);
Expand All @@ -102,7 +104,8 @@ public async Task ShouldUpdateWorkflowAction()
createdWorkflow.ShouldNotBeNull();
createdWorkflow.Id.ShouldNotBeNull();

GetWorkflowResponse getWorkflowResponse = await DefaultApi.WorkflowsClient().GetWorkflow(createdWorkflow.Id);
GetWorkflowResponse getWorkflowResponse =
await DefaultApi.WorkflowsClient().GetWorkflow(createdWorkflow.Id);

getWorkflowResponse.ShouldNotBeNull();
getWorkflowResponse.Id.ShouldNotBeNullOrEmpty();
Expand All @@ -116,10 +119,11 @@ public async Task ShouldUpdateWorkflowAction()
{
Url = "https://google.com/fail/fake",
Headers = new Dictionary<string, string>(),
Signature = new WebhookSignature {Key = "8V8x0dLK%AyD*DNS8JJr", Method = "HMACSHA256"}
Signature = new WebhookSignature { Key = "8V8x0dLK%AyD*DNS8JJr", Method = "HMACSHA256" }
};

var emptyResponse = await DefaultApi.WorkflowsClient().UpdateWorkflowAction(getWorkflowResponse.Id, actionId, updateAction);
var emptyResponse = await DefaultApi.WorkflowsClient()
.UpdateWorkflowAction(getWorkflowResponse.Id, actionId, updateAction);
emptyResponse.ShouldNotBeNull();
emptyResponse.HttpStatusCode.ShouldNotBeNull();
emptyResponse.ResponseHeaders.ShouldNotBeNull();
Expand All @@ -142,7 +146,8 @@ public async Task ShouldUpdateWorkflowCondition()
createdWorkflow.ShouldNotBeNull();
createdWorkflow.Id.ShouldNotBeNull();

GetWorkflowResponse getWorkflowResponse = await DefaultApi.WorkflowsClient().GetWorkflow(createdWorkflow.Id);
GetWorkflowResponse getWorkflowResponse =
await DefaultApi.WorkflowsClient().GetWorkflow(createdWorkflow.Id);

getWorkflowResponse.ShouldNotBeNull();
getWorkflowResponse.Id.ShouldNotBeNullOrEmpty();
Expand Down Expand Up @@ -191,7 +196,8 @@ public async Task ShouldUpdateWorkflowCondition()
await DefaultApi.WorkflowsClient().UpdateWorkflowCondition(getWorkflowResponse.Id,
eventWorkflowConditionResponse.Id, updateEventCondition);

GetWorkflowResponse getWorkflowResponse2 = await DefaultApi.WorkflowsClient().GetWorkflow(createdWorkflow.Id);
GetWorkflowResponse getWorkflowResponse2 =
await DefaultApi.WorkflowsClient().GetWorkflow(createdWorkflow.Id);

getWorkflowResponse2.ShouldNotBeNull();
getWorkflowResponse2.Conditions.ShouldNotBeNull();
Expand All @@ -204,5 +210,41 @@ await DefaultApi.WorkflowsClient().UpdateWorkflowCondition(getWorkflowResponse.I
updatedEventConditionResponse.Id.ShouldNotBeNull();
updatedEventConditionResponse.Type.ShouldNotBeNull();
}

[Fact(Skip = "unstable")]
public async Task ShouldCreateAndTestWorkflows()
{
var createdWorkflow = await CreateWorkflow();

var eventTypesRequest = new EventTypesRequest
{
EventTypes = new List<string>
{
"payment_approved",
"payment_declined",
"card_verification_declined",
"card_verified",
"payment_authorization_incremented",
"payment_authorization_increment_declined",
"payment_capture_declined",
"payment_captured",
"payment_refund_declined",
"payment_refunded",
"payment_void_declined",
"payment_voided",
"dispute_canceled",
"dispute_evidence_required",
"dispute_expired",
"dispute_lost",
"dispute_resolved",
"dispute_won"
}
};

EmptyResponse getWorkflowResponse =
await DefaultApi.WorkflowsClient().TestWorkflow(createdWorkflow.Id, eventTypesRequest);

getWorkflowResponse.ShouldNotBeNull();
}
}
}

0 comments on commit 1146bb2

Please sign in to comment.