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
6 changes: 6 additions & 0 deletions src/CheckoutSdk/Payments/IPaymentsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ Task<ItemsResponse<PaymentAction>> GetPaymentActions(
string paymentId,
CancellationToken cancellationToken = default);

Task<CancelAScheduledRetryResponse> CancelAScheduledRetry(
string paymentId,
CancelAScheduledRetryRequest cancelAScheduledRetryRequest,
string idempotencyKey = null,
CancellationToken cancellationToken = default);

Task<CaptureResponse> CapturePayment(
string paymentId,
CaptureRequest captureRequest = null,
Expand Down
14 changes: 14 additions & 0 deletions src/CheckoutSdk/Payments/PaymentsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Checkout.Payments
public class PaymentsClient : AbstractClient, IPaymentsClient
{
private const string PaymentsPath = "payments";
private const string CancelAScheduledRetryPath = "cancellations";

public PaymentsClient(
IApiClient apiClient,
Expand Down Expand Up @@ -72,6 +73,19 @@ public Task<ItemsResponse<PaymentAction>> GetPaymentActions(
SdkAuthorization(),
cancellationToken);
}

public Task<CancelAScheduledRetryResponse> CancelAScheduledRetry(string paymentId, CancelAScheduledRetryRequest cancelAScheduledRetryRequest,
string idempotencyKey = null,
CancellationToken cancellationToken = default)
{
CheckoutUtils.ValidateParams("paymentId",paymentId,"cancelAScheduledRetryRequest", cancelAScheduledRetryRequest);
return ApiClient.Post<CancelAScheduledRetryResponse>(
BuildPath(PaymentsPath, paymentId, CancelAScheduledRetryPath),
SdkAuthorization(),
cancelAScheduledRetryRequest,
cancellationToken,
idempotencyKey);
}

public Task<CaptureResponse> CapturePayment(
string paymentId,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Checkout.Payments.Request
{
public class CancelAScheduledRetryRequest
{
public string Reference { get; set; }
}
}
11 changes: 11 additions & 0 deletions src/CheckoutSdk/Payments/Response/CancelAScheduledRetryResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Checkout.Common;

namespace Checkout.Payments.Response
{
public class CancelAScheduledRetryResponse : Resource
{
public string ActionId { get; set; }

public string Reference { get; set; }
}
}
27 changes: 26 additions & 1 deletion test/CheckoutSdkTest/Payments/PaymentsClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace Checkout.Payments
public class PaymentsClientTest : UnitTestFixture
{
private const string PaymentsPath = "payments";
private const string CancelAScheduledRetryPath = "cancellations";

private readonly SdkAuthorization _authorization = new SdkAuthorization(PlatformType.Default, ValidDefaultSk);
private readonly Mock<IApiClient> _apiClient = new Mock<IApiClient>();
Expand Down Expand Up @@ -260,6 +261,29 @@ private async Task ShouldGetPaymentActions()
response.ShouldNotBeNull();
response.ShouldBeSameAs(paymentActions);
}

[Fact]
private async Task ShouldCancelAScheduledRetry()
{
var cancelAScheduledRetryRequest = new CancelAScheduledRetryRequest();
var cancelAScheduledRetryResponse = new CancelAScheduledRetryResponse();

_apiClient.Setup(apiClient =>
apiClient.Post<CancelAScheduledRetryResponse>(
PaymentsPath + "/payment_id/" + CancelAScheduledRetryPath,
_authorization,
cancelAScheduledRetryRequest,
CancellationToken.None,
"test"))
.ReturnsAsync(() => cancelAScheduledRetryResponse);

IPaymentsClient paymentsClient = new PaymentsClient(_apiClient.Object, _configuration.Object);

var response = await paymentsClient.CancelAScheduledRetry("payment_id", cancelAScheduledRetryRequest, "test");

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

[Fact]
private async Task ShouldCapturePayment_Id()
Expand Down Expand Up @@ -304,7 +328,8 @@ private async Task ShouldCapturePayment_Request()
var captureResponse = new CaptureResponse();

_apiClient.Setup(apiClient =>
apiClient.Post<CaptureResponse>(PaymentsPath + "/payment_id/captures", _authorization,
apiClient.Post<CaptureResponse>(PaymentsPath + "/payment_id/captures",
_authorization,
captureRequest,
CancellationToken.None, "test"))
.ReturnsAsync(() => captureResponse);
Expand Down
17 changes: 17 additions & 0 deletions test/CheckoutSdkTest/Payments/RequestPaymentsIntegrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,23 @@ private async Task ShouldMakeCard3dsPayment_N3d()
paymentResponse.HasLink("void").ShouldBeTrue();
}

[Fact(Skip = "Use on demand")]
private async Task ShouldCancelAScheduleRetry()
{
var paymentResponse = await MakeCardPayment();

var request = new CancelAScheduledRetryRequest
{
Reference = paymentResponse.Reference,
};

var response = await DefaultApi.PaymentsClient().CancelAScheduledRetry(paymentResponse.Id, request);

response.ShouldNotBeNull();
response.ActionId.ShouldNotBeNullOrEmpty();
response.Reference.ShouldNotBeNullOrEmpty();
}

[Fact]
private async Task ShouldTokenPayment()
{
Expand Down
Loading