Skip to main content
PhonePe enables various businesses to integrate their web apps or mobile sites with the Switch platform and instantly reach out to the PhonePe user base. By integrating Razorpay APIs with PhonePe Switch payment flow, you can accept in-app payments made by your customers without having to worry about handling settlements or reconciliation separately.
Feature RequestThis is an on-demand feature. Please raise a request with our Support team to get this feature activated on your Razorpay account.to get this feature activated on your account.

User Flow

The user’s journey through this entire flow is outlined below:
1

Step 1

Customers log in to the PhonePe app and click PhonePe Switch.
2

Step 2

In the PhonePe Switch, customers select your app, place orders and click Proceed to Pay.
3

Step 3

Customers are redirected to the PhonePe payment page.
4

Step 4

After the successful payment on the PhonePe payment page, customers are redirected to your website.

Prerequisites

Before integrating with the Checkout, run through this checklist:
  • Check if your webapp is integrated with PhonePe Switch.
  • Understand the payment flow.
  • Sign up for a Razorpay Account.
  • Generate the API keys from the Dashboard. Use the test API Keys to test out the integration.
Watch the video to see how to generate API key in Test Mode.
PCI DSS CertificationA customer’s payment information should never reach your servers, unless you are PCI DSS certified.

Integration Steps

Steps to integrate Custom Checkout in your site:
  1. Create an Order from your Server.
  2. Invoke Checkout and Pass Order Id and Other Options to it
  3. Include the JavaScript code in your Webpage.
  4. Instantiate Razorpay Custom Checkout.
  5. Submit Payment Details.
  6. Store Fields in Your Server.
  7. Verify the Signature.

Step 1: Create an Order in your Server

When a customer places an order on your website or application, use the details to create an order on Razorpay. /orders
Request

Request Parameters

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. You can create Orders in INR only. receipt optional : string Your receipt ID for this order can be passed here. Maximum length is 40 characters. phonepe_switch_context optional notes optional : object Key-value pair that can be used to store additional information about the entity. Maximum 15 key-value pairs, 256 characters (maximum) each. For example, "note_key": "Beam me up Scotty”.

Step 2: Invoke Checkout and Pass Order Id and Other Options to it

Step 2.1: Include the JavaScript code in your Webpage

Include the following script, preferably in “ section of your page:
Index HTML
Including the Javascript, not the LibraryInclude the script from https://checkout.razorpay.com/v1/razorpay.js instead of serving a copy from your own server. This allows new updates and bug fixes to the library to get automatically served to your application.We always maintain backward compatibility with our code.

Step 2.2: Instantiate Razorpay Custom Checkout

Single Instance on a Page

Invoke a Single Instance

Multiple Instances on Same Page

If you need multiple razorpay instances on same page, you can globally set some of the options:
Invoke Multiple Instances

Step 2.3: Submit Payment Details

Once the order is created and the customer’s payment details are obtained, the information should be sent to Razorpay to complete the payment. The data that needs to be submitted depends upon the payment method selected by the customer.You can do this by invoking createPayment method:
createPayment with handler Function
ERRORNoteThe createPayment method should be called within an event listener triggered by user action to prevent the popup from being blocked. For example:
Handler Function vs Callback URL
  • Handler Function:
When you use the handler function, the response object of the successful payment (razorpay_payment_id, razorpay_order_id and razorpay_signature) is submitted to the Checkout Form. You need to collect these and send them to your server.
  • Callback URL:
When you use a Callback URL, the response object of the successful payment (razorpay_payment_id, razorpay_order_id and razorpay_signature) is submitted to the Callback URL.

Step 3: Store Fields in Your Server

A successful payment returns the following fields to the Checkout form.

Success Callback

  • You need to store these fields in your server.
  • You can confirm the authenticity of these details by verifying the signature in the next step.
Success Callback
razorpay_payment_id : string Unique identifier for the payment returned by Checkout only for successful payments. razorpay_order_id : string Unique identifier for the order returned by Checkout. razorpay_signature : string Signature returned by the Checkout. This is used to verify the payment.

Step 4: Verify the Signature

This is a mandatory step to confirm the authenticity of the details returned to the Checkout form for successful payments.

To verify the razorpay_signature returned to you by the Checkout form:

  1. Create a signature in your server using the following attributes:
    • order_id: Retrieve the order_id from your server. Do not use the razorpay_order_id returned by Checkout.
    • razorpay_payment_id: Returned by Checkout.
    • key_secret: Available in your server. The key_secret that was generated from the Dashboard.
  2. Use the SHA256 algorithm, the razorpay_payment_id and the order_id to construct a HMAC hex digest as shown below:
    HMAC Hex Digest
  3. If the signature you generate on your server matches the razorpay_signature returned to you by the Checkout form, the payment received is from an authentic source.

Generate Signature on Your Server

Given below is the sample code for payment signature verification:
Java

Post Signature Verification

After you have completed the integration, you can set up webhooks, make test payments, replace the test key with the live key and integrate with other APIs.

Payment Capture Settings

After payment is authorized, you need to capture it to settle the amount to your bank account as per the settlement schedule. Payments that are not captured are auto-refunded after a fixed time.
Watch Out
  • You should deliver the products or services to your customers only after the payment is captured. Razorpay automatically refunds all the uncaptured payments.
  • You can track the payment status using our Fetch a Payment API or webhooks. Authorized payments can be automatically captured. You can auto-capture all payments using global settings on the Razorpay Dashboard. Know more about capture settings for payments.
Watch Out!Payment capture settings work only if you have integrated with Orders API on your server side. Know more about the Orders API.Each authorized payment can also be captured individually. You can manually capture payments using Payment Capture API or Dashboard. Know more about capture settings for payments.After the integration is complete, a Pay button appears on your webpage/app.Click the button and make a test transaction to ensure the integration is working as expected. You can start accepting actual payments from your customers once the test transaction is successful.
Watch Out!This is a mock payment page that uses your test API keys, test card and payment details.
  • Ensure you have entered only your Test Mode API keys in the Checkout code.
  • Test mode features a mock bank page with Success and Failure buttons to replicate the live payment experience.
  • No real money is deducted due to the usage of test API keys. This is a simulated transaction.
Following are all the payment modes that the customer can use to complete the payment on the Checkout. Some of them are available by default, while others may require approval from us. Raise a request from the Dashboard to enable such payment methods.

Payment Method | Code | Availability

Debit Card | debit | ✓

Credit Card | credit | ✓

Netbanking | netbanking| ✓

UPI | upi | ✓

EMI - Credit Card EMI, Debit Card EMI and No Cost EMI | emi | ✓

Wallet | wallet | ✓

Cardless EMI | cardless_emi | Requires Approval.

Bank Transfer | bank_transfer | Requires Approval and Integration.

Emandate | emandate | Requires Approval and Integration.

Pay Later| paylater | Requires Approval.You can make test payments using one of the payment methods configured at the Checkout.

Netbanking

You can select any of the listed banks. After choosing a bank, Razorpay will redirect to a mock page where you can make the payment success or a failure. Since this is Test Mode, we will not redirect you to the bank login portals. Check the list of supported banks.

UPI

You can enter one of the following UPI IDs:
  • success@razorpay: To make the payment successful.
  • failure@razorpay: To fail the payment.
Check the list of supported UPI flows.
Handy TipsYou can use Test Mode to test UPI payments, and Live Mode for UPI Intent and QR payments.

Cards

You can use the following test cards to test transactions for your integration in Test Mode.

Domestic Cards

Use the following test cards for Indian payments:

Network | Card Number | CVV & Expiry Date

Visa | 4100 2800 0000 1007 | Use a random CVV and any future date ^^^^^

Mastercard | 5500 6700 0000 1002 |

RuPay | 6527 6589 0000 1005 |

Diners | 3608 280009 1007 |

Amex | 3402 560004 01007 |

Error Scenarios

Use these test cards to simulate payment errors. See the complete list of error test cards with detailed scenarios. Check the following lists:

International Cards

Use the following test cards to test international payments. Use any valid expiration date in the future in the MM/YY format and any random CVV to create a successful payment.

Card Network | Card Number | CVV & Expiry Date

Mastercard | 5555 5555 5555 4444 5105 1051 0510 5100 5104 0600 0000 0008 | Use a random CVV and any future date ^^

Visa | 4012 8888 8888 1881 | Check the list of supported card networks.

Wallet

You can select any of the listed wallets. After choosing a wallet, Razorpay will redirect to a mock page where you can make the payment success or a failure. Since this is Test Mode, we will not redirect you to the wallet login portals. Check the list of supported wallets.