POST
endpoint on your server to receive webhook events from Modem Pay. Ensure this endpoint is accessible over HTTPS to maintain security.
customer.created
, payment_intent.created
, charge.succeeded
). The event type is provided in the event
field, while the main data is within the payload
.
x-modem-signature
header in each webhook request. This header allows you to verify that the event originated from Modem Pay.
x-modem-signature
header from the incoming request.
modempay.webhooks.composeEventDetails
for Validation:modempay.webhooks.composeEventDetails
function. This function performs the necessary checks, verifying the signature and parsing the payload.
listen
command creates a secure public tunnel using Localtunnel to forward webhooks to a local endpoint. This is particularly useful for testing webhooks during development.
Disclaimer:
--forward-url
: Specifies your local endpoint to receive webhook events.http://localhost:3000/webhook
.
"customer.created"
, "customer.updated"
, "customer.deleted"
"payment_intent.created"
, "payment_intent.cancelled"
"charge.succeeded"
, "charge.failed"
, "charge.cancelled"
, "charge.created"
, "charge.updated"
listen
command captures both manually triggered events and automatically triggered events from the Modem Pay system. For testing purposes, always use the webhook secret generated by the listen command. This secret is displayed in the terminal and can also be found in the Modem Pay dashboard, but only in test mode.Important: Production secrets and endpoints remain unaffected and are not impacted by the test mode configuration.charge.succeeded
event payload to the configured webhook endpoint for testing.
200 OK
status to confirm receipt. This ensures Modem Pay doesn’t retry the webhook unnecessarily.modempay.webhooks.composeEventDetails
returns an Event
object containing the event type and payload data. The event types you may receive include:
"customer.created"
, "customer.updated"
, "customer.deleted"
"payment_intent.created"
, "payment_intent.cancelled"
"charge.succeeded"
, "charge.cancelled"
, "charge.created"
, "charge.updated"
"transfer.succeeded"
, "transfer.cancelled"
, "transfer.reversed"
, "transfer.failed"
modempay.webhooks.composeEventDetails
to handle incoming webhooks in a Node.js application:
200 OK
status as confirmation. This ensures Modem Pay won’t re-send the event unless there’s an error response.
200 OK
status before performing any tasks that might cause delays or timeouts, such as updating records or sending invoices. This prevents webhook retries and ensures smooth processing.200 OK
HTTP response, Modem Pay will retry the delivery up to 3 times, with each retry spaced 10 minutes apart. A failure could be due to reasons such as server timeouts, network errors, or non-2xx response codes.
To avoid unnecessary retries and ensure smooth webhook processing, always return a 200 OK
response immediately, even if you need to carry out time-consuming tasks (like writing to a database or triggering external API calls). It’s recommended to offload such operations to a background worker or job queue.
By following this best practice, you help prevent duplicate processing and reduce the risk of delays or rate-limiting due to repeated webhook attempts.