Available in🇮🇳 India
UPI payments enable customers to make payments using a Virtual Payment Address (VPA) without entering bank information.
Customers enter their VPAs on your UI, open the respective UPI apps and complete the payment after 2-factor authentication (UPI PIN and MPIN) on their mobile devices. Customers are redirected to your website or app after successful payment.
In this flow, customers likely enter invalid VPAs or forget their VPAs, which could lead to higher drop-off rates. To overcome this problem, Razorpay enables you to validate and save the VPAs of a customer. Know more about Saved VPA.
NPCI Restrictions for UPI Collect FlowAs per NPCI guidelines, the following MCC codes are restricted and cannot accept UPI Collect payments:
Restricted MCC Codes
Restricted MCC Codes
Best Practices
Follow these best practices to accept online payments using the UPI collect flow:- Validate the VPA before initiating the payment request.
- Add a custom UPI Collect expiry based on the business requirement to provide enough time for the customer to complete the payment.
- Use the Saved VPA feature offered by Razorpay to provide a better customer experience.
Prerequisites
- Reach out to our Support Team to enable VPA validation and saved VPA features for your account.
- Keep the API keys (
Key_IdandKey_Secret) handy for integration. - Generate API Keys from the Dashboard.
User Flow
Let us understand the process for accepting payments via the UPI collect flow:- The customer selects UPI as the payment method and enters the VPA of their choice on the UI.
Razorpay validates the entered VPA. - The customer saves the entered VPA details while completing the payment.
Razorpay saves all the valid VPA details as tokens. - On a repeat visit, the customer selects the VPA token to complete the payment.
Create VPA Tokens
Given below are the steps to create VPA tokens:- Create a customer or fetch the customer for whom the VPA should be saved.
- Create an order.
- Validate the VPA entered by the customer.
- Initiate payment with a collect request on the provided VPA.
- Handle Payment Success and Error Events.
Step 1: Create a Customer
Handy TipsSkip this step if you already have customers created in your account.
email and contact.
POST /customers
Response
Request Parameters
name mandatory
: string The name of the customer.
email optional
: string The email id of the customer.
contact optional
: string The phone number of the customer.
fail_existing optional
: string The request throws an exception by default if a customer with the exact details already exists. You can pass an additional parameter fail_existing to get the existing customer’s details in the response. Possible values:
1(default): If a customer with the same details already exists, throws an error.0: If a customer with the same details already exists, fetches details of the existing customer.
notes optional
: json object Set of key-value pairs that can be associated with an entity. This can be useful for storing additional information about the entity. A maximum of 15 key-value pairs, each of 256 characters (maximum), are supported.
Step 2: Create an Order
You should create an order before initiating a payment at your end.POST /orders
Response
Request Parameters
amount mandatory
: integer The amount for which the order was created, in currency subunits. For example, for an amount of ₹295, enter 29500.
currency mandatory
: string ISO code for the currency in which you want to accept the payment. Only INR is supported.
receipt optional
: string Receipt number that corresponds to this order, set for your internal reference. Maximum length of 40 characters.
notes optional
: json 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 3: Validate the VPA
Collect the VPA details of the customer and validate it as follows:POST /payments/validate/vpa
Response
Request Parameters
vpa mandatory
: string The virtual payment address (VPA) you want to validate. For example, gauravkumar@exampleupi.
Step 4: Initiate a Payment
Once validated, you can now save the VPA provided by the customer. Create a payment with the validvpa as follows:
POST /payments/create/upi
Request Parameters
amount mandatory
: integer The amount associated with the payment in the smallest unit of the supported currency. For example, 2000 means ₹20.
currency mandatory
: string ISO code of the currency associated with the payment amount. Only INR is supported.
order_id mandatory
: string Unique identifier of the order obtained in the response of the previous step.
notes optional
: json object Key-value pairs that can hold additional information about the payment. Refer to the Notes section of the API Reference Guide.
description optional
: string Descriptive text of the payment.
contact mandatory
: string Phone number of the customer.
email mandatory
: string Email address of the customer.
save
: boolean Specifies if the VPA should be stored as tokens. Possible values are:
true: Saves the VPA details.false(default): Does not save the VPA details.
customer_id mandatory
: string Unique identifier of the customer, obtained from the response of Step 1.
ip mandatory
: string The client’s browser IP address. For example, 117.217.74.98.
referer mandatory
: string Value of referer header passed by the client’s browser. For example, https://example.com/
user_agent mandatory
: string Value of user_agent header passed by the client’s browser. For example, Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36
upi
: object Details of the collect expiry.
flow mandatory
: string Specify the type of the UPI payment flow. Possible values are:
collect(default)intent
vpa mandatory
: string The customer’s VPA to which the collect request will be sent.
expiry_time mandatory
: integer The number of minutes after which the link will expire. The default value is 5. Maximum value is 5760.
Response Parameters
razorpay_payment_id
: string Unique identifier for the payment returned by Checkout only for successful payments.
Step 5: Handle Payment Success and Error Events
Once the customer completes the payment, aPOST request is made to the callback_url provided in the payment request. The data contained in this request will depend on whether the payment was a success or a failure.
Success Callback
If the payment made by the customer is successful, the following fields are sent:razorpay_payment_idrazorpay_order_idrazorpay_signature
Callback Example
Failure Callback
If the payment has failed, the callback will contain details of the error. Refer to Errors for details.Create Payments using Tokens
The customer can make payments using the VPA tokens (which were saved earlier) on a repeat transaction.- Create an order.
- Fetch all tokens of a customer.
- Initiate a payment with the token selected by the customer.
- Handle Payment Success and Error Events.
Step 1: Create an Order
You should create an order before initiating the payment.POST /orders
Response
Request Parameters
amount mandatory
: integer The amount for which the order was created, in currency subunits. For example, for an amount of ₹295, enter 29500. Payment can only be made for this amount against the order.
currency mandatory
: string ISO code for the currency in which you want to accept the payment. Refer the list of supported currencies.
receipt optional
: string Receipt number that corresponds to this order, set for your internal reference. Can have a maximum length of 40 characters.
notes optional
: json 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: Fetch VPA Tokens of a Customer
Use the API given below to retrieve all the card (if saved earlier) and VPA tokens of a customer.GET /customers/:customer_id/tokens
Step 3: Initiate a Payment Using VPA Token
In each payment create request, instead of thevpa field, pass the customer_id and token attributes:
POST /payments/create/upi
Request Parameters
customer_id
: string Unique identifier of the customer.
token
: string Token of the saved VPA.
Response Parameters
Once the payment is successfully created, you will receive a response containing thenext array. This array tells you the next steps that you should take to process the payment:
razorpay_payment_id
: string Unique identifier for the payment returned by Checkout only for successful payments.
next
: array A list of action objects available to you to continue the payment process. Present when the payment requires further processing.
action
: string The action that you need to perform further. In this case, the value is poll
url
: string Contains the URL that you must poll to fetch the status of the payment, either authorized or failed.
Step 4: Handle Payment Success and Error Events
Once the customer completes the payment, aPOST request is made to the callback_url provided in the payment request. The data contained in this request will depend on whether the payment was a success or a failure.
Success Callback
If the payment made by the customer is successful, the following fields are sent:razorpay_payment_idrazorpay_order_idrazorpay_signature
Callback Example
Failure Callback
If the payment has failed, the callback will contain details of the error. Refer to Errors for details.Verify Payment Status
You can verify the status of the payments using any of the following methods:- Poll Razorpay servers periodically for the payments made for the order using our Fetch Payment APIs.
- Subscribe to the webhook events created in our system for each of the following entities:
Payment failure and re-initiating payment
If the Order is not markedpaid within 2-3 minutes, then you can re-initiate payment for the same.