API ReferenceIntegrationsKnowledge Base

Integrating with Standard Checkout

Integrate Razorpay Standard Checkout with your website or web app to start accepting online payments from customers. Razorpay supports a slew of payment methods - netbanking, credit and debit cards, wallets and UPI.

Our checkout.js library provides all the essential features for integrating Razorpay Checkout with the client-side of your application. This is available only for web-based integrations.

Here is a screenshot of the checkout form:

Note: If your website is built on top of an Ecommerce Platform, such as WordPress or Shopify, please refer to Razorpay Ecommerce Plugins document.

Supported Payment Methods#

Payment Methods such as netbanking, credit and debit cards, wallets and UPI are available by default on Standard Checkout. You do not have to change anything in your integration to support different payment methods that we provide or add in the future.

The table below lists the various payment methods available to you. Some of them are available by default, while others require approval from us. Raise a request with our Support Team to enable such payment methods.

Payment Method

Availability

Debit Card

Credit Card

Net Banking

UPI

EMI

Bank Transfer

Requires
- Approval and Integration

e-Mandate

Requires
- Approval and Integration

Pay Later

Requires
- Approval

Refer to our Pay Later documentation for more information.

Cardless EMI

Requires
- Approval and Integration

The table below lists the various wallets available to you. Some of them are available by default, while others require approval from us. Raise a request with our Support Team to enable such wallets.

Wallet Provider

Availability

Wallet Code

FreeCharge

freecharge

PayZapp

payzapp

Ola Money

Requires
- Approval

olamoney

PhonePe

Requires
- Approval

phonepe

Airtel Money

Requires
- Approval

airtelmoney

MobiKwik

Requires
- Approval

mobikwik

JioMoney

Requires
- Approval

jiomoney

Amazon Pay

Requires
- Approval and Integration

amazonpay

PayPal

International Payments Only

Requires
- Approval

Refer to our PayPal documentation for more information.

paypal

Two flavours of Standard Checkout. Which one to choose?#

Standard Automatic Checkout
The 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. This is the default method available for integration and is easy to integrate into your own product.


Standard Manual Checkout
In Manual Checkout method, the Checkout form is invoked by the 'custom button' on your site and the form options are passed as variables in a key-value pair format within a <script> tag. Opt for this when you have multiple products, or a complex way to pre-calculate amount for a payment (in javascript). It provides a greater control in the payment process.

Steps#

  1. Create an Order in your server-side

  2. Paste Standard Checkout script in your website

  3. Store fields in Database

  4. Pass Order ID to Checkout

  5. Verify the Signature

Post-integration, you can:

  • Configure the webhook
  • Make a Test payment
  • Replace Test Key with Live Key
  • Integrate with APIs for further actions

Step 1 - Create an Order in your server-side#

Orders API helps to:

  • Prevent multiple payments by binding a single successful payment to an order.
  • Auto capture payments immediately after authorization.

Here is the list of attributes for creating the order:

amount mandatory
integer The transaction amount, expressed in the currency subunit, such as paise (in case of INR). For example, for an actual amount of ₹299.35, the value of this field should be 29935.
currency mandatory
string The currency in which the transaction should be made. See the list of supported currencies. Default is INR.
receipt optional
string Your receipt id for this order should be passed here. Maximum length 40 characters.
payment_capture optional
boolean Set to 1 to automatically capture the payment. Set to 0 to capture payments manually using the API or Dashboard. Learn about capturing payments.
notes optional
JSON object Object consisting of key value pairs as notes.
You can read more about Notes in the API documentation.

Sample Code#

The following is a sample API request and response for creating an order:

Copycurl -X POST https://api.razorpay.com/v1/orders -H 'content-type:application/json' -d '{ "amount": 50000, "currency": "INR", "receipt": "rcptid_11", "payment_capture": 1 }'
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_DBJOWzybf0sJbb", "entity": "order", "amount": 50000, "amount_paid": 0, "amount_due": 50000, "currency": "INR", "receipt": "rcptid_11", "status": "created", "attempts": 0, "notes": [], "created_at": 1566986570 }

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

Step 2 - Paste Standard Checkout script in your website#

Automatic#

If you plan to integrate Razorpay Standard Automatic Checkout, use the code given below. The following sample code will pass the Razorpay Checkout options as HTML data attributes.
Note:
Please create an Order and replace the Order ID in the sample code below. Otherwise, the system will throw an error for invalid order number.

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 Key ID generated from the Dashboard data-amount="50000" // Amount is in currency subunits. Default currency is INR. Hence, 50000 refers to 50000 paise or INR 500. data-currency="INR" data-order_id="order_CgmcjRh9ti2lP7"//This is a sample Order ID. Create an Order using Orders API. (https://razorpay.com/docs/payment-gateway/orders/integration/#step-1-create-an-order) 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-prefill.contact="9999999999" data-theme.color="#F37254" ></script> <input type="hidden" custom="Hidden Element" name="hidden"> </form>

Notes:

  • Replace the URL mentioned in the above 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.

  • An extensive list of checkout form options are available here.


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.

The response body contains additional parameters, razorpay_order_id and razorpay_signature, when you integrate with our Orders API.

Only successful authorizations are auto-submitted. In case of failed payments, checkout form is displayed again to facilitate retry of the payments.


Manual#

If you plan to integrate Razorpay Standard Manual Checkout, use the code given below.

  • Modify the attributes and the handler function to handle the response object. Use the Checkout form table as reference.

The sample code given below will pass the form options for an amount of ₹299.35.

Note:
Please create an Order and replace the Order ID in the sample code below. Otherwise, the system will throw an error for invalid order number.

Copy<button id="rzp-button1">Pay</button> <script src="https://checkout.razorpay.com/v1/checkout.js"></script> <script> var options = {    "key": "YOUR_KEY_ID", // Enter the Key ID generated from the Dashboard    "amount": "50000", // Amount is in currency subunits. Default currency is INR. Hence, 50000 refers to 50000 paise or INR 500.    "currency": "INR", "name": "Acme Corp",    "description": "A Wild Sheep Chase is the third novel by Japanese author Haruki Murakami",    "image": "https://example.com/your_logo", "order_id": "order_9A33XWu170gUtm",//This is a sample Order ID. Create an Order using Orders API. (https://razorpay.com/docs/payment-gateway/orders/integration/#step-1-create-an-order). Refer the Checkout form table given below    "handler": function (response){        alert(response.razorpay_payment_id);    },    "prefill": {        "name": "Gaurav Kumar",        "email": "gaurav.kumar@example.com", "contact": "9999999999"    },    "notes": {        "address": "note value"    },    "theme": {        "color": "#F37254"    } }; var rzp1 = new Razorpay(options); document.getElementById('rzp-button1').onclick = function(e){    rzp1.open();    e.preventDefault(); } </script>

Notes:
The open method of Razorpay object (rzp1.open()) must be invoked by your site's JavaScript, which may or may not be a user-driven action such as a click.
The appearance of the Pay Now with Razorpay or the custom button can be customized by writing css rules for the razorpay_payment_button.

Once the payment is successfully authorized, a handler function is called automatically. This function returns a response object containing razorpay_payment_id. This handler function must be called back to your server-side for capturing the payment. The response body contains additional parameters, razorpay_order_id and razorpay_signature, if you have integrated with our Orders API.

Send the razorpay_payment_id to your server-sided handler url with any other attributes as you may need to capture the transaction. If the capture response has no error_code set, that means the payment is successful.

Switch between Automatic and Manual methods
You may switch from one checkout method to the other. Also, you can track the modal if you are using the Manual method. Learn more here

Step 3 - Store fields in Database#

Make arrangements to store the following objects from Razorpay in your database:

razorpay_order_id
string Order ID returned by Razorpay Orders API.
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.

Step 4 - Pass Order ID to Checkout#

The razorpay_order_id, returned on 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{ "amount": "100", // and other options "order_id": "order_CuEzONfnOI86Ab" // Order ID created in Step 1 }

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

Step 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.

This allows you to decide if a payment should be successful or not. The razorpay_signature is 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 using a 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 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.

The integration is now complete!

Post-Integration Steps#

Setup Webhooks#

Webhooks allow you to build or set up integrations that subscribe to certain events on Razorpay API. When one of those events is triggered, we send an HTTP POST payload in JSON to the webhook's configured URL.

Learn how to setup Webhooks.

Make Test Payments#

Once the integration is complete, you can make a test payment from your application.

Making Test Payments Using Test Cards

Card Network

Domestic / International

Card Number

Mastercard

Domestic

5104 0155 5555 5558
5104 0600 0000 0008

Visa

Domestic

4111 1111 1111 1111

Mastercard

International

5555 5555 5555 4444
5105 1051 0510 5100

Visa

International

4012 8888 8888 1881
4000 1841 8621 8826

You can navigate to DashboardTransactionsPayments to check if the payment has gone through. If no payment_ID has been generated, it means that the transaction has failed.


Replace Test Key with Live Key#

Now that the integration is working, you can switch to the live mode and start accepting payments from customers. But first you need to swap the test API keys with the live keys.

  1. Switch to live mode using the option in the menu ribbon.
  2. Navigate to Settings.
  3. Click API Keys.
  4. Click Generate Key to generate key for live mode.
  5. Replace the test API keys with the Live Keys in the Checkout code.

Integrate with APIs for further actions#

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