This repository contains backend code for E-commerce Application. It handles various Operations of Users, Products, Orders, Payments. The routes (Rest Api's) and models schemas for the same were created and handled accordingly.
-
Used JSON Web Tokens for Authentication & authorization.
-
Used zod for Data Validation.
-
Implemented Paypal's payment Gatweway using it's sandbox Environment. which includes ( initiating payment, capturing it, refund, getting payment info )
-
Mocked Stripe's Payment Gateway using nock.
-
Mocked Logistic Provider's and domain provider's Api endpoints using nock by creating endpoints for post shipment, track shipmet status, register domain, check domaininfo.
-
Implemented rate limiting.
-
Created indexes on columns, which are frequently used like email, sku, text index on product Name etc.
-
Implemented thorough error handeling using try catch.
-
Implemented Roles such as user, admin,with admin getting access to cruicial routes.
-
Live Link of Backend deployed on vercel :https://backend-my-indiaa-gamma.vercel.app/
-
Postman API documentation: https://documenter.getpostman.com/view/30343018/2sA3drGDxf
- Node.js
- Express.js
- MongoDB as Database
- Endpoint:
/user/signup
- Request Body
{
"name":"Kushal Jain",
"email":"kalakushal.jain@gmail.com",
"password":"kushal@789"
}
- Response
{
"message": "User Signed Up Succesfully",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2Njc3ZTNjYWJiN2JmMzY3YTNkMzkxNzUiLCJyb2xlIjoidXNlciIsImlhdCI6MTcxOTMxNzY2NSwiZXhwIjoxNzIxOTA5NjY1fQ.PHNOy-Cfeyx8U3t2pLXoMv_X3ONwB57iKZ1C8g_aOLA"
}
- Endpoint:
/user/signin
- Request Body
{
"email":"kalakushal.jain@gmail.com",
"password":"kushal@789"
}
- Response
{
"message": "User Signedin Succesfully",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2Njc3ZTNjYWJiN2JmMzY3YTNkMzkxNzUiLCJyb2xlIjoidXNlciIsImlhdCI6MTcxOTMxNzY2NSwiZXhwIjoxNzIxOTA5NjY1fQ.PHNOy-Cfeyx8U3t2pLXoMv_X3ONwB57iKZ1C8g_aOLA"
}
- Endpoint:
/product
- Request Body
{
"sku":"xyzlmn",
"name":"Diary Milk",
"price":10,
"description":"It is a chocolate by cadbury",
"category":"Chocolates",
"stock":10
}
- Response
{
"message": "Product saved succesfully",
"product: product details
}
- Endpoint:
/product
- Response
{
"products": [
{
"_id": "6678138c5ee21e608857869f",
"sku": "1234abcaz",
"name": "Realme 7",
"price": 15000,
"stock": 10,
"description": "It is an electronic phone by Realme Inc.",
"category": "electronics",
"createdAt": "2024-06-23T12:22:36.948Z",
"updatedAt": "2024-06-23T12:22:36.948Z",
"__v": 0
},
,,,
]
}
- Endpoint:
/product
- query parameter:
name=productName
- Response
{
"products": [
{
"_id": "66780936253374ba86b4f45e",
"sku": "123abc",
"name": "Iphone 14 Pro",
"price": 100000,
"stock": 10,
"description": "Iphone by Apple Inc.",
"category": "electronics",
"createdAt": "2024-06-23T11:38:30.643Z",
"updatedAt": "2024-06-23T11:38:30.643Z",
"__v": 0
}
]
}
- Endpoint:
/product/:productId
- Response
{
"product": {
"_id": "667809ea253374ba86b4f463",
"sku": "1234abc",
"name": "Toaster",
"price": 2750,
"stock": 10,
"description": "Toaster it is.",
"category": "electronics",
"createdAt": "2024-06-23T11:41:30.002Z",
"updatedAt": "2024-06-23T12:14:14.785Z",
"__v": 0
}
}
- Endpoint:
/product/:productId
- ReuestBody
{
"price":2750
}
- Response
{
"message": "Product Updated Succesfully"
}
- Endpoint:
/order
- Request Body
{ "products":[
{
"product":"6679111b7e0781a34cec929f",
"price":10,
"quantity":2
}
]
}
- Response
{
"message": "Order saved succesfully",
"saveOrder": {
"userId": "6678331ae7de2db3bfd7dd0e",
"products": [
{
"product": "6679111b7e0781a34cec929f",
"price": 10,
"quantity": 2,
"_id": "667ab4234cb771e27cb80bc2"
}
],
"totalAmount": 20,
"status": "pending",
"_id": "667ab4234cb771e27cb80bc1",
"createdAt": "2024-06-25T12:12:19.335Z",
"updatedAt": "2024-06-25T12:12:19.335Z",
"__v": 0
}
}
- Endpoint:
/orders
- Response
{
orders:[
{
all order details.
}
]
}
- Endpoints:
/order/myorders
- Response Body
{
"orders":[
all order details.
]
}
- Endpoint:
/payment/create-order/:orderId
- Response:
{
"id": "953878881B447042F",
"links": [
{
"href": "https://www.sandbox.paypal.com/checkoutnow?token=953878881B447042F",
"rel": "approve",
"method": "GET"
},..
]
}
- Endpoints:
/payment/capture-payment/:paymentOrderId
- ** RequestBody**
{
"orderId":"667911717e0781a34cec92a1"
}
- Response
{
"id": "953878881B447042F",
"status": "COMPLETED",
"payment_source": {
"paypal":{
..
}
},
"purchase_units": [
]
....
}
- Other Payment Endpoints
- Refund Endpoints:
post
/payment/refund/:captureId
- Payment Info:
get
/payment/:paymentOrderId
- Endpoint:
/shipment/
- RequestBody:
{
"address":"hyderabad, Inida",
"phoneNumber":"9834637838"
}
- Response:
{
"shipmentId": "1263536",
"status": "Shipment created succesfully"
}
- Endpoint:
/shipment/shipment-status
- query params
shipmentId=id
- Response
{
"status": "in transit",
"current_location": "Hyderabad",
"estimated_delivery_data": "28-06-2023"
}
- Endpoint1
get
/domain/check?domainName=name
- Response:
{
"domainName": "x.com",
"available": true,
"price": "200",
"currency": "INR"
}
-Endpoint2 post
/domain/register
- Body:
{
"domainName":"x.com"
}
- Response
{
domainName: "x.com",
registration_status: "success",
transaction_amount: "100"
}
- Endpoint :
/paymentMock/paymentIntent
- Response:
{
"id": "pi_123",
"amount": 300,
"currency": "usd",
"status": "prcoessing"
}
- Endpoint :
/paymentMock/refund
` Body:
{
"id":"pi_123"
}
- Response:
{
"id": "pi_123",
"amount": 2000,
"status": "succeeded"
}