Skip to main content
A webhook is a POST request Modem Pay sends to your server when something happens, like a payment succeeding. Use webhooks to mark orders paid, send receipts and update your records, even when the customer closes their browser.

Set up your endpoint

1

Create a POST endpoint

It must be public and use HTTPS, for example https://yoursite.com/webhooks/modempay. Local addresses like localhost are refused. To test locally, use the CLI.
2

Add it in the dashboard

Go to Developers → Webhooks and enter the URL. You can have one webhook per account in test mode and one in live mode.
3

Copy the signing secret

You’ll use it to check that each request really came from Modem Pay. For safety, revealing it asks for a one-time code sent to your email.
4

Reply 200 quickly

Return 200 as soon as you’ve checked the signature, then do the slow work (emails, database updates) afterwards.
Saving the webhook URL creates a new signing secret. This happens when you change the URL, and when you turn a disabled webhook back on. After any change, copy the new secret to your server, or every signature check will fail.

What a webhook looks like

Every webhook has two fields: event, the name of what happened, and payload, the object it happened to.

Events

Payments (charge.*)

Verify the signature

Every webhook has an x-modem-signature header. It’s an HMAC-SHA512 of the exact request body, made with your webhook signing secret. Check it before you trust anything in the request.
Use the raw body. Don’t parse the JSON and turn it back into a string. Many frameworks change spacing or key order when they do that, and the signature no longer matches. This is the most common reason signature checks fail, especially on Firebase, Vercel and other serverless platforms.

Still failing?

  • Are you using the secret from the same mode? Test and live webhooks have different secrets.
  • Did you change the webhook URL recently? That creates a new secret.
  • Are you using the webhook signing secret, not your API secret key?
  • Are you checking the raw body? Log rawBody.length and compare it with the Content-Length header.

Retries

If your endpoint doesn’t reply with a 2xx status, or times out, Modem Pay tries again up to 3 more times, 10 minutes apart. You can see every delivery, with your server’s response, in Developers → Webhooks → Events. From there you can resend any event by hand.

Handle duplicates

Because of retries, you may get the same event more than once. Make your handler safe to run twice. For example, before marking an order paid, check it isn’t already paid. The payload.id stays the same across retries.

Webhooks or callback_url?

You can also pass a callback_url when you create a payment intent. Modem Pay then sends that payment’s events to that URL instead of your webhook. This is handy when different payments belong to different systems. See Callback URL for how to verify those.

Good practice

  • Fulfil orders on charge.succeeded, not when the customer lands on your return_url.
  • Check payload.amount and payload.currency match what you expected.
  • Check payload.test_mode is false before shipping real goods.
  • Reply fast. Put slow work in a background job.