How to receive webhooks

Optionally, CardPlusPay can POST a signed JSON notification to a URL you set on your API key. Order events are on by default. Catalog events are opt-in. Polling GET /orders/{id} stays fully supported. You do not need webhooks to complete an integration.

When to use this

  • Optional — If you never set a webhook URL, CardPlusPay does not POST to you. Use GET /orders/{id} as today.
  • Faster notification — Receive order and (if you opt in) catalog events without waiting for your next poll or catalog refresh.
  • Still poll when needed — If you do not use webhooks, you must poll while an order is pending. Even with webhooks, poll after timeouts, missed POSTs, or as a backup. Webhook payloads do not include gift card codes; load codes from GET /orders/{id} after order.completed.

A failed or slow webhook does not change the order or your API wallet. Fulfillment continues independently of your receiver. Deliveries are at-least-once: the same event can be POSTed more than once. They are not exactly-once. Persist id (same value as webhook-id) and skip side effects on duplicates.

Step 1: Set a webhook URL on your API key

  1. In the CardPlusPay Dashboard, open API Keys.
  2. Set Webhook URL on the key (Edit). The URL must be HTTPS. Private or loopback hosts are rejected.
  3. When you first save a URL (or rotate the secret), CardPlusPay shows a signing secret once. It starts with whsec_. Store it in your secrets manager. It is not shown again.
  4. Open the key Details page and use the Webhooks card for events, Send test, delivery logs, and Replay.

Clear the URL to stop sending. Empty URL does not mint a new secret. If the dashboard asks you to rotate the webhook signing secret, POSTs are paused until you rotate (a new whsec_ is shown once). After a rotate, CardPlusPay dual-signs with the previous secret for 24 hours so you can roll receivers.

On Details you can uncheck order events (they are optional) and check catalog events (off until you opt in). Saving no events means CardPlusPay will not send order or catalog POSTs; Send test still works.

Step 2: Understand events

There is no order.pending event. Pending is data.status on order.created. There is no previous_status field; the event name is the transition.

Event Default When
order.created On An order exists after POST /orders. data.status may be pending or completed.
order.completed On Status becomes completed. If POST /orders already returns completed, you also receive this as a second POST (two deliveries, two ids). Later settlement of a pending order sends only this event (not created again).
order.failed On Status becomes failed (including a pending order that later fails).
catalog.availability_changed Off A listed catalog item’s in-stock flag changes. data includes item_code, in_stock, and charged_price when present.
catalog.charged_price_changed Off A listed item’s charged_price changes. data includes item_code, in_stock, charged_price.
catalog.removed Off An item is unpublished from the public catalog. data is item_code only.
webhook.test — Dashboard Send test only. data is { "ok": true }. Does not create or change orders.
Purchase result Webhooks
Sync completed in POST /orders order.created then order.completed (two POSTs, two ids)
Pending then later success order.created (status: pending) then later order.completed
Pending then later fail order.created (status: pending) then later order.failed
Idempotent POST /orders replay (same Idempotency-Key and body) HTTP 200 with the stored order. No second order.created.

Step 3: Headers and body

CardPlusPay POSTs to your HTTPS URL. This is not a path on api.cardpluspay.com. Signing follows Standard Webhooks v1. Redirects are not followed: the POST uses the exact URL you saved; an HTTP 3xx is a failed delivery.

Header Meaning
Content-Typeapplication/json
webhook-idStable event id. Same value as JSON id. Retries, Replay, and crash-retries reuse it. Use this for idempotency.
webhook-timestampUnix seconds included in the signed content. Reject if |now − timestamp| > 300 (libraries do this).
webhook-signatureStandard Webhooks signatures (v1,<base64>). HMAC-SHA256 of {webhook-id}.{webhook-timestamp}.{raw body} using your whsec_ secret. After rotate, this header may contain several space-separated signatures (current and previous).
X-Webhook-EventEvent name. Convenience only — not part of the signed content.
X-Webhook-Delivery-AttemptAttempt number (1, 2, …). Informational only. Do not use it for idempotency.
{
  "event": "order.created",
  "id": "wh_...",
  "created_at": "2026-09-13T00:00:00+00:00",
  "data": {
    "order_id": 123,
    "order_no": "ORD-...",
    "status": "pending",
    "amount": 5.5
  }
}
{
  "event": "catalog.availability_changed",
  "id": "wh_...",
  "created_at": "2026-09-13T00:00:00+00:00",
  "data": {
    "item_code": "GOOGLE-5USD-KOXx",
    "in_stock": true,
    "charged_price": 5.5
  }
}

Treat JSON id (and webhook-id) as idempotent: process each id once. Automatic retries, dashboard Replay, and a recovered send after a crash reuse the same id and the same JSON body. Return 2xx to acknowledge. This payload does not include gift card codes.

Step 4: Verify the signature

Use a Standard Webhooks library (PHP, Node, Python, Go, and others). Verify with the raw request body and the three webhook-* headers. Do not re-encode JSON. Constant-time compare is handled by the library.

<?php
$secret = getenv('CARDPLUSPAY_WEBHOOK_SECRET'); // whsec_...
$raw = file_get_contents('php://input');
$headers = [
    'webhook-id' => $_SERVER['HTTP_WEBHOOK_ID'] ?? '',
    'webhook-timestamp' => $_SERVER['HTTP_WEBHOOK_TIMESTAMP'] ?? '',
    'webhook-signature' => $_SERVER['HTTP_WEBHOOK_SIGNATURE'] ?? '',
];

try {
    $wh = new \StandardWebhooks\Webhook($secret);
    $verified = $wh->verify($raw, $headers);
} catch (\Throwable $e) {
    http_response_code(401);
    exit;
}

$payload = json_decode($verified, true);
$eventId = $payload['id'] ?? $headers['webhook-id'];
// Persist $eventId. If you already processed it, return 200 and do nothing else.
http_response_code(200);

Step 5: Acknowledge, retries, and dashboard

  • Return any 2xx as soon as you have accepted the event (after signature check and idempotent persist).
  • Non-2xx and timeouts are retried with backoff for up to about 48 hours. Each retry keeps the same id. If your response includes Retry-After, CardPlusPay waits at least that long, capped at 1 hour.
  • HTTP 410 Gone stops further POSTs until you re-enable webhooks on the key. Repeated consecutive failures can also disable delivery; re-enable from Details.
  • Send test queues webhook.test. Replay sends the same message again (next attempt number, same id).

Step 6: Load codes via GET

After order.completed, call GET /orders/{order_id} to retrieve gift card codes (or confirm delivery.status for direct top-up). See order status & polling.

← Order status · Integration Guide · List orders & balance →