dart_mpesa 2.0.3 copy "dart_mpesa: ^2.0.3" to clipboard
dart_mpesa: ^2.0.3 copied to clipboard

This library contains methods that make it easy to consume Mpesa Api.

example/dart_mpesa_example.dart

import 'package:dart_mpesa/dart_mpesa.dart';

void main() async {
  var mpesa = Mpesa(
      shortCode: '',
      consumerKey: '',
      consumerSecret: '',
      initiatorName: '',
      securityCredential: '',
      passKey: '',
      identifierType: IdentifierType
          .OrganizationShortCode, // Type of organization, options, OrganizationShortCode, TillNumber, OrganizationShortCode
      applicationMode: ApplicationMode.test);

  // lipa na mpesa online
  var _res = await mpesa.lipanaMpesaOnline(
    phoneNumber: '',
    amount: 0,
    accountReference: '',
    transactionDesc: '',
    callBackURL: '',
  );

  print(_res.statusCode);
  print(_res.rawResponse);

  // b2c
  _res = await mpesa.b2cTransaction(
      phoneNumber: '',
      amount: 0,
      remarks: '',
      occassion: '',
      resultURL: '',
      queueTimeOutURL: '',
      commandID: BcCommandId.BusinessPayment // default
      );

  print(_res.statusCode);
  print(_res.rawResponse);

  // b2b paybill
  _res = await mpesa.b2bPaybillTransaction(
    shortCode: '',
    amount: 0,
    remarks: '',
    accountReference: '',
    resultURL: '',
    queueTimeOutURL: '',
  );

  print(_res.statusCode);
  print(_res.rawResponse);

  // b2b buy goods
  _res = await mpesa.b2bBuyGoodsTransaction(
    shortCode: '',
    amount: 0,
    remarks: '',
    resultURL: '',
    queueTimeOutURL: '',
  );

  print(_res.statusCode);
  print(_res.rawResponse);

  // b2b
  _res = await mpesa.b2bTransaction(
    shortCode: '',
    amount: 0,
    remarks: '',
    accountReference: '', // optional
    resultURL: '',
    queueTimeOutURL: '',
    identifierType: IdentifierType
        .OrganizationShortCode, // options, OrganizationShortCode, TillNumber, OrganizationShortCode
    commandID: BbCommandId
        .BusinessToBusinessTransfer, // options, BusinessToBusinessTransfer, BusinessPayBill, BusinessBuyGoods, DisburseFundsToBusiness, MerchantToMerchantTransfer
  );

  print(_res.statusCode);
  print(_res.rawResponse);

  // account balance
  _res = await mpesa.accountBalance(
    remarks: '',
    resultURL: '',
    queueTimeOutURL: '',
  );

  // transaction status
  _res = await mpesa.transactionStatus(
    transactionID: '',
    identifierType:
        IdentifierType.MSISDN, // Type of organization receiving the transaction
    remarks: '',
    occassion: '',
    resultURL: '',
    queueTimeOutURL: '',
  );

  print(_res.statusCode);
  print(_res.rawResponse);
}
6
likes
130
points
28
downloads

Publisher

verified publisherphan-tec.com

Weekly Downloads

This library contains methods that make it easy to consume Mpesa Api.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

http

More

Packages that depend on dart_mpesa