This is a simple e-commerce service, but its functionality is powerful.
-
Docker and Docker Compose (Optional)
This Project use modular system
, Functional Programming (FP)
and Object Oriented programming (OOP)
The OOP
only implemented to handle Response Exeception, the rest in using FP
I also implements SOLID Prinsiple, but mostly using for:
-S (Single-Responsibilty)
Good,
-O (Open-Closed)
Good enough,
-D (Dependency Inversion)
Good enough,
-O (Liskov substitution)
Not perfect yet,
Below is Folder Structure that maybe would help you to undestand about this project.
and each modules
have responsibilty
base on folder name
.
├── `app`
│ ├── api
│ │ ├── v1
│ │ │ ├── auth
│ │ │ │ └── index.js
│ │ │ ├── cart
│ │ │ │ └── index.js
│ │ │ └── ..dst
│ │ │ └── ..index.js
│ │ └── index.js
│ ├── index.js
│ ├── helpers
│ │ ├── folder
│ │ └── file js
│ ├── libraries
│ │ └── folder name
│ │ └── index.js
│ └── modules
│ ├── controllers
│ │ └── sub-controllers
│ │ └── index.js
│ ├── models
│ │ └── sub-models
│ │ └── index.js
│ ├── repositoris
│ │ └── sub-repositoris
│ │ └── index.js
│ ├── schemas
│ │ └── sub-schemas
│ │ └── index.js
│ ├── services
│ │ └── sub-services
│ │ └── index.js
│ └── middleware
│ └── index.js
│ ├── midlerware A
│ └── midlerware B
├── index.sj
├── .sequelizerc
├── Dockerfile
├── docker-compose.yml
└── ..etc config files
Before running application, please take a look the file env.example
and change to .env
Noted: This project using Docker and Docker Compose,
if you want to run without Docker
, you have to change the Configuration host for mysql
and redis
NODE_ENV = development
APP_PORT = 3000
APP_ISSUER = gitbub.com/mrbontor
....
This Service is using Json Web Token (JWT)
and Cookie
to manage user session, please take a look for details in AUTH API
- mysql ->
./configs/mysql.js
- sequelize ->
./.sequelizerc
- mysql ->
./db/mysql_data
- sequelize ->
./db/redis_data
-> ./.prettierrc.json
By default, you can run this service following command below:
# cloning github
$ git clone https://github.com/mrbontor/Simple-eCommerce-API-Service.git
# enter to root dir
$ cd Simple-eCommerce-API-Service
# install dependencies
$ npm install
#if your system already have Redis and Mysql,
$ npx sequelize-cli db:migrate
#please check user seeder file, need a user with role Admin
$ npx sequelize db:seed:all
$ node app.js
###
# Run with Docker Compose
#
# dont need seeder
##
#create container network, please look in docker-compose.yml if you want to change it.
$ docker network create k-link-dev
# run app and start
$ docker-compose up --build -d
#or just
$ docker-compose up
# check healt app
$ curl http://localhost:3000
# {"uptime":48.741330481,"message":"OK","timestamp":1674976023067}%
# stop
$ docker-compose down
# remove volumes
$ docker-compose down --remove-orphans --volumes
# some usefull commands
# backup db
$ docker exec -it mysqldb /usr/bin/mysqldump -u root --password=LiveIn2023 ecommerce > backup.sql
#login to container
$ docker exec -it [`container-name`] sh
As i mentioned before, the Unit Test Code
not finish yet, but already finish with documentation in /postman
Note : I dont finish the Unit Test yet, but i have provided all the API serive including test case
for every endpoints and functionalities
K-LINK-Ecommerce-Service
how to run:
# start
$ npm test
Please follow this Postman Doc Import Api for better information
The Postman file
also included documentation
, environtment
and Examples responses
for each cases
You just need to import
the file.
- AUTH
- USER
- PRODUCT
- STOCK
- CART
- TRANSACTION
User(s) must be authenticated before accessing any API.
The AUTH API
will return accessToken
, refreshToken
and DID
API
has provided Cookies
for clients with expiration time
.
To change the lifetime
, look in the .env
file. Expiration time is used to handle JWT Token
and Cookie
expiration
Notes:
accessToken
will be returned in response bodyrefreshToken
will be returned asCookie
with nameRTOKEN
deviceId
is the device identifier and will be returned as aCookie
with nameDID
User login using method POST with paramatersusername
and password.
Endpoint:
Method: POST
Type: RAW
URL: {{local}}/v1/auth/login
Body:
{
"username": "superadmin",
"password": "Haruslolos123!"
}
More example Requests/Responses:
Body:
{
"username": "superadmin",
"password": "Haruslolos123!"
}
{
"status": true,
"message": "Success",
"data": {
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7ImlkVXNlciI6MSwidXNlcm5hbWUiOiJzdXBlcmFkbWluIiwiZW1haWwiOiJzdXBlcmFkbWluQGdtYWlsLmNvbSIsImlzQWN0aXZlIjp0cnVlLCJpc0FkbWluIjp0cnVlfSwiaWF0IjoxNjc0ODgwNDE0LCJleHAiOjE3MTA4ODQwMTQsImF1ZCI6ImtsaW5rLmNvLmlkIiwiaXNzIjoia2xpbmsuY28uaWQifQ.VcT-Te8oHqUXJj5HfwM1EDbPYTcbw-gEBCKwL2lq9Tk"
}
}
Status Code: 200
Body:
{
"username": "superadmin"
}
{
"status": false,
"message": "Validation Error!",
"errors": [
{
"param": "password",
"key": "required",
"message": "password is required"
}
]
}
Status Code: 400
Body:
{
"username": "superadmins",
"password": "Haruslolos123!"
}
{
"status": false,
"message": "Un Authorized!"
}
Status Code: 401
Body:
{
"username": "superadmin",
"password": "Haruslolos123!!"
}
{
"status": false,
"message": "Un Authorized!"
}
Status Code: 401
Body:
{
"username": "user",
"password": "Haruslolos123!"
}
{
"status": false,
"message": "Your account has been deactive, please contact your administrator!"
}
Status Code: 422
Register user use JSON
payload to create a user
fields:
- username,
required
- email,
required
- password,
required
Endpoint:
Method: POST
Type: RAW
URL: {{local}}/v1/auth/register
Body:
{
"username": "usertest",
"email": "usertest@gmail.com",
"password": "Haruslolos123!"
}
More example Requests/Responses:
Body:
{
"username": "user3",
"email": "user3@gmail.com",
"password": "Haruslolos123!"
}
{
"status": true,
"message": "Success",
"data": {
"username": "user3",
"email": "user3@gmail.com",
"isActive": true,
"isAdmin": false
}
}
Status Code: 200
Body:
{
"username": "user2",
"email": "user2@gmail.com",
"password": "Haruslolos123!"
}
{
"status": false,
"message": "Username is already used!"
}
Status Code: 422
Body:
{
"username": "XXXXXXXXXXXXXXXXXXXX",
"email": "user2@gmail.com",
"password": "Haruslolos123!"
}
{
"status": false,
"message": "Email is already used!"
}
Status Code: 422
Body:
{
"username": 1,
"email": "user2@gmail.com",
"password": "Haruslolos123!",
"test": "additional"
}
{
"status": false,
"message": "Validation Error!",
"errors": [
{
"param": "test",
"key": "additionalProperties",
"message": "must NOT have additional properties"
},
{
"param": "/username/undefined",
"key": "type",
"message": "must be string"
}
]
}
Status Code: 400
Fetch new Token as a refresh token
Endpoint:
Method: GET
Type:
URL: {{local}}/v1/auth/refresh-token
More example Requests/Responses:
Body: None
{
"status": true,
"message": "Success",
"data": {
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7ImlkVXNlciI6MSwidXNlcm5hbWUiOiJzdXBlcmFkbWluIiwiZW1haWwiOiJzdXBlcmFkbWluQGdtYWlsLmNvbSIsImlzQWN0aXZlIjp0cnVlLCJpc0FkbWluIjp0cnVlfSwiaWF0IjoxNjc0ODgwOTU3LCJleHAiOjE3MTA4ODQ1NTcsImF1ZCI6ImtsaW5rLmNvLmlkIiwiaXNzIjoia2xpbmsuY28uaWQifQ.II0mD_30MRG7Qp7MQ5UhtoI_JIco7dDsPTnzbXmldzQ"
}
}
Status Code: 200
Body: None
Unauthorized
Status Code: 401
User Logout and remove token, cookies etc
Endpoint:
Method: GET
Type:
URL: {{local}}/v1/auth/logout
Query params:
Key | Value | Description |
---|---|---|
allDevices | true | true or false |
More example Requests/Responses:
Query:
Key | Value | Description |
---|---|---|
allDevices | true | true or false |
Body: None
Status Code: 204
Query:
Key | Value | Description |
---|---|---|
allDevices | true | true or false |
Body: None
Unauthorized
Status Code: 401
Users
directory contains all the user related APIs. For authentication these apis requrie AuthBearerToken
Create user use JSON
payload to create a user
fields:
- username,
required
- email,
required
- password,
required
Endpoint:
Method: POST
Type: RAW
URL: {{local}}/v1/users
Body:
{
"username": "superadmin",
"email": "superadmin@gmail.com",
"password": "Haruslolos123!"
}
More example Requests/Responses:
Body:
{
"username": "user3",
"email": "user3@gmail.com",
"password": "Haruslolos123!"
}
{
"status": true,
"message": "Success",
"data": {
"username": "user3",
"email": "user3@gmail.com",
"isActive": true,
"isAdmin": false
}
}
Status Code: 200
Body:
{
"username": "user2",
"email": "user2@gmail.com",
"password": "Haruslolos123!"
}
{
"status": false,
"message": "Username is already used!"
}
Status Code: 422
Body:
{
"username": "XXXXXXXXXXXXXXXXXXXX",
"email": "user2@gmail.com",
"password": "Haruslolos123!"
}
{
"status": false,
"message": "Email is already used!"
}
Status Code: 422
Body:
{
"username": 1,
"email": "user2@gmail.com",
"password": "Haruslolos123!",
"test": "additional"
}
{
"status": false,
"message": "Validation Error!",
"errors": [
{
"param": "test",
"key": "additionalProperties",
"message": "must NOT have additional properties"
},
{
"param": "/username/undefined",
"key": "type",
"message": "must be string"
}
]
}
Status Code: 400
Body:
{
"username": "user2",
"email": "user2@gmail.com",
"password": "Haruslolos123!"
}
Forbidden
Status Code: 403
Patch role user use JSON
payload to update user role
fields:
- isAdmin,
required
Endpoint:
Method: PATCH
Type: RAW
URL: {{local}}/v1/users/role/1
Body:
{
"isAdmin": true
}
More example Requests/Responses:
Body:
{
"isAdmin": true
}
Status Code: 204
Body:
{
"isAdmin": "true"
}
{
"status": false,
"message": "Validation Error!",
"errors": [
{
"param": "isAdmin",
"key": "type",
"message": "isAdmin should be in boolean format"
}
]
}
Status Code: 400
Body:
{
"isAdmin": true
}
Forbidden
Status Code: 403
Patch status user use JSON
payload to update user status
fields:
- isActive,
required
Endpoint:
Method: PATCH
Type: RAW
URL: {{local}}/v1/users/status/1
Body:
{
"isActive": true
}
More example Requests/Responses:
Body:
{
"isActive": true
}
Status Code: 204
Body:
{
"isActive": true
}
{
"status": false,
"message": "Validation Error!",
"errors": [
{
"param": "isAdmin",
"key": "type",
"message": "isAdmin should be in boolean format"
}
]
}
Status Code: 400
Body:
{
"isActive": true
}
Forbidden
Status Code: 403
Patch
password user use JSON
payload to update user password.
fields:
- password,
required
- newPassword,
required
Noted: Changing password will remove Token Bearer
Endpoint:
Method: PATCH
Type: RAW
URL: {{local}}/v1/users/password
Body:
{
"password": "Haruslolos123!",
"newPassword": "Haruslolos123!"
}
More example Requests/Responses:
Body:
{
"password": "!Haruslolos123",
"newPassword": "Haruslolos123!"
}
Status Code: 204
Body:
{
"password": "Haruslolos123!",
"newPassword": "!Haruslolos123"
}
{
"status": false,
"message": "Incorect Password"
}
Status Code: 400
Body:
{
"password": "!Haruslolos123",
"newPassword": "Haruslolos123!"
}
Unauthorized
Status Code: 401
Fetch all users list
Endpoint:
Method: GET
Type:
URL: {{local}}/v1/users
More example Requests/Responses:
Body: None
{
"status": true,
"message": "Success",
"data": [
{
"id": 1,
"username": "superadmin",
"email": "superadmin@gmail.com",
"isActive": true,
"isAdmin": true
},
{
"id": 2,
"username": "user",
"email": "user@gmail.com",
"isActive": true,
"isAdmin": false
},
{
"id": 3,
"username": "user2",
"email": "user2@gmail.com",
"isActive": true,
"isAdmin": false
},
{
"id": 4,
"username": "user3",
"email": "user3@gmail.com",
"isActive": true,
"isAdmin": false
}
]
}
Status Code: 200
Body: None
Forbidden
Status Code: 403
Fetch a single user using idUser
Only Admin can perform this API
Endpoint:
Method: GET
Type:
URL: {{local}}/v1/users/3
More example Requests/Responses:
Body: None
{
"status": true,
"message": "Success",
"data": {
"username": "user2",
"email": "user2@gmail.com",
"isActive": true,
"isAdmin": false
}
}
Status Code: 200
Body: None
Forbidden
Status Code: 403
Fetch user's profile with current session
Endpoint:
Method: GET
Type:
URL: {{local}}/v1/users/profiles
More example Requests/Responses:
Body: None
{
"status": true,
"message": "Success",
"data": {
"username": "superadmin",
"email": "superadmin@gmail.com",
"isActive": true,
"isAdmin": true
}
}
Status Code: 200
Body: None
{
"status": false,
"message": "User is not found!"
}
Status Code: 404
Update user use JSON
payload to update a user
Note: dont need update since there is only a few fields.
Endpoint:
Method: PUT
Type: RAW
URL: {{local}}/v1/users/1
Body:
{
"username": "superadmin",
"email": "superadmin@gmail.com"
}
Delete a single user using idUser
Only Admin can perform this API
Endpoint:
Method: DELETE
Type:
URL: {{local}}/v1/users/3
More example Requests/Responses:
Body: None
Status Code: 204
Body: None
{
"status": false,
"message": "User not found!"
}
Status Code: 404
Body: None
Forbidden
Status Code: 403
Body: None
{
"status": false,
"message": "He is Zeus, you cant delete him!!!"
}
Status Code: 422
To access the PRODUCT API, a Bearer Token
is needed which can be obtained from the AUTH API
While creating a Product, it also will create data into Table Stock
with Quantity 0
Price 0
User Admin
to update Stock for Quantity
and Price
first.
Create product use JSON
payload to create a product.
fields:
- name is
required
- description is
optional
Endpoint:
Method: POST
Type: RAW
URL: {{local}}/v1/products
Body:
{
"name": "product",
"description": null
}
More example Requests/Responses:
Body:
{
"name": "product",
"description": "product"
}
{
"status": true,
"message": "Success",
"data": {
"id": 1,
"name": "product",
"description": "product",
"status": true,
"updatedAt": "2023-01-28T05:11:47.090Z",
"createdAt": "2023-01-28T05:11:47.090Z"
}
}
Status Code: 200
Body:
{
"description": "product"
}
{
"status": false,
"message": "Validation Error!",
"errors": [
{
"param": "name",
"key": "required",
"message": "Name is required!"
}
]
}
Status Code: 400
Body:
{
"name": "product",
"description": "product",
"test": "asd"
}
{
"status": false,
"message": "Validation Error!",
"errors": [
{
"param": "",
"key": "additionalProperties",
"message": "Field(s) is not allowed"
}
]
}
Status Code: 400
Body:
{
"name": "product",
"description": null
}
{
"status": false,
"message": "Product is already exist!"
}
Status Code: 422
Body:
{
"name": "product",
"description": "product"
}
Unauthorized
Status Code: 401
Body:
{
"name": "product",
"description": null
}
Forbidden
Status Code: 403
Update product use JSON
payload to update a product.
fields:
- name is
required
- description is
optional
Noted: Only Admin can perform this API
Endpoint:
Method: PUT
Type: RAW
URL: {{local}}/v1/products/1
Body:
{
"name": "product",
"description": "with description"
}
More example Requests/Responses:
Body:
{
"name": "product",
"description": "with description"
}
Status Code: 204
Body:
{
"name": "product",
"description": "with description"
}
{
"status": false,
"message": "Product not found!"
}
Status Code: 404
Body:
{
"name": "product",
"description": "product"
}
Unauthorized
Status Code: 401
Body:
{
"name": "product",
"description": null
}
Forbidden
Status Code: 403
Fetch all Product
list
Endpoint:
Method: GET
Type:
URL: {{local}}/v1/products
More example Requests/Responses:
Body: None
{
"status": true,
"message": "Success",
"data": [
{
"id": 1,
"name": "product",
"description": "product",
"status": true,
"createdAt": "2023-01-28T05:11:47.000Z",
"updatedAt": "2023-01-28T05:11:47.000Z",
"stock": {
"price": 0,
"idStock": 1,
"quantity": 0
}
}
]
}
Status Code: 200
Body: None
Unauthorized
Status Code: 401
Fetch a single product using idProduct
Endpoint:
Method: GET
Type:
URL: {{local}}/v1/products/1111
More example Requests/Responses:
Body: None
{
"status": true,
"message": "Success",
"data": {
"id": 1,
"name": "product",
"description": "with description",
"status": true,
"createdAt": "2023-01-28T05:11:47.000Z",
"updatedAt": "2023-01-28T07:14:10.000Z",
"stock": {
"price": 10000,
"idStock": 1,
"quantity": 12
}
}
}
Status Code: 200
Body: None
{
"status": false,
"message": "Product is not found!"
}
Status Code: 404
Body: None
Unauthorized
Status Code: 401
Delete a single product using idProduct
Noted: Deleting a product
will delete stock
as well and Only Admin can perform this API
Endpoint:
Method: DELETE
Type:
URL: {{local}}/v1/products/2
More example Requests/Responses:
Body: None
Status Code: 204
Body: None
Unauthorized
Status Code: 401
Body: None
Forbidden
Status Code: 403
To access the STOCK API, a Bearer Token
is needed which can be obtained from the AUTH API
STOCK API
is used to manage Quantity
and Price
of Product.
Only user with role Admin
can perform this API
Create stoc use JSON
payload to create a stock.
fields:
- idProduct is
required
- quantity is
required
- price is
required
Noted: this Api already performed in POST Product
__, but this can help user
managing between Product
and Stock
Endpoint:
Method: POST
Type: RAW
URL: {{local}}/v1/stocks
Body:
{
"idProduct": 1,
"quantity": 10,
"price": 10000
}
More example Requests/Responses:
Body:
{
"idProduct": 1,
"quantity": 10,
"price": 10000
}
{
"status": true,
"message": "Success",
"data": {
"price": 10000,
"id": 3,
"idProduct": 1,
"quantity": 10,
"updatedAt": "2023-01-28T07:47:07.924Z",
"createdAt": "2023-01-28T07:47:07.924Z"
}
}
Status Code: 200
Body:
{
"idProduct": 1,
"quantity": 10,
"price": "10000",
"test": "additional property"
}
{
"status": false,
"message": "Validation Error!",
"errors": [
{
"param": "test",
"key": "additionalProperties",
"message": "must NOT have additional properties"
},
{
"param": "price",
"key": "type",
"message": "Price must be number"
}
]
}
Status Code: 400
Body:
{
"idProduct": 1111,
"quantity": 10,
"price": 10000
}
{
"status": false,
"message": "Product is not found"
}
Status Code: 404
Body: None
Unauthorized
Status Code: 401
Body: None
Forbidden
Status Code: 403
Update stock product use JSON
payload to update a stock product.
fields:
- quantity is
required
- price is
required
- idStock as params,
required
Noted: Only Admin can perform this API
Endpoint:
Method: PUT
Type: RAW
URL: {{local}}/v1/stocks/7
Body:
{
"quantity": 12,
"price": 10000
}
More example Requests/Responses:
Body:
{
"quantity": 12,
"price": 10000
}
Status Code: 204
Body:
{
"idProduct": 1,
"quantity": 10,
"price": "10000",
"test": "additional property"
}
{
"status": false,
"message": "Validation Error!",
"errors": [
{
"param": "idProduct",
"key": "additionalProperties",
"message": "must NOT have additional properties"
},
{
"param": "test",
"key": "additionalProperties",
"message": "must NOT have additional properties"
},
{
"param": "price",
"key": "type",
"message": "Price must be number"
}
]
}
Status Code: 400
Body:
{
"quantity": 10,
"price": 10000
}
{
"status": false,
"message": "Product is not found"
}
Status Code: 404
Body:
{
"quantity": 10,
"price": 10000
}
Unauthorized
Status Code: 401
Body: None
Forbidden
Status Code: 403
Fetch all stocks list
Endpoint:
Method: GET
Type:
URL: {{local}}/v1/stocks
More example Requests/Responses:
Body: None
{
"status": true,
"message": "Success",
"data": [
{
"price": 10000,
"id": 1,
"idProduct": 1,
"quantity": 12,
"createdAt": "2023-01-28T05:11:47.000Z",
"updatedAt": "2023-01-28T07:51:05.000Z",
"product": {
"idProduct": 1,
"name": "product",
"status": true
}
},
{
"price": 10000,
"id": 3,
"idProduct": 1,
"quantity": 10,
"createdAt": "2023-01-28T07:47:07.000Z",
"updatedAt": "2023-01-28T07:47:07.000Z",
"product": {
"idProduct": 1,
"name": "product",
"status": true
}
}
]
}
Status Code: 200
Body: None
Unauthorized
Status Code: 401
Fetch a single stock of product using idStock
Endpoint:
Method: GET
Type:
URL: {{local}}/v1/stocks/1
More example Requests/Responses:
Body: None
{
"status": true,
"message": "Success",
"data": {
"price": 10000,
"id": 1,
"idProduct": 1,
"quantity": 12,
"createdAt": "2023-01-28T05:11:47.000Z",
"updatedAt": "2023-01-28T07:51:05.000Z",
"product": {
"idProduct": 1,
"name": "product",
"status": true
}
}
}
Status Code: 200
Body: None
Unauthorized
Status Code: 401
Delete a single stock using idStock
Noted: Deleting a stock
will delete product
as well and Only Admin can perform this API
Endpoint:
Method: DELETE
Type:
URL: {{local}}/v1/stocks/3
More example Requests/Responses:
Body: None
Status Code: 204
Body: None
Unauthorized
Status Code: 401
Body: None
Forbidden
Status Code: 403
The API
using Redis Database
to store the cart
items
This API is only available for User Logged In
with active
session
Even user has logged out
, this used to keep the cart exists
.
Create/Add item cart use JSON
payload to add item to cart.
fields:
- data is
required
- data is
array
Endpoint:
Method: POST
Type: RAW
URL: {{local}}/v1/carts
Body:
{
"data": [
{
"idProduct": 3,
"quantity": 1
},
{
"idProduct": 5,
"quantity": 1
}
]
}
More example Requests/Responses:
Body:
{
"data": [
{
"idProduct": 3,
"quantity": 6
},
{
"idProduct": 5,
"quantity": 2
}
]
}
{
"status": true,
"message": "Success",
"data": true
}
Status Code: 200
Body:
{
"data": [
{
"idProduct": 3,
"quantity": 6
},
{
"idProduct": 5,
"quantity": 2
}
]
}
{
"status": false,
"message": "Insuficient quantity of product2"
}
Status Code: 422
Body:
{
"data": [
{
"idProduct": 3,
"quantity": 6
},
{
"idProduct": 5,
"quantity": 2
}
]
}
Unauthorized
Status Code: 401
Fetch all cart
list of actve
session
Endpoint:
Method: GET
Type:
URL: {{local}}/v1/carts
More example Requests/Responses:
Body: None
{
"status": true,
"message": "Success",
"data": {
"details": [
{
"idProduct": 3,
"quantity": 6,
"status": true,
"subTotal": 60000,
"name": "product2",
"originProduct": {
"price": 10000,
"idStock": 4,
"quantity": 12
}
},
{
"idProduct": 5,
"quantity": 2,
"status": true,
"subTotal": 20000,
"name": "product",
"originProduct": {
"price": 10000,
"idStock": 7,
"quantity": 12
}
}
],
"grandTotal": 80000
}
}
Status Code: 200
Body: None
{
"status": false,
"message": "The shoppping cart is empty, please select some items first!"
}
Status Code: 404
Body: None
Unauthorized
Status Code: 401
Delete all cart list
Endpoint:
Method: DELETE
Type:
URL: {{local}}/v1/carts
More example Requests/Responses:
Body: None
Status Code: 204
Body: None
Unauthorized
Status Code: 401
The TRANSACTION API
is used to manage user transaction.
Endpoint:
Method:
Type:
URL:
CHECKOUT API is used to simulate Calculation from CART API.
we will used Active Session
and Cache
to create a transaction.
Endpoint:
Method: POST
Type: RAW
URL: {{local}}/v1/transactions/checkout
Body:
{
"amountPaid": 200000
}
More example Requests/Responses:
Body:
{
"amountPaid": 200000
}
{
"status": true,
"message": "Success",
"data": {
"details": [
{
"idProduct": 3,
"quantity": 1,
"status": true,
"subTotal": 10000,
"name": "product2",
"originProduct": {
"idStock": 4,
"quantity": 11,
"price": "10000"
}
},
{
"idProduct": 5,
"quantity": 1,
"status": true,
"subTotal": 10000,
"name": "product",
"originProduct": {
"idStock": 7,
"quantity": 11,
"price": "10000"
}
}
],
"grandTotal": 20000,
"amountPaid": 200000
}
}
Status Code: 200
Body:
{
"amountPaid": 200000
}
{
"status": false,
"message": "The shoppping cart is empty, please select some items first!"
}
Status Code: 404
Body: None
Unauthorized
Status Code: 401
Fetch all transaction
list
If User
has role Admin
, it will show all
history transactions and if User
is not , it will only return user's own
history transaction
Endpoint:
Method: GET
Type:
URL: {{local}}/v1/transactions/history
More example Requests/Responses:
Body: None
{
"status": true,
"message": "Success",
"data": [
{
"total": null,
"amountPaid": 200000,
"id": 29,
"idUser": 6,
"invoice": "e5ee47d7-653c-4ee5-8a09-9c1ba844f1d5",
"details": [
{
"name": "product2",
"status": true,
"quantity": 1,
"subTotal": 10000,
"idProduct": 3
},
{
"name": "product",
"status": true,
"quantity": 1,
"subTotal": 10000,
"idProduct": 5
}
],
"status": "done",
"createdAt": "2023-01-29T02:04:36.000Z",
"updatedAt": "2023-01-29T02:04:36.000Z"
}
]
}
Status Code: 200
Body: None
{
"status": true,
"message": "Success",
"data": [
{
"total": 20000,
"amountPaid": 200000,
"id": 24,
"idUser": 2,
"invoice": "984e4a16-4024-421c-a56a-d954f2be6447",
"details": [
{
"name": "product2",
"status": true,
"quantity": 1,
"subTotal": 10000,
"idProduct": 3
},
{
"name": "product",
"status": true,
"quantity": 1,
"subTotal": 10000,
"idProduct": 5
}
],
"status": "done",
"createdAt": "2023-01-29T01:15:29.000Z",
"updatedAt": "2023-01-29T01:15:29.000Z",
"user": {
"username": "user"
}
},
{
"total": 20000,
"amountPaid": 200000,
"id": 25,
"idUser": 2,
"invoice": "2db43379-bf3c-4755-8ffd-fb2620ae28d0",
"details": [
{
"name": "product2",
"status": true,
"quantity": 1,
"subTotal": 10000,
"idProduct": 3
},
{
"name": "product",
"status": true,
"quantity": 1,
"subTotal": 10000,
"idProduct": 5
}
],
"status": "done",
"createdAt": "2023-01-29T01:17:54.000Z",
"updatedAt": "2023-01-29T01:17:54.000Z",
"user": {
"username": "user"
}
},
{
"total": 20000,
"amountPaid": 200000,
"id": 29,
"idUser": 6,
"invoice": "e5ee47d7-653c-4ee5-8a09-9c1ba844f1d5",
"details": [
{
"name": "product2",
"status": true,
"quantity": 1,
"subTotal": 10000,
"idProduct": 3
},
{
"name": "product",
"status": true,
"quantity": 1,
"subTotal": 10000,
"idProduct": 5
}
],
"status": "done",
"createdAt": "2023-01-29T02:04:36.000Z",
"updatedAt": "2023-01-29T02:04:36.000Z",
"user": {
"username": "usertest"
}
},
{
"total": 20000,
"amountPaid": 200000,
"id": 30,
"idUser": 6,
"invoice": "6c65eb48-c082-4e87-b334-e4e2a5ad64c7",
"details": [
{
"name": "product2",
"status": true,
"quantity": 1,
"subTotal": 10000,
"idProduct": 3
},
{
"name": "product",
"status": true,
"quantity": 1,
"subTotal": 10000,
"idProduct": 5
}
],
"status": "done",
"createdAt": "2023-01-29T02:09:55.000Z",
"updatedAt": "2023-01-29T02:09:55.000Z",
"user": {
"username": "usertest"
}
}
]
}
Status Code: 200
Body: None
Unauthorized
Status Code: 401
If you have any question, please contact me or send me email