Search Bar

Integrate Payment Gateway in Android using Paytm

Integrate Payment Gateway in Android using Paytm: Accepting Payments with Paytm


Hi Friends, 
                     Today we going to learn Payment Gateway in Android using Paytm Payment Gateway. Paytm is most popular payment wallet in India. There is the official documentation about integrating Paytm at PayWithPaytm/Developer but that is very confusing, and if you are a newbie then you can face troubles. Here I will show you every step in detailed explanation so you can easily integrate Paytm payments into your android application.





Getting Credentials from Paytm

The first step is getting a credential from Paytm. Paytm provides it to all the merchants. So you need to signup as a merchant in Paytm. But the problem is it takes time, and you need to submit some docs like GST, Bank Account details.
But you do not need to worry as the developer can get sandbox access for development purposes.

1) Go to this link and sign in with your Paytm account.
2) You do not need to submit any details after Sign up just click on Sandbox Access link as shown in the below image.

Developers looking to access Sandbox Click here.png
Developers looking to access Sandbox Click here.png

3) Now you will see your Sandbox Credential.


Sandbox Credentials
Sandbox Credentials

4) You are going to use the above credentials. Now let's integrate the Paytm Payment.

How to Integrate Paytm Payment into Android Application?

Let’s first understand how we add Paytm Payment in our Application. We need to perform these two steps.

   A) Generate CHECKSUM on our server.
   B) Accept Payment with Paytm SDK.

We need to generate the Checksum on our server, so the process requires some server-side implementation as well. And here on the server side, I am going to use PHP with Live Server. Or you also use Xampp Server /or/ any other you want.

And for sending Request from the android side I will be using Retrofit.

Paytm Integration in Android Example

Configuring the Paytm Checksum Kit

Now let’s start the real process. We will start with the server-side implementation.

1) Open XAMPP Server and Start the Server. (Skip this step if you are using a live server).
2) Then download the Paytm App Checksum Kit. And paste it to your server’s root directory. (For XAMPP it is c:/xampp/htdocs by default)

 Paytm App Checksum Kit
 Paytm App Checksum Kit
Paytm PHP Checksum Kit (Local Folder in C://htdoc....)
Paytm PHP Checksum Kit (Local Folder in C://htdoc..)
3) I have renamed the folder to only paytm to make it short and simple.
4) Inside the folder, we have a file named generateChecksum.php and we need to use it for generating the checksum.
5) But first, we need to put our Paytm Merchant Key in the configuration.
6) Go to config_paytm.php (it is inside the lib folder paytm/lib/config_paytm.php), and put your Paytm Merchant Key.


<?php
//Change the value of PAYTM_MERCHANT_KEY constant with details received from Paytm.
define('PAYTM_MERCHANT_KEY', 'YOUR_MERCHANT_KEY_HERE');


?>

7) That’s it for the server side implementation, we just need to route to generateChecksum.php file. So it is localhost/paytm/generateChecksum.php.

NOTE: But remember using localhost will not work you need to find the IP. You can see it using the ipconfig command, and if you are using a live server, then you can use the URL with your domain. 
ipconfig command
ipconfig command


Now, let’s move ahead by creating an Android Studio Project.

Integrating Paytm Payment in Android Project

1)  Creating a New Project: 

First, we will create a new Android Studio Project. I have created a project named PaytmPaymentSample with an Empty Activity.

2)  Adding Paytm SDK:


Now in android Gradle dependency add --> implementation 'com.paytm:pgplussdk:1.1.5'
(Come inside your app level build.gradle file)

3) Adding Permissions and Paytm Activity:


We need to add INTERNET and ACCESS_NETWORK_STATE permission, and PaytmPGActivity (The activity comes with the Paytm SDK that we already added).

So open AndroidManifest.xml and modify it as below.

NOTE: If PaytmPGActivity shows error then remove it.


4) Adding Retrofit and Gson:

As I told you above that, we are going to use the Retrofit Library for sending network request. So for this, we need to Add Retrofit and Gson.
Come inside your app level build.gradle file and add both libraries.



implimentation 'com.squareup.retrofit2:retrofit:2.2.0'
    implimentation 'com.squareup.retrofit2:converter-gson:2.2.0'

5) Defining Constants:

Now, we will define all the required constants in a separate class. For this create a new class named Constants.java and define the following inside.
Remember you need to change the first 3 values according to the Paytm Credentials you got.


Creating User Interface

Now we will create a very Simple User Interface. So come inside activity_main.xml and write the following code.



Creating Retrofit Models and Interface

Creating Models

We need two classes one is for CHECKSUM and other is for storing Paytm payment details.

First, create a class named Checksum.java and write the following code.



Now create Paytm.java and write the following code.


Creating Retrofit API Interface

Create a new interface named Api.java.


If you don’t know anything about using Retrofit you better go through the Retrofit Tutorial first.

Now come to MainActivity.java and write the following code to complete our project.


Now you can try running your application.

Bingo! it is working fine.

Paytm Integration in Android Example – Source Code

 Download Project



If you are having some problem following this example, then you get my source code. The link is given below.



Other Ads




Other Code 2


Post a Comment

0 Comments