This project is a Nodejs based implementation for integrating a popular payment gateway in Nepal, Khalti in your app.This project is designed to provide streamline online payment processing within your application. This can be modified and integrated in your dream app, or if you wish you can just use the api as your need.
This project is a simplified sales webservice implementing khalti. This aims to provide a simple yet effective understanding of how you can use and integrate khalti in your application. Some technical aspects of project and their implementation are as:
-
Authentication: The auth implemented is quite simple it uses a simple two role approach of 'USER' and 'ADMIN'. The authentication is based on cookies a simple isloggedIn flag is used to know about the state of login and the user id is also set in the cookies. The authentication approach used here is not recommended as this project emphasize on using the khalti api and integrating with ease. You can opt for better authentication approach like using jwt or using sessions as well.
-
Transaction history: A user can view his transaction history with ease which gives the details including the date of transaction, product and price. A admin can view all the transactions including more details including username , userid and khalti_transaction_id.
-
Access Management:
- You have to be logged in to view products.
- Only admin can add new Products.
- Features like transaction, payment verification are only accessible to logged in users.
- Simplified Integration
- Error Handling
- Extendibility
- Secure Transactions
- Transaction History details
- Node.js 18+ and npm installed on your machine.
- Clone the repository:
git clone https://github.com/Senor101/Khalti-node_API.git
- Install dependencies:
cd Khalti-node_API.git
npm install
-
Configuration, create a
.env
file in the root directory with required API keys mentioned in.env.example
. You can get the API keys for khalti by creating a merchant account. You can do so by clicking here Khalti. -
Run the application locally:
npm start
-
Head over to
http://localhost:8000/api/v1/
and explore the backend service. -
Head over to
http://localhost:8000/
to explore the simplified frontend services.
- Include the payment gateway integration modules into your nodejs project by importing the necessary components.
- Take a reference of this project to implement khalti in your next dream project with your own desired business logic.
This project is licensed under MIT License