Promo Code Handling
cart_service.applyPromoCode / removePromoCode
Overview
Promo codes are managed exclusively on the backend cart — there is no local-cart equivalent. Apply sends the new full code list (Medusa overwrites); remove sends an empty list to clear.
User Flow
- User enters a promo code on CartScreen or CheckoutScreen.
- If no backend cart yet, the UI creates one first (createPhysicalCart / createProvisionCart).
- applyPromoCode posts {promo_codes: [code]} → response includes the updated discountTotal.
- removePromoCode posts {promo_codes: []} to clear.
- If a promo changes the total, updatePaymentCollectionAmount may need to resync the Stripe collection.
Cases & Edge Cases
- Multiple stacking promo codes are technically possible — pass them all in promo_codes; UI today only supports one at a time.
- Removing a code that was never applied is a no-op (empty → empty) — UI must not show a 'removed' toast unless the previous state had a code.
- Discount drift vs payment-collection amount is a documented Medusa edge case — updatePaymentCollectionAmount exists specifically to recover.
Code References
- lib/src/core/services/cart_service.dart:378 // applyPromoCode
- lib/src/core/services/cart_service.dart:415 // removePromoCode
- lib/src/core/services/cart_service.dart:536 // updatePaymentCollectionAmount
API Calls
Empty — fill this in later. Open the manifest and add content here.
Notes
Backend evolved between Medusa V1 (DELETE per-code) and V2 (POST full list). Keep removePromoCode pinned to the V2 semantic.