Collect Payments – QR, Blogs, Excel Plugin, SMS, WhatsApp, PayU Payment Gateway for Web and App. Businesses can collect payments easily and fast by integrating a PayU payment gateway into their Android app.

With the extensive development of mobile commerce and a manifold increase in digital payments, it is essential to integrate a payment gateway in any eCommerce app. 

Nowadays, many applications are required to have a payment gateway so that users may conduct transactions within their apps to buy any goods or services. Many apps use payment gateways, but integrating them into Android apps is tricky. As a result, to make this process as simple as possible, PayU has given a service through which we can quickly integrate payment options into our app and handle all payment ways. This post will look at how we integrated a payment gateway into our Android app.

About PayU

PayU is one of India’s most popular payment gateways, utilized by both small and large businesses to sell their items online and receive money quickly. PayU India offers payment gateway services for large businesses and SMB/SMEs. PayU’s Android SDK is fairly simple to use, and we’ll go over it in more detail later in this post.

Android Integration

Make sure you have the following installed and configured before continuing with this blog:

  • Version 1.6 or higher of the Java Development Kit
  • SDK for Android
  • A Git client
  • Eclipse / Android Studio
  • Prerequisites for PayU Payment Gateway (Key, Salt)

PayU’s SDK may be used to create the following two sorts of solutions:

1. Non-seamless: If you don’t want to design your own UI, you may use this module instead.

2. Seamless: In this instance, you’ll need to create your own user interface to capture financial data, such as credit card numbers and CVVs.

Using the SDK’s built-in UI for a non-seamless integration

Obtain all of the necessary parameters

  • Create a PaymentParams object and use its default set methods to put all of the received parameters in it, then setHash to paymentHash.

PaymentParams mPaymentParams = new PaymentParams();
mPaymentParams.setKey (“gtKFFx”);
mPaymentParams.setAmount (“15.0”);
mPaymentParams.setProductInfo (“Tshirt”);
mPaymentParams.setFirstName (“Guru”);
mPaymentParams.setEmail (“guru@gmail.com”);
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”);

If you are not utilizing udf1-5, you do not need to set them.

If you don’t wish to use them, email and firstname can be empty strings “”.

You must give user credentials here for the store user card functionality mPaymentParams.setUserCredentials(“your key:user id”) to work.

mPaymentParams.setOfferKey(“your_offer_key”), for offers

mPaymentParams.setPhone(“your number”) is used for any other payment default param (such as phone and others).

  • Using your own server, obtain the appropriate hashes. Create a PayuHashes object and use the given default set methods to set the associated hashes.

mPaymentParams.setHash(payuHashes.getPaymentHash());

  •   Create a new intent with the PayUBaseActivity as the target and complete the steps below.

intent.putExtra(PayuConstants.ENV, PayuConstants.PRODUCTION_ENV); intent.putExtra(PayuConstants.PAYMENT_DEFAULT_PARAMS, mPaymentParams); intent.putExtra(PayuConstants.PAYU_HASHES, payuHashes);

  • To make it possible to pay with a single click

// Enable one click with MOBILE as storage option for hash

intent.putExtra(PayuConstants.STORE_ONE_CLICK_HASH,PayuConstants.STORE_ONE_CLICK_HASH_MOBILE);

OR

// Enable once click with MERCHANT SERVER as storage option for hash

intent.putExtra(PayuConstants.STORE_ONE_CLICK_HASH,PayuConstants.STORE_ONE_CLICK_HASH_SERVER);

OR

// DISABLE one click payment

intent.putExtra(PayuConstants.STORE_ONE_CLICK_HASH,PayuConstants.STORE_ONE_CLICK_HASH_NONE);

  •   Begin the activity and leave the rest to PayU SDK.

startActivity(intent);

Using Your Own UI For Seamless Integration

We will only consider credit card and net banking transactions as examples of seamless integration. This method may be used to connect one-click Payment Cards, Store Cards, Cash Cards, and PayU payments.

Seamless Credit / Debit card Payment Integration

Create a PaymentParams object and fill it with all of the received parameters using the default set methods, just as you did for the non-seamless style, and setHash to paymentHash.

  •      To mPaymentParams, add the following extra attributes.

mPaymentParams.setCardNumber(cardNumber);
mPaymentParams.setCardName(cardName);
mPaymentParams.setNameOnCard(cardName);
mPaymentParams.setExpiryMonth(expiryMonth);// MM
mPaymentParams.setExpiryYear(expiryYear);// YYYY 
mPaymentParams.setCvv(cvv);

  •   To make it possible to pay with a single click

// To store one click payment hash pass 1
mPaymentParams.setEnableOneClickPayment(1);
// Otherwise pass 0, OR don’t call the method at all
mPaymentParams.setEnableOneClickPayment(0);

  •    With the above data of the type PostData, create a PaymentPostParams object. Set the environment (test or prod), establish the intent, then start the PaymentsActivity activity.

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();
}

 Seamless Net Banking Integration

  • Create a PaymentParams object and fill it with all the received parameters using the default set methods, just as you did for the non-seamless style and setHash to paymentHash.
  • Add the bankCode (String) of the selected bank to the mPaymentParams defined earlier using your spinner/list view adapter.

mPaymentParams.setBankCode(bankCode);

  • Start the PaymentsActivity by creating a PaymentPostParams object of type PostData.

PostData 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();
}

PayU will supply you with a test configuration to begin the integration process, including a test merchant account and test credit card details, so you can get a feel for the whole transaction flow. The SDK code must then be integrated into your application. You should be ready to point your app to the PayU production server for some actual transactions after the testing is completed.

Credentials for test

To enable more logs, start using the test key and salt (which targets the test server). Please use the following test account (exclusively for testing purposes):

  • Key: ktKFFx
  • Salt: bDwWELix

Card with a dummy test

This will succeed only in the test environment. On the test server, all other cards (genuine or fake) will also fail.

  • Name on card: Shefali Singh
  • Card Number: 2355 6756 9902 6654
  • CVV: 098
  • Expiry date: 11/2023

Output

Because we’re using test credentials, we won’t be able to make a payment. You must make your application active in the PayU dashboard and generate a new key in order to make your payments live.

It’s all about getting started with PayU’s Android app integration. Good luck with your integration!

6