@thorprovider/create-storefront 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/README.md +119 -0
  2. package/bin/install.js +116 -0
  3. package/commands/sf-add-view.md +21 -0
  4. package/commands/sf-init.md +16 -0
  5. package/commands/sf-theme.md +15 -0
  6. package/commands/sf-view.md +20 -0
  7. package/package.json +40 -0
  8. package/recipes/archetype.schema.json +39 -0
  9. package/recipes/archetypes.json +148 -0
  10. package/recipes/recipe.schema.json +59 -0
  11. package/recipes/recipes.json +90 -0
  12. package/recipes/sections.json +46 -0
  13. package/recipes/validate.mjs +190 -0
  14. package/skills/building-storefronts/SKILL.md +178 -0
  15. package/skills/building-storefronts/references/frontend-integration.md +229 -0
  16. package/skills/json-render-core/SKILL.md +291 -0
  17. package/skills/json-render-next/SKILL.md +194 -0
  18. package/skills/json-render-react/SKILL.md +298 -0
  19. package/skills/json-render-remotion/SKILL.md +111 -0
  20. package/skills/json-render-shadcn/SKILL.md +159 -0
  21. package/skills/json-render-solid/SKILL.md +204 -0
  22. package/skills/nextjs-shadcn/SKILL.md +303 -0
  23. package/skills/nextjs-shadcn/references/architecture.md +499 -0
  24. package/skills/nextjs-shadcn/references/project-setup.md +127 -0
  25. package/skills/nextjs-shadcn/references/shadcn-platform.md +258 -0
  26. package/skills/nextjs-shadcn/references/sidebar.md +274 -0
  27. package/skills/nextjs-shadcn/references/styling.md +555 -0
  28. package/skills/sf-scaffold/SKILL.md +118 -0
  29. package/skills/sf-theme-gen/SKILL.md +44 -0
  30. package/skills/sf-view-gen/SKILL.md +94 -0
  31. package/skills/shadcn-component-discovery/SKILL.md +273 -0
  32. package/skills/shadcn-component-discovery/references/registries.md +226 -0
  33. package/skills/shadcn-theming/SKILL.md +104 -0
  34. package/skills/shadcn-theming/references/templates/theme-setup.md +109 -0
  35. package/skills/shadcn-theming/references/theming-guide.md +90 -0
  36. package/skills/storefront-best-practices/SKILL.md +421 -0
  37. package/skills/storefront-best-practices/reference/components/breadcrumbs.md +123 -0
  38. package/skills/storefront-best-practices/reference/components/cart-popup.md +189 -0
  39. package/skills/storefront-best-practices/reference/components/country-selector.md +298 -0
  40. package/skills/storefront-best-practices/reference/components/footer.md +112 -0
  41. package/skills/storefront-best-practices/reference/components/hero.md +241 -0
  42. package/skills/storefront-best-practices/reference/components/megamenu.md +239 -0
  43. package/skills/storefront-best-practices/reference/components/navbar.md +397 -0
  44. package/skills/storefront-best-practices/reference/components/popups.md +221 -0
  45. package/skills/storefront-best-practices/reference/components/product-card.md +125 -0
  46. package/skills/storefront-best-practices/reference/components/product-reviews.md +217 -0
  47. package/skills/storefront-best-practices/reference/components/product-slider.md +174 -0
  48. package/skills/storefront-best-practices/reference/components/search.md +101 -0
  49. package/skills/storefront-best-practices/reference/connecting-to-backend.md +391 -0
  50. package/skills/storefront-best-practices/reference/design.md +388 -0
  51. package/skills/storefront-best-practices/reference/features/promotions.md +307 -0
  52. package/skills/storefront-best-practices/reference/features/wishlist.md +230 -0
  53. package/skills/storefront-best-practices/reference/layouts/account.md +380 -0
  54. package/skills/storefront-best-practices/reference/layouts/cart.md +316 -0
  55. package/skills/storefront-best-practices/reference/layouts/checkout.md +486 -0
  56. package/skills/storefront-best-practices/reference/layouts/home-page.md +264 -0
  57. package/skills/storefront-best-practices/reference/layouts/order-confirmation.md +231 -0
  58. package/skills/storefront-best-practices/reference/layouts/product-details.md +527 -0
  59. package/skills/storefront-best-practices/reference/layouts/product-listing.md +520 -0
  60. package/skills/storefront-best-practices/reference/layouts/static-pages.md +356 -0
  61. package/skills/storefront-best-practices/reference/medusa.md +307 -0
  62. package/skills/storefront-best-practices/reference/mobile-responsiveness.md +183 -0
  63. package/skills/storefront-best-practices/reference/seo.md +195 -0
  64. package/templates/app/app/[[...slug]]/page.tsx +17 -0
  65. package/templates/app/app/[[...slug]]/renderer.tsx +10 -0
  66. package/templates/app/app/globals.css +101 -0
  67. package/templates/app/app/layout.tsx +35 -0
  68. package/templates/app/lib/__STOREFRONT__/catalog.ts +132 -0
  69. package/templates/app/lib/__STOREFRONT__/handlers.ts +33 -0
  70. package/templates/app/lib/__STOREFRONT__/registry.tsx +134 -0
  71. package/templates/app/lib/__STOREFRONT__/runtime.ts +25 -0
  72. package/templates/app/lib/__STOREFRONT__/spec/home.ts +62 -0
  73. package/templates/app/lib/__STOREFRONT__/spec/index.ts +59 -0
  74. package/templates/app/lib/__STOREFRONT__/spec/types.ts +14 -0
  75. package/templates/app/lib/__STOREFRONT__/state.ts +35 -0
@@ -0,0 +1,486 @@
1
+ # Checkout Page Layout
2
+
3
+ ## Contents
4
+
5
+ - [Overview](#overview)
6
+ - [Decision: Single-Page vs Multi-Step](#decision-single-page-vs-multi-step)
7
+ - [Guest vs Logged-In Checkout](#guest-vs-logged-in-checkout)
8
+ - [Component Architecture](#component-architecture-recommended)
9
+ - [Checkout Flow](#checkout-flow)
10
+ - [Key Ecommerce Considerations](#key-ecommerce-considerations)
11
+ - [Backend Integration](#backend-integration)
12
+ - [Mobile Checkout](#mobile-checkout)
13
+ - [Trust and Conversion Optimization](#trust-and-conversion-optimization)
14
+ - [Error Handling](#error-handling)
15
+ - [Checklist](#checklist)
16
+
17
+ ## Overview
18
+
19
+ Final step in conversion funnel where customers provide shipping and payment information. Must be optimized for completion with minimal friction.
20
+
21
+ **⚠️ CRITICAL: Always fetch shipping methods AND payment methods from backend. Users must be able to select from available options - never skip payment method selection.**
22
+
23
+ ### Key Requirements
24
+
25
+ - Clear steps and progress indication
26
+ - Guest checkout option (if backend supports it)
27
+ - Shipping address and method selection
28
+ - **Shipping methods fetched from backend (vary by address/region)**
29
+ - **Payment methods fetched from backend (user must select preferred method)**
30
+ - Payment processing
31
+ - Order review before submission
32
+ - Trust signals throughout
33
+ - Mobile-optimized (60%+ traffic is mobile)
34
+ - Fast loading and submission
35
+
36
+ ## Decision: Single-Page vs Multi-Step
37
+
38
+ **Use Single-Page Checkout when:**
39
+ - Simple products with few shipping options
40
+ - Mobile-heavy traffic (>60% mobile users)
41
+ - Fewer form fields required (<15 total)
42
+ - Startup or new store (minimize friction)
43
+ - Fast checkout is prioritized
44
+ - Low average order value (<$50)
45
+
46
+ **Benefits:**
47
+ - Fewer clicks (no step navigation)
48
+ - User sees full scope upfront
49
+ - Faster on mobile (no page loads)
50
+ - Lower perceived friction
51
+
52
+ **Use Multi-Step Checkout when:**
53
+ - Complex shipping (international, multiple carriers)
54
+ - B2B customers (need detailed information)
55
+ - Many form fields required (>15 total)
56
+ - High-value products (>$100, thoroughness expected)
57
+ - Established brand (customers trust process)
58
+ - Need clear progress indication
59
+
60
+ **Benefits:**
61
+ - Less overwhelming (one step at a time)
62
+ - Progress indicator reduces anxiety
63
+ - Easier step-by-step validation
64
+ - Better for complex forms
65
+
66
+ **Recommended: Hybrid Approach**
67
+ - Single-page scroll layout on desktop
68
+ - Accordion-based sections on mobile (expand/collapse)
69
+ - Progressive disclosure of sections
70
+ - Best of both worlds
71
+
72
+ **Common steps:**
73
+ 1. Shipping Information (address)
74
+ 2. Delivery (shipping method selection)
75
+ 3. Payment (payment method and details)
76
+ 4. Review (final review before submission)
77
+
78
+ ## Guest vs Logged-In Checkout
79
+
80
+ **IMPORTANT:** Guest checkout availability depends on backend support.
81
+
82
+ **Guest checkout (recommended if backend supports it):**
83
+ - Reduces friction (no signup barrier)
84
+ - "Checkout as Guest" option prominent
85
+ - Email required for order confirmation
86
+ - Optional "Create account?" checkbox after order
87
+ - Don't force account creation
88
+
89
+ **Logged-in checkout:**
90
+ - Pre-fill saved addresses and payment methods
91
+ - "Returning customer? Log in" link at top
92
+ - Allow seamless switch between guest/login
93
+
94
+ ## Component Architecture (RECOMMENDED)
95
+
96
+ **Build separate components for each checkout step for better maintainability and reusability.**
97
+
98
+ ✅ **Create individual step components:**
99
+ - `ShippingInformationStep` - Contact and shipping address form
100
+ - `DeliveryMethodStep` - Shipping method selection
101
+ - `PaymentInformationStep` - Payment method and details
102
+ - `OrderReviewStep` - Final review before submission
103
+
104
+ **Benefits of component separation:**
105
+ - **Maintainability**: Fix bugs or update one step without affecting others
106
+ - **Reusability**: Reuse shipping address component in account settings, checkout, etc.
107
+ - **Testability**: Test each step independently
108
+ - **Code organization**: Clearer separation of concerns (validation, submission logic per step)
109
+ - **Easier debugging**: Isolate issues to specific steps
110
+ - **Flexibility**: Easy to reorder steps or add/remove steps based on requirements
111
+ - **Performance**: Lazy load steps or split bundles for faster initial load
112
+
113
+ **What to separate:**
114
+ - Main checkout page/container component
115
+ - Individual step components (ShippingInformationStep, DeliveryMethodStep, etc.)
116
+ - Reusable order summary component (shown on all steps)
117
+
118
+ **Component communication:**
119
+ Each step component should accept:
120
+ - Current step data (form values)
121
+ - Callback to update data (e.g., `onShippingUpdate`)
122
+ - Callback to proceed to next step (e.g., `onContinue`)
123
+ - Loading/error states
124
+ - Validation errors
125
+
126
+ **Shared components:**
127
+ - Address form (used in shipping and billing)
128
+ - Payment method selector
129
+ - Order summary (sidebar, shown on all steps)
130
+
131
+ **Works for both single-page and multi-step:**
132
+ - Single-page: Render all steps at once, scroll-based navigation
133
+ - Multi-step: Show one component at a time, controlled by step state
134
+ - Accordion: Expand/collapse components as sections
135
+
136
+ **Common mistake:**
137
+ - ❌ Building entire checkout as one massive component with all form fields, logic, and validation mixed together
138
+ - ✅ Separate components for each step, shared state management in parent
139
+
140
+ ## Checkout Flow
141
+
142
+ ### Complete Checkout Flow Diagram
143
+
144
+ ```
145
+ ┌─────────────────────────────────────────────────────────────────────┐
146
+ │ CHECKOUT PROCESS │
147
+ └─────────────────────────────────────────────────────────────────────┘
148
+
149
+ ┌──────────────────────────────────────────────────────┐
150
+ │ Optional: Guest Checkout vs Login │
151
+ │ • Guest: Enter email only │
152
+ │ • Logged-in: Pre-fill saved data │
153
+ └────────────────────┬─────────────────────────────────┘
154
+ │
155
+ ▼
156
+ ┌──────────────────────────────────────────────────────┐
157
+ │ STEP 1: Shipping Information │
158
+ │ ├─ Contact: Email, Phone │
159
+ │ ├─ Shipping Address: Name, Address, City, etc. │
160
+ │ └─ Billing Address: □ Same as shipping / Different │
161
+ └────────────────────┬─────────────────────────────────┘
162
+ │
163
+ ▼
164
+ ┌──────────────────────────────────────────────────────┐
165
+ │ STEP 2: Delivery │
166
+ │ • Fetch shipping methods from backend │
167
+ │ • Display: Standard, Express, Overnight │
168
+ │ • Show: Cost + Delivery estimate │
169
+ │ • Update order total │
170
+ └────────────────────┬─────────────────────────────────┘
171
+ │
172
+ ▼
173
+ ┌──────────────────────────────────────────────────────┐
174
+ │ STEP 3: Payment Information │
175
+ │ • Fetch payment methods from backend │
176
+ │ • Options: Card, PayPal, Apple Pay, etc. │
177
+ │ • Enter: Card details (tokenized) │
178
+ │ • Use billing address from Step 1 │
179
+ └────────────────────┬─────────────────────────────────┘
180
+ │
181
+ ▼
182
+ ┌──────────────────────────────────────────────────────┐
183
+ │ STEP 4: Order Review │
184
+ │ • Review: Items, addresses, shipping, payment │
185
+ │ • Optional: □ Agree to Terms and Conditions │
186
+ │ • Click: [Place Order] Button │
187
+ │ → Payment processing triggered │
188
+ └────────────────────┬─────────────────────────────────┘
189
+ │
190
+ ▼
191
+ ┌──────────────────────────────────────────────────────┐
192
+ │ Loading: Processing payment... │
193
+ │ • Authorize/capture payment via gateway │
194
+ │ • Create order in backend │
195
+ │ • Send confirmation email │
196
+ └────────────────────┬─────────────────────────────────┘
197
+ │
198
+ ┌────┴────┐
199
+ │ │
200
+ Success Failure
201
+ │ │
202
+ ▼ ▼
203
+ ┌───────────────────┐ ┌──────────────────────┐
204
+ │ Order Confirmation│ │ Show Error Message │
205
+ │ • Order number │ │ • Retry payment │
206
+ │ • Details │ │ • Keep form data │
207
+ │ • Tracking link │ │ • Suggest solutions │
208
+ └───────────────────┘ └──────────────────────┘
209
+ ```
210
+
211
+ ## Key Ecommerce Considerations
212
+
213
+ ### Shipping Address Collection
214
+
215
+ Collect:
216
+ - Required: email, name, address, city, state/zip, country
217
+ - Optional: phone.
218
+
219
+ **Key ecommerce considerations:**
220
+ - Email placement: First if guest checkout (identifies customer)
221
+ - Country placement: Early if shipping methods vary by country (affects available shipping)
222
+ - Phone: Optional to reduce friction, but recommended for delivery coordination
223
+ - Billing address: "Same as shipping" checkbox (default checked)
224
+
225
+ **For Medusa backends:**
226
+ - Country dropdown: Show only countries from cart's region (don't show all countries globally)
227
+ - Get countries from: `cart.region.countries` or `sdk.store.region.retrieve(cart.region_id)`
228
+ - Medusa regions contain specific countries - limiting options ensures correct pricing and shipping
229
+ - If user needs different country, they must change region first (typically via country selector component)
230
+
231
+ ### Shipping Method Selection
232
+
233
+ **Fetch from backend after address provided** (shipping methods vary by address/region):
234
+ - Display as radio buttons with cost + delivery estimate
235
+ - Update order total immediately when method changes
236
+ - Highlight free shipping if available
237
+ - Show "Add $X for free shipping" if close to threshold
238
+ - Handle unavailable shipping: show message, suggest alternatives
239
+
240
+ ### Payment Method Selection
241
+
242
+ **CRITICAL: Always fetch payment methods from backend and allow user to select from available options.**
243
+
244
+ Payment methods vary by store configuration (backend settings). NEVER assume which payment methods are available or hardcode payment options. Users MUST be able to choose their preferred payment method.
245
+
246
+ **Fetch available methods from backend:**
247
+ ```typescript
248
+ // ALWAYS fetch payment providers from backend
249
+ // For Medusa:
250
+ const { payment_providers } = await sdk.store.payment.listPaymentProviders()
251
+
252
+ // For other backends:
253
+ // Change based on the integrated backend
254
+ const paymentMethods = await fetch(`${apiUrl}/payment-methods`)
255
+ // Returns: card, paypal, apple_pay, google_pay, stripe, etc.
256
+ ```
257
+
258
+ **Display payment method selection UI:**
259
+ - Show all enabled payment providers returned by backend
260
+ - Allow user to select their preferred method (radio buttons or cards)
261
+ - Don't skip selection step - user must actively choose
262
+ - Map backend codes to display names in the storefront. For example `pp_system_manual` -> `Manual payment`.
263
+ - Common options: Credit/Debit Card, PayPal, Apple Pay, Google Pay, Buy Now Pay Later
264
+
265
+ **Available payment methods (examples, actual options come from backend):**
266
+ - Credit/Debit Card (most common, via Stripe/Braintree/other gateway)
267
+ - PayPal (redirect or in-context)
268
+ - Apple Pay (Safari, iOS only)
269
+ - Google Pay (Chrome, Android)
270
+ - Buy Now Pay Later (Affirm, Klarna - if enabled by store)
271
+ - Manual payment (bank transfer, cash on delivery - if enabled)
272
+
273
+ **Why backend fetching is required:**
274
+ - Store admin controls which payment providers are enabled
275
+ - Payment methods vary by region, currency, order value
276
+ - Test vs production mode affects available methods
277
+ - Can't assume all stores use the same payment gateway
278
+
279
+ **For Medusa backends - Payment flow:**
280
+
281
+ 1. **List available payment providers:**
282
+ ```typescript
283
+ const { payment_providers } = await sdk.store.payment.listPaymentProviders({
284
+ region_id: cart.region_id // Required to get region-specific providers
285
+ })
286
+ ```
287
+
288
+ 2. **Display providers and allow user to select:**
289
+ Show payment providers as radio buttons or cards. User must actively select one.
290
+
291
+ 3. **Initialize payment session after selection:**
292
+ ```typescript
293
+ // When user selects a provider
294
+ await sdk.store.payment.initiatePaymentSession(cart, {
295
+ provider_id: selectedProvider.id // e.g., "pp_stripe_stripe", "pp_system_default"
296
+ })
297
+
298
+ // Re-fetch cart to get updated payment session data
299
+ const { cart: updatedCart } = await sdk.store.cart.retrieve(cart.id)
300
+ ```
301
+
302
+ 4. **Render provider-specific UI:**
303
+ - Stripe providers (`pp_stripe_*`): Render Stripe Elements card UI
304
+ - Manual payment (`pp_system_default`): No additional UI needed
305
+ - Other providers: Implement according to provider requirements
306
+
307
+ **Important:** Payment provider IDs are returned from the backend (e.g., `pp_stripe_stripe`, `pp_system_manual`). Map these to user-friendly display names in your UI.
308
+
309
+ **Digital wallets (mobile priority):**
310
+ - Apple Pay / Google Pay should be prominent on mobile
311
+ - One-click payment (pre-filled shipping)
312
+ - Significantly faster checkout
313
+ - Higher conversion on mobile
314
+
315
+ **Card payment:**
316
+ - Use payment gateway (Stripe Elements, Braintree)
317
+ - Never handle raw card data (PCI compliance)
318
+ - Tokenize card data before submission
319
+ - Auto-detect card type (show logo)
320
+
321
+ ### Order Review
322
+
323
+ **Display for final confirmation:**
324
+ Cart items, addresses, shipping method/cost, payment method, order total breakdown.
325
+
326
+ **Key elements:**
327
+ - "Edit" link next to each section (returns to step or edits inline)
328
+ - Terms checkbox (if required): "I agree to Terms and Conditions"
329
+ - Place Order button: Large (48-56px), shows total, loading state on submit
330
+
331
+ ### Order Summary Sidebar
332
+
333
+ **Desktop:** Sticky sidebar with items, prices, totals. Updates in real-time.
334
+ **Mobile:** Collapsible at top ("Show order summary" toggle). Keeps focus on form.
335
+
336
+ ## Backend Integration
337
+
338
+ **Address validation (optional):**
339
+ - Use address lookup APIs (Google, SmartyStreets) for higher accuracy
340
+ - Tradeoff: accuracy vs friction. Consider for high-value orders.
341
+
342
+ **Payment processing flow:**
343
+ 1. Frontend tokenizes payment (Stripe Elements, Braintree)
344
+ 2. Send token + order details to backend
345
+ 3. Backend authorizes/captures payment & creates order
346
+ 4. Redirect to confirmation page
347
+
348
+ **Never:** Send raw card data, store cards without PCI compliance, process payments client-side.
349
+
350
+ **On payment failure:** Show specific error, keep form data, allow retry without re-entering.
351
+
352
+ ### Order Completion and Cart Cleanup (CRITICAL)
353
+
354
+ **After order is successfully placed, you MUST reset the cart state:**
355
+
356
+ **Common issue:** Cart popup and cart state still show old cart content after order is placed. This happens because the global cart state (Context, Zustand, Redux) isn't cleared after checkout completion.
357
+
358
+ **Required actions on successful order:**
359
+
360
+ 1. **Clear cart from global state:**
361
+ - Reset cart state in Context/Zustand/Redux to null or empty
362
+ - Update cart count to 0 in navbar
363
+ - Prevent old cart items from showing in cart popup
364
+
365
+ 2. **Clear localStorage cart ID:**
366
+ - Remove cart ID from localStorage: `localStorage.removeItem('cart_id')`
367
+ - Or create new cart and update cart ID in localStorage
368
+ - Ensures fresh cart for next shopping session
369
+
370
+ 3. **Invalidate cart queries (if using TanStack Query):**
371
+ - `queryClient.invalidateQueries({ queryKey: ['cart'] })`
372
+ - Or `queryClient.removeQueries({ queryKey: ['cart', cartId] })`
373
+ - Prevents stale cart data from cache
374
+
375
+ 4. **Redirect to order confirmation page:**
376
+ - Navigate to `/order-confirmation/[order_id]` or `/thank-you/[order_id]`
377
+ - Show order details, tracking info, confirmation
378
+
379
+ **Pattern:**
380
+ ```typescript
381
+ // After successful order placement
382
+ async function onOrderSuccess(order) {
383
+ // 1. Clear cart state
384
+ setCart(null) // or clearCart() from context
385
+
386
+ // 2. Clear localStorage
387
+ localStorage.removeItem('cart_id')
388
+
389
+ // 3. Invalidate queries (if using TanStack Query)
390
+ queryClient.invalidateQueries({ queryKey: ['cart'] })
391
+
392
+ // 4. Redirect to confirmation
393
+ router.push(`/order-confirmation/${order.id}`)
394
+ }
395
+ ```
396
+
397
+ **Why this is critical:**
398
+ - Without clearing cart state, cart popup shows old items after order
399
+ - User sees "phantom cart" if they click cart icon after checkout
400
+ - Creates confusion and poor UX
401
+ - May prevent user from starting new shopping session
402
+
403
+ ## Mobile Checkout
404
+
405
+ **Key optimizations:**
406
+ - Digital wallets prominent (Apple Pay/Google Pay) - significantly faster checkout
407
+ - Single-column layout, 44-48px touch targets
408
+ - Appropriate keyboard types, autocomplete attributes enabled
409
+ - Collapsible order summary at top (shows total, expands on tap)
410
+ - Sticky Place Order button at bottom (always accessible, shows total)
411
+ - Accordion sections (one step at a time, reduces cognitive load)
412
+
413
+ **For detailed mobile patterns and safe area insets**, see `reference/mobile-responsiveness.md`.
414
+
415
+ ## Trust and Conversion Optimization
416
+
417
+ **Trust signals (critical for conversion):**
418
+ - "Secure Checkout" badge, payment provider logos (Visa, Mastercard)
419
+ - Return policy link visible, customer support contact
420
+ - Near Place Order: "100% secure checkout", guarantees/free returns if offered
421
+ - For new brands: Customer review count, social proof
422
+
423
+ **Reduce abandonment:**
424
+ - Progress indicator (shows steps remaining)
425
+ - Auto-save form data, clear pricing (no surprise fees)
426
+ - Minimal required fields, smart defaults, autocomplete enabled
427
+
428
+ **Reduce perceived friction:**
429
+ - "No account required" (guest checkout)
430
+ - "Free shipping" highlighted
431
+ - Time estimate: "Less than 2 minutes"
432
+
433
+ ## Error Handling
434
+
435
+ **Form validation:**
436
+ - Validate on blur, show error below field
437
+ - User-friendly messages ("Please enter a valid email address")
438
+ - Scroll to first error on submit
439
+
440
+ **Payment errors:**
441
+ - Card declined: "Your card was declined. Please try another payment method."
442
+ - Keep form data, suggest alternatives (try another card, PayPal)
443
+ - Network timeout: Show retry option without re-entering data
444
+
445
+ **Stock availability errors:**
446
+ - Out of stock: Remove item, recalculate, allow continue with remaining items
447
+ - Quantity reduced: Update automatically, show message, allow continue
448
+
449
+ ## Checklist
450
+
451
+ **Essential checkout features:**
452
+
453
+ - [ ] **RECOMMENDED: Separate components created for each checkout step**
454
+ - [ ] Components: ShippingInformationStep, DeliveryMethodStep, PaymentInformationStep, OrderReviewStep
455
+ - [ ] Decision made: Single-page or multi-step (based on complexity)
456
+ - [ ] Guest checkout option (if backend supports it)
457
+ - [ ] Email field first (if guest checkout)
458
+ - [ ] Shipping address form with autocomplete attributes
459
+ - [ ] "Billing same as shipping" checkbox (default checked)
460
+ - [ ] Shipping methods fetched from backend dynamically
461
+ - [ ] Shipping cost updates order total in real-time
462
+ - [ ] **CRITICAL: Payment methods fetched from backend (NEVER assume or hardcode)**
463
+ - [ ] **CRITICAL: Payment method selection UI shown to user (user must select from available options)**
464
+ - [ ] Payment methods: show only enabled providers returned by backend
465
+ - [ ] For Medusa: Payment session initialized after user selects provider (sdk.store.payment.initiatePaymentSession)
466
+ - [ ] For Medusa: Country dropdown limited to cart's region countries
467
+ - [ ] Digital wallets prominent on mobile (Apple Pay, Google Pay)
468
+ - [ ] Payment tokenization (never send raw card data)
469
+ - [ ] Order review section before submission
470
+ - [ ] Order summary sidebar (sticky on desktop, collapsible on mobile)
471
+ - [ ] Promo code input (if not applied in cart)
472
+ - [ ] Trust signals throughout (secure checkout, return policy)
473
+ - [ ] Terms and conditions checkbox (if required)
474
+ - [ ] Place Order button prominent (48-56px, shows total)
475
+ - [ ] Loading state during payment processing
476
+ - [ ] Progress indicator (if multi-step)
477
+ - [ ] Clear error messages for validation failures
478
+ - [ ] Error handling for payment failures (keep form data)
479
+ - [ ] Stock availability check before order creation
480
+ - [ ] Mobile optimized (44-48px touch targets, single column)
481
+ - [ ] Autocomplete enabled on all form fields
482
+ - [ ] Keyboard accessible (tab through fields, enter to submit)
483
+ - [ ] ARIA labels on form fields (aria-required, aria-invalid)
484
+ - [ ] Redirect to order confirmation on success
485
+ - [ ] **CRITICAL: Clear cart state after successful order** (reset cart in Context/Zustand, remove cart ID from localStorage, invalidate cart queries)
486
+ - [ ] Cart popup shows empty cart after order completion (not old items)