Skip to main content

Official RohoPay Python SDK for mobile-money & card payments.

Project description

RohoPay Python SDK

Official Python SDK for RohoPay — mobile-money (MTN, Airtel, M-Pesa) and card (Visa, Mastercard) payments across East Africa.

Install

pip install rohopay

Quick start

import os
import uuid
from rohopay import RohoPay

client = RohoPay(api_key=os.environ["ROHOPAY_API_KEY"])

tx = client.collect(
    phone="256700123456",
    amount=50000,
    currency="UGX",
    description="Order #1001",
    callback_url="https://your-app.com/webhooks/rohopay",
    idempotency_key=str(uuid.uuid4()),  # optional; auto-generated if omitted
)
print(tx.internal_reference, tx.status)

card = client.checkout(
    amount=75000,
    customer_name="Jane Mukasa",
    customer_email="jane@example.com",
    return_url="https://your-app.com/checkout/return",
    card_number="4111111111111111",
    card_expiry="10/26",
    card_cvv="123",
)
# redirect the user to card.payment_url  (card is a CheckoutResult)

Methods

Method Endpoint
collect(...) POST /api/v1/collect
disburse(...) (live mode only) POST /api/v1/disburse
checkout(...) POST /api/v1/checkout
get_transaction(reference) GET /api/v1/transactions/:reference
list_transactions(**params) GET /api/v1/transactions
iter_transactions(**params) generator, auto-paginates list_transactions
get_balance() GET /api/v1/wallet/balanceBalance
verify_webhook(body, sig, secret)
construct_event(body, sig, secret, tolerance_seconds=300)

Errors

All errors subclass rohopay.RohoPayError and carry status, code, and request_id:

AuthenticationError (401), InvalidRequestError (400/404/422), IdempotencyError (409), RateLimitError (429), APIError (>=500), APIConnectionError (network/timeout), SignatureVerificationError (webhooks).

from rohopay import RohoPay, APIError

try:
    client.collect(phone="...", amount=1000)
except APIError as e:
    print(e.status, e.code, e.request_id)

Verify webhooks

import os
raw_body = request.get_data(as_text=True)
signature = request.headers.get("X-RohoPay-Signature", "")
if not client.verify_webhook(raw_body, signature, os.environ["ROHOPAY_WEBHOOK_SECRET"]):
    return "invalid signature", 401

# Or parse + verify in one step (raises SignatureVerificationError):
event = client.construct_event(raw_body, signature, os.environ["ROHOPAY_WEBHOOK_SECRET"])

The gateway signs outgoing webhooks automatically with the X-RohoPay-Signature header (sha256=<HMAC-SHA256 of raw body>). Your webhook secret is HMAC(APP_SECRET, "webhook:<userID>") — fetch it from Dashboard → Webhooks (the webhook_secret field) and pass it as the secret argument.

Constants

TransactionStatus, PaymentMethod, TransactionType, Environment enums, CURRENCIES, LIVE_BASE_URL, SANDBOX_BASE_URL, WEBHOOK_SIGNATURE_HEADER, and rohopay.__version__ (1.1.3).

Project details


Download files

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

Source Distribution

rohopay-1.1.3.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

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

rohopay-1.1.3-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file rohopay-1.1.3.tar.gz.

File metadata

  • Download URL: rohopay-1.1.3.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for rohopay-1.1.3.tar.gz
Algorithm Hash digest
SHA256 6d210388b7f6b532aa0c99196eda47f493c6672d86732a2c35baf0ab6574cac6
MD5 4f9d5d30993bed70863774bcac1b6816
BLAKE2b-256 db62c7705d0c97795769f78db46ab51b397c14a94644a8ede9225b19723a08c8

See more details on using hashes here.

File details

Details for the file rohopay-1.1.3-py3-none-any.whl.

File metadata

  • Download URL: rohopay-1.1.3-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for rohopay-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2af46d183cd11964d0ff515e9f1240a1ecc249c0be5b62706357f56e21d8711c
MD5 c19933d72b26ad11d4e25abe5e69a853
BLAKE2b-256 4e54609df34278ba7bb02ec417e8fa38c40597a4df3e7a3fe238706f87da1fa7

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