/mvola-dart

A dart package for interacting with the MVola API.

Primary LanguageDartMIT LicenseMIT

MVolaAPI dart package

This is a package that can be used to interact with the [not that] brand new MVola API from a Dart or Flutter client.

⚠️ DISCLAIMER

It is not recommended to manage payments in the client side due to some security reasons (most of dart packages are used for Flutter), so use it at your own risk. It was only after the first release of the package that I acknowledged that fact but I am not gonna delete it.

🔫 Features

It allow you to make payments, see the status of a transaction and get the details of a previously made transaction.

🛠️ Getting started

This package depends on the uuid and the http packages.

Installing from the command line

Type in the terminal :

dart pub add mvola

or, if your adding it to a flutter project :

flutter pub add mvola

Pubspec installation

Add these lines to your pubspec.yaml :

dependencies:
    mvola:

More info can be found on pub.dev, the official package repository for Dart and Flutter.

Usage

Start by importing the library.

import 'package:mvola/mvola.dart';

Then create an instance of the MVolaClient class with the base url for the requests(https://devapi.mvola.mg in the sandbox and https://api.mvola.mg in production, as mentionned in the documentation) and a consumer key and a consumer secret. An optional callbackUrl can be provided, it's the url where the API send a notification whether a transaction has been successful or not.

var mvola = MVolaClient(baseUrl, consumerKey, consumerSecret);

[consumerKey] and [consumerSecret] can be found on the mvola devportal upon creating an application.

You then have to generate an access token in order to make transactions. You can store it in a variable for later use or just call the method to set it.

await mvola.generateAccessToken();

Now, you can make transactions, get the status of that transaction or get the details of a transaction.

// make a transaction
var transactionResponse = await mvola.initTransaction(
    partnerName: 'name',
    partnerNumber: '0343500004',
    creditNumber: '0343500004',
    amount: 5000,
    debitNumber: '0343500003',
    description: 'short description',
);

// get the status of a transaction
var transactionStatus = await mvola.getTransactionStatus(transactionResponse.serverCorrelationId, '0343500004', 'name');

// get the detail of a transaction
var transaction = await mvola.getTransactionDetail(serverCorrelationId, "name", "0343500004");

In the development environment, only 0343500004 and 0343500003 can be used as merchant or customer numbers.

The complete example code can be found here or here.

Todo

  • Improve documentation
  • Improve error/exception responses
  • Add badges to README.md
  • Add disclaimer to not use this package with client-side code (use with server-side stuff like serverpod)

Support

If you encounter any issue or want more information about this package, don't hesitate to email me or message me on facebook or open an issue.

Additional information

ℹ️ This package is still in early stage of developpment. So please, don't hesitate to point out any issue or suggest an improvment.

License

MIT

Author

👤 Tsierenana Botramanagna Gracy

✉️ gtsierenana@gmail.com