This is a Simple Ecommerce REST-API project built with Laravel. It provides a backend RESTful API for managing products, orders, and user management for an ecommerce store. It also includes features such as email notifications for order status and registration, category and subcategory management, and integration with Stripe payment gateway.
- Product management: CRUD operations for managing products including add, delete, and update.
- Order management: Create, update, and retrieve orders. Email notifications for order status.
- User management: Manage user account informations and authentication.
- Category and subcategory management: Organize products into categories and subcategories.
- Stripe payment integration: Accept payments using the Stripe payment gateway.
- Clone the repository:
git clone https://github.com/mabdusshakur/simp-estore-api.git
- Install dependencies:
composer install
- Set up your environment variables: Rename
.env.example
to.env
and update the necessary values. - Add your Stripe API secrets: Open the
.env
file and add your Stripe API keys in theSTRIPE_KEY
andSTRIPE_SECRET
. - Configure your mail server: Open the
.env
file and update theMAIL_*
variables with your mail server configurations. - Connect the database: Open the
.env
file and update theDB_*
variables with your database connection details. - Generate an application key:
php artisan key:generate
- Run database migrations:
php artisan migrate
- Seed the database:
php artisan
,php artisan db:seed --class=CountrySeeder
- Start the development server:
php artisan serve
The base URL for all API endpoints is http://localhost:8000/api
.
- current api version is { v1 }
- http://localhost:8000/api/v1
- for admin route http://localhost:8000/api/v1/admin/{route}
Authorization: Bearer <your_token_here>
- URL:
/register
- Method:
POST
- Description: Creates a new user.
- Parameters:
name
(string): The name of the product. Required. Maximum length of 255 characters.email
(string): The email of the user. Required. Must be a valid email format. Must be unique in the "users" table.phone_number
(string): The phone number of the user. Required. Must be a numeric value. Must be unique in the "users" table.password
(string): The password of the user. Required. Minimum length of 8 characters. Must be confirmed withpassword_confirmation
, field.
- Response:
- Status Code:
201 Created
- Body:
{ "status": "success", "message": "User created successfully", "user": { "name": "John Doe", "email": "[email protected]", "phone_number": "1234567890", "........" : "........", "........" : "........" }, "token": "1|H0ARNWXu38km000001JXyOM5555C2PmXKZr00000", "token_type": "Bearer" }
- Status Code:
- URL:
/login
- Method:
POST
- Description: Login a user.
- Parameters:
- Parameters:
email
(string): The email of the user. Sometimes required. Must be a valid email format. Required ifphone_number
is not provided.phone_number
(string): The phone number of the user. Sometimes required. Must be a numeric value. Required ifemail
is not provided.password
(string): The password of the user. Required. Minimum length of 8 characters.
- Parameters:
- Response:
- Status Code:
200 OK
- Body:
{ "status": "success", "user": { "name": "John Doe", "email": "[email protected]", "phone_number": "1234567890", "........" : "........", "........" : "........" }, "token": "2|H0ARNWXu38km000001JXyOM5555C2PmXKZr00000", "token_type": "Bearer" }
- Status Code:
- URL:
/products
- Method:
GET
- Description: Retrieves a list of all products.
- Parameters: None
- Optional Query Parameters:
- search by name:
?search=product_name
- sotr by name:
?sort=name&order=asc
||?sort=name&order=desc
- sotr by created_at:
?sort=created_at&order=asc
||?sort=created_at&order=desc
- sotr by updated_at:
?sort=updated_at&order=asc
||?sort=updated_at&order=desc
- sotr by regular_price:
?sort=regular_price&order=asc
||?sort=regular_price&order=desc
- sotr by sale_price:
?sort=sale_price&order=asc
||?sort=sale_price&order=desc
- sotr by status:
?sort=status&order=asc
||?sort=status&order=desc
- sotr by stock:
?sort=stock&order=asc
||?sort=stock&order=desc
- sort by view_count:
?sort=view_count&order=asc
||?sort=view_count&order=desc
- sort by sold_count:
?sort=sold_count&order=asc
||?sort=sold_count&order=desc
- Get products by category:
?category_id=category_id
- Get products by subcategory:
?subcategory_id=subcategory_id
- paginate:
?paginate=20
|| default 10
- search by name:
- Optional Query Parameters:
- Response:
- Status Code:
200 OK
- Body: Array of product objects
- Status Code:
- URL:
/products/{id}
- Method:
GET
- Description: Retrieves a specific product by its ID.
- Parameters:
id
(integer): The ID of the product.
- Response:
- Status Code:
200 OK
- Body: Product object
- Status Code:
-
Image Path:
you will find the image path in the response with double slash (//) so please remove one slash (/) from the image path
-
URL:
/products
-
Method:
POST
-
Description: Creates a new product.
-
Parameters:
name
(string): The name of the product. Required. Maximum length of 255 characters.slug
(string): The slug of the product (generated from the name).description
(string): The description of the product. Required.regular_price
(float): The regular price of the product. Required. Must be a numeric value.sale_price
(float): The sale price of the product. Optional. Must be a numeric value.category_id
(integer): The ID of the category the product belongs to. Required. Must exist in the "categories" table.subcategory_id
(integer): The ID of the subcategory the product belongs to. Required. Must exist in the "sub_categories" table.status
(string): The status of the product. Required. Must be a boolean value.stock
(integer): The stock quantity of the product. Required. Must be an integer value.images
(required): The images of the product. Required.
-
Response:
- Status Code:
201 Created
- Body: Created product object
- Status Code:
- URL:
/products/{id}
- Method:
PUT
- Description: Updates an existing product.
- Parameters:
name
(string): The name of the product. Required. Maximum length of 255 characters.slug
(string): The slug of the product (generated from the name).description
(string): The description of the product. Required.regular_price
(float): The regular price of the product. Required. Must be a numeric value.sale_price
(float): The sale price of the product. Optional. Must be a numeric value.category_id
(integer): The ID of the category the product belongs to. Required. Must exist in the "categories" table.subcategory_id
(integer): The ID of the subcategory the product belongs to. Required. Must exist in the "sub_categories" table.status
(string): The status of the product. Required. Must be a boolean value.stock
(integer): The stock quantity of the product. Required. Must be an integer value.
- Response:
- Status Code:
200 OK
- Body: Updated product object
- Status Code:
** You can use POST method to update product as well if you have problem with PUT method form-data request.
- URL:
/products/{id}
- Method:
DELETE
- Description: Deletes a product.
- Parameters:
id
(integer): The ID of the product.
- Response:
- Status Code:
200 OK
- Body: Product deleted successfully
- Status Code:
- URL:
/categories
- Method:
GET
- Description: Retrieves a list of all categories.
- Parameters: None
-Optional Query Parameters:
- search by name:
?search=category_name
- sotr by name:?sort=name&order=asc
||?sort=name&order=desc
- sotr by created_at:?sort=created_at&order=asc
||?sort=created_at&order=desc
- sotr by updated_at:?sort=updated_at&order=asc
||?sort=updated_at&order=desc
- sotr by products_count:?sort=products_count&order=asc
||?sort=products_count&order=desc
- sotr by sub_categories_count:?sort=sub_categories_count&order=asc
||?sort=sub_categories_count&order=desc
- paginate:?paginate=20
|| default 10 - Response:
- Status Code:
200 OK
- Body: Array of categories objects, with each object containing a list of subcategories
- Status Code:
- URL:
/categories/{id}
- Method:
GET
- Description: Retrieves a specific categories by its ID.
- Parameters:
id
(integer): The ID of the categories.
- Response:
- Status Code:
200 OK
- Body: category object, with each object containing a list of subcategories
- Status Code:
- URL:
/categories
- Method:
POST
- Description: Creates a new category.
- Parameters:
name
(string): The name of the category. Required. Maximum length of 255 characters. Unique.slug
(string): The slug of the category (generated from the name).
- Response:
- Status Code:
201 Created
- Body: Created category object
- Status Code:
- URL:
/category/{id}
- Method:
PUT
- Description: Updates an existing category.
- Parameters:
name
(string): The name of the category. Required. Maximum length of 255 characters. Unique.slug
(string): The slug of the category (generated from the name).
- Response:
- Status Code:
200 OK
- Body: Updated category object
- Status Code:
- URL:
/category/{id}
- Method:
DELETE
- Description: Deletes a category.
- Parameters:
id
(integer): The ID of the category.
- Response:
- Status Code:
200 OK
- Body: Category deleted successfully
- Status Code:
- URL:
/sub-categories
- Method:
GET
- Description: Retrieves a list of all Sub-Categories.
- Parameters: None
- Optional Query Parameters:
- search by name:
?search=sub_category_name
- sotr by name:
?sort=name&order=asc
||?sort=name&order=desc
- sotr by created_at:
?sort=created_at&order=asc
||?sort=created_at&order=desc
- sotr by updated_at:
?sort=updated_at&order=asc
||?sort=updated_at&order=desc
- sotr by products_count:
?sort=products_count&order=asc
||?sort=products_count&order=desc
- paginate:
?paginate=20
|| default 10
- search by name:
- Optional Query Parameters:
- Response:
- Status Code:
200 OK
- Body: Array of Sub-Categories objects
- Status Code:
- URL:
/sub-categories/{id}
- Method:
GET
- Description: Retrieves a specific Sub-Categories by its ID.
- Parameters:
id
(integer): The ID of the Sub-Categories.
- Response:
- Status Code:
200 OK
- Body: Sub-Categories object
- Status Code:
- URL:
/sub-categories
- Method:
POST
- Description: Creates a new Sub-Category.
- Parameters:
name
(string): The name of the Sub-Category. Required. Maximum length of 255 characters. Unique.slug
(string): The slug of the Sub-Category (generated from the name).category_id
(integer): The ID of the category the Sub-Category belongs to. Required. Must exist in the "categories" table.
- Response:
- Status Code:
201 Created
- Body: Created Sub-Category object
- Status Code:
- URL:
/sub-categories/{id}
- Method:
PUT
- Description: Updates an existing Sub-Category.
- Parameters:
name
(string): The name of the Sub-Category. Required. Maximum length of 255 characters. Unique.slug
(string): The slug of the Sub-Category (generated from the name).category_id
(integer): The ID of the category the Sub-Category belongs to. Required. Must exist in the "categories" table.
- Response:
- Status Code:
200 OK
- Body: Updated Sub-Category object
- Status Code:
- URL:
/sub-categories/{id}
- Method:
DELETE
- Description: Deletes a Sub-Category.
- Parameters:
id
(integer): The ID of the Sub-Category.
- Response:
- Status Code:
200 OK
- Body: Sub-Category deleted successfully
- Status Code:
- URL:
/api/wishlists
- Method:
GET
- Description: Retrieves a list of all wishlists.
- Parameters: None
- Response:
- Status Code:
200 OK
- Body: Array of wishlists objects
- Status Code:
- URL:
/api/wishlists
- Method:
POST
- Description: Creates a new wishlists.
- Parameters:
product_id
(integer): The ID of the product the wishlist belongs to. Required. Must exist in the "products" table.
- Response:
- Status Code:
200 OK
- Body: Wishlist created successfully
- Status Code:
- URL:
/wishlist-exists/{productId}
- Method:
POST
- Description: Checks if the user has already added a wishlist for the specified product.
- Route Parameters:
productId
(integer): The ID of the product to check.
- Response:
- Status Code:
200 OK
- Body: JSON response indicating if the wishlist exists or not. Possible values are
true
orfalse
.
- Status Code:
- URL:
/api/wishlists/{id}
- Method:
DELETE
- Description: Delete a Wishlist.
- Parameters:
id
(integer): The ID of the Wishlist.
- Response:
- Status Code:
200 OK
- Body: Wishlist deleted successfully
- Status Code:
- URL:
/api/wishlists/destroy-all
- Method:
POST
- Description: Deletes all wishlists belongs to the Authenticated User.
- Response:
- Status Code:
200 OK
- Body: All wishlist deleted successfully
- Status Code:
- URL:
/carts
- Method:
GET
- Description: Retrieves a list of all carts.
- Parameters: None
- Response:
- Status Code:
200 OK
- Body: Array of carts objects
- Status Code:
- URL:
/carts
- Method:
POST
- Description: Creates a new carts.
- Parameters:
product_id
(integer): The ID of the product the cart belongs to. Required. Must exist in the "products" table.quantity
(integer): The quantity of the product. Required.
- Response:
- Status Code:
201 Created
- Body: Created cart object
- Status Code:
- URL:
/carts/{id}
- Method:
PUT
- Description: Updates an existing Cart.
- Parameters:
quantity
(integer): The quantity of the product. Required.
- Response:
- Status Code:
200 OK
- Body: Cart updated successfully
- Status Code:
- URL:
/carts/increment/{cart}
- Method:
POST
- Description: Increments the quantity of the product by 1.
- Response:
- Status Code:
200 OK
- Body: Cart Item incremented successfully
- Status Code:
- URL:
/carts/decrement/{cart}
- Method:
POST
- Description: Decrements the quantity of the product by 1.
- Response:
- Status Code:
200 OK
- Body: Cart Item decremented successfully
- Status Code:
- URL:
/carts/{id}
- Method:
DELETE
- Description: Deletes a carts.
- Parameters:
id
(integer): The ID of the carts.
- Response:
- Status Code:
200 OK
- Body: Cart deleted successfully
- Status Code:
- URL:
/carts/destroy-all
- Method:
POST
- Description: Deletes all Cart items belongs to the Authenticated User.
- Response:
- Status Code:
200 OK
- Body: Cart emptied successfully
- Status Code:
- URL:
/profile
- Method:
GET
- Description: Retrieves the user's profile.
- Response:
- Status Code:
200 OK
- Body: JSON object containing the user's profile data
- Status Code:
- URL:
/profile
- Method:
POST
- Description: Updates the user's profile.
- Request Body:
name
(string, optional): The user's name.email
(string, optional): The user's email.phone_number
(numeric, optional): The user's phone number.address_1
(string, optional): The user's address line 1.address_2
(string, optional): The user's address line 2.city
(string, optional): The user's city.country
(numeric, optional): The user's country ID.postal_code
(numeric, optional): The user's postal code.avatar
(file, optional): The user's avatar.
- Response:
- Status Code:
200 OK
- Body: JSON object containing the updated user's profile data
- Status Code:
- URL:
/orders
- Method:
POST
- Description: Creates a new order.
- Request Body:
status
(string, required): The status of the order.payment_method
(string, required): The payment method used for the order.options
:cod
(Cash on Delivery)stripe
(Stripe)card_number
(string, required): The card number for payment.exp_month
(string, required): The expiration month of the card.exp_year
(string, required): The expiration year of the card.cvc
(string, required): The card verification code.
stripe_intent
(Stripe Payment Intent)follow #Confirm Stripe Intent Payment, reference
transaction_id
(string, nullable): The transaction ID for the order.
- Response:
- Status Code:
201 Created
- Body: JSON object containing the created order data
- Status Code:
Get Orders (Authentication Required), (same route, admin role holder can access all orders, user role holder can access only his/her orders)
- URL:
/orders
- Method:
GET
- Description: Retrieves a list of orders.
- Response:
- Status Code:
200 OK
- Body: JSON array containing the order objects
- Status Code:
- URL:
/orders/{id}
- Method:
GET
- Description: Retrieves a specific order by ID.
- Response:
- Status Code:
200 OK
- Body: JSON object containing the order data
- Status Code:
- URL:
/orders/{id}
- Method:
PUT
- Description: Updates an existing order.
- Request Body:
status
(string, required): The updated status of the order.
- Response:
- Status Code:
200 OK
- Body: JSON object containing the updated order data
- Status Code:
- URL:
/orders/confirm-stripe-intent-payment
- Method:
POST
- Description: Confirms a Stripe intent payment for an order.
- Request Body:
payment_intent_client_id
(string, required): The client ID of the payment intent.
- Response:
- Status Code:
200 OK
if payment is successful,400 Bad Request
if payment fails - Body: JSON object indicating the success or failure of the payment
- Status Code:
Contributors are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.