Integrating Paytm Wallet SDK in an Android Application

08 / Feb / 2016 by Ashish Mishra 38 comments

How Paytm SDK Work

The Paytm Payments SDK for iOS and Android enables merchants to integrate payments into their mobile app. The following diagram describes how a typical payment transaction works. The components involved in completing a payment transaction are as follows:

  • User Placing the Order: The end user who wants to initiate a payment transaction.
  • Merchant Application: The Application of the merchant where the Paytm Wallet needs to be integrated. This may be an Android or iOS application.
  • Paytm SDK: The SDK provided by Paytm to make all the API calls to Payment Gateway and Merchant’s Web server (which is explained in the next point).
  • Merchant’s Web server: The merchant needs to setup this web server at their end. The logic to generate and verify CheckSum needs to be setup on this server. Checksum helps ensure the integrity of transactions i.e. it helps ensure that the transaction requests have not been intercepted and tampered with. Checksum utilities are provided by Paytm for different development platforms.
  • Payment Gateway: 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 Gateway will interact with the Banks as well.

SDK Flow

Steps for Android Integration

Step are given below.

  • download PGSDK library from http://paywithpaytm.com/developer/#web_plugin or
  • Client side certificate (Optional :provide by PAYTM Web).
    Password for the Client side certificate. (Optional: provided by PAYTM Web).
    Add Client side certificate file inside raw folder. If raw folder is not there then create raw folder within “res” folder.
  • Add the INTERNET and ACCESS_NETWORK_STATE permissions to your AndroidManifest.xml. These two permissions are required for PGSDK Service to run. AndroidManifest.xml <uses-permission android:name=”android.permission.INTERNET”/>
    <uses-permission android:name=”android.permission.ACCESS_NETWORK_STATE”/>
  • Add PaytmPGActivity in your AndroidManifest.xml and this activity already present in your PGSDK.This Activity perform all transaction related information and provide you callback.

AndroidManifest.xml

<activity
android:name=”com.paytm.pgsdk.PaytmPGActivity”
android:configChanges=”keyboardHidden|orientation|keyboard”
/>

How to use API

  1. Obtain the PaytmPGService instance. Either obtain Staging service or obtain Production service depending on your need. PaytmPGService.getStagingService() will return the Service Object pointing to Staging Environment.PaytmPGService.getProductionService() will return the Service Object pointing to Production Environment.
  2. Create PaytmOrder Object holding the Order Information. Syntax for creating PaytmOrder Object is as follows:

PaytmOrder Order = new PaytmOrder(Map<String, String> paramMap);

Where,
paramMap is the map containing request parameter names and their respective values. Please refer Example given in the next sub-section.

  1. Create PaytmMerchant Object holding the Merchant Configuration. Syntax for creating PaytmMerchant Object is as follows:

PaytmMerchant Merchant = new PaytmMerchant(String inChecksumGenerationURL, String inChecksumVerificationURL);

where,
inChecksumGenerationURL is the Merchant Checksum Generation URL and
inChecksumVerificationURL Merchant Checksum Verification URL

  1. Create PaytmClientCertificate Object holding the Certificate information. This step is conditional. Only if the client certificate is requested and used by merchant (as given in Prerequisites section above), then create the PaytmClientCertificate object. Otherwise pass the PaytmClientCertificate as null. Syntax for creating PaytmClientCertificate Object is as follows:

PaytmClientCertificate Certificate = new PaytmClientCertificate(String inPassword, String inFileName);

where,
inPassword is the Client side certificate password
inFileName is the Client side certificate file name. This file must be present inside “raw” folder.

  1. Call the initialize() method to set PaytmOrder, PaytmMerchant and PaytmClientCertificate Objects. Method Signature is as follows:

void com.paytm.pgsdk.PaytmPGService.initialize(PaytmOrder inOrder, PaytmMerchant inMerchant, PaytmClientCertificate inCertificate);

inOrder  is the Object which is holding Order Information.
inMerchant  is the Object which is holding Merchant Configuration.
inCertificate is the Object which is holding Certificate Information. Pass this as null if no client certificate is used by the merchant (as given above in the Prerequisites section

Example-

//Getting the Service Instance. PaytmPGService.getStagingService()  will return the Service pointing to Staging Environment and PaytmPGService.getProductionService() will return the Service pointing to Production Environment.
PaytmPGService Service = null;
Service = PaytmPGService.getStagingService();
//or
Service = PaytmPGService.getProductionService();
//Create new order Object having all order information.
Map<String, String> paramMap = new HashMap<String, String>();
paramMap.put("REQUEST_TYPE", "DEFAULT");
paramMap.put("ORDER_ID", ‘ORDER12345’)
paramMap.put("MID", "klbGlV59135347348753");
paramMap.put("CUST_ID”,’CUST110’)
paramMap.put("CHANNEL_ID", "WAP");
paramMap.put("INDUSTRY_TYPE_ID", "Retail");
paramMap.put("WEBSITE", "paytm");
paramMap.put("TXN_AMOUNT", "1.0");
paramMap.put("THEME ", "merchant");

PaytmOrder Order = new PaytmOrder(paramMap);
//Create new Merchant Object having all merchant configuration.
PaytmMerchant Merchant = new PaytmMerchant( "http://hostname/<checksum-gerneration-URL>", " http://hostname/<checksum-verification-URL>");

//Set PaytmOrder and PaytmMerchant objects. Call this method and set both objects before starting transaction.
Service.initialize(Order, Merchant, null);

//Start the Payment Transaction. Before starting the transaction ensure that initialize method is called.
Service.startPaymentTransaction(this, true, true, new PaytmPaymentTransactionCallback()
{
  @Override
  public void someUIErrorOccurred(String inErrorMessage)
  {
  // Some UI Error Occurred in Payment Gateway Activity.
  // This may be due to initialization of views in Payment Gateway Activity or may be due to initialization of webview.
  // Error Message details the error occurred.
  }
  
  @Override
  public void onTransactionSuccess(Bundle  inResponse)
  {
    // After successful transaction this method gets called.
    // Response bundle contains the merchant response parameters.
  }
  
  @Override
  public void onTransactionFailure(String inErrorMessage, Bundle  inResponse)
  {
    // This method gets called if transaction failed.
    // Here in this case transaction is completed, but with a failure.
    // Error Message describes the reason for failure.
    // Response bundle contains the merchant response parameters.
  }
  
  @Override
  public void networkNotAvailable()
  {
  // If network is not available, then this method gets called.
  }
  
  @Override
  public void clientAuthenticationFailed(String  inErrorMessage)
  {
  // This method gets called if client authentication failed.
  // Failure may be due to following reasons
  //      1. Server error or downtime.
  //      2. Server unable to generate checksum or checksum response is 
  //         not in proper format.
  //      3. Server failed to authenticate that client. That is value of
  //         payt_STATUS is 2.
  // Error Message describes the reason for failure.
  }
  
  @Override
  public void onErrorLoadingWebPage(int iniErrorCode, String inErrorMessage, String inFailingURL)
  {
  // This page gets called if some error occurred while loading some URL in Webview.
  // Error Code and Error Message describes the error.
  // Failing URL is the URL that failed to load.
  }
  });

Test your  transactions:

The following Staging Wallet can be used for testing transactions:
Mobile number: 7777777777
Password: Paytm12345
OTP – 489871

Response Codes

Interpretation of the most common response codes can be found below:

  • 101-  Transaction Successful
  • 141-  Transaction cancelled by customer after landing on Payment Gateway Page.
  • 227-  Payment Failed due to a technical error. Please try after some time.
  • 810-  Page closed by customer after landing on Payment Gateway Page.
  • 8102-   Transaction cancelled by customer post login. Customer had sufficient Wallet balance for completing transaction.
  • 8103-  Transaction cancelled by customer post login. Customer had in-sufficient Wallet balance for completing transaction.
FOUND THIS USEFUL? SHARE IT

comments (38)

  1. sandeep

    is this is the sdk that can pay my users money through PAYTM when they complete the tasks which i have give
    does anyone came through this ? if yes please reply

    Reply
  2. Harvi Patel

    Hello
    I am using your way to integrate in android app in my code There some this type of error can occure An Oops! moment Payment failed due toany of these reasons: Session expired due to inactivity You double-clicked on a button our system encountered an obstacle

    Reply
  3. Sourabh Patil

    Hello sir,
    I’m implementing paytm payment gateway in my app but some error occurs that shown in attachment image.i also generate merchant id,merchant key,also authorise username and password.
    I think problem occurs in app url because i give the app url that is my play store app url link. thats why cannot generate payment gateway page please help me..

    Reply
  4. Varun Dagur

    Hi, friends i am integrating the paytm payment gateway with sdk 2.0.1 with test details in my android app. but when i click start transaction button its load paytm screen with oops error. kindly guide me what i am missing.

    Reply
    1. Ashish Mishra

      Please check in callback method for error .They provide response in override method and its cause.
      Please read those carefully and you will find cause.

      Reply
      1. Varun Dagur

        i place the toast and log in the all callback method but not any toast is showing and not the log is display on logical

        Reply
        1. Ashish Mishra

          Then you need to check you checksum-verification-URL and checksum-gerneration-URL because they are not able to communicate with paytm server.

          Reply
      2. Mehul Prajapati

        Dear Ashish,
        I have integrate paytm many times and this time I am stuck.
        In sample android app, it has set static checksum string.
        Can you please explain why it has static checksum string.
        if it should be dynamic than please also provide that code and update in git.
        I have done many experiments but, it is always says “OOPS”.
        I have used git code and not changed the code , only MID,WEBSITE,CALLBACK_URL so, no need to send you my code, I guess.
        Please help me out.

        Reply
    2. Ashish

      Please check param details very carefully and check errors in patym callback methods.

      paramMap.put(“ORDER_ID”, ‘ORDER12345’)
      paramMap.put(“MID”, “klbGlV59135347348753”);
      paramMap.put(“CUST_ID”,’CUST110’)

      Reply
  5. Vinod

    I places generateChecksum.php and verifyChecksum.php files in server and imported paytm sdk in android studio and setted up all necessary keys too and when i click on pay now checksum hash is generating and printing… So how to avoid this and get response from paytm about transaction response

    Reply
  6. Kamal

    Hi,I am developing hybrid mobile app using ionic. I want to integrate paytm payment option in my app . Can you guide me for it ?
    Basically so far I have downloaded Paytm_App_Checksum_Kit_JSP and was proceeding further. As of now I am stuck at place like when my app’s user select Paytm as payment option where should I redirect him ?

    It would be helpful If you can guide me to step by step process of integrating paytm payment option in ionic app.

    Thanks,
    Kamal

    Reply
    1. Nagaraju

      Hi kamal,
      I think we both are sailed on the same boat …, did you get any response regarding your query , if Yes can you please share your knowledge on paytm integration with me..

      Reply
    1. Ashish

      Yes they removed code from github so now you can contact tech team for any issue .They provide you quick response and updated technical doc as well.

      Reply
  7. Saumil Shah

    Is it possible following two things generate from iOS side?
    1. checksum-verification-URL
    2. checksum-gerneration-URL

    Reply
    1. Ashish Mishra

      I am not sure buddy but I think Yes.Because for the mobile app paytm provide these URL.

      For better answer please contact paytm technical team they will provide full detail with documentation.

      Reply
    2. ramneet

      et mc: PGMerchantConfiguration = PGMerchantConfiguration.default()
      //Step 2: If you have your own checksum generation and validation url set this here. Otherwise use the default Paytm urls

      mc.checksumGenerationURL = “https://pguat.paytm.com/paytmchecksum/paytmCheckSumGenerator.jsp”
      mc.checksumValidationURL = “https://pguat.paytm.com/paytmchecksum/paytmCheckSumVerify.jsp”

      Reply
  8. Sudeep

    I am making a app which will have multiple vendor can Paytm SDK to be setup to pay multiple vendor based on what customer selects.

    Reply
  9. abhi

    I am getting ‘Oops message on clicking pay now button. Debug log says : chromium: [WARNING: web_contents_imp.cc(2573)] ran insecure content from analytics.patytm.com/piwik/….
    this content should also be loaded over HTTPS.

    Please help.. its urgent

    Reply
  10. Sagar

    Hi I am using paytm sdk in android app . and i have checksum and payment gateway response url. when I test the checksum url at development and staging using postman/rest client (using urlencode parameters) . Its working but when i test the same with android . I get some error. I am using django at backend . I have compare both the objects sending from app and postman . I have found no diffrence in it . What could be the problem

    Reply
    1. Ashish Mishra

      Please check your request param while sending data from mobile app.
      Paytm provide complete doc how to send data when you are requesting from mobile app.

      Reply
    1. Ashis Mishra

      Please contact PAYTM technical support team they will provide you url inChecksumGenerationURL and inChecksumVerificationURL both.

      Reply
    1. Ashish Mishra

      Hi Rajashree,

      Please let me know if you facing any issue while integrating with IOS sdk.
      You can directly communicate with PAYTM technical team and they will help out.

      Reply
    1. Ashish Mishra

      Through checksum utility you can generate nChecksumGenerationURL and nChecksumVerificationURL .You can check in sdk provided by paytm team for web application.

      Backend developer provide you inChecksumGenerationURL and inChecksumVerificationURL from checksum utility.

      Reply
  11. Ravindra Varpe

    Hello
    I am using your way to integrate in android app in my code getStagingService() working correctly but when we got to production environment then server application show session expired or clear cookies

    plase give some solution

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *