search

All In One SDK integration in Xamarin

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

This integration will support the following flows:

  • App Invoke Flow: In case the Paytm app is installed, it will be launched to complete the transaction and give the response 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 transaction and give the response back to your app.

Overview of payment processing in Xamarin App

  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 transaction token.
    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

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. 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 the Initiate Transaction API from your backend to generate Transaction Token.

Follow the steps below to integrate All-in-One SDK in your Xamarin app:

Project

  1. Add below Nuget package to your project Dependencies/NuGet:
    copy icon
    Paytm.AllInOneSdk

    Note: Please ignore the warning message

    Warning Message

  2. Call plugin method as below:
    copy icon
    using AllInOneSDK;
    …
     public partial class MainPage : ContentPage, PaymentCallback
    {
            public void error(string errorMessage)
            {
                ...
                AllInOnePlugin.DestroyInstance();
            }
    
            public void success(Dictionary<string, object> dictionary)
            {
                ...
                AllInOnePlugin.DestroyInstance();
            }
    
           public void startTransaction()
           {
             AllInOnePlugin.startTransaction(orderId, mid, txnToken, amount, callbackurl, isStaging, restrictAppInvoke, this); // this -> PaymentCallback
           }
    }
    Attributes Description Mandatory

    mid

    String(20)

    A unique identifier which is a part of your account credentials and is provided to every merchant by Paytm. It is different on staging and production environment. Yes

    orderid

    String(50)

    A 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 received in response to Initiate Transaction API request. Yes

    amount

    String

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

    isStaging

    Boolean

    Defines the staging or production server (True for staging and False for production) Yes

    callbackurl

    String(255)

    On completion of the transaction, Paytm Payment Gateway sends 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

    restrictAppInvoke

    Boolean

    restrictAppInvoke is to define app invoke restriction (Only Redirection flow when True else AppInovke if Paytm app is installed) Yes

Follow the steps below to integrate All-in-One SDK in your Xamarin app:

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 below nuget package in android packages
    Android packages
  2. Add below OnActivityResult method in MainAcivity.cs
    copy icon
    using AllInOneSDK;
    ...
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
        ...
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
            {
                base.OnActivityResult(requestCode, resultCode, data);
                AllInOnePlugin.OnActivityResult(requestCode, resultCode, data);
            }
    }
    

Note:Please remove fast assembly Deployment check from Android Build of Android.Project Option

android build

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 the OpenUrl method in AppDelegate.cs and call AllInOnePlugin.handleOpenUrl(url) in it.
    using AllInOneSDK;
    
    public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
        {
           ....
    
            [Export("application:openURL:sourceApplication:annotation:")]
            public bool OpenUrl(UIApplication application, NSUrl url, string sourceApplication, NSObject annotation)
            {
                AllInOnePlugin.handleOpenUrl(url);
                return true;
            }
        }
    
  2. In Info.plist,
    1. In the Source tab, add LSApplicationQueriesSchemes. Change the type to Array. Create a new item in it and set its value as “paytm”.
      LSApplication Queries Schemes
    2. In the Advanced tab, add a new URL Type that you’ll be using as the callback from Paytm app (URL Scheme: “paytm”+”MID”). Example: paytmMid123
      URL Types

Note:

  1. 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"
  2. In case of app crash in release mode add the below proguard rules to your project

    • keep class com.paytm.pgsdk.** { *; }
    • keep class easypay.** { *; }
    • keep class android.support.v7.widget.** { *; }
    • dontwarn android.support.v7.widget.**
    • white_check_mark eyes raised_hands