Skip to content

Commit

Permalink
Send 202 response with an empty body
Browse files Browse the repository at this point in the history
  • Loading branch information
gcatanese committed Mar 11, 2024
1 parent 78b5c96 commit 97a99a5
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 @@ -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
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 97a99a5

Please sign in to comment.