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.
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.
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.
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.
- 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.
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.
To make the payment, first you need to create UpiConfig and provide mandatory parameters, merchant key and postdata, that we described above.
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.
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
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.