dart-mesomb

Dart client for MeSomb API (v1.1) with support for:

  • Payment operations
  • Checkout sessions
  • Customer management
  • Product management
  • Fundraising
  • Wallet operations

API reference: https://mesomb.hachther.com/en/api/v1.1/schema/

Install

dart pub add mesomb

Import

import 'package:mesomb/mesomb.dart';

Credentials

Use the keys from your MeSomb dashboard:

  • applicationKey for payment/checkout/customer/product operations
  • fundKey for fundraising operations
  • providerKey for wallet operations
  • accessKey
  • secretKey

Payment Operation

final payment = PaymentOperation(
  '<applicationKey>',
  '<accessKey>',
  '<secretKey>',
);

Collect money

final collect = await payment.makeCollect(
  amount: 1000,
  service: 'MTN',
  payer: '677550203',
  country: 'CM',
  currency: 'XAF',
  lineItems: [
    {
      'product_data': {'name': 'T-Shirt'},
      'quantity': 1,
      'unit_amount': 1000,
      'currency': 'XAF',
    }
  ],
);

print(collect.success);
print(collect.transaction.success);

Deposit money

final deposit = await payment.makeDeposit(
  amount: 2000,
  service: 'ORANGE',
  receiver: '699123456',
  message: 'Payout',
  reference: 'order-1001',
);

print(deposit.status);

Purchase airtime

final airtime = await payment.purchaseAirtime(
  amount: 500,
  service: 'MTN',
  receiver: '677550203',
  merchant: 'MTN',
);

print(airtime.message);

Get application status

final app = await payment.getStatus();
print(app.key);
print(app.name);
print(app.countries);

Get or check transactions by IDs

final transactions = await payment.getTransactions(['id-1', 'id-2']);
final checked = await payment.checkTransactions(['id-1', 'id-2']);

print(transactions.length);
print(checked.first.status);

Refund transaction

final refund = await payment.refundTransaction(
  'transaction-id',
  amount: 100,
  currency: 'XAF',
);

print(refund.success);

Checkout Operation

final checkout = CheckoutOperation(
  '<applicationKey>',
  '<accessKey>',
  '<secretKey>',
);

Create checkout session

final session = await checkout.createCheckoutSession(
  amount: 1500,
  currency: 'XAF',
  successUrl: 'https://example.com/success?sid={CHECKOUT_SESSION_ID}',
  cancelUrl: 'https://example.com/cancel',
  description: 'Order #55',
  clientReferenceId: 'order-55',
  expiresIn: 1800,
  customer: {
    'email': 'john@acme.com',
    'first_name': 'John',
    'last_name': 'Doe',
  },
  lineItems: [
    {
      'product_data': {'name': 'Notebook'},
      'quantity': 1,
      'unit_amount': 1500,
      'currency': 'XAF',
    }
  ],
);

print(session.id);
print(session.url);

Retrieve / expire / delete session

final one = await checkout.getCheckoutSession('session-id');
print(one.status);

final expired = await checkout.expireCheckoutSession('session-id');
print(expired.status);

await checkout.deleteCheckoutSession('session-id');

Customer Operation

final customers = CustomerOperation(
  '<applicationKey>',
  '<accessKey>',
  '<secretKey>',
);

Create customer

final createdCustomer = await customers.createCustomer(
  firstName: 'Jane',
  lastName: 'Doe',
  email: 'jane@acme.com',
  phone: '677550203',
  town: 'Douala',
  region: 'Littoral',
  country: 'CM',
);

print(createdCustomer.id);

List / retrieve customers

final customerPage = await customers.getCustomers(page: 1);
print(customerPage.count);

final customer = await customers.getCustomer(customerPage.results.first.id!);
print(customer.email);

Update customer

final updatedCustomer = await customers.updateCustomer(
  12,
  firstName: 'Janet',
  email: 'janet@acme.com',
);

final patchedCustomer = await customers.partialUpdateCustomer(
  12,
  phone: '699000111',
);

print(updatedCustomer.firstName);
print(patchedCustomer.phone);

Delete customer

await customers.deleteCustomer(12);

Products Operation

final products = ProductsOperation(
  '<applicationKey>',
  '<accessKey>',
  '<secretKey>',
);

Create product

final createdProduct = await products.createProduct(
  name: 'Premium Plan',
  category: 'Subscription',
  description: 'Monthly plan',
  defaultPrice: 5000,
);

print(createdProduct.id);

List / retrieve products

final productPage = await products.getProducts(page: 1);
print(productPage.count);

final product = await products.getProduct(productPage.results.first.id);
print(product.name);

Update product

final updatedProduct = await products.updateProduct(
  'prod-id',
  name: 'Premium Plan Plus',
  defaultPrice: 7000,
);

final patchedProduct = await products.partialUpdateProduct(
  'prod-id',
  category: 'Enterprise',
);

print(updatedProduct.defaultPrice);
print(patchedProduct.category);

Delete product

await products.deleteProduct('prod-id');

Fundraising Operation

final fundraising = FundraisingOperation(
  '<fundKey>',
  '<accessKey>',
  '<secretKey>',
);

Contribute

final contribution = await fundraising.makeContribution(
  amount: 1000,
  service: 'MTN',
  payer: '677550203',
  fullName: {
    'first_name': 'John',
    'last_name': 'Donor',
  },
  contact: {
    'phone_number': '677550203',
    'email': 'john@acme.com',
  },
);

print(contribution.success);

Get / check contributions

final contributions = await fundraising.getContributions(['id-1', 'id-2']);
final checkedContributions =
    await fundraising.checkContributions(['id-1', 'id-2']);

print(contributions.length);
print(checkedContributions.length);

Wallet Operation

final wallet = WalletOperation(
  '<providerKey>',
  '<accessKey>',
  '<secretKey>',
);

Wallet CRUD

final createdWallet = await wallet.createWallet(
  lastName: 'Doe',
  phoneNumber: '677550203',
  gender: 'M',
  firstName: 'John',
  email: 'john@acme.com',
  country: 'CM',
);

final oneWallet = await wallet.getWallet(createdWallet.id);
final walletPage = await wallet.getWallets(1);

final updatedWallet = await wallet.updateWallet(
  createdWallet.id,
  lastName: 'Doe Updated',
  phoneNumber: '677550203',
  gender: 'M',
);

print(oneWallet.number);
print(walletPage.count);
print(updatedWallet.lastName);

await wallet.deleteWallet(createdWallet.id);

Wallet transactions

final credit = await wallet.addMoney(1, 1000, message: 'Top up');
final debit = await wallet.removeMoney(1, 500, message: 'Debit');
final transfer = await wallet.transferMoney(1, 2, 300, message: 'Transfer');

final tx = await wallet.getTransaction(credit.id);
final txPage = await wallet.listTransactions(page: 1, wallet: 1);
final searched = await wallet.getTransactions(['id-1', 'id-2']);

print(debit.amount);
print(transfer.amount);
print(tx.reference);
print(txPage.count);
print(searched.length);

Notes

  • Use RandomGenerator.nonce() when you need to force a custom nonce.
  • Use mode: 'asynchronous' for async payment flow where supported.
  • Use lineItems for payment itemization (products is kept only for backward compatibility).

Author

Hachther LLC - contact@hachther.com

Libraries

mesomb