[Create an Application](#1-create-an-application)
[Generate Token](#2-generate-token)
[Create accounts and upload KYC details using onboarding APIs](#3-c...
[Generate Onboarding URL and redirect users](#4-generate-onboarding...
[Fetch access token associated with the merchant](#5-fetch-access-t...
[Access resources using access token](#6-access-resources-using-acc...
[Process Payments](#7-process-payments)
[Subscribe to onboarding webhooks to receive account activation upd...
1. Create an Application
The first step towards building an integration is creating an application on the Razorpay Partner Dashboard. Here, an application refers to a software entity that you register on Razorpay to facilitate OAuth-based authentication and authorisation for businesses on your platform. It acts as an intermediary between you and Razorpay. Internally, Razorpay OAuth identifies the applications by theirclient_id.
- When you create an application on Razorpay, we generate two clients linked to the application: development and production clients.
- Each client has its own
client_idandclient_secret. - You can use the development client in your sandbox environment or during the integration phase, and the production client once you go live.
Development and Production Clients
Given below is a comparison of the development and production clients:Particulars | Development Client | Production Client
Redirect URI | Can have any type of Redirect URIs whitelisted, including non-HTTP and localhost. | Cannot use non-HTTPS Redirect URIs.
Test and Live Mode Access | Can access both modes. | Can access only live mode data.To create an application:
- Log in to the Dashboard and navigate to Applications under Partners.
- Click Create Application under Created Applications.
-
Provide the following details and click Save.
- Name: The application name provided here is displayed on the Razorpay authorisation interface.
- Website: Enter the URL of the application’s website.
- Logo: Upload a square image for application logo. If logo is absent, a default logo is used.
- Client ID: Publicly exposed identifier of the client which is generated uniquely. It helps identify your application on Razorpay.
- Client Secret: Privately shared string between the application and Razorpay. It helps to authenticate the identity of the application on server-to-server API calls. Do not expose the client secret publicly.
- Redirect URIs: A whitelisted set of URIs defined during creation. Production clients can only use secure HTTPS URIs to prevent man-in-the-middle attacks. You can define multiple redirect URIs.
- Edit the Redirect URIs for your clients if needed.
- Click Save.
2. Generate Token
The next step is to generate a bearer token to access onboarding APIs. You must use the access token generated in the response to hit the onboarding APIs. Below is a sample code to generate a bearer token using Onboarding SDK.access_token is valid for 90 days. After your access token expires, you will receive a 4XX error response. Regenerate the access token using your credentials.
3. Create Account and Upload KYC Details
Use onboarding APIs to add KYC details of your clients. You can pre-fill all or a few KYC details using APIs and let the users fill in the remaining on the onboarding form. Below are the APIs available to onboard clients.API | Action
Account | Create and update a client account. Add basic details like name, phone number, email ID and KYC details like business name, type and business PAN details. Check the Account API Entity for the complete list of fields.
Product Configuration | Configure products for an account. Update payment methods, settlement details and refund settings. Check the Product Configuration API Entity for the complete list of fields.
Stakeholder | Add the KYC details of the authorised signatory or the owner of the business. Check the Stakeholder API Entity for the list of fields.
Document | Upload KYC documents for accounts and stakeholders. Know more about Document APIs. List of required KYC documents as per business type.4. Generate Onboarding URL
Below is the sample code to generate the onboarding URL.Sample Onboarding URL
Query Parameters
Define the following query parameters in the URL.client_id mandatory
: string The unique client identifier.
response_type mandatory
: string Specifies that the application is requesting an authorisation code grant. Possible value is code.
redirect_uri mandatory
: string Callback URL used by Razorpay to redirect after the user approves or denies the authorisation request. The client should whitelist the redirect_uri.
scope mandatory
: string Defines what access your application is requesting from the user. You can request multiple scopes by specifying each scope name separately in the URL using array notation. For example: scope[]=read_only&scope[]=read_write. Possible values:
read_only: Provides read access to all resources. That is, allGETAPI requests.read_write: Provides read and write access to all resources on the API.
state mandatory
: string A random string generated by your service. This parameter helps prevent cross-site request forgery (CSRF) attacks. State validation has to be implemented by your application and should work as described below:
- Your application should generate a unique random string and save it in the database.
- Send the random string to Razorpay in the authorisation request in the
stateparameter. - Razorpay sends back the same
statevalue as query params on your redirect URI. - In your backend, you validate that the state value stored in your database matches the one you received for the
client_idand the user that initiated the authorisation.
onboarding_signature conditionally mandatory
: string This parameter is applicable only for accounts created using KYC pre-fill. This will reduce sub-merchant onboarding time. Know more about onboarding signature.
Success Response Parameters
We send the following query parameters if the user approves the authorisation request:code
: URL-encoded authorisation code. You can exchange this code for an access token in the next step.
state
: The value of the state parameter sent in the authorisation request.
Error Response Parameters
Error | Cause | Solution
phone number unverified | - You are using an expiredonboarding_signature.
onboarding_signatureis not provided or is invalid. | Use a validonboarding_signature. An onboarding signature is valid for 24 hours. You can regenerate it using the same code.
Redirect Users to Onboarding
You need to share the Razorpay-hosted co-branded onboarding URL with your clients. Clients use this URL to continue the onboarding process.The user will be redirected to the co-branded onboarding form when...
After the necessary details are submitted, the user is prompted to...
The client gives authorisation, which allows Razorpay to connect th...
On successful authorisation, Razorpay redirects the user back to a...
Onboarding Signature
onboarding_signature is a mandatory parameter if you are pre-filling KYC details. The onboarding signature is used to verify the identity of the partner initiating the onboarding URL.
Use the below sample code to generate an onboarding_signature.
Authorisation Response
After completion, the browser is redirected to URI specified in theredirect_uri parameter.
5. Fetch Access Token
You require an access token to create payments and refunds on behalf of your clients using APIs. Exchange the authorisation code received in the previous step for an access token.Request Parameters
client_id mandatory
: string Unique client identifier.
client_secret mandatory
: string Client secret string.
grant_type mandatory
: string Defines the grant type for the request. Possible value is authorization_code.
redirect_uri mandatory
: string Specifies the same redirect_uri used in the authorisation request.
code mandatory
: string Decoded authorisation code received in the last step.
mode optional
: string The type of mode. Possible values:
testlive(default)
Response Parameters
The server responds with the following parameters:token_type
: string Defines the type of access token. Possible value is Bearer.
expires_in
: integer Integer representing the TTL of the access token in seconds.
access_token
: string A private key used to access sub-merchant resources on Razorpay. Used for server-to-server calls only.
public_token
: string A public key is used only for public routes such as Checkout or Payments.
refresh_token
: string Used to refresh the access token when it expires.
razorpay_account_id
: string Identifies the sub-merchant ID who granted the authorisation.
Error Response Parameters
Refer to our errors page for the list of errors and solutions. Store theaccess_token received above on your server. Using this token, you can access the sub-merchant’s data, create payments and refunds using Razorpay APIs.
Regenerate Access Token
Theaccess_token is valid for 90 days. After your access token expires, you will receive a 4XX error response. Use a refresh token to generate a new access token. You can make a request using your refresh token to generate a new (access_token and refresh_token) pair.
Below is a sample API request to request a new token.
6. Access Resources Using Access Token
After you obtain an access token, you can use it to access the sub-merchant’s data on Razorpay APIs. The access is controlled based on the scope requested for and granted by the user during the authorisation process. Provide the access token in theBearer authorisation header while requesting Razorpay APIs.
Given below is a sample code for the Fetch all Payments API.
7. Process Payments
As a Technology Partner, you can allow sub-merchants to accept payments through various Payment Methods and channels. after gettingaccess_token.
1. Access Payment APIs using OAuth
You can process payments on behalf of your sub-merchants using Razorpay APIs. Use the tokens generated during OAuth integration. Use theaccess_token generated in the build integration step to authenticate using Bearer Auth.
Below is a sample code to create an Order and process payments.
/orders
2. Public Token
Using thepublic_token for authorisation can secure a public-facing implementation such as Razorpay Checkout. In such cases, the public_token can replace the key_id field as shown below:
3. Verify Payment Signature
This is a mandatory step to confirm the authenticity of the details returned to the Checkout form for successful payments. To verify therazorpay_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.client_secret: Available in your server. Theclient_secretthat was generated from the RazorpayDashboard.
-
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.