1. First, you need to create an account with Mobikwik and get your API credentials (Merchant ID and Secret Key).
2. Create a new controller file in your CodeIgniter application and name it Payment.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()
{
$data = array(
'merchant_id' => 'YOUR_MERCHANT_ID',
'order_id' => 'ORDER_'.time(),
'amount' => '100',
'return_url' => site_url('payment/success'),
'callback_url' => site_url('payment/failure'),
);
$this->load->view('payment', $data);
}
public function success()
{
echo 'Payment Success';
}
public function failure()
{
echo 'Payment Failure';
}
}
Create a new view file in your CodeIgniter application and name it payment.php
<form method="post" action="https://www.mobikwik.com/checkout">
<input type="hidden" name="mid" value="<?= $merchant_id ?>">
<input type="hidden" name="orderid" value="<?= $order_id ?>">
<input type="hidden" name="amount" value="<?= $amount ?>">
<input type="hidden" name="returnUrl" value="<?= $return_url ?>">
<input type="hidden" name="callbackUrl" value="<?= $callback_url ?>">
<input type="submit" value="Pay with Mobikwik">
</form>
Update your routes.php file to point to the Payment controller.
$route['payment'] = 'payment';
$route['payment/success'] = 'payment/success';
$route['payment/failure'] = 'payment/failure';
Finally, run your CodeIgniter application and visit the payment page by navigating to http://your-site.com/payment.
Implement security measures like verifying the payment response from Mobikwik and validating the data to ensure that the payment is secure. You can add this code in the success() function in the Payment controller.
public function success()
{
$order_id = $_POST['orderid'];
$txnid = $_POST['txnid'];
$amount = $_POST['amount'];
$status = $_POST['status'];
// Check if the payment response is authentic
$secret_key = 'YOUR_SECRET_KEY';
$hash_string = $secret_key.'|'.$order_id.'|'.$txnid.'|'.$amount.'|'.$status;
$hash = hash('sha512', $hash_string);
$received_hash = $_POST['hash'];
if ($hash != $received_hash)
{
// Payment response is not authentic
echo 'Payment Failure';
}
else
{
// Payment response is authentic
// Validate the data and mark the order as paid in your database
echo 'Payment Success';
}
}
My name is Deepak tailor as a fullstack developer. I have been in the IT industry (PHP, Nodejs, flutter) for the last 5 years. For professional and customize web development & app development, you can send inquiry on our email.
----
You can contact him at deepaktailor10@yahoo.in