Skip to content

Commit 3ab309b

Browse files
Add CancelAScheduledRetry endpoint and related classes (#484)
1 parent 49ef629 commit 3ab309b

File tree

6 files changed

+81
-1
lines changed

6 files changed

+81
-1
lines changed

src/CheckoutSdk/Payments/IPaymentsClient.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ Task<ItemsResponse<PaymentAction>> GetPaymentActions(
2929
string paymentId,
3030
CancellationToken cancellationToken = default);
3131

32+
Task<CancelAScheduledRetryResponse> CancelAScheduledRetry(
33+
string paymentId,
34+
CancelAScheduledRetryRequest cancelAScheduledRetryRequest,
35+
string idempotencyKey = null,
36+
CancellationToken cancellationToken = default);
37+
3238
Task<CaptureResponse> CapturePayment(
3339
string paymentId,
3440
CaptureRequest captureRequest = null,

src/CheckoutSdk/Payments/PaymentsClient.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace Checkout.Payments
88
public class PaymentsClient : AbstractClient, IPaymentsClient
99
{
1010
private const string PaymentsPath = "payments";
11+
private const string CancelAScheduledRetryPath = "cancellations";
1112

1213
public PaymentsClient(
1314
IApiClient apiClient,
@@ -72,6 +73,19 @@ public Task<ItemsResponse<PaymentAction>> GetPaymentActions(
7273
SdkAuthorization(),
7374
cancellationToken);
7475
}
76+
77+
public Task<CancelAScheduledRetryResponse> CancelAScheduledRetry(string paymentId, CancelAScheduledRetryRequest cancelAScheduledRetryRequest,
78+
string idempotencyKey = null,
79+
CancellationToken cancellationToken = default)
80+
{
81+
CheckoutUtils.ValidateParams("paymentId",paymentId,"cancelAScheduledRetryRequest", cancelAScheduledRetryRequest);
82+
return ApiClient.Post<CancelAScheduledRetryResponse>(
83+
BuildPath(PaymentsPath, paymentId, CancelAScheduledRetryPath),
84+
SdkAuthorization(),
85+
cancelAScheduledRetryRequest,
86+
cancellationToken,
87+
idempotencyKey);
88+
}
7589

7690
public Task<CaptureResponse> CapturePayment(
7791
string paymentId,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Checkout.Payments.Request
2+
{
3+
public class CancelAScheduledRetryRequest
4+
{
5+
public string Reference { get; set; }
6+
}
7+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Checkout.Common;
2+
3+
namespace Checkout.Payments.Response
4+
{
5+
public class CancelAScheduledRetryResponse : Resource
6+
{
7+
public string ActionId { get; set; }
8+
9+
public string Reference { get; set; }
10+
}
11+
}

test/CheckoutSdkTest/Payments/PaymentsClientTest.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace Checkout.Payments
1717
public class PaymentsClientTest : UnitTestFixture
1818
{
1919
private const string PaymentsPath = "payments";
20+
private const string CancelAScheduledRetryPath = "cancellations";
2021

2122
private readonly SdkAuthorization _authorization = new SdkAuthorization(PlatformType.Default, ValidDefaultSk);
2223
private readonly Mock<IApiClient> _apiClient = new Mock<IApiClient>();
@@ -260,6 +261,29 @@ private async Task ShouldGetPaymentActions()
260261
response.ShouldNotBeNull();
261262
response.ShouldBeSameAs(paymentActions);
262263
}
264+
265+
[Fact]
266+
private async Task ShouldCancelAScheduledRetry()
267+
{
268+
var cancelAScheduledRetryRequest = new CancelAScheduledRetryRequest();
269+
var cancelAScheduledRetryResponse = new CancelAScheduledRetryResponse();
270+
271+
_apiClient.Setup(apiClient =>
272+
apiClient.Post<CancelAScheduledRetryResponse>(
273+
PaymentsPath + "/payment_id/" + CancelAScheduledRetryPath,
274+
_authorization,
275+
cancelAScheduledRetryRequest,
276+
CancellationToken.None,
277+
"test"))
278+
.ReturnsAsync(() => cancelAScheduledRetryResponse);
279+
280+
IPaymentsClient paymentsClient = new PaymentsClient(_apiClient.Object, _configuration.Object);
281+
282+
var response = await paymentsClient.CancelAScheduledRetry("payment_id", cancelAScheduledRetryRequest, "test");
283+
284+
response.ShouldNotBeNull();
285+
response.ShouldBeSameAs(cancelAScheduledRetryResponse);
286+
}
263287

264288
[Fact]
265289
private async Task ShouldCapturePayment_Id()
@@ -304,7 +328,8 @@ private async Task ShouldCapturePayment_Request()
304328
var captureResponse = new CaptureResponse();
305329

306330
_apiClient.Setup(apiClient =>
307-
apiClient.Post<CaptureResponse>(PaymentsPath + "/payment_id/captures", _authorization,
331+
apiClient.Post<CaptureResponse>(PaymentsPath + "/payment_id/captures",
332+
_authorization,
308333
captureRequest,
309334
CancellationToken.None, "test"))
310335
.ReturnsAsync(() => captureResponse);

test/CheckoutSdkTest/Payments/RequestPaymentsIntegrationTest.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,23 @@ private async Task ShouldMakeCard3dsPayment_N3d()
249249
paymentResponse.HasLink("void").ShouldBeTrue();
250250
}
251251

252+
[Fact(Skip = "Use on demand")]
253+
private async Task ShouldCancelAScheduleRetry()
254+
{
255+
var paymentResponse = await MakeCardPayment();
256+
257+
var request = new CancelAScheduledRetryRequest
258+
{
259+
Reference = paymentResponse.Reference,
260+
};
261+
262+
var response = await DefaultApi.PaymentsClient().CancelAScheduledRetry(paymentResponse.Id, request);
263+
264+
response.ShouldNotBeNull();
265+
response.ActionId.ShouldNotBeNullOrEmpty();
266+
response.Reference.ShouldNotBeNullOrEmpty();
267+
}
268+
252269
[Fact]
253270
private async Task ShouldTokenPayment()
254271
{

0 commit comments

Comments
 (0)