Skip to main content

PyMeSomb

Python SDK for MeSomb services.

Installation

pip install pymesomb

Quick Start

Important: all operation methods use keyword arguments (not a single dict argument).

from pymesomb.operations import PaymentOperation

operation = PaymentOperation(
    application_key="YOUR_APPLICATION_KEY",
    access_key="YOUR_ACCESS_KEY",
    secret_key="YOUR_SECRET_KEY",
)

response = operation.make_collect(
    amount=100,
    service="MTN",
    payer="670000000",
)

print(response.status)
print(response.is_operation_success())
print(response.is_transaction_success())

Configuration

By default, requests target the MeSomb host configured by the SDK. For local testing you can override it:

from pymesomb import mesomb

Payment Use Cases

1) Collect money (basic)

from pymesomb.operations import PaymentOperation

payment = PaymentOperation("APP_KEY", "ACCESS_KEY", "SECRET_KEY")

res = payment.make_collect(
    amount=100,
    service="MTN",
    payer="670000000",
    trx_id="order-1001",
)

print(res.status, res.transaction.reference)

2) Collect money with customer, location, and line_items

from pymesomb.operations import PaymentOperation

payment = PaymentOperation("APP_KEY", "ACCESS_KEY", "SECRET_KEY")

res = payment.make_collect(
    amount=1000,
    service="MTN",
    payer="670000000",
    trx_id="order-1002",
    customer={
        "phone": "+237677550439",
        "email": "fisher.bank@gmail.com",
        "first_name": "Fisher",
        "last_name": "BANK",
    },
    location={
        "town": "Douala",
        "region": "Littoral",
        "country": "Cameroon",
    },
    line_items=[
        {
            "product_data": {"name": "Sac a Main"},
            "unit_amount": 1000,
            "quantity": 1,
            "currency": "XAF",
        }
    ],
)

print(res.transaction.amount, res.transaction.currency)

3) Deposit money

from pymesomb.operations import PaymentOperation

payment = PaymentOperation("APP_KEY", "ACCESS_KEY", "SECRET_KEY")

res = payment.make_deposit(
    amount=1500,
    service="ORANGE",
    receiver="690000000",
    trx_id="payout-9001",
)

print(res.status)

4) Airtime purchase

from pymesomb.operations import PaymentOperation

payment = PaymentOperation("APP_KEY", "ACCESS_KEY", "SECRET_KEY")

res = payment.purchase_airtime(
    amount=500,
    service="MTN",
    receiver="670000000",
    merchant="MTN",
    trx_id="airtime-001",
)

print(res.status)

5) Yango refill

from pymesomb.operations import PaymentOperation

payment = PaymentOperation("APP_KEY", "ACCESS_KEY", "SECRET_KEY")

res = payment.make_yango_refill(
    amount=2000,
    service="MTN",
    payer="670000000",
    driver_id="DRIVER_123",
    trx_id="yango-001",
)

print(res.status)

6) Refund

from pymesomb.operations import PaymentOperation

payment = PaymentOperation("APP_KEY", "ACCESS_KEY", "SECRET_KEY")

res = payment.refund_transaction(
    trx_id="MESOMB_TRANSACTION_ID",
    amount=100,
    currency="XAF",
)

print(res.status)

7) Get payment app status and transactions

from pymesomb.operations import PaymentOperation

payment = PaymentOperation("APP_KEY", "ACCESS_KEY", "SECRET_KEY")

status = payment.get_status()
print(status.name, status.countries)

transactions = payment.get_transactions(["ID1", "ID2"], source="MESOMB")
print(len(transactions))

Checkout Use Cases

Create checkout session

from pymesomb.operations import CheckOutOperation

checkout = CheckOutOperation("APP_KEY", "ACCESS_KEY", "SECRET_KEY")

session = checkout.create(
    amount="1200",  # decimal string supported by API schema
    success_url="https://merchant.local/success",
    cancel_url="https://merchant.local/cancel",
    client_reference_id="ORD-1001",
    line_items=[
        {
            "product": "prod_001",
            "unit_amount": 1200,
            "quantity": 1,
            "currency": "XAF",
        }
    ],
    fees_included=True,
    secure_pay={
        "terms_accepted": True,
        "pay_mode": "optional",
        "dispute_enabled": True,
    },
)

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

Retrieve, expire, and delete checkout session

from pymesomb.operations import CheckOutOperation

checkout = CheckOutOperation("APP_KEY", "ACCESS_KEY", "SECRET_KEY")

session = checkout.retreive("cs_xxx")  # SDK method name is `retreive`
print(session.status)

expired = checkout.expire("cs_xxx")
print(expired.status)

deleted = checkout.delete("cs_xxx")
print(deleted)

Wallet Use Cases

from pymesomb.operations import WalletOperation

wallet = WalletOperation("PROVIDER_KEY", "ACCESS_KEY", "SECRET_KEY")

created = wallet.create_wallet(
    last_name="DOE",
    first_name="John",
    phone_number="670000000",
    gender="M",
)

print(created.id, created.number)

Fundraising Use Cases

from pymesomb.operations import FundraisingOperation

fund = FundraisingOperation("FUND_KEY", "ACCESS_KEY", "SECRET_KEY")

res = fund.make_contribution(
    amount=1000,
    service="MTN",
    payer="670000000",
    full_name={"last_name": "DOE", "first_name": "John"},
    contact={"phone_number": "670000000"},
    accept_terms=True,
)

print(res.status)

Error Handling

from pymesomb.exceptions import (
    ServiceNotFoundException,
    PermissionDeniedException,
    InvalidClientRequestException,
)

try:
    # your operation call here
    pass
except ServiceNotFoundException as exc:
    print("Service not found:", exc)
except PermissionDeniedException as exc:
    print("Permission denied:", exc)
except InvalidClientRequestException as exc:
    print("Invalid request:", exc)

Changelog

2.1.1 (2026-05-06)

  • Rename products to line_items to improve clarity.
  • Add secure payment in checkout creation.

2.1.0 (2026-04-23)

  • Integration of checkout operation to create a checkout session and get the checkout URL.
  • Integration of customer and product management operations.

2.0.3 (2025-03-24)

  • Add purchase_airtime to depose airtime in an account.

2.0.2 (2025-03-12)

  • Rename identifier to id in WalletTransaction.

2.0.1 (2025-03-12)

  • Add get_transactions method to retrieve transactions based on IDs and external IDs.
  • Rename get_transactions to list_transactions in wallet operation.
  • Improve canonical query handling in signature.py.

2.0.0 (2025-02-10)

  • Add fundraising operations.
  • Add wallet operations.
  • Add refund transaction operation.

Breaking changes

  • Parameters for make_collect and make_deposit are no longer passed as a dict, but as keyword arguments.
  • Remove security operations.
  • Change parameter ts(str) to date(datetime) in Transaction class.

1.1.1 (2025-01-31)

  • Integration of Yango refill.

1.1.0 (2024-09-02)

  • Add wallet operations: create wallet, update wallet, get wallet, delete wallet, adjust wallet and list wallets.

1.0.4 (2024-04-28)

  • Add function to detect phone number operator in Cameroon.

1.0.3 (2024-01-24)

  • Handle case when trxID is not string.
  • Fix crash to display response.
  • Add raw_response in TransactionResponse to store MeSomb response.

1.0.2 (2023-07-25)

Breaking changes

  • Only one parameter is now passed to make_deposit and make_collect. The parameter is a map that contains all details of your request.
  • All methods now return MeSomb models, not dict.

1.0.0 (2022-10-20)

  • First release of the module.

For canonical release history, you can also check HISTORY.md.

Author

Hachther LLC <contact@hachther.com>

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymesomb-2.1.2.tar.gz (28.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pymesomb-2.1.2-py3-none-any.whl (20.0 kB view details)

Uploaded Python 3

File details

Details for the file pymesomb-2.1.2.tar.gz.

File metadata

  • Download URL: pymesomb-2.1.2.tar.gz
  • Upload date:
  • Size: 28.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.7

File hashes

Hashes for pymesomb-2.1.2.tar.gz
Algorithm Hash digest
SHA256 80f943014768c927ab1b7dc157b31de8e10aa663a84d8702b6d0cf8e63853ac5
MD5 390466431a2c25e1379670ec80439db8
BLAKE2b-256 7b0dadb7ce07102d390012b2705e43832383b6c63a77b7971ff91f80985ce23c

See more details on using hashes here.

File details

Details for the file pymesomb-2.1.2-py3-none-any.whl.

File metadata

  • Download URL: pymesomb-2.1.2-py3-none-any.whl
  • Upload date:
  • Size: 20.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.7

File hashes

Hashes for pymesomb-2.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 30e1029200356ded4d0db9e960c40f3e744fbcc3b8db9b213585983d132bb821
MD5 87a363cecb4dfa5b2f90cd18e42dc25a
BLAKE2b-256 94a4a82f2a706d91857c9d89fb686f870a76e51f58271e7e39d921cb35a184d9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page