Integration
Integration with the Native OTP Assist mobile SDK in 4 steps:
    1.
    Include the SDK in your application.
    2.
    Set up the payment hash and postdata
    3.
    Initiate the payment.
    4.
    Verify the transaction.
Watch the complete integration video of PayU OTP Assist.

Include the SDK in your app build.gradle

1
implementation 'in.payu:native-otp-assist:1.2.1'
Copied!
Compatibility
Min SDK Version: 21
Compile SDK Version: 30

Generate Payment Hash

Refer this document: Generate Hash
Every transaction (payment or non-payment) needs a hash by the merchant before sending the transaction details to PayU. This is required for PayU to validate the authenticity of the transaction. This should be done on your server.

Payment Post Data

Use Core Sdk library to generate payment postdata.

Initiate Payment

Initialize the Native OTP Assist SDK by providing the PayUOtpAssistConfig object having postdata and reference to the PayUOtpAssistCallback to listen to the SDK events.
Java
Kotlin
1
PayUOtpAssistConfig payUOtpAssistConfig = PayUOtpAssistConfig();
2
payUOtpAssistConfig.setPostData("POST_DATA_FOR_TRANSACTION");
3
4
5
PayUOtpAssist.open(
6
Context context,
7
PayUOtpAssistCallback payUOtpAssistCallback,
8
PayUOtpAssistConfig payUOtpAssistConfig)
Copied!
1
val payUOtpAssistConfig = PayUOtpAssistConfig()
2
payUOtpAssistConfig.postData = "POST_DATA_FOR_TRANSACTION"
3
PayUOtpAssist.open(
4
context: Context,
5
payUOtpAssistCallback: PayUOtpAssistCallback,
6
payUOtpAssistConfig: PayUOtpAssistConfig)
Copied!
Make sure to add internet permission in your manifest file.
1
2
<uses-permission android:name="android.permission.INTERNET" />
Copied!
We fetch the OTP via RECEIVE_SMS if RECEIVE_SMS permission granted, otherwise, fetch the OTP using Google Consent API. To understand the flow, refer to this page.

Callbacks

List of the callback function provided by PayUOtpAssistCallback class:
    1.
    fun onPaymentSuccess(merchantResponse: String?, payUResponse: String?)- Called when payment succeeds. merchantResponse:
    2.
    fun onPaymentFailure(merchantResponse: String?, payUResponse: String?)- Called when payment fails.
    3.
    fun onError(errorCode: String?, errorMessage: String?)- Called when we got some error where,
      errorCode : Error Code
      errorMessage : Error Description
    4.
    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. Below is the code snippet to open the CustomBrowser.
Java
Kotlin
1
boolean shouldHandleFallback(PayUAcsRequest payUAcsRequest){
2
3
CustomBrowserConfig customBrowserConfig = new CustomBrowserConfig(merchantKey, txnId);
4
5
//Set the issuerUrl and issuerPostData to open in WebView for otp assist redirection to bank page
6
if (payUAcsRequest.getIssuerUrl()!=null && payUAcsRequest.getIssuerPostData()!=null) {
7
customBrowserConfig.setPostURL(payUAcsRequest.getIssuerUrl());
8
customBrowserConfig.setPayuPostData(payUAcsRequest.getIssuerPostData())
9
10
}else if (payUAcsRequest.getAcsTemplate()!=null){
11
customBrowserConfig.setHtmlData(payUAcsRequest.getAcsTemplate());
12
}else {
13
//Set the first url to open in WebView
14
customBrowserConfig.setPostURL(url);
15
customBrowserConfig.setPayuPostData(payuConfig.getData);
16
}
17
return false;
18
}
19
Copied!
1
fun shouldHandleFallback(payUAcsRequest: PayUAcsRequest) : Boolean {
2
3
val customBrowserConfig = CustomBrowserConfig(merchantKey, txnId)
4
5
//Set the issuerUrl and issuerPostData to open in WebView for otp assist redirection to bank page
6
if (!payUAcsRequest?.issuerUrl.isNullOrEmpty() && !payUAcsRequest?.issuerPostData.isNullOrEmpty()) {
7
customBrowserConfig.postURL = payUAcsRequest?.issuerUrl
8
customBrowserConfig.payuPostData = payUAcsRequest?.issuerPostData
9
10
}else if (!payUAcsRequest?.acsTemplate.isNullOrEmpty()){
11
customBrowserConfig.htmlData = payUAcsRequest?.acsTemplate
12
}else {
13
//Set the first url to open in WebView
14
customBrowserConfig.postURL = url
15
customBrowserConfig.payuPostData = payuConfig.data
16
}
17
return false
18
}
Copied!
You will get PayUAcsRequest on shouldHandleFallback() callback. whether you will get issuerUrl and issuerPostData or acsTemplate on PayUAcsRequest acsTemplate is the Html string that you need to load to the Webview.
PayUAcsRequest field
Description
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");

Error codes and their description.

1
- ErrorCode: Description
2
3
- 1001 : No Internet
4
5
- 1002 : Network timeout, please verify with your server.
6
7
- 1003 : Gateway timeout, please verify with your server.
8
9
- 1004 : User cancelled it, please verify with your server.
10
11
- 1005 : Something went wrong , please verify with your server.
12
13
- 1006 : Bank page timed out, please verify with your server.
Copied!

Verify the transaction through Webhooks or polling

Once 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.

Implementation of PayU WebHook

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.
Refer to this document, for Webhook implementation.
There is another option to verify payment through polling, the transaction status after the SDK callback from your backend.
Last modified 1mo ago