-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
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
ASTRO20should 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
- External coupon service: A dedicated microservice for coupon management. This would be more scalable but adds complexity — overkill for this demo application.
- Database-backed codes: Storing discount codes in PostgreSQL or Valkey. Better for production but unnecessary for demonstrating the checkout flow integration.
- 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 logicsrc/checkout(Go) — Discount validation, price adjustment duringPlaceOrder()src/payment(Node.js) — Receives the adjusted total for charging- Proto definitions — May need a
DiscountCodemessage or field onPlaceOrderRequest
Implementation considerations
- The existing
Moneyprotobuf 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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels