A RESTful API to manage and apply different types of discount coupons for an e-commerce platform.
- Overview
- Features
- Technology Stack
- Setup and Installation
- API Endpoints
- Coupon Cases
- Limitations and Assumptions
- Future Improvements
This API allows an e-commerce platform to manage and apply various discount coupons including cart-wide discounts, product-specific discounts, and "Buy X Get Y" (BxGy) deals with repetition limits.
- Create, read, update, and delete coupons
- Check applicable coupons for a given cart
- Apply a specific coupon to a cart and calculate the discounted prices
- Support for multiple coupon types
- Expiration dates for coupons
- Backend Framework: Django with Django REST Framework
- Database: SQLite
- Documentation: OpenAPI/Swagger
- Clone the repository:
git clone https://github.com/yourusername/coupon-management-api.git
cd coupon-management-api- Create and activate a virtual environment:
python -m venv venv
# On macOS/Linux:
source venv/bin/activate
# On Windows:
venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Run migrations:
python manage.py migrate- (Optional) Create a superuser for Django admin:
python manage.py createsuperuser- Start the development server:
python manage.py runserver- Access the API documentation:
- Swagger UI: http://localhost:8000/
- Redoc: http://localhost:8000/redoc/
- (Optional) Access the Django admin:
Notes:
- The default database is SQLite; no additional setup is required.
- All API endpoints are public (no authentication by default).
- Product IDs are assumed to be valid and managed externally.
- For Windows users, use
venv\Scripts\activateto activate the virtual environment.
POST /coupons: Create a new couponGET /coupons: Retrieve all couponsGET /coupons/{id}: Retrieve a specific coupon by IDPUT /coupons/{id}: Update a specific coupon by IDDELETE /coupons/{id}: Delete a specific coupon by IDPOST /applicable-coupons: Fetch all applicable coupons for a given cartPOST /apply-coupon/{id}: Apply a specific coupon to the cart
- Percentage Discount: Applies a percentage discount to the entire cart if it exceeds a certain threshold
- Example: 10% off on carts over $100
- Fixed Amount Discount: Applies a fixed amount discount to the entire cart if it exceeds a certain threshold
- Example: $15 off on carts over $150
- Free Shipping: Removes shipping cost if cart exceeds a certain threshold
- Example: Free shipping on carts over $50
- Percentage Discount on Specific Product: Applies a percentage discount to a specific product
- Example: 20% off on Product A
- Fixed Amount Discount on Specific Product: Applies a fixed amount discount to a specific product
- Example: $5 off on Product B
- Category Discount: Applies a discount to all products in a specific category
- Example: 15% off on all electronics
- Brand Discount: Applies a discount to all products of a specific brand
- Example: 10% off on all Nike products
- Same Product: Buy a certain quantity of a product and get additional units of the same product free
- Example: Buy 2 of Product A, get 1 of Product A free
- Different Product: Buy a certain quantity of one product and get another product free
- Example: Buy 2 of Product A, get 1 of Product B free
- Product Set: Buy from a set of products and get free items from another set
- Example: Buy 2 products from [X, Y, Z], get 1 product free from [A, B, C]
- Repetition Limit: Limit how many times a BxGy coupon can be applied
- Example: Buy 2 get 1 free with a repetition limit of 3 (max 3 free items)
- Expiration Date: Coupons valid only until a specific date
- Time-of-Day Restriction: Coupons valid only during specific hours
- Example: Happy hour discount valid from 2-5 PM
- Tiered Discounts: Different discount percentages based on cart value tiers
- Example: 5% off on carts over $50, 10% off on carts over $100, 15% off on carts over $200
- First-time User Discounts: Special discounts for first-time purchasers
- Loyalty Tier Discounts: Different discounts based on customer loyalty level
- Bundle Discounts: Discount when specific product combinations are purchased together
- Quantity-Based Sliding Scale: Different discount percentages based on quantity purchased
- Example: 5% off for 2 items, 10% off for 5 items, 15% off for 10+ items
- Nth Purchase Discount: Every nth purchase of a product gets a discount
- Example: Every 5th coffee is free
- Buy X from Category A, Get Y from Category B: Category-based BxGy offers
- Tiered BxGy: Different free products based on quantity purchased
- Example: Buy 2 get 1 free, buy 5 get 3 free, buy 10 get 7 free
- Cross-sell BxGy: Buy main product, get accessory free
- Coupon Stacking: Rules for combining multiple coupons
- Exclusions: Products or categories excluded from coupons
- Maximum Discount Cap: Limit on total discount amount
- Coupon stacking is not supported (only one coupon can be applied at a time)
- No user authentication/authorization
- No product database integration (products are referenced by ID only)
- In-memory cart handling (no persistent carts)
- Limited error handling for edge cases
- Product IDs are valid and exist in an external system
- Cart items include accurate product information
- Percentage discounts are applied to the original price
- BxGy discounts are applied to the lowest-priced eligible products
- For category/brand discounts, category/brand information is included in the request
- Support for coupon stacking with priority rules
- User authentication and authorization
- Integration with product database
- Persistent carts
- Advanced analytics for coupon usage
- More complex coupon types
- Improved error handling