Skip to content

Commit

Permalink
Response code 202
Browse files Browse the repository at this point in the history
  • Loading branch information
gcatanese committed Mar 11, 2024
1 parent ddcc6b3 commit 9a35b19
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/main/kotlin/com/adyen/checkout/api/WebhookResource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import com.adyen.util.HMACValidator
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import java.security.SignatureException
import java.util.function.Consumer

/**
* REST controller for receiving Adyen webhook notifications
Expand Down Expand Up @@ -44,7 +44,7 @@ class WebhookResource @Autowired constructor(@Value("\${ADYEN_HMAC_KEY}") key: S
try {
// We always recommend validating HMAC signature in the webhooks for security reasons, see https://docs.adyen.com/development-resources/webhooks/verify-hmac-signatures
if (!HMACValidator().validateHMAC(item, hmacKey)) {
// Invalid HMAC signature: do not send [accepted] response
// Invalid HMAC signature
log.warn("Could not validate HMAC signature for incoming webhook message: {}", item)
throw RuntimeException("Invalid HMAC signature")
}
Expand All @@ -63,8 +63,9 @@ class WebhookResource @Autowired constructor(@Value("\${ADYEN_HMAC_KEY}") key: S
item.pspReference
)

// Notify the server that we've accepted the payload
return ResponseEntity.ok().body("[accepted]")
// Acknowledge event has been consumed
return ResponseEntity.status(HttpStatus.ACCEPTED).build()

} catch (e: SignatureException) {
log.error("Error while validating HMAC Key", e)
}
Expand Down

0 comments on commit 9a35b19

Please sign in to comment.