Skip to content

Commit

Permalink
Added comments and specified the endpoints "https://terminal-api-test…
Browse files Browse the repository at this point in the history
  • Loading branch information
kwokhe committed Sep 30, 2024
1 parent a0e0303 commit 8664bc5
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 90 deletions.
10 changes: 5 additions & 5 deletions Adyen.Test/NotificationDecryptionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ public void TestNotificationDecryption()
{
try
{
string encryptedNotification = @"{""SaleToPOIRequest"":{""SecurityTrailer"":{""AdyenCryptoVersion"":1,""Nonce"":""Be6rAx+vRju2aCHwPh6lrg=="",""KeyIdentifier"":""ncrkey"",""Hmac"":""LG8A9Re1M8xLMr7rDUk0NwsnvAOX+VLjHv9sPHWTl34="",""KeyVersion"":1},""NexoBlob"":""x2DY8J2M9ZCyjOZ8Gt7JdLBA\/6bT\/KXvvAbJf9kzguqO8dWp1I1pPLQpLstpdIiAVqSwG3PR0PrP\/lF82UmhmCnUJGCuEXilqvBNF1tF\/yEgnFOklNc1myR2IPW\/+2oZOWKFXlTo\/gX89EbODXOOGUqaJfSdpDhlqjyMz7mGczobTPvPGqCVx2BDHU8VTxI9nicwQv+QV48GqVZzxnP8ZOdQOQ5cac+bcS0Y3l7SmWpIoQsoicnjahTY9ICosLJmN4DvDHsN4Kh2DAetFO5b9I9Lqgm\/dvnXUVhb9tPbM7Pn+ratjYpaNbonbO5M+Tm8rDEIyKoUUuFXPWISymrCXtCDVKEb2B5S5pilUmokrXVa9Ldtsv3BKG7rbrglYEuql4WVs6kzr6ybgAKh1Q0LsAXEve3pydt72ay4U3FOJSBxJ3gNqmnG8mVW2HCXQVo1RgVaZmP5TBWYuksCKXYypnMulu1PlRI++oeW\/J2qjQU="",""MessageHeader"":{""ProtocolVersion"":""3.0"",""SaleID"":""null"",""MessageClass"":""Event"",""MessageCategory"":""Event"",""POIID"":""P400Plus-275102806"",""MessageType"":""Notification"",""DeviceID"":""5""}}}";
string expectedDecryption = @"{ ""SaleToPOIRequest"": { ""EventNotification"": { ""EventDetails"": ""reference_id=9876"", ""TimeStamp"": ""2020-11-13T09:02:35.697Z"", ""EventToNotify"": ""SaleWakeUp"" }, ""MessageHeader"": { ""ProtocolVersion"": ""3.0"", ""SaleID"": ""null"", ""MessageClass"": ""Event"", ""MessageCategory"": ""Event"", ""POIID"": ""P400Plus-275102806"", ""MessageType"": ""Notification"", ""DeviceID"": ""5"" } } }";
var encryptedNotification = @"{""SaleToPOIRequest"":{""SecurityTrailer"":{""AdyenCryptoVersion"":1,""Nonce"":""Be6rAx+vRju2aCHwPh6lrg=="",""KeyIdentifier"":""ncrkey"",""Hmac"":""LG8A9Re1M8xLMr7rDUk0NwsnvAOX+VLjHv9sPHWTl34="",""KeyVersion"":1},""NexoBlob"":""x2DY8J2M9ZCyjOZ8Gt7JdLBA\/6bT\/KXvvAbJf9kzguqO8dWp1I1pPLQpLstpdIiAVqSwG3PR0PrP\/lF82UmhmCnUJGCuEXilqvBNF1tF\/yEgnFOklNc1myR2IPW\/+2oZOWKFXlTo\/gX89EbODXOOGUqaJfSdpDhlqjyMz7mGczobTPvPGqCVx2BDHU8VTxI9nicwQv+QV48GqVZzxnP8ZOdQOQ5cac+bcS0Y3l7SmWpIoQsoicnjahTY9ICosLJmN4DvDHsN4Kh2DAetFO5b9I9Lqgm\/dvnXUVhb9tPbM7Pn+ratjYpaNbonbO5M+Tm8rDEIyKoUUuFXPWISymrCXtCDVKEb2B5S5pilUmokrXVa9Ldtsv3BKG7rbrglYEuql4WVs6kzr6ybgAKh1Q0LsAXEve3pydt72ay4U3FOJSBxJ3gNqmnG8mVW2HCXQVo1RgVaZmP5TBWYuksCKXYypnMulu1PlRI++oeW\/J2qjQU="",""MessageHeader"":{""ProtocolVersion"":""3.0"",""SaleID"":""null"",""MessageClass"":""Event"",""MessageCategory"":""Event"",""POIID"":""P400Plus-275102806"",""MessageType"":""Notification"",""DeviceID"":""5""}}}";
var expectedDecryption = @"{ ""SaleToPOIRequest"": { ""EventNotification"": { ""EventDetails"": ""reference_id=9876"", ""TimeStamp"": ""2020-11-13T09:02:35.697Z"", ""EventToNotify"": ""SaleWakeUp"" }, ""MessageHeader"": { ""ProtocolVersion"": ""3.0"", ""SaleID"": ""null"", ""MessageClass"": ""Event"", ""MessageCategory"": ""Event"", ""POIID"": ""P400Plus-275102806"", ""MessageType"": ""Notification"", ""DeviceID"": ""5"" } } }";

//create a mock client
Client client = CreateMockTestClientPosLocalApiRequest("mocks/terminalapi/pospayment-encrypted-success.json");
TerminalApiLocalService terminalApiLocalService = new TerminalApiLocalService(client);
string decryptedNotification = terminalApiLocalService.DecryptNotification(encryptedNotification, _encryptionCredentialDetails);
var client = CreateMockTestClientPosLocalApiRequest("mocks/terminalapi/pospayment-encrypted-success.json");
var terminalLocalApi = new TerminalLocalApi(client);
var decryptedNotification = terminalLocalApi.DecryptNotification(encryptedNotification, _encryptionCredentialDetails);
Assert.AreEqual(decryptedNotification, expectedDecryption);
}
catch (Exception)
Expand Down
67 changes: 23 additions & 44 deletions Adyen.Test/TerminalApiLocalServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Adyen.Model.TerminalApi;

namespace Adyen.Test
{
[TestClass]
public class TerminalApiLocalServiceTest : BaseTest
{
[TestMethod]
public async Task RequestEncryptedAsync_Success() {
public async Task RequestEncryptedAsync_Success()
{
try
{
SaleToPOIRequest saleToPoiRequest = MockPosApiRequest.CreatePosPaymentRequest();
Expand All @@ -23,19 +25,20 @@ public async Task RequestEncryptedAsync_Success() {
KeyIdentifier = "CryptoKeyIdentifier12345",
Password = "p@ssw0rd123456"
};
Client client = CreateMockTestClientPosCloudApiRequest("mocks/terminalapi/pospayment-async-success.json");
Client client = CreateMockTestClientPosCloudApiRequest("mocks/terminalapi/pospayment-encrypted-success.json");
ITerminalApiLocalService localService = new TerminalApiLocalService(client);
string response = await localService.RequestEncryptedAsync(saleToPoiRequest, encryptionCredentialDetails, new CancellationToken());
Assert.AreEqual(response, "ok");
SaleToPOIResponse response = await localService.RequestEncryptedAsync(saleToPoiRequest, encryptionCredentialDetails, new CancellationToken());
Assert.IsNotNull(response);
}
catch (Exception)
{
Assert.Fail();
}
}

[TestMethod]
public void RequestEncrypted_Success() {
public void RequestEncrypted_Success()
{
try
{
SaleToPOIRequest saleToPoiRequest = MockPosApiRequest.CreatePosPaymentRequest();
Expand All @@ -46,43 +49,27 @@ public void RequestEncrypted_Success() {
KeyIdentifier = "CryptoKeyIdentifier12345",
Password = "p@ssw0rd123456"
};
Client client = CreateMockTestClientPosCloudApiRequest("mocks/terminalapi/pospayment-async-success.json");
ITerminalApiLocalService localService = new TerminalApiLocalService(client);
string response = localService.RequestEncrypted(saleToPoiRequest, encryptionCredentialDetails);
Assert.AreEqual(response, "ok");
}
catch (Exception)
{
Assert.Fail();
}
}

[TestMethod]
public async Task RequestAsync_Success() {
try
{
SaleToPOIRequest saleToPoiRequest = MockPosApiRequest.CreatePosPaymentRequest();
Client client = CreateMockTestClientPosCloudApiRequest("mocks/terminalapi/pospayment-async-success.json");
Client client = CreateMockTestClientPosCloudApiRequest("mocks/terminalapi/pospayment-encrypted-success.json");
ITerminalApiLocalService localService = new TerminalApiLocalService(client);
string response = await localService.RequestAsync(saleToPoiRequest, new CancellationToken());
Assert.AreEqual(response, "ok");
SaleToPOIResponse response = localService.RequestEncrypted(saleToPoiRequest, encryptionCredentialDetails);
Assert.IsNotNull(response);
}
catch (Exception)
{
Assert.Fail();
}
}



[TestMethod]
public void Request_Success() {
public async Task RequestAsync_Success()
{
try
{
SaleToPOIRequest saleToPoiRequest = MockPosApiRequest.CreatePosPaymentRequest();
Client client = CreateMockTestClientPosCloudApiRequest("mocks/terminalapi/pospayment-async-success.json");
Client client = CreateMockTestClientPosCloudApiRequest("mocks/terminalapi/pospayment-success.json");
ITerminalApiLocalService localService = new TerminalApiLocalService(client);
string response = localService.Request(saleToPoiRequest);
Assert.AreEqual(response, "ok");
SaleToPOIResponse response = await localService.RequestAsync(saleToPoiRequest, new CancellationToken());
Assert.IsNotNull(response);
}
catch (Exception)
{
Expand All @@ -91,23 +78,15 @@ public void Request_Success() {
}

[TestMethod]
public void DecryptNotification_Success()
public void Request_Success()
{
try
{
EncryptionCredentialDetails encryptionCredentialDetails = new EncryptionCredentialDetails
{
AdyenCryptoVersion = 1,
KeyIdentifier = "ncrkey",
Password = "ncrpass"
};
string encryptedNotification = @"{""SaleToPOIRequest"":{""SecurityTrailer"":{""AdyenCryptoVersion"":1,""Nonce"":""Be6rAx+vRju2aCHwPh6lrg=="",""KeyIdentifier"":""ncrkey"",""Hmac"":""LG8A9Re1M8xLMr7rDUk0NwsnvAOX+VLjHv9sPHWTl34="",""KeyVersion"":1},""NexoBlob"":""x2DY8J2M9ZCyjOZ8Gt7JdLBA\/6bT\/KXvvAbJf9kzguqO8dWp1I1pPLQpLstpdIiAVqSwG3PR0PrP\/lF82UmhmCnUJGCuEXilqvBNF1tF\/yEgnFOklNc1myR2IPW\/+2oZOWKFXlTo\/gX89EbODXOOGUqaJfSdpDhlqjyMz7mGczobTPvPGqCVx2BDHU8VTxI9nicwQv+QV48GqVZzxnP8ZOdQOQ5cac+bcS0Y3l7SmWpIoQsoicnjahTY9ICosLJmN4DvDHsN4Kh2DAetFO5b9I9Lqgm\/dvnXUVhb9tPbM7Pn+ratjYpaNbonbO5M+Tm8rDEIyKoUUuFXPWISymrCXtCDVKEb2B5S5pilUmokrXVa9Ldtsv3BKG7rbrglYEuql4WVs6kzr6ybgAKh1Q0LsAXEve3pydt72ay4U3FOJSBxJ3gNqmnG8mVW2HCXQVo1RgVaZmP5TBWYuksCKXYypnMulu1PlRI++oeW\/J2qjQU="",""MessageHeader"":{""ProtocolVersion"":""3.0"",""SaleID"":""null"",""MessageClass"":""Event"",""MessageCategory"":""Event"",""POIID"":""P400Plus-275102806"",""MessageType"":""Notification"",""DeviceID"":""5""}}}";
string expectedDecryption = @"{ ""SaleToPOIRequest"": { ""EventNotification"": { ""EventDetails"": ""reference_id=9876"", ""TimeStamp"": ""2020-11-13T09:02:35.697Z"", ""EventToNotify"": ""SaleWakeUp"" }, ""MessageHeader"": { ""ProtocolVersion"": ""3.0"", ""SaleID"": ""null"", ""MessageClass"": ""Event"", ""MessageCategory"": ""Event"", ""POIID"": ""P400Plus-275102806"", ""MessageType"": ""Notification"", ""DeviceID"": ""5"" } } }";

Client client = CreateMockTestClientPosLocalApiRequest("mocks/terminalapi/pospayment-encrypted-success.json");
SaleToPOIRequest saleToPoiRequest = MockPosApiRequest.CreatePosPaymentRequest();
Client client = CreateMockTestClientPosCloudApiRequest("mocks/terminalapi/pospayment-success.json");
ITerminalApiLocalService localService = new TerminalApiLocalService(client);
string decryptedNotification = localService.DecryptNotification(encryptedNotification, encryptionCredentialDetails);
Assert.AreEqual(decryptedNotification, expectedDecryption);
SaleToPOIResponse response = localService.Request(saleToPoiRequest);
Assert.IsNotNull(response);
}
catch (Exception)
{
Expand Down
8 changes: 7 additions & 1 deletion Adyen/Service/TerminalApiAsyncService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace Adyen.Service
{
/// <summary>
/// Service that sends requests to the Adyen Cloud Terminal API `/async` endpoint.
/// Service that sends requests to the Adyen Cloud Terminal API `https://terminal-api-test.adyen.com/async` endpoint.
/// </summary>
public interface ITerminalApiAsyncService
{
Expand Down Expand Up @@ -54,13 +54,19 @@ public interface ITerminalApiAsyncService
string DecryptNotification(string notification, EncryptionCredentialDetails encryptionCredentialDetails);
}

/// <summary>
/// Service that sends requests to the Adyen Cloud Terminal API `https://terminal-api-test.adyen.com/async` endpoint.
/// </summary>
public class TerminalApiAsyncService : AbstractService, ITerminalApiAsyncService
{
private readonly TerminalApiAsyncClient _asyncClient;
private readonly SaleToPoiMessageSerializer _saleToPoiMessageSerializer;
private readonly SaleToPoiMessageSecuredEncryptor _saleToPoiMessageSecuredEncryptor;
private readonly SaleToPoiMessageSecuredSerializer _saleToPoiMessageSecuredSerializer;

/// <summary>
/// Service that sends requests to the Adyen Cloud Terminal API `https://terminal-api-test.adyen.com/async` endpoint.
/// </summary>
public TerminalApiAsyncService(Client client) : base(client)
{
_saleToPoiMessageSerializer = new SaleToPoiMessageSerializer();
Expand Down
Loading

0 comments on commit 8664bc5

Please sign in to comment.