Payment Gateway Icon-Implementing PayUMoney Payment Gateway Integration in CodeIgniter for Indian Market

Implementing PayUMoney Payment Gateway Integration in CodeIgniter for Indian Market

To integrate the PayUMoney payment gateway in a CodeIgniter application for the Indian market, you will need to follow several steps. These steps include setting up your PayUMoney account, obtaining the necessary credentials, and implementing the payment process in your CodeIgniter application.

Here’s a step-by-step guide to help you integrate PayUMoney:

### Step 1: Set Up PayUMoney Account

1. Sign up for a PayUMoney merchant account at [PayUMoney](https://www.payumoney.com/).

2. Once your account is approved, you will receive your merchant key and salt. Keep these credentials secure as you will need them for the integration.

### Step 2: Install the PayUMoney Library

You can use an existing PHP library for PayUMoney integration or write your own. If you’re using a library, you can integrate it into your CodeIgniter application by placing it in the `application/libraries` folder.

For this example, let’s assume you’re writing your own simple library. Create a new file `PayUMoney.php` in `application/libraries`.

“`php

key = isset($config[‘key’]) ? $config[‘key’] : ”;

$this->salt = isset($config[‘salt’]) ? $config[‘salt’] : ”;

$this->url = ‘https://secure.payu.in/_payment’;

}

public function getChecksum($params) {

// Implement checksum calculation here

// You can use the PayUmoney PHP library or write your own checksum calculation logic

}

public function initiatePayment($params) {

// Prepare and send payment request to PayUMoney

}

// Other helper methods

}

“`

### Step 3: Load the Library in Your Controller

In your controller, load the PayUMoney library.

“`php

$this->load->library(‘PayUMoney’, array(‘key’ => ‘YOUR_MERCHANT_KEY’, ‘salt’ => ‘YOUR_MERCHANT_SALT’));

“`

### Step 4: Create a Payment Method

Create a method in your controller to handle the payment process.

“`php

public function pay() {

$payment_data = array(

‘amount’ => 1000, // Amount in INR

‘product_info’ => ‘Product Description’,

‘txnid’ => substr(hash(‘sha256’, mt_rand() . microtime()), 0, 20),

// Other necessary parameters

);

$checksum = $this->payumoney->getChecksum($payment_data);

$payment_data[‘checksum’] = $checksum;

// Redirect to PayUMoney payment page

redirect($this->payumoney->url . ‘?’ . http_build_query($payment_data));

}

“`

### Step 5: Handle the Response

After the payment is processed, PayUMoney will send a response back to a specified URL (the callback URL). You need to handle this response in your application.

Create a method in your controller to handle the response.

“`php

public function paymentResponse() {

if ($this->input->post(‘status’) == ‘success’) {

// Payment was successful

// Update your database and perform other actions as needed

} else {

// Payment failed

// Handle failure case

}

}

“`

### Step 6: Set Up the Callback URL

In your PayUMoney account, set the callback URL to the URL where your `paymentResponse` method is located, e.g., `https://yourdomain.com/index.php/your_controller/paymentResponse`.

### Step 7: Test the Integration

Test the payment flow by initiating a payment from your application. Make sure to test both success and failure scenarios.

Remember that this is a simplified example. In a production environment, you should handle security concerns, validate inputs, and ensure that your checksum calculation is accurate. Always refer to the [PayUMoney documentation](https://www.payumoney.com/techsupport/integration) for the most up-to-date and detailed integration steps.