-
Notifications
You must be signed in to change notification settings - Fork 10
Android SDK Integration
Gradle: compile 'com.payu.india:payu-sdk:4.4.8'
IMPORTANT: PayU Android SDK version3.0 is deprecated.We are no longer supporting it.
Before proceeding further with this document make sure that you have read this document
You must already have installed and configured:
- Java JDK version 1.6 or greater
- Android SDK
- A Git client
- Android Studio / Eclipse
- All PayU PG Prerequisites (Key, Salt)
SDK
Sample App (see branches)
Custom Browser
Custom Browser Sample App Without SDK
The PayU Sample App essentially consists of three main components:
-
Native app: Merchants will essentially need to replace the sample app with their own app
-
sdkui module: That is the sample UI used by the above sample app. This is a default UI that is available for use by Merchants
-
Non-Seamless: In case you decide to not build your own UI, you are free to use this module
-
Seamless: In case you need to build your own UI, please go through this module carefully to increase your understanding of how to use SDK’s features
-
PayU SDK module: Consists of all the core sdk components and apis
-
Get all the required parameters
-
Create an object of
PaymentParams
, put all the obtained parameters in it by using its default set methods andsetHash
to paymentHashPaymentParams mPaymentParams = new PaymentParams(); mPaymentParams.setKey(“gtKFFx”); mPaymentParams.setAmount(“15.0”); mPaymentParams.setProductInfo(“Tshirt”); mPaymentParams.setFirstName(“Guru”); mPaymentParams.setEmail(“[email protected]”); mPaymentParams.setTxnId(“0123479543689”); mPaymentParams.setSurl(“https://payu.herokuapp.com/success”); mPaymentParams.setFurl(“https://payu.herokuapp.com/failure"); mPaymentParams.setUdf1(“udf1l”); mPaymentParams.setUdf2(“udf2”); mPaymentParams.setUdf3(“udf3”); mPaymentParams.setUdf4(“udf4”); mPaymentParams.setUdf5(“udf5”); mPaymentParams.setHash("your payment hash");
- You don't need to set udf1-5 in case you are not using them
- Email and Firstname can be empty strings "" if you don't want to use them
- For store user card feature
mPaymentParams.setUserCredentials("your_key:user_id")
, you need to pass user_credentials here- For offers
mPaymentParams.setOfferKey("your_offer_key")
- For any other payment default param (like phone and others)
mPaymentParams.setPhone("your_number")
-
Get the required hashes by using your own server. Create an object of class
PayuHashes
and set the corresponding hashes using the default set methods providedmPaymentParams.setHash(payuHashes.getPaymentHash());
-
Create a new intent pointing to
PayUBaseActivity
and do the following:intent.putExtra(PayuConstants.ENV, PayuConstants.PRODUCTION_ENV); intent.putExtra(PayuConstants.PAYMENT_DEFAULT_PARAMS, mPaymentParams); intent.putExtra(PayuConstants.PAYU_HASHES, payuHashes);
-
Start the activity and let PayU SDK take care of the rest
startActivity(intent);
-
Create an object of
PaymentParams
, put all the obtained parameters in it by using its default set methods in the same way as you will create for the non-seamless style andsetHash
to paymentHash -
Set the following additional properties to
mPaymentParams
mPaymentParams.setCardNumber(cardNumber); mPaymentParams.setCardName(cardName); mPaymentParams.setNameOnCard(cardName); mPaymentParams.setExpiryMonth(expiryMonth);// MM mPaymentParams.setExpiryYear(expiryYear);// YYYY mPaymentParams.setCvv(cvv);
-
Create
PaymentPostParams
object with the above data of the typePostData
. Make sure to set the environment (test or prod), create intent and launch the activity (PaymentsActivity
if you are using PayU's webview)PostData postData = new PaymentPostParams(mPaymentParams, PayuConstants.CC).getPaymentPostParams(); if (postData.getCode() == PayuErrors.NO_ERROR) { // launch webview PayuConfig payuConfig = new PayuConfig(); payuConfig.setEnvironment(PayuConstants.PRODUCTION_ENV); payuConfig.setData(postData.getResult()); Intent intent = new Intent(this,PaymentsActivity.class); intent.putExtra(PayuConstants.PAYU_CONFIG,payuConfig); startActivityForResult(intent, PayuConstants.PAYU_REQUEST_CODE); } else { // something went wrong Toast.makeText(this,postData.getResult(), Toast.LENGTH_LONG).show(); }
-
Create an activity for Webview, in case you are not using PayU's webview activity (PaymentsActivity)
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_payments); // initialize Bundle bundle =getIntent().getExtras(); PayuConfig payuConfig =bundle.getParcelable(PayuConstants.PAYU_CONFIG); WebView mWebView =(WebView) findViewById(R.id.webview); String url =payuConfig.getEnvironment() == PayuConstants.PRODUCTION_ENV ? PayuConstants.PRODUCTION_PAYMENT_URL :PayuConstants.MOBILE_TEST_PAYMENT_URL; byte[] encodedData = EncodingUtils.getBytes(payuConfig.getData(), "base64"); mWebView.postUrl(url,encodedData); mWebView.getSettings().setSupportMultipleWindows(true); mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.getSettings().setDomStorageEnabled(true); mWebView.setWebChromeClient(new WebChromeClient() {}); mWebView.setWebViewClient(new WebViewClient() {}); }
At this point you should be able to see Bank’s 3D Secure page
-
Create an object of
PaymentParams
, put all the obtained parameters in it by using its default set methods in the same way as you will create for the non-seamless style andsetHash
to paymentHash -
Get the bankCode (String) of selected bank from your spinner/list view adapter and add it to the
mPaymentParams
created abovemPaymentParams.setBankCode(bankCode);
-
Create
PaymentPostParams
object of the type PostDataPostData postData = new PaymentPostParams(mPaymentParams, PayuConstants.NB).getPaymentPostParams(); if (postData.getCode() == PayuErrors.NO_ERROR){ // launch webview PayuConfig payuConfig = new PayuConfig(); payuConfig.setEnvironment(PayuConstants.PRODUCTION_ENV); payuConfig.setData(postData.getResult()); Intent intent = new Intent(this,PaymentsActivity.class); intent.putExtra(PayuConstants.PAYU_CONFIG,payuConfig); startActivityForResult(intent, PayuConstants.PAYU_REQUEST_CODE); } else { // something went wrong Toast.makeText(this,postData.getResult(), Toast.LENGTH_LONG).show(); }
-
Create an activity for Webview just like for CC
-
Create an object of
PaymentParams
, put all the obtained parameters in it by using its default set methods in the same way as you will create for the non-seamless style andsetHash
to paymentHash -
Get the bankCode (String) of selected cash card from your spinner/list view adapter and add it to the
mPaymentParams
created abovemPaymentParams.setBankCode(bankCode);
-
Create
PaymentPostParams
object of the type PostDataPostData postData = new PaymentPostParams(mPaymentParams, PayuConstants.CASH).getPaymentPostParams(); if (postData.getCode() == PayuErrors.NO_ERROR){ // launch webview PayuConfig payuConfig = new PayuConfig(); payuConfig.setEnvironment(PayuConstants.PRODUCTION_ENV); payuConfig.setData(postData.getResult()); Intent intent = new Intent(this,PaymentsActivity.class); intent.putExtra(PayuConstants.PAYU_CONFIG,payuConfig); startActivityForResult(intent, PayuConstants.PAYU_REQUEST_CODE); } else { // something went wrong Toast.makeText(this,postData.getResult(), Toast.LENGTH_LONG).show(); }
-
Create an activity for Webview just like for CC
-
Create an object of
PaymentParams
, put all the obtained parameters in it by using its default set methods in the same way as you will create for the non-seamless style andsetHash
to paymentHash -
Set the following additional properties to
mPaymentParams
mPaymentParams.setCardToken(cardToken); mPaymentParams.setCvv(cvv); mPaymentParams.setNameOnCard(cardName); mPaymentParams.setExpiryMonth(expiryMonth);// MM mPaymentParams.setExpiryYear(expiryYear);// YYYY mPaymentParams.setCardName(storedCard.getCardName());
-
Create
PaymentPostParams
object with the above data of the typePostData
. Make sure to set the environment (test or prod), create intent and launch the activity (PaymentsActivity
if you are using PayU's webview)PostData postData = new PaymentPostParams(mPaymentParams, PayuConstants.CC).getPaymentPostParams(); if (postData.getCode() == PayuErrors.NO_ERROR) { // launch webview PayuConfig payuConfig = new PayuConfig(); payuConfig.setEnvironment(PayuConstants.PRODUCTION_ENV); payuConfig.setData(postData.getResult()); Intent intent = new Intent(this,PaymentsActivity.class); intent.putExtra(PayuConstants.PAYU_CONFIG,payuConfig); startActivityForResult(intent, PayuConstants.PAYU_REQUEST_CODE); } else { // something went wrong Toast.makeText(this,postData.getResult(), Toast.LENGTH_LONG).show(); }
-
Create an activity for Webview just like for CC
-
Create
PaymentPostParams
object with the above data of the typePostData
. Make sure to set the environment (test or prod), create intent and launch the activity (PaymentsActivity
if you are using PayU's webview)PostData postData = new PaymentPostParams(mPaymentParams, PayuConstants.CC).getPaymentPostParams(); if (postData.getCode() == PayuErrors.NO_ERROR) { // launch webview PayuConfig payuConfig = new PayuConfig(); payuConfig.setEnvironment(PayuConstants.PRODUCTION_ENV); payuConfig.setData(postData.getResult()); Intent intent = new Intent(this,PaymentsActivity.class); intent.putExtra(PayuConstants.PAYU_CONFIG,payuConfig); startActivityForResult(intent, PayuConstants.PAYU_REQUEST_CODE); } else { // something went wrong Toast.makeText(this,postData.getResult(), Toast.LENGTH_LONG).show(); }
-
Create an activity for Webview just like for CC
-
Create an object of
PaymentParams
, put all the obtained parameters in it by using its default set methods in the same way as you will create for the non-seamless style andsetHash
to paymentHash -
Create PaymentPostParams object of the type PostData
PostData postData = new PaymentPostParams(mPaymentParams, PayuConstants.PAYU_MONEY).getPaymentPostParams(); if (postData.getCode() == PayuErrors.NO_ERROR){ // launch webview // launch webview PayuConfig payuConfig = new PayuConfig(); payuConfig.setEnvironment(PayuConstants.PRODUCTION_ENV); payuConfig.setData(postData.getResult()); Intent intent = new Intent(this,PaymentsActivity.class); intent.putExtra(PayuConstants.PAYU_CONFIG,payuConfig); startActivityForResult(intent, PayuConstants.PAYU_REQUEST_CODE); } else { // something went wrong Toast.makeText(this,postData.getResult(), Toast.LENGTH_LONG).show(); }
- Enable UPI as payment option in merchant panel
- Merchant Key
- Merchant salt
- User Credential
1-Initialise PayuConfig with environment to test
2-Initialize MerchantWebService with mentioned data points
MerchantWebService merchantWebService = new MerchantWebService();
merchantWebService.setKey(merchantKey); // Merchant key
merchantWebService.setCommand(PayuConstants.PAYMENT_RELATED_DETAILS_FOR_MOBILE_SDK); // Command for fetching payment related details
merchantWebService.setVar1(userCredential) // User Credential of the merchant
merchantWebService.setHash(paymentRelatedHash) //Hash for fetching payment related details such as payment options
3-Fetch PostData
PostData postData = new MerchantWebServicePostParams(merchantWebService).getMerchantWebServicePostParams();
if (postData.getCode() == PayuErrors.NO_ERROR) {
payuConfig.setData(postData.getResult());
}
Note: If PostData has no error - you are good to go else please check the data point set in merchantWebService
4-Make an object GetPaymentRelatedDetailsTask
GetPaymentRelatedDetailsTask paymentRelatedDetailsForMobileSdkTask = new GetPaymentRelatedDetailsTask(this);
//where ,
//Input param (this) is the instance of class which implements PaymentRelatedDetailsListener
//‘PaymentRelatedDetailsListener’ is interface with abstract method, which is
//public void onPaymentRelatedDetailsResponse(PayuResponse payuResponse)
5-Once you call ‘execute’, the GetPaymentRelatedDetailsTask, ‘onPaymentRelated Details Response’ callback is called
@Override
public void onPaymentRelatedDetailsResponse(PayuResponse payuResponse) {
mPayuResponse = payuResponse;
// Check if UPI as payment option available.
if(payuResponse.isUpiAvailable()){
// UPI as payment option is available
}
}
1-Initialize PaymentParams with mentioned data points
PaymentParams mPaymentParams = new PaymentParams();
mPaymentParams.setKey(merchantKey)
mPaymentParams.setAmount(amount)
mPaymentParams.setProductInfo(productInfo)
mPaymentParams.setFirstName(firstName)
mPaymentParams.setEmail(emailId)
mPaymentParams.setTxnId(transactionID)
mPaymentParams.setSurl(surl) // Success URL
mPaymentParams.setFurl(furl) // Failure URL
mPaymentParams.setUdf1(udf1)
mPaymentParams.setUdf2(udf2)
mPaymentParams.setUdf3(udf3)
mPaymentParams.setUdf4(udf4)
mPaymentParams.setHash(paymentHash); // Payment Hash for making payment
mPaymentParams.setUdf5(udf5)
mPaymentParams.setVpa(virtualAddress) // Virtual address (must for UPI payment)
Note: Validations for virtual address
a.Vpa length should be less than or equal to 50
b.Regex for VPA : value.match(/^([A-Za-z0-9.])+@[A-Za-z0-9]+$/)
2-Fetch PostData
PostData mPostData = new PaymentPostParams(mPaymentParams, PayuConstants.UPI).getPaymentPostParams();
if (mPostData.getCode() == PayuErrors.NO_ERROR) {
payuConfig.setData(mPostData.getResult());
}
Note: If mPostData contain no error you are good to go else check PaymentParams
3-Post data to PayU
webview.postUrl(url, payuConfig.getData().getBytes());
//where, url - PayU Payment URL
NOTE: Refer this link for surl-furl implementation to understand more why onSuccess JS interface is needed.
- Create an activity for Webview just like for CC
- Enable Tez as payment option in merchant panel
- Merchant Key
- Merchant salt
- User Credential
1-Initialise PayuConfig with environment to test
2-Initialize MerchantWebService with mentioned data points
MerchantWebService merchantWebService = new MerchantWebService();
merchantWebService.setKey(merchantKey); // Merchant key
merchantWebService.setCommand(PayuConstants.PAYMENT_RELATED_DETAILS_FOR_MOBILE_SDK); // Command for fetching payment related details
merchantWebService.setVar1(userCredential) // User Credential of the merchant
merchantWebService.setHash(paymentRelatedHash) //Hash for fetching payment related details such as payment options
3-Fetch PostData
PostData postData = new MerchantWebServicePostParams(merchantWebService).getMerchantWebServicePostParams();
if (postData.getCode() == PayuErrors.NO_ERROR) {
payuConfig.setData(postData.getResult());
}
Note: If PostData has no error - you are good to go else please check the data point set in merchantWebService
4-Make an object GetPaymentRelatedDetailsTask
GetPaymentRelatedDetailsTask paymentRelatedDetailsForMobileSdkTask = new GetPaymentRelatedDetailsTask(this);
//where ,
//Input param (this) is the instance of class which implements PaymentRelatedDetailsListener
//‘PaymentRelatedDetailsListener’ is interface with abstract method, which is
//public void onPaymentRelatedDetailsResponse(PayuResponse payuResponse)
5-Once you call ‘execute’, the GetPaymentRelatedDetailsTask, ‘onPaymentRelated Details Response’ callback is called
@Override
public void onPaymentRelatedDetailsResponse(PayuResponse payuResponse) {
mPayuResponse = payuResponse;
// Check if Tez as payment option available.
if(payuResponse.isGoogleTezAvailable()){
// Tez as payment option is available
}
}
1-Initialize PaymentParams with mentioned data points
PaymentParams mPaymentParams = new PaymentParams();
mPaymentParams.setKey(merchantKey)
mPaymentParams.setAmount(amount)
mPaymentParams.setProductInfo(productInfo)
mPaymentParams.setFirstName(firstName)
mPaymentParams.setEmail(emailId)
mPaymentParams.setTxnId(transactionID)
mPaymentParams.setSurl(surl) // Success URL
mPaymentParams.setFurl(furl) // Failure URL
mPaymentParams.setUdf1(udf1)
mPaymentParams.setUdf2(udf2)
mPaymentParams.setUdf3(udf3)
mPaymentParams.setUdf4(udf4)
mPaymentParams.setHash(paymentHash); // Payment Hash for making payment
mPaymentParams.setUdf5(udf5)
mPaymentParams.setVpa(virtualAddress) // Tez Virtual address (Optional if set address will be auto populated on payment screen)
2-Fetch PostData
PostData mPostData = new PaymentPostParams(mPaymentParams, PayuConstants.TEZ).getPaymentPostParams();
if (mPostData.getCode() == PayuErrors.NO_ERROR) {
payuConfig.setData(mPostData.getResult());
}
Note: If mPostData contain no error you are good to go else check PaymentParams
3-Post data to PayU
webview.postUrl(url, payuConfig.getData().getBytes());
//where, url - PayU Payment URL
NOTE: Refer this link for surl-furl implementation to understand more why onSuccess JS interface is needed.
- Create an activity for Webview just like for CC
1- Payment Related Details
PhonePe Intent is returned as payment option, when it is enabled from merchant panel, in onPaymentRelatedDetailsResponse(PayuResponse payuResponse)
1.1) Check Availability of PhonePe Intent - (Optional)
Method - isPhonePeIntentAvailable()
Return: true – PhonePe Intent is enabled
false – PhonePe Intent is disable
Example: payuResponse.isPhonePeIntentAvailable()
1.2) Get Post Data for PhonePe Intent
Create PaymentPostParams object with the above data(similar to other payment options) of the type PostData
PostData mPostData = new PaymentPostParams(mPaymentParams,PayuConstants.PHONEPE_INTENT).getPaymentPostParams();
1- Payment Related Details
LazyPay is returned as payment option, when it is enabled from merchant panel, in onPaymentRelatedDetailsResponse(PayuResponse payuResponse)
1.1) Check Availability of LazyPay - (Optional)
Method - isLazyPayAvailable()
Return: true – LazyPay is enabled
false – LazyPay is disable
Example: payuResponse. isLazyPayAvailable()
1.2) payuResponse.getLazyPay(): Return LazyPay list which contain description about lazy pay.
2- Payment Params for LazyPay
2.1) Notify Url – Callback URL of merchant where a notification of transaction status will be sent on completion of transaction. It should be HTTPS.
-
Get all the required parameters
-
Create an object of PaymentParams
PaymentParams mPaymentParams = new PaymentParams(); // set other payment params in mPaymentParams
mPaymentParams.setNotifyURL(mPaymentParams.getSurl());
2.2) Get Post Data for LazyPay
Create PaymentPostParams object with the above data of the type PostData
PostData mPostData = new PaymentPostParams(mPaymentParams, PayuConstants.LAZYPAY).getPaymentPostParams();
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
- SDKs Overview
- Server Side
- Client Side
- Android SDK Integration
- Android Custom Browser
- Android Samsung Pay SDK integration
- Android PhonePe Intent SDK integration
- Android Google Pay™ SDK Integration
- Android PayU CheckoutPro SDK Integration
- IOS PayU CheckoutPro SDK Integration
- iOS integration with PayU Checkout UI
- iOS SDK integration
- iOS Custom Browser
- Mobile Releases
- FAQs
- Common Issues