Skip to main content
Webhooks let your server receive real-time HTTP callbacks when events happen in your AnySpend organization — payments completing, checkouts expiring, and more. Instead of polling the API, you register a URL and AnySpend pushes events to you.

How It Works

1

Register a webhook endpoint

Create a webhook via the Dashboard or the API, specifying the URL and which events to subscribe to.
2

AnySpend sends events

When a subscribed event occurs, AnySpend sends a POST request to your URL with a JSON payload and a signature header.
3

Verify and process

Your server verifies the HMAC-SHA256 signature, processes the event, and responds with a 200 status within 30 seconds.
4

Automatic retries

If your server does not respond with a 2xx status, AnySpend retries up to 3 times with exponential backoff.

Supported Events

You can subscribe to all events by passing ["*"] as the events array, or pick only the ones you need.

Creating a Webhook

Webhook Payload

Every webhook delivery sends a POST request with the following JSON body:

Headers

Reconciling Payments with Your System

The payment.completed webhook always includes a checkoutSession block containing clientReferenceId, metadata, customerEmail, and customerName — everything you need to match payments to your internal records.

Using client_reference_id

Pass your order or user ID when creating the checkout (via URL parameter or API):

Using metadata

For richer data, use metadata key-value pairs:
Both client_reference_id and metadata are always included in the webhook payload. You can set them via URL parameters for simple integrations or the Checkout Sessions API for server-side control.

Verifying Signatures

Always verify the X-AnySpend-Signature header before processing a webhook. Without verification, an attacker could send forged events to your endpoint.
The signature is computed as:

Express.js (Node.js)

Python (Flask)

Retry Policy

If your endpoint does not respond with a 2xx status code within 30 seconds, AnySpend marks the delivery as failed and retries. After 3 failed retries, the delivery is marked as failed permanently. You can still manually retry it from the Dashboard or API.
If your endpoint consistently fails (10+ consecutive failed deliveries), the webhook will be automatically disabled and you will receive an email notification. Re-enable it from the Dashboard after fixing the issue.

Viewing Delivery History

Retrying Failed Deliveries

Testing Webhooks

Use the test endpoint to send a synthetic event to your webhook URL. This helps verify your endpoint is reachable and your signature verification logic is correct.
The test event uses the payment.completed event type with mock data. Your handler should process it like any other event, but you can check for the X-AnySpend-Test: true header if you want to skip side effects during testing.

Best Practices

Respond quickly

Return a 200 immediately and process the event asynchronously (e.g., in a background job queue). Webhook deliveries time out after 30 seconds.

Handle duplicates

Use the X-AnySpend-Delivery-Id header or data.id field to deduplicate events. Retries may deliver the same event more than once.

Verify signatures

Always verify the X-AnySpend-Signature header. Never trust the payload without verification.

Use HTTPS

Webhook URLs must use HTTPS in production. HTTP URLs are only allowed for localhost during development.