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.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.*)
Payments (charge.*)
Payment intents (payment_intent.*)
Payment intents (payment_intent.*)
Payouts (transfer.*)
Payouts (transfer.*)
Customers (customer.*)
Customers (customer.*)
Invoices (invoice.*)
Invoices (invoice.*)
Verify the signature
Every webhook has anx-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.
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.lengthand compare it with theContent-Lengthheader.
Retries
If your endpoint doesn’t reply with a2xx 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. Thepayload.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 yourreturn_url. - Check
payload.amountandpayload.currencymatch what you expected. - Check
payload.test_modeisfalsebefore shipping real goods. - Reply fast. Put slow work in a background job.
