• Getting Started
    • Website Integration
      Mobile Integration (Android/IOS)
      Enterprise Solutions
      Accept Payments
      Process Payments
      Disbursals
      API References
      Webhooks
      Testing
      Refunds
      Guides
      Other Processes

      Paytm All-in-One SDK


      Paytm All-in-One SDK provides a swift, secure and seamless payment experience to your users by invoking the Paytm App (if installed on your user’s smartphone) to complete payment for your order.

      Paytm All-in-One SDK enables payment acceptance via Paytm wallet, Paytm Payments Bank, saved Debit/Credit cards, Net Banking, BHIM UPI and EMI as available in your customer’s Paytm account.If Paytm App is not installed on customer’s device, transaction will be processed via web view within the All-in-One SDK

      Demo of payment through Paytm All-in-One SDK

      Merchant Integration

      Merchant can integrate the above App invoke flow via 2 methods

      1. Integrating All-in-one SDK
      2. Integrating API for App Invoke

      Integration method 1: All-in-One SDK

      This All-in-One SDK is meant for making payments seamlessly with Paytm regardless of Paytm App being installed on device or not.This SDK handles 2 flows :

      1. App Invoke Flow: In case Paytm App is installed, it will be launched to complete the transaction and give the result back to merchant App.
      2. Redirection Flow : In case Paytm App is not installed, All-in-One SDK will open webview to process transaction and give result to merchant.

      Overview of payment processing via Paytm All-in-One SDK


      1. On your mobile App, user adds goods/services into the shopping/order cart and proceeds to checkout.
      2. You call Initiate Transaction API from your backend to generate transaction token.
      3. Initiate Paytm All-in-One SDK with the transaction token received in step 2.
      4. If Paytm App is installed on user's phone,the payment will be completed on Paytm App using user's saved credentials else transaction will be processed via web view within the All-in-One SDK(Paytm hosted redirection flow).
      5. Paytm processes the transaction with the user’s bank and returns transaction response to your App.
      6. You call the Transaction Status API to verify the transaction response.
      7. Notify the payment status to user and proceed with the order/service fulfilment.

      Flow diagram for integration via All-in-One SDK

      app invoke demo

      Integration Steps for All-in-One SDK


      1. Add the below line to ‘repositories’ section of your project level build.gradle file
        maven {
                url "https://artifactory.paytm.in/libs-release-local"
            }
        
      2. Add below line to ‘dependencies’ section of your App build.gradle
        implementation 'com.paytm.appinvokesdk:appinvokesdk:0.6

      Step 1: Call Initiate Transaction API from your backend to generate Transaction Token.

      Step 2: Create order object as following , passing mandatory parameters

      PaytmOrder paytmOrder = new PaytmOrder(orderid, mid, txnToken, amount, callbackurl)
      AttributesDescriptionMandatory
      orderidString(50)Unique reference ID for a transaction which is generated by merchant Special characters allowed in Order ID are: "@" "-" "_" ".".Yes
      midString(20)This is a unique identifier provided to every merchant by Paytm. MID is part of your account credentials and is different on staging and production environment.Yes
      txnTokenStringTransaction token received from calling initiateTransaction API (Note - pass same order id in sdk which was used for initiateTransaction).Yes
      amountStringAmount in INR payable by customer. Should contain digits up to two decimal points. The amount should not include any separator like (",")Yes
      callbackurlString(255)Staging Environment: "https://securegw-stage.paytm.in/theia/paytmCallback?ORDER_ID=<order_id>"
      Production Environment: "https://securegw.paytm.in/theia/paytmCallback?ORDER_ID=<order_id>"
      Yes

      Step 3: Create object of TransactionManager class and pass PaytmOrder object created in step 2 along with callback interface to receive results for redirection (webview flow)

      TransactionManager transactionManager = new TransactionManager(paytmOrder, new PaytmPaymentTransactionCallback() // code statement);

      Step 4: Start the transaction passing requestCode to listen for All-in-One SDK flow in onActivityResult.

      transactionManager.startTransaction(this, requestCode);

      Step 5: Getting payment status result

      1. App Invoke flow i.e. if transaction is processed via Paytm App
        For App Invoke result will be delivered via onActivityResult in your activity.
        Merchant has to pass request code while calling TransactionManager.startTransaction
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == ActivityRequestCode && data != null) {
        Toast.makeText(this, data.getStringExtra("nativeSdkForMerchantMessage") + data.getStringExtra("response"), Toast.LENGTH_SHORT).show();
        }
        }
        
      2. Redirection Flow (Paytm App is not installed on user’s device)
        For redirection flow the status of Payment will be delivered via PaytmPaymentTransactionCallback.
        This interface has multiple methods like below to get error or completion status of the transaction.
        public void onTransactionResponse(Bundle inResponse) {
        /*Display the message as below */
        Toast.makeText(getApplicationContext(), "Payment Transaction response " + inResponse.toString(), Toast.LENGTH_LONG).show();
        }
        

      Sample Response

      Bundle[{
      "indent_size": "4",
      "indent_char": " ",
      "max_preserve_newlines": "5",
      "preserve_newlines": true,
      "keep_array_indentation": false,
      "break_chained_methods": false,
      "indent_scripts": "normal",
      "brace_style": "collapse",
      "space_before_conditional": true,
      "unescape_strings": false,
      "jslint_happy": false,
      "end_with_newline": false,
      "wrap_line_length": "0",
      "indent_inner_html": false,
      "comma_first": false,
      "e4x": false,
      "indent_empty_lines": false
      }]
      

      Integration method 2: API based App invoke


      If you don't want to integrate All-in-One SDK, you can integrate API based App invoke flow

      Overview of App invoke flow integration via APIs

      1. On your mobile App, user adds goods/services into the shopping/order cart and proceeds to checkout.
      2. You call the Initiate Transaction API.
      3. Paytm shares a transaction token with you.
      4. Check if Paytm App is installed on user's phone.
      5. If Paytm App is installed, invoke the App.
      6. User completes payment on the Paytm App using his/her saved credentials.
      7. If Paytm App is not installed, call the Show Payment Page API and redirect the user to Paytm’s hosted payment page.
      8. Paytm processes the transaction with the user’s bank and returns transaction response.
      9. You call the Transaction Status API to verify the transaction response.
      10. Notify the payment status to user and proceed with the order/service fulfilment.

      Flow diagram for API integration of App invoke flow

      flow

      Steps for integration


      STEP 1: Get your authentication keys

      • MID: A unique merchant identifier issued by Paytm for your account

      • Merchant Key:This is a unique secret key used to secure encryption of every request. This needs to be kept on server side and should not be shared with anyone.

      STEP 2: Get Transaction Token

      • When a user clicks Pay with Paytm to checkout on your mobile App, create an order in your backend system and call Initiate Transaction API
      • Paytm validates your details and return the TXN_Token
      • Send this TXN_Token to your website or mobile App

      STEP 3: Invoke Paytm App

      Use the following steps to invoke Paytm App as per your platform:

      Input Parameters

      ATTRIBUTESDETAILSMANDATORY
      amountTotal amount of TransactionYes
      orderIDUnique reference ID for a transaction which is generated by merchant and sent in the request. No special character allowed except ("@" "-","_")Yes
      txnTokenTransaction Token received in the response of Initiate Transaction APIYes
      midThis is a unique identifier provided to every merchant by PaytmYes
      API based App Invoke on Android

      Paytm App invoke using API based integration will depend on the Paytm App version on user's mobile device. First, check the version of Paytm App installed on the user's device using the code below. If the Paytm App version is 8.6.0 or above, App Invoke will have a user experience as the GIF provided above. If the Paytm app version is below 8.6.0 then full screen Paytm App will invoke as shown in the flow diagram below:

      app invoke android
      1. Create Intent to open Paytm Activity on your App. Check the App version on the User’s phone
        Check current Paytm app version
        privateString getPaytmVersion(Context context) {
            PackageManager pm = context.getPackageManager();
            try{
              PackageInfo pkgInfo = pm.getPackageInfo(PAYTM_APP_PACKAGE, PackageManager.GET_ACTIVITIES);
              returnpkgInfo.versionName;
            }catch (PackageManager.NameNotFoundException e) {
                   PaytmUtility.debugLog("Paytm app not installed");
            } 
            return null;
        }
        Compares two version strings.
        <p>
        Use this instead of String.compareTo() for a non-lexicographical
        
        comparison that works for versiorn strings. e.g. "1.10".compareTo("1.6")
         @param str1 a string of ordinal numbers separated by decimal points.
        
        @param str2 a string of ordinal numbers separated by decimal points
        @return The result is a negative integer if str1 is _numerically_ less than str2.
        
        The result is a positive integer if str1 is _numerically_ greater than str2.
        
        The result is zero if the strings are _numerically_ equal.
        
         @note It does not work if "1.10" is supposed to be equal to "1.10.0".
        private int versionCompare(String str1, String str2) {
        if (TextUtils.isEmpty(str1) || TextUtils.isEmpty(str2)) {
               return 1;
           }
           String[] vals1 = str1.split("\\.");
           String[] vals2 = str2.split("\\.");
           int i = 0;
           set index to first non-equal ordinal or length of shortest version string
           while (i < vals1.length && i < vals2.length && vals1[i].equalsIgnoreCase(vals2[i])) {
               i++;
           }
           compare first non-equal ordinal number
           if (i < vals1.length && i < vals2.length) {
               int diff = Integer.valueOf(vals1[i]).compareTo(Integer.valueOf(vals2[i]));
               return Integer.signum(diff);
           }
           the strings are equal or one string is a substring of the other
           e.g. "1.2.3" = "1.2.3" or "1.2.3" < "1.2.3.4"
           return Integer.signum(vals1.length - vals2.length);
        }
        if (versionCompare(currentAppVersion, "8.6.0") < 0) {
        Full screen App Invoke flow
        }else{
        New App Invoke flow
        }
        
        1. If the App version is less than 8.6.0, then use the code below
          Intent paytmIntent = new Intent();
                  Bundle bundle = new Bundle();gues
                  bundle.putDouble("nativeSdkForMerchantAmount", Amount);
                  bundle.putString("orderid", OrderID);
                  bundle.putString("txnToken", txnToken);
                  bundle.putString("mid", MID);
                  paytmIntent.setComponent(new ComponentName("net.one97.paytm", "net.one97.paytm.AJRJarvisSplash"));
                  paytmIntent.putExtra("paymentmode", 2); // You must have to pass hard coded 2 here, Else your transaction would not proceed. 
                  paytmIntent.putExtra("bill", bundle); 
                  startActivityForResult(paytmIntent, ActivityRequestCode);
                  
        2. Else, if the App version is 8.6.0 or greater, then use the code below for new App Invoke flow integration:
          Intent paytmIntent = new Intent();
                  paytmIntent.setComponent(new ComponentName("net.one97.paytm", "net.one97.paytm.AJRJarvisSplash"))
                  paytmIntent.putExtra("paymentmode", 2);
                  paytmIntent.putExtra("enable_paytm_invoke", true);
                  paytmIntent.putExtra("paytm_invoke", true);
                  paytmIntent.putExtra("price", Amount); //this is string amount
                  paytmIntent.putExtra("nativeSdkEnabled", true);
                  paytmIntent.putExtra("orderid", OrderID);
                  paytmIntent.putExtra("txnToken", txnToken);
                  paytmIntent.putExtra("mid", MID);
                  context.startActivityForResult(paytmIntent, requestCode);
                  
      2. Receive output parameters in onActivityResult
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == ActivityRequestCode && data != null) {
        Toast.makeText(this, data.getStringExtra("nativeSdkForMerchantMessage") + data.getStringExtra("response"), Toast.LENGTH_SHORT).show();
        }
        }
        

      STEP 4: In Case Paytm App is not installed, redirect user to Paytm hosted Checkout Page

      1. As of now, an order is created in your order system and transaction token is also generated using Transaction Token.
      2. Post the payload and transaction token in an HTML form. This redirects the user to Paytm's payment page. The payload details are mentioned here.
      3. User fills payment details and completes the payment authentication. Once the payment is complete, response is posted in HTML form POST on your App/website's callback URL.
      4. Verify checksum hash received in response to ensure that it has not been tampered with.

      STEP 5: Verifying Payment

      You should validate transaction response via a server-side request using Transaction status API. This API requires checksumhash in request and response. You must verify the Order ID and Amount with your data. The status should be treated as the final status of the transaction in all cases.

      On completion of your integration

      Post completion of integration on your staging environment, do a complete transaction from order summary page on your website or mobile App

      1. Attempt a test transaction using test paymodes credentials.
      2. Ensure you re-verify transaction response with Transaction Status API via server to server call in payment flow and not separately as a one-time activity.
      3. See the transaction details in "Test Data” mode on your dashboard.

      Once the test transaction is complete, move your code to live environment with production account details. Note that production accounts details are available after you have activated your account on the dashboard. Lastly, it's recommended that you read about Managing Refunds and late payment notifications In case of any issues with integration, please get in touch.