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

Uploaded Python 3

File details

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

File metadata

  • Download URL: rohopay-1.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 e8d2a07668211d9dff3f8571218c51dac32c5ed1f76ee83a4bd95ff0c894460f
MD5 4153028e04aacb588e4b40c6da230c74
BLAKE2b-256 58c2542fbb24a4333f73235d1e0f76f94d6c67df84096b094c885d59426edb69

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rohopay-1.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ef9a8928f9af1e7dc3746d4ad151eff5db8a830952b381250e956ec826a5914c
MD5 9f112c8f9cb28be20fdae5e5354bd9bd
BLAKE2b-256 7ed91d507f2c42fc36b61c091b54ed9c502a676f44038f5e03b48b772b922ebc

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