Skip to content

Commit

Permalink
Merge pull request #732 from Adyen/hotfix-main
Browse files Browse the repository at this point in the history
[PW-8004] Release 9.2.0
  • Loading branch information
AlexandrosMor authored Feb 2, 2023
2 parents e097e2e + a4a1c6e commit 75d10a9
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 11 deletions.
6 changes: 3 additions & 3 deletions Adyen.Test/Adyen.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

<IsPackable>false</IsPackable>

<AssemblyVersion>9.1.0</AssemblyVersion>
<AssemblyVersion>9.2.0</AssemblyVersion>

<FileVersion>9.1.0</FileVersion>
<FileVersion>9.2.0</FileVersion>

<Version>9.1.0</Version>
<Version>9.2.0</Version>

<LangVersion>7.2</LangVersion>
</PropertyGroup>
Expand Down
47 changes: 45 additions & 2 deletions Adyen.Test/NotificationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@
// *
// * Adyen Dotnet API Library
// *
// * Copyright (c) 2020 Adyen B.V.
// * Copyright (c) 2023 Adyen B.V.
// * This file is open source and available under the MIT license.
// * See the LICENSE file for more info.
// */
#endregion

using System;
using Adyen.ApiSerialization;
using Adyen.Model.Nexo;

namespace Adyen.Test
{
using Microsoft.VisualStudio.TestTools.UnitTesting;
Expand Down Expand Up @@ -120,6 +124,45 @@ public void TestRefundFail()
Assert.IsFalse(notificationItem.Success);
Assert.AreEqual("Insufficient balance on payment", notificationItem.Reason);
}

[TestMethod]
public void TestPOSDisplayNotification()
{
var notification =
"{\"SaleToPOIRequest\":{\"DisplayRequest\":{\"DisplayOutput\":[{\"Device\": \"CashierDisplay\",\"InfoQualify\": \"Status\",\"OutputContent\": {\"OutputFormat\": \"MessageRef\",\"PredefinedContent\": {\"ReferenceID\": \"TransactionID=oLkO001517998574000&TimeStamp=2018-02-07T10%3a16%3a14.000Z&event=TENDER_CREATED\"}},\"ResponseRequiredFlag\": false}]},\"MessageHeader\":{\"SaleID\":\"POSSystemID12345\",\"ProtocolVersion\":\"3.0\",\"MessageType\":\"Request\",\"POIID\":\"V400m-324688179\",\"ServiceID\":\"0207111617\",\"MessageClass\":\"Device\",\"MessageCategory\":\"Display\",\"DeviceID\":\"1517998562\"}}}";
var serializer = new SaleToPoiMessageSerializer();
var saleToPoiRequest = serializer.DeserializeNotification(notification);
var displayRequest = (DisplayRequest)saleToPoiRequest.MessagePayload;
Assert.AreEqual(displayRequest.DisplayOutput[0].OutputContent.OutputFormat, OutputFormatType.MessageRef);
Assert.AreEqual(displayRequest.DisplayOutput[0].Device, DeviceType.CashierDisplay);
}

[TestMethod]
public void TestPOSEventNotification()
{
var notification = @"{
'SaleToPOIRequest':{
'EventNotification':{
'EventDetails':'newstate=IDLE&oldstate=START',
'EventToNotify':'Shutdown',
'TimeStamp':'2019-08-07T10:16:10.000Z'
},
'MessageHeader':{
'SaleID':'POSSystemID12345',
'ProtocolVersion':'3.0',
'MessageType':'Notification',
'POIID':'V400m-324688179',
'MessageClass':'Event',
'MessageCategory':'Event',
'DeviceID':'1517998561'
}
}
}";
var serializer = new SaleToPoiMessageSerializer();
var saleToPoiRequest = serializer.DeserializeNotification(notification);
var eventNotification = (EventNotification)saleToPoiRequest.MessagePayload;
Assert.AreEqual(eventNotification.EventDetails, "newstate=IDLE&oldstate=START");
Assert.AreEqual(eventNotification.TimeStamp, new DateTime(2019, 8, 7, 10, 16, 10));
}
}
}

8 changes: 4 additions & 4 deletions Adyen/Adyen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<Copyright>Adyen</Copyright>
<Version>9.1.0</Version>
<AssemblyVersion>9.1.0</AssemblyVersion>
<FileVersion>9.1.0</FileVersion>
<Version>9.2.0</Version>
<AssemblyVersion>9.2.0</AssemblyVersion>
<FileVersion>9.2.0</FileVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Description>The Adyen API Library for .net core enables you to work with Adyen APIs, Hosted Payment Pages and terminal api with any .net application.</Description>
<PackageProjectUrl>https://github.com/Adyen/adyen-dotnet-api-library</PackageProjectUrl>
<RepositoryUrl>https://github.com/Adyen/adyen-dotnet-api-library</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>9.1.0</PackageTags>
<PackageTags>9.2.0</PackageTags>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Authors>Adyen</Authors>
<Company>Adyen</Company>
Expand Down
33 changes: 32 additions & 1 deletion Adyen/ApiSerialization/SaleToPoiMessageSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
// *
// * Adyen Dotnet API Library
// *
// * Copyright (c) 2020 Adyen B.V.
// * Copyright (c) 2023 Adyen B.V.
// * This file is open source and available under the MIT license.
// * See the LICENSE file for more info.
// */
#endregion

using System;
using Adyen.Model.Nexo;
using Adyen.Model.Nexo.Message;
using Adyen.Security;
using Newtonsoft.Json.Linq;

Expand Down Expand Up @@ -64,6 +66,35 @@ public SaleToPOIResponse Deserialize(string saleToPoiMessageDto)
return deserializedOutputMessage;
}

public SaleToPOIRequest DeserializeNotification(string terminalNotificationJson)
{
// Parse JsonObject
var saleToPoiRequestJson = JObject.Parse(terminalNotificationJson);
var saleToPoiRequestItem = saleToPoiRequestJson.First;
var saleToPoiRequestType = saleToPoiRequestItem?.First;
var saleToPoiString = saleToPoiRequestType?.ToString() ?? throw new ArgumentNullException(nameof(terminalNotificationJson));

// Get Message Header
var messageHeader = DeserializeMessageHeader(saleToPoiRequestType);

// Get Payload and create new SaleToPOIRequest object
var notification = new SaleToPOIRequest
{
MessageHeader = messageHeader
};
if (saleToPoiString.Contains("DisplayRequest"))
{
notification.MessagePayload = saleToPoiRequestType["DisplayRequest"]?.ToObject<DisplayRequest>();
} else if (saleToPoiString.Contains("EventNotification"))
{
notification.MessagePayload = saleToPoiRequestType["EventNotification"]?.ToObject<EventNotification>();
} else
{
throw new Exception("Json input is not a terminal notification.");
}
return notification;
}

private object DeserializeMessagePayload(MessageHeader messageHeader, JToken saleToPoiMessageWithoutRootJToken)
{
var messageCategory = messageHeader.MessageCategory;
Expand Down
2 changes: 1 addition & 1 deletion Adyen/Constants/ClientConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ public class ClientConfig
public static string BinLookupApiVersion = "v50";

public static string LibName = "adyen-dotnet-api-library";
public static string LibVersion = "9.1.0";
public static string LibVersion = "9.2.0";
}
}
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ var config = new Config
var client = new Client(config);
~~~~

To parse the terminal API notifications, please use the following custom deserializer. This method will throw an exception for non-notification requests.
~~~~ csharp
var serializer = new SaleToPoiMessageSerializer();
var saleToPoiRequest = serializer.DeserializeNotification(your_terminal_notification);

~~~~
## Contributing

We encourage you to contribute to this repository, so everyone can benefit from new features, bug fixes, and any other improvements.
Expand Down

0 comments on commit 75d10a9

Please sign in to comment.