Skip to Content
Pymstr

Webhooks

Pymstr sends webhook notifications to your server when payment and payout events occur.

Setup

  1. Go to Dashboard > Integration > Webhooks
  2. Enter your endpoint URL.
  3. Save your webhook secret. It starts with whsec_ and is shown only once.

To replace the secret, use Regenerate signing secret on the same page. Deliveries are signed with the new secret at once, so update your server in the same step. A delivery your server rejects before it has the new secret is retried on the retry schedule.

Event Types

EventDescription
payment.*Payment link events, listed on Payments
payout.*Payout events, listed on Payouts
testTest event (sent from the dashboard)

Dashboard-created links only

payment.created and payout.created fire only for links created from the dashboard. Resources you create via the API (pk_ key) do not emit a .created event, because you already have the resource from the 201 Created response.

A failed payment can be credited later

In very rare cases, you get both payment.failed and payment.completed for the same paymentId, in either order. Treat completed as final. The same applies to payout.failed and payout.completed. See Late Credit.

Payload Format

All webhook payloads follow this structure:

{
  "event": "payment.completed",
  "timestamp": "2026-02-24T10:05:00.000Z",
  "data": {
    "paymentId": "01234567-89ab-cdef-0123-456789abcdef",
    "externalId": "order-123"
  }
}

Parameter

Type

For payout.* events, data.payoutId replaces data.paymentId (and data.externalId is the payout's reference):

{
  "event": "payout.completed",
  "timestamp": "2026-02-24T10:05:00.000Z",
  "data": {
    "payoutId": "01234567-89ab-cdef-0123-456789abcdef",
    "externalId": "batch-2026-10"
  }
}

Signature Verification

Every webhook includes these headers:

HeaderDescription
X-Pymstr-TimestampUnix timestamp (seconds), the same value as t in X-Pymstr-Signature
X-Pymstr-SignatureFormat: t=<timestamp>,v1=<signature>
Content-Typeapplication/json

Verification steps

  1. Extract t (timestamp) and v1 (signature) from the X-Pymstr-Signature header
  2. Reject if the timestamp is more than 5 minutes from your server's time, earlier or later (replay protection)
  3. Compute HMAC-SHA256 of {timestamp}.{raw_body} using your webhook secret as the key, the whole string with its whsec_ prefix
  4. Compare your computed signature with v1 using constant-time comparison
import express from 'express'
import { createHmac, timingSafeEqual } from 'crypto'

const app = express()

function verifyWebhook(body, signatureHeader, secret, tolerance = 300) {
  // Parse signature header
  const parts = signatureHeader.split(',')
  const timestamp = parts.find(p => p.startsWith('t='))?.slice(2)
  const signature = parts.find(p => p.startsWith('v1='))?.slice(3)

  if (!timestamp || !signature) {
    throw new Error('Invalid signature format')
  }

  // Reject a timestamp more than 5 minutes from now, earlier or later
  const now = Math.floor(Date.now() / 1000)
  if (Math.abs(now - parseInt(timestamp)) > tolerance) {
    throw new Error('Timestamp outside tolerance')
  }

  // Compute expected signature
  const signedPayload = `${timestamp}.${body}`
  const hmac = createHmac('sha256', secret)
  hmac.update(signedPayload)
  const expected = hmac.digest('hex')

  // Constant-time comparison
  const sigBuffer = Buffer.from(signature, 'hex')
  const expectedBuffer = Buffer.from(expected, 'hex')

  if (sigBuffer.length !== expectedBuffer.length) {
    return false
  }

  return timingSafeEqual(sigBuffer, expectedBuffer)
}

// Express example
app.post('/webhook', express.raw({ type: 'application/json' }), async (req, res) => {
  const signature = req.headers['x-pymstr-signature'] ?? ''
  const body = req.body.toString()

  try {
    if (!verifyWebhook(body, signature, process.env.PYMSTR_WEBHOOK_SECRET)) {
      return res.status(401).send('Invalid signature')
    }
  } catch {
    return res.status(401).send('Invalid signature')
  }

  try {
    const { event, data } = JSON.parse(body)
    if (event === 'payment.completed') {
      // Events can arrive out of order: fetch the current state before acting
      const response = await fetch(`https://api.pymstr.com/v1/payments/${data.paymentId}`, {
        headers: { 'Authorization': `Bearer ${process.env.PYMSTR_API_KEY}` },
      })
      if (!response.ok) throw new Error(`Get Payment answered ${response.status}`)
      const payment = await response.json()
      if (payment.status === 'SUCCESSFUL') {
        // Mark the order for payment.externalId as paid. The same event can arrive twice.
      }
    }
  } catch {
    // Any answer other than 2xx makes Pymstr send the event again
    return res.status(500).send('Try again')
  }

  // Answer 2xx only after the work is done
  res.status(200).send('OK')
})

Source IP Addresses

Webhooks are sent from these addresses: 34.27.107.78, 136.119.23.57. If your endpoint sits behind a firewall or an IP allowlist, allow every one of them. An address check does not replace signature verification.

Retry Schedule

Failed deliveries are retried with exponential backoff:

AttemptDelayCumulative
1Immediate0
21 minute1 minute
35 minutes6 minutes
430 minutes36 minutes
52 hours2h 36m
68 hours10h 36m
724 hours34h 36m

After 7 attempts, the delivery is marked as failed. Total retry window: ~34.5 hours.

A delivery is considered successful on any HTTP 2xx response. All other responses (4xx, 5xx, timeouts, connection errors) trigger a retry. Each attempt carries a new timestamp and signature.

Test Webhook

To verify your endpoint, use Dashboard > Integration > Webhooks > Send test event. Pymstr sends a test event to your saved webhook URL and shows whether your endpoint answered with a 2xx. The test event has no data field:

{
  "event": "test",
  "timestamp": "2026-02-24T10:05:00.000Z"
}

Best Practices

  • Answer after the work is done. Return a 2xx only once you have handled or stored the event, because a failure after a 2xx is never retried. The request times out after 10 seconds, so store the event and finish longer work from your own queue.
  • Verify signatures. Always validate X-Pymstr-Signature and check the timestamp is within 5 minutes.
  • Be idempotent. Use paymentId (or payoutId) + event as a deduplication key. While Pymstr deduplicates on its end, network issues can cause duplicate deliveries.
  • Fetch current state. Events may arrive out of order. Always call GET /v1/payments/:id (or GET /v1/payouts/:id) to get the authoritative status before acting on an event. Mark an order paid only when status is SUCCESSFUL.
  • Use HTTPS. Pymstr only delivers to an https:// URL.