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 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.


  • 1 Getting Credentials from Paytm
  • 2 How to Integrate Paytm Payment into Android Application?
  • 3 Paytm Integration in Android Example
    • 3.1 Configuring the Paytm Checksum Kit
    • 3.2 Integrating Paytm Payment in Android Project
      • 3.2.1 Creating a New Project
      • 3.2.2 Adding Paytm SDK
      • 3.2.3 Adding Permissions and Paytm Activity
      • 3.2.4 Adding Retrofit and Gson
      • 3.2.5 Defining Constants
      • 3.2.6 Creating User Interface
      • 3.2.7 Creating Retrofit Models and Interface
        • Creating Models
        • Creating Retrofit API Interface
  • 4 Paytm Integration in Android Example – Source Code
    • 4.1 Sharing is Caring:

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

  • Now you will see your 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 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.
//Change the value of PAYTM_MERCHANT_KEY constant with details received from Paytm.
  • 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 .

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

  • Now click on File->Project Structure .

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

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

  • 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.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
    <!-- the following two permissions are needed --> 
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
        <activity android:name=".MainActivity">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
        Add this activity to your manifest
        it comes with the Paytm SDK
        <activity android:name="com.paytm.pgsdk.PaytmPGActivity"
            android:screenOrientation="portrait" android:configChanges="keyboardHidden|orientation|keyboard"/>

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.
    compile 'com.squareup.retrofit2:retrofit:2.2.0'
    compile 'com.squareup.retrofit2:converter-gson:2.2.0'

Defining Constants

  • Now, we will define all the required constants in a separate class. For this create a new class named and define the following inside.
  • Remember you need to change the first 3 values according to the Paytm Credentials you got.
 * Created by Belal on 1/10/2018.
public class Constants {
    public static final String M_ID = "xxxxxxxx"; //Paytm Merchand Id we got it in paytm credentials
    public static final String CHANNEL_ID = "WEB"; //Paytm Channel Id, got it in paytm credentials
    public static final String INDUSTRY_TYPE_ID = "Retail"; //Paytm industry type got it in paytm credential
    public static final String WEBSITE = "APP_STAGING";
    public static final String CALLBACK_URL = "";

Creating User Interface

  • Now we will create a very Simple User Interface. So come inside activity_main.xml and write the following code.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android=""
        android:padding="4dp" />
        android:text="Apple MacBook Air Core i5 5th Gen - (8 GB/128 GB SSD/Mac OS Sierra)"
        android:textColor="#000000" />
        android:text="13.3 Inch, 256 GB"
        android:textAppearance="@style/Base.TextAppearance.AppCompat.Small" />
        android:textStyle="bold" />
        android:textStyle="bold" />
        android:text="Buy" />
  • The above code will generate the following layout.

  • 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 and write the following code.
 * Created by Belal on 1/10/2018.
public class Checksum {
    private String checksumHash;
    private String orderId;
    private String paytStatus;
    public Checksum(String checksumHash, String orderId, String paytStatus) {
        this.checksumHash = checksumHash;
        this.orderId = orderId;
        this.paytStatus = paytStatus;
    public String getChecksumHash() {
        return checksumHash;
    public String getOrderId() {
        return orderId;
    public String getPaytStatus() {
        return paytStatus;
  • Now create and write the following code.
import android.util.Log;
import java.util.UUID;
 * Created by Belal on 1/10/2018.
public class Paytm {
    String mId;
    String orderId;
    String custId;
    String channelId;
    String txnAmount;
    String website;
    String callBackUrl;
    String industryTypeId;
    public Paytm(String mId, String channelId, String txnAmount, String website, String callBackUrl, String industryTypeId) {
        this.mId = mId;
        this.orderId = generateString();
        this.custId = generateString();
        this.channelId = channelId;
        this.txnAmount = txnAmount; = website;
        this.callBackUrl = callBackUrl;
        this.industryTypeId = industryTypeId;
        Log.d("orderId", orderId);
        Log.d("customerId", custId);
    public String getmId() {
        return mId;
    public String getOrderId() {
        return orderId;
    public String getCustId() {
        return custId;
    public String getChannelId() {
        return channelId;
    public String getTxnAmount() {
        return txnAmount;
    public String getWebsite() {
        return website;
    public String getCallBackUrl() {
        return callBackUrl;
    public String getIndustryTypeId() {
        return industryTypeId;
    * The following method we are using to generate a random string everytime
    * As we need a unique customer id and order id everytime 
    * For real scenario you can implement it with your own application logic
    * */
    private String generateString() {
        String uuid = UUID.randomUUID().toString();
        return uuid.replaceAll("-", "");

Creating Retrofit API Interface

  • Create a new interface named .
import retrofit2.Call;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;
 * Created by Belal on 1/10/2018.
public interface Api {
    //this is the URL of the paytm folder that we added in the server
    //make sure you are using your ip else it will not work 
    String BASE_URL = "";
    Call<Checksum> getChecksum(
            @Field("MID") String mId,
            @Field("ORDER_ID") String orderId,
            @Field("CUST_ID") String custId,
            @Field("CHANNEL_ID") String channelId,
            @Field("TXN_AMOUNT") String txnAmount,
            @Field("WEBSITE") String website,
            @Field("CALLBACK_URL") String callbackUrl,
            @Field("INDUSTRY_TYPE_ID") String industryTypeId
  • If you don’t know anything about using Retrofit you better go through the Retrofit Tutorial  first.
  • Now come to and write the following code to complete our project.
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import com.paytm.pgsdk.PaytmOrder;
import com.paytm.pgsdk.PaytmPGService;
import com.paytm.pgsdk.PaytmPaymentTransactionCallback;
import java.util.HashMap;
import java.util.Map;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
//implementing PaytmPaymentTransactionCallback to track the payment result.
public class MainActivity extends AppCompatActivity implements PaytmPaymentTransactionCallback {
    //the textview in the interface where we have the price
    TextView textViewPrice;
    protected void onCreate(Bundle savedInstanceState) {
        //getting the textview
        textViewPrice = findViewById(;
        //attaching a click listener to the button buy
        findViewById( View.OnClickListener() {
            public void onClick(View view) {
                //calling the method generateCheckSum() which will generate the paytm checksum for payment
    private void generateCheckSum() {
        //getting the tax amount first.
        String txnAmount = textViewPrice.getText().toString().trim();
        //creating a retrofit object.
        Retrofit retrofit = new Retrofit.Builder()
        //creating the retrofit api service
        Api apiService = retrofit.create(Api.class);
        //creating paytm object
        //containing all the values required
        final Paytm paytm = new Paytm(
        //creating a call object from the apiService
        Call<Checksum> call = apiService.getChecksum(
        //making the call to generate checksum
        call.enqueue(new Callback<Checksum>() {
            public void onResponse(Call<Checksum> call, Response<Checksum> response) {
                //once we get the checksum we will initiailize the payment.
                //the method is taking the checksum we got and the paytm object as the parameter
                initializePaytmPayment(response.body().getChecksumHash(), paytm);
            public void onFailure(Call<Checksum> call, Throwable t) {
    private void initializePaytmPayment(String checksumHash, Paytm paytm) {
        //getting paytm service
        PaytmPGService Service = PaytmPGService.getStagingService();
        //use this when using for production
        //PaytmPGService Service = PaytmPGService.getProductionService();
        //creating a hashmap and adding all the values required
        Map<String, String> paramMap = new HashMap<>();
        paramMap.put("MID", Constants.M_ID);
        paramMap.put("ORDER_ID", paytm.getOrderId());
        paramMap.put("CUST_ID", paytm.getCustId());
        paramMap.put("CHANNEL_ID", paytm.getChannelId());
        paramMap.put("TXN_AMOUNT", paytm.getTxnAmount());
        paramMap.put("WEBSITE", paytm.getWebsite());
        paramMap.put("CALLBACK_URL", paytm.getCallBackUrl());
        paramMap.put("CHECKSUMHASH", checksumHash);
        paramMap.put("INDUSTRY_TYPE_ID", paytm.getIndustryTypeId());
        //creating a paytm order object using the hashmap
        PaytmOrder order = new PaytmOrder(paramMap);
        //intializing the paytm service
        Service.initialize(order, null);
        //finally starting the payment transaction
        Service.startPaymentTransaction(this, true, true, this);
    //all these overriden method is to detect the payment result accordingly 
    public void onTransactionResponse(Bundle bundle) {
        Toast.makeText(this, bundle.toString(), Toast.LENGTH_LONG).show();
    public void networkNotAvailable() {
        Toast.makeText(this, "Network error", Toast.LENGTH_LONG).show();
    public void clientAuthenticationFailed(String s) {
        Toast.makeText(this, s, Toast.LENGTH_LONG).show();
    public void someUIErrorOccurred(String s) {
        Toast.makeText(this, s, Toast.LENGTH_LONG).show();
    public void onErrorLoadingWebPage(int i, String s, String s1) {
        Toast.makeText(this, s, Toast.LENGTH_LONG).show();
    public void onBackPressedCancelTransaction() {
        Toast.makeText(this, "Back Pressed", Toast.LENGTH_LONG).show();
    public void onTransactionCancel(String s, Bundle bundle) {
        Toast.makeText(this, s + bundle.toString(), Toast.LENGTH_LONG).show();
  • Now you can try running your application.

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.

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 ��