Skip to content

Add promotional discount code feature to checkout flow #96

@rishikeshradhakrishnan

Description

@rishikeshradhakrishnan

Is your feature request related to a problem?

Currently, the checkout flow has no mechanism for applying promotional discount codes. Customers cannot redeem coupons or promotional offers during checkout, which limits marketing capabilities and reduces conversion opportunities. The pricing logic simply sums item_price × quantity + shipping_cost with no discount layer in between.

Describe the solution you'd like

Add a promotional discount code feature to the checkout flow that allows customers to apply coupon codes before placing an order. The feature should:

1. Discount Code Input (Frontend - TypeScript/Next.js)

  • Add a discount code input field on the cart/checkout page
  • Display validation feedback (valid/invalid code)
  • Show the discount amount and updated order total in real-time

2. Supported Discount Codes

Validate against a simple in-memory store with these initial codes:

Code Type Discount
SAVE10 Percentage 10% off entire order
FREESHIP Shipping Free shipping (set shipping cost to $0)
ASTRO20 Conditional percentage 20% off orders over $100

3. Discount Validation & Application

  • Validate discount codes against an in-memory store (no database required for v1)
  • Apply percentage discounts to the item subtotal before adding shipping
  • ASTRO20 should only apply when the pre-discount subtotal exceeds $100 (in the user's currency)
  • Only one discount code per order

4. Order Confirmation

  • Ensure the discount amount is reflected in the OrderResult
  • Display discount details in the order confirmation page and email

5. OpenTelemetry Instrumentation

  • Add appropriate spans for discount code validation
  • Record discount code usage as span attributes (code used, discount amount, success/failure)
  • Add metrics for discount code redemption rates

Describe alternatives you've considered

  1. External coupon service: A dedicated microservice for coupon management. This would be more scalable but adds complexity — overkill for this demo application.
  2. Database-backed codes: Storing discount codes in PostgreSQL or Valkey. Better for production but unnecessary for demonstrating the checkout flow integration.
  3. Feature flag approach: Using the existing flagd integration to toggle discounts. This doesn't model real coupon behavior well.

Additional Context

Services impacted

  • src/frontend (TypeScript/Next.js) — UI input field, display logic
  • src/checkout (Go) — Discount validation, price adjustment during PlaceOrder()
  • src/payment (Node.js) — Receives the adjusted total for charging
  • Proto definitions — May need a DiscountCode message or field on PlaceOrderRequest

Implementation considerations

  • The existing Money protobuf type (currency_code, units, nanos) supports precise discount arithmetic
  • Currency conversion should happen before discount validation (so ASTRO20's $100 threshold works correctly across currencies)
  • The checkout service already orchestrates calls to Cart, Currency, Shipping, and Payment — discount logic fits naturally into this flow
  • Follow existing OpenTelemetry instrumentation patterns (spans, attributes, metrics) already present in the codebase

Tip: React with 👍 to help prioritize this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions