Razorpay payment gateway php integration


In this tutorial, I will explain to you how we can integrate the Razorpay payment gateway into our PHP Application.

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.

Before we start the integration Razorpay payment gateway in our application you need to have a Razorpay account you can get your account using this link.


  • Razorpay Account
  • PHP v5.3 or higher

you can get your test API key details from setting -> API Keys

Create Payment Form
In index.php file, we will create HTML of test item with item details and customer details.

<form action="process_payment.php" name="payment" method="post" style="width:100%">
  <input type="text" name="user_name" id="user_name" value="">
  <label>Phone Number</label>
  <input type="text" name="user_phone" id="user_phone"  value="">
  <label>Email Address</label>
  <input type="text" name="user_email" id="user_email"  value="">
  <input type="text" name="amount" id="amount"  value="">
  <button  type="submit" name="paysubmit" >Process Order </button>

Sage Pay Payment Gateway Integration using PHP
PayPal Standard Payment Gateway Integration in PHP

Handle Item Details for Payment
In payment.php file, We will create order data with payment amount and currency to generate Razorpay order id.


	$uname  = $_POST['user_name'];
	$uphone = $_POST['user_phone'];
	$uemail = $_POST['user_email'];
	$amount = $_POST['amount'];
	if(!empty($uname) & !empty($uphone) & !empty($uemail) & !empty($amount))
		$keyId = 'rzp_test_hX1saThT40JaFu';  //API key 
		$total_amount = $amount*100;
        <form action="charge_payment.php" method="POST">
        data-key="<?php echo $keyId;?>" 
        data-amount= <?php echo $amount;?>
        data-buttontext="Pay Now"
        data-name="COMPANY NAME"
        data-prefill.name= <?php echo $uname;?>
        data-prefill.email= <?php echo $uemail;?>
        data-prefill.contact= +1<?php echo $uphone;?>
        <input type="hidden" custom="Hidden Element" name="hidden">

You have to create two more PHP files verify.php and cancel.php if the user makes a payment or cancel payment then you need to redirect the user to that page. You can print $_POST variable on that page.

That’s it hope this post help you to implement the Razorpay payment gateway in your PHP web application/website. Once you tested successfully you need to change test mode API keys with live keys.

Please follow and like us:

By Rodney

I’m Rodney D Clary, a web developer. If you want to start a project and do a quick launch,I am available for freelance work.

Leave a Reply

Your email address will not be published. Required fields are marked *