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.
Integration Steps
Steps to integrate Custom Checkout in your site:- Create an Order from your Server.
- Invoke Checkout and Pass Order Id and Other Options to it
- Include the JavaScript code in your Webpage.
- Instantiate Razorpay Custom Checkout.
- Submit Payment Details.
- Store Fields in Your Server.
- 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. /ordersRequest
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 ERRORNoteThe
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 invokingcreatePayment method:createPayment with handler Function
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:
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:
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:
-
Create a signature in your server using the following attributes:
order_id: Retrieve theorder_idfrom your server. Do not use therazorpay_order_idreturned by Checkout.razorpay_payment_id: Returned by Checkout.key_secret: Available in your server. Thekey_secretthat was generated from the Dashboard.
-
Use the SHA256 algorithm, the
razorpay_payment_idand theorder_idto construct a HMAC hex digest as shown below:HMAC Hex Digest -
If the signature you generate on your server matches the
razorpay_signaturereturned 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 isauthorized, 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.
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 paymentsuccess 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.
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 paymentsuccess or a failure. Since this is Test Mode, we will not redirect you to the wallet login portals.
Check the list of supported wallets.
Related Information
- Webhooks (Recommended)
- Error Codes (Recommended)
- How Payment Gateway Works
- Payment States
- Settlements
- Refunds