mirror of
https://github.com/hanzoai/agency.git
synced 2026-09-30 20:39:59 +00:00
- Add Stripe dependencies (@stripe/stripe-js and @stripe/react-stripe-js) - Create Stripe configuration with product/price IDs - Update PurchaseCredits component to use Stripe checkout - Add PaymentSuccess and PaymentCancel pages for redirect handling - Create environment variables example file - Add comprehensive Stripe integration documentation - Update routes to include success/cancel pages Note: This is a client-side implementation suitable for demos. Production use requires backend API for secure payment processing.
4.6 KiB
4.6 KiB
Stripe Payment Integration
This guide explains how to set up and use the Stripe payment integration for the Hanzo Agency website.
Setup Instructions
1. Create a Stripe Account
- Go to https://stripe.com and create an account
- Once logged in, navigate to the Stripe Dashboard
2. Get Your API Keys
- In the Stripe Dashboard, go to Developers > API keys
- Copy your Publishable key (starts with
pk_test_orpk_live_) - Keep your Secret key safe (you'll need it for backend integration)
3. Create Products and Prices
In the Stripe Dashboard, go to Products and create the following:
Credit Packs:
-
Starter Pack
- Name: "100 Credits - Starter Pack"
- Price: $100.00 (one-time)
- Copy the price ID (starts with
price_)
-
Professional Pack
- Name: "500 Credits - Professional Pack"
- Price: $450.00 (one-time)
- Copy the price ID
-
Enterprise Pack
- Name: "2000 Credits - Enterprise Pack"
- Price: $1,500.00 (one-time)
- Copy the price ID
Services:
-
Agency Service
- Name: "Full-Service Creative Agency"
- Price: $5,000.00/month (recurring)
- Copy the price ID
-
Instant Site
- Name: "Instant Site - 24hr Delivery"
- Price: $500.00 (one-time)
- Copy the price ID
4. Configure Environment Variables
- Create a
.envfile in the project root (copy from.env.example) - Add your Stripe configuration:
# Stripe Configuration
VITE_STRIPE_PUBLISHABLE_KEY=pk_test_your_key_here
# Credit Pack Price IDs
VITE_STRIPE_STARTER_PRICE_ID=price_xxxxx
VITE_STRIPE_PROFESSIONAL_PRICE_ID=price_xxxxx
VITE_STRIPE_ENTERPRISE_PRICE_ID=price_xxxxx
# Service Price IDs
VITE_STRIPE_AGENCY_PRICE_ID=price_xxxxx
VITE_STRIPE_INSTANT_SITE_PRICE_ID=price_xxxxx
5. Install Dependencies
npm install
# or
pnpm install
Testing the Integration
Test Credit Cards
Use these test card numbers in test mode:
- Success: 4242 4242 4242 4242
- Decline: 4000 0000 0000 0002
- Requires Authentication: 4000 0025 0000 3155
Use any future date for expiry and any 3 digits for CVC.
Testing Flow
- Go to
/loginand create a test account - Navigate to
/dashboard - Click "Purchase Credits"
- Select a credit pack and quantity
- Click "Continue to Payment"
- You'll be redirected to Stripe Checkout
- Use a test card to complete payment
- You'll be redirected back to
/successor/cancel
Current Implementation
Client-Side Only
The current implementation uses Stripe's client-side checkout, which is suitable for:
- Simple payment flows
- Fixed-price products
- Public pricing
Limitations
- No server-side validation
- Credits are managed in localStorage (not secure for production)
- No webhook handling for payment confirmation
- No customer management
Production Recommendations
For production use, you should:
-
Add Backend API
- Create checkout sessions server-side
- Validate payments with webhooks
- Store credits in a database
- Manage customer records
-
Security Improvements
- Never expose secret keys
- Validate all payments server-side
- Use webhooks to confirm payments
- Implement proper authentication
-
Enhanced Features
- Customer portal for managing subscriptions
- Invoice generation
- Email receipts
- Refund handling
File Structure
src/
├── lib/
│ └── stripe.ts # Stripe configuration and helpers
├── pages/
│ ├── PurchaseCredits.tsx # Credit purchase page
│ ├── PaymentSuccess.tsx # Success redirect page
│ ├── PaymentCancel.tsx # Cancel redirect page
│ └── Payment.tsx # General payment page
└── App.tsx # Routes configuration
Troubleshooting
"Stripe not loaded" error
- Check that your publishable key is correct
- Ensure you're using the correct environment (test/live)
Payment fails
- Check the browser console for errors
- Verify price IDs are correct
- Ensure products are active in Stripe Dashboard
Success page shows error
- This demo uses localStorage, so make sure it's not blocked
- In production, implement proper backend validation
Next Steps
- Set up a backend server (Node.js, Python, etc.)
- Implement Stripe webhooks
- Create a database for user and credit management
- Add customer portal integration
- Implement subscription management for agency services