Skip to content

Commit

Permalink
support CancellationToken passing to base API (Adyen#937)
Browse files Browse the repository at this point in the history
  • Loading branch information
selfdeceited authored Nov 20, 2023
1 parent fce0f4a commit c0fc8ff
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions Adyen/Service/TerminalCloudApi.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Threading;
using System.Threading.Tasks;
using Adyen.ApiSerialization;
using Adyen.Model.TerminalApi;
Expand Down Expand Up @@ -25,15 +26,17 @@ public interface ITerminalCloudApi
/// Task async CloudApi asynchronous call
/// </summary>
/// <param name="saleToPoiRequest"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<SaleToPOIResponse> TerminalRequestAsynchronousAsync(SaleToPOIMessage saleToPoiRequest);
Task<SaleToPOIResponse> TerminalRequestAsynchronousAsync(SaleToPOIMessage saleToPoiRequest, CancellationToken cancellationToken = default);

/// <summary>
/// Task async CloudApi synchronous call
/// </summary>
/// <param name="saleToPoiRequest"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<SaleToPOIResponse> TerminalRequestSynchronousAsync(SaleToPOIMessage saleToPoiRequest);
Task<SaleToPOIResponse> TerminalRequestSynchronousAsync(SaleToPOIMessage saleToPoiRequest, CancellationToken cancellationToken = default);
}
public class TerminalCloudApi : AbstractService, ITerminalCloudApi
{
Expand Down Expand Up @@ -79,11 +82,11 @@ public SaleToPOIResponse TerminalRequestSync(SaleToPOIMessage saleToPoiRequest)
return _saleToPoiMessageSerializer.Deserialize(response);
}

public async Task<SaleToPOIResponse> TerminalRequestAsynchronousAsync(SaleToPOIMessage saleToPoiRequest)
public async Task<SaleToPOIResponse> TerminalRequestAsynchronousAsync(SaleToPOIMessage saleToPoiRequest, CancellationToken cancellationToken = default)
{
var serializedMessage = _saleToPoiMessageSerializer.Serialize(saleToPoiRequest);
Client.LogLine("Request: \n" + serializedMessage);
var response = await _terminalApiAsync.RequestAsync(serializedMessage);
var response = await _terminalApiAsync.RequestAsync(serializedMessage, cancellationToken: cancellationToken);
Client.LogLine("Response: \n" + response);
if (string.IsNullOrEmpty(response) || string.Equals("ok", response))
{
Expand All @@ -92,11 +95,11 @@ public async Task<SaleToPOIResponse> TerminalRequestAsynchronousAsync(SaleToPOIM
return _saleToPoiMessageSerializer.Deserialize(response);
}

public async Task<SaleToPOIResponse> TerminalRequestSynchronousAsync(SaleToPOIMessage saleToPoiRequest)
public async Task<SaleToPOIResponse> TerminalRequestSynchronousAsync(SaleToPOIMessage saleToPoiRequest, CancellationToken cancellationToken = default)
{
var serializedMessage = _saleToPoiMessageSerializer.Serialize(saleToPoiRequest);
Client.LogLine("Request: \n" + serializedMessage);
var response = await _terminalApiSync.RequestAsync(serializedMessage);
var response = await _terminalApiSync.RequestAsync(serializedMessage, cancellationToken: cancellationToken);
Client.LogLine("Response: \n" + response);
if (string.IsNullOrEmpty(response) || string.Equals("ok", response))
{
Expand Down

0 comments on commit c0fc8ff

Please sign in to comment.