Closed faid-terence closed 5 months ago
@Calebgisa72 Please edit the description to match GitHub issue format and also include the implementation plan attached
My Implementation Plan:
Create a New Branch Task: Create a new branch for this feature. The branch will be called "ft-buyer-coupon"
Check if the Coupon Database is already Set Up.
Implement Coupon Validation Service Task: Create a service for validating coupon codes. Steps: Implement a check, checking if a coupon exists and is valid. Check the expiration date and usage status.
Implement Coupon Application Service Task: Create a service to apply the coupon and calculate the discount. Steps: Implement a function that calculates the discount based on the coupon type and value. Update the order total with the discount applied. Mark the coupon as used if it is a one-time-use coupon.
Create API Endpoint Task: Develop an API endpoint for applying coupons during checkout. Steps: Create a POST endpoint /apply-coupon. Apply the coupon using the application service. Return the updated order total and appropriate messages to the frontend.
Handle Edge Cases Task: Implement error handling for various scenarios. Steps: Handle invalid coupon codes. Handle expired coupons. Handle already-used coupons.
Write Unit Tests Task: Create unit tests for the coupon services and API endpoint. Steps: Test the coupon validation logic. Test the coupon application logic. Test the API endpoint with different scenarios (valid coupon, invalid coupon, expired coupon, unauthenticated user).
Code Review and Testing Task: Conduct a code review and run tests. Steps: Submit a pull request for review. Address any feedback from the code review. Ensure all tests pass successfully.
@Calebgisa72 Include the ERD
The backend needs to handle the application of coupons during checkout and ensure that the discount is accurately applied to the order total.
Acceptance Criteria
[ ] Apply Valid Coupon
Given a POST request to apply a coupon during checkout
When the request contains a valid coupon code and the user is logged in
Then the discount should be applied to the order total and a confirmation message should be sent to the frontend
[ ] Handle Invalid Coupon or Unauthenticated User
Given a POST request to apply a coupon during checkout
When the request contains an invalid coupon code or the user is not logged in
Then an appropriate error message should be sent to the frontend
Development Notes