esewa_pnp 0.1.0+1

  • Readme
  • Changelog
  • Example
  • Installing
  • 78

esewa_pnp #

pub package

esewa_pnp is a flutter plugin that let's developer to integrate native eSewa payment method into their flutter application with just few lines of code.

How to install #

  • Download eSewaSdk.arr file and save it.

  • Go to this YouTube link and watch full integration walk through video https://youtu.be/95hBW2SDM-Q.

  • Add following attribute inside your AndroidMainfest.xml

     <application
        ...
        android:theme="@style/Theme.AppCompat.Light.NoActionBar"
        ...>
    ...
    </application>
    
    

Usage #

  1. Create a ESewaConfiguration object. Start with test environment. When application is ready, you can switch it to live (ENVIRONMENT_LIVE)
...

ESewaConfiguration _configuration = ESewaConfiguration(
    clientID: "<Client-ID>",
    secretKey: "<Secret-Key>",
    environment: ESewaConfiguration.ENVIRONMENT_TEST //ENVIRONMENT_LIVE
);

clientID and secretKey values are provided by eSewa to its merchant/client and is unique for each. For development phase, you can use the following credentials:

clientID: "JB0BBQ4aD0UqIThFJwAKBgAXEUkEGQUBBAwdOgABHD4DChwUAB0R"

secretKey: "BhwIWQQADhIYSxILExMcAgFXFhcOBwAKBgAXEQ=="

  1. Create ESewaPnp object and pass configuration.
...
ESewaPnp _eSewaPnp = ESewaPnp(configuration: _configuration);
  1. Finally create the payment object
...
ESewaPayment _payment = ESewaPayment(
    amount: <ANY_INTEGER_VALUE>,
    productName: "<Product-Name>",
    productID: "<Unique-Product-ID>",
    callBackURL: "<Call-Back-URL>"
);
  1. Now call initPayment method.
...
final _res = await _eSewaPnp.initPayment(payment: _payment);

initPayment will return an Either type (ref. dart functional programming with dartz) . Response can be either Failure type or Result type.

Failure type indicates the payment process fail.

Result type indicates the successful payment.

  1. Determine application behavior according to the response
...
_res.fold(
    (l) {
        // TODO:: Stuffs after failure.
    },
    (r) {
        // TODO:: Stuffs after successful payment.
    }
);

❌ Failure #

Failure class is returned when payment process fails.

  • .message [String] : returns the error message

✅ Result #

Result class is returned when payment process successful.

  • .message [String] : returns readable success message
  • .productId [String] : returns product id of the product customer paid for
  • .productName [String] : returns product name of the product customer paid for
  • .totalAmount [String] : returns total amount customer paid
  • .date [String] : returns the date of transaction
  • .status [String] : returns the transaction status
  • .referenceId [String] : returns the transaction reference id

👨‍🦱 Author #

Ashim Upadhaya

Checkout example implementation : EsewaPnp Example

This plugin can only be used on android platform because I don't have mac.

0.1.0 #

  • Initial release

0.1.0+1 #

  • "esewa_pnp integration walk through" youtube video link added to README.md

example/lib/main.dart

import 'package:esewa_pnp/esewa.dart';
import 'package:flutter/material.dart';

import 'package:esewa_pnp/esewa_pnp.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  ESewaPnp _esewaPnp;
  ESewaConfiguration _configuration;

  final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();

  @override
  void initState() {
    super.initState();

    _configuration = ESewaConfiguration(
      clientID: "JB0BBQ4aD0UqIThFJwAKBgAXEUkEGQUBBAwdOgABHD4DChwUAB0R",
      secretKey: "BhwIWQQADhIYSxILExMcAgFXFhcOBwAKBgAXEQ==",
      environment: ESewaConfiguration.ENVIRONMENT_TEST,
    );
    _esewaPnp = ESewaPnp(configuration: _configuration);
  }

  int _amount = 0;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        primaryColor: Color.fromRGBO(65, 161, 36, 1),
      ),
      home: Scaffold(
        key: _scaffoldKey,
        appBar: AppBar(
          title: Text("ESewa PNP"),
        ),
        body: Container(
          padding: EdgeInsets.all(20),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              TextField(
                keyboardType: TextInputType.number,
                onChanged: (value) {
                  setState(() {
                    _amount = int.parse(value);
                  });
                },
                decoration: InputDecoration(
                  labelText: "Enter amount",
                ),
              ),
              SizedBox(
                height: 16,
              ),
              Container(
                width: double.infinity,
                child: RaisedButton(
                  color: Color.fromRGBO(65, 161, 36, 1),
                  onPressed: () {
                    pay();
                  },
                  child: Text(
                    "Pay",
                    style: TextStyle(
                      color: Colors.white,
                      fontSize: 18,
                    ),
                  ),
                ),
              ),
              SizedBox(
                height: 84,
              ),
              Text(
                "Plugin developed by Ashim Upadhaya.",
                style: TextStyle(color: Colors.black45),
              )
            ],
          ),
        ),
      ),
    );
  }

  Future<void> pay() async {
    ESewaPayment eSewaPayment = ESewaPayment(
      amount: _amount,
      productName: "Test Product",
      productID: "abc123001",
      callBackURL: "https://www.uashim.com.np/",
    );
    final res = await _esewaPnp.initPayment(payment: eSewaPayment);

    res.fold((l) {
      _scaffoldKey.currentState
          .showSnackBar(_buildSnackBar(Colors.red, l.message));
    }, (r) {
      _scaffoldKey.currentState.showSnackBar(
          _buildSnackBar(Color.fromRGBO(65, 161, 36, 1), r.message));
    });
  }

  Widget _buildSnackBar(Color color, String msg) {
    return SnackBar(
      backgroundColor: color,
      content: Text(msg),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  esewa_pnp: ^0.1.0+1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:esewa_pnp/esewa_pnp.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
59
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
78
Learn more about scoring.

We analyzed this package on Jul 2, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform ios

Because of import path [package:esewa_pnp/esewa_pnp.dart] that declares support for platforms: android

Package does not support Flutter platform linux

Because of import path [package:esewa_pnp/esewa_pnp.dart] that declares support for platforms: android

Package does not support Flutter platform macos

Because of import path [package:esewa_pnp/esewa_pnp.dart] that declares support for platforms: android

Package does not support Flutter platform web

Because of import path [package:esewa_pnp/esewa_pnp.dart] that declares support for platforms: android

Package does not support Flutter platform windows

Because of import path [package:esewa_pnp/esewa_pnp.dart] that declares support for platforms: android

Package not compatible with SDK dart

because of import path [esewa_pnp] that is in a package requiring null.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (dartz).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
dartz ^0.8.9 0.8.9 0.9.1
equatable ^1.1.0 1.2.0
flutter 0.0.0
meta ^1.1.8 1.1.8
Transitive dependencies
collection 1.14.12 1.14.13
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
flutter_test