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 two 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 https://developer.paytm.com/docs/subscription/.

  1. On your mobile app, the user adds goods/services into the shopping/order cart and proceeds to checkout. You call Initiate Transaction API from your backend to generate 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 starting the integration make sure, you follow the following steps:

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

  2. Get the merchant Id and merchant key for the integration environment after creating the account.

  3. Go through the checksum logic to understand how to generate and validate the checksum.

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

Integration Steps for SDK based integration

  1. Add Dependencies 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:1.5.3'

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

      Please refer to the table below for other supported versions.
       

      appinvokesdk version Features Status
      appinvokesdk version 1.5.3 PlayStore app rejection handled - insecure encryption in EasyPay Published
      appinvokesdk version 1.5
      1. Redirection page bug fixes

      2. Subscription support added

      Available on request
      appinvokesdk version 1.4 Fixed several exceptions like TransactionTooLargeException, !! FAILED BINDER TRANSACTION !! and some Null Pointer Exceptions. Available on request
      appinvokesdk version 1.3 Handling of Invalid Checksum Hash Exception in redirection flow. Available on request
  2. Call 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 below params:
    "enablePaymentMode" : [{
        "mode":"UPI",
        "channelse":["UPIPUSH"]
    }]
  3. Create an order object as following, passing 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: "@" "-" "_" ".". 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 received from calling Initiate Transaction API (Note - pass same order id in SDK which was used for initiateTransaction). 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 can be a 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. Start the transaction passing requestCode to listen for All-in-One SDK flow in onActivityResult.
    transactionManager.startTransaction(this, requestCode);
  6. Getting payment status result.
    1. App Invoke flow i.e. if a 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 the 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
      }]
  7. Paytm provides payment response on both Callback URL and Webhook URL. Please refer to the sample response for different payment sources here.

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