SDK Integration
  • Getting Started
  • Onboarding Requirements
  • Hash Generation
  • Test Merchant list
  • Android
    • Android SDK Offering
    • PayUCheckoutPro
      • Integration
      • Build the Payment Params
        • Additional Params
      • Hash Generation
      • Set up the payment hashes
      • Initiate the Payment
      • Customized Integration
        • Set Webview Properties
        • SDK Configuration
        • Additional Offerings
      • Offers Integration
      • Convenience Fee Integration
      • Custom Note Integration
      • MCP Integration
    • Core
      • Supported Payment Types
      • TPV Integration
      • Merchant Web Services
        • Getting Enabled Payment Options
        • GetCheckoutDetails API
        • Lookup API
    • Custom Browser
      • Integration
        • CustomBrowser Config
        • CustomBrowserCallback
        • Supporting below Lollipop Versions
        • Third-Party Payments Support
      • Sample App
      • Change Logs
    • Native OTP Assist
      • Integration
      • Customization
      • Change Logs
    • UPI
      • Integration
      • TPV Integration in UPI
      • Sample App
      • Change Logs
    • Google Pay™
      • Integration
      • Sample App
    • PhonePe
      • Integration
      • Sample App
      • Change Logs
    • OlaMoney
    • PayU OTP Parser
      • Integration
    • FAQ Android
  • iOS
    • PayUCheckoutPro
      • Integration
      • Advanced Integration
      • Set up the payment hashes
      • Convenience Fee Integration
      • MCP Integration
      • Custom Note Integration
    • Core
      • POD Integration
      • Seamless
      • Web Services
      • Objective C-Non-Seamless
      • Standing Instructions
      • TPV Integration
      • Sample App
    • Custom Browser
      • Sample App
    • OlaMoney
    • Native OTP Assist
      • Integration
      • Customization
    • UPI
      • Integration
      • Sample App
    • PayUParams
      • PayUSIParams
      • PayUBeneficiaryParams
  • Releasing to Apple
  • React-Native
    • PayUCheckoutPro
      • Integration
      • Set up the payment hashes
      • Advanced Integration
      • Change Logs
    • Core
    • Non-Seamless Wrapper
    • TPV (beta)
      • Integration
  • FAQ iOS
Powered by GitBook
On this page
  • Onboarding Requirements
  • Gradle Dependency
  • Generate Payment Hash
  • Payment Request Post Data
  • Set up for Test/Sandbox Merchant
  • Payment Options
  • Dependency for PhonePe
  • Dependency for Google pay
  • Dependency for Samsung pay
  • Callbacks
  • Make Payment
  • Make Intent Payment by Specific App
  • Disable Manual VPA Fallback Option from Generic Intent Tray
  • VPA Validation
  • Verify the transaction through Webhooks or polling
  • Implementation of PayU WebHook
  • Staging Environment Configurations

Was this helpful?

  1. Android
  2. UPI

Integration

PayU UPI SDK Integration

PreviousUPINextTPV Integration in UPI

Last updated 3 years ago

Was this helpful?

Onboarding Requirements

To start transacting through Google Pay, please register yourself on Google Pay using the following , 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 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 .

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

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

Generate Payment 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.

Post Data can be generated by using


        PaymentParamsUpiSdk mPaymentParamsUpiSdk = new PaymentParamsUpiSdk();
        mPaymentParamsUpiSdk.setKey(inputData); //Your Merchant Key

        mPaymentParamsUpiSdk.setProductInfo("product info");
        mPaymentParamsUpiSdk.setFirstName("first name"); //Customer First name
        mPaymentParamsUpiSdk.setEmail("email"); //Customer Email
        mPaymentParamsUpiSdk.setTxnId("txnId"); //Your transaction id
        mPaymentParamsUpiSdk.setAmount("Transaction Amount"); //Your transaction Amount(In Double as String)
        mPaymentParamsUpiSdk.setSurl("success url");
        mPaymentParamsUpiSdk.setFurl("failure url");
        mPaymentParamsUpiSdk.setUdf1("udf1");
        mPaymentParamsUpiSdk.setUdf2("udf2");
        mPaymentParamsUpiSdk.setUdf3("udf3");
        mPaymentParamsUpiSdk.setUdf4("udf4");
        mPaymentParamsUpiSdk.setUdf5("udf5");
        mPaymentParamsUpiSdk.setVpa("vpa"); //In case of UPI Collect set customer vpa here
        mPaymentParamsUpiSdk.setUserCredentials("user credentials");
        mPaymentParamsUpiSdk.setOfferKey("offer key");
        mPaymentParamsUpiSdk.setPhone("phone number");//Customer Phone Number
        mPaymentParamsUpiSdk.setHash("hash");//Your Payment Hash

        String postDataFromUpiSdk = new PostDataGenerate.PostDataBuilder(this).
                setPaymentMode(UpiConstant.UPI).setPaymentParamUpiSdk(mPaymentParamsUpiSdk).
                build().toString();
 /**
     * Callback of payment availability while doing through UPISDK.
     */
    PayUUPICallback payUUpiSdkCallback = new PayUUPICallback() {

        @Override
        public void isPaymentOptionAvailable(boolean isAvailable, PaymentOption paymentOption) {
            super.isPaymentOptionAvailable(isAvailable, paymentOption);
            switch (paymentOption) {
                case PHONEPE:
                   //check whether you show Phonepe or not using isAvailable.
                    break;
                case SAMSUNGPAY:
                 //check whether you show Samsung Pay or not using isAvailable
                    break;
            }
        }
    };
 //Checking the payment availability for PHONEPE, SAMSUNGPAY and Google Pay.
 // It will return the availability on payUUpiSdkCallback isPaymentOptionAvailable() method.
   Upi upi = Upi.getInstance();
        upi.checkForPaymentAvailability(this, PaymentOption.PHONEPE, payUUpiSdkCallback, mPayUHashes.getPaymentRelatedDetailsForMobileSdkHash(), mPaymentParamsUpiSdk.getKey(), mPaymentParamsUpiSdk.getUserCredentials());
        upi.checkForPaymentAvailability(this, PaymentOption.SAMSUNGPAY, payUUpiSdkCallback, mPayUHashes.getPaymentRelatedDetailsForMobileSdkHash(), mPaymentParamsUpiSdk.getKey(), mPaymentParamsUpiSdk.getUserCredentials());
        upi.checkForPaymentAvailability(this, PaymentOption.TEZ, payUUpiSdkCallback, mPayUHashes.getPaymentRelatedDetailsForMobileSdkHash(), mPaymentParamsUpiSdk.getKey(), mPaymentParamsUpiSdk.getUserCredentials());

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.

    <application
    <meta-data
        android:name="payu_web_service_url"
        android:value="https://test.payu.in" />

    <meta-data
        android:name="payu_post_url"
        android:value="https://test.payu.in" />

</application>

Payment Options

Following Payment Options are currently supported by UPI sdk.

PaymentOption.PHONEPE: Payment using PhonePe
PaymentOption.SAMSUNGPAY: Payment using Samsung pay.
PaymentOption.TEZ: Payment using Google Pay.
PaymentOption.UPI_INTENT: Payment using UPI apps installed on device.i,e, Intent flow..
PaymentOption.UPI_COLLECT: UPI payment through web flow.

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:

allprojects {
    repositories {
        maven {
            url "https://phonepe.mycloudrepo.io/public/repositories/phonepe-intentsdk-android"
        }
    }
}

Add below dependency to project build.gradle

implementation 'in.payu:phonepe-intent:1.6.0'

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

implementation 'in.payu:payu-gpay:1.4.0'

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

implementation 'com.payu.samsungpay:samsungpay:1.0'

Generate Postdata Using upi-sdk

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.

    - Error Codes      : Error messages 
    
    - 1                : VENDOR_NOT_SUPPORTED   // Device Vendor is not supported
    - 2                : DEVICE_NOT_SUPPORTED   // Device is not supported 
    - 3                : APP_VERSION_MISMATCH   // Samsung Pay version doesn't meet requirements 
    - 4                : COUNTRY_NOT_SUPPORTED  // Country of device origin is not supported by Samsung Pay 
    - 5                : MERCHANT_KEY_NOT_REGISTER_FOR_SAMSUNG_PAY        // Merchant is not registered for 
                                                                             Samsung Pay with PayU 
    - 6                : CONTEXT_NULL           // Context is null
    - 7                : PAYMENT_ID_NOT_PRESENT // Check your postdata

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

    - code        : 1002 
    - errormsg    : MERCHANT_INFO_NOT_PRESENT 
    - code        : 1004
    - errormsg    : INVOKING_APP_NOT_INSTALLED_CODE //Selected app is not installed on device.
    - code        : 1005
    - errormsg    : INVOKING_APP_NOT_ONBOARDED_CODE //Uses has not onboarded on UPI on selected application
  • 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.

        PayUUPICallback payUUpiSdkCallbackUpiSdk = new PayUUPICallback() {
        @Override
        public void onPaymentFailure(String payuResult, String merchantResponse) {
            super.onPaymentFailure(payuResult, merchantResponse);

         //Payment failed
        }
        @Override
        public void onPaymentSuccess(String payuResult, String merchantResponse) {
            super.onPaymentSuccess(payuResult, merchantResponse);
            //Payment succeed
        }

        @Override
        public void onVpaEntered(String vpa, IValidityCheck iValidityCheck) {
            super.onVpaEntered(vpa, iValidityCheck);
            String input = "payu merchant key" + "|validateVPA|" + vpa + "|" + "payu merchant salt";
            iValidityCheck.verifyVpa(calculateHash(input));
        }

        @Override
        public void onUpiErrorReceived(int code, String errormsg) {
            super.onUpiErrorReceived(code, errormsg);
          //Any error on upisdk
        }

        };

Make Payment

  UpiConfig upiConfig = new UpiConfig();
  upiConfig.setMerchantKey("merchant key");
  upiConfig.setPayuPostData("postdata");// that we generate above
  //In order to set CustomProgress View use below settings
  upiConfig.setProgressDialogCustomView(<Custom Progress Dialog View>);

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.

upiConfig.setPackageNameForSpecificApp("<UPI_PACKAGE_ID>");
where UPI_PACKAGE_ID can be any of UPI apps like - 
com.phonepe.app(PhonePe),
com.google.android.apps.nbu.paisa.user(GPay) etc.

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.

upiConfig.setDisableIntentSeamlessFailure(UpiConfig.FALSE/UpiConfig.TRUE);

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

Upi upi = Upi.getInstance();
upi.makePayment(payUUpiSdkCallbackUpiSdk, activity, upiConfig);
upiConfig.setGmsProviderUpdatedStatus(UpiConfig.DISABLE/UpiConfig.ENABLE);

VPA Validation

sha512(key|command|var1|salt)
where
key=YOUR KEY
command=validateVPA
salt= YOUR SALT
var1= the vpa, you want to validate

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.

Upi upi = Upi.getInstance();
upi.getCommandResponse(Activity, postdata, PayUUPICallback);

Create postdata for VPA validation

String postData= "key=" + Your Key + "&var1=" + {VPA for validation} + "&command=validateVPA&" + "hash=" + {Hash you generated above}

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

PayUCommandResponse Sample

{"status":"SUCCESS",
"vpa":"VPA you are validating",
"isVPAValid":1, //It will be 0(Invalid) or 1(Valid)
"payerAccountName":"Payer Name corresponding to the VPA"}

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.

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.

<meta-data android:name="payu_debug_mode_enabled" android:value="true" />
<meta-data android:name="payu_web_service_url" android:value="https://test.payu.in" />
<meta-data android:name="payu_post_url" android:value="https://test.payu.in" />

Refer this document, to generate the hash.

By using library.

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

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 .

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

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

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

Refer to this , for Webhook implementation.

There is another option to through polling, the transaction status after the SDK callback from your backend.

Google Onboarding
Merged Manifest view
document
Gradle doc
PG Sdk
SDK Integration
detail
document
verify payment
above
Generate Hash
here
here