Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webhook processing: 202 response with empty body #194

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 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 @@ -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
Loading