StackupDocs
Stackup

Notifications

Get notified when payments complete via webhooks.

Methods

MethodDescriptionReturns
notifyCreate a webhook handlerRequestHandler

notify

Type (parameters: { secret: string; handler: (event: WebhookEvent) => Promise<void> }) => RequestHandler

Create a webhook handler to receive real-time payment notifications.

export const handler = notify({
  secret: process.env.WEBHOOK_SECRET!,
  handler: async (event) => {
    if (event.type === "payment.succeeded") {
      const { payment } = event.payload
      
      await db.orders.update({
        where: { txHash: payment.txHash },
        data: { status: "paid" }
      })
    }
  }
})

Event Types

EventDescription
payment.succeededPayment completed successfully

Payload Format

{
  "type": "payment.succeeded",
  "payload": {
    "payment": {
      "status": "succeeded",
      "amount": "1000000",
      "tokenAddress": "0x...",
      "txHash": "0x...",
      "blockNumber": 12345678,
      "productID": "prd_..."
    }
  }
}

Security

Webhooks are signed with HMAC-SHA256. The notify helper automatically verifies signatures with a default tolerance of 5 minutes.

Manual Verification

For manual verification, webhooks include these headers:

HeaderDescription
x-webhook-timestampUnix timestamp (seconds) when the webhook was sent
x-webhook-signatureHMAC-SHA256 signature prefixed with sha256=

The signature is computed over {timestamp}.{payload} where payload is the raw request body.

Retry Behavior

Failed deliveries retry up to 3 times with delays: immediate, 5 minutes, 30 minutes.

Types

Endpoint

PropertyTypeDescription
idstringUnique identifier
workspaceIDstringParent workspace
namestringEndpoint display name
urlstringDestination URL
secretstringSigning secret (whsec_...)
eventsstring[]Enabled event types
status"active" | "paused"Delivery status
timeCreatedDateCreation timestamp
timeUpdatedDateLast modification

WebhookEvent

PropertyTypeDescription
type"payment.succeeded"Event name
payloadWebhookEventPayloadEvent data

WebhookEventPayload

PropertyTypeDescription
paymentWebhookPaymentPayment info

WebhookPayment

PropertyTypeDescription
status"succeeded" | "failed"Payment status
amountstringAmount in token's smallest unit
tokenAddressstring | nullToken contract address
txHashstringTransaction hash (0x...)
blockNumbernumberBlock number
productIDstring | nullPurchased product ID

Errors

A list of errors that can be returned by the Notifications API.