Skip to main content
Samrat Dutta Roy
Back to selected work
[03]·Core Checkout Infrastructure

Stadium — Dynamic Rush Shipping Tier Engine & Viewport-Adaptive Placement

Checkout shipping date calculation engine with production holiday calendars, weekend-skipping business day math, dynamic cutoff timestamps, and zero-flicker viewport collision detection.

Role

Core Checkout Infrastructure · Vinsol | Stadium

Status

Shipped to Production

Domain

Systems & Architecture

Deployment

Production Application
ReactTypeScriptNext.jsSCSS ModulesState MachinesContext APIJestReact Testing LibraryLaunchDarkly

Key Outcomes & Verified Highlights

  • Built a step-by-step checkout state machine that makes sure mandatory details are completed before allowing optional steps or final submission.
  • Created dynamic validation for enterprise accounting fields like purchase orders, cost codes, and department IDs based on company rules.
  • Fixed race conditions between loading order details, wallet balances, and asynchronous payment methods so the cart always displays accurate amounts.
  • Wrote automated test suites across billing, custom fields, and step-gating helpers to guarantee checkout reliability.

01 — Context & Checkout Constraints

Stadium delivers customized corporate gift boxes and event swag for time-sensitive enterprise events (product launches, quarterly conferences, board meetings). Orders frequently require expedited fulfillment with strict delivery guarantees.

Standard e-commerce checkout systems assume static delivery estimates (e.g. "3–5 business days"). For corporate gifting, delivery pricing is dynamic: the surcharge varies continuously depending on warehouse processing lead times, daily carrier cutoff hours, and destination timezones.


02 — Problem Analysis: The Triple Checkout Failure

A post-mortem of the legacy checkout funnel revealed three cascading failure points:

LayerFailure MechanismCustomer & Business Impact
Tier MathCalendar days used instead of operational business daysWeekend orders undercharged for rush shipping, costing Stadium tens of thousands in warehouse overtime
Viewport ClippingDate picker popover clipped by modal overflow boundaries on mobile viewportsMobile checkout drop-off rate spiked; users could not reach the confirmation CTA
State SynchronizationDelivery surcharge updated independently of the payment intentRace condition: customers authorized a total that excluded the newly selected rush shipping fee

03 — Architecture: 3-Tier Dynamic Checkout Engine

The fulfillment engine was redesigned as a three-tier architecture separating business logic from presentation and payment state:

text
[ Customer Enters Delivery Address & Target Date ]
                        │
                        ▼
[ Layer 1: Business-Day Fulfillment Engine ]
  ├── Carrier cutoff time evaluation (12:00 PM EST deadline)
  ├── Weekend & holiday exclusion walk
  └── Contiguous tier classification (Standard / Express / Overnight)
                        │
                        ▼
[ Layer 2: Checkout Finite State Machine ]
  ├── Synchronized total recalculation
  ├── Server-side payment intent reconciliation
  └── Address invalidation rollback guard
                        │
                        ▼
[ Layer 3: Viewport-Adaptive Date Picker UI ]
  ├── Collision-aware viewport clamping
  └── Multi-modal container boundary escape (Portal mount)

04 — Rush Shipping Tier & Business-Day Calculation Model

Warehouse processing schedules operate strictly on business days. If an order is placed on Friday at 2:00 PM EST for delivery on Monday, the order cannot use standard 2-day ground shipping; it requires an emergency Saturday fulfillment run.

Dynamic Tier Classification Matrix

Days to Delivery (Business Days)Fulfillment ClassificationLogistics RoutingPricing Surcharge
1 Business DayEmergency OvernightDedicated same-day pick & pack + Next-Day Air$75.00 / recipient
2 Business DaysExpress PriorityNext-morning priority batch + 2-Day Air$35.00 / recipient
3–4 Business DaysExpedited GroundStandard warehouse queue + Expedited transit$15.00 / recipient
5+ Business DaysStandard FulfillmentStandard batching + Ground transitFree / Base rate

Fulfillment Invariants

  1. Daily Cutoff Rule: Orders submitted after 12:00 PM warehouse local time increment lead time by +1 business day.
  2. Contiguous Tier Boundaries: Tier conditions are mutually exclusive and non-overlapping. Exactly one tier matches any valid calendar selection.
  3. Idempotent Date Walks: Forward business day increments skip weekends (day === 0 || day === 6) deterministically, ensuring timezone shifts across US coasts never calculate negative lead times.

05 — Viewport-Adaptive Popover & Collision Invariants

The delivery date picker must render inside nested modals and checkout slide-outs without getting clipped by container overflow: hidden boundaries.

Collision Detection & Placement Rules

Rather than locking to a fixed downward popover, the layout engine calculates viewport margins dynamically:

text
[ Trigger Element Clicked ]
             │
             ├─────────────────────────────────────────┐
             ▼                                         ▼
[ Vertical Space Evaluation ]              [ Horizontal Clamping ]
If bottomSpace < popoverHeight:             If popoverRight > windowWidth:
  ➔ Flip upward (top alignment)               ➔ Align right edge to trigger
Else:                                       Else:
  ➔ Default downward alignment                ➔ Center horizontally
  • Portal Mounting: The date picker popover escapes parent modal overflow traps by mounting into a top-level React Portal attached to document.body.
  • Passive Viewport Listeners: Repositioning listens to scroll and resize events with passive flags and requestAnimationFrame debouncing, preventing layout thrashing during touch scroll.

06 — Checkout Finite State Machine & Financial Sync

The checkout funnel treats delivery date selection as a formal step in the transaction state machine.

text
[ Idle / Cart Loaded ]
          │
          ▼
[ Address Entered ] ──► (Validating Zip/Country)
          │
          ▼
[ Tier Selected ] ──► Recalculate Shipping Surcharge
          │
          ▼
[ Intent In-Flight ] ──► Lock Place Order CTA (Prevent Double Click)
          │
          ▼
[ Intent Settled ] ──► Enable Payment / Finalize Order

Invalidation & Rollback Guard

If the user edits their shipping address after selecting a delivery date, the state machine rolls back to the Address Entered state, clears the previously selected delivery tier, and refetches eligible dates for the new postal zone. This prevents undercharging for addresses requiring remote carrier delivery.


07 — Technical Accounting: Trade-Off Decisions

ComponentSelected ApproachAlternative EvaluatedEngineering Justification
Date ArithmeticLightweight custom business-day walker (~50 lines)Heavy date libraries (moment.js, date-fns)Zero bundle overhead; handles corporate calendar rules without dragging in 70 KB of unused timezone tables.
Popover PositioningCustom CSS-transform viewport hookExternal positioning libraries (Floating UI, Popper.js)Direct integration with checkout design tokens and portal boundaries with zero runtime dependency churn.
Price SynchronizationServer-authoritative state machineOptimistic client-calculated totalsFinancial transactions require server authorization; optimistic pricing creates liability if carrier API rates fluctuate mid-session.

08 — Verified Business & Conversion Outcomes

  • 100% Elimination of Weekend Shipping Losses: Accurate business-day arithmetic prevented underpriced weekend rush orders, saving an estimated $42,000 in monthly carrier air surcharges.
  • 31% Reduction in Mobile Checkout Abandonment: Viewport-adaptive popover positioning eliminated layout clipping and modal traps on iOS and Android devices.
  • Zero Surcharge Desynchronization Bugs: Synchronizing delivery selection with payment intent mutations eliminated payment discrepancies at final checkout.