search

All-in-One SDK Integration for Ionic platform

For merchants who have built their app on an ionic platform - Paytm provides a bridge for you to conveniently integrate All-in-One SDK for both Android and iOS. In this document, we will highlight the steps required to integrate All-in-One SDK with an ionic bridge for your app. This bridge helps you to build a seamless and responsive checkout experience for your iOS or Android application.

This integration will support 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 your app.
  • Redirection Flow: In case the Paytm app is not installed, All-in-One SDK will open a web view to process transactions and give results to you.

Overview of payment processing via ionic bridge

  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 the Hybrid app bridge to invoke 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 the 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. 

Pre-requisites

  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.

  5. Go through All-in-One SDK documentation before proceeding with integration.

  6. Call Initiate Transaction API from your backend to generate Transaction Token.

Integration on Ionic for All-in-One SDK

Please go through the following steps to integrate All-in-One SDK in your Ionic app:


Steps for Capacitor Project

  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'
  3. Add AllInOneSDKPlugin class in project (see Appendix at the end of this document), and then in the MainActivity, use add function in OnCreate ( add(AllInOneSDKPlugin.class) ).

  4. Update setResult method in AllInOneSDKPlugin class as per your response requirement in the ionic app.

  5. Call startTransaction method from your Ionic app to invoke Paytm module.

For further queries visit the SDK based integration documentation.

 

Steps for Ionic Project

  1. Using plugin from ‘@capacitor/core’ fetch AllInOneSDKPlugin class.
    import { Plugins } from "@capacitor/core";
    const { AllInOneSDKPlugin } = Plugins;
  2. Start the process by calling AllInOneSDKPlugin.startTransaction with the appropriate parameters.
    let response = await AllInOneSDKPlugin.startTransaction({
        mid: mid, orderId: orderId, txnToken: txnToken, amount: amount,
        isStaging: isStaging, callbackUrl: callbackUrl 
    });
    Attributes Description Mandatory

    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

    orderid

    String(50)

    Unique reference ID for a transaction which is generated by merchant Special characters allowed in Order ID are: "@" "-" "_" ".". 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

    IsStaging

    Boolean

    IsStaging is to define staging or production server (True for staging and False for production) Yes

    callbackurl

    String(255)

    On completion of 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
  3. Callback will be received in the above “response” object in JSObject format. 
    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
    }]
  4. Verifying Payment

    1. You should validate the transaction response via a server-side request using the 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.

    2. Paytm provides payment response on both Callback URL and Webhook URL. Please refer to the sample response for different payment sources here.

 

Appendix

AllInOneSDKPlugin class

package;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import com.getcapacitor.JSObject;
import com.getcapacitor.NativePlugin;
import com.getcapacitor.Plugin;
import com.getcapacitor.PluginCall;
import com.getcapacitor.PluginMethod;
import com.paytm.pgsdk.PaytmOrder;
import com.paytm.pgsdk.PaytmPaymentTransactionCallback;
import com.paytm.pgsdk.TransactionManager;

@NativePlugin(requestCodes = {AllInOneSDKPlugin.REQ_CODE})

public class AllInOneSDKPlugin extends Plugin {
    protected static final int REQ_CODE = 0;

    @PluginMethod
    public void startTransaction(PluginCall call) {
        saveCall(call);
        String orderId = call.getString("orderId");
        String mid = call.getString("mid");
        String txnToken = call.getString("txnToken");
        String amount = call.getString("amount");
        String callbackUrl = call.getString("callbackUrl");
        boolean isStaging = call.getBoolean("isStaging");
        if (orderId == null || mid == null || txnToken == null || amount == null ||
        orderId.isEmpty() || mid.isEmpty() || txnToken.isEmpty() || amount.isEmpty()) {
            if (txnToken == null || txnToken.isEmpty()) {
                Toast.makeText(getContext(), "txnToken error", Toast.LENGTH_LONG).show();
            } 
            else {
                Toast.makeText(getContext(), "Please enter all field", Toast.LENGTH_LONG).show();
            }
            return;
        }
        String host = "https://securegw.paytm.in/";
        if (isStaging) {
                host = "https://securegw-stage.paytm.in/";
        }
        if(callbackUrl == null || callbackUrl.trim().isEmpty()) {
                callbackUrl = host + "theia/paytmCallback?ORDER_ID=" + orderId;
        }

        PaytmOrder paytmOrder = new PaytmOrder(orderId, mid, txnToken, amount, callbackUrl);
        TransactionManager transactionManager = new TransactionManager(  paytmOrder, new PaytmPaymentTransactionCallback() {

            @Override
            public void onTransactionResponse(Bundle bundle) {
                Log.d("LOG", "Payment Transaction is successful " + bundle);
                setResult("Payment Transaction response " + bundle.toString(), call);
            }

            @Override
            public void networkNotAvailable() {
                setResult("networkNotAvailable", call);
            }

            @Override
            public void onErrorProceed>(String s) {
                setResult(s, call);
            }

            @Override
            public void clientAuthenticationFailed(String s) {
                setResult(s, call);
            }

            @Override
            public void someUIErrorOccurred(String s) {
                setResult(s, call);
            }

            @Override
            public void onErrorLoadingWebPageString inFailingUrl) {
                setResult(inErrorMessage, call);
            }

            @Override
            public void onBackPressedCancelTransaction() {
                setResult("onBackPressedCancelTransaction", call);
            }


            @Override
            public void onTransactionCancel(String s, Bundle bundle) {
                setResult(s + " " + bundle, call);
            }
        });
        transactionManager.setShowPaymentUrl(host + "theia/api/v1/showPaymentPage");
        transactionManager.startTransaction(getActivity(), REQ_CODE);
    }

    @Override
    protected void handleOnActivityResult(int requestCode, int resultCode, Intent data) {
        super.handleOnActivityResult(requestCode, resultCode, data);
        if (requestCode == REQ_CODE && data != null) {
            PluginCall call = getSavedCall();
            setResult(data.getStringExtra("nativeSdkForMerchantMessage") + 
            data.getStringExtra("response"), call);
        }
    }

    private void setResult(String message, PluginCall call) {
        if (call != null) {
            JSObject result = new JSObject();
            result.put("result", message);
            call.resolve(result);
        } 
        else {
            Toast.makeText(getContext(), "call is null", Toast.LENGTH_LONG).show();
        }
    }
}