How to Integrate Paytm wallet in android application

The Payment Gateway of Paytm. It will communicate with the Paytm SDK and Merchant's Web server. In case, the payment is made via credit cards/debit cards/net banking, the Payment Gatway will interact with the Banks as well.

The Paytm Payment Integration SDK for android enables merchants to payments into their mobile app. Download PGSDK Library from http://paywithpaytm.com/developer/paytm_sdk_doc?target=integration-guide... . The Payment Gateway of Paytm. It will communicate with the Paytm SDK and Merchant's Web server. In case, the payment is made via credit cards/debit cards/net banking, the Payment Gatway will interact with the Banks as well.

There are two type of Paytm Payment Integration :-

1. Retail Store

2. App/Website

 

Retail Store :-

Step 1 :-

Step 2 :-

Step 3 :-

Step 4 :-

Step 5 :-

 

App/Website :-

 

Step 1 :-

Step 2 :-

Step 3 :-

Step 4 :-

Step 5 :-

Step 6 :-

Step 7 :-

Step 8 :-

Step 9 :-

 

 

<service
            android:name=".CustomFirebaseMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT"/>
            </intent-filter>
        </service>

        <service
            android:name=".CustomFirebaseInstanceIDService">
            <intent-filter>
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
            </intent-filter>
        </service>

1. PaytmActivity

package com.tutorialsee.paytm;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.Toast;

import com.paytm.pgsdk.PaytmMerchant;
import com.paytm.pgsdk.PaytmOrder;
import com.paytm.pgsdk.PaytmPGService;
import com.paytm.pgsdk.PaytmPaymentTransactionCallback;

public class PaytmActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_paytm);
initOrderId();
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

@Override
protected void onStart(){
super.onStart();
initOrderId();
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
}


private void initOrderId() {
Random r = new Random(System.currentTimeMillis());
String orderId = "ORDER" + (1 + r.nextInt(2)) * 10000
+ r.nextInt(10000);
EditText orderIdEditText = (EditText) findViewById(R.id.order_id);
orderIdEditText.setText(orderId);
}

public void onStartTransaction(View view) {
PaytmPGService Service = PaytmPGService.getStagingService();
Map<String, String> paramMap = new HashMap<String, String>();

// these are mandatory parameters

paramMap.put("ORDER_ID", ((EditText) findViewById(R.id.order_id)).getText().toString());
paramMap.put("MID", ((EditText) findViewById(R.id.merchant_id)).getText().toString());
paramMap.put("CUST_ID", ((EditText) findViewById(R.id.customer_id)).getText().toString());
paramMap.put("CHANNEL_ID", ((EditText) findViewById(R.id.channel_id)).getText().toString());
paramMap.put("INDUSTRY_TYPE_ID", ((EditText) findViewById(R.id.industry_type_id)).getText().toString());
paramMap.put("WEBSITE", ((EditText) findViewById(R.id.website)).getText().toString());
paramMap.put("TXN_AMOUNT", ((EditText) findViewById(R.id.transaction_amount)).getText().toString());
paramMap.put("THEME", ((EditText) findViewById(R.id.theme)).getText().toString());
paramMap.put("EMAIL", ((EditText) findViewById(R.id.cust_email_id)).getText().toString());
paramMap.put("MOBILE_NO", ((EditText) findViewById(R.id.cust_mobile_no)).getText().toString());
PaytmOrder Order = new PaytmOrder(paramMap);

PaytmMerchant Merchant = new PaytmMerchant(
"https://pguat.paytm.com/paytmchecksum/paytmCheckSumGenerator.jsp",
"https://pguat.paytm.com/paytmchecksum/paytmCheckSumVerify.jsp");


Service.initialize(Order, Merchant, null);

Service.startPaymentTransaction(this, true, true,
new PaytmPaymentTransactionCallback() {
@Override
public void someUIErrorOccurred(String inErrorMessage) {
Toast.makeText(getApplicationContext(), "Ui/Webview error occured.", Toast.LENGTH_LONG).show();

}

@Override
public void onTransactionSuccess(Bundle inResponse) {
Log.d("LOG", "Payment Transaction is successful " + inResponse);
Toast.makeText(getApplicationContext(), "Payment Transaction is successful ", Toast.LENGTH_LONG).show();
}

@Override
public void onTransactionFailure(String inErrorMessage,
Bundle inResponse) {
Log.d("LOG", "Payment Transaction Failed " + inErrorMessage);
Toast.makeText(getBaseContext(), "Payment Transaction Failed ", Toast.LENGTH_LONG).show();
recreate();
}

@Override
public void networkNotAvailable() {

Toast.makeText(getBaseContext(), "No Internet connection.", Toast.LENGTH_LONG).show();

}

@Override
public void clientAuthenticationFailed(String inErrorMessage) {

Toast.makeText(getBaseContext(), "Client Authentication Failed.", Toast.LENGTH_LONG).show();

}

@Override
public void onErrorLoadingWebPage(int iniErrorCode,
String inErrorMessage, String inFailingUrl) {

}


@Override
public void onBackPressedCancelTransaction() {
// TODO Auto-generated method stub
}
});
}
}

2. activity_paytm

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"

android:background="#ffffff">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Confirmation Order Details"
android:textStyle="bold"
android:textSize="18dip"
android:gravity="center"
android:background="#4399CD"
android:textColor="#ffffff"
android:padding="15dp"
android:layout_marginBottom="10dip"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:orientation="vertical">



<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#DFF0D8"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:layout_margin="0.1dp"
android:weightSum="1">

<TextView
android:layout_width="0dip"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="#7D4A54"
android:padding="5dp"
android:layout_weight="0.50"
android:text="@string/order_id"
android:textStyle="bold"

android:textSize="13dip"/>

<EditText
android:id="@+id/order_id"
android:layout_width="0dip"
android:layout_height="match_parent"
android:gravity="center"
android:background="#ffffff"
android:padding="5dp"
android:layout_weight="0.50"
android:textSize="13dip"
android:text="@string/sample_order_id"
android:singleLine="true" />

</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#DFF0D8"
android:layout_marginTop="5dp"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:layout_margin="0.1dp"
android:weightSum="1">

<TextView
android:layout_width="0dip"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="#7D4A54"
android:padding="5dp"
android:layout_weight="0.50"
android:text="@string/customer_id"
android:textStyle="bold"
android:textSize="13dip"/>

<EditText
android:id="@+id/customer_id"
android:layout_width="0dip"
android:layout_height="match_parent"
android:gravity="center"
android:background="#ffffff"
android:padding="5dp"
android:layout_weight="0.50"
android:textSize="13dip"
android:text="@string/sample_customer_id"
android:singleLine="true" />

</LinearLayout>
</LinearLayout>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#DFF0D8"
android:layout_marginTop="5dp"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:layout_margin="0.1dp"
android:weightSum="1">

<TextView
android:layout_width="0dip"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="#7D4A54"
android:padding="5dp"
android:layout_weight="0.50"
android:text="@string/transaction_amount"
android:textStyle="bold"
android:textSize="13dip"/>

<EditText
android:id="@+id/transaction_amount"
android:layout_width="0dip"
android:layout_height="match_parent"
android:gravity="center"
android:background="#ffffff"
android:padding="5dp"
android:layout_weight="0.50"
android:textSize="13dip"
android:text="@string/sample_transaction_amount"
android:singleLine="true" />

</LinearLayout>
</LinearLayout>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#DFF0D8"
android:layout_marginTop="5dp"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:layout_margin="0.1dp"
android:weightSum="1">

<TextView
android:layout_width="0dip"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="#7D4A54"
android:padding="5dp"
android:layout_weight="0.50"
android:text="@string/cust_email_id"
android:textStyle="bold"
android:textSize="13dip"/>

<EditText
android:id="@+id/cust_email_id"
android:layout_width="0dip"
android:layout_height="match_parent"
android:gravity="center"
android:background="#ffffff"
android:padding="5dp"
android:layout_weight="0.50"
android:textSize="13dip"
android:text="@string/sample_cust_email_id"
android:singleLine="true" />

</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#DFF0D8"
android:layout_marginTop="5dp"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:layout_margin="0.1dp"
android:weightSum="1">

<TextView
android:layout_width="0dip"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="#7D4A54"
android:padding="5dp"
android:layout_weight="0.50"
android:text="@string/cust_mobile_no"
android:textStyle="bold"
android:textSize="13dip"/>

<EditText
android:id="@+id/cust_mobile_no"
android:layout_width="0dip"
android:layout_height="match_parent"
android:gravity="center"
android:background="#ffffff"
android:padding="5dp"
android:layout_weight="0.50"
android:textSize="13dip"
android:text="@string/sample_cust_mobile_no"
android:singleLine="true" />

</LinearLayout>
</LinearLayout>
</LinearLayout>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Merchant Properties"
android:textStyle="bold"
android:textSize="18dip"
android:textColor="#7D4A54"
android:layout_gravity="left"
android:layout_marginTop="10dip"
android:layout_marginBottom="10dip"/>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#DFF0D8"
android:layout_marginTop="5dp"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:layout_margin="0.1dp"
android:weightSum="1">

<TextView
android:layout_width="0dip"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="#7D4A54"
android:padding="5dp"
android:layout_weight="0.50"
android:text="@string/merchant_id"
android:textStyle="bold"
android:textSize="13dip"/>

<EditText
android:layout_width="0dip"
android:layout_height="match_parent"
android:gravity="center"
android:background="#ffffff"
android:padding="5dp"
android:layout_weight="0.50"
android:id="@+id/merchant_id"
android:textSize="13dip"
android:text="@string/sample_merchant_id_staging"
android:singleLine="true"/>

</LinearLayout>
</LinearLayout>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#DFF0D8"
android:layout_marginTop="5dp"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:layout_margin="0.1dp"
android:weightSum="1">

<TextView
android:layout_width="0dip"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="#7D4A54"
android:padding="5dp"
android:layout_weight="0.50"
android:text="@string/channel_id"
android:textStyle="bold"
android:textSize="13dip"/>

<EditText
android:layout_width="0dip"
android:layout_height="match_parent"
android:gravity="center"
android:background="#ffffff"
android:padding="5dp"
android:layout_weight="0.50"
android:id="@+id/channel_id"
android:textSize="13dip"
android:text="@string/sample_channel_id"
android:singleLine="true"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#DFF0D8"
android:layout_marginTop="5dp"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:layout_margin="0.1dp"
android:weightSum="1">

<TextView
android:layout_width="0dip"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="#7D4A54"
android:padding="5dp"
android:layout_weight="0.50"
android:text="@string/industry_type_id"
android:textStyle="bold"
android:textSize="13dip"/>

<EditText
android:layout_width="0dip"
android:layout_height="match_parent"
android:gravity="center"
android:background="#ffffff"
android:padding="5dp"
android:layout_weight="0.50"
android:id="@+id/industry_type_id"
android:textSize="13dip"
android:text="@string/sample_industry_type_id"
android:singleLine="true"/>

</LinearLayout>
</LinearLayout>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#DFF0D8"
android:layout_marginTop="5dp"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:layout_margin="0.1dp"
android:weightSum="1">

<TextView
android:layout_width="0dip"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="#7D4A54"
android:padding="5dp"
android:layout_weight="0.50"
android:text="@string/website"
android:textStyle="bold"
android:textSize="13dip"/>

<EditText
android:layout_width="0dip"
android:layout_height="match_parent"
android:gravity="center"
android:background="#ffffff"
android:padding="5dp"
android:layout_weight="0.50"
android:id="@+id/website"
android:textSize="13dip"
android:text="@string/sample_website"
android:singleLine="true"/>

</LinearLayout>
</LinearLayout>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#DFF0D8"
android:layout_marginTop="5dp"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:layout_margin="0.1dp"
android:weightSum="1">

<TextView
android:layout_width="0dip"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="#7D4A54"
android:padding="5dp"
android:layout_weight="0.50"
android:text="@string/theme"
android:textStyle="bold"
android:textSize="13dip"/>

<EditText
android:layout_width="0dip"
android:layout_height="match_parent"
android:gravity="center"
android:background="#ffffff"
android:padding="5dp"
android:layout_weight="0.50"
android:id="@+id/theme"
android:textSize="13dip"
android:text="@string/sample_theme"
android:singleLine="true"/>

</LinearLayout>
</LinearLayout>
</LinearLayout>

</LinearLayout>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:weightSum="1"
android:visibility="gone"
android:id="@+id/checksum_generation">

<TextView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.50"
android:text="@string/checksum_generation_url"
android:textStyle="bold"
android:textSize="13dip"
android:gravity="left"/>

<EditText
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.50"
android:id="@+id/checksum_generation_url"
android:textSize="13dip"
android:text="@string/sample_checksum_generation_url"
android:singleLine="true"/>

</LinearLayout>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:weightSum="1"
android:visibility="gone"
android:id="@+id/checksum_verification">

<TextView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.50"
android:text="@string/checksum_verification_url"
android:textStyle="bold"
android:textSize="13dip"
android:gravity="left"/>

<EditText
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.50"
android:textSize="13dip"
android:id="@+id/checksum_verification_url"
android:text="@string/sample_checksum_verification_url"
android:singleLine="true"/>

</LinearLayout>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/start_transaction"
android:text="Confirm Order"
android:onClick="onStartTransaction"
android:layout_gravity="center"
android:textStyle="bold"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:textSize="16dip"
android:layout_marginBottom="10dp"

android:textColor="#ffffff"
android:background="#042E6F"
android:layout_marginTop="10dip"/>

</LinearLayout>

</ScrollView>

3. AndroidManifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.tutorialsee.paytm"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"/>
   
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
   
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.tutorialsee.paytm.PaytmActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait">
            <intent-filter >
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity
            android:name="com.paytm.pgsdk.PaytmPGActivity"
            android:screenOrientation="portrait"
            android:configChanges="keyboardHidden|orientation|keyboard"/>
    </application>

</manifest>