search

SDK based integration

SDK based integration for All-in-One payment solution allows you to integrate the SDK in your native apps for both Android and iOS apps. The integration lets your customers make seamless payments with Paytm regardless of Paytm app being installed on device or not.

This SDK supports the following flows:

  • App Invoke Flow: In case the Paytm app is installed, it will be launched to complete the transaction and give the result back to the merchant app.

  • Redirection Flow: In case the Paytm app is not installed, All-in-One SDK will open web-view to process transaction and give result to the merchant.

Overview of payment processing via SDK based integration

Note: This page describes the integration steps for integrating All-in-One payment solution for one time payment. In case you want to integrate the same for recurring payments, please refer to the Paytm Subscription.

  1. On your mobile app, the user adds goods/services into the shopping/order cart and proceeds to checkout. You call the Initiate Transaction API from your backend to generate the transaction tokens.

    Within the Initiate Transaction API, you also get an option to include single or multiple payment sources for the users, thus allowing you to make your own payment page with multiple payment sources.

  2. Launch Paytm All-in-One SDK with the transaction token received in step 1.

  3. If Paytm app is installed on user's phone, the payment will be completed on Paytm app using the user's saved credentials else transaction will be processed via web view within the All-in-One SDK(Paytm hosted redirection flow).

  4. Paytm processes the transaction with the user’s bank and returns transaction response to your app.

  5. You call the Transaction Status API to verify the transaction response.

  6. Notify the payment status to the user and proceed with the order/service fulfilment.

 

Flow diagram for payment processing via SDK based integration

Pre-requisites

Before you begin the integration, make sure you follow the steps below:

  1. Create an account on Paytm as a merchant. Click how to create an account.

    Note: Save the MID and merchant key generated in the above step.
  2. Go through the checksum logic to understand how to generate and validate the checksum.

  3. Get the staging android or iOS Paytm app for integration testing on the merchant staging environment.

Integration Steps for SDK based integration

Note:

  1. Download the paytm staging app from here and install it. Login on the staging app with credentials 7777777777 and static otp 888888.
  2. To help you with the integration, we have provided a sample merchant app integrated with this SDK. To get the sample app, please click here.
  1. Add Dependencies for All-in-One SDK

    1. Add the line below to ‘repositories’ section of your project level build.gradle file.

      maven {
          url "https://artifactory.paytm.in/libs-release-local"
      }
    2. Add the line below to ‘dependencies’ section of your app build.gradle.

      implementation 'com.paytm.appinvokesdk:appinvokesdk:1.6.15'

      Please refer to the table below for other supported versions:

      appinvokesdk version Features Status
      com.paytm.appinvokesdk:appinvokesdk:1.6.17 Bug Fixed Published
      com.paytm.appinvokesdk:appinvokesdk:1.6.16 Bug Fixed Published
      com.paytm.appinvokesdk:appinvokesdk:1.6.15 Bug Fixed Published
      com.paytm.appinvokesdk:appinvokesdk:1.6.14 Removed unused READ_PHONE_STATE permission Published
      com.paytm.appinvokesdk:appinvokesdk:1.6.13 Bug Fixed Published
      com.paytm.appinvokesdk:appinvokesdk:1.6.5 Support of EMI subvention for Paytm users on app versions older than 9.10.0 Published
      com.paytm.appinvokesdk:appinvokesdk:1.6.4 Fixes - In redirection flow, on android back button cancel dialog. On cancelled call close order api Removed Unused permissions Published
      com.paytm.appinvokesdk:appinvokesdk:1.6.3 Enabled Redirection flow when Paytm App is not logged in Published
      com.paytm.appinvokesdk:appinvokesdk:1.5.3 PlayStore app rejection handled - insecure encryption in EasyPay Published
      Note: To support PSP Apps (UPI Intent) on redirection flow or to invoke Paytm app for Target SDK version 30 ( Android 11) and above. Please use AllInOneSDK version 1.6.3 or latest.
    3. Download the paytm staging app from here and install it. Login on the staging app with credentials 7777777777 and static otp 888888.
  2. Call the Initiate Transaction API from your backend to generate Transaction Token.
    In case you want to allow/show specific payment sources, pass the enablePaymode param in the Initiate Transaction API as depicted below. This feature will enable you to create your own cart payment page with multiple payment sources. Please refer to the Initiate Transaction API documentation for all possible payment sources that can be enabled.

    For Example, if you want to enable UPI as the only paymode, then pass the parameters below within the Initiate Transaction API.
    "enablePaymentMode" : [{
        "mode":"UPI",
    }]
    If you want to use only UPI Intent within All-in-One SDK, pass the below params:
    "enablePaymentMode" : [{
        "mode":"UPI",
        "channels":["UPIPUSH"]
    }]
  3. Create an order object as following, passing the mandatory parameters.
    PaytmOrder paytmOrder = new PaytmOrder(orderid, mid, txnToken, amount, callbackurl)
    Attributes Description Mandatory

    orderid

    String(50)

    Unique reference ID for a transaction which is generated by merchant Special characters allowed in Order ID are: "@" "-" "_" ".".

    Note - pass same order Id in SDK which was used for initiateTransaction

    Yes

    mid

    String(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

    txnToken

    String

    Transaction token in response to the Initiate Transaction API request. Yes

    amount

    String

    Amount in INR payable by the customer. Should contain digits up to two decimal points. The amount should not include any separator like (",") Yes

    callbackurl

    String(255)

    On completion of the transaction, Paytm Payment Gateway will send the response on this URL. This URL should be same as passed in callbackURL of Initiate Transaction API. It can be a dynamic or static response URL as mentioned below:
    • 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
  4. 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);
  5. For app invoke restriction (Only Redirection flow when false else AppInovke if paytm app is installed).
    transactionManager.setAppInvokeEnabled(false)
  6. For doing transaction on merchant staging
    transactionManager.setShowPaymentUrl("https://securegw-stage.paytm.in/theia/api/v1/showPaymentPage");
    
  7. Call this method if EMI subvention is integrated and need to be offered for this transaction
    transactionManager.setEmiSubventionEnabled(true);
    
  8. Start the transaction passing requestCode to listen for All-in-One SDK flow in onActivityResult.
    transactionManager.startTransaction(this, requestCode);
  9. In case of enabling Redirection flow when Paytm App is not logged in, use the below method-
    transactionManager.startTransactionAfterCheckingLoginStatus(this, clientId, requestCode);
  10. Getting payment status result.
    1. App Invoke flow i.e. if a transaction is processed via Paytm app

      For App Invoke, the 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 the user’s device)

      For redirection flow, the status of Payment will be delivered via PaytmPaymentTransactionCallback. This interface has multiple methods as given below to get an error or completion status of the transaction.
      //this function gets called with a response after the payment is done or canceled.
      void onTransactionResponse(@Nullable Bundle inResponse){
           Toast.makeText(getApplicationContext(), "Payment Transaction response " + inResponse.toString(), Toast.LENGTH_LONG).show();
      }
      
      //this function gets called with an error message and response bundle when there is any error while starting the payment.
      void onTransactionCancel(String inErrorMessage,@Nullable Bundle inResponse){
      }
      
      //this function gets called when there is an error in loading a web page or exception in response that needs to be sent to the merchant.
      void onErrorLoadingWebPage(int iniErrorCode, String inErrorMessage, String inFailingUrl){
      }
      
      // this function gets called when any ui element throws an error while loading.
      void someUIErrorOccurred(String inErrorMessage) {
      }
      
      
      //this function gets called when there is no network available.
      void networkNotAvailable(){
      }
      
      //this function gets called when there is an error message while starting the payment. 
      void onErrorProceed(String error){
      }
      

      Sample Response

      "Bundle"[
         {
            "STATUS"="TXN_SUCCESS",
            "ORDERID"="Order Id",
            "CHARGEAMOUNT"="0.00",
            "TXNAMOUNT"="1.00",
            "TXNDATE"="2020-07-21 19:00:05.0",
            "MID"="Merchant Id",
            "TXNID"="Transaction Value",
            "RESPCODE"="01",
            "PAYMENTMODE"="UPI",
            "BANKTXNID"="Bank transaction Id",
            "CURRENCY"="INR",
            "GATEWAYNAME"="ICICI",
            "RESPMSG"="Txn Success"
         }
      ]
  11. Paytm provides payment response on both Callback URL and Webhook URL. Please click here for more details.
  12. Mandatory: Ensure you re-verify transaction response with Transaction Status API (OR Fetch Subscription Status API in case of subscription payments) via server to server call in payment flow and not separately as a one-time activity.
Note:

In case of Okhttp Exception, make the following changes to your build.gradle (app level):

  • Exclude okhttp from the app invoke SDK
    implementation('com.paytm.appinvokesdk:appinvokesdk:1.5.4'){
        exclude group: "com.squareup.okhttp3", module: 'okhttp3'
    }
  • If okhttp is not added in your project dependencies then add
    implementation "com.squareup.okhttp3:okhttp:4.8.0"
 

Note:

  1. Get the latest Paytm All-in-one SDK for iOS here.
  2. Download the paytm staging app from here and install it. Login on the staging app with credentials 7777777777 and static otp 888888.
  3. To help you with the integration, we have provided a sample merchant app integrated with this SDK. To get the sample app, please click here.
  1. Call the Initiate Transaction API from your backend to generate Transaction Token.
    In case you want to allow/show specific payment sources, pass the enablePaymode param in the Initiate Transaction API as depicted below. This feature will enable you to create your own cart payment page with multiple payment sources. Please refer to the Initiate Transaction API documentation for all possible payment sources that can be enabled.

    For Example, if you want to enable UPI as the only paymode, then pass the below parameters within Initiate Transaction API.
    "enablePaymentMode" : [{
        "mode":"UPI",
    }]
    If you want to use only UPI Intent within All-in-One SDK, pass the params below:
    "enablePaymentMode" : [{
        "mode":"UPI",
        "channels":["UPIPUSH"]
    }]
  2. Call the openPaytm method with following mandatory parameters.
    Delegate is a type of AIDelegate which have 2 protocols.
    self.appInvoke.openPaytm(merchantId: merchantId, orderId: orderId, txnToken: txnToken, 
    amount: amount, callbackUrl: callback, delegate: self, environment: env, urlScheme: urlScheme)
    Attributes Description Mandatory

    merchantId

    String(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

    orderid

    String(50)

    Unique reference ID for a transaction which is generated by merchant Special characters allowed in Order ID are: "@" "-" "_" ".".

    Note - pass same order Id in SDK which was used for initiateTransaction

    Yes

    txnToken

    String

    Transaction token in response to the Initiate Transaction API request. Yes

    amount

    String

    Amount in INR payable by the customer. Should contain digits up to two decimal points. The amount should not include any separator like (",") Yes

    callbackurl

    String(255)

    On completion of the transaction, Paytm Payment Gateway will send the response on this URL. This URL should be same as passed in callbackURL of Initiate Transaction API. It can be a dynamic or static response URL as mentioned below:
    • 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

    delegate

    AIDelegate

    Merchant gets the Callback of transaction status in AIDelegate in case the app is not installed. No

    environment

    AIEnvironment

    User has to set the environment in which he is testing. It has 2 values.
    • production
    • staging
    No

    urlScheme

    String(255)

    Merchant has to provide us with a unique Identifier.
    Since iOS doesn't support call back inherently, we will do the following things:
    • For merchants who can give us the urlScheme for a callback, we will return transaction status, error string & response data in the callback. A standard urlScheme API design will be provided by us with few free fields to cater to merchant needs. like “merchantScheme://”.
    • For merchants who can't provide urlScheme, they can use URL schemes like Add a URL Scheme "paytm"+"MID" for more info go through step 4
    Note:This is only for iOS.
    No
  3. In case the Paytm app is not installed, redirect the user to Paytm hosted Checkout Page.
    1. As of now, an order is created in your order system and the transaction token is also generated using Initiate Transaction API.
    2. In case Paytm app does not exist then the user has to implement delegate methods of AIDelegate. openPaymentWebVC will provide the merchant with the controller to present/push which handles the Paytm hosted checkout page as described below.
      / MARK: - AIDelegate
      extension ViewController: AIDelegate {
          func openPaymentWebVC(_ controller: UIViewController?) {
              if let vc = controller {
                  DispatchQueue.main.async {[weak self] in
                      self?.present(vc, animated: true, completion: nil)
                  }
              }
          }
      }
  4. In case the merchant doesn’t have callback URL, add an entry into Info.plist. LSApplicationQueriesSchemes(Array) Item 0 (String)->paytm.

    1. Add a URL Scheme “paytm”+”MID”.

    2. Define the app delegate method to handle Paytm response. The client will get the response in Appdelegate Method.
      func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
          let dict = separateDeeplinkParamsIn(url: url.absoluteString, byRemovingParams: nil)
          //get paytm params from dictionary
          return true
      }
    3. Now we are also supporting UPI intent in the web view of All in One SDK(Native). As of now we are supporting Paytm, Phonepe and Google Pay. To configure the same add schema of the apps into Info.plist LSApplicationQueriesSchemes(Array).
  5. Paytm provides payment response on both Callback URL and Webhook URL. Please click here for getting more details on this.
  6. Mandatory: Ensure you re-verify transaction response with Transaction Status API (OR Fetch Subscription Status API in case of subscription payments) via server to server call in payment flow and not separately as a one-time activity.

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 the test paymodes credentials.
  2. See the transaction details in the "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.