Temple of the Moon Books - Shipping Backend
Overview
Dynamic shipping rate calculator with local delivery, USPS rate approximations, handling fees, and shipping markup for larger orders.
Location: src/lib/shipping.ts
Pricing Structure
| Component | Rule | Amount |
|---|---|---|
| Handling Fee | Items over 1 lb | $2.00 per order |
| Shipping Markup | Orders over $50 | 20% markup on shipping |
| Local Delivery | KC Metro ZIP codes | Free |
Shipping Methods
USPS First Class (up to 13 oz)
- 3-5 business days
- Rates: 4.50 based on weight
USPS Priority Mail (any weight)
- 2-3 business days
- Rates: 45.00+ based on weight
USPS Ground Advantage (up to 70 lbs)
- 5-7 business days
- Rates: 28.00+ based on weight
Local Delivery (KC Metro)
- 1-3 business days
- Free for all KC Metro ZIP codes
KC Metro Free Delivery Zone
Includes all ZIP codes for:
- Kansas City, MO (64xxx)
- Independence, Blue Springs, Leeβs Summit
- Raytown, Grandview
- Liberty, Gladstone, North KC
- Kansas City, KS (66xxx)
- Overland Park, Olathe, Shawnee, Lenexa
~150+ ZIP codes covered.
Rate Calculation Logic
calculateShipping(
totalWeightLbs: number,
destinationZip: string,
orderSubtotal?: number,
hasHeavyItem?: boolean
): ShippingEstimate- Check if local delivery eligible β free shipping
- Check for heavy items (>1 lb) β add $2 handling
- Check order subtotal (>$50) β apply 20% markup
- Calculate base USPS rates by weight
- Apply markup + handling to final price
- Sort by price, return all options
Checkout Integration
- Shipping calculated in real-time as ZIP is entered
- Auto-selects local delivery if eligible, otherwise cheapest option
- Tax calculated at 8.6% (Missouri)
Files involved:
src/lib/shipping.ts- Rate calculationsrc/app/checkout/page.tsx- Checkout UI
Recent Changes (2026-01-31)
- Added $2 handling fee for items over 1 lb
- Added 20% shipping markup for orders over $50
- Handling fee noted in shipping method descriptions
- Fixed price scraper to grab retail price (strikethrough) not sale price
- Created
scripts/fix-pricing.tsfor bulk price corrections
Testing
# Test shipping calculation
cd /home/shdwdev/projects/templeofthemoonbooks.com
npx ts-node -e "
import { calculateShipping, hasHeavyItem } from './src/lib/shipping';
console.log(calculateShipping(0.5, '64112', 75, false)); // KC, over $50
console.log(calculateShipping(2.0, '90210', 30, true)); // LA, heavy item
"