table = $this->table('tiki_webhooks'); } public function getWebhooks($conditions = []) { return $this->table->fetchAll([], $conditions, -1, -1, ['webhookId' => 'asc']); } public function getWebhook($webhookId) { return $this->table->fetchFullRow(['webhookId' => (int) $webhookId]); } public function createWebhook($data) { $data['created'] = $this->now; $data['lastModif'] = $this->now; $webhookId = $this->table->insert($data); return $this->getWebhook($webhookId); } public function updateWebhook($webhookId, $data) { $data['lastModif'] = $this->now; $this->table->update($data, ['webhookId' => $webhookId]); return $this->getWebhook($webhookId); } public function deleteWebhook($webhookId) { return $this->table->delete(['webhookId' => $webhookId]); } public function verify($webhook) { $rawData = file_get_contents("php://input"); $headers = getallheaders(); $received = $headers[$webhook['signatureHeader']] ?? ''; switch ($webhook['verification']) { case 'hmac': $computed = hash_hmac('sha256', $rawData, $webhook['secret']); break; case 'base64 hmac': $computed = base64_encode(hash_hmac('sha256', $rawData, $webhook['secret'], true)); break; default: $computed = ''; } if (empty($received) || empty($computed) || $received !== $computed) { return false; } else { return true; } } }