This project uses MySQL as the database. Ensure you have MySQL installed and running on your system.
Create a .env
file in the root directory of the project and add necessary environment variables like DB_USERNAME
, DB_PASSWORD
, DB_NAME
, and STRIPE_SECRET_KEY
.
PORT=8080
# Environment Name
NODE_ENV=development
DB_NAME=loyalty_demo_db
DB_HOST=127.0.0.1
DB_PORT=3306
DB_USER=
DB_PWD=
CLIENT_URL=http://localhost:8080
STRIPE_SECRET_KEY=
STRIPE_WEBHOOK_SECRET=
Run npm install
in the project's root directory to install the required dependencies.
Run npm run db:create
to create the database, npm run db:migrate
to run migrations, and npm run db:seed
to seed the database.
Execute npm run watch
to start the dev server and run the application.
- Create a
.env
file in the root directory of the project and add necessary environment variables. - Run
npm install
in the project's root directory to install the required dependencies. - Run
npm run db:create
to create the database. - Run
npm run db:migrate
to run migrations. - Run
npm run db:seed
to seed the database. - Run
npm run watch
to start the dev server and run the application. - Create a product in
/product
route. - Create a cart in
/cart
route. - Add items to cart in
/cart/{id}/items
route. - Checkout the cart in
/cart/checkout
route. The stripe checkout session will be created and return as response. - Stripe local webhook server is needed to run before completing checkout session. So in another terminal run
stripe listen --forward-to localhost:8080/order/webhook/success
. Make sure you have stipe cli installed. - Go to that checkout session url in browser to complete the payment. Just use test card number 4242 4242 4242 4242. Order will be created in database with calculated points and customer will be rewarded if they are eligible (set
eligible_to_redeem_points
to true). - The other endpoints such as points transfer, product CRUD can be explored in the shared postman collection.