monnify_flutter_sdk 0.0.1-beta

  • Readme
  • Changelog
  • Example
  • Installing
  • new58

monnify_flutter_sdk #

Flutter plugin for Monnify SDK

pub package

Getting Started #

To use this plugin, add monnify_flutter_sdk as a dependency in your pubspec.yaml file.

How to use #

This plugin exposes two APIs:

1. Initialize #

Initialize the plugin. This should be done once, preferably in the initState of your widget.

import 'package:monnify_flutter_sdk/monnify_flutter_sdk.dart';
import 'package:monnify_flutter_sdk/ApplicationMode.dart';
import 'package:monnify_flutter_sdk/Transaction.dart';
import 'package:monnify_flutter_sdk/TransactionResponse.dart';
import 'package:monnify_flutter_sdk/SubAccountDetails.dart';
import 'package:monnify_flutter_sdk/PaymentMethod.dart';

class _MyAppState extends State<MyApp> {

  @override
  void initState() {
    super.initState();
    MonnifyFlutterSdk.initialize(
              'YOUR_API_KEY', 
              'CONTRACTCODE', 
              ApplicationMode.TEST
    )
  }
}

2. Initialize Payment #

Create an object of the Transaction class and pass it to the initializePayment function

Future<void> initPayment() async {
    TransactionResponse transactionResponse =
          await MonnifyFlutterSdk.initializePayment(Transaction(
              2000,
              "NGN",
              "Customer Name",
              "mail.cus@tome.er",
              "PAYMENT_REF",
              "Description of payment",
              metaData: {
                "ip": "196.168.45.22",
                "device": "mobile_flutter"
                // any other info
              },
              paymentMethods: [PaymentMethod.CARD, PaymentMethod.ACCOUNT_TRANSFER],
              incomeSplitConfig: [
                SubAccountDetails("MFY_SUB_319452883968", 10.5, 500, true),
                SubAccountDetails("MFY_SUB_259811283666", 10.5, 1000, false)]
          )
    );
}

Optional params: Payment Methods specify transaction-level payment methods. Sub-Accounts in incomeSplitConfig are accounts that will receive settlement for the particular transaction being initialized. MetaData is map with single depth for any extra information you want to pass along with the transaction.

The TransactionResponse class received after sdk is closed contains the below fields

String paymentDate;
double amountPayable;
double amountPaid;
String paymentMethod;
String transactionStatus;
String transactionReference;
String paymentReference;

Need more information? #

For further info about Monnify's mobile SDKs, including transaction status types, see the documentations for the Android and iOS SDKs

0.0.1 #

  • TODO: Describe initial release.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:math';

import 'package:flutter/services.dart';
import 'package:monnify_flutter_sdk/monnify_flutter_sdk.dart';
import 'package:monnify_flutter_sdk/ApplicationMode.dart';
import 'package:monnify_flutter_sdk/Transaction.dart';
import 'package:monnify_flutter_sdk/TransactionResponse.dart';
import 'package:monnify_flutter_sdk/SubAccountDetails.dart';
import 'package:monnify_flutter_sdk/PaymentMethod.dart';

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

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

class _MyAppState extends State<MyApp> {
  BuildContext mContext;

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

  Future<void> initializeSdk() async {
    try {
      if (await MonnifyFlutterSdk.initialize(
          'MK_TEST_G9YG93QQJA', '4551641593', ApplicationMode.TEST)) {
        _showToast("SDK initialized!");
      }
    } on PlatformException catch (e, s) {
      print("Error initializing sdk");
      print(e);
      print(s);

      _showToast("Failed to init sdk!");
    }
  }

  Future<void> initPayment() async {
    TransactionResponse transactionResponse;

    try {
      transactionResponse =
          await MonnifyFlutterSdk.initializePayment(Transaction(
              2000.0,
              "NGN",
              "Customer Name",
              "mail.cus@tome.er",
              getRandomString(15),
              "Description of payment",
              metaData: {
                "ip": "196.168.45.22",
                "device": "mobile"
              },
              paymentMethods: [PaymentMethod.CARD, PaymentMethod.ACCOUNT_TRANSFER],
              /*incomeSplitConfig: [SubAccountDetails("MFY_SUB_319452883968", 10.5, 500, true),
                SubAccountDetails("MFY_SUB_259811283666", 10.5, 1000, false)]*/
          ));

      _showToast(
          transactionResponse.transactionStatus.toString() + "\n" +
          transactionResponse.paymentReference.toString() + "\n" +
          transactionResponse.transactionReference.toString() + "\n" +
          transactionResponse.amountPaid.toString() + "\n" +
          transactionResponse.amountPayable.toString() + "\n" +
          transactionResponse.paymentDate.toString() + "\n" +
          transactionResponse.paymentMethod.toString());

    } on PlatformException catch (e, s) {
      print("Error initializing payment");
      print(e);
      print(s);

      _showToast("Failed to init payment!");
    }
  }

  String getRandomString(int length) {
    const _chars =
        'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890';
    Random _rnd = Random();

    return String.fromCharCodes(Iterable.generate(
        length, (_) => _chars.codeUnitAt(_rnd.nextInt(_chars.length))));
  }

  void _showToast(String message) {
    final scaffold = Scaffold.of(mContext);
    scaffold.showSnackBar(
      SnackBar(
        content: Text(message),
        action: SnackBarAction(
            label: 'CLOSE', onPressed: scaffold.hideCurrentSnackBar),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Monnify Plugin Sample'),
        ),
        body: Builder(
          builder: (context) {
            mContext = context;
            return Center(
              child: FlatButton(
                child: Text("PAY"),
                onPressed: () => initPayment(),
              ),
            );
          },
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  monnify_flutter_sdk: ^0.0.1-beta

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:monnify_flutter_sdk/monnify_flutter_sdk.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
23
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
85
Overall:
Weighted score of the above. [more]
58
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 linux

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

Package does not support Flutter platform macos

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

Package does not support Flutter platform web

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

Package does not support Flutter platform windows

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

Package not compatible with SDK dart

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

Health issues and suggestions

Document public APIs. (-0.22 points)

73 out of 75 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Package is pre-release. (-5 points)

Pre-release versions should be used with caution; their API can change in breaking ways.

Dependencies

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