From 045d60f6db3cf1516196ccb27b3b485221fe6135 Mon Sep 17 00:00:00 2001 From: Beppe Catanese <1771700+gcatanese@users.noreply.github.com> Date: Mon, 11 Mar 2024 16:54:51 +0100 Subject: [PATCH] Webhook processing: 202 response with empty body (#76) * Send a 202 response with an empty body * Add return statement * Return ok from service * Return 202 with empty body --- app/controllers/checkouts_controller.rb | 3 ++- app/models/checkout.rb | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/checkouts_controller.rb b/app/controllers/checkouts_controller.rb index fbb0dd0..1ad7454 100644 --- a/app/controllers/checkouts_controller.rb +++ b/app/controllers/checkouts_controller.rb @@ -51,6 +51,7 @@ def handle_shopper_redirect def adyen_webhooks notifications = params["notificationItems"] response = Checkout.adyen_webhooks(notifications) - render json: response + # Return 202 with empty body + render status: 202, body: '' end end diff --git a/app/models/checkout.rb b/app/models/checkout.rb index 79b1e06..2b14048 100644 --- a/app/models/checkout.rb +++ b/app/models/checkout.rb @@ -58,9 +58,10 @@ def adyen_webhooks(notifications) if validator.valid_notification_hmac?(notification, hmacKey) puts notification["eventCode"] puts notification["merchantReference"] - "[accepted]" + # Send a 202 response with an empty body + "Ok" else - # In case of invalid hmac, do not send [accepted] response + # In case of invalid hmac raise "Invalid HMAC Signature" end end