# iPay Payment Gateway - Admin Routes

## Admin Panel URLs

Access these URLs from your admin panel to manage the payment gateway:

### 1. Membership Plans Management
**URL:** `https://your-domain.com/admin/ipay-plans`

**Features:**
- View all pricing plans
- Add new plans
- Edit existing plans (name, price, duration, features)
- Delete plans (with safety checks for active subscriptions)
- See subscriber counts for each plan

**Actions Available:**
- Create plans with custom pricing
- Set plan duration (30 days for monthly, 365 for yearly, etc.)
- Configure max scans (10, 50, 100, 500, or unlimited)
- Enable/disable PDF downloads
- Enable/disable comparison tool access
- Activate/deactivate plans

---

### 2. Payment Settings
**URL:** `https://your-domain.com/admin/ipay-settings`

**Features:**
- Configure iPay API credentials
- Set Merchant/Vendor ID
- Set Secret Key (Hash Key)
- Configure API endpoint (Live or Demo)
- Set callback URL (IPN URL)
- Enable/disable test mode
- Enable/disable auto-activation of memberships

**Important Settings:**
- **Test Mode:** Use iPay demo credentials for testing
- **Auto-Activate:** Automatically activate memberships when payment is confirmed (recommended)

**Demo Credentials (for testing):**
- Vendor ID: `demo`
- Hash Key: `demoCHANGED`
- API Endpoint: `https://demo.ipayafrica.com/v3/ke`

---

### 3. Payment Transactions
**URL:** `https://your-domain.com/admin/ipay-transactions`

**Features:**
- View all payment transactions
- Filter by status (Completed, Pending, Failed)
- Search by transaction ID, iPay reference, or email
- View transaction details (customer, plan, amount, payment method)
- See transaction statistics dashboard
- Track total revenue

**Statistics Dashboard:**
- Total transactions
- Completed transactions
- Pending transactions
- Total revenue (KES)

**Transaction Details:**
- Transaction ID and iPay reference
- Customer information
- Plan purchased
- Payment amount and method
- Payment status
- iPay response data

---

## Frontend Routes

These routes are accessible to customers:

- **Pricing Page:** `https://your-domain.com/pricing`
- **Checkout:** `https://your-domain.com/checkout` (redirects to iPay)
- **Payment Success:** `https://your-domain.com/payment/success`
- **Payment Failed:** `https://your-domain.com/payment/failed`
- **Payment Callback:** `https://your-domain.com/payment/callback` (IPN from iPay)

---

## Quick Start Guide

### Step 1: Configure Payment Settings
1. Go to `https://your-domain.com/admin/ipay-settings`
2. Enter your iPay credentials (or use demo credentials for testing)
3. Enable test mode if testing
4. Save settings

### Step 2: Configure Pricing Plans
1. Go to `https://your-domain.com/admin/ipay-plans`
2. Review the default plans (Basic Monthly, Professional Monthly, Professional Yearly)
3. Edit plans as needed or create new ones
4. Make sure at least one plan is active

### Step 3: Test the Payment Flow
1. Visit `https://your-domain.com/pricing`
2. Select a plan and click "Get Started"
3. Fill in the checkout form
4. Use test phone number: `0722000000` (M-Pesa Success)
5. Complete the payment on iPay demo page
6. Verify transaction appears in admin panel

### Step 4: Go Live
1. Get live credentials from iPay Africa Dashboard
2. Update settings in admin panel with live credentials
3. Disable test mode
4. Set callback URL in iPay dashboard: `https://your-domain.com/payment/callback`
5. Enable IPN notifications in iPay dashboard

---

## Troubleshooting

### Pricing Page Returns 404
**Solution:** Make sure custom routes are added to `core/routes/custom_router.php`. The installer should have added these automatically, but if not, they need to be added manually.

### Payments Not Activating Automatically
**Solution:**
1. Check that auto-activate is enabled in payment settings
2. Verify callback URL is correct in iPay dashboard
3. Check transactions table for iPay response data

### Admin Routes Not Working
**Solution:** The admin routes should work automatically since the controllers are in the `admin/controllers/` folder. Make sure:
- Files exist: `ipay-plans.php`, `ipay-settings.php`, `ipay-transactions.php`
- You're logged into the admin panel
- Plugin system is enabled (PLUG_SYS = true)

---

## Security Notes

- Never share your iPay Secret Key (Hash Key)
- Always use HTTPS in production
- Keep test mode disabled in production
- Regularly review transaction logs
- Back up the database regularly

---

## Support

For issues or questions:
1. Check the main README.md in the plugin folder
2. Review the INSTALLATION_GUIDE.md
3. Check transaction logs in the admin panel
4. Review iPay Africa documentation at https://ipayafrica.com