diff --git a/authorisation-adjustment-example/src/main/java/com/adyen/checkout/api/WebhookController.java b/authorisation-adjustment-example/src/main/java/com/adyen/checkout/api/WebhookController.java index 89e9025..a4130e8 100644 --- a/authorisation-adjustment-example/src/main/java/com/adyen/checkout/api/WebhookController.java +++ b/authorisation-adjustment-example/src/main/java/com/adyen/checkout/api/WebhookController.java @@ -10,6 +10,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -42,7 +43,7 @@ public WebhookController(ApplicationProperty applicationProperty) { /** * Process incoming Webhook notification: get NotificationRequestItem, validate HMAC signature, - * consume the event asynchronously, send response ["accepted"] + * consume the event asynchronously, send response status 202 * * @param json Payload of the webhook event * @return @@ -71,24 +72,25 @@ public ResponseEntity webhooks(@RequestBody String json) throws Exceptio consumeEvent(item); } else { - // invalid HMAC signature: do not send [accepted] response + // invalid HMAC signature log.warn("Could not validate HMAC signature for incoming webhook message: {}", item); throw new RuntimeException("Invalid HMAC signature"); } } catch (SignatureException e) { - // Unexpected error during HMAC validation: do not send [accepted] response + // Unexpected error during HMAC validation log.error("Error while validating HMAC Key", e); throw new SignatureException(e); } } else { - // Unexpected event with no payload: do not send [accepted] response + // Unexpected event with no payload log.warn("Empty NotificationItem"); - throw new Exception("empty"); + throw new Exception("empty payload"); } // Acknowledge event has been consumed - return ResponseEntity.ok().body("[accepted]"); + return ResponseEntity.status(HttpStatus.ACCEPTED).build(); + } // process payload asynchronously diff --git a/checkout-example-advanced/src/main/java/com/adyen/checkout/api/WebhookResource.java b/checkout-example-advanced/src/main/java/com/adyen/checkout/api/WebhookResource.java index 07de56b..cf2a657 100644 --- a/checkout-example-advanced/src/main/java/com/adyen/checkout/api/WebhookResource.java +++ b/checkout-example-advanced/src/main/java/com/adyen/checkout/api/WebhookResource.java @@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -39,7 +40,7 @@ public WebhookResource(ApplicationProperty applicationProperty) { /** * Process incoming Webhook notification: get NotificationRequestItem, validate HMAC signature, - * consume the event asynchronously, send response ["accepted"] + * consume the event asynchronously, send response status 202 * * @param json Payload of the webhook event * @return @@ -70,24 +71,24 @@ public ResponseEntity webhooks(@RequestBody String json) throws Exceptio consumeEvent(item); } else { - // invalid HMAC signature: do not send [accepted] response + // invalid HMAC signature log.warn("Could not validate HMAC signature for incoming webhook message: {}", item); throw new RuntimeException("Invalid HMAC signature"); } } catch (SignatureException e) { - // Unexpected error during HMAC validation: do not send [accepted] response + // Unexpected error during HMAC validation log.error("Error while validating HMAC Key", e); throw new SignatureException(e); } } else { - // Unexpected event with no payload: do not send [accepted] response + // Unexpected event with no payload log.warn("Empty NotificationItem"); - throw new Exception("empty"); + throw new Exception("empty payload"); } // Acknowledge event has been consumed - return ResponseEntity.ok().body("[accepted]"); + return ResponseEntity.status(HttpStatus.ACCEPTED).build(); } // process payload asynchronously diff --git a/checkout-example/src/main/java/com/adyen/checkout/api/WebhookResource.java b/checkout-example/src/main/java/com/adyen/checkout/api/WebhookResource.java index 4a51fba..5b18046 100644 --- a/checkout-example/src/main/java/com/adyen/checkout/api/WebhookResource.java +++ b/checkout-example/src/main/java/com/adyen/checkout/api/WebhookResource.java @@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -39,7 +40,7 @@ public WebhookResource(ApplicationProperty applicationProperty) { /** * Process the incoming Webhook event: get NotificationRequestItem, validate HMAC signature, - * consume the event asynchronously, send response ["accepted"] + * consume the event asynchronously, send response status 202 * * @param json Payload of the webhook event * @return @@ -69,24 +70,24 @@ public ResponseEntity webhooks(@RequestBody String json) throws Exceptio consumeEvent(item); } else { - // invalid HMAC signature: do not send [accepted] response + // invalid HMAC signature log.warn("Could not validate HMAC signature for incoming webhook message: {}", item); throw new RuntimeException("Invalid HMAC signature"); } } catch (SignatureException e) { - // Unexpected error during HMAC validation: do not send [accepted] response + // Unexpected error during HMAC validation log.error("Error while validating HMAC Key", e); throw new SignatureException(e); } } else { - // Unexpected event with no payload: do not send [accepted] response + // Unexpected event with no payload log.warn("Empty NotificationItem"); - throw new Exception("empty"); + throw new Exception("Event with empty payload"); } // Acknowledge event has been consumed - return ResponseEntity.ok().body("[accepted]"); + return ResponseEntity.status(HttpStatus.ACCEPTED).build(); } // process payload asynchronously diff --git a/giftcard-example/src/main/java/com/adyen/giftcard/api/WebhookResource.java b/giftcard-example/src/main/java/com/adyen/giftcard/api/WebhookResource.java index 4bcd075..3abedfa 100644 --- a/giftcard-example/src/main/java/com/adyen/giftcard/api/WebhookResource.java +++ b/giftcard-example/src/main/java/com/adyen/giftcard/api/WebhookResource.java @@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -39,7 +40,7 @@ public WebhookResource(ApplicationProperty applicationProperty) { /** * Process the incoming Webhook event: get NotificationRequestItem, validate HMAC signature, - * consume the event asynchronously, send response ["accepted"] + * consume the event asynchronously, send response status 202 * * @param json Payload of the webhook event * @return @@ -59,7 +60,7 @@ public ResponseEntity webhooks(@RequestBody String json) throws Exceptio try { if (!getHmacValidator().validateHMAC(item, this.applicationProperty.getHmacKey())) { - // invalid HMAC signature: do not send [accepted] response + // invalid HMAC signature log.warn("Could not validate HMAC signature for incoming webhook message: {}", item); throw new RuntimeException("Invalid HMAC signature"); } @@ -105,19 +106,19 @@ public ResponseEntity webhooks(@RequestBody String json) throws Exceptio } } catch (SignatureException e) { - // Unexpected error during HMAC validation: do not send [accepted] response + // Unexpected error during HMAC validation log.error("Error while validating HMAC Key", e); throw new SignatureException(e); } } else { - // Unexpected event with no payload: do not send [accepted] response + // Unexpected event with no payload log.warn("Empty NotificationItem"); - throw new Exception("empty"); + throw new Exception("empty payload"); } // Acknowledge event has been consumed - return ResponseEntity.ok().body("[accepted]"); + return ResponseEntity.status(HttpStatus.ACCEPTED).build(); } // process payload asynchronously diff --git a/giving-example/src/main/java/com/adyen/giving/api/GivingWebhookResource.java b/giving-example/src/main/java/com/adyen/giving/api/GivingWebhookResource.java index a598881..87a36b5 100644 --- a/giving-example/src/main/java/com/adyen/giving/api/GivingWebhookResource.java +++ b/giving-example/src/main/java/com/adyen/giving/api/GivingWebhookResource.java @@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -66,12 +67,12 @@ public ResponseEntity webhooks(@RequestBody String json) throws IOExcept consumeEvent(item); } else { - // Unexpected event with no payload: do not send [accepted] response + // Unexpected event with no payload log.warn("Empty NotificationItem"); } // Acknowledge event has been consumed - return ResponseEntity.ok().body("[accepted]"); + return ResponseEntity.status(HttpStatus.ACCEPTED).build(); } // process payload asynchronously diff --git a/giving-example/src/main/java/com/adyen/giving/api/WebhookResource.java b/giving-example/src/main/java/com/adyen/giving/api/WebhookResource.java index 1cb5aa2..5ceb4b7 100644 --- a/giving-example/src/main/java/com/adyen/giving/api/WebhookResource.java +++ b/giving-example/src/main/java/com/adyen/giving/api/WebhookResource.java @@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -39,7 +40,7 @@ public WebhookResource(ApplicationProperty applicationProperty) { /** * Process incoming Webhook notification: get NotificationRequestItem, validate HMAC signature, - * consume the event asynchronously, send response ["accepted"] + * consume the event asynchronously, send response status 202 * * @param json Payload of the webhook event * @return @@ -70,24 +71,24 @@ public ResponseEntity webhooks(@RequestBody String json) throws Exceptio consumeEvent(item); } else { - // invalid HMAC signature: do not send [accepted] response + // invalid HMAC signature log.warn("Could not validate HMAC signature for incoming webhook message: {}", item); throw new RuntimeException("Invalid HMAC signature"); } } catch (SignatureException e) { - // Unexpected error during HMAC validation: do not send [accepted] response + // Unexpected error during HMAC validation log.error("Error while validating HMAC Key", e); throw new SignatureException(e); } } else { - // Unexpected event with no payload: do not send [accepted] response + // Unexpected event with no payload log.warn("Empty NotificationItem"); - throw new Exception("empty"); + throw new Exception("empty payload"); } // Acknowledge event has been consumed - return ResponseEntity.ok().body("[accepted]"); + return ResponseEntity.status(HttpStatus.ACCEPTED).build(); } // process payload asynchronously diff --git a/in-person-payments-example/src/main/java/com/adyen/ipp/api/WebhookController.java b/in-person-payments-example/src/main/java/com/adyen/ipp/api/WebhookController.java index 26cd88f..32b2100 100644 --- a/in-person-payments-example/src/main/java/com/adyen/ipp/api/WebhookController.java +++ b/in-person-payments-example/src/main/java/com/adyen/ipp/api/WebhookController.java @@ -7,6 +7,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -34,7 +35,7 @@ public WebhookController(ApplicationProperty applicationProperty) { /** * Process the incoming Webhook event: get NotificationRequestItem, validate HMAC signature, - * consume the event asynchronously, send response ["accepted"] + * consume the event asynchronously, send response status 202 * * @param json Payload of the webhook event * @return @@ -54,7 +55,7 @@ public ResponseEntity webhooks(@RequestBody String json) throws IOExcept try { if (!getHmacValidator().validateHMAC(item, this.applicationProperty.getHmacKey())) { - // invalid HMAC signature: do not send [accepted] response + // invalid HMAC signature log.warn("Could not validate HMAC signature for incoming webhook message: {}", item); throw new RuntimeException("Invalid HMAC signature"); } @@ -85,7 +86,7 @@ public ResponseEntity webhooks(@RequestBody String json) throws IOExcept } } catch (SignatureException e) { - // Unexpected error during HMAC validation: do not send [accepted] response + // Unexpected error during HMAC validation log.error("Error while validating HMAC Key", e); throw new RuntimeException(e.getMessage()); } @@ -93,7 +94,7 @@ public ResponseEntity webhooks(@RequestBody String json) throws IOExcept } // Acknowledge event has been consumed - return ResponseEntity.ok().body("[accepted]"); + return ResponseEntity.status(HttpStatus.ACCEPTED).build(); } @Bean diff --git a/paybylink-example/src/main/java/com/adyen/paybylink/api/WebhookController.java b/paybylink-example/src/main/java/com/adyen/paybylink/api/WebhookController.java index 1a82ee5..9ea6faa 100644 --- a/paybylink-example/src/main/java/com/adyen/paybylink/api/WebhookController.java +++ b/paybylink-example/src/main/java/com/adyen/paybylink/api/WebhookController.java @@ -9,6 +9,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -40,7 +41,7 @@ public WebhookController(ApplicationProperty applicationProperty) { /** Process incoming Webhook event: get NotificationRequestItem, validate HMAC signature, * Process the incoming Webhook: get NotificationRequestItem, validate HMAC signature, - * consume the event asynchronously, send response ["accepted"] + * consume the event asynchronously, send response status 202 * * @param json Payload of the webhook event * @return @@ -70,24 +71,24 @@ public ResponseEntity webhooks(@RequestBody String json) throws Exceptio consumeEvent(item); } else { - // invalid HMAC signature: do not send [accepted] response + // invalid HMAC signature log.warn("Could not validate HMAC signature for incoming webhook message: {}", item); throw new RuntimeException("Invalid HMAC signature"); } } catch (SignatureException e) { - // Unexpected error during HMAC validation: do not send [accepted] response + // Unexpected error during HMAC validation log.error("Error while validating HMAC Key", e); throw new SignatureException(e); } } else { - // Unexpected event with no payload: do not send [accepted] response + // Unexpected event with no payload log.warn("Empty NotificationItem"); throw new Exception("empty"); } // Acknowledge event has been consumed - return ResponseEntity.ok().body("[accepted]"); + return ResponseEntity.status(HttpStatus.ACCEPTED).build(); } // process payload asynchronously diff --git a/subscription-example/src/main/java/com/adyen/checkout/api/WebhookResource.java b/subscription-example/src/main/java/com/adyen/checkout/api/WebhookResource.java index abadfdb..b9becdc 100644 --- a/subscription-example/src/main/java/com/adyen/checkout/api/WebhookResource.java +++ b/subscription-example/src/main/java/com/adyen/checkout/api/WebhookResource.java @@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -37,7 +38,7 @@ public WebhookResource(ApplicationProperty applicationProperty) { /** * Process the incoming Webhook event: get NotificationRequestItem, validate HMAC signature, - * consume the event asynchronously, send response ["accepted"] + * consume the event asynchronously, send response status 202 * * @param json Payload of the webhook event * @return @@ -57,7 +58,7 @@ public ResponseEntity webhooks(@RequestBody String json) throws IOExcept try { if (!getHmacValidator().validateHMAC(item, this.applicationProperty.getHmacKey())) { - // invalid HMAC signature: do not send [accepted] response + // invalid HMAC signature log.warn("Could not validate HMAC signature for incoming webhook message: {}", item); throw new RuntimeException("Invalid HMAC signature"); } @@ -86,7 +87,7 @@ public ResponseEntity webhooks(@RequestBody String json) throws IOExcept } } catch (SignatureException e) { - // Unexpected error during HMAC validation: do not send [accepted] response + // Unexpected error during HMAC validation log.error("Error while validating HMAC Key", e); throw new RuntimeException(e.getMessage()); } @@ -94,7 +95,7 @@ public ResponseEntity webhooks(@RequestBody String json) throws IOExcept } // Acknowledge event has been consumed - return ResponseEntity.ok().body("[accepted]"); + return ResponseEntity.status(HttpStatus.ACCEPTED).build(); }