Razorpay Payment Gateway Integration in PHP
Razorpay is the most user friendly payment gateway that’s provides payment solutions in India . It’s a new entry in payment gateways and getting popular very fast due to its friction less transactions functionality for web and mobile. Razorpay provides clean, fast, secure payments services with hassle free integration with developer friendly APIs. It allows online business to accept and process payments payments modes like Debit Card, Credit Card, Net Banking, UPI and PrePaid Digital Wallets.
So if you’re looking for tutorial to integrate Razorpay payment gateway in your project using PHP, then you’re here at right place. In this tutorial you will learn how to integrate Razorpay payment gateway using PHP in easy steps with live example.
Step1: Create Razorpay Account
First we need to create account on Razorpay and generate KeyId and Secret Key. We will keep created Razorpay account in test mode to test payment functionality.
Step2: Update Razorpay Config Details
Here in this example, we will use Test App to integrate Razorpay gateway. So we will update config.php with KeyId and Secret Key from Razorpay.
Step3: Create Form with Item Details
In index.php file, we will create HTML of test item with item details and customer details to send to perform payment. Here we have pay.php on action to handle payment.
Example: Razorpay Payment Gateway Integration in PHP
Step4: Handle Item Details for Payment
In pay.php file, we will include config.php and Razorpay API files. We will also start session to store razorpay_order_id into session. We will create order data with payment amount and currency to generate Razorpay order id.
$api = new Api($keyId, $keySecret);
$orderData = [
'receipt' => 3456,
'amount' => $_POST['amount'] * 100,
'currency' => $_POST['currency'],
'payment_capture' => 1
$razorpayOrder = $api->order->create($orderData);
$razorpayOrderId = $razorpayOrder['id'];
$_SESSION['razorpay_order_id'] = $razorpayOrderId;
$displayAmount = $amount = $orderData['amount'];
$data = [
"key" => $keyId,
"amount" => $amount,
"name" => $_POST['item_name'],
"description" => $_POST['item_description'],
"image" => "",
"prefill" => [
"name" => $_POST['cust_name'],
"email" => $_POST['email'],
"contact" => $_POST['contact'],
"notes" => [
"address" => $_POST['address'],
"merchant_order_id" => "12312321",
"theme" => [
"color" => "#F37254"
"order_id" => $razorpayOrderId,
Pay with Razorpay
Contact : email@example.com (OR) firstname.lastname@example.org / +91 87784 09644 (OR) +91 93443 88665