A robust and secure RESTful mock API for handling UPI payments, user authentication, expense tracking, and financial learning features.
-
Authentication System
- User registration and login
- JWT-based authentication
- Secure password hashing
-
Payment Processing
- UPI payment integration
- Payment request handling
- Transaction history
-
Expense Management
- Track expenses
- Categorize transactions
- Generate expense reports
-
Financial Learning
- Educational content
- Financial tips and insights
- Learning resources
-
Notification System
- Real-time notifications
- Payment alerts
- System updates
- Node.js
- Express.js
- MongoDB (Mongoose)
- JWT for authentication
- Bcrypt for password hashing
- CORS enabled
- Environment variables support
- Node.js (v14 or higher)
- MongoDB
- npm or yarn
- Clone the repository:
git clone [repository-url]
cd UPI-API- Install dependencies:
npm install- Create a
.envfile in the root directory with the following variables:
PORT=3000
MONGODB_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret- Start the development server:
npm run dev| Endpoint | Method | Description |
|---|---|---|
/api/auth/signup |
POST | Register a new user |
/api/auth/login |
POST | Log in an existing user |
/api/auth/logout |
POST | Log out the current user |
/api/auth/current-user |
GET | Get the profile of the current user |
/api/balance |
POST | Get the balance of the current user |
/api/pay |
POST | Create a payment |
/api/transactions |
GET | Get payment transaction history |
/api/requests |
GET | Get pending payment requests |
/api/requests |
POST | Create a payment request |
/api/requests/accept/:id |
POST | Accept a payment request |
/api/requests/reject/:id |
POST | Reject a payment request |
/api/notifications |
GET | Get notifications |
/api/notifications/mark-all-as-read |
PATCH | Mark all notifications as seen |
/api/notifications/mark-as-read/:id |
PATCH | Mark a notification as seen by ID |
/api/notifications/dismiss/:id |
DELETE | Dismiss a notification by ID |
POST /api/auth/signupRequest Body:
{
"email": "sahil@gmail.com",
"phone": "1234567890",
"username": "mrsahil",
"password": "12345678"
}Response:
{
"status": "success",
"message": "User account created successfully.",
"data": {
"userId": "68234a177329f739edde8dd4",
"username": "mrsahil",
"email": "sahil@gmail.com"
},
"timestamp": "2025-05-13T13:33:11.449Z"
}POST /api/auth/loginRequest Body:
{
"username": "mrsahil",
"password": "12345678"
}
Response:
{
"status": "success",
"message": "User logged in successfully.",
"data": {
"userId": "68171a83fb6428ea8504aaf7",
"authToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY4MTcxYTgzZmI2NDI4ZWE4NTA0YWFmNyIsInVzZXJuYW1lIjoibXJzYWhpbGphaXN3YWwiLCJpYXQiOjE3NDcxNDQzMjAsImV4cCI6MTc0NzE0NzkyMH0.3dCv1mtORQ9YtXeVk8ajE0MV1GBxynuVjwPC2PPYOqA",
"expiresIn": 3600
},
"timestamp": "2025-05-13T13:52:00.196Z"
}POST /api/auth/logoutResponse:
{
"status": "success",
"message": "User logged out successfully.",
"timestamp": "2025-05-13T14:38:50.152Z"
}GET /api/auth/current-userHeaders:
Authorization: Bearer <token>
Response:
{
"status": "success",
"message": "Current user fetched successfully.",
"data": {
"username": "mrsahil",
"email": "sahil@gmail.com",
"finalBalance": 7636
},
"timestamp": "2025-05-13T14:40:47.376Z"
}POST /api/balanceHeaders:
Authorization: Bearer <token>
Response:
{
"status": "success",
"message": "Balance fetched successfully.",
"data": {
"username": "mrsahil",
"email": "sahil@gmail.com",
"finalBalance": 7621
},
"timestamp": "2025-05-13T14:48:07.413Z"
}POST /api/payHeaders:
Authorization: Bearer <token>
Request Body:
{
"amount": 15,
"note": "meal",
"payee": "mruser"
}Response:
{
"status": "success",
"message": "Payment of ₹15 to 'mruser' completed.",
"data": {
"transactionId": "68235a8c7329f739edde8e88",
"amount": 15,
"note": "meal",
"payee": "mruser",
"balanceAfterTransaction": 7621,
"transactionDate": "2025-05-13T14:43:24.408Z"
},
"timestamp": "2025-05-13T14:43:24.558Z"
}GET /api/transactionsHeaders:
Authorization: Bearer <token>
Response:
{
"status": "success",
"message": "Transaction history fetched successfully.",
"data": [
{
"transactionId": "68235a8c7329f739edde8e88",
"amount": 15,
"type": "debited",
"note": "prasadam",
"status": "Success",
"sender": "mrsahil",
"receiver": "mruser",
"transactionDate": "2025-05-13T14:43:24.408Z"
},
{
"transactionId": "682318d49a434189f6e66165",
"amount": 450,
"type": "debited",
"note": "paymeback",
"status": "Success",
"sender": "mrsahil",
"receiver": "mruser",
"transactionDate": "2025-05-13T10:03:00.140Z"
},GET /api/requestsHeaders:
Authorization: Bearer <token>
Response:
{
"status": "success",
"message": "Pending payment requests fetched successfully.",
"data": {
"requests": [
{
"paymentRequestId": "681f56f3f3d52476bfe1ae0a",
"amount": 123,
"note": "test-notification",
"requester": "mrvarunk",
"createdAt": "2025-05-10T13:38:59.120Z"
},
"pendingCount": 41
},
"timestamp": "2025-05-15T08:55:59.277Z"
}
}POST /api/requestsHeaders:
Authorization: Bearer <token>
Request Body:
{
"amount": 200.00,
"recipientId": "recipient_user_id",
"description": "Request for project payment"
}Response:
{
"status": "success",
"message": "Payment request of ₹1 sent to 'mruser'.",
"data": {
"transactionId": "682360b17329f739edde8e9e",
"amount": 1,
"note": "test-notification",
"recipient": "mruser",
"date": "2025-05-13T15:09:37.428Z",
"status": "pending"
}
}
}POST /api/requests/accept/:idHeaders:
Authorization: Bearer <token>
Params:
id of payment request
Response:
{{
"status": "success",
"message": "Payment request accepted.",
"data": {
"request": {
"_id": "6822b737d6ea9dfe398f350a",
"requester": "68171d1e483ee19dff1c9ccd",
"recipient": "68171a83fb6428ea8504aaf7",
"amount": 2,
"note": "req testing",
"status": "accepted",
"createdAt": "2025-05-13T03:06:31.461Z",
"__v": 0
},
"transactions": {
"debitTransaction": {
"userId": "68171a83fb6428ea8504aaf7",
"sender": "mrsahil",
"receiver": "mruser",
"amount": 2,
"type": "debited",
"status": "completed",
"note": "req testing",
"date": "2025-05-15T07:46:27.483Z",
"_id": "68259bd37329f739edde8f08",
"__v": 0
},
"creditTransaction": {
"userId": "68171d1e483ee19dff1c9ccd",
"sender": "mrsahil",
"receiver": "mruser",
"amount": 2,
"type": "credited",
"status": "completed",
"note": "req testing",
"date": "2025-05-15T07:46:27.523Z",
"_id": "68259bd37329f739edde8f0a",
"__v": 0
}
},
"recipientBalance": 7619
}
}POST /api/requests/reject/:idHeaders:
Authorization: Bearer <token>
Params:
id of payment request
Response:
{
"status": "success",
"message": "Payment request rejected.",
"data": {
"_id": "681f159ead5d4fa36e4d1b6e",
"requester": "68171d1e483ee19dff1c9ccd",
"recipient": "68171a83fb6428ea8504aaf7",
"amount": 51,
"note": "test-notification",
"status": "rejected",
"createdAt": "2025-05-10T09:00:14.869Z",
"__v": 0
}
}GET /api/notificationsHeaders:
Authorization: Bearer <token>
Response:
{
"status": "success",
"message": "Notifications fetched successfully.",
"data": [
{
"_id": "6822b737d6ea9dfe398f350c",
"userId": "68171a83fb6428ea8504aaf7",
"message": "You have received a payment request of ₹2 from mruser with note: \"req testing\".",
"seen": true,
"type": "request_sent",
"transactionId": "6822b737d6ea9dfe398f350a",
"createdAt": "2025-05-13T03:06:31.493Z",
"__v": 0
},
} PATCH /api/notificationsHeaders:
Authorization: Bearer <token>
Response:
{
"status": "success",
"message": "All notifications marked as seen."
} PATCH /api/notifications/mark-as-read/:idHeaders:
Authorization: Bearer <token>
Response:
{
"status": "success",
"message": "All notifications marked as seen."
} DELETE /api/notifications/dismiss/:idHeaders:
Authorization: Bearer <token>
Response:
{
"status": "success",
"message": "Notification dismissed."
} - Password hashing using bcrypt
- JWT-based authentication
- CORS protection
- Environment variable configuration
- Secure payment processing
The project uses nodemon for development, which automatically restarts the server when changes are detected.
npm run devThe API implements comprehensive error handling for:
- Invalid requests
- Authentication failures
- Database errors
- Payment processing errors
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the ISC License.
- Sahil Jaiswal - Initial work
For support, please open an issue in the repository or contact the development team.