Prerequisites
Before you integrate TPV on Razorpay Standard integration, you should fulfill the following requirements:- Set up your Razorpay account, if you have not done already.
- Contact your dedicated support POC to enable the TPV feature for your account.
- Generate API keys required to authenticate API requests sent to Razorpay servers.
- Check the best practices.
1. Build Integration
In the TPV integration flow, Razorpay maps the customers’ bank accounts to ensure that the payment is processed only from their registered bank accounts. Follow the steps given below:1.1 Collect Investor Bank Account details
You should collect the bank account details provided by the investor at the time of registration.1.2 Create an Order
Pass the investor bank account details to thebank_account array of the Orders API. You can choose to make the investor pay using a certain payment method or permit them to choose any of the supported payment method, that is, netbanking, UPI or debit card.
Scenario | Action Needed
Pay Using Specific Payment Method |Pass the method parameter.
Pay Using Any Method (Netbanking/UPI/Debit Card) | Do not pass the method parameter.
/orders
Scenario 1: Method Parameter is Passed
The investor needs to pay using the payment method specified by you in the order. For example, if you want the investor to pay using UPI, you must pass method=upi.
Netbanking
Given below is the sample code when the method is netbanking.
Curl
Debit Card
Given below is the sample code when themethod is card.
Curl
UPI
Given below is the sample code when themethod is upi.
Curl
Scenario 2: Method Parameter is Not Passed
If you want the investor to select any of the payment method, do not pass themethod field. This way, they can choose netbanking, debit card or UPI to make the payment, as per their convenience.
Curl
Request and Response Parameters
Create a request payload using the following attributes:amount mandatory
: integer The transaction amount expressed in paise (currency supported is INR). For example, for an actual amount of ₹1, the value of this field should be 100.
currency mandatory
: string The currency in which the transaction should be made. You can create Orders in INR only.
receipt optional
: string Receipt number that corresponds to this Order, set for your internal reference. Maximum length is 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”.
method mandatory
: string The payment method used to make the payment. If this parameter is not passed, investors will be able to make payments using both netbanking and UPI payment methods. Possible values:
netbanking: Investors can make payments only using netbanking.card: Investors can make payments using debit card.upi: Investors can make payments only using UPI.
bank_account
: Details of the bank account that the investor has provided at the time of registration.
account_number mandatory
: string The bank account number from which the investor should make the payment. For example, 765432123456789 Payments will not be processed for an incorrect account number.
name mandatory
: string The name linked to the bank account. For example, Gaurav Kumar.
ifsc mandatory
: string The bank IFSC. For example, HDFC0000053.
id
: string Unique identifier of the payment.
entity
: string Indicates the type of entity. Here, it is order.
amount
: integer The payment amount represented in the smallest unit of the currency passed. For example, amount = 100 translates to 100 paise, that is ₹1 (default currency is INR).
amount_paid
: integer The amount that has been paid.
amount_due
: integer The amount that is yet to be paid.
currency
: string The 3-letter ISO currency code for the payment. Currently, we only support INR.
receipt
: string A unique identifier of the order entered by the user. For example, BILL13375649.
status
: string The status of the order.
notes
: object Key-value pair you can use to store additional information about the entity. Maximum of 15 key-value pairs, 256 characters each. For example, “note_key”: “Beam me up Scotty”.
created_at
: integer The Unix timestamp at which the order was created.
offer_id
: string Unique identifier of the offer.
attempts
: integer The number of payment attempts, successful and failed, that have been made against this order.
1.3 Add Checkout Code
Send theorder_id obtained in the response of the previous step along with the other Checkout attributes to trigger Razorpay Checkout.
Following are two sample codes for Checkout:
- On successful payment, your web page is displayed to the user.
-
On payment failure, the customer is notified of the reason for failure and requested to retry the payment.
- On successful payment, the customer is redirected to the specified URL. For example, a payment success page.
-
On payment failure, the customer is requested to retry payment at Checkout.
Copy-paste the form parameters as
optionsin your HTML code:Know more about theCheckout Form Fields.Checkout with Handler Function
Handy Tips
- The open method of the Razorpay object (
rzp1.open()) should be invoked by your site’s JavaScript. This may or may not be a user-driven action such as a click. - UPI Intent Apps will appear on the standard checkout if the method is
upiin the Orders API.
1.4 Handle Payment Success and Failure
The way you handle payment success and failure scenarios depends on the Checkout sample code you opted for in the previous step.Checkout with Handler Function
If you used Sample Code with Handler Function: Investor sees your application web page, and the Checkout returns the response object of the successful payment (razorpay_payment_id, razorpay_order_id and razorpay_signature). You need to collect these and send them to your server.
Success Handling Code
Failure Handling Code
Checkout with Callback URL
If you used the Sample Code with the 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. Only successful authorisations are auto-submitted.
In case of failed payments, the Checkout Form is displayed again for payment retry.
1.5 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.
1.6 Verify 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.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.2. Test Integration
After the integration is complete, a Pay button will appear 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 netbanking, card or UPI payment methods configured at the Checkout.3. Go-Live
Consider these steps before taking the integration live.3.1 Accept Live Payments
Perform an end-to-end simulation of funds flow in the Test Mode. Once confident that the integration is working as expected, switch to the Live Mode and start accepting payments from customers.3.2 Payment Capture
After payment isauthorised, 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.
3.2 Set Up Webhooks
Ensure you have set up webhooks in the live mode and configured the events for which you want to receive notifications.Related Information
- Webhooks (Recommended)
- Error Codes (Recommended)
- How Payment Gateway Works
- Payment States
- Settlements
- Refunds