# 420Deals.ch A premium collective buying platform for CBD in Switzerland. ## Setup ### Database 1. Create the database using the provided SQL file: ```bash mysql -u root -p < cbd420.sql ``` 2. Run the migration to add image support (optional but recommended): ```bash mysql -u root -p cbd420 < migrations/add_image_url.sql ``` 3. Create a `.env.local` file in the root directory: ```env DB_HOST=localhost DB_PORT=3306 DB_USER=root DB_PASSWORD=your_password DB_NAME=cbd420 # NOWPayments Configuration # For testnet/sandbox testing: NOWPAYMENTS_TESTNET=true NOWPAYMENTS_SANDBOX_API_KEY=your_sandbox_api_key_here NOWPAYMENTS_CURRENCY=usd # Sandbox doesn't support CHF, use USD or other supported currency # For production: # NOWPAYMENTS_TESTNET=false # NOWPAYMENTS_API_KEY=your_production_api_key_here # NOWPAYMENTS_CURRENCY=chf # Default is CHF for production # IPN Callback URL (your external Node.js service that handles IPN callbacks) IPN_CALLBACK_URL=http://your-ipn-service.com/api/payments/ipn-callback # Payment Currency (crypto currency for payments, e.g. btc, eth, usdt) # Default: btc NOWPAYMENTS_PAY_CURRENCY=btc # Use Fixed Rate (optional, true/false) # If true, exchange rate is frozen for 20 minutes. Payment expires if not paid within 20 minutes. # Default: false NOWPAYMENTS_FIXED_RATE=false # Base URL (use your domain in production) NEXT_PUBLIC_BASE_URL=http://localhost:3420 ``` ### Installation ```bash npm install ``` ### Development ```bash npm run dev ``` Visit [http://localhost:3000](http://localhost:3000) for the main site and [http://localhost:3000/admin](http://localhost:3000/admin) for the admin panel. ## Admin Panel Access the admin panel at `/admin` to: - Create new drops - View all drops - Monitor drop progress and sold out status ### Creating a Drop 1. Navigate to `/admin` 2. Fill in the form: - **Product Name**: e.g., "Harlequin – Collective Drop" - **Batch Size**: Total amount (e.g., 1000) - **Unit**: Custom unit (e.g., g, kg, ml, etc.) - **Price Per Gram**: Price in CHF (e.g., 2.50) - **Product Image**: Optional product image upload (JPEG, PNG, WebP, max 5MB) 3. Click "Create Drop" ## Payment Integration (NOWPayments) ### Testnet/Sandbox Setup 1. **Create a Sandbox Account**: Register at [https://sandbox.nowpayments.io/](https://sandbox.nowpayments.io/) 2. **Generate Sandbox API Key**: - Log in to your sandbox dashboard - Navigate to **Settings** > **Payments** > **API keys** - Generate a test API key 3. **Configure Environment Variables**: ```env NOWPAYMENTS_TESTNET=true NOWPAYMENTS_SANDBOX_API_KEY=your_sandbox_api_key_here ``` 4. **Run Pending Orders Migration**: ```bash mysql -u root -p cbd420 < migrations/create_pending_orders.sql ``` 5. **Test Payments**: - Create test payments through the application - Payments will use the sandbox environment - No real money will be charged ### Production Setup 1. **Get Production API Key** from [NOWPayments Dashboard](https://nowpayments.io/) 2. **Update Environment Variables**: ```env NOWPAYMENTS_TESTNET=false NOWPAYMENTS_API_KEY=your_production_api_key_here NEXT_PUBLIC_BASE_URL=https://yourdomain.com ``` ## Project Structure - `app/` - Next.js app directory - `api/drops/` - API routes for drop management - `api/payments/` - Payment integration endpoints - `admin/` - Admin panel page - `components/` - React components - `lib/db.ts` - Database connection pool - `lib/nowpayments.ts` - NOWPayments API configuration - `cbd420.sql` - Database schema - `migrations/` - Database migration files