API ReferenceIntegrationsKnowledge Base

Quick Integration

Razorpay helps you quickly start accepting payments from your customers. Follow these simple steps to complete the integration with our Standard Automatic Checkout:

Prerequisites#

Steps to follow:

  1. Paste Standard Checkout script in your website
  2. Create an Order in your backend
  3. Store fields in Database
  4. Pass Order ID to Checkout
  5. Verify the Signature
  6. Make a Test Payment
  7. Switch to Live Mode

1. Paste Standard Checkout script in your website#

The Standard Automatic Checkout method provides a default Razorpay Pay with Razorpay button that invokes the Checkout form. The checkout form options are passed as data attributes inside a <script> tag. You can add any additional, hidden or visible fields to the form, which will be submitted along with the form.

The following sample code will pass the Razorpay Checkout options as HTML data attributes:

Copy<form action="https://www.example.com/payment/success/" method="POST"> <script src="https://checkout.razorpay.com/v1/checkout.js" data-key="YOUR_KEY_ID" // Enter the Test API Key ID generated from DashboardSettingsAPI Keys data-amount="29935" // Amount is in currency subunits. Default currency is INR. Hence, 29935 refers to 29935 paise or INR 299.35. data-currency="INR"//You can accept international payments by changing the currency code. Contact our Support Team to enable International for your account data-order_id="order_CgmcjRh9ti2lP7"//Replace with the order_id generated by you in the backend. data-buttontext="Pay with Razorpay" data-name="Acme Corp" data-description="A Wild Sheep Chase is the third novel by Japanese author Haruki Murakami" data-image="https://example.com/your_logo.jpg" data-prefill.name="Gaurav Kumar" data-prefill.email="gaurav.kumar@example.com" data-theme.color="#F37254" ></script> <input type="hidden" custom="Hidden Element" name="hidden"> </form>

When the checkout process is completed, the browser will add an additional field <name=id> to the form that contains the script tag. This form is then automatically submitted. Once the payment is successfully authorized, razorpay_payment_id is submitted along with the form to the action url.

Note:
Replace the URL mentioned in the below code with your website's success callback URL.

<form action="https://www.example.com/payment/success/" method="POST">

In case of a failure, Razorpay offers the customer the retry option.

2. Create an Order in your backend#

The second step is to create an Order in the backend using the Orders API. The following is a sample API request and response for creating an order:

Copycurl -u <YOUR_TEST_KEY> \ https://api.razorpay.com/v1/orders -X POST \ --data "amount=50000" \ --data "currency=INR" \ --data "receipt=rcptid #1" \ --data "payment_capture=0" https://api.razorpay.com/v1/orders
Copytry { JSONObject orderRequest = new JSONObject(); orderRequest.put("amount", 50000); // amount in the smallest currency unit orderRequest.put("currency", "INR"); orderRequest.put("receipt", "order_rcptid_11"); orderRequest.put("payment_capture", false); Order order = razorpay.Orders.create(orderRequest); } catch (RazorpayException e) { // Handle Exception System.out.println(e.getMessage()); }
Copyorder_amount = 50000 order_currency = 'INR' order_receipt = 'order_rcptid_11' notes = {'Shipping address': 'Bommanahalli, Bangalore'} # OPTIONAL client.order.create(amount=order_amount, currency=order_currency, receipt=order_receipt, notes=notes, payment_capture='0')
Copy$order = $client->order->create([ 'receipt' => 'order_rcptid_11', 'amount' => 50000, // amount in the smallest currency unit 'currency' => 'INR',// <a href="https://razorpay.freshdesk.com/support/solutions/articles/11000065530-what-currencies-does-razorpay-support" target="_blank">See the list of supported currencies</a>.) 'payment_capture' => '0' ]);
CopyDictionary<string, object> options = new Dictionary<string,object>(); options.Add("amount", 50000); // amount in the smallest currency unit options.add("receipt", "order_rcptid_11"); options.add("currency", "INR"); options.add("payment_capture", "0"); Order order = client.Order.Create(options);
Copyoptions = amount: 50000, currency: 'INR', receipt: '<order_rcptid_11>', payment_capture: '0' order = Razorpay::Order.create
Copyvar options = { amount: 50000, // amount in the smallest currency unit currency: "INR", receipt: "order_rcptid_11",// payment_capture: '0' }; instance.orders.create(options, function(err, order) { console.log(order); });
Copy{ "id": "order_4xbQrmEoA5WJ0G", "entity": "order", "amount": 50000, "currency": "INR", "receipt": "order_rcptid_11", "status": "created", "attempts": 0, "created_at": 1455696638, "notes": {} }

A successful creation of the Order returns the order_id that you need to store against the Order defined in your system.

3. Store the fields in Database#

Store the following objects from Razorpay in your database:

razorpay_order_id
string Order ID returned by Razorpay Orders API.
Returned once the payment is completed by the customer.
razorpay_payment_id
string Returned by Razorpay API only for successful payments.
razorpay_signature
string A hexadecimal string used for verifying the payment.

Note: In your system, let us say, unique identifier for an Order is transaction_id or checkout_id. This is not the order_id returned by Razorpay.

4. Pass Order ID to Checkout#

The razorpay_order_id, returned by Razorpay on a successful creation of the order should be sent to the Checkout form. Additionally, you need to send an extra key-value pair as shown:

Copy{ "data-amount": "29935", // and other options "data-order_id": "<order_id>" // Order ID returned by Razorpay }

A successful payment for the Order returns razorpay_order_id, payment_id and razorpay_signature, which is then used for payment verification.

5. Verify the Signature#

Signature verification is a mandatory step that ensures all your authorized payments are successfully verified. You can carry out payment verification using the signature verification step that allows you to decide if a payment should be successful or not. The razorpay_signatureis returned to you by the Checkout form on a successful payment. This signature needs to be verified in your backend server.

To verify payments, you need to generate a verification signature with SHA256 algorithm and verify it against the razorpay_signature, returned in the Checkout form.

Generate a Signature#

The razorpay_signature is returned to you by the Checkout form on successful payment. This signature needs to be verified in your server.

  1. Create a signature in your server using the following attributes:

    • razorpay_payment_id - Returned by Checkout
    • razorpay_order_id - Returned by Checkout
    • key_secret - Available in your server
  2. Using the SHA256 algorithm and razorpay_payment_idandrazorpay_order_id, construct a HMAC hex digest as shown below:

Copygenerated_signature = hmac_sha256(razorpay_order_id + "|" + razorpay_payment_id, secret); if (generated_signature == razorpay_signature) { payment is successful }

Post Signature Verification Steps#

After verifying the signature, fetch the order in your system that corresponds torazorpay_order_id in your database. You can now mark this fetched order as successful and process the order.

Note:
A successful creation of an Order returns razorpay_order_id, which should be stored against the order created in your system. After validating the signature, you have to fetch the order in your system corresponding to the razorpay_order_id and mark this order successful.

Make a Test Payment#

  1. Go to your website and start a transaction with click the Pay With Razorpay button.
  2. Make the payment. Since this is a test payment, no money is actually deducted from your bank account or cards.
  3. The transaction is reflected in Dashboard → Transactions → Payments in captured state. This means that the transaction was successful.

Switch to Live Mode#

Once you have successfully integrated and tested it out, you can switch to the live mode. You can do this by replacing the Test API Key with the Live Key. You can generate the Live Key from the Dashboard.

Use the APIs#

Once the integration is complete, the next thing to do is to use APIs for:

  • Payments

    • Retrieve information regarding automatically captured Payments
    • Capture Payments manually
  • Settlements

    • Retrieve information regarding Settlements
  • Refunds

    • Initiate Refunds
    • Retrieve information regarding Refunds

Other Integration Methods#

Looking to integrate Razorpay with your mobile app or at a server-level? Here are the other integration methods available:

Integration Type

Integration Methods

Web Integration

Standard Checkout Integration

Custom Checkout Integration

Mobile Integration

Android Standard Checkout Integration

Android Custom Checkout Integration

iOS Standard Checkout Integration

iOS Custom Checkout Integration

Cordova SDK Integration

React Native SDK Integration

Flutter SDK Integration

Ecommerce Plugins

Arastta Integration

CS-Cart Integration

Easy Digital Download Integration

Magento Integration

OpenCart Integration

PrestaShop Integration

Shopify Integration

WHMCS Integration

Wix Integration

WooCommerce Integration

WordPress Integration

Server Integrations (Languages)

PHP Integration

Ruby Integration

Python Integration

NodeJS Integration

.NET Integration

Java Integration