search

All-in-One SDK Integration in Flutter App

To merchants who have built their app on Flutter platform, Paytm provides a bridge to conveniently integrate All-in-One SDK. On this page, we will highlight the steps required to integrate All-in-One SDK with Flutter 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 Flutter 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

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

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

Integration of All-in-One SDK in flutter app

Please change minSDKversion to ‘18’ in your app level build.gradle file

 
android {
   ...
   defaultConfig {
       ...
       minSdkVersion 18
       ...
   }
}

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.

In Flutter Project

  1. Add this to your package's pubspec.yaml file:
    dependencies:
       ...
      paytm_allinonesdk: ^1.0.0
  2. You can install packages from the command line with Flutter:
    $ flutter pub get
  3. Now in your Dart code, you can use
    import 'package:paytm_allinonesdk/paytm_allinonesdk.dart';
  4. Call plugin method as below:
    var response = AllInOneSdk.startTransaction(
             mid, orderId, amount, txnToken, null, isStaging, restrictAppInvoke);
    response.then((value) {
           print(value);
           setState(() {
             result = value.toString();
           });
     }).catchError((onError) {
           if (onError is PlatformException) {
             setState(() {
               result = onError.message + " \n  " + onError.details.toString();
             });
           } else {
             setState(() {
               result = onError.toString();
             });
           }
     });
    
  5. Callback will be received in ‘then’ method as below else error message will be received in catchError method.

    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
    }]
  6. Verifying Payment
    You should validate 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.