Skip to Content
Paycose Docs
Features

Webhooks

Receive signed event notifications on your server — register endpoints, choose events, read the event payload, verify signatures, and handle retries.

A webhook tells your server that something happened — a charge was paid, a refund failed, an invoice became overdue — as it happens, so you don't have to poll for it. You register an HTTPS URL as a webhook endpoint, choose the events it receives, and Paycose sends each event to it as a signed POST.

Register an endpoint

In the Dashboard:

Open Developer → Webhook and choose New endpoint.

The webhook endpoints list

Enter your HTTPS URL and pick the events to send (all events by default).

A new webhook endpoint

Copy the signing secret: it is shown once, and you need it to verify signatures.

The signing secret, shown once

Or with the API:

curl "$WALLET/webhook_endpoints" \
  -H "Authorization: Bearer ${SECRET_KEY}" \
  -H "X-Country: TH" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/webhooks/paycose",
    "description": "Order service",
    "enabled_events": ["charge.paid", "refund.updated", "invoice.paid"]
  }'
{
  "id": "we_2c7e9a1b3d5f4e6a8c0b2d4f6a8e0c1b",
  "object": "webhook_endpoint",
  "url": "https://example.com/webhooks/paycose",
  "description": "Order service",
  "enabled_events": ["charge.paid", "refund.updated", "invoice.paid"],
  "secret": "q3Jx0b8ZcVt1yW4nE6uLr2sKf9pAhGdM7iOeTlXwUvY",
  "status": "active",
  "api_version": "2026-11-01",
  "timestamp_tolerance_sec": 300
}

The response above shows the main fields. Keep these points in mind:

  • The secret signs every delivery. It is returned only when the endpoint is created and when you roll it. Store it with your other secrets.
  • The URL must use HTTPS and be reachable from the public internet. A country can have one endpoint per URL; a second one is refused with 409 (webhook_endpoint.already_exists).
  • Country and mode. An endpoint belongs to the country in X-Country and to the mode of the key that created it. Endpoints made with a sk_test_ key receive only test-mode events, and endpoints made with a sk_live_ key only live-mode events.
  • enabled_events lists the event types to send, or ["*"] for all of them. See Event types.
  • api_version is the API version the endpoint's events are sent in. Send it to choose one; it defaults to the version of the request that created the endpoint. Today the only version is 2026-11-01. See Event payload and API versions.

Manage endpoints

ActionRequest
List endpointsGET /webhook_endpoints
Retrieve oneGET /webhook_endpoints/{id}
Change onePATCH /webhook_endpoints/{id} with any of url, description, enabled_events, status, timestamp_tolerance_sec, api_version
Roll the secretPOST /webhook_endpoints/{id}/rotate_secret; the response holds the new secret
Delete oneDELETE /webhook_endpoints/{id}
  • Pause deliveries with "status": "disabled", and resume them with "status": "active". While an endpoint is disabled, nothing is sent to it, and deliveries still waiting to be retried are dropped.
  • enabled_events in a PATCH replaces the whole list.
  • Rolling the secret takes effect at once: the next delivery, including a retry of an earlier event, is signed with the new secret. To switch without failed deliveries, let your server accept a signature from either the old or the new secret until the roll is done, then drop the old one.

Event types

These are the names you can put in enabled_events:

ResourceEvents
Chargescharge.created, charge.updated, charge.paid, charge.captured, charge.failed, charge.canceled, charge.expired, charge.requires_action, charge.refunded
Disputescharge.dispute.created, charge.dispute.updated, charge.dispute.closed, charge.dispute.funds_withdrawn, charge.dispute.funds_reinstated
Payment intentspayment_intent.succeeded, payment_intent.canceled, payment_intent.payment_failed
Checkout sessionscheckout.session.completed, checkout.session.expired
Payment linkspayment_link.created, payment_link.updated
Refundsrefund.created, refund.updated, refund.failed
Customerscustomer.created, customer.updated, customer.deleted, customer.tax_id.created, customer.tax_id.updated, customer.tax_id.deleted
Payment methodspayment_method.created, payment_method.updated, payment_method.deleted
Bank accountsbank_account.created, bank_account.deleted
Invoicesinvoice.created, invoice.updated, invoice.finalized, invoice.finalization_failed, invoice.sent, invoice.paid, invoice.payment_failed, invoice.payment_action_required, invoice.overdue, invoice.uncollectible, invoice.void, invoice.creditnote.updated
Credit notescredit_note.created, credit_note.issued, credit_note.applied, credit_note.voided, credit_note.updated
Subscriptionssubscription.created, subscription.updated, subscription.paused, subscription.resumed, subscription.canceled, subscription.trial_will_end
Subscription schedulessubscription_schedule.created, subscription_schedule.updated, subscription_schedule.canceled, subscription_schedule.completed, subscription_schedule.released, subscription_schedule.expiring, subscription_schedule.aborted — reserved, never sent: schedules are not supported
Quotesquote.created, quote.finalized, quote.accepted, quote.canceled
Products and pricesproduct.created, product.updated, product.deleted, price.created, price.updated, price.deleted
Coupons and promotion codescoupon.created, coupon.updated, coupon.deleted, promotion_code.created, promotion_code.updated, promotion_code.deleted
Shipping and tax ratesshipping_rate.created, shipping_rate.updated, shipping_rate.deleted, tax_rate.created, tax_rate.updated
Billing portalbilling_portal.configuration.created, billing_portal.configuration.updated, billing_portal.session.created
Payoutspayout.created, payout.approved, payout.pending, payout.sent, payout.paid, payout.canceled, payout.failed
Application feesapplication_fee.created, application_fee.refunded, application_fee.refund.updated
Provider credentialsprovider.credentials_invalid, provider.credentials_restored

Retired names are refused when you create an endpoint and dropped when you update one: refund.approved, refund.rejected, refund.canceled and credit_note.canceled. An endpoint that already listed one of them also receives its replacement: refund.updated for refund.approved and refund.canceled, refund.failed for refund.rejected, and credit_note.voided for credit_note.canceled.

An event's data is the object it is about, in the same shape that object has in API responses. A .deleted event carries the object as it was just before it was deleted. Two families send a summary instead: payment_intent.* sends the intent's status, amounts and outcome, and provider.* sends a provider_credential_state.

The event pages describe the data of each event family.

Event payload

Every delivery's body is an event object:

{
  "id": "evt_0c1f4e2a9b7d4e6f8a1c3e5b7d9f0a2c",
  "object": "event",
  "api_version": "2026-11-01",
  "created": 1793494800,
  "data": {
    "object": {
      "id": "in_5e7a2c9d1b3f4a6e8c0d2b4f6a8c0e1d",
      "object": "invoice",
      "status": "paid",
      "currency": "thb",
      "amount_due": 49900,
      "created": 1793491200,
      "metadata": { "order_id": "SO-1042" }
    }
  },
  "livemode": false,
  "type": "invoice.paid"
}
FieldDescription
idThe event's id, the same on every retry; GET /events/{id} returns this delivery.
objectAlways "event".
api_versionThe endpoint's API version; today always 2026-11-01.
createdWhen the event happened, in Unix seconds.
data.objectThe object, shaped as the API returns it.
livemodefalse for test-mode events.
typeThe event type.

The example shows a few fields of the invoice; the real data.object carries the whole object.

Delivery headers

Every delivery is a POST with these headers:

HeaderValue
Content-Typeapplication/json
Paycose-Signaturet=<unix seconds>,v1=<signature>. t is when this attempt was sent; v1 is the HMAC-SHA256 of <t>.<raw body>, keyed with the endpoint's secret, as lowercase hex. Every attempt is signed afresh.
X-Webhook-EventThe event type, such as invoice.paid.
X-Webhook-TimestampWhen the event happened, in Unix seconds. Retries send the same value.
X-Webhook-SignatureThe HMAC-SHA256 of the raw body alone, keyed with the endpoint's secret, as lowercase hex.
Idempotency-KeyThe id of this delivery. Retries send the same value.

Verify the signature

Check every delivery before you act on it by verifying Paycose-Signature. It signs the send time with the body, so a delivery replayed later fails.

Read the raw body

Compute the signature over the exact bytes you received, before any JSON parsing. Re-encoded JSON will not match.

Compute the HMAC

Split Paycose-Signature into t and v1, and take the HMAC-SHA256 of <t>.<raw body> (the timestamp, a dot, then the body). Key it with the endpoint's secret as you received it (don't base64-decode it) and hex-encode the result.

Compare in constant time

Compare your result with v1 using a constant-time comparison, and reject the delivery if they differ.

Check the timestamp

Reject a delivery whose t is more than a few minutes from your clock; the samples allow 5 minutes.

Skip deliveries you have handled

Store each Idempotency-Key you process, and answer 200 without doing the work again when one comes back.

import crypto from 'node:crypto';
import express from 'express';

const secret = process.env.PAYCOSE_WEBHOOK_SECRET;
const TOLERANCE_SECONDS = 5 * 60;

function verify(req) {
  const header = req.get('Paycose-Signature') ?? '';
  const parts = Object.fromEntries(header.split(',').map((kv) => kv.split('=')));
  const t = Number(parts.t);
  if (!Number.isFinite(t) || Math.abs(Math.floor(Date.now() / 1000) - t) > TOLERANCE_SECONDS) return false;
  const expected = crypto
    .createHmac('sha256', secret)
    .update(Buffer.concat([Buffer.from(`${t}.`), req.body]))
    .digest();
  const given = Buffer.from(parts.v1 ?? '', 'hex');
  return given.length === expected.length && crypto.timingSafeEqual(given, expected);
}

const app = express();

app.post('/webhooks/paycose', express.raw({ type: 'application/json' }), async (req, res) => {
  if (!verify(req)) return res.sendStatus(400);
  const deliveryId = req.get('Idempotency-Key');
  if (await alreadyHandled(deliveryId)) return res.sendStatus(200); // your own store

  const event = JSON.parse(req.body.toString('utf8'));
  await queueForProcessing(deliveryId, event.type, event.data.object); // your own queue
  res.sendStatus(200);
});

The endpoint's timestamp_tolerance_sec (default 300) is stored for your own use; Paycose does not apply it when sending. Use it as your Paycose-Signature tolerance if you keep the setting with the endpoint.

Responses and retries

  • Answer within 20 seconds with a 2xx status. Anything else — another status, a timeout, a refused connection — counts as a failed attempt. Do slow work after you answer.
  • Failed deliveries are retried with the same body and headers. A delivery gets five attempts in all: the first, then retries about 5 minutes, 30 minutes, 2 hours and 24 hours after each failure. After the fifth failure it is marked failed and not sent again.
  • Events can arrive more than once and out of order. A retry can overlap a later event. Skip deliveries you have handled, and read the object's current state from the API when order matters.
  • Disabled and deleted endpoints. Deliveries waiting for a disabled endpoint are dropped. Deliveries for a deleted endpoint keep failing until their attempts run out.

Delivery log

GET /webhook/events lists your deliveries and their outcome, newest first:

curl -g "$WALLET/webhook/events?filter[status]=failed" \
  -H "Authorization: Bearer ${SECRET_KEY}" \
  -H "X-Country: TH"
FieldDescription
job_idThe delivery id, sent as the Idempotency-Key header.
eventThe event type.
endpoint_idThe endpoint it was sent to.
statuspending while attempts remain, delivered, or failed.
attemptsFailed attempts so far.
last_response_code, last_error, failed_atWhat the last attempt got, when the delivery failed.
dataThe event data.

You can filter by status, event, endpoint_id and job_id. Each entry has object: "webhook_event", and its event_id is the id of the event it delivered.

Test your endpoint

Create an endpoint with your sk_test_ key, then act in test mode — create a customer, pay a test invoice — and watch the deliveries arrive and appear in the delivery log. Test-mode events never reach live endpoints, and live events never reach test endpoints.

What's next

On this page