Path : /home/vishqocm/pcib.in/
File Upload :
Current File : /home/vishqocm//pcib.in/RAZORPAY_SETUP.md

# Razorpay Integration Setup

This document explains how to set up the Razorpay payment gateway integration for the Institute Management System.

## Prerequisites

- PHP 7.4 or higher
- Composer installed
- Razorpay account with API keys

## Installation Steps

1. **Install Dependencies**

   Run the following command in the project root directory:

   ```bash
   composer install
   ```

   This will install the Razorpay PHP SDK and other dependencies.

2. **Database Setup**

   Execute the following SQL query to create the payment_orders table:

   ```sql
   -- Create payment_orders table for Razorpay integration
   CREATE TABLE IF NOT EXISTS `payment_orders` (
     `id` int(11) NOT NULL AUTO_INCREMENT,
     `user_id` int(11) NOT NULL,
     `course_id` int(11) NOT NULL,
     `amount` decimal(10,2) NOT NULL,
     `currency` varchar(5) NOT NULL DEFAULT 'INR',
     `receipt` varchar(255) NOT NULL,
     `razorpay_order_id` varchar(255) DEFAULT NULL,
     `payment_for` varchar(255) DEFAULT NULL,
     `status` enum('created','paid','failed','refunded') NOT NULL DEFAULT 'created',
     `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
     `updated_at` timestamp NULL DEFAULT NULL,
     PRIMARY KEY (`id`),
     KEY `user_id` (`user_id`),
     KEY `course_id` (`course_id`),
     KEY `razorpay_order_id` (`razorpay_order_id`)
   ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

   -- Add foreign key constraints if needed
   ALTER TABLE `payment_orders`
     ADD CONSTRAINT `payment_orders_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
     ADD CONSTRAINT `payment_orders_course_id_fk` FOREIGN KEY (`course_id`) REFERENCES `courses` (`id`) ON DELETE CASCADE;
   ```

   You can run this SQL directly in your database administration tool (e.g., phpMyAdmin) or save it as `create_payment_orders_table.sql` and import.

3. **Configuration**

   Configure Razorpay API keys in the admin panel:

   - Log in as admin
   - Go to Settings > Payment Settings
   - Enter your Razorpay Key ID and Key Secret
   - Save the settings

   The system will store these keys in the `site_settings` table.

## Razorpay Account Setup

1. **Create a Razorpay Account**

   Sign up at [Razorpay.com](https://razorpay.com) if you haven't already.

2. **Get API Keys**

   - Log in to your Razorpay Dashboard
   - Go to Settings > API Keys
   - Generate Test/Live API keys
   - Copy the Key ID and Key Secret

3. **Configure Webhook (optional)**

   - Go to Settings > Webhooks
   - Set the URL to: `https://your-domain.com/payment_webhook.php`
   - Select events: payment.authorized, payment.failed, payment.captured, etc.
   - Set a secret for webhook authentication

## Testing

1. **Test Mode**

   Use Razorpay test mode for testing payments:
   - In test mode, you can use test cards from Razorpay documentation
   - No actual money is charged

2. **Test Cards**

   You can use these test cards for testing payments:
   - Card Number: 4111 1111 1111 1111
   - Expiry: Any future date
   - CVV: Any 3-digit number

## Going Live

1. **Switch to Live Mode**

   - Replace test API keys with live API keys
   - Update webhook URL with production domain

2. **Verify Account**

   Make sure your Razorpay account is fully verified for live transactions.

## Files Added/Modified

- `student/payment_process.php` - Handles Razorpay payment initialization
- `student/payment_callback.php` - Processes payment callback from Razorpay
- `student/ajax/get_course_payment_details.php` - AJAX endpoint for payment details
- `create_payment_orders_table.sql` - SQL file to create the payment_orders table
- `composer.json` - Dependency configuration with Razorpay SDK