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.

Include the SDK in your app build.gradle

implementation 'com.payu.india:native-otp-assist:1.0.0'

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
Java
PayUOtpAssistConfig payUOtpAssistConfig = PayUOtpAssistConfig();
payUOtpAssistConfig.setPostData("POST_DATA_FOR_TRANSACTION");
PayUOtpAssist.open(
Context context,
PayUOtpAssistCallback payUOtpAssistCallback,
PayUOtpAssistConfig payUOtpAssistConfig)
Kotlin
val payUOtpAssistConfig = PayUOtpAssistConfig()
payUOtpAssistConfig.postData = "POST_DATA_FOR_TRANSACTION"
PayUOtpAssist.open(
context: Context,
payUOtpAssistCallback: PayUOtpAssistCallback,
payUOtpAssistConfig: PayUOtpAssistConfig)

Make sure to add internet permission in your manifest file.

<uses-permission android:name="android.permission.INTERNET" />

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

- ErrorCode: Description
- 1001 : No Internet
- 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 : Bank page timed out, please verify with your server.

Verify the transaction

Once you get the response from SDK, make sure to confirm it with the PayU server. It is recommended to implement the PayU backend verify call from your backend.

Implementation of PayU verify API

Since you already have the txnID (Order ID generated at your end) value for such cases, you simply need to execute the verify_payment API with the necessary input parameters.

The output would return you the transaction status in "status" key and various other parameters also.

Url: https://info.payu.in/merchant/postservice.php?form=2

curl --location --request POST '{{Url}}' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'key={merchantKey}' \
--data-urlencode 'command=verify_payment' \
--data-urlencode 'hash=c6febddfaaf6986dd8bd982d3769f856ab149e4de92dbad995c8df808ffcfbcb2c227a3fae38b69eb39ad7b6ce4e06e6b12289f70cc500cea5a2cda449c7dcba' \
--data-urlencode 'var1=Txn1234'

var1:

Parameter

Description

Sample Value

var1

In this parameter, you can put all the txnid(Your transaction ID/order ID) values in a pipe separated form.

100123|100124|100125

command

This parameter must have the name of the web-service.

It must be verify_payment

key

Its the merchant key that PayU provided you.

hash

This parameter must contain the hash value to be calculated at your end. The string used for calculating the hash is mentioned below: sha512(key|command|var1|salt) sha512 is the encryption method used here.

c6febddfaaf6986dd8bd982d3769f856ab149e4de92dbad995c8df808ffcfbcb2c227a3fae38b69eb39ad7b6ce4e06e6b12289f70cc500cea5a2cda449c7dcba