Steps to Integrate
Watch the following complete integration video of PayU OTP Assist:
Step 1: Include the SDK in your Application
Include the SDK in your application’s build.gradle:
- Min SDK Version: 21
- Compile SDK Version: 31 or later
Step 2: Set up Payment Hash and Post Data
Generate Payment Hash
For more information on the generation of Payment Hash, refer to Hash Generation.
Note: Every transaction (payment or non-payment) needs a hash set up by you before sending the transaction details to PayU. Hash is required for PayU to validate the authenticity of the transaction. This hashing should be done on your server.
Payment Post Data
Note: Use the Core SDK library to generate payment post data.
Step 3: Initiate Payment
Initialize Native OTP SDK
Initialize the Native OTP Assist SDK by providing the
PayUOtpAssistConfig object having post data and reference to
PayUOtpAssistCallback to listen to the SDK events similar to the following code block:
Note: Ensure that you configure the Internet permission in your manifest file:
<uses-permission android:name="android.permission.INTERNET" />
PayU fetches the OTP through RECEIVE_SMS if the RECEIVE_SMS permission is granted. Otherwise, fetch the OTP using the Google Consent API. To understand the flow, refer to PayU OTP Parser.
The following is a list of callback functions provided by PayUOtpAssistCallback class:
- fun onPaymentSuccess(merchantResponse: String?, payUResponse: String?): Called when payment succeeds. merchantResponse:
- fun onPaymentFailure(merchantResponse: String?, payUResponse: String?): Called when payment fails.
- fun onError(errorCode: String?, errorMessage: String?): Called when we got some error where:
- errorCode : Error Code
- errorMessage : Error Description
- fun shouldHandleFallback(payUAcsRequest: PayUAcsRequest) : Boolean – It’s an optional callback, override when you want to handle the Bank page redirection flow. You just need to change the return value to false. You can also open CustomeBrowser in fallback scenarios. The following code snippet is to launch the CustomBrowser.
You will get
shouldHandleFallback() callback. Whether you will get
PayUAcsRequest.acsTemplate is the HTML string that you need to load to the Web view.
|issuerUrl||It’s the Bank/ACS page Url.|
|issuerPostData||You need to load issuerUrl to the Webview along with this issuerPostdata string. Ex: webView.postUrl(issuerUrl, issuerPostData.toByteArray())|
|acsTemplate||If issuerUrl is empty, you need to load acsTemplate to the Webview. Ex: webView.loadData(acsTemplate, “text/html”, “UTF-8”);|
The following table lists error codes and their description:
|1002||Network timeout, please verify with your server.|
|1003||Gateway timeout, please verify with your server.|
|1004||User cancelled it, please verify with your server.|
|1005||Something went wrong, please verify with your server.|
|1006||The bank page timed out, please verify with your server.|
Note: After you get the response from SDK, make sure to confirm it with the PayU server. It is recommended to implement the PayU Webhook or backend verify call from your backend.
Step 4: Verify the Transaction using Webhook
After you get the response from SDK, make sure to confirm it with the PayU server.
Note: It is recommended to implement the PayU Webhook or backend verify call from your backend.
Webhook is a server-to-server callback. Once this feature is activated for merchants, PayU would send an S2S response, in addition to SDK callback, to the merchant. It is recommended for the merchant to process the transaction order status – based upon the S2S response and not via the Browser Redirection/SDK callback response to ensure optimum translation outcomes. For more information on the Webhook implementation, refer to Web Checkout Integration Documentation > Webhooks,
Also, you can verify payment through polling, the transaction status after the SDK callback from your backend. For more information, refer to Verify the Transaction.