Integrating Payment Gateways with CodeIgniter 4: A Complete Guide for Indian E‑Commerce Businesses
Indian e‑commerce is growing rapidly, and offering a smooth, secure checkout experience is essential for converting visitors into customers. If you are building your store with CodeIgniter 4, integrating popular Indian payment gateways such as Razorpay, Paytm, and Cashfree can be done efficiently while keeping security and SEO best practices in mind.
Why Choose CodeIgniter 4 for Payment Integration?
- Lightweight MVC framework with excellent performance.
- Built‑in HTTP client and request/response handling simplifies API calls.
- Easy routing and controller structure for creating webhook endpoints.
- Strong community support and extensive documentation.
Before diving into the code, ensure you have the following prerequisites:
- PHP 7.4+ and Composer installed.
- A fresh CodeIgniter 4 project (via
composer create-project codeigniter4/appstarter). - API keys for Razorpay, Paytm, and Cashfree (sandbox credentials for testing).
- SSL certificate on your domain (required for live transactions).
1. Setting Up Razorpay in CodeIgniter 4
Install Razorpay SDK
composer require razorpay/razorpay
Create a Controller
<?php
namespace App\Controllers;
use Razorpay\Api\Api;
class Payment extends BaseController
{
public function razorpayCheckout()
{
$api = new Api('YOUR_RAZORPAY_KEY_ID', 'YOUR_RAZORPAY_KEY_SECRET');
$orderData = [
'receipt' => 'receipt_' . uniqid(),
'amount' => 50000, // amount in paise (₹500)
'currency' => 'INR',
'payment_capture' => 1 // auto capture
];
$razorpayOrder = $api->order->create($orderData);
$data = [
'orderId' => $razorpayOrder['id'],
'amount' => $orderData['amount'],
'currency' => $orderData['currency'],
'keyId' => 'YOUR_RAZORPAY_KEY_ID',
'name' => 'Your Store Name',
'description'=> 'Purchase description',
'image' => base_url('assets/logo.png'),
'prefill' => [
'name' => 'Customer Name',
'email' => 'customer@example.com',
'contact'=> '9999999999'
],
'theme' => ['color' => '#F37254']
Join the Conversation
0 Comments