Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Checkout.Issuing.ControlProfiles.Requests
{
public class ControlProfileRequest
{
public string Name { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Checkout.Common;
using System;

namespace Checkout.Issuing.ControlProfiles.Responses
{
public class ControlProfileResponse : Resource
{
public string Id { get; set; }

public string Name { get; set; }

public DateTime? CreatedDate { get; set; }

public DateTime? LastModifiedDate { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Collections.Generic;

namespace Checkout.Issuing.ControlProfiles.Responses
{
public class ControlProfilesResponse : HttpMetadata
{
public IList<ControlProfileResponse> ControlProfiles { get; set; }
}
}
36 changes: 36 additions & 0 deletions src/CheckoutSdk/Issuing/IIssuingClient.ControlProfiles.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Checkout.Common;
using Checkout.Issuing.ControlProfiles.Requests;
using Checkout.Issuing.ControlProfiles.Responses;
using Checkout.Payments;
using System.Threading;
using System.Threading.Tasks;

namespace Checkout.Issuing
{
public partial interface IIssuingClient
{
Task<ControlProfileResponse> CreateControlProfile(ControlProfileRequest controlProfileRequest,
CancellationToken cancellationToken = default);

Task<ControlProfilesResponse> GetAllControlProfiles(string targetId,
CancellationToken cancellationToken = default);

Task<ControlProfileResponse> GetControlProfileDetails(string controlProfileId,
CancellationToken cancellationToken = default);

Task<ControlProfileResponse> UpdateControlProfile(string controlProfileId,
ControlProfileRequest controlProfileRequest,
CancellationToken cancellationToken = default);

Task<VoidResponse> RemoveControlProfile(string controlProfileId,
CancellationToken cancellationToken = default);

Task<Resource> AddTargetToControlProfile(string controlProfileId,
string targetId,
CancellationToken cancellationToken = default);

Task<Resource> RemoveTargetFromControlProfile(string controlProfileId,
string targetId,
CancellationToken cancellationToken = default);
}
}
3 changes: 3 additions & 0 deletions src/CheckoutSdk/Issuing/IssuingClient.Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public partial class IssuingClient : AbstractClient, IIssuingClient
private const string PresentmentsPath = "presentments";
private const string ReversalsPath = "reversals";
private const string TransactionsPath = "transactions";
private const string ControlProfilesPath = "control-profiles";
private const string AddPath = "add";
private const string RemovePath = "remove";

public IssuingClient(IApiClient apiClient, CheckoutConfiguration configuration) :
base(apiClient, configuration, SdkAuthorizationType.OAuth)
Expand Down
90 changes: 90 additions & 0 deletions src/CheckoutSdk/Issuing/IssuingClient.ControlProfiles.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using Checkout.Common;
using Checkout.Issuing.ControlProfiles.Requests;
using Checkout.Issuing.ControlProfiles.Responses;
using Checkout.Payments;
using System.Threading;
using System.Threading.Tasks;

namespace Checkout.Issuing
{
public partial class IssuingClient
{
public Task<ControlProfileResponse> CreateControlProfile(ControlProfileRequest controlProfileRequest, CancellationToken cancellationToken = default)
{
CheckoutUtils.ValidateParams("controlProfileRequest", controlProfileRequest);
return ApiClient.Post<ControlProfileResponse>(
BuildPath(IssuingPath, ControlsPath, ControlProfilesPath),
SdkAuthorization(),
controlProfileRequest,
cancellationToken
);
}

public Task<ControlProfilesResponse> GetAllControlProfiles(string targetId, CancellationToken cancellationToken = default)
{
CheckoutUtils.ValidateParams("targetId", targetId);
return ApiClient.Get<ControlProfilesResponse>(
BuildPath(IssuingPath, ControlsPath, ControlProfilesPath),
SdkAuthorization(),
cancellationToken
);
}

public Task<ControlProfileResponse> GetControlProfileDetails(string controlProfileId, CancellationToken cancellationToken = default)
{
CheckoutUtils.ValidateParams("controlProfileId", controlProfileId);
return ApiClient.Get<ControlProfileResponse>(
BuildPath(IssuingPath, ControlsPath, ControlProfilesPath, controlProfileId),
SdkAuthorization(),
cancellationToken
);
}

public Task<ControlProfileResponse> UpdateControlProfile(string controlProfileId, ControlProfileRequest controlProfileRequest,
CancellationToken cancellationToken = default)
{
CheckoutUtils.ValidateParams("controlProfileId", controlProfileId, "controlProfileRequest", controlProfileRequest);
return ApiClient.Patch<ControlProfileResponse>(
BuildPath(IssuingPath, ControlsPath, ControlProfilesPath, controlProfileId),
SdkAuthorization(),
controlProfileRequest,
cancellationToken
);
}

public Task<VoidResponse> RemoveControlProfile(string controlProfileId, CancellationToken cancellationToken = default)
{
CheckoutUtils.ValidateParams("controlProfileId", controlProfileId);
return ApiClient.Delete<VoidResponse>(
BuildPath(IssuingPath, ControlsPath, ControlProfilesPath, controlProfileId),
SdkAuthorization(),
cancellationToken
);
}

public Task<Resource> AddTargetToControlProfile(string controlProfileId, string targetId, CancellationToken cancellationToken = default)
{
CheckoutUtils.ValidateParams("controlProfileId", controlProfileId, "targetId", targetId);
return ApiClient.Post<Resource>(
BuildPath(IssuingPath, ControlsPath, ControlProfilesPath, controlProfileId, AddPath, targetId),
SdkAuthorization(),
null,
cancellationToken,
null
);
}

public Task<Resource> RemoveTargetFromControlProfile(string controlProfileId, string targetId,
CancellationToken cancellationToken = default)
{
CheckoutUtils.ValidateParams("controlProfileId", controlProfileId, "targetId", targetId);
return ApiClient.Post<Resource>(
BuildPath(IssuingPath, ControlsPath, ControlProfilesPath, controlProfileId, RemovePath, targetId),
SdkAuthorization(),
null,
cancellationToken,
null
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
using Checkout.Common;
using Checkout.Issuing.ControlProfiles.Requests;
using Checkout.Issuing.ControlProfiles.Responses;
using Checkout.Payments;
using Moq;
using Shouldly;
using System.Threading;
using System.Threading.Tasks;
using Xunit;

namespace Checkout.Issuing.ControlProfiles
{
public class ControlProfilesClientTest : UnitTestFixture
{
private readonly SdkAuthorization _authorization =
new SdkAuthorization(PlatformType.DefaultOAuth, ValidDefaultSk);

private readonly Mock<IApiClient> _apiClient = new Mock<IApiClient>();
private readonly Mock<SdkCredentials> _sdkCredentials = new Mock<SdkCredentials>(PlatformType.DefaultOAuth);
private readonly Mock<IHttpClientFactory> _httpClientFactory = new Mock<IHttpClientFactory>();
private readonly Mock<CheckoutConfiguration> _configuration;

public ControlProfilesClientTest()
{
_sdkCredentials.Setup(credentials => credentials.GetSdkAuthorization(SdkAuthorizationType.OAuth))
.Returns(_authorization);

_configuration = new Mock<CheckoutConfiguration>(_sdkCredentials.Object,
Environment.Sandbox, _httpClientFactory.Object);
}

[Fact]
private async Task ShouldCreateControlProfile()
{
ControlProfileRequest controlProfileRequest = new ControlProfileRequest();
ControlProfileResponse controlProfileResponse = new ControlProfileResponse();

_apiClient.Setup(apiClient =>
apiClient.Post<ControlProfileResponse>("issuing/controls/control-profiles", _authorization,
controlProfileRequest,
CancellationToken.None, null))
.ReturnsAsync(() => controlProfileResponse);

IIssuingClient client =
new IssuingClient(_apiClient.Object, _configuration.Object);

ControlProfileResponse response = await client.CreateControlProfile(controlProfileRequest);

response.ShouldNotBeNull();
response.ShouldBeSameAs(controlProfileResponse);
}

[Fact]
private async Task ShouldGetAllControlProfiles()
{
ControlProfilesResponse controlProfilesResponse = new ControlProfilesResponse();

_apiClient.Setup(apiClient =>
apiClient.Get<ControlProfilesResponse>("issuing/controls/control-profiles", _authorization,
CancellationToken.None))
.ReturnsAsync(() => controlProfilesResponse);

IIssuingClient client =
new IssuingClient(_apiClient.Object, _configuration.Object);

ControlProfilesResponse response = await client.GetAllControlProfiles("target_id");

response.ShouldNotBeNull();
response.ShouldBeSameAs(controlProfilesResponse);
}

[Fact]
private async Task ShouldGetControlProfileDetails()
{
ControlProfileResponse controlProfileResponse = new ControlProfileResponse();

_apiClient.Setup(apiClient =>
apiClient.Get<ControlProfileResponse>("issuing/controls/control-profiles/control_profile_id",
_authorization,
CancellationToken.None))
.ReturnsAsync(() => controlProfileResponse);

IIssuingClient client =
new IssuingClient(_apiClient.Object, _configuration.Object);

ControlProfileResponse response = await client.GetControlProfileDetails("control_profile_id");

response.ShouldNotBeNull();
response.ShouldBeSameAs(controlProfileResponse);
}

[Fact]
private async Task ShouldUpdateControlProfile()
{
ControlProfileRequest controlProfileRequest = new ControlProfileRequest();
ControlProfileResponse controlProfileResponse = new ControlProfileResponse();

_apiClient.Setup(apiClient =>
apiClient.Patch<ControlProfileResponse>("issuing/controls/control-profiles/control_profile_id",
_authorization,
controlProfileRequest,
CancellationToken.None,
null))
.ReturnsAsync(() => controlProfileResponse);

IIssuingClient client =
new IssuingClient(_apiClient.Object, _configuration.Object);

ControlProfileResponse response =
await client.UpdateControlProfile("control_profile_id", controlProfileRequest);

response.ShouldNotBeNull();
response.ShouldBeSameAs(controlProfileResponse);
}

[Fact]
private async Task ShouldDeleteControlProfile()
{
VoidResponse removeControlProfileResponse = new VoidResponse();

_apiClient.Setup(apiClient =>
apiClient.Delete<VoidResponse>("issuing/controls/control-profiles/control_profile_id",
_authorization,
CancellationToken.None))
.ReturnsAsync(() => removeControlProfileResponse);

IIssuingClient client =
new IssuingClient(_apiClient.Object, _configuration.Object);

VoidResponse response = await client.RemoveControlProfile("control_profile_id");

response.ShouldNotBeNull();
response.ShouldBeSameAs(removeControlProfileResponse);
}

[Fact]
private async Task ShouldAddTargetToControlProfile()
{
Resource response = new Resource();

_apiClient.Setup(apiClient =>
apiClient.Post<Resource>("issuing/controls/control-profiles/control_profile_id/add/target_id",
_authorization,
null,
CancellationToken.None,
null))
.ReturnsAsync(() => response);

IIssuingClient client =
new IssuingClient(_apiClient.Object, _configuration.Object);

Resource result = await client.AddTargetToControlProfile("control_profile_id", "target_id");

result.ShouldNotBeNull();
result.ShouldBeSameAs(response);
}

[Fact]
private async Task ShouldRemoveTargetFromControlProfile()
{
Resource response = new Resource();

_apiClient.Setup(apiClient =>
apiClient.Post<Resource>("issuing/controls/control-profiles/control_profile_id/remove/target_id",
_authorization,
null,
CancellationToken.None,
null))
.ReturnsAsync(() => response);

IIssuingClient client =
new IssuingClient(_apiClient.Object, _configuration.Object);

Resource result = await client.RemoveTargetFromControlProfile("control_profile_id", "target_id");

result.ShouldNotBeNull();
result.ShouldBeSameAs(response);
}
}
}
Loading
Loading