PayclaveDocs

Payclave developers

Webhooks

Verify raw-body signatures, deduplicate events, and recover failed deliveries.

Register an endpoint

Webhooks let your backend react when payment state changes, even after the customer leaves checkout. Use invoice.paid for order fulfillment. Subscribe to other events only when your application has a handler for them; payment and delivery events can support customer updates and operational monitoring.

Register your server's HTTPS webhook URL and subscribe to the events your integration handles. Store the endpoint secret securely on your server.

bash
curl https://api.payclave.com/v1/webhook-endpoints \  -H "Authorization: Bearer sk_test_..." \  -H "Content-Type: application/json" \  -d '{    "url": "https://merchant.example/webhooks/payclave",    "eventTypes": ["invoice.paid", "payment.failed"]  }'

Configure the endpoint in the same mode as the checkout. Use the signing secret for that endpoint when verifying its deliveries. A webhook signing secret and an API key have different jobs; using the API key to verify a webhook will fail.

Verify deliveries

Read the unmodified raw body and verify the HMAC SHA-256 signature from X-Payclave-Signature. The server SDK verifies the signature and timestamp before returning the event.

Read request.text() before parsing JSON. Reformatting or serializing the body changes the bytes that were signed. If your framework parses bodies automatically, preserve the raw body for this route. Reject a delivery if signature or timestamp validation fails, and never execute fulfillment code for that request.

typescript
import { constructPayclaveWebhookEvent } from "@payclave/sdk-server"
type EventStore = { processOnce(eventId: string, handler: () => Promise<void>): Promise<void>}
declare const eventStore: EventStoredeclare function queueFulfillment(data: unknown): Promise<void>
export async function verifyPayclaveWebhook(request: Request) { const rawBody = await request.text() const signature = request.headers.get("X-Payclave-Signature") ?? ""
const event = constructPayclaveWebhookEvent({ payload: rawBody, signature, secret: process.env.PAYCLAVE_WEBHOOK_SECRET!, })
const expectedMode = process.env.PAYCLAVE_MODE if (expectedMode !== "test" && expectedMode !== "live") { throw new Error("Set PAYCLAVE_MODE to test or live") } if (event.mode !== expectedMode) { return new Response(null, { status: 204 }) }
await eventStore.processOnce(event.id, async () => { if (event.type === "invoice.paid" && event.data.test !== true) { // Validate the invoice against your stored order before fulfillment. await queueFulfillment(event.data) } })
return new Response(null, { status: 204 })}

The example leaves eventStore.processOnce and queueFulfillment to your application. Store processed event IDs durably and make the order update safe to retry. A process restart must not forget which orders were already fulfilled. Set PAYCLAVE_MODE explicitly so a test event cannot update a live order.

Record the accepted job or order update before marking an event complete. If fulfillment runs in another system, give that job its own stable idempotency key. A crash between accepting the event and carrying out the order must leave enough stored state to resume without sending goods or granting access twice.

Fulfill once
Implement processOnce with durable, atomic storage. Confirm the invoice belongs to the expected merchant order, amount, and mode. Test webhook deliveries do not represent real payments. Never fulfill from a browser redirect or an unverified event.

Respond with a successful HTTP status after durable processing or durable enqueueing. Deliveries may retry; deduplicate by event ID. Inspect delivery status, response codes, attempt logs, and manual replay in the dashboard. A replay must remain safe.

Recover failed deliveries

Inspect the delivery's response code and attempts when an event does not reach your handler. Fix the endpoint URL, signature configuration, or application error before requesting a replay. If your handler received the event but lost its response, the replay may contain work you already completed. Return success for an event your server has already processed safely.

Keep long-running fulfillment work outside the HTTP request after recording it durably. If you have not accepted the work durably, return a failure so delivery can be retried. A successful response tells Payclave your endpoint accepted that delivery.

Retry schedule and secret rotation

Any 2xx response acknowledges a delivery. Failed deliveries retry after one minute, five minutes, thirty minutes, and two hours. A fifth failed attempt ends automatic retries. Review the attempt history, fix the handler, then request replay for recoverable failures.

Secret rotation and webhook incidents require merchant feature access. Read the endpoint's secret status, coordinate the replacement with your server verifier, and follow the returned overlap and retirement state. Keep secrets out of logs. Do not repeatedly rotate a key to resolve a raw-body parsing error; correct signature verification first.

Endpoint status, rotation, replay, and incident contracts

Events

EventDescription
marketplace.paidEvery recipient independently credited; issuer-only parent event. Separate transactions are not atomic.
invoice.issuedAn itemized draft was issued and made collectible.
invoice.paidThe invoice has been fully paid. Validate its mode and order facts before fulfillment.
invoice.partially_paidA verified payment reduced the collectible remainder.
invoice.past_dueAn issued collectible invoice passed its due date.
invoice.overpaidCredited payment exceeds the commercial total. Review the excess separately.
invoice.voidedInvoice collection was voided; prior payment records remain intact.
invoice.uncollectibleThe merchant marked the remaining collection uncollectible.
invoice.refund_recordedA merchant-sent refund was recorded. Payclave never sends refunds; check verificationStatus before treating it as sent.
invoice.refund_verifiedPayclave verified onchain that a recorded refund moved from the settlement wallet to the refund address.
invoice.refund_failedA recorded refund could not be verified onchain. verificationFailureReason explains why; its amount is refundable again.
invoice.payment_received_after_voidA payment arrived for a voided invoice. Review it without reopening or automatically fulfilling the invoice.
invoice.payment_received_after_uncollectibleA payment arrived for an uncollectible invoice. Review the collection record.
invoice.expiredThe invoice expired before payment completion.
payment_link.completedA single-use payment link completed. Use the underlying invoice for fulfillment checks.
payment_link.expiredA payment link expired.
payment.failedA payment attempt failed verification or processing.
payment.underpaidAn attempt paid less than expected. Inspect the invoice remainder.
payment.overpaidAn attempt paid more than expected. Inspect the invoice and received amount.

On this page