# Backend Server Setup

## Quick Start

1. **Install dependencies:**
   ```bash
   cd js/backend
   npm install
   ```

2. **Configure environment variables:**
   - Edit `web.env` file
   - Make sure `PAYSTACK_SECRET_KEY` and `PAYSTACK_PUBLIC_KEY` are set
   - Set `PORT` (default: 5000)

3. **Start the server:**
   ```bash
   npm start
   ```

   You should see: `Backend listening on port 5000`

4. **Test the server:**
   - Open browser: `http://localhost:5000/_/health`
   - Should return: `{"ok":true}`

## Troubleshooting

### "Failed to fetch" Error

This means the frontend cannot reach the backend server. Check:

1. **Is the backend server running?**
   - Check terminal for: `Backend listening on port 5000`
   - If not, start it with `npm start`

2. **Is the port correct?**
   - Backend runs on port 5000 by default
   - Frontend expects: `http://localhost:5000`
   - If you changed the port, update `js/payment.js`:
     ```javascript
     const backendURL = "http://localhost:YOUR_PORT";
     ```

3. **CORS Issues:**
   - The server has CORS enabled, but if you're hosting on a different domain, you may need to configure CORS origins

4. **Firewall/Network:**
   - Make sure port 5000 is not blocked
   - Check if another service is using port 5000

## Production Deployment

For production, change the backend URL in `js/payment.js`:

```javascript
const backendURL = "https://your-backend-domain.com";
```

Make sure:
- Backend is accessible at that URL
- CORS is configured for your frontend domain
- Environment variables are set on your hosting platform

