--- name: fake-stripe-payments category: fake-stripe-testing description: Build a fake Stripe-like payment system for testing booking/purchase flows without real credentials. Creates real DB records. --- # Fake Stripe Payment System Build a fake Stripe-like payment system for testing booking and purchase flows without real Stripe credentials. Creates real database records that integrate with existing admin dashboards. ## When to Use - Testing payment/booking flows in development - Demo environments where real payments aren't needed - QA testing end-to-end transaction pipelines - When you need transaction data to appear in admin dashboards ## Implementation Pattern ### 1. Database Schema Create records in existing tables (no new tables needed): **For Class Bookings:** - `reservations` table: customer_id, class_id, status='confirmed' - Decrement class spots_available **For Product Purchases:** - `orders` table: customer_id, total, order_number (generate like VAGD-DG2B-5KV7) - `order_line_items` table: order_id, product_id, quantity, unit_price - `transactions` table: order_id, amount, stripe_fee, net_amount, payment_method, gateway='Stripe (Fake)', device_type='Mobile App' - `customer_credits` table: customer_id, credit_package_id, credits (if product is credit package) - Update `customers.total_remaining_credits` and `customers.total_spent_all` ### 2. API Endpoints ```javascript // POST /api/bookings // Body: { customer_id, class_id } // Creates reservation, decrements spots, returns success // POST /api/orders // Body: { customer_id, items: [{ product_id, quantity }] } // Creates order + line items + transaction // If credit package: creates customer_credits, updates customer totals // Returns order with fake Stripe ID (ch_fake_abc123) ``` ### 3. Checkout Modal Component - Pre-fill test card: 4242 4242 4242 4242 - Show billing info (can be read-only for testing) - Calculate totals with tax (e.g., 8.25% TX sales tax) - Calculate Stripe fees: 2.9% + $0.30 - On confirm: call API, show success message, update UI (spots count, etc.) ### 4. Order Number Generation ```javascript function generateOrderNumber() { const parts = [ Math.random().toString(36).substring(2, 6).toUpperCase(), Math.random().toString(36).substring(2, 6).toUpperCase(), Math.random().toString(36).substring(2, 6).toUpperCase() ]; return parts.join('-'); // e.g., VAGD-DG2B-5KV7 } ``` ### 5. Fake Stripe IDs ```javascript const chargeId = `ch_fake_${Math.random().toString(36).substring(2, 12)}`; const paymentIntentId = `pi_fake_${Math.random().toString(36).substring(2, 12)}`; ``` ## Key Details - Tax rate: 8.25% (Texas sales tax) - Stripe fee formula: amount * 0.029 + 0.30 - Payment method display: "Visa ending in 4242" - Gateway: "Stripe (Fake)" - Device type: "Mobile App" - Test card: 4242 4242 4242 4242, any expiry, any CVC ## Verification After checkout, verify in database: - Reservation/order appears in admin dashboard - Transaction record with correct amount/fees - Customer credits updated (if applicable) - Class spots decremented (for bookings) ## Pitfalls - Route ordering: put `/api/customers/search` before `/api/customers/:id` to avoid param matching issues - Timezone conversion: DB stores UTC timestamps, ensure date queries align - Spot counting: use COALESCE for spots_available, handle nulls - Idempotency: consider adding idempotency keys for production-like testing ## Testing Flow 1. Profile → Sign In (Demo) → search customer 2. Navigate to class/product detail 3. Tap Book/Purchase button 4. Confirm in checkout modal 5. Verify success message + UI updates 6. Check admin dashboard for new records