Sobes.tech
Middle

What changes are required in the API when adding promo codes?

sobes.tech AI

Answer from AI

Adding promo codes to the API will require the following changes:

  1. New endpoints or extension of existing ones:

    • Add a method to check the validity of a promo code (e.g., POST /promo/validate).
    • A method to apply a promo code to an order (e.g., POST /order/{id}/apply-promo).
  2. Changes to data models:

    • Introduce an "Promo Code" entity with fields: code, discount type, amount or percentage, validity date, usage conditions.
    • Add a field in orders to store the applied promo code and the final discount.
  3. Validation and business logic:

    • Implement checks for promo code conditions in the API (expiration date, minimum amount, usage count).
  4. Documentation update:

    • Describe new endpoints and parameters.

Example JSON request for promo code validation:

{
  "promoCode": "SUMMER2024",
  "orderAmount": 1500
}

Response:

{
  "valid": true,
  "discountAmount": 200
}
What changes are required in the API when adding… - sobes.tech