Giter VIP home page Giter VIP logo

esewa_sdk's Introduction

Overview

The​ ​ eSewa​ ​ Mobile​ ​ SDK​ ​ enable​ ​ to​ ​ easily​ ​ accept​ ​ eSewa​ ​ payments. The​ ​ SDK​ ​ supports​ ​ only​ ​ one​ ​ use​ ​ case​ ​ for​ ​ making​ ​ payment​ –​ Single​ ​Payment​ ​(i.e.​ ​ One​ ​ payment​ ​ per​ ​ one​ ​ user​ ​ log​ ​in).

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

Getting Started

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 : in EsewaPayment is an optional field; include it if you are making government payment. Your payment without 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.

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.

https://esewa.com.np/mobile/transaction?txnRefId={refId}

REQUEST TYPE : GET Headers

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/#/android?id=error-cases-and-handling

esewa_sdk's People

Contributors

kodiarydeveloper avatar sandesh0017 avatar sumanrajpathak avatar

Stargazers

 avatar Piyush shakya avatar  avatar Sandesh Shrestha avatar  avatar Popular avatar

Watchers

 avatar

Forkers

sandesh0017

esewa_sdk's Issues

Could not find module 'EsewaSDK'

Swift Compiler Error (Xcode): Could not find module 'EsewaSDK' for target 'arm64-apple-ios'; found: x86_64-apple-ios-simulator, arm64-apple-ios-simulator, at: {projectdir}/ios/.symlinks/plugins/esewa_flutter_sdk/ios/EsewaSDK.framework/Modules/EsewaSDK.swiftmodule
/Users/flutter/.pub-cache/hosted/pub.dev/esewa_flutter_sdk-2.0.1/ios/Classes/SwiftEsewaFlutterSdkPlugin.swift:2:7

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.