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.

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

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

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-Countryand to the mode of the key that created it. Endpoints made with ask_test_key receive only test-mode events, and endpoints made with ask_live_key only live-mode events. enabled_eventslists the event types to send, or["*"]for all of them. See Event types.api_versionis 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 is2026-11-01. See Event payload and API versions.
Manage endpoints
| Action | Request |
|---|---|
| List endpoints | GET /webhook_endpoints |
| Retrieve one | GET /webhook_endpoints/{id} |
| Change one | PATCH /webhook_endpoints/{id} with any of url, description, enabled_events, status, timestamp_tolerance_sec, api_version |
| Roll the secret | POST /webhook_endpoints/{id}/rotate_secret; the response holds the new secret |
| Delete one | DELETE /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_eventsin aPATCHreplaces 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:
| Resource | Events |
|---|---|
| Charges | charge.created, charge.updated, charge.paid, charge.captured, charge.failed, charge.canceled, charge.expired, charge.requires_action, charge.refunded |
| Disputes | charge.dispute.created, charge.dispute.updated, charge.dispute.closed, charge.dispute.funds_withdrawn, charge.dispute.funds_reinstated |
| Payment intents | payment_intent.succeeded, payment_intent.canceled, payment_intent.payment_failed |
| Checkout sessions | checkout.session.completed, checkout.session.expired |
| Payment links | payment_link.created, payment_link.updated |
| Refunds | refund.created, refund.updated, refund.failed |
| Customers | customer.created, customer.updated, customer.deleted, customer.tax_id.created, customer.tax_id.updated, customer.tax_id.deleted |
| Payment methods | payment_method.created, payment_method.updated, payment_method.deleted |
| Bank accounts | bank_account.created, bank_account.deleted |
| Invoices | invoice.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 notes | credit_note.created, credit_note.issued, credit_note.applied, credit_note.voided, credit_note.updated |
| Subscriptions | subscription.created, subscription.updated, subscription.paused, subscription.resumed, subscription.canceled, subscription.trial_will_end |
| Subscription schedules | subscription_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 |
| Quotes | quote.created, quote.finalized, quote.accepted, quote.canceled |
| Products and prices | product.created, product.updated, product.deleted, price.created, price.updated, price.deleted |
| Coupons and promotion codes | coupon.created, coupon.updated, coupon.deleted, promotion_code.created, promotion_code.updated, promotion_code.deleted |
| Shipping and tax rates | shipping_rate.created, shipping_rate.updated, shipping_rate.deleted, tax_rate.created, tax_rate.updated |
| Billing portal | billing_portal.configuration.created, billing_portal.configuration.updated, billing_portal.session.created |
| Payouts | payout.created, payout.approved, payout.pending, payout.sent, payout.paid, payout.canceled, payout.failed |
| Application fees | application_fee.created, application_fee.refunded, application_fee.refund.updated |
| Provider credentials | provider.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"
}| Field | Description |
|---|---|
id | The event's id, the same on every retry; GET /events/{id} returns this delivery. |
object | Always "event". |
api_version | The endpoint's API version; today always 2026-11-01. |
created | When the event happened, in Unix seconds. |
data.object | The object, shaped as the API returns it. |
livemode | false for test-mode events. |
type | The 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:
| Header | Value |
|---|---|
Content-Type | application/json |
Paycose-Signature | t=<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-Event | The event type, such as invoice.paid. |
X-Webhook-Timestamp | When the event happened, in Unix seconds. Retries send the same value. |
X-Webhook-Signature | The HMAC-SHA256 of the raw body alone, keyed with the endpoint's secret, as lowercase hex. |
Idempotency-Key | The 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
2xxstatus. 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
failedand 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"| Field | Description |
|---|---|
job_id | The delivery id, sent as the Idempotency-Key header. |
event | The event type. |
endpoint_id | The endpoint it was sent to. |
status | pending while attempts remain, delivered, or failed. |
attempts | Failed attempts so far. |
last_response_code, last_error, failed_at | What the last attempt got, when the delivery failed. |
data | The 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.