# Webhook Setup Guide for Localhost Development

## For Ghana Cedi (GHS) Payments

### 1. Paystack Account Setup
- Make sure your Paystack account supports Ghana Cedi (GHS)
- If not, contact Paystack support to enable GHS currency

### 2. Localhost Webhook Testing Options

#### Option A: Using ngrok (Recommended)
1. **Install ngrok**: Download from https://ngrok.com/
2. **Start your local server**: Make sure XAMPP is running
3. **Run ngrok**: Open command prompt and run:
   ```
   ngrok http 80
   ```
4. **Copy the HTTPS URL**: You'll get something like `https://abc123.ngrok.io`
5. **Set webhook URL in Paystack**: `https://abc123.ngrok.io/ghs/public/webhook_tunnel.php`

#### Option B: Using localtunnel
1. **Install localtunnel**: `npm install -g localtunnel`
2. **Run localtunnel**: `lt --port 80`
3. **Copy the URL**: You'll get something like `https://abc123.loca.lt`
4. **Set webhook URL in Paystack**: `https://abc123.loca.lt/ghs/public/webhook_tunnel.php`

#### Option C: Using Cloudflare Tunnel
1. **Install cloudflared**: Download from https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/
2. **Run tunnel**: `cloudflared tunnel --url http://localhost:80`
3. **Copy the URL**: You'll get something like `https://abc123.trycloudflare.com`
4. **Set webhook URL in Paystack**: `https://abc123.trycloudflare.com/ghs/public/webhook_tunnel.php`

### 3. Paystack Dashboard Configuration

1. **Log into Paystack Dashboard**
2. **Go to Settings → API Keys & Webhooks**
3. **Add Webhook URL**: Use the tunnel URL + `/ghs/public/webhook_tunnel.php`
4. **Select Events**: Choose `charge.success`
5. **Copy Webhook Secret**: Save this for your config

### 4. Update Configuration

Edit `src/paystack_config.php`:
```php
define('PAYSTACK_PUBLIC_KEY', 'pk_test_your_ghana_public_key');
define('PAYSTACK_SECRET_KEY', 'sk_test_your_ghana_secret_key');
define('PAYSTACK_WEBHOOK_SECRET', 'your_webhook_secret_from_paystack');
```

### 5. Test Payment Flow

1. **Visit**: `http://localhost/ghs/public/pay_for_registration.php`
2. **Enter email**: Use a test email
3. **Click Pay**: You'll be redirected to Paystack
4. **Use test card**: `4084084084084081` (Visa) or `5078507850785078` (Mastercard)
5. **Complete payment**: You'll be redirected back to your app

### 6. Debugging

- **Check webhook logs**: `logs/webhook_log.txt`
- **Check Paystack dashboard**: View transaction details
- **Check database**: Verify payment records in `payments` table

### 7. Production Deployment

When you deploy to production:
1. **Update webhook URL**: Use your actual domain
2. **Switch to live keys**: Replace test keys with live keys
3. **Update currency**: Ensure GHS is enabled for live account

## Important Notes

- **Ghana Cedi**: Make sure your Paystack account supports GHS
- **Amount**: ₵50 = 5000 pesewas (smallest unit)
- **Test Mode**: Always test in test mode first
- **Webhook Security**: Never expose webhook secrets in client-side code
