Overview
Xendit is a payment gateway that allows you to accept payments from your users especially for Southeast Asia countries. It supports various payment methods such as credit card, bank transfer, and e-wallet. Here's a full checkout flow:
Setup
You need to add more environment variables to your project by following these steps:
-
Create API Key
Please create an account and get the API key from Settings > Developers > API Keys. Generate an API key with Money-in write permission.
-
Add Webhook
Then, add the webhook URL to your project from Settings > Developers > Webhooks. Add the webhook URL to listen to the invoices event.
code
-
Update Environment Variables
Add the following environment variables to your project:
.env
Done! You may need to restart the server to apply the changes. And, you can apply for store activation when your landing page is ready.
Client Side
Create a checkout method in the pricing page (app/(landing)/pricing/page.tsx) to hit the order API and redirect the user to the payment page.
page.tsx
API Endpoint
Then, here's an example of the API route to create an order in the app/api/orders/route.ts
:
route.ts
Note. You may need to add the failed page to display the proper error message to the user in /app/dash/failed/page.tsx
.
Webhook Handler
Lastly, you need to create a webhook handler in the app/api/webhooks/xendit/route.ts
to listen to the events. Here's an example of how to handle the invoice events:
route.ts