Skip to Content
Payrudder

Receive webhooks on your machine

Get a signed Payrudder webhook to a handler on your own computer, and find out why one did not arrive.

Payrudder tells your application what happened (an invoice was paid, a subscription ended) by posting a signed JSON message to an address you register. This tutorial gets one such message to a handler on your own computer and shows how to see what went wrong when it does not arrive.

The scheme itself (event types, headers, retries) is in Webhooks. Here you do it.

Before you start

You need a key with the webhook permissions and the command line, signed in (payrudder login).

Steps

Write a handler that verifies

Write the endpoint your application will have. It must:

  • read the raw body,
  • verify the Payrudder-Signature header with the endpoint's secret,
  • answer 2xx quickly,
  • ignore an event id it has seen before (deliveries are at least once).

The code for your language is in The code at the bottom of this page, made by the same generator as the Connect page of the console. Start it on localhost:3000, at /webhooks/payrudder.

Get deliveries to your machine

Payrudder posts to a registered address, so that address must reach your computer. Pick the case that is yours:

With the development compose file, register http://host.docker.internal:4242/ as an endpoint in the console's Webhooks tab, then run the receiver:

Run the receiver
payrudder webhooks listen --forward-to http://localhost:3000/webhooks/payrudder --secret whsec_...

whsec_... is the secret the console showed once when you created the endpoint.

The development stack allows http:// and private addresses. A production one never does.

The receiver verifies each delivery before it forwards it, and forwards it unchanged (body and headers), so your handler's own check runs on the real signature. What it prints:

Receiver output
Listening on http://127.0.0.1:4242 for Payrudder deliveries.
10:21:40  ping   0192...  attempt 1  signature ok  -> HTTP 200 (4ms)

Send an event

Send a ping
payrudder webhooks trigger ping

This sends the one event the API can send on request, a ping, and waits for the answer of the endpoint.

For a real event, make the thing happen: in the sandbox, close a period and the invoice's events (invoice.finalized, invoice.paid) follow.

Find out why one did not arrive

Watch deliveries
payrudder webhooks deliveries --watch

This lists the deliveries with their state, the number of attempts and the HTTP status your endpoint answered, and keeps printing each one that appears or changes.

A delivery that was not accepted is retried after 1 minute, 5 minutes, 30 minutes, 2 hours, 6 hours and 24 hours, then given up. The console's Webhooks tab can send one again by hand.

You seeLikely cause
REFUSED: ... signature does not match in the receiverThe wrong secret, or the body was changed before verification (a framework that parsed and re-encoded the JSON). Verify the raw bytes.
REFUSED: ... outside the toleranceYour computer's clock is more than five minutes off.
-> ... connection refusedYour handler is not running on the --forward-to address.
HTTP 4xx or 5xx from your handlerYour handler failed. Payrudder gets the same status and will retry.
Nothing at allThe registered address does not reach this computer (a tunnel that stopped, a firewall), or the endpoint is paused or subscribed to other event types.

Prepare for live

Register the endpoint of your deployed application (https://, a public address) for the live environment. The secret is per endpoint and per environment. You can keep the verification code: it is the same.

The code

The handler in each language, built from the SDKs of this repository.

The SDKs are not on a registry yet, so the install lines are the honest ones. See SDKs.

# A delivery carries Payrudder-Signature: t=<unix time>,v1=<hex>. The hex is HMAC-SHA256 of "<t>.<raw body>" under your endpoint's secret.
# Check it on the raw body before parsing; the SDKs do it for you (see the other tabs).

Next steps