Overview

The eSewa Mobile SDK enables native Android to easily accept eSewa payments. The SDK supports only one use case for making payment – Single Payment (i.e., one payment per one user login).

INSTRUCTIONS

Clients can download the sdk from this drive link.

IMPORTANT: Please make sure your flutter project is migrated to dart sound null safety feature.

  • 1. Extract the zip

  • 2. Copy esewa_flutter_sdk folder to the root of your project

  • 3. Add the sdk path in pubspec.yaml dependencies as follows and run flutter pub get command in terminal:

dependencies:
  flutter:
    sdk: flutter
  esewa_flutter_sdk:
    path: ./esewa_flutter_sdk 

IOS Configuration

Currently, the IOS SDK supports Xcode 15.2.Also, IOS uses two different framework for release/App Store builds and simulator/testing builds.

  • 1. Step-1
    BUILD | TODO RELEASE* | Copy the ios folder from IOS_RELEASE directory to esewa_flutter_sdk folder SIMULATOR | Copy the ios folder from IOS_SIMULATOR directory to esewa_flutter_sdk folder *Used by default

  • 2. Step-2
    Open terminal in your project's ios module path and run pod install and restart your XCODE( Not doing this will show esewa_flutter_sdk import error in GeneratedPluginRegistrant.m file) WARNING: Your IOS app won't build if u use the build desired for simulator in release/App Store builds.

Android Configuration

Step-1

• Go to your project's root folder • Go to android folder > app > src > main > AndroidManifest.xml

inside tag
android:theme="@style/Theme.AppCompat.Light.NoActionBar" 
<uses-permission android:name="android.permission.INTERNET"/>

<application
        android:label="your_app"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar"
        android:icon="@mipmap/ic_launcher"> 
Step-2

Android Gradle plugin & Kotlin version Update.Since, the new android sdk lib comes packaged with AGP 7.0+, you are required to update your flutter project's gradle version to 7+
•Go to your project's root folder •Go to android folder > build.gradle • Add the following:

 dependencies {
      classpath 'com.android.tools.build:gradle:7.0.2'
      classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31'
  } 

• Go to gradle folder > gradle-wrapper.properties •Add the following:

distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip 

•Sync your gradle •Done

How to use SDK for Payment?

eSewa Config
Environment environment  
String      clientId  
String      secretId
 

NOTE: Use Environment.live for live credentials & then client Id and secret Key provided by Esewa Credentials For Test Env

CLIENT_ID = JB0BBQ4aD0UqIThFJwAKBgAXEUkEGQUBBAwdOgABHD4DChwUAB0R  
SECRET_KEY = BhwIWQQADhIYSxILExMcAgFXFhcOBwAKBgAXEQ== 
eSewa Payment
String productId : send unique product Id for the product you are paying for
String productName: name of the product
String amount: amount you are paying
String call-back url (optional) : eSewa sends a copy of proof of payment to this URL after successful payment in live environment. Callback URL is a POST request API(Refer to the developer documentation for it's details)
String ebpNo(optional) : This field is required in case of government payments. 
eSewa Payment Success Result
String productId
String productName
String totalAmount
String environment
String code
String merchantName
String message
String date
String status
String refId 
Transaction Verification
  try {
      EsewaFlutterSdk.initPayment(
        esewaConfig: EsewaConfig(
          environment: Environment.test,
          clientId: CLIENT_ID,
          secretId: SECRET_KEY,
        ),
        esewaPayment: EsewaPayment(
          productId: "1d71jd81",
          productName: "Product One",
          productPrice: "20",
        ),
          onPaymentSuccess: (EsewaPaymentSuccessResult data) {
          debugPrint(":::SUCCESS::: => $data");
          verifyTransactionStatus(data);
        },
        onPaymentFailure: (data) {
          debugPrint(":::FAILURE::: => $data");
        },
        onPaymentCancellation: (data) {
          debugPrint(":::CANCELLATION::: => $data");
        },
      );
    } on Exception catch (e) {
      debugPrint("EXCEPTION : ${e.toString()}");
    }

void verifyTransactionStatus(EsewaPaymentSuccessResult result) async {
    var response = await callVerificationApi(result);
    if (response.statusCode == 200) {
      var map = {'data': response.data};
      final sucResponse = EsewaPaymentSuccessResponse.fromJson(map);
      debugPrint("Response Code => ${sucResponse.data}");
      if (sucResponse.data[0].transactionDetails.status == 'COMPLETE') {
       //TODO Handle Txn Verification Success
        return;
      }
      //TODO Handle Txn Verification Failure
    } else {
      //TODO Handle Txn Verification Failure
    }
  }
 

NOTE : ebpNo in EsewaPayment is an optional field; include it if you are making government payment. Your payment without ebpNo will be recognized as a normal payment.

VIA CALLBACK URL

Esewa sends a proof of payment in the callback-URL(if provided)after successful payment in live environment.

VIA TRANSACTION VERIFICATION API (Recommended Method)

In case of mobile devices, We suggest to use the TXN verification API with txnRefId to verify ur transaction status and check for “status” key in “transactionDetails” object from the response body. “status” => “COMPLETE” means the transaction verification is successful. For live enviromment, please remove 'rc' from url

https://rc.esewa.com.np/mobile/transaction?txnRefId={refId} 
REQUEST TYPE : GET 
merchantId : ***********************************************
merchantSecret : ***********************************************
Content-Type : application/json 
RESPONSE
[
    {
        "productId": "1999",
        "productName": "Android SDK Payment",
        "totalAmount": "25.0",
        "code": "00",
        "message": {
            "technicalSuccessMessage": "Your transaction has been completed.",
            "successMessage": "Your transaction has been completed."
        },
        "transactionDetails": {
            "date": "Mon Dec 26 12:58:14 NPT 2022",
            "referenceId": "0004VZR",
            "status": "COMPLETE"
        },
        "merchantName": "Android SDK Payment"
    }
] 

Payment Failure/Cancellation

In case of payment failure and cancellation, onPaymentFailure and onPaymentCancellation callbacks are triggered which return the error message For more information regarding various cases of payment failures and cancellation, VISIT https://developer.esewa.com.np/pages/Android#errorcasesandhandling