From 5b4fc6de86cfc60b5cf9f74d9d7da84953c1db35 Mon Sep 17 00:00:00 2001 From: jillingk <93914435+jillingk@users.noreply.github.com> Date: Mon, 10 Jun 2024 08:22:25 +0200 Subject: [PATCH] Try to deserialize merchant payload (#1027) --- .../WebhooksTests/LegacyWebhookHandlerTest.cs | 13 +++++++ .../merchant-webhook-payload.json | 35 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 Adyen.Test/mocks/notification/merchant-webhook-payload.json diff --git a/Adyen.Test/WebhooksTests/LegacyWebhookHandlerTest.cs b/Adyen.Test/WebhooksTests/LegacyWebhookHandlerTest.cs index ea4dc7bd5..9d5f181ae 100644 --- a/Adyen.Test/WebhooksTests/LegacyWebhookHandlerTest.cs +++ b/Adyen.Test/WebhooksTests/LegacyWebhookHandlerTest.cs @@ -2,6 +2,7 @@ using System.Linq; using Adyen.ApiSerialization; using Adyen.Model.TerminalApi; +using Adyen.Util; using Adyen.Webhooks; using Microsoft.VisualStudio.TestTools.UnitTesting; using Newtonsoft.Json; @@ -27,6 +28,18 @@ public void TestAuthorisationSuccess() Assert.AreEqual("1234", notificationItem.AdditionalData["authCode"]); Assert.AreEqual("123456789", notificationItem.PspReference); } + + [TestMethod] + public void TestMerchantWebhookPayload() + { + var mockPath = GetMockFilePath("mocks/notification/merchant-webhook-payload.json"); + var jsonRequest = MockFileToString(mockPath); + var webhookHandler = new WebhookHandler(); + var handleNotificationRequest = webhookHandler.HandleNotificationRequest(jsonRequest); + var json1 = JsonConvert.SerializeObject(handleNotificationRequest); + var json2 = jsonRequest; + Assert.IsTrue(JToken.DeepEquals(JToken.Parse(json1.ToLower()), JToken.Parse(json2.ToLower()))); + } [TestMethod] public void TestCaptureSuccess() diff --git a/Adyen.Test/mocks/notification/merchant-webhook-payload.json b/Adyen.Test/mocks/notification/merchant-webhook-payload.json new file mode 100644 index 000000000..35496269a --- /dev/null +++ b/Adyen.Test/mocks/notification/merchant-webhook-payload.json @@ -0,0 +1,35 @@ +{ + "live" : "false", + "notificationItems" : [ + { + "NotificationRequestItem" : { + "additionalData" : { + "expiryDate" : "", + "authCode" : "", + "cardSummary" : "0008", + "recurringProcessingModel" : "", + "checkout.cardAddedBrand" : "*******", + "hmacSignature" : "pyUnnXjepXkHBEgmWFFmZceAVK0d9b98Mt6UOAIDX8s=" + }, + "amount" : { + "currency" : "EUR", + "value" : 0 + }, + "eventCode" : "AUTHORISATION", + "eventDate" : "2024-04-30T08:03:24+02:00", + "merchantAccountCode" : "IKEAMXMX", + "merchantReference" : "5908da9e-3be7-4be7-be7f-d645a357dffd", + "operations" : [ + "CANCEL", + "CAPTURE", + "REFUND" + ], + "originalreference": null, + "paymentMethod" : "mc", + "pspReference" : "VZ6GZ9MGQFJSKK65", + "reason" : "033608:0008:03/2030", + "success" : true + } + } + ] +} \ No newline at end of file