atlp-rwanda / knights-ecomm-be

Knights ecommerce backend APIs
https://knights-ecomm-be-lcdh.onrender.com
0 stars 0 forks source link

Buyer should be able to apply coupons during checkout #93

Closed faid-terence closed 6 months ago

faid-terence commented 6 months ago

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

Development Notes

faid-terence commented 6 months ago

@Calebgisa72 Please edit the description to match GitHub issue format and also include the implementation plan attached

Calebgisa72 commented 6 months ago

My Implementation Plan:

  1. Create a New Branch Task: Create a new branch for this feature. The branch will be called "ft-buyer-coupon"

  2. Check if the Coupon Database is already Set Up.

  3. 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.

  4. 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.

  5. 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.

  6. Handle Edge Cases Task: Implement error handling for various scenarios. Steps: Handle invalid coupon codes. Handle expired coupons. Handle already-used coupons.

  7. 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).

  8. 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.

faid-terence commented 6 months ago

@Calebgisa72 Include the ERD

Calebgisa72 commented 6 months ago

ERD Link: https://lucid.app/lucidchart/f7670bc9-25a6-4026-a9ab-a6e084927d58/edit?viewport_loc=-2284%2C-1118%2C5125%2C2662%2C0_0&invitationId=inv_1a824c8f-58b7-4659-823e-f22e62caa237