Let's Integrate and make payment via esewa. There are few steps to consider when
using the esewa payment gateway integration which we will demistify in this
article. Let's start with the practical example,
Live_demo and
source_code,
and docs are available on esewa
developer.
The stack
The entire stack includes the following components:
Hono.js & Hono JSX Middleware
Htmx as the client-side framework.
eSewa ( Epay )
Drizzle ORM for database interactions.
React components for front-end rendering.
Tailwind CSS for styling and design
Cloudflare D1
Cloudflare Workers
Bun, Zod and more
Esewa Test Credential
Setting up Backend
I won't be going deep in these tech stacks and more on the setup, I will focus
more on the simple basic route, and in the payment integration flow.
Now, we have imported all the required components.
This is the webhook route where you can verify the payment, or do bunch of
others thing that you like.
here, we have create the main route which will render the payment form, and also
fetching the single product data from the server and passing it to client, but
for in your real world scenario you can fetch the actual order data from your
database.
How Payment Verification Works
After the user is redirected back to your site (via the /verify route), we check
the validity of the payment using HMAC signatures. The server verifies the
payment details against the eSewa signature to ensure no tampering.
Transaction UUID is generated uniquely for each transaction. Signatures are
created using the product and transaction details, ensuring that data hasn’t
been modified during the process.
So here is the simple fn for creating the signature.
Client-Side Implementation
On the front end, we’ll render the payment form and submit the necessary data to
the eSewa API. We will also handle generating the signature required for secure
transactions.
Status Check
Conclusion
This blog has demonstrated how to integrate the eSewa payment gateway with a
modern stack using Hono.js, Axios, and React for front-end rendering. The
integration handles product display, secure payment processing, and transaction
verification.