Skip to content

Commit fa49b15

Browse files
Add control profiles issuing (#465)
1 parent c1c012e commit fa49b15

File tree

8 files changed

+452
-0
lines changed

8 files changed

+452
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Checkout.Issuing.ControlProfiles.Requests
2+
{
3+
public class ControlProfileRequest
4+
{
5+
public string Name { get; set; }
6+
}
7+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Checkout.Common;
2+
using System;
3+
4+
namespace Checkout.Issuing.ControlProfiles.Responses
5+
{
6+
public class ControlProfileResponse : Resource
7+
{
8+
public string Id { get; set; }
9+
10+
public string Name { get; set; }
11+
12+
public DateTime? CreatedDate { get; set; }
13+
14+
public DateTime? LastModifiedDate { get; set; }
15+
}
16+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System.Collections.Generic;
2+
3+
namespace Checkout.Issuing.ControlProfiles.Responses
4+
{
5+
public class ControlProfilesResponse : HttpMetadata
6+
{
7+
public IList<ControlProfileResponse> ControlProfiles { get; set; }
8+
}
9+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using Checkout.Common;
2+
using Checkout.Issuing.ControlProfiles.Requests;
3+
using Checkout.Issuing.ControlProfiles.Responses;
4+
using Checkout.Payments;
5+
using System.Threading;
6+
using System.Threading.Tasks;
7+
8+
namespace Checkout.Issuing
9+
{
10+
public partial interface IIssuingClient
11+
{
12+
Task<ControlProfileResponse> CreateControlProfile(ControlProfileRequest controlProfileRequest,
13+
CancellationToken cancellationToken = default);
14+
15+
Task<ControlProfilesResponse> GetAllControlProfiles(string targetId,
16+
CancellationToken cancellationToken = default);
17+
18+
Task<ControlProfileResponse> GetControlProfileDetails(string controlProfileId,
19+
CancellationToken cancellationToken = default);
20+
21+
Task<ControlProfileResponse> UpdateControlProfile(string controlProfileId,
22+
ControlProfileRequest controlProfileRequest,
23+
CancellationToken cancellationToken = default);
24+
25+
Task<VoidResponse> RemoveControlProfile(string controlProfileId,
26+
CancellationToken cancellationToken = default);
27+
28+
Task<Resource> AddTargetToControlProfile(string controlProfileId,
29+
string targetId,
30+
CancellationToken cancellationToken = default);
31+
32+
Task<Resource> RemoveTargetFromControlProfile(string controlProfileId,
33+
string targetId,
34+
CancellationToken cancellationToken = default);
35+
}
36+
}

src/CheckoutSdk/Issuing/IssuingClient.Base.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ public partial class IssuingClient : AbstractClient, IIssuingClient
1616
private const string PresentmentsPath = "presentments";
1717
private const string ReversalsPath = "reversals";
1818
private const string TransactionsPath = "transactions";
19+
private const string ControlProfilesPath = "control-profiles";
20+
private const string AddPath = "add";
21+
private const string RemovePath = "remove";
1922

2023
public IssuingClient(IApiClient apiClient, CheckoutConfiguration configuration) :
2124
base(apiClient, configuration, SdkAuthorizationType.OAuth)
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
using Checkout.Common;
2+
using Checkout.Issuing.ControlProfiles.Requests;
3+
using Checkout.Issuing.ControlProfiles.Responses;
4+
using Checkout.Payments;
5+
using System.Threading;
6+
using System.Threading.Tasks;
7+
8+
namespace Checkout.Issuing
9+
{
10+
public partial class IssuingClient
11+
{
12+
public Task<ControlProfileResponse> CreateControlProfile(ControlProfileRequest controlProfileRequest, CancellationToken cancellationToken = default)
13+
{
14+
CheckoutUtils.ValidateParams("controlProfileRequest", controlProfileRequest);
15+
return ApiClient.Post<ControlProfileResponse>(
16+
BuildPath(IssuingPath, ControlsPath, ControlProfilesPath),
17+
SdkAuthorization(),
18+
controlProfileRequest,
19+
cancellationToken
20+
);
21+
}
22+
23+
public Task<ControlProfilesResponse> GetAllControlProfiles(string targetId, CancellationToken cancellationToken = default)
24+
{
25+
CheckoutUtils.ValidateParams("targetId", targetId);
26+
return ApiClient.Get<ControlProfilesResponse>(
27+
BuildPath(IssuingPath, ControlsPath, ControlProfilesPath),
28+
SdkAuthorization(),
29+
cancellationToken
30+
);
31+
}
32+
33+
public Task<ControlProfileResponse> GetControlProfileDetails(string controlProfileId, CancellationToken cancellationToken = default)
34+
{
35+
CheckoutUtils.ValidateParams("controlProfileId", controlProfileId);
36+
return ApiClient.Get<ControlProfileResponse>(
37+
BuildPath(IssuingPath, ControlsPath, ControlProfilesPath, controlProfileId),
38+
SdkAuthorization(),
39+
cancellationToken
40+
);
41+
}
42+
43+
public Task<ControlProfileResponse> UpdateControlProfile(string controlProfileId, ControlProfileRequest controlProfileRequest,
44+
CancellationToken cancellationToken = default)
45+
{
46+
CheckoutUtils.ValidateParams("controlProfileId", controlProfileId, "controlProfileRequest", controlProfileRequest);
47+
return ApiClient.Patch<ControlProfileResponse>(
48+
BuildPath(IssuingPath, ControlsPath, ControlProfilesPath, controlProfileId),
49+
SdkAuthorization(),
50+
controlProfileRequest,
51+
cancellationToken
52+
);
53+
}
54+
55+
public Task<VoidResponse> RemoveControlProfile(string controlProfileId, CancellationToken cancellationToken = default)
56+
{
57+
CheckoutUtils.ValidateParams("controlProfileId", controlProfileId);
58+
return ApiClient.Delete<VoidResponse>(
59+
BuildPath(IssuingPath, ControlsPath, ControlProfilesPath, controlProfileId),
60+
SdkAuthorization(),
61+
cancellationToken
62+
);
63+
}
64+
65+
public Task<Resource> AddTargetToControlProfile(string controlProfileId, string targetId, CancellationToken cancellationToken = default)
66+
{
67+
CheckoutUtils.ValidateParams("controlProfileId", controlProfileId, "targetId", targetId);
68+
return ApiClient.Post<Resource>(
69+
BuildPath(IssuingPath, ControlsPath, ControlProfilesPath, controlProfileId, AddPath, targetId),
70+
SdkAuthorization(),
71+
null,
72+
cancellationToken,
73+
null
74+
);
75+
}
76+
77+
public Task<Resource> RemoveTargetFromControlProfile(string controlProfileId, string targetId,
78+
CancellationToken cancellationToken = default)
79+
{
80+
CheckoutUtils.ValidateParams("controlProfileId", controlProfileId, "targetId", targetId);
81+
return ApiClient.Post<Resource>(
82+
BuildPath(IssuingPath, ControlsPath, ControlProfilesPath, controlProfileId, RemovePath, targetId),
83+
SdkAuthorization(),
84+
null,
85+
cancellationToken,
86+
null
87+
);
88+
}
89+
}
90+
}
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
using Checkout.Common;
2+
using Checkout.Issuing.ControlProfiles.Requests;
3+
using Checkout.Issuing.ControlProfiles.Responses;
4+
using Checkout.Payments;
5+
using Moq;
6+
using Shouldly;
7+
using System.Threading;
8+
using System.Threading.Tasks;
9+
using Xunit;
10+
11+
namespace Checkout.Issuing.ControlProfiles
12+
{
13+
public class ControlProfilesClientTest : UnitTestFixture
14+
{
15+
private readonly SdkAuthorization _authorization =
16+
new SdkAuthorization(PlatformType.DefaultOAuth, ValidDefaultSk);
17+
18+
private readonly Mock<IApiClient> _apiClient = new Mock<IApiClient>();
19+
private readonly Mock<SdkCredentials> _sdkCredentials = new Mock<SdkCredentials>(PlatformType.DefaultOAuth);
20+
private readonly Mock<IHttpClientFactory> _httpClientFactory = new Mock<IHttpClientFactory>();
21+
private readonly Mock<CheckoutConfiguration> _configuration;
22+
23+
public ControlProfilesClientTest()
24+
{
25+
_sdkCredentials.Setup(credentials => credentials.GetSdkAuthorization(SdkAuthorizationType.OAuth))
26+
.Returns(_authorization);
27+
28+
_configuration = new Mock<CheckoutConfiguration>(_sdkCredentials.Object,
29+
Environment.Sandbox, _httpClientFactory.Object);
30+
}
31+
32+
[Fact]
33+
private async Task ShouldCreateControlProfile()
34+
{
35+
ControlProfileRequest controlProfileRequest = new ControlProfileRequest();
36+
ControlProfileResponse controlProfileResponse = new ControlProfileResponse();
37+
38+
_apiClient.Setup(apiClient =>
39+
apiClient.Post<ControlProfileResponse>("issuing/controls/control-profiles", _authorization,
40+
controlProfileRequest,
41+
CancellationToken.None, null))
42+
.ReturnsAsync(() => controlProfileResponse);
43+
44+
IIssuingClient client =
45+
new IssuingClient(_apiClient.Object, _configuration.Object);
46+
47+
ControlProfileResponse response = await client.CreateControlProfile(controlProfileRequest);
48+
49+
response.ShouldNotBeNull();
50+
response.ShouldBeSameAs(controlProfileResponse);
51+
}
52+
53+
[Fact]
54+
private async Task ShouldGetAllControlProfiles()
55+
{
56+
ControlProfilesResponse controlProfilesResponse = new ControlProfilesResponse();
57+
58+
_apiClient.Setup(apiClient =>
59+
apiClient.Get<ControlProfilesResponse>("issuing/controls/control-profiles", _authorization,
60+
CancellationToken.None))
61+
.ReturnsAsync(() => controlProfilesResponse);
62+
63+
IIssuingClient client =
64+
new IssuingClient(_apiClient.Object, _configuration.Object);
65+
66+
ControlProfilesResponse response = await client.GetAllControlProfiles("target_id");
67+
68+
response.ShouldNotBeNull();
69+
response.ShouldBeSameAs(controlProfilesResponse);
70+
}
71+
72+
[Fact]
73+
private async Task ShouldGetControlProfileDetails()
74+
{
75+
ControlProfileResponse controlProfileResponse = new ControlProfileResponse();
76+
77+
_apiClient.Setup(apiClient =>
78+
apiClient.Get<ControlProfileResponse>("issuing/controls/control-profiles/control_profile_id",
79+
_authorization,
80+
CancellationToken.None))
81+
.ReturnsAsync(() => controlProfileResponse);
82+
83+
IIssuingClient client =
84+
new IssuingClient(_apiClient.Object, _configuration.Object);
85+
86+
ControlProfileResponse response = await client.GetControlProfileDetails("control_profile_id");
87+
88+
response.ShouldNotBeNull();
89+
response.ShouldBeSameAs(controlProfileResponse);
90+
}
91+
92+
[Fact]
93+
private async Task ShouldUpdateControlProfile()
94+
{
95+
ControlProfileRequest controlProfileRequest = new ControlProfileRequest();
96+
ControlProfileResponse controlProfileResponse = new ControlProfileResponse();
97+
98+
_apiClient.Setup(apiClient =>
99+
apiClient.Patch<ControlProfileResponse>("issuing/controls/control-profiles/control_profile_id",
100+
_authorization,
101+
controlProfileRequest,
102+
CancellationToken.None,
103+
null))
104+
.ReturnsAsync(() => controlProfileResponse);
105+
106+
IIssuingClient client =
107+
new IssuingClient(_apiClient.Object, _configuration.Object);
108+
109+
ControlProfileResponse response =
110+
await client.UpdateControlProfile("control_profile_id", controlProfileRequest);
111+
112+
response.ShouldNotBeNull();
113+
response.ShouldBeSameAs(controlProfileResponse);
114+
}
115+
116+
[Fact]
117+
private async Task ShouldDeleteControlProfile()
118+
{
119+
VoidResponse removeControlProfileResponse = new VoidResponse();
120+
121+
_apiClient.Setup(apiClient =>
122+
apiClient.Delete<VoidResponse>("issuing/controls/control-profiles/control_profile_id",
123+
_authorization,
124+
CancellationToken.None))
125+
.ReturnsAsync(() => removeControlProfileResponse);
126+
127+
IIssuingClient client =
128+
new IssuingClient(_apiClient.Object, _configuration.Object);
129+
130+
VoidResponse response = await client.RemoveControlProfile("control_profile_id");
131+
132+
response.ShouldNotBeNull();
133+
response.ShouldBeSameAs(removeControlProfileResponse);
134+
}
135+
136+
[Fact]
137+
private async Task ShouldAddTargetToControlProfile()
138+
{
139+
Resource response = new Resource();
140+
141+
_apiClient.Setup(apiClient =>
142+
apiClient.Post<Resource>("issuing/controls/control-profiles/control_profile_id/add/target_id",
143+
_authorization,
144+
null,
145+
CancellationToken.None,
146+
null))
147+
.ReturnsAsync(() => response);
148+
149+
IIssuingClient client =
150+
new IssuingClient(_apiClient.Object, _configuration.Object);
151+
152+
Resource result = await client.AddTargetToControlProfile("control_profile_id", "target_id");
153+
154+
result.ShouldNotBeNull();
155+
result.ShouldBeSameAs(response);
156+
}
157+
158+
[Fact]
159+
private async Task ShouldRemoveTargetFromControlProfile()
160+
{
161+
Resource response = new Resource();
162+
163+
_apiClient.Setup(apiClient =>
164+
apiClient.Post<Resource>("issuing/controls/control-profiles/control_profile_id/remove/target_id",
165+
_authorization,
166+
null,
167+
CancellationToken.None,
168+
null))
169+
.ReturnsAsync(() => response);
170+
171+
IIssuingClient client =
172+
new IssuingClient(_apiClient.Object, _configuration.Object);
173+
174+
Resource result = await client.RemoveTargetFromControlProfile("control_profile_id", "target_id");
175+
176+
result.ShouldNotBeNull();
177+
result.ShouldBeSameAs(response);
178+
}
179+
}
180+
}

0 commit comments

Comments
 (0)