search

Subscription activation - All-in-One SDK

The All-in-One SDK is intended to make payments seamless with Paytm irrespective of whether the Paytm app is installed on a device or not. This SDK handles the following 2 flows:

  1. App Invoke Flow: If the Paytm App is installed on a mobile device, it gets launched to complete the subscription activation and sends back the result to the merchant app.
     
  2. Redirection Flow: If the Paytm App is not installed on a mobile device, a webview opens to complete the subscription activation and sends back the result to the merchant.
     

Note: You can Integrate All-in-One payment solution via non SDK app invoke, where you invoke the Paytm app using a deeplink (if Paytm App is installed on user’s device) or redirect the user to Paytm’s hosted payment page (if Paytm App is not installed). For more details, click here.

Demo

Overview

  1. This flow starts when after the user has selected the plan and you have obtained the transaction token using the Initiate Subscription API
  2. Launch Paytm All-in-One SDK with the Transaction Token. If the Paytm app is installed on the user's mobile device, the subscription will be completed on the Paytm app, else it will be processed via web view within the All-in-One SDK (Paytm hosted redirection flow).
  3. The customer enters the payment details to complete the authorization. Post completing the authorization & the first payment, the SDK would confirm the status on your app.
  4. Use the Subscription S2S Callback or Fetch Subscription Status API to confirm the subscription and display the confirmation to the user on your app/website.
     

Flow diagram to show the subscription activation via All-in-one-SDK
 

Integration Steps

  1. Include Dependency

    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.2’
      
  2. Creation of Order object

    Create an order object as follows, passing the mandatory parameters.
     
    PaytmOrder paytmOrder = new PaytmOrder (orderid, mid, txnToken, amount, callbackurl)
     
    ATTRIBUTES DESCRIPTION MANDATORY
    orderid
    String(50)
    A unique reference ID generated by a merchant for the transaction. The special characters allowed in Order ID are "@" "-" "_" ".". Yes
    mid
    String(20)
    Unique identifier provided to every merchant as a part of their account credentials by Paytm. It is different in the staging and production environment. Yes
    txnToken
    String
    Transaction Token received by calling the Initiate Transaction API.
    (Note - Pass the same Order ID in the SDK that was used to initiate the transaction).
    Yes
    amount
    String
    Amount in INR payable by customer. It must contain digits up to two decimal points without any separator like (","). Yes
    callbackurl
    String(255)
    On completion of a transaction, Paytm payment gateway sends 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
  3. Creation of TransactionManager object

    Create an object of TransactionManager className and pass PaytmOrder object created in step 1 along with the callback interface to receive results for redirection (webview flow)
    TransactionManager transactionManager = new TransactionManager(paytmOrder, 
    new PaytmPaymentTransactionCallback() // code statement);
    transactionManager.setSubscriptionFlow(true);
  4. Starting a Transaction

    Start a transaction passing requestCode to listen for All-in-One SDK flow in onActivityResult.
     
    transactionManager.startTransaction(this, 01); 01=sample requestcode
  5. Retrieval of payment status result

    1. App Invoke flow (If the transaction is processed via Paytm App)
      For app invoke flow, the result will be delivered via onActivityResult in your activity.
      Merchant has to pass the same request code which is used while calling TransactionManager.startTransaction.
      In our example above we have used 01 as requestCode.
      @Override
                  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
                      if (requestCode == 01 && 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 payment status will be delivered via PaytmPaymentTransactionCallback. This interface has multiple methods to get error or completion status of the transaction as shown below.
      public void onTransactionResponse(Bundle inResponse) {
                      /*Display the message as below */
                      Toast.makeText(getApplicationContext(), "Payment Transaction response"  + 
                      inResponse.toString(), Toast.LENGTH_LONG).show();
                  }
  6. Fetching the latest subscription status

    Paytm will provide an S2S callback on your configured callback URL. Alternatively, you use a Fetch Subscription Status API to fetch the latest status.

 

Note: Get the latest Paytm All-in-one SDK for iOS here.

Step 1: Call openPaytm method with following mandatory parameters

AIHandler().openPaytm(merchantId: merchantId, orderId: orderId, txnToken: token, amount: amount, callbackUrl : callback_url, delegate: self)


Delegate is a type of AIDelegate which have 2 protocols.

public protocol AIDelegate {
    func openPaymentWebVC(_ controller: UIViewController?)
    func didFinish(with status: PaymentStatus, response: [String:Any])
}

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

  1. In case Paytm app does not exist then user has to implement delegate methods of AIDelegate. openPaymentWebVC will provide the merchant 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)
                }
            }
        }
    }
    
    AIHandler().openPaytmSubscription(merchantId: String, orderId: String, txnToken: String, amount: String, callbackUrl: String?, delegate: AIDelegate)

Step 3 : In case merchant don’t have callback URL, Add an entry into Info.plist LSApplicationQueriesSchemes(Array) Item 0 (String)-> paytm

iosinvoke

  • Add a URL Scheme “paytm”+”MID”

    app-invoke
  • Define the app delegate method to handle Paytm response. 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
    }