Integrating a payment gateway into any e-commerce application is especially important at a time when mobile commerce is growing rapidly and digital payments are proliferating. Currently, many apps need to have payment gateway functionality in order for users to be able to make transactions and purchase goods or services within the app. While many apps are using payment gateways, integrating them in Android apps is a challenge. To simplify this process, PayU offers a service that allows us to quickly integrate payment options into our apps and handle all payment methods. In this article, we will explore how we integrate payment gateways into Android apps:- www.deekpay.com

Integrating a payment gateway into any e-commerce application is especially important at a time when mobile commerce is growing rapidly and digital payments are proliferating. Currently, many apps need to have payment gateway functionality in order for users to be able to make transactions and purchase goods or services within the app. While many apps are using payment gateways, integrating them in Android apps is a challenge. To simplify this process, PayU offers a service that allows us to quickly integrate payment options into our apps and handle all payment methods. In this article, we'll look at how we can integrate payment gateways into Android apps

About PayU

PayU is one of the most popular payment gateways in India and is widely used by small and large businesses to sell goods online and collect payments quickly.PayU India provides payment gateway services to large corporates as well as SMBs/SMEs.PayU's Android SDK is relatively easy to use, which we'll talk about in more detail in the subsequent parts of this article.

Android Integration

Before proceeding with the following blog content, please ensure that you have installed and configured the following:

- Java Development Kit version 1.6 or higher

- Android SDK

- Git Client

- Eclipse / Android Studio

- Prerequisites for the PayU payment gateway (key, salt)

PayU's SDK can be used to create the following two types of solutions:

1. Non-seamless integration: you can use this module if you don't want to design your own UI.

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

Non-seamless integration using the SDK built-in UI

Get all necessary parameters

Create a PaymentParams object and use its default setup method to put all the received parameters into it, and then set the hash value of paymentHash.

"`java

PaymentParams 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");

“`

If you do not use udf1-5, there is no need to set them. Email and name can be left blank if you do not wish to use them.

You must provide user credentials in order for the shop user card feature to work:

"`java

mPaymentParams.setUserCredentials("your key:user id");

“`

For offers, use:

"`java

mPaymentParams.setOfferKey("your_offer_key");

“`

For other payment default parameters (e.g., phone, etc.), use:

"`java

mPaymentParams.setPhone("your number");

“`

Use your own server to get the correct hash values. Create a PayuHashes object and set the relevant hash value using the given default setting method.

"`java

mPaymentParams.setHash(payuHashes.getPaymentHash());

“`

Create a new Intent to target PayUBaseActivity and complete the following steps.

"`java

intent.putExtra(PayuConstants.ENV, PayuConstants.PRODUCTION_ENV);

intent.putExtra(PayuConstants.PAYMENT_DEFAULT_PARAMS, mPaymentParams);

intent.putExtra(PayuConstants.PAYU_HASHES, payuHashes);

“`

To enable one-click payments:

"`java

// Enable one-click payments with MOBILE as the option to store the hash

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

“`

Or:

"`java

// Enable one-click payments with MERCHANT SERVER as the option to store the hash

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

“`

Or:

"`java

// Disable one-click payments

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

“`

Start the campaign and leave the rest to the PayU SDK.

"`java

startActivity(intent);

“`

Seamless integration using your own UI

We will consider only credit card and internet banking transactions as examples of seamless integration. This method can be used to connect one-click payment cards, shop cards, cash cards and PayU payments.

Seamless credit/debit card payment integration

Create a PaymentParams object and populate all received parameters using the default settings method, as in the non-seamless style, and set the Hash to paymentHash.

"`java

mPaymentParams.setCardNumber(cardNumber);

mPaymentParams.setCardName(cardName);

mPaymentParams.setNameOnCard(cardName);

mPaymentParams.setExpiryMonth(expiryMonth); // MM

mPaymentParams.setExpiryYear(expiryYear); // YYYYY

mPaymentParams.setCvv(cvv);

“`

To enable one-click payments:

"`java

// Store one-click payment hash, pass 1

mPaymentParams.setEnableOneClickPayment(1);

“`

Or:

"`java

// Otherwise pass 0, or don't call the method at all

mPaymentParams.setEnableOneClickPayment(0);

“`

Using the above PostData of type PostData, create a PaymentPostParams object. Set up the environment (test or production), create the Intent, and then start the PaymentsActivity activity.

"`java

PostData postData = new PaymentPostParams(mPaymentParams, PayuConstants.CC).getPaymentPostParams();

if (postData.getCode() == PayuErrors.NO_ERROR) {

// Start the 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 {

// An error has occurred

Toast.makeText(this, postData.getResult(), Toast.LENGTH_LONG).show();

}

“`

Seamless Internet Banking Integration

Create a PaymentParams object and populate all received parameters using the default settings method as in the non-seamless style and set the Hash to paymentHash. add the bankCode (string) of the selected bank to the previously defined mPaymentParams, using your spinner/list view adapter.

"`java

mPaymentParams.setBankCode(bankCode);

“`

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

"`java

PostData postData = new PaymentPostParams(mPaymentParams, PayuConstants.NB).getPaymentPostParams();

if (postData.getCode() == PayuErrors.NO_ERROR){

// Start the 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 {

// An error has occurred

Toast.makeText(this, postData.getResult(), Toast.LENGTH_LONG).show();

}

“`

PayU will provide you with test configurations to begin the integration process, including test merchant accounts and test credit card details so you understand the entire transaction process. The SDK code must then be integrated into your application. After testing is complete, you should be ready to point your application to the PayU production server for some real-world transactions.

test voucher

To enable more logging, start using the test key and salt (for the test server). Use the following test account (for testing purposes only):

- Key: ktKFFx

- Salt: bDwWELix

Test card information:

- Name of cardholder: Shefali Singh

- Card number: 2355 6756 9902 6654

- CVV: 098

- Expiry date: 11/2023

exports

Since we are using test credentials, payments cannot be made. You must activate your app in the PayU dashboard and generate a new key for your payment to take effect.

That's a primer on PayU Android app integration. Good luck with your integration!