isw_mobile_sdk 1.0.0-5.6

  • Readme
  • Changelog
  • Example
  • Installing
  • 45

isw_mobile_sdk #

This library aids in processing payment through the following channels

  • [x] Card
  • [x] Verve Wallet
  • [x] QR Code
  • [X] USSD

Getting started #

There are three steps you would have to complete to set up the SDK and perform transaction

  • Install the SDK as a dependency
  • Configure the SDK with Merchant Information
  • Initiate payment with customer details

Installation #

To install the sdk add the following to your dependencies map in pubspec.yaml


dependencies:
  #.... others

  # add the dependency for sdk
  isw_mobile_sdk: '<latest-version>'

Configuration #

You would also need to configure the project with your merchant credentials.

import 'dart:async';
import 'package:isw_mobile_sdk/isw_mobile_sdk.dart';


class _MyAppState extends State<MyApp> {

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

    // messages to SDK are asynchronous, so we initialize in an async method.
  Future<void> initSdk() async {

    // messages may fail, so we use a try/catch PlatformException.
    try {
        String  merchantId = "your-merchant-id",
        merchantCode = "your-merchant-code",
        merchantSecret = "your-merchant-secret",
        currencyCode = "currency-code"; // e.g  566 for NGN

        var config = new IswSdkConfig (
            merchantId, 
            merchantKey, 
            merchantCode, 
            currencyCode
        );

        // initialize the sdk
        await IswMobileSdk.initialize(config);
        // intialize with environment, default is Environment.TEST
        // IswMobileSdk.initialize(config, Environment.SANDBOX);

    } on PlatformException {}
  }
}

Once the SDK has been initialized, you can then perform transactions.

Performing Transactions

You can perform a transaction, once the SDK is configured, by providing the payment info and payment callbacks, like so:


  Future<void> pay(int amount) async {

    var customerId = "<customer-id>",
        customerName = "<customer-name>",
        customerEmail = "<customer.email@domain.com>",
        customerMobile = "<customer-phone>",
        // generate a unique random
        // reference for each transaction
        reference = "<your-unique-ref>";

    
    // initialize amount
    // amount expressed in lowest
    // denomination (e.g. kobo): "N500.00" -> 50000
    int amountInKobo = amount * 100

    // create payment info
    var iswPaymentInfo = new IswPaymentInfo(
        customerId, 
        customerName,
        customerEmail, 
        customerMobile, 
        reference, 
        amountInKobo
    );


    // trigger payment
    var result = await IswMobileSdk.pay(iswPaymentInfo);

    // process result
    handleResult(result)
  }

Handling Result

To handle result all you need to do is process the result in the callback methods: whenever the user cancels, the value would be null and hasValue would be false. When the transaction is complete, hasValue would be true and value would have an instance of IswPaymentResult: an object with the below fields.

|-----------------------|---------------|----------| | responseCode | String | txn response code | | responseDescription | String | txn response code description | | isSuccessful | boolean | flag indicates if txn is successful | | transactionReference | String | reference for txn | | amount | Number | txn amount | | channel | String| channel used to make payment: one of CARD, WALLET, QR, USSD |


void handleResult(Optional<IswPaymentResult> result) {

    if (result.hasValue) {
        // process result
        showPaymentSuccess(result.value);
    } else { 
        showPaymentError()
    }
    
}

And that is it, you can start processing payment in your flutter app.

1.0.0-5.6 #

  • Bumps core module to version 1.0.0-5.6

1.0.0-5.5 #

  • No Updates

1.0.0-5.4 #

  • Updates Flutter sdk to 1.12.13

Changed #

  • Removed FlutterActivity reference and uses Application class instead

1.0.0-5.3 #

  • Initial Release

Supports 4 modes of payment: CARD, WALLET, QR, USSD

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:isw_mobile_sdk/isw_mobile_sdk.dart';
import 'certificate.dart';


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

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

class _MyAppState extends State<MyApp> {
  final GlobalKey<FormState> _formKey = new GlobalKey<FormState>();
  String _amountString = '';

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {

      var credential = Config.prodConfig;
      var config = new IswSdkConfig(
        credential.merchantId, 
        credential.merchantSecret, 
        credential.merchantCode, 
        credential.currencyCode
      );

      // initialize the sdk
      await IswMobileSdk.initialize(config, Environment.PRODUCTION);
      // intialize with environment, default is Environment.TEST
      // IswMobileSdk.initialize(config, Environment.SANDBOX);

    } on PlatformException {}
  }

  Future<void> pay(BuildContext context) async {
    // save form
    this._formKey.currentState.save();
    
    String customerId = "your+customer+id",
        customerName = "James Emmanuel",
        customerEmail = "kenneth.ngedo@gmail.com",
        customerMobile = "08031149929",
        reference = "pay" + DateTime.now().millisecond.toString();

    int amount;
    // initialize amount
    if (this._amountString.length == 0)
      amount = 2500 * 100;
    else
      amount = int.parse(this._amountString) * 100;

    // create payment info
    IswPaymentInfo iswPaymentInfo = new IswPaymentInfo(customerId, customerName,
        customerEmail, customerMobile, reference, amount);

    print(iswPaymentInfo);

    // trigger payment
    var result = await IswMobileSdk.pay(iswPaymentInfo);

    var message;
    if (result.hasValue) {
      message = "You completed txn using: " + result.value.channel.toString();
    } else {
      message = "You cancelled the transaction pls try again";
    }
    Scaffold.of(context).showSnackBar(new SnackBar(
      content: new Text(message),
      duration: Duration(seconds: 3),
    ));
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Charity Fortune'),
          backgroundColor: Colors.black,
        ),
        body: Center(
          child: Padding(
            padding: EdgeInsets.all(20),
            child: new Form(
              key: this._formKey,
              child: Column(
                children: <Widget>[
                  TextFormField(
                    decoration: InputDecoration(labelText: 'Amount'),
                    keyboardType: TextInputType.number,
                    onSaved: (String val) {
                      this._amountString = val;
                    },
                  ),
                  Builder(
                    builder: (ctx) => new Container(
                      width: MediaQuery.of(ctx).size.width,
                      child: RaisedButton(
                        child: Text(
                          "Pay",
                          style: TextStyle(color: Colors.white),
                        ),
                        onPressed: () => pay(ctx),
                        color: Colors.black,
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  isw_mobile_sdk: ^1.0.0-5.6

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:isw_mobile_sdk/isw_mobile_sdk.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
75
Overall:
Weighted score of the above. [more]
45
Learn more about scoring.

We analyzed this package on Jul 3, 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:isw_mobile_sdk/isw_mobile_sdk.dart] that declares support for platforms: android, ios

Package does not support Flutter platform macos

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

Package does not support Flutter platform web

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

Package does not support Flutter platform windows

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

Package not compatible with SDK dart

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

Health suggestions

Format lib/isw_mobile_sdk.dart.

Run flutter format to format lib/isw_mobile_sdk.dart.

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

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