Checkout Webhooks: Track Order Lifecycle Events
Learn how to set up webhooks to track every stage of the checkout process and monitor the order lifecycle effectively.
Webhooks allow you to track the status of an order. Every phase of the checkout has its own webhook events, making it easy to track each stage of the checkout process.
How to Set up Webhooks
In this guide, you will use nodejs to create an API endpoint to listen for and parse webhook events. To get started:
1. Create an endpoint route
Using a standard nodejs API server, create an endpoint.
2. Configure the endpoint to read and parse webhook events
Webhook events are sent as HTTP POST requests. To process them, your server must parse the request body and handle the event accordingly. On this endpoint, modify the code to handle POST requests only. When a POST request comes through, parse the webhook event of the request body. Ensure your webhook listener responds with a 200
status code. Otherwise the webhook may be sent until you acknowledge it.
The snippet below is an example handler that parses webhook events:
Do not be strict with payload validations as Crossmint may add new fields to the webhooks as products evolve.
Your server must return a 2xx HTTP status so the webhook is marked as delivered.
3. Pre & post processing
Add your pre and post processing logic when setting up your webhook listener. For example, you can call back to your database when a certain id has succeeded or even use Sendgrid or EmailJS to send an email to a recipient when a mint completes.
4. Setting Up Webhooks on the Crossmint Console
Register your newly created endpoint in the Crossmint Developer Console for the relevant webhook event types by following [this guide] (/introduction/platform/webhooks/add-endpoint). Once done, you’ll be redirected to the endpoint details page. Here, you can find the signing secret for verifying webhooks and see a table of all triggered webhook events.
The last step is to test the endpoint. To do this, purchase some NFTs and observe the responses to ensure everything is set up correctly.
Webhooks Available
Type | Description |
---|---|
orders.quote.created | Triggered when a new order is created in the system, initiating the checkout process. |
orders.quote.updated | Triggered when an existing order is updated, such as when modifying the recipient or item details. |
orders.payment.succeeded | Triggered as soon as a payment is successfully processed and confirmed. |
orders.payment.failed | Triggered when a payment attempt fails, for example, due to insufficient funds or invalid payment details. |
orders.delivery.initiated | Triggered when the delivery process begins after the payment has been successfully processed. |
orders.delivery.completed | Triggered when the delivery of the order is successfully completed and confirmed by the system. |
orders.delivery.failed | Triggered when the delivery of an order fails, for example, due to an item being unavailable during the minting process. |
You can check the responses of each event in the webhooks section in the Developer Console.