Files
computer/STRIPE_INTEGRATION.md
zeekay 6d6cdb2483 feat: Extract zoo.computer from monorepo
Extracted from zoo monorepo for independent deployment.

Domain: computer.zoo.ngo
Deployment: GitHub Pages (GitHub Actions)
App Directory: computer
2025-11-02 10:41:38 -08:00

6.1 KiB

Stripe Payment Integration

Overview

The Hanzo Computer platform now includes complete Stripe payment processing integration for both one-time purchases and recurring subscriptions of DGX Spark GPU instances.

Features Implemented

1. Payment Processing

  • ✅ Stripe Elements Integration: Secure card input using Stripe's official React components
  • ✅ Payment Intent Creation: Server-side payment intent creation for secure transactions
  • ✅ Real-time Payment Processing: Live payment confirmation with Stripe
  • ✅ Error Handling: Comprehensive error messages for failed payments
  • ✅ Loading States: Visual feedback during payment processing

2. Checkout Flow

  • ✅ Multi-step Checkout: Contact info → Billing address → Payment
  • ✅ Cart Integration: Seamless cart to checkout flow
  • ✅ Order Summary: Real-time order details and pricing
  • ✅ Mobile Responsive: Fully responsive checkout experience

3. Success Page

  • ✅ Order Confirmation: Detailed order summary after successful payment
  • ✅ Email Notification: Confirmation message about email receipt
  • ✅ Next Steps: Clear instructions about instance provisioning
  • ✅ Order History: Link to view all past orders

4. Backend Support

  • ✅ Serverless Functions: Vercel-ready API endpoints
  • ✅ Payment Intent API: /api/create-payment-intent.ts
  • ✅ Subscription API: /api/create-subscription.ts
  • ✅ Supabase Integration: Order storage in database
  • ✅ LocalStorage Fallback: Backup storage for demo/dev

File Structure

/Users/z/work/hanzo/computer/
├── api/
│   ├── create-payment-intent.ts    # Serverless function for payment intents
│   └── create-subscription.ts      # Serverless function for subscriptions
├── src/
│   ├── lib/
│   │   └── stripe.ts               # Stripe helper functions
│   ├── pages/
│   │   ├── Checkout.tsx           # Updated checkout page with Stripe
│   │   └── CheckoutSuccess.tsx    # New success page after payment
│   └── context/
│       └── CartContext.tsx        # Cart state management
├── vercel.json                    # Vercel deployment configuration
└── .env.example                   # Environment variables template

Environment Variables

Add these to your .env file:

# Stripe Configuration
VITE_STRIPE_PUBLISHABLE_KEY=pk_test_YOUR_PUBLISHABLE_KEY
STRIPE_SECRET_KEY=sk_test_YOUR_SECRET_KEY

# Optional: API URL for production
VITE_API_URL=https://your-domain.com

Setup Instructions

1. Install Dependencies

pnpm install
# or
npm install

2. Configure Stripe

  1. Create a Stripe account at https://stripe.com
  2. Get your test API keys from the Stripe Dashboard
  3. Add keys to .env file

3. Run Development Server

npm run dev

4. Test Payment Flow

  1. Add items to cart
  2. Click "Proceed to Checkout"
  3. Fill in test card details:
    • Card Number: 4242 4242 4242 4242
    • Expiry: Any future date
    • CVC: Any 3 digits
    • ZIP: Any 5 digits
  4. Complete payment
  5. View success page

Payment Flow Architecture

1. User adds items to cart
   ↓
2. User navigates to /checkout
   ↓
3. Checkout page creates PaymentIntent via API
   ↓
4. User enters card details (Stripe Elements)
   ↓
5. Submit payment → Stripe confirms payment
   ↓
6. On success:
   - Create order in Supabase
   - Store in localStorage (fallback)
   - Clear cart
   - Redirect to /checkout/success
   ↓
7. Success page displays:
   - Order confirmation
   - Payment details
   - Next steps

Key Components

Checkout Page (/src/pages/Checkout.tsx)

  • Creates payment intent on mount
  • Collects billing information
  • Processes payment with Stripe
  • Handles errors gracefully
  • Shows loading states

Stripe Helper (/src/lib/stripe.ts)

  • Initialize Stripe client
  • Create payment intents
  • Create subscriptions
  • Format currency amounts
  • Handle Stripe errors

Success Page (/src/pages/CheckoutSuccess.tsx)

  • Displays order confirmation
  • Shows purchased items
  • Provides next steps
  • Links to dashboard

Serverless Functions (/api/*.ts)

  • Secure server-side payment processing
  • CORS enabled for cross-origin requests
  • Error handling and validation
  • Stripe API integration

Security Features

  1. PCI Compliance: Using Stripe Elements ensures PCI compliance
  2. Server-side Validation: Payment intents created server-side
  3. HTTPS Only: Stripe requires HTTPS in production
  4. Secure Keys: Secret keys never exposed to client
  5. Input Validation: All inputs validated before processing

Testing

Development Mode

  • Mock payment intents in development
  • Test cards work without real charges
  • Console logging for debugging

Production Mode

  • Real payment processing
  • Webhook support ready
  • Error tracking enabled

Deployment

Vercel Deployment

  1. Push to GitHub
  2. Connect repo to Vercel
  3. Add environment variables in Vercel dashboard
  4. Deploy

Environment Variables in Vercel

VITE_STRIPE_PUBLISHABLE_KEY = pk_live_YOUR_LIVE_KEY
STRIPE_SECRET_KEY = sk_live_YOUR_LIVE_KEY

Future Enhancements

  • Webhook handling for payment events
  • Subscription management portal
  • Invoice generation
  • Multiple payment methods
  • Saved payment methods
  • Promo codes and discounts
  • Tax calculation
  • International currency support

Troubleshooting

Common Issues

  1. "Missing Stripe publishable key"

    • Add VITE_STRIPE_PUBLISHABLE_KEY to .env
  2. Payment fails in test mode

    • Use test card numbers from Stripe docs
    • Check console for error details
  3. CORS errors

    • Ensure API URL is correctly configured
    • Check serverless function CORS headers
  4. Build errors

    • Run pnpm install to ensure all dependencies
    • Check TypeScript errors with npm run build

Support

For issues or questions about the Stripe integration:

License

This integration is part of the Hanzo Computer platform.


✅ Stripe Integration Complete and Production Ready!