Skip to content

Checkout Service: Implement discount validation and price adjustment #98

@rishikeshradhakrishnan

Description

@rishikeshradhakrishnan

Parent Issue

Part of #96 — Add promotional discount code feature to checkout flow

Service

src/checkout (Go)

Scope

Discount Code Store

  • Create an in-memory discount code store with the following codes:
    Code Type Rule
    SAVE10 Percentage 10% off entire order subtotal
    FREESHIP Shipping Set shipping cost to $0
    ASTRO20 Conditional 20% off when subtotal > $100
  • Only one discount code allowed per order

Validation Logic

  • Validate the discount code from PlaceOrderRequest
  • For ASTRO20, check that the subtotal (after currency conversion) exceeds $100 equivalent
  • Return appropriate error if code is invalid or conditions are not met

Price Adjustment in PlaceOrder()

  • Apply discount after currency conversion but before calling the Payment service
  • For percentage discounts: calculate discount on item subtotal (excluding shipping)
  • For FREESHIP: zero out the shipping cost from the Shipping service quote
  • Pass the adjusted total to the Payment service Charge() call
  • Include discount details in the OrderResult response

OpenTelemetry Instrumentation

  • Add a span for discount code validation (discount.validate)
  • Record span attributes: discount.code, discount.type, discount.amount, discount.valid
  • Add a metric counter for discount code usage (by code and success/failure)

Acceptance Criteria

  • In-memory store holds all three discount codes
  • SAVE10 correctly applies 10% off the item subtotal
  • FREESHIP sets shipping to $0
  • ASTRO20 applies 20% off only when subtotal > $100; returns error otherwise
  • Invalid codes return a descriptive gRPC error
  • Payment service receives the correctly adjusted total
  • OrderResult includes discount information
  • OpenTelemetry spans and metrics are recorded for discount operations

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