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.0).

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.2.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.2-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rohopay-1.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 1f2e4483584ffc162ebb7821b47ff36d064cc54f5a75b691fe861599e9253bc0
MD5 6bb0c1dc0efc7d69b1e9d8f9f55a4995
BLAKE2b-256 48b0a5ff5cda118ca52a95422bf29efb3692c4ee66b6832d24aa3d2a8edbaab0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rohopay-1.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bfafc8ba4feb954ec86380bb13c73b81d4771712b754e59a5666b3cbea849f90
MD5 119a18cbeca8b7cc17fea61c12df782f
BLAKE2b-256 26cd0eb430bb6339b768ea0291321ce5fbf26ceba9855509854e6fcb234035bc

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