22 private $allowedTopicValues = [
26 'guarantees/completion',
49 $this->decoder = $decoder;
60 $body = $webhookRequest->
getBody();
62 $hash = $webhookRequest->
getHash();
64 return $this->isValidTopic($eventTopic)
65 && $this->isValidBody($body)
66 && $this->isValidHash($eventTopic, $body, $hash);
75 private function isValidTopic($topic)
77 return in_array($topic, $this->allowedTopicValues);
86 private function isValidBody($body)
89 $decodedBody = $this->decoder->decode($body);
90 }
catch (\Exception $e) {
94 return !empty($decodedBody);
105 private function isValidHash($eventTopic, $body, $hash)
108 $apiKey = $eventTopic ==
'cases/test' ?
'ABCDE' : $this->config->getApiKey();
109 $actualHash = base64_encode(hash_hmac(
'sha256', $body, $apiKey,
true));
111 return $hash === $actualHash;
validate(WebhookRequest $webhookRequest)
__construct(Config $config, DecoderInterface $decoder)