Android SDK

Accept mobile payments in any Android App using our native Android SDK. With our mobile SDKs, you do not need to worry about PCI DSS compliance by eliminating the need to send card data to your server. Instead, our libraries send the card data directly to PayU servers which are PCI-DSS Compliant. The PayUmoney mobile SDKs ensure strong encryption and data security to ensure complete peace of mind to your users.

Have a look at the animated image below to understand payment collection through PayUmoney Plug & Play Android SDK.

This integration guide will assist you in integrating with the PayUmoney Android SDK and the PayUmoney Plug n Play module to provide a complete payment experience to your users.

Features Supported

The following features are supported in the PayUmoney Plug and Play Android SDK.

  • Saved Cards
  • Auto-OTP Read and Entry
  • Multiple Payment methods
  • Ready to use Payment UI

  • Seamless login to PayUmoney accounts

Payment Modes Supported

The following payment modes are supported in the PayUmoney Plug and Play Android SDK.

Steps to Integrate

1

Prerequisites

Meet the Prerequisites

2

Set up the SDK

Import and configure the PayUmoney PnP SDK

3

Server Side Changes

Calculate the security hash value on your server

4

Set Payments Parameters

Provide details of customer and transaction to the SDK

5

Set the hash

Build Payment Parameters and set the server computed hash

6

Start the Payment Flow

Invoke the function to open the checkout page

7

Response Handling

Verify response hash and display transaction status to the customer

Getting Started with the Android SDK

This guide will take you through building your app's payment flow using the PayUmoney Android SDK. The SDK handles collection, storage, and reuse of your user's payment details, and can also be used to collect billing info. Have a look at the Android SDK Payment Activity Diagram before you take the deep dive.

Steps to Integrate

1

Prerequisites

Meet the Prerequisites

2

Set up the SDK

Import and configure the PayUmoney PnP SDK

3

Server Side Changes

Calculate the security hash value on your server

4

Set Payments Parameters

Provide details of customer and transaction to the SDK

5

Set the hash

Build Payment Parameters and set the server computed hash

6

Start the Payment Flow

Invoke the function to open the checkout page

7

Response Handling

Verify response hash and display transaction status to the customer

Prerequisites

  • Sign up with PayUmoney as merchant
  • Get the Merchant Id,Key and Salt, which are available on your merchant dashboard

Selecting the right SDK

The PayUmoney SDK provides a set of optional modules that provide several additional features during Payment Acceptance. Based on your needs, please select the appropriate modules to enhance your user’s payment experience:

  • PayUmoney Core SDK (Mandatory) - This is the base SDK required to accept payments in your app. The Core SDK is mandatorily required. All other modules are optional and work on top of the Core SDK.
  • PayUmoney PnP Module: The PayUmoney PnP (Plug n Play) module provides a rich and well-designed set of ready to use screens that provide a superior payment experience to your users. The PnP module works on top of the PayUmoney Core SDK and allows you to provide multiple payment methods to your users with minimal effort.
  • PayU Custom Browser: The Custom Browser (CB) provides OTP assist features such as auto read of OTP, entry, and submission in the Bank’s 2-Factor authentication page.
Note:
The Core SDK does not contain User Interfaces for accepting payments. If only the Core SDK is used, you must create the UI for displaying the checkout form and the subsequent payment information entry. Please use the PnP module if want a ready-to-use set of checkout UI experiences. To integrate with the Core SDK, please visit the PayUmoney Core SDK Integration Guide.

Setting up the PnP SDK

To import and configure the PayUmoney SDK in your project, please implement the following changes in your app:

Import PayUmoney SDK as a Gradle Dependency

In your project’s build.gradle file, please add the PayUmoney Plug and Play (PnP) SDK module as a dependency by adding the following line:

compile('com.payumoney.sdkui:plug-n-play:1.0.0'){
    transitive = true;
    exclude module: 'payumoney-sdk'
}
compile 'com.payumoney.core:payumoney-sdk:7.0.1'

For reference, please see the screenshot below:

Dependencies

The image given above is for representational purpose only.

Calculate Server-Side Hash

The only server side change required while integrating PayUmoney Android SDK is generating a hash parameter for both the payment request & response.

A hash is an encrypted value (checksum) that must be sent by the merchant in a payment request that is then sent back by PayUmoney in the payment response. A hash is used to protect transactions against “man in the middle” attacks.

Hash Generation for Payment Request

Use the following sample java sequence to generate a request hash.

String hashSequence = key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5||||||salt;
String serverCalculatedHash= hashCal("SHA-512", hashSequence);

Sample Java Request Hash Generation Code

String hashSequence = key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5||||||salt;
public static String hashCal(String type, String hashString) {
	StringBuilder hash = new StringBuilder();
	MessageDigest messageDigest = null;
	try {
		messageDigest = MessageDigest.getInstance(type);
		messageDigest.update(hashString.getBytes());
		byte[] mdbytes = messageDigest.digest();
		for (byte hashByte : mdbytes) {
			 hash.append(Integer.toString((hashByte & 0xff) + 0x100, 16).substring(1));
		}
	} catch (NoSuchAlgorithmException e) {
		e.printStackTrace();
	}
	return hash.toString();
}

Hash Generation for Payment Response

$responseHashSeq = $salt.'|'.$status.'|udf1|udf2|||||'.$email.'|'.$firstname.'|'.$productinfo.'|'.$amount.'|'.$txnid.'|'.$key;
$hash = hash("sha512", $respnsseHashSeq);
Note:
The entire hash logic is built on the assumption 'Salt' is always safe with the merchant. Hence, it is very important for the merchant to keep the 'Salt' safe by adhering to the best security practices. For eg: Merchant should always compute from the server side and never from the client side, should never share the 'Salt' & 'Key' over emails or directly commit on public repositories like Github.

Set Payments Params

To start using the PayUmoney PnP SDK, you need you initialize the SDK by providing details about the customer and the transaction. Please use the sample code provided below to setup the SDK initializer.

The ‘udf’ fields below stand for ‘user defined field’. These are optional fields to pass custom information about the transaction to PayUmoney. You may pass up to 5 UDF fields.

PayUmoneySdkInitializer.PaymentParam.Builder builder = new
PayUmoneySdkInitializer.PaymentParam.Builder();
builder.setAmount(amount)                          // Payment amount
.setTxnId(txnId)                                             // Transaction ID
.setPhone(phone)                                           // User Phone number
.setProductName(productName)                   // Product Name or description
.setFirstName(firstName)                              // User First name
.setEmail(email)                                            // User Email ID
.setsUrl(appEnvironment.surl())                    // Success URL (surl)
.setfUrl(appEnvironment.furl())                     //Failure URL (furl)
.setUdf1(udf1)
.setUdf2(udf2)
.setUdf3(udf3)
.setUdf4(udf4)
.setUdf5(udf5)
.setUdf6(udf6)
.setUdf7(udf7)
.setUdf8(udf8)
.setUdf9(udf9)
.setUdf10(udf10)
.setIsDebug(true)                              // Integration environment - true (Debug)/ false(Production)
.setKey(“enter merchant key”)                        // Merchant key
.setMerchantId(“enter merchant ID”);             // Merchant ID

Build payment params and set the hash

The hash computed on the server side should be passed as an input parameter to the transaction request and hence needs to be passed to the SDK as shown below:

//declare paymentParam object
PayUmoneySdkInitializer.PaymentParam paymentParam = builder.build();
//set the hash
paymentParam.setMerchantHash(hash);

Start the Payment Flow

Invoke the following function to open the checkout page. The Customer will now interact with PayUmoney screens till the transaction is complete.

// Invoke the following function to open the checkout page.
PayUmoneyFlowManager.startPayUMoneyFlow(
PayUmoneySdkInitializer.PaymentParam paymentParam,
Activity context,
int style,
boolean isOverrideResultScreen)

Inputs:

  • PayUmoneySdkInitializer.PaymentParam - paymentparams (initialized in step 2)
  • Activity - activity context
  • Style - theme resource
  • Example:
    <style name="AppTheme.Green" parent="PayumoneyAppTheme">
    <item name="colorPrimary">@color/persian_green_primary</item>
    <item name="colorPrimaryDark">@color/persian_green_dark</item>
    <item name="colorAccent">@color/persian_green_accent</item>
    <item name="colorButtonNormal">@color/persian_green_primary</item>
    <item name="alertDialogTheme">@style/AlertDialogStyle_green</item>
    <item name="actionMenuTextColor">@color/white</item>
    </style>

  • isOverrideResultScreen

    False - PNP will take care of Transaction result screen
    True - merchant will take care of Transaction result screen

PayUmoneyFlowManager.startPayUMoneyFlow(paymentParam,
this, R.style.AppTheme_default, isOverrideResultScreen);
PayUmoney login
Logged Checkout
add card
Pay using netbanking

Response Handling

The PayUmoney SDK provides default response handling and screens thereby removing the need for you to create your own screens or handle the response from the PayUmoney server.

The default screens are illustrated in the screenshots below:

Payment success screen
Payment failure Screen

If you need custom screens for transaction success and failure, please review the steps below.

When making a payment using the PayUmoney Android SDK gives two types of payment response:

  • A client-side response in the callback function
  • A server to server callback on the Webhook, if set from the PayUmoney dashboard.

To know when the payment has completed, override the onActivityResult in your activity as exemplified in the sample code below

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Result Code is -1 send from Payumoney activity
Log.d("MainActivity", "request code " + requestCode + " resultcode " + resultCode);
if (requestCode == PayUmoneyFlowManager.REQUEST_CODE_PAYMENT && resultCode == RESULT_OK && data != null) {
TransactionResponse transactionResponse = data.getParcelableExtra(PayUmoneyFlowManager.INTENT_EXTRA_TRANSACTION_RESPONSE);
if (transactionResponse != null && transactionResponse.getPayuResponse() != null) {
if(transactionResponse.getTransactionStatus().equals(TransactionResponse.TransactionStatus.SUCCESSFUL)){
//Success Transaction
} else{
//Failure Transaction
}
// Response from Payumoney
String payuResponse = transactionResponse.getPayuResponse();
// Response from SURl and FURL
String merchantResponse = transactionResponse.getTransactionDetails();
}  else if (resultModel != null && resultModel.getError() != null) {
Log.d(TAG, "Error response : " + resultModel.getError().getTransactionResponse());
} else {
Log.d(TAG, "Both objects are null!");
}
}
}

Now, you will need to add these lines of JavaScript to your success and failure pages (SURL, FURL) for the Android SDK to be able to detect the result.

Success Page: PayUmoney.success()
Failure Page: PayUmoney.failure()

Before transaction response is displayed to the user, please verify the authenticity of the transaction by generating a response hash. The hash generated by you should match the one send by PayUmoney in response.

Managing User Login

The PayUmoney SDK provides a simple mechanism to allow users to log into their PayUmoney account and utilize features such a Saved Cards, PayUmoney wallet balance etc when making payments.

  • isUserLoggedIn() - Return true if user is logged in else return false
  • logoutUser() - Log out logged in user
boolean userLoginStatus = PayUmoneyFlowManager.isUserLoggedIn(getApplicationContext());
PayUmoneyFlowManager.logoutUser(getApplicationContext());

Change the UI Theme config using

The PayUmoney Plug and Play SDK allows you to customize the UI theme and define a Custom Look & Feel of the checkout experience. The SDK allows you to change the color and text for the following UI elements:

  • Button text on the result screen
  • Page Title
  • Color combinations (when a theme is not provided)

To customize the UI, please follow the instructions below:

PayUmoneyConfig payUmoneyConfig = PayUmoneyConfig.getInstance();

  • Change the button text on the result screen (Default text is “Continue”) payUmoneyConfig.setDoneButtonText(“Done”);
  • Page Title - Change Page titles (Default is “Merchant Display Name” set in merchant panel. If in
    the merchant panel, “PayUmoney” is used as the default page title) payUmoneyConfig.setPayUmoneyActivityTitle(“Payumoney”);
  • Change color using config: Color config is useful when a theme is not provided. setColorPrimaryDark(“#FFFFFF”)
    setColorPrimary(“#FFFFFF”)
    setTextColorPrimary(“#FFFFFF”)
    setAccentColor(“#FFFFFF”)
Note:
Color changes are not needed if theme is already provided in "startPayUMoneyFlow()" method.

Testing the Integration

For using SDK in test mode you need to follow the below-mentioned steps.

  1. PayUmoneySdkInitializer.PaymentParam.Builder().setIsDebug(true)
  2. Send the SURL/FURL, MerchantId and key accordingly for test and live mode.Goto ‘Parameters Section’ to know what this means.

Transaction Request Parameters

This section contains the details about different request parameters used while transacting using PayUmoney.

S.No. Parameter Name Required Value
1. key Compulsory Merchant key provided by PayUmoney
2. Txnid Compulsory Unique transaction id to be sent by the merchant.
3. Amount Compulsory Payment amount (Type cast to float)
4. ProductInfo Compulsory Product Description
5. firstName Compulsory Only alphabets a-z are allowed
6. Email Compulsory Customer’s email id
7. phone Compulsory Mobile or landline number (numerics only)
8. udf1 User defined field 1
9. udf2 User defined field 2
10. udf3 User defined field 3
11. udf4 User defined field 4
12. udf5 User defined field 5
13. SURL Compulsory URL called on payment completion
14. FURL Compulsory URL called on payment failure
15. hash Compulsory Hash or Checksum = sha512(key | txnid | amount | productinfo | firstname | email | udf1 | udf2 | udf3 | udf4 | udf5 | salt) (SALT is provided by PayUmoney)
Note:
udf1 to udf5 are user-defined fields. These are meant to send any additional values that you need to post. However, if you don’t feel the need to post any additional params, even then you will need post these params with blank values.

Transaction Response Parameters

This section contains the details about different response parameters encountered when transacting using PayUmoney.

S.No. Parameter Name Description Sample Value
1. status Transaction Status. (Described in detail in the Transaction Status section) success
2. firstname Firstname of the payer Tom
3. amount Transaction Amount 1.0
4. txnid Transaction Id passed by the merchant 0nf725
5. hash Security hash generated in response to protect against data tampering. Merchant is required to generate a response hash and verify it against this hash. 127e2c44016aa4c3dd5bacc09b0239b09c6174f275c0ec4c8ec7da3db915a754407849cf2537f8655255ac54ee652c4ef972c721462ec9d0a67c08b66bdbb6ba
6. productinfo Book1
7. mobile Mobile No of the payer 7406740707
8. email Email Id of the payer abc@payu.in
9. payuMoneyId The PayUmoney transaction id. 144190307
10. mode Payment Mode in:
  • Netbanking (NB)
  • Debit Card(DC)
  • Credit Card(CC)
NB

Transaction Status

A transaction can have several different statuses as explained in the table below.

S.No. Status Description
1. Not Started The transaction has not been started yet.
2. Initiated The transaction has been started but not completed.
3. Money With PayUmoney The transaction was successful and the transaction amount is with PayUmoney.
4. Under Dispute A dispute for the transaction has been raised.
5. Refunded The entire amount of the transaction has been refunded.
6. Partially Refunded A part of the amount of the transaction has been refunded.
7. Bounced Incomplete or no details provided at PayUmoney payment page.
8. Failed The transaction didn't complete due to a failure.
9. Settlement in Process Settlement for the transaction is in process.
10. Completed The transaction is settled and complete.

Sample App

To understand the PayUmoney payment flow, you may download and install our sample app and choose to Pay using PayUmoney.

Download Link: https://github.com/payu-intrepos/payumoney-new-sample-app