PhonePe Switch Integration

Integrate your Razorpay Custom web application to accept payments in PhonePe Switch platform.

PhonePe Switch platform allows customers to switch seamlessly between PhonePe and their preferred apps within the PhonePe app itself. With a single tap, customers can log in to these apps without downloading them. For example, customers can book cabs or hotel rooms right on the PhonePe app and utilize offers provided by PhonePe.

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 Request

  • This is an on-demand feature. Please raise a request with our to get this feature activated on your Razorpay account.
  • Watch this video to know how to raise a feature enablement request on the Razorpay Dashboard.
Feature Request GIF

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

  1. Customers log in to the PhonePe app and click PhonePe Switch.
  2. In the PhonePe Switch, customers select your app, place orders and click Proceed to Pay.
  3. Customers are redirected to the PhonePe payment page.
  4. After the successful payment on the PhonePe payment page, customers are redirected to your website.

For more details of the user journey through PhonePe Switch, refer to the


Before integrating with the Checkout, run through this checklist:

  • Check if your webapp is integrated with PhonePe Switch.
  • Understand the .
  • Sign up for a Razorpay Account.
  • Generate the API keys from the . 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 Certification

A customer's payment information should never reach your servers, unless you are PCI DSS certified.

Steps to integrate Custom Checkout in your site:

  1. .
  2. .
  3. .
  4. .
  5. .
  6. .

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

-H "Content-Type: application/json" \
-d '{
"amount": 1000,
"currency": "INR",
"receipt": "merchant_txn_id"
"phonepe_switch_context" : "{\n\"orderContext\":{\"trackingInfo\":{\n\"type\":\"HTTPS\",\"url\":\"\"}},\"fareDetails\":{\n\"payableAmount\":3900,\"totalAmount\":3900},\"cartDetails\":{\"cartItems\":[{\"quantity\":1,\"address\":{\"addressString\":\"TEST\",\"city\":\"TEST\",\"pincode\":\"TEST\",\"country\":\"TEST\",\n\"latitude\":1,\"longitude\":1},\"shippingInfo\":{\n\"deliveryType\":\"STANDARD\",\"time\":{\"timestamp\":1561540218,\"zoneOffSet\":\"+05:30\"\n\n\n}},\n\n\n\n\n\"category\":\"SHOPPING\",\"itemId\":\"1234567890\",\n\"price\":3900,\"itemName\":\"TEST\"}]}}"



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.



string The currency in which the transaction should be made.
You can create Orders in INR only.



string Your receipt ID for this order can be passed here. Maximum length is 40 characters.



json string This is the transactionContext created by PhonePe. It contains the shopping cart details for the customer transacting on the PhonePe Switch platform. It is the transactionContext which is expected by PhonePe.
Refer to




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

Include the following script, preferably in <head> section of your page:

<script type="text/javascript" src=""></script>

Including the Javascript, not the Library

Include the script from 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.

var razorpay = new Razorpay({
key: '<YOUR_KEY_ID>',
// logo, displayed in the payment processing popup
image: '',

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

key: '<YOUR_KEY_ID>',
// logo, displayed in the payment processing popup
image: '',
new Razorpay({}); // will inherit key and image from above.

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:

var data = {
amount: 1000, // in currency subunits. Here 1000 = 1000 paise, which equals to ₹10
currency: "INR",
email: '',
contact: '9123456780',
notes: {
address: 'Ground Floor, SJR Cyber, Laskar Hosur Road, Bengaluru',
order_id: "order_EdUtuxhupLSOUH", // Enter the order ID obtained from Step 1
method: 'wallet',
wallet: 'phonepeswitch'
var btn = document.querySelector('#btn');
btn.addEventListener('click', function(){
razorpay.on('payment.success', function(resp){
}); // will pass payment ID, order ID, and Razorpay signature to success handler.
razorpay.on('payment.error', function(resp){
alert(resp.error.description)}); // will pass error object to error handler


The createPayment method should be called within an event listener triggered by user action to prevent the popup from being blocked. For example:

$('button').click( function (){ razorpay.createPayment(...) })

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.

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

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


string Unique identifier for the payment returned by Checkout only for successful payments.


string Unique identifier for the order returned by Checkout.


string Signature returned by the Checkout. This is used to verify the payment.

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 .
  2. Use the SHA256 algorithm, the razorpay_payment_id and the order_id to construct a HMAC hex digest as shown below:

    generated_signature = hmac_sha256(order_id + "|" + razorpay_payment_id, secret);
    if (generated_signature == razorpay_signature) {
    payment is successful
  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.

Given below is the sample code for payment signature verification:

RazorpayClient razorpay = new RazorpayClient("[YOUR_KEY_ID]", "[YOUR_KEY_SECRET]");
String secret = "EnLs21M47BllR3X8PSFtjtbd";
JSONObject options = new JSONObject();
options.put("razorpay_order_id", "order_IEIaMR65cu6nz3");
options.put("razorpay_payment_id", "pay_IH4NVgf4Dreq1l");
options.put("razorpay_signature", "0d4e745a1838664ad6c9c9902212a32d627d68e917290b0ad5f08ff4561bc50f");
boolean status = Utils.verifyPaymentSignature(options, secret);

After you have completed the integration, you can

, make test payments, replace the test key with the live key and integrate with other .

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 or webhooks.

  • Auto-capture payments (recommended)
    Authorized payments can be automatically captured. You can auto-capture all payments on the Razorpay Dashboard.

Watch Out!

Payment capture settings work only if you have integrated with Orders API on your server side. Know more about the


  • Manually capture payments
    Each authorized payment can also be captured individually. You can manually capture payments using:

Know more about


After the integration is complete, a Pay button will appear on your webpage/app.

Test integration 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 is successful.

You can make test payments using one of the payment methods configured at the Checkout.

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 in the Checkout code.
  • Due to using test keys, no real money is deducted. 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 require approval from us. Raise a request from the

to enable such payment methods.

Payment MethodCodeAvailability
EMI - , and emi
cardless_emiRequires .
bank_transferRequires and Integration.
emandateRequires and Integration.
paylaterRequires .

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


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


Handy Tips

UPI payments should be tested in Live Mode.

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

  • Use any valid expiration date in the future in the MM/YY format.
  • Use any random CVV to create a successful payment.
Card NetworkDomestic / InternationalCard Number
MastercardDomestic5267 3181 8797 5449
VisaDomestic4111 1111 1111 1111
MastercardInternational5555 5555 5555 4444
5105 1051 0510 5100
VisaInternational4012 8888 8888 1881
5104 0600 0000 0008

Check the list of


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


Is this integration guide useful?