-
Home
-
Blogs
-
How-to-integrate-Razorpay-Payment-Gateway-in-PHP-Payment-Gateway-Tutorial -
How to integrate Razorpay Payment Gateway in PHP - Payment Gateway Tutorial
By Deepak Sharma | May, 30 2020 08:15

Hello Friends today I am talking about how we can integrate Razorpay Payment Gateway in PHP Based website, in simply and easy way with video tutorial.
Believe me, most of the time we are facing problem during integration of any type of payment gate way, but it is not much hard as we think. Today I shall tell you to integrate Razorpay Payment Gateway in PHP websites.
Steps as follow :
- First of all we required razorpay merchant account.
- Login into your marchant account.
- Now to settings -> API keys -> generate test key, now export keys in excel for future requirement.
- Now download Razorpay php kit from github url : https://github.com/razorpay/razorpay-php/releases download razorpay-php.zip from 2.5.0 latest release.
- Now create database and tables to store response from payment gateway (razorpay db name) create it as per your requirement.
- Now create table payment_laser and add fields as pay_id, payment_id, order_id, signature_hash, created_at.
- Now extract download razorpay-php.zip kit into your wamp->www/xamp->htdocs folder and extract all files.
- Now create database config connection with your website.
-
$conn = mysqli_connect("localhost","root","","razorpay");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}
?>
-
Now goto project root folder ans create new file called demo.php.
-
and write/past code below :
-
How to integrate Razorpay Payment Gateway in PHP | Payment Gateway Tutorial
.booking-div {
padding: 15px;
box-shadow: inset 0 0 0 1px #e0e5e9;
border: 5px solid #fbfbfc;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
margin-bottom: 30px;
background-color: #fff;
width: 350px;
margin: 0% 10%;
}
.b-fields .b-f-div label {
background: #dbdbdb;
font-size: 12px;
margin-top: 0;
position: absolute;
padding: 10px;
border-radius: 5px 0 0 5px;
color: #787878;
width: 60px;
text-align: center;
}
input{
width: 100%;
height: 35px;
border-radius: 4px;
border: 1px solid #528ff0;
padding-left: 5px;
}
How to integrate Razorpay Payment Gateway in PHP
Payment Gateway Tutorial
-
Now again to route folder and create file called pay.php;
-
And Write or paste code as below :
-
require_once 'configDB.php';
require_once 'razorpay-php/Razorpay.php';
use Razorpay\Api\Api;
$keyId = 'XXXXXXXXXXXXX';
$secretKey = 'XXXXXXXXXXXXXXX';
$api = new Api($keyId, $secretKey);
$CUSTOMER_NAME = $_POST['CUSTOMER_NAME'];
$CUSTOMER_EMAIL = $_POST['CUSTOMER_EMAIL'];
$CUSTOMER_MOBILE = $_POST['CUSTOMER_MOBILE'];
$PAY_AMT = $_POST['PAY_AMT'];
/*
* To create order to RazorPay
*/
$order = $api->order->create(array(
'receipt' => rand(1000, 9999) . 'ORD',
'amount' => $PAY_AMT,
'payment_capture' => 1,
'currency' => 'INR',
)
);
?>
-
Wait replace your keys : with your razorpay merchant api key: we download them in STEP : 3
-
$keyId = 'XXXXXXXXXXXXX';
$secretKey = 'XXXXXXXXXXXXXXX';
-
Now again goto project root folder and create file called success.php;
-
And Write/Paste code as below :
-
require_once 'configDB.php';
echo ''; print_r($_POST);
$sql = "INSERT INTO payment_laser (payment_id, order_id, signature_hash)
VALUES ('".$_POST['razorpay_payment_id']."', '".$_POST['razorpay_order_id']."', '".$_POST['razorpay_signature']."')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "
" . $conn->error;
}
$conn->close();
die; ?>
-
Now goto browser and open your project.
-
Now fill all fields and click on pay button. Then make dummy payment with razorpay and make is success using netbanking option. then you redirect to success.php and check out into your datbase table or new payment transaction log
-
Thanks you read this article. For demo tutorial check out video on this link
How to integrate Razorpay Payment Gateway Video Tutorial
0 comments