Skip to content

Commit

Permalink
Merge pull request #194 from adyen-examples/webhook-ack-202
Browse files Browse the repository at this point in the history
Webhook processing: 202 response with empty body
  • Loading branch information
gcatanese authored Mar 19, 2024
2 parents 27efce8 + ed97e65 commit 53245ee
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -114,15 +114,17 @@ 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;
}

// 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
Expand Down

0 comments on commit 53245ee

Please sign in to comment.