iamnabink / flutter_esewa

An un-official Flutter plugin for eSewa Payment Gateway, integrate with ease and without any hassle.
https://pub.dev/packages/esewa_flutter
MIT License
3 stars 2 forks source link
android dart esewa flutter flutter-package flutter-plugin ios package payment-gateway payment-integration

eSewa Flutter Share on Twitter Share on Facebook

Pub Version License: MIT

An un-official Flutter plugin for eSewa Payment Gateway. With this plugin, you can easily integrate eSewa Payment Gateway into your Flutter app and start accepting payments from your customers. Whether you're building an eCommerce app or any other type of app that requires payments, this plugin makes the integration process simple and straightforward.

Cover Image

Note

This package doesn't use any plugin or native APIs for payment initialization. Instead, it is based on the Flutter InAppWebView package. A shoutout to the developer of InAppWebView package for providing such a useful package.

Features

Requirements

Setup

Platform Configuration
iOS No Configuration Needed. For more info, see here
Android Set minSdkVersion of your android/app/build.gradle file to at least 19. For more info, see here

Usage

  1. Add esewa_flutter as a dependency in your pubspec.yaml file:
dependencies:
  esewa_flutter: ^1.0.0
  1. Import the package in your Dart code:

import 'package:esewa_flutter/esewa_flutter.dart';

  1. Create an instance of ESewaConfig with your payment information:

The ESewaConfig class holds the configuration details for the payment gateway. Pass an instance of ESewaConfig to the init() method of the Esewa class to initiate the payment process.

final config = ESewaConfig.live(
  amt: 100,
  scd: 'merchant_id',
  pid: 'product_id',
  su: 'https://success.com.np',
  fu: 'https://failure.com.np',
);
  1. Initialize the payment by calling Esewa.init() method:
final result = await Esewa.i.init(
  context: context,
  eSewaConfig: config,
);
  1. Check the payment result:

After the payment is completed or cancelled by the user, the plugin returns an instance of EsewaPaymentResult. If the payment was successful, hasData will be true and you can access the EsewaPaymentResponse object using data. If the payment was unsuccessful, hasError will be true and you can access the error message using error.

if (result.hasData) {
  // Payment successful
  final response = result.data!;
  print('Payment successful. Ref ID: ${response.refId}');
} else {
  // Payment failed or cancelled
  final error = result.error!;
  print('Payment failed or cancelled. Error: $error');
}

Dev/Live Mode

ESewaConfig supports both dev and live mode. For live mode, use the ESewaConfig.live() constructor, and for dev mode, use the ESewaConfig.dev() constructor. Here's an example of using the dev mode:

final config = ESewaConfig.dev(
  amt: 100,
  pid: 'product_id',
  su: 'https://success.com.np',
  fu: 'https://failure.com.np',
);

APIs

Class : Esewa

The Esewa provides a way to initialize Esewa payment using a custom button or a custom UI. Here's an example:

Methods

 init({required BuildContext context,required ESewaConfig eSewaConfig,EsewaPageContent? pageContents})

: Initializes the eSewa payment gateway with the given configuration

Initializes payment method


final result = await Esewa.i.init(
context: context,
eSewaConfig: ESewaConfig.dev(
// .live for live
su: 'https://www.marvel.com/hello',
amt: 10,
fu: 'https://www.marvel.com/hello',
pid: '1212',
// scd: dotenv.env['ESEWA_SCD']!
));

Class : EsewaPageContent

The EsewaPageContent class provides options for customizing the Esewa payment screen. You can add an app bar and a custom loader to the payment screen. Here's an example:

EsewaPageContent(
  appBar: AppBar(
    title: Text('Esewa Payment'),
  ),
  progressLoader: CircularProgressIndicator(),
);

Class: ESewaConfig

The ESewaConfig class is used to configure the eSewa payment gateway for either live or dev mode. It has two constructors:

Properties

Class: EsewaPaymentResult

Class representing the result of a payment transaction.

Properties

Class: EsewaPayButton

The EsewaPayButton is a customizable button widget that allows users to initiate the payment process for the eSewa Payment Gateway. The button can be easily integrated into your Flutter app by calling the EsewaPayButton constructor and passing the required parameters.

Here is an example of how to use the EsewaPayButton widget:

EsewaPayButton(
  paymentConfig: ESewaConfig.dev(
    su: 'https://www.marvel.com/hello',
    amt: 10,
    fu: 'https://www.marvel.com/hello',
    pid: '1212',
  ),
  width: 40,
  onFailure: (result) async {
    // handle failure scenario here
  },
  onSuccess: (result) async {
    // handle success scenario here
  },
),

With EsewaPayButton, the integration of eSewa Payment Gateway becomes even easier, as the payment process can be initiated with just a single button press.

Properties

The EsewaPayButton widget has the following parameters:

Dev Testing Information

If you want to test eSewa payment integration in development environment, you can use the following information:

Screenshots

Here are some screenshots of the eSewa Payment Gateway integrated into a ecommerce Flutter app:

Example Order Screen Payment Screen

Run the example app

License

This plugin is released under the MIT License. See LICENSE for details.

Contributions

Contributions are welcome! To make this project better, Feel free to open an issue or submit a pull request on Github..

Contact

If you have any questions or suggestions, feel free to contact me on LinkedIn.