From 97a99a5106b5b54795a85eac49aa754ad786d828 Mon Sep 17 00:00:00 2001 From: Beppe Catanese Date: Mon, 11 Mar 2024 16:10:50 +0100 Subject: [PATCH 1/2] Send 202 response with an empty body --- server/index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/server/index.js b/server/index.js index 9c70b79..9c62ecf 100644 --- a/server/index.js +++ b/server/index.js @@ -44,7 +44,7 @@ app.post("/api/sessions", async (req, res) => { const host = req.get('host'); // Ideally the data passed here should be computed based on business logic - const response = await checkout.sessions({ + const response = await checkout.PaymentsApi.sessions({ amount: { currency: "EUR", value: 10000 }, // Value is 100€ in minor units countryCode: "NL", merchantAccount: process.env.ADYEN_MERCHANT_ACCOUNT, // Required: your merchant account @@ -114,7 +114,7 @@ app.post("/api/webhooks/notifications", async (req, res) => { // Handle the notification if(!validator.validateHMAC(notification, hmacKey)) { - // invalid hmac: do not send [accepted] response + // invalid hmac console.log("Invalid HMAC signature: " + notification); res.status(401).send('Invalid HMAC signature'); return; @@ -122,7 +122,9 @@ app.post("/api/webhooks/notifications", async (req, res) => { // Process the notification asynchronously based on the eventCode consumeEvent(notification); - res.send('[accepted]'); + + // acknowledge event has been consumed + res.status(202).send(); // Send a 202 response with an empty body }); // Process payload From ed97e65093b499d52ed2f4da1619189e7f659a6f Mon Sep 17 00:00:00 2001 From: Beppe Catanese Date: Mon, 11 Mar 2024 16:36:28 +0100 Subject: [PATCH 2/2] Correct package name --- server/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/index.js b/server/index.js index 9c62ecf..19fce35 100644 --- a/server/index.js +++ b/server/index.js @@ -75,7 +75,7 @@ app.all("/api/handleShopperRedirect", async (req, res) => { } try { - const response = await checkout.paymentsDetails({ details }); + const response = await checkout.PaymentsApi.paymentsDetails({ details }); // Conditionally handle different result codes for the shopper switch (response.resultCode) { case "Authorised": @@ -122,7 +122,7 @@ app.post("/api/webhooks/notifications", async (req, res) => { // Process the notification asynchronously based on the eventCode consumeEvent(notification); - + // acknowledge event has been consumed res.status(202).send(); // Send a 202 response with an empty body });