Skip to Content
Docs

Webhooks

Receive real-time event notifications from Pay.com to keep your backend systems in sync with payment activity.

Webhooks let Pay.com notify your backend systems about events as they happen, without your server having to poll the API. When something changes in your account (a charge succeeds, a refund is processed, or a payout completes), Pay.com sends an HTTP POST request with a JSON payload to a URL you configure.

When webhooks are required

Webhooks are useful for logging all activity, but they are required for certain asynchronous payment flows:

  • 3D Secure with confirm: true: When you configure a server-to-server 3DS flow with automatic authorization, the charge is authorized before the customer is redirected back to your site. A dropped network connection can prevent the redirect from completing, so you must listen for the charge.succeeded webhook to finalize the order.
  • ACH direct debits: These payment methods don't clear immediately. The API creates a charge with pending status, and the final outcome is delivered only via webhook once the banking network updates Pay.com.
  • Bank transfer payouts: Payouts start as pending, and the final payout.succeeded or payout.failed event arrives asynchronously.

Always verify the signature of every webhook event before processing it. This confirms the event genuinely came from Pay.com and not a third party.

Set up an endpoint in the dashboard

Create the endpoint in the Pay.com dashboard, then copy its signing secret. You can also set up an endpoint with the API.

  1. 1

    Access the dashboard

    Log in to your Pay.com dashboard. In the left sidebar, click Developers, then select Webhooks. This page lists all existing webhook endpoints configured for your account.

  2. 2

    Create a new webhook

    Click + Add Webhook. You are redirected to the Webhook Management page.

    Webhook Management page in the Pay.com dashboard

    Fill in the following fields:

    • Webhook Name: a label to identify this endpoint in the dashboard.
    • Endpoint URL: the public URL on your server that receives the POST requests.
    • Events to send: choose All events to receive every notification, or select individual event types to limit the webhook to a specific use case.

    To get an endpoint running locally, paste this minimal endpoint into a new file. It implements every step in Verify webhook signatures:

    // server.js
    // 1) Install dependencies: npm install express
    // 2) Run: node server.js
    
    const express = require('express')
    const crypto = require('crypto')
    const app = express()
    
    // Your endpoint's signing secret, from your server's environment.
    const webhookSecret = process.env.PAY_COM_WEBHOOK_SECRET
    if (!webhookSecret?.trim()) throw new Error('Set PAY_COM_WEBHOOK_SECRET')
    
    // express.raw keeps the body as the exact bytes Pay.com sent, up to 5 MB.
    app.post('/webhook', express.raw({ type: 'application/json', limit: '5mb' }), (req, res) => {
      const header = req.headers['pay-signature']
      if (!header) return res.status(400).send('Missing Pay-Signature header')
      if (!Buffer.isBuffer(req.body)) return res.status(400).send('Expected a JSON body')
    
      let timestamp
      const signatures = []
      for (const element of header.split(',')) {
        const [prefix, value] = element.split('=', 2)
        if (prefix === 't') timestamp = value
        else if (prefix === 'v1' && value) signatures.push(value)
      }
      if (!timestamp || signatures.length === 0) return res.status(400).send('Malformed Pay-Signature header')
    
      const expected = Buffer.from(
        crypto.createHmac('sha256', webhookSecret).update(`${timestamp}.`).update(req.body).digest('hex'),
        'utf8',
      )
      const signatureMatches = signatures.some((signature) => {
        const received = Buffer.from(signature, 'utf8')
        return received.length === expected.length && crypto.timingSafeEqual(expected, received)
      })
      if (!signatureMatches) return res.status(400).send('Invalid webhook signature')
    
      const event = JSON.parse(req.body.toString('utf8'))
      // Pay.com can send an event more than once: skip one whose event.id you've already handled.
      // Then handle it, for example by event.type.
    
      // Return a 200 response to acknowledge receipt of the event.
      res.status(200).send()
    })
    
    app.listen(4242, () => console.log('Running on port 4242'))

    When you're done, click Save changes to create the webhook.

  3. 3

    Copy your signing secret

    After saving, you are redirected back to the Webhooks list. Click the webhook you created to open its detail page.

    Here you can reveal and copy the signing secret for this endpoint. You use this secret to verify the signature of every incoming event. You can also edit, disable, or delete the webhook from this page.

    A signing secret starts with whsec-pay-com-live-, or with whsec-pay-com-sandbox- in the sandbox. An endpoint made before secrets had a prefix keeps its UUID secret until you roll it.

    Store the signing secret securely and never expose it in client-side code or public repositories.

Set up an endpoint with the API

POST /v1/webhook_endpoints creates an endpoint:

  • url is the public URL on your server that receives the events. It must use https.
  • event_types lists the events to send, at least one.
  • name is optional, and defaults to API.

An API key can subscribe an endpoint only to events about resources it can read. Asking for any other event returns 403 with event_type_not_allowed.

The response is the only one that carries the endpoint's signing secret, in secret, so store it then. Listing or retrieving endpoints never returns it. You can reveal it on the endpoint's page in the dashboard.

Monitor webhook deliveries

Select any webhook from the Developers → Webhooks page to view its delivery log. For each event you can inspect:

  • The event status and HTTP status code.
  • The event ID and when it was created.
  • The full request payload Pay.com sent.
  • The response your server returned.
  • Details about the next retry attempt if the previous delivery failed.

If your server misses an event, you can manually resend it from this view.

Pay.com retries failed deliveries every 15 minutes for up to 24 hours. Retries stop as soon as your server returns a 2xx response.

Verify webhook signatures

Pay.com signs every webhook event with an HMAC-SHA256 signature and includes it in the Pay-Signature HTTP header. Verifying this signature confirms that the event came from Pay.com and has not been tampered with.

The Pay-Signature header contains a timestamp (prefixed by t=), which is when Pay.com signed the request, in milliseconds since the Unix epoch. Then it has a signature (prefixed by v1=). For example:

Pay-Signature: t=1790928292249,v1=1aeb7cc4bf7a95b9dc91e7b72c5f675f5364cba3fc33f6444015f8195fdc7624

The header can carry more than one v1 signature. Accept the event if any of them matches.

  1. 1

    Extract the timestamp and signatures

    Split the Pay-Signature header value on the , character to get a list of elements. Then split each element on the first = to separate the prefix from the value. Reject the request if the header, t, or v1 is missing.

    • The value for prefix t is the timestamp.
    • Each value for prefix v1 is a signature. Keep all of them.

    Ignore any other prefixes to prevent downgrade attacks.

    const header = req.headers['pay-signature'] ?? '';
    let timestamp;
    const signatures = [];
    for (const element of header.split(',')) {
      const [prefix, value] = element.split('=', 2);
      if (prefix === 't') timestamp = value;
      else if (prefix === 'v1' && value) signatures.push(value);
    }
  2. 2

    Build the signed payload string

    Construct the payload that Pay.com signed (t.payload) by concatenating:

    1. The timestamp (as a string).
    2. A literal . character.
    3. The raw JSON request body, exactly as received and before any parsing. Read it as bytes (for example with express.raw() in Express or request.get_data() in Flask) and don't decode it. Anyone can send to your URL, so cap the body's size, at 5 MB for example.
    // rawBody is the Buffer from express.raw()
    const signedPayload = Buffer.concat([Buffer.from(`${timestamp}.`), rawBody]);

    Use the raw request body, not a re-serialized version. Parsing and re-serializing JSON can change whitespace or key ordering, which causes signature verification to fail.

  3. 3

    Compute the expected signature

    Using your endpoint's whole signing secret as the key, prefix included, compute an HMAC with the SHA-256 hash function over the signed payload. Refuse to verify if the secret is missing or blank, because anyone can sign with a blank key.

    const crypto = require('crypto');
    
    if (!YOUR_SIGNING_SECRET?.trim()) throw new Error('Missing signing secret');
    
    const expectedSignature = crypto
      .createHmac('sha256', YOUR_SIGNING_SECRET)
      .update(signedPayload)
      .digest('hex');
  4. 4

    Compare the signatures

    Use a constant-time comparison to compare the expected signature to each received v1 signature, and accept the event if any of them matches. This protects against timing attacks. In Node.js, crypto.timingSafeEqual throws if the two values have different lengths, so check the lengths first and treat a mismatch as an invalid signature. In Python, hmac.compare_digest raises an error for text that isn't ASCII, so compare bytes.

    If none matches, don't return 2xx, or Pay.com won't send that event again.

    const crypto = require('crypto');
    
    const expected = Buffer.from(expectedSignature, 'utf8');
    const isValid = signatures.some((signature) => {
      const received = Buffer.from(signature, 'utf8');
      return received.length === expected.length && crypto.timingSafeEqual(expected, received);
    });
    
    if (!isValid) throw new Error('Invalid signature');
    
    // Signature is valid: safe to process the event.
  5. 5

    Skip events you've already handled

    Keep the id of each event you handle, and skip an event whose id you've already seen. This also stops a replayed request from being handled twice.

Next steps

  • Webhook events: a complete list of all event types Pay.com can send, organized by resource.
  • Webhook endpoints: create, list, retrieve, and delete endpoints with the API.
Was this page helpful?