Available in🇮🇳 India
What UPI Collect Is
In the UPI Collect flow, the customer enters their Virtual Payment Address (VPA) on your UI. Razorpay sends a collect request to that VPA. The customer approves the request in their UPI app with their UPI PIN, and you receive the payment status.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 you initiate the payment. Show the customer name returned by the API and let the customer confirm it before you send the collect request.
- Set
upi.expiry_timebased on your business needs so that the customer has enough time to approve the request. - Tell the customer to open their UPI app to approve the request, and show a timer until the request expires.
- Use Saved VPA that repeat customers do not have to enter their VPA again.
Prerequisites
- Reach out to our Support Team to enable UPI Collect and VPA validation for your account. Ask for the saved VPA feature too if you plan to use Saved VPA.
- Generate API keys in the Dashboard. Use test keys (
rzp_test_) while you build, and live keys (rzp_live_) after you go live. Keep the key secret on your server only.- Partner auth is different from merchant auth. If you are a partner calling the APIs on behalf of a business you onboarded, do not use API keys or Basic Auth. Use the business’s OAuth access token instead. Know more about generating an access token.
- The access token expires every 90 days. Use the refresh token to get a new one before it expires. Know more about tokens.
- Verify payment signatures with your OAuth application’s
client_secret, not an API key secret. Verify webhooks with the secret you set on the application. Know more about partner signature verification.
- Partner auth is different from merchant auth. If you are a partner calling the APIs on behalf of a business you onboarded, do not use API keys or Basic Auth. Use the business’s OAuth access token instead. Know more about generating an access token.
- If you are an international business looking to collect payments from Indian customers, refer to our import payment flow documentation.
- Authenticate every API call with Basic Auth if you use API keys. Use your Key Id as the username and your Key Secret as the password. Know how to authenticate.
User Flow
- The customer selects UPI as the payment method and enters their VPA on your UI.
- You validate the VPA and show the name linked to it. The customer confirms the name.
- You initiate the payment. Razorpay sends a collect request to the customer’s VPA.
- The customer opens their UPI app, approves the request and enters their UPI PIN.
- You receive the payment status through webhooks or by polling the payment.
Integration Steps
- Create an order.
- Validate the VPA entered by the customer.
- Initiate a payment with a collect request on the validated VPA.
- Handle payment success and error events.
- Verify the payment status.
Step 1: Create an Order
You should create an order before initiating a payment at your end.POST /orders
Response
Request Parameters
The amount for which the order was created, in currency subunits. For example, for an amount of ₹295, enter
29500.ISO code for the currency in which you want to accept the payment. Only
INR is supported.Receipt number that corresponds to this order, set for your internal reference. Maximum length of 40 characters.
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: Validate the VPA
Before you send a collect request, check that the customer’s VPA exists and is active. This avoids collect requests that are sure to fail. Collect the VPA details of the customer and validate it as follows:POST /payments/validate/vpa
Response
Request Parameters
The virtual payment address (VPA) you want to validate. For example,
gauravkumar@exampleupi.Response Parameters
Indicates whether the VPA exists. Possible values:
true: The VPA exists. Proceed to initiate the payment.false: The VPA does not exist. Ask the customer to enter the VPA again.
Error Responses
When the API cannot check the VPA, it returns an error object instead.Error Response
Handy Tips
- A response with
successasfalseis still an HTTP200response. Decide the next step using thesuccessfield, not the HTTP status. - VPAs with the
@paytmhandle and VPAs of banks that are not recognised return200withsuccessasfalse. Treat this as an invalid VPA. - Check the VPA format on your page before you call the API, for example with the pattern
/^[a-z0-9.-]{2,}@[a-z0-9]+$/i. Validate when the customer leaves the field, not on every keystroke. - Do not store a validated VPA and skip the check later. A VPA can be deactivated, so validate it on every checkout.
- You cannot validate a VPA in Test Mode.
Step 3: Initiate a Payment
After the VPA is validated, create a payment with thevpa the customer confirmed. Razorpay sends a collect request to this VPA.
POST /payments/create/upi
Request Parameters
The amount associated with the payment in the smallest unit of the supported currency. For example,
2000 means ₹20.Key-value pairs that can hold additional information about the payment.
Refer to the Notes section of the API Reference Guide.
Refer to the Notes section of the API Reference Guide.
Value of
referer header passed by the client’s browser. For example, https://example.com/Value of
For example, Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36
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
Specify the type of the UPI payment flow.
Possible values are:
Possible values are:
collect(default)intent
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 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.Step 5: Verify the 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:
Test the Integration
Once you’ve completed the integration, test it using our test cases for UPI Collect.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.
Saved VPA
Customers often mistype their VPA or forget it, which leads to drop-offs. With Saved VPA, Razorpay saves a customer’s VPA as a token after a successful payment. On a repeat visit, the customer picks the saved VPA instead of typing it again. Saved VPA is not available in Test Mode yet. Test Mode support is coming soon. The customer experience works like this:- The customer enters their VPA on your UI and completes a UPI Collect payment.
- Razorpay saves the VPA as a token for that customer.
- On a repeat visit, you show the customer’s saved VPAs on your UI.
- The customer selects a saved VPA and completes the payment.
- Create a customer or fetch the existing customer.
- Save the VPA during the customer’s first payment.
- On a repeat visit, fetch the saved VPAs of the customer.
- Initiate a payment using the saved VPA the customer selects.
Create a Customer
Handy TipsSkip this step if you already have customers created in your account.
email and contact.
POST /customers
Response
Request Parameters
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.
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.
Save the VPA
Follow the integration steps above. In Step 3: Initiate a Payment, also pass thecustomer_id and save parameters. Razorpay saves the VPA as a token when the payment succeeds.
Curl
Unique identifier of the customer, obtained when you create a customer.
Specifies if the VPA should be saved as a token. Possible values:
true: Saves the VPA.false(default): Does not save the VPA.
Fetch the Saved VPAs of a Customer
On a repeat visit, fetch the tokens saved for the customer and show the VPAs on your UI. The response also includes saved cards, if any. Show only the tokens wheremethod is upi.
GET /customers/:customer_id/tokens
Initiate a Payment Using a Saved VPA
Create an order first. Then, in the payment request, pass thecustomer_id and token of the VPA the customer selected instead of upi.vpa:
POST /payments/create/upi
Request Parameters
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.
After you initiate the payment, handle the payment events and verify the payment status as in the main flow.