Crear un destino

POST/webhooks.php
Terminal
curl "https://circus-pay.com/api/webhooks.php" \
  -H "Authorization: Bearer $CIRCUSPAY_SECRET_KEY" \
  -H "Content-Type: application/json" \
  --data '{
  "url": "https://example.com/webhooks/circuspay",
  "events": [
    "payment.succeeded",
    "payment.failed",
    "payment.refunded"
  ],
  "description": "Boutique principale"
}'

Guarda el webhook.secret recibido al crear el webhook en CIRCUSPAY_WEBHOOK_SECRET. Sirve para verificar las firmas y es distinto de la clave API.

Verificar la firma

X-ONIPAY-Signature contiene el HMAC-SHA256 hexadecimal del cuerpo HTTP sin modificar, calculado con el secreto del webhook. Verifica el cuerpo exacto recibido antes de volver a codificar el JSON.

PHP · verificación de firma
<?php
$raw = file_get_contents('php://input');
$received = $_SERVER['HTTP_X_ONIPAY_SIGNATURE'] ?? '';
$secret = getenv('CIRCUSPAY_WEBHOOK_SECRET');
if (!$secret || !preg_match('/^[a-f0-9]{64}$/', $received)) {
    http_response_code(400); exit;
}
$expected = hash_hmac('sha256', $raw, $secret);
if (!hash_equals($expected, $received)) {
    http_response_code(400); exit;
}
$event = json_decode($raw, true);
if (!is_array($event)) { http_response_code(400); exit; }
// Persist the event durably before returning 2xx.
// Deduplicate fulfilment by your order + transaction reference.
// Verify order, amount, currency and final status server-side.
// Return 5xx if durable processing/queuing fails.

Procesar los eventos

ParámetroDescripción
payment.succeededVerifica el pago y confirma el pedido una sola vez.
payment.failedRegistra el intento fallido sin confirmar el pedido.
payment.refundedSincroniza el estado del reembolso.
webhook.testPrueba técnica del destino. No provoca la entrega de ningún pedido.

Los eventos de pago usan un sobre con type, created y data. El contenido de data depende del flujo. No supongas que todos los eventos tienen el mismo esquema; concilia las referencias con tus transacciones.

Probar la recepción

POST/webhooks.php?action=test
Terminal
curl "https://circus-pay.com/api/webhooks.php?action=test" \
  -H "Authorization: Bearer $CIRCUSPAY_SECRET_KEY" \
  -H "Content-Type: application/json" \
  --data '{
  "id": 123
}'

Consultar las entregas

GET/webhooks.php?id=123&logs=1
Terminal
curl "https://circus-pay.com/api/webhooks.php?id=123&logs=1" \
  -H "Authorization: Bearer $CIRCUSPAY_SECRET_KEY"

Sustituye 123 por tu ID de webhook. La respuesta logs contiene las últimas 50 entregas, con el código HTTP, la duración y cualquier error.