Integration

PayU UPI SDK Integration

Onboarding Requirements

To start transacting through Google Pay, please register yourself on Google Pay using the following Google Onboarding, In this registration process please add the Merchant VPA Ids created by PayU for you. In the case of multiple VPAs, all of them needs to be registered. For any queries regarding the same, drop an email to "mobile.integration@payu.in" team and we will get back to you.

Gradle Dependency

Adding the PayU Upi SDK (available at Maven Central)is a fairly straight forward process:

 implementation 'in.payu:upisdk:1.5.3'

If you are getting the below compile error.

Android resource linking failed /Users/sample/AndroidStudioProjects/MyApp/app/build/intermediates/merged_manifests/debug/AndroidManifest.xml:18: error: unexpected element found in <manifest>

Manifest merger failed with multiple errors, see logs Upon expanding the Merged Manifest view you would then see an additional error: Error: Missing 'package' key attribute on element package

It means you need to fix your Gradle plugin, refer to this document.

As UPI sdk is compiled on sdk version 29 with androidx support , it might happen that your app and SDK have common dependencies that lead to compile-time errors due to the duplicity of classes.

In such cases, you need to define resolutionStrategy on your project/App's build.gradle. For more details, Gradle doc.

configurations.all {
    resolutionStrategy {
        force "path of conflicting library 1"
        force "path of conflicting library 2"
        ...
    }
}

Generate Payment Hash

Refer this document, Generate Hash to generate the 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 Request Post Data

Ways to generate Postdata:

  • By UPI SDK itself - recommended if using UPI SDK alone.

  • By using PG Sdk library.

Post Data can be generated by using

Set up for Test/Sandbox Merchant

If you are using the SDK with a test merchant, please provide this metadata value to the manifest file else removed these lines below.

Payment Options

Following Payment Options are currently supported by UPI sdk.

Dependency for PhonePe

To make payment through PhonePe, you must have to add payu phonepe dependency.

Gradle

Add below url in root project build.gradle:

Add below dependency to project build.gradle

Dependency for Google pay

To make payment through Google Pay, you must have to add PayU Google Pay dependency.

Gradle

Add below dependency to project build.gradle

Dependency for Samsung pay

To make payment through Samsung Pay, you must have to add payu samsung pay dependency.

Gradle

Add below dependency to project build.gradle

Generate Postdata Using upi-sdk

Refer this document, SDK Integration, Refer PaymentPostParams class to generate Postdata.

Once you check the payment the availability of Payment, you could go ahead to make the payment.

Callbacks

  • onPaymentFailure(String payuResult,String merchantResponse) - Calls when payment fails.

  • onPaymentSuccess(String payuResult,String merchantResponse) - Calls when payment succeeds.

  • onUpiErrorReceived(int errorCode,String errorMessage) - Called for error on UPI SDK where,

    Following are error messages w.r.t. Samsung Pay initialisation failure.

    In case below error is received while processing payment please check your Payment Post Data/ Payment hash

  • isPaymentOptionAvailable(boolean isAvailable, PaymentOption paymentOption) Merchant must check for Samsung Pay/PhonePe payment option availability on the customer device before showing Samsung Pay/PhonePe as payment option on their checkout page.

  • onVpaEntered(String vpa, IValidityCheck iValidityCheck) For Generic Intent, we need to calculate validateVpahash using vpa and provide to verifyVpa method of iValidityCheck. Hash can be calculated using webservice command "validateVpa" as mentioned here.

Make Payment

To make the payment, first you need to create UpiConfig and provide mandatory parameters, merchant key and postdata, that we described above.

Make Intent Payment by Specific App

In order to make Intent Payment by Specific UPI app kindly set the desired name of UPI app in upiConfig object as below.

Disable Manual VPA Fallback Option from Generic Intent Tray

You can disable the Manual VPA Fallback option from Generic Intent tray from backend as well as from frontend.

In order to disable it from front end, set UpiConfig.TRUE to setDisableIntentSeamlessFailure flag of UpiConfig.

Provide the PayUUPICallback instance and Upiconfig object to Upi makepayment() method.

For Device API Level 19, You must enable Gms provider service and set gmsProviderUpdatedStatus of UpiConfig below. For more detail.

VPA Validation

You can validate a VPA of its own using the SDK. You need to create a hash through this below command. Hash can be calculated using Webservice command "validateVpa" as mentioned here

This feature available from UPI SDK version >=1.2.0

After creating the hash, you need to call getCommandResponse() method of Upi with the postdata.

Create postdata for VPA validation

You will get the response to onCommandResponse(String payUCommandResponse, String command) of PayUUPICallback.

PayUCommandResponse Sample

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.

Staging Environment Configurations

To Test on Staging Environment(test.payu.in) use your Staging Env. merchant key and salt and add below configurations in your application manifest.

Last updated

Was this helpful?