Skip to content

Commit

Permalink
In-person Payments - Adyen HttpClient throws a 400: BadRequest, Respo…
Browse files Browse the repository at this point in the history
…nseBody: {"errors":["At toplevel: Missing"]} (#1078)

* Use SaleToPoiRequest

* Update README.md

---------

Co-authored-by: kwokhe <[email protected]>
  • Loading branch information
Kwok-he-Chu and kwokhe authored Nov 4, 2024
1 parent 7e5f07e commit ca50b28
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 51 deletions.
32 changes: 16 additions & 16 deletions Adyen/Service/TerminalApiAsyncService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,36 @@ namespace Adyen.Service
public interface ITerminalApiAsyncService
{
/// <summary>
/// Sends an encrypted <see cref="SaleToPOIRequest"/> or <see cref="SaleToPOIMessage"/> to the terminal-api `/async` endpoint.
/// Sends an encrypted <see cref="SaleToPOIRequest"/> to the terminal-api `/async` endpoint.
/// </summary>
/// <param name="saleToPoiRequest"><see cref="SaleToPOIRequest"/> or <see cref="SaleToPOIMessage"/>.</param>
/// <param name="saleToPoiRequest"><see cref="SaleToPOIRequest"/>.</param>
/// <param name="encryptionCredentialDetails"><see cref="EncryptionCredentialDetails"/>. These must match the credentials that you configured in the Customer Area. Make sure your terminal is updated to latest version.</param>
/// <param name="cancellationToken"><see cref="CancellationToken"/>.</param>
/// <returns>A <see cref="Task{TValue}"/> that represents the <see cref="string"/>.</returns>
Task<string> RequestEncryptedAsync(SaleToPOIMessage saleToPoiRequest, EncryptionCredentialDetails encryptionCredentialDetails, CancellationToken cancellationToken);
Task<string> RequestEncryptedAsync(SaleToPOIRequest saleToPoiRequest, EncryptionCredentialDetails encryptionCredentialDetails, CancellationToken cancellationToken);

/// <summary>
/// Sends an encrypted <see cref="SaleToPOIRequest"/> or <see cref="SaleToPOIMessage"/> to the terminal-api `/async` endpoint.
/// Sends an encrypted <see cref="SaleToPOIRequest"/> to the terminal-api `/async` endpoint.
/// </summary>
/// <param name="saleToPoiRequest"><see cref="SaleToPOIRequest"/> or <see cref="SaleToPOIMessage"/>.</param>
/// <param name="saleToPoiRequest"><see cref="SaleToPOIRequest"/>.</param>
/// <param name="encryptionCredentialDetails"><see cref="EncryptionCredentialDetails"/>. These must match the credentials that you configured in the Customer Area. Make sure your terminal is updated to latest version.</param>
/// <returns>Response <see cref="string"/>.</returns>
string RequestEncrypted(SaleToPOIMessage saleToPoiRequest, EncryptionCredentialDetails encryptionCredentialDetails);
string RequestEncrypted(SaleToPOIRequest saleToPoiRequest, EncryptionCredentialDetails encryptionCredentialDetails);

/// <summary>
/// Sends a <see cref="SaleToPOIRequest"/> or <see cref="SaleToPOIMessage"/> to the terminal-api `/async` endpoint.
/// Sends a <see cref="SaleToPOIRequest"/> to the terminal-api `/async` endpoint.
/// </summary>
/// <param name="saleToPoiRequest"><see cref="SaleToPOIRequest"/> or <see cref="SaleToPOIMessage"/>.</param>
/// <param name="saleToPoiRequest"><see cref="SaleToPOIRequest"/>.</param>
/// <param name="cancellationToken"><see cref="CancellationToken"/>.</param>
/// <returns>A <see cref="Task{TValue}"/> that represents the <see cref="string"/>.</returns>
Task<string> RequestAsync(SaleToPOIMessage saleToPoiRequest, CancellationToken cancellationToken);
Task<string> RequestAsync(SaleToPOIRequest saleToPoiRequest, CancellationToken cancellationToken);

/// <summary>
/// Sends a <see cref="SaleToPOIRequest"/> or <see cref="SaleToPOIMessage"/> to the terminal-api `/async` endpoint.
/// Sends a <see cref="SaleToPOIRequest"/> to the terminal-api `/async` endpoint.
/// </summary>
/// <param name="saleToPoiRequest"><see cref="SaleToPOIRequest"/> or <see cref="SaleToPOIMessage"/>.</param>
/// <param name="saleToPoiRequest"><see cref="SaleToPOIRequest"/>.</param>
/// <returns>Response <see cref="string"/>.</returns>
string Request(SaleToPOIMessage saleToPoiRequest);
string Request(SaleToPOIRequest saleToPoiRequest);

/// <summary>
/// Used to decrypt the notification received.
Expand Down Expand Up @@ -76,7 +76,7 @@ public TerminalApiAsyncService(Client client, SaleToPoiMessageSerializer saleToP
}

/// <inheritdoc/>
public async Task<string> RequestEncryptedAsync(SaleToPOIMessage saleToPoiRequest, EncryptionCredentialDetails encryptionCredentialDetails, CancellationToken cancellationToken)
public async Task<string> RequestEncryptedAsync(SaleToPOIRequest saleToPoiRequest, EncryptionCredentialDetails encryptionCredentialDetails, CancellationToken cancellationToken)
{
string serializedMessage = _saleToPoiMessageSerializer.Serialize(saleToPoiRequest);
Client.LogLine("Request: \n"+ serializedMessage);
Expand All @@ -88,7 +88,7 @@ public async Task<string> RequestEncryptedAsync(SaleToPOIMessage saleToPoiReques
}

/// <inheritdoc/>
public string RequestEncrypted(SaleToPOIMessage saleToPoiRequest, EncryptionCredentialDetails encryptionCredentialDetails)
public string RequestEncrypted(SaleToPOIRequest saleToPoiRequest, EncryptionCredentialDetails encryptionCredentialDetails)
{
string serializedMessage = _saleToPoiMessageSerializer.Serialize(saleToPoiRequest);
Client.LogLine("Request: \n"+ serializedMessage);
Expand All @@ -100,7 +100,7 @@ public string RequestEncrypted(SaleToPOIMessage saleToPoiRequest, EncryptionCre
}

/// <inheritdoc/>
public async Task<string> RequestAsync(SaleToPOIMessage saleToPoiRequest, CancellationToken cancellationToken)
public async Task<string> RequestAsync(SaleToPOIRequest saleToPoiRequest, CancellationToken cancellationToken)
{
string serializedMessage = _saleToPoiMessageSerializer.Serialize(saleToPoiRequest);
Client.LogLine("Request: \n" + serializedMessage);
Expand All @@ -110,7 +110,7 @@ public async Task<string> RequestAsync(SaleToPOIMessage saleToPoiRequest, Cancel
}

/// <inheritdoc/>
public string Request(SaleToPOIMessage saleToPoiRequest)
public string Request(SaleToPOIRequest saleToPoiRequest)
{
string serializedMessage = _saleToPoiMessageSerializer.Serialize(saleToPoiRequest);
Client.LogLine("Request: \n" + serializedMessage);
Expand Down
32 changes: 16 additions & 16 deletions Adyen/Service/TerminalApiLocalService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,50 +14,50 @@ namespace Adyen.Service
public interface ITerminalApiLocalService
{
/// <summary>
/// Sends an encrypted <see cref="SaleToPOIRequest"/> or <see cref="SaleToPOIMessage"/> to the endpoint specified in <see cref="Config.LocalTerminalApiEndpoint"/> (e.g. `https://198.51.100.1:8443/nexo`).
/// Sends an encrypted <see cref="SaleToPOIRequest"/> to the endpoint specified in <see cref="Config.LocalTerminalApiEndpoint"/> (e.g. `https://198.51.100.1:8443/nexo`).
/// To protect local communications, you need to add and validate Adyen's certificate (see docs) and encrypt your messages.
/// </summary>
/// <param name="saleToPoiRequest"><see cref="SaleToPOIRequest"/> or <see cref="SaleToPOIMessage"/>.</param>
/// <param name="saleToPoiRequest"><see cref="SaleToPOIRequest"/>.</param>
/// <param name="encryptionCredentialDetails"><see cref="EncryptionCredentialDetails"/>. These must match the credentials that you configured in the Customer Area. Make sure your terminal is updated to latest version.</param>
/// <param name="cancellationToken"><see cref="CancellationToken"/>.</param>
/// <returns>A <see cref="Task{TValue}"/> that represents the <see cref="SaleToPOIResponse"/>.</returns>
Task<SaleToPOIResponse> RequestEncryptedAsync(SaleToPOIMessage saleToPoiRequest, EncryptionCredentialDetails encryptionCredentialDetails, CancellationToken cancellationToken);
Task<SaleToPOIResponse> RequestEncryptedAsync(SaleToPOIRequest saleToPoiRequest, EncryptionCredentialDetails encryptionCredentialDetails, CancellationToken cancellationToken);

/// <summary>
/// Sends an encrypted <see cref="SaleToPOIRequest"/> or <see cref="SaleToPOIMessage"/> to the endpoint specified in <see cref="Config.LocalTerminalApiEndpoint"/> (e.g. `https://198.51.100.1:8443/nexo`).
/// Sends an encrypted <see cref="SaleToPOIRequest"/> to the endpoint specified in <see cref="Config.LocalTerminalApiEndpoint"/> (e.g. `https://198.51.100.1:8443/nexo`).
/// To protect local communications, you need to add and validate Adyen's certificate (see docs) and encrypt your messages.
/// </summary>
/// <param name="saleToPoiRequest"><see cref="SaleToPOIRequest"/> or <see cref="SaleToPOIMessage"/>.</param>
/// <param name="saleToPoiRequest"><see cref="SaleToPOIRequest"/>.</param>
/// <param name="encryptionCredentialDetails"><see cref="EncryptionCredentialDetails"/>. These must match the credentials that you configured in the Customer Area. Make sure your terminal is updated to latest version.</param>
/// <returns><see cref="SaleToPOIResponse"/>.</returns>
SaleToPOIResponse RequestEncrypted(SaleToPOIMessage saleToPoiRequest, EncryptionCredentialDetails encryptionCredentialDetails);
SaleToPOIResponse RequestEncrypted(SaleToPOIRequest saleToPoiRequest, EncryptionCredentialDetails encryptionCredentialDetails);

/// <summary>
/// Sends a <see cref="SaleToPOIRequest"/> or <see cref="SaleToPOIMessage"/> to the endpoint specified in <see cref="Config.LocalTerminalApiEndpoint"/> (e.g. `https://198.51.100.1:8443/nexo`) .
/// Sends a <see cref="SaleToPOIRequest"/> to the endpoint specified in <see cref="Config.LocalTerminalApiEndpoint"/> (e.g. `https://198.51.100.1:8443/nexo`) .
/// If you want to send unencrypted requests for local testing purposes, override the <see cref="System.Net.Http.HttpClientHandler"/> that is passed in the constructor of <see cref="System.Net.Http.HttpClient"/>.
///
/// Example:
/// <see cref="System.Net.Http.HttpClientHandler"/> handler = new HttpClientHandler { ServerCertificateCustomValidationCallback = (message, certificate2, arg3, arg4) => true };
/// var httpClient = new <see cref="Adyen.Client"/>(<see cref="Adyen.Config"/>, new <see cref="System.Net.Http.HttpClient"/>(handler));
/// var terminalApiLocalService = new <see cref="TerminalApiLocalService"/>(httpClient, <see cref="SaleToPoiMessageSerializer"/>, <see cref="SaleToPoiMessageSecuredEncryptor"/>, <see cref="SaleToPoiMessageSecuredSerializer"/>);
/// </summary>
/// <param name="saleToPoiRequest"><see cref="SaleToPOIRequest"/> or <see cref="SaleToPOIMessage"/>.</param>
/// <param name="saleToPoiRequest"><see cref="SaleToPOIRequest"/>.</param>
/// <param name="cancellationToken"><see cref="CancellationToken"/>.</param>
/// <returns>A <see cref="Task{TValue}"/> that represents the <see cref="SaleToPOIResponse"/>.</returns>
Task<SaleToPOIResponse> RequestAsync(SaleToPOIMessage saleToPoiRequest, CancellationToken cancellationToken);
Task<SaleToPOIResponse> RequestAsync(SaleToPOIRequest saleToPoiRequest, CancellationToken cancellationToken);

/// <summary>
/// Sends a <see cref="SaleToPOIRequest"/> or <see cref="SaleToPOIMessage"/> to the endpoint specified in <see cref="Config.LocalTerminalApiEndpoint"/> (e.g. `https://198.51.100.1:8443/nexo`).
/// Sends a <see cref="SaleToPOIRequest"/> to the endpoint specified in <see cref="Config.LocalTerminalApiEndpoint"/> (e.g. `https://198.51.100.1:8443/nexo`).
/// If you want to send unencrypted requests for local testing purposes, override the <see cref="System.Net.Http.HttpClientHandler"/> that is passed in the constructor of <see cref="System.Net.Http.HttpClient"/>.
///
/// Example:
/// <see cref="System.Net.Http.HttpClientHandler"/> handler = new HttpClientHandler { ServerCertificateCustomValidationCallback = (message, certificate2, arg3, arg4) => true };
/// var httpClient = new <see cref="Adyen.Client"/>(<see cref="Adyen.Config"/>, new <see cref="System.Net.Http.HttpClient"/>(handler));
/// var terminalApiLocalService = new <see cref="TerminalApiLocalService"/>(httpClient, <see cref="SaleToPoiMessageSerializer"/>, <see cref="SaleToPoiMessageSecuredEncryptor"/>, <see cref="SaleToPoiMessageSecuredSerializer"/>);
/// </summary>
/// <param name="saleToPoiRequest"><see cref="SaleToPOIRequest"/> or <see cref="SaleToPOIMessage"/>.</param>
/// <param name="saleToPoiRequest"><see cref="SaleToPOIRequest"/>.</param>
/// <returns><see cref="SaleToPOIResponse"/>.</returns>
SaleToPOIResponse Request(SaleToPOIMessage saleToPoiRequest);
SaleToPOIResponse Request(SaleToPOIRequest saleToPoiRequest);

/// <summary>
/// Decrypts a <see cref="SaleToPoiMessageSecured"/> and returns the <see cref="SaleToPOIResponse"/>.
Expand Down Expand Up @@ -90,7 +90,7 @@ public TerminalApiLocalService(Client client, SaleToPoiMessageSerializer saleToP
}

/// <inheritdoc/>
public async Task<SaleToPOIResponse> RequestEncryptedAsync(SaleToPOIMessage saleToPoiRequest, EncryptionCredentialDetails encryptionCredentialDetails, CancellationToken cancellationToken)
public async Task<SaleToPOIResponse> RequestEncryptedAsync(SaleToPOIRequest saleToPoiRequest, EncryptionCredentialDetails encryptionCredentialDetails, CancellationToken cancellationToken)
{
string serializedMessage = _saleToPoiMessageSerializer.Serialize(saleToPoiRequest);
Client.LogLine("Request: \n" + serializedMessage);
Expand All @@ -108,7 +108,7 @@ public async Task<SaleToPOIResponse> RequestEncryptedAsync(SaleToPOIMessage sale
}

/// <inheritdoc/>
public SaleToPOIResponse RequestEncrypted(SaleToPOIMessage saleToPoiRequest, EncryptionCredentialDetails encryptionCredentialDetails)
public SaleToPOIResponse RequestEncrypted(SaleToPOIRequest saleToPoiRequest, EncryptionCredentialDetails encryptionCredentialDetails)
{
string serializedMessage = _saleToPoiMessageSerializer.Serialize(saleToPoiRequest);
Client.LogLine("Request: \n" + serializedMessage);
Expand All @@ -126,7 +126,7 @@ public SaleToPOIResponse RequestEncrypted(SaleToPOIMessage saleToPoiRequest, Enc
}

/// <inheritdoc/>
public async Task<SaleToPOIResponse> RequestAsync(SaleToPOIMessage saleToPoiRequest, CancellationToken cancellationToken)
public async Task<SaleToPOIResponse> RequestAsync(SaleToPOIRequest saleToPoiRequest, CancellationToken cancellationToken)
{
string serializedMessage = _saleToPoiMessageSerializer.Serialize(saleToPoiRequest);
Client.LogLine("Request: \n" + serializedMessage);
Expand All @@ -140,7 +140,7 @@ public async Task<SaleToPOIResponse> RequestAsync(SaleToPOIMessage saleToPoiRequ
}

/// <inheritdoc/>
public SaleToPOIResponse Request(SaleToPOIMessage saleToPoiRequest)
public SaleToPOIResponse Request(SaleToPOIRequest saleToPoiRequest)
{
string serializedMessage = _saleToPoiMessageSerializer.Serialize(saleToPoiRequest);
Client.LogLine("Request: \n" + serializedMessage);
Expand Down
Loading

0 comments on commit ca50b28

Please sign in to comment.