Built a RESTful API to manage and apply different types of discount coupons (cart-wise, product-wise, and BxGy) for an e-commerce platform, with the ability to easily add new types of coupons in the future.
- Coupon Types: ● Cart-wise: Apply a discount to the entire cart if the total amount exceeds a certain threshold. ● Product-wise: Apply a discount to specific products. ● BxGy: “Buy X, Get Y” deals with a repetition limit and can be applicable to a set of products (e.g., Buy 3 of Product X or Product Y, get 1 of Product P and Product Q free and so on).
- Note: Scheduler Implemented for expiring the coupon on weekly basis.
- API Endpoints: ● POST /coupons: Create a new coupon.
● GET /coupons: Retrieve all coupons.
● GET /coupons/{id}: Retrieve a specific coupon by its ID.
● PUT /coupons/{id}: Update a specific coupon by its ID.
● DELETE /coupons/{id}: Delete a specific coupon by its ID.
● POST /applicable-coupons: Fetch all applicable coupons for a given cart and calculate the total discount that will be applied by each coupon.
● POST /apply-coupon/{id}: Apply a specific coupon to the cart and return the updated cart with discounted prices for each item.
- Coupon Structure: ● Each coupon have an ID, type (cart-wise, product-wise, BxGy), discount details, and conditions etc for applicability.
● The implementation designed to easily add new types of coupons in the future. 5. Database: ● Here MySql database used. ● Store and fetch coupon details and conditions.
- Error Handling: ● Implemented to handled error (e.g., coupon not found, invalid input, conditions not met).