Paytm Integration in Android Example – Accepting Payments with Paytm

Paytm is the most popular mobile wallet and payment method used in India. So I thought to publish a Paytm Integration in Android Example. In this post, we will learn how can we add a …

paytm integration in android example

Paytm is the most popular mobile wallet and payment method used in India. So I thought to publish a Paytm Integration in Android Example.
In this post, we will learn how can we add a Pay with Paytm method in our android application.
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 in your application.

Getting Credentials from Paytm

The first step is getting 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.

  • Go to this link and sign in with your Paytm account.
  • You do not need to submit any details after Signup just click on Sandbox Access link as shown in the below image.
paytm sandbox
Paytm Sandbox
  • Now you will see your Sandbox Credential.
sandbox credential
Sandbox Credential
  • You are going to use the above credentials. Now lets 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.

  1. Generate CHECKSUM on our server.
  2. 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 Xampp Server.

And for sending Request from 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.

  • Open XAMPP Server and Start the Server. (Skip this step if you are using a live server).
  • 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 php kit
Paytm PHP Checksum Kit
  • I have renamed the folder to only paytm to make it short and simple.
  • Inside the folder we have a file named generateChecksum.php and we need to use it for generating checksum.
  • But first we need to put our Paytm Merchant Key in the configuration.
  • Go to config_paytm.php (it is inside the lib folder paytm/lib/config_paytm.php), and put your Paytm Merchant Key.

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

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. 

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

Integrating Paytm Payment in Android Project

Creating a New Project

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

Adding Paytm SDK

  • Now download the Paytm SDK. Inside the SDK you will find a file named PGSDK_V2.1.jar. We need to add this file in our project dependencies.
  • So first on the project explorer select Project.

project explorer

  • Then inside app/lib paste the PGSDK_V2.1.jar that we downloaded.

adding paytm sdk

  • Now click on File->Project Structure.

project structure

  • Now from the top tabs go to dependency, and from the right green plus icon select jar dependency.

jar dependency

  • Now select the jar from the lib folder that you added, and hit ok.

adding dependency android studio

  • That’s it the Paytm SDK is added.

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.

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.

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.

  • The above code will generate the following layout.

paytm integration in android example

  • Make sure you add an image named macbook_air in the drawable folder. Or if the name of your image is different, then change it in the ImageView of your layout.

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.
paytm integration in android example
Paytm Integration in Android Example
  • Bingo! it is working fine.

Paytm Integration in Android Example – Source Code

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

[sociallocker id=5688] Paytm Integration in Android Example [/sociallocker]

So that’s all for this Paytm Integration in Android Example friends. I hope you found it useful if you did, please SHARE it with your friends.
And if you are having any query regarding this Paytm Integration in Android Example then don’t hesitate in commenting. Thank You 🙂

Hi, my name is Belal Khan and I am a Google Developers Expert (GDE) for Android. The passion of teaching made me create this blog. If you are an Android Developer, or you are learning about Android Development, then I can help you a lot with Simplified Coding.

Expand Your Knowledge: Next Tutorial Picks

0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x