Integrating PhonePe as a payment gateway in CodeIgniter 3 involves following steps
Integrating PhonePe as a payment gateway in CodeIgniter 3 involves following similar steps as for Instamojo. Here's a guide on how to do it:
Step 1: Install CodeIgniter 3
If you haven't already installed CodeIgniter 3, you can download it from the official website and set up your project.
Step 2: Get PhonePe API Credentials
To integrate PhonePe, you'll need to sign up as a merchant on PhonePe's Business Console (https://business.phonepe.com/merchant) and get your API credentials, including the merchant ID and API key.
Step 3: Create a Controller
Create a controller in CodeIgniter to handle payment requests and responses. For example, you can create a controller named "Payment" using the following command in your terminal:
```bash
php index.php tools/make_controller Payment
```
Step 4: Configure Payment Gateway Settings
In your CodeIgniter project, open the `config.php` file located in `application/config` and set the `base_url` to your project's URL.
Step 5: Create Payment Form
Create a view file where users can fill in payment details and submit the payment request. For example, create a view file named `payment_form.php` in your `application/views` folder.
```php
<!-- application/views/payment_form.php -->
<form method="post" action="<?= base_url('payment/process_payment') ?>">
<input type="text" name="amount" placeholder="Amount">
<input type="text" name="name" placeholder="Name">
<input type="email" name="email" placeholder="Email">
<button type="submit">Pay Now</button>
</form>
```
Step 6: Process Payment Request
In the `Payment` controller, process the payment request and redirect the user to the PhonePe payment page.
```php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Payment extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->helper('url');
}
public function index() {
$this->load->view('payment_form');
}
public function process_payment() {
$merchant_id = 'YOUR_PHONEPE_MERCHANT_ID';
$api_key = 'YOUR_PHONEPE_API_KEY';
$amount = $this->input->post('amount');
$name = $this->input->post('name');
$email = $this->input->post('email');
// Generate payment URL with required parameters
$payment_url = "https://mercury.phonepe.com/payments/pay/" . $merchant_id . "/" . $amount . "/" . $name . "/" . $email . "?redirect_url=" . base_url('payment/payment_success');
redirect($payment_url);
}
public function payment_success() {
// Handle successful payment here
echo 'Payment Successful';
}
}
```
Remember to replace `'YOUR_PHONEPE_MERCHANT_ID'` and `'YOUR_PHONEPE_API_KEY'` with your actual PhonePe API credentials obtained from your PhonePe Business Console.
Step 7: Handling Payment Response
Create a method in the `Payment` controller to handle successful payment responses. After successful payment, the user will be redirected back to the `payment_success` method, where you can handle the payment completion.
Conclusion
Integrating PhonePe as a payment gateway in CodeIgniter 3 involves setting up a controller to handle payment requests and responses, and creating a payment form where users can enter their payment details. Upon form submission, users will be redirected to the PhonePe payment page for secure payment processing. After successful payment, users will be redirected back to your website, and you can handle the payment completion in the `payment_success` method.
Please note that the integration steps provided above are based on general principles, and the actual implementation may vary based on your specific requirements and the latest updates from PhonePe's API. Always refer to PhonePe's official documentation for the most up-to-date information and guidelines.