Webhook Basic
Webhook is used to received notification about the status of the checkout, let's try a minimal example of a webhook endpoint
Creating a POST endpoint
We will be using Nextjs
in this example, but you can use any framework of your choice
Get the checkout data
The webhook will attach a checkoutId
in the request body. We can use this ID to query
the full checkout and transaction data for further processing
Verify the checkout status
We will follow a security principle called Zero Trust
, in simple term, do not trust the webhook.
So with the checkout data that we queried, we will use it to verify that there is least one successful transaction.
Process your business logic
In this step, you can process your business logic, such as updating subscription status. etc.
- Webhook will be considered
SUCCESSFUL
if the returned status code is in range of200
- Webhook will be considered
FAILED
if the returned status code is of error ones, e.g.400
,500