azampay 1.0.0 copy "azampay: ^1.0.0" to clipboard
azampay: ^1.0.0 copied to clipboard

A pure-Dart SDK for the AzamPay payment APIs — Tanzania, Rwanda and International Money Transfer (IMT). Works in Flutter, server-side Dart and CLI.

example/example.dart

// ignore_for_file: avoid_print
import 'package:azampay/azampay.dart';

/// Builds a unique, idempotent reference for a transaction, e.g. `ORDER-1720...`.
///
/// AzamPay uses this to de-duplicate requests, so it must be unique per
/// transaction. A UUID or your own order id works just as well — the important
/// part is that you never reuse one.
String reference(String prefix) =>
    '$prefix-${DateTime.now().millisecondsSinceEpoch}';

Future<void> main() async {
  // 1. Create a client with your merchant credentials (from your AzamPay
  //    developer account). Sandbox is the default; pass `sandbox: false` for
  //    production.
  final azampay = AzamPay(
    appName: '<your app name>',
    clientId: '<your client id>',
    clientSecret: '<your client secret>',
    // sandbox: false,
  );

  // ---------------------------------------------------------------------------
  // TANZANIA
  // ---------------------------------------------------------------------------

  // Phone numbers must be prefixed with the country code (255 for Tanzania),
  // e.g. 2557XXXXXXXX. Replace the placeholders below with real values.

  // Mobile-money (MNO) push checkout — charge a customer's wallet.
  final mno = await azampay.tanzania.mnoCheckout(
    accountNumber: '<Customer Phone Number>', // country-code prefixed (255...)
    amount: 1000, // amount to charge
    currency: 'TZS',
    provider: MnoProvider.azampesa, // Airtel | Tigo | Halopesa | Azampesa | Mpesa
    externalId: reference('ORDER'), // your unique transaction reference
  );
  print('MNO success: ${mno.success}, message: ${mno.message}');

  // Bank checkout — charge a bank account (generate an OTP first).
  final bank = await azampay.tanzania.bankCheckout(
    merchantAccountNumber: '<Your Merchant Account Number>',
    merchantMobileNumber: '<Customer Phone Number>',
    amount: 5000,
    currencyCode: 'TZS',
    provider: BankProvider.crdb, // CRDB | NMB
    otp: '<OTP from generateCrdbOtp / generateNmbOtp>',
    referenceId: reference('ORDER'),
  );
  print('Bank success: ${bank.success}');

  // Disbursement — pay money OUT, from your wallet to a recipient.
  final payout = await azampay.tanzania.disburse(
    // SOURCE = you (the sender / payer).
    source: const DisbursementAccount(
      accountNumber: '<Your Payout Wallet Number>',
      fullName: '<Your Company Name>',
      bankName: 'Azampesa', // sender provider: Airtel | Tigo | Azampesa
      currency: 'TZS',
      countryCode: 'TZ',
    ),
    // DESTINATION = the person receiving the money.
    destination: const DisbursementAccount(
      accountNumber: '<Recipient Phone Number>',
      fullName: '<Recipient Name>',
      bankName: 'Tigo', // recipient provider: Airtel | Tigo | Azampesa
      currency: 'TZS',
      countryCode: 'TZ',
    ),
    transferDetails: const TransferDetails(amount: 2000, type: 'SendMoney'),
    externalReferenceId: reference('PAYOUT'),
  );
  print('Payout: ${payout.statusCode}');

  // ---------------------------------------------------------------------------
  // RWANDA
  // ---------------------------------------------------------------------------

  final rwPayment = await azampay.rwanda.initiatePayment(
    provider: 'Airtel',
    currencyCode: 'RWF',
    amount: '1000',
    referenceId: reference('RW-ORDER'),
    accountNumber: '<Customer Phone Number>', // country-code prefixed (250...)
  );
  print('RW payment: ${rwPayment.transactionId}');

  // ---------------------------------------------------------------------------
  // INTERNATIONAL MONEY TRANSFER (IMT)
  // ---------------------------------------------------------------------------

  // IMT payloads are compliance-heavy; inspect `.doc` for the exact fields.
  print(azampay.imt.sendMoney.doc);

  // ---------------------------------------------------------------------------
  // SELF-DOCUMENTATION
  // ---------------------------------------------------------------------------

  // Read any endpoint's full documentation inline while coding.
  print(azampay.tanzania.mnoCheckout.doc);

  // List every endpoint in a region.
  print(azampay.rwanda.describe());

  azampay.close();
}
3
likes
160
points
184
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A pure-Dart SDK for the AzamPay payment APIs — Tanzania, Rwanda and International Money Transfer (IMT). Works in Flutter, server-side Dart and CLI.

Repository (GitHub)
View/report issues

Topics

#payments #azampay #tanzania #rwanda #mobile-money

License

MIT (license)

Dependencies

http

More

Packages that depend on azampay