Skip to content

Latest commit

 

History

History
264 lines (182 loc) · 3.86 KB

File metadata and controls

264 lines (182 loc) · 3.86 KB

Redde Python SDK

Official Python SDK for integrating with the Redde Payments API.

This SDK allows developers to easily integrate Redde mobile money and payment services into Python applications.

Features

  • Receive Money (Mobile Money / Wallet)
  • Send Money (Cashout)
  • Transaction Status Check
  • Async support using httpx
  • Automatic retries with exponential backoff
  • Typed responses using Pydantic
  • Structured error handling
  • Webhook signature verification
  • Production-grade logging

Installation

Install locally:

pip install -e .

Or once published:

pip install redde-python-sdk

Quick Start

import asyncio
from redde.async_client import AsyncReddeClient
from redde.models.payment import ReceiveMoneyRequest

async def main():

    client = AsyncReddeClient(
        api_key="YOUR_API_KEY",
        app_id="YOUR_APP_ID"
    )

    request = ReceiveMoneyRequest(
        amount=10.50,
        clientreference="order-1001",
        clienttransid="txn-1001",
        nickname="Customer Payment",
        paymentoption="MTN",
        walletnumber="0240000000"
    )

    response = await client.receive_money(request)

    print(response)

    await client.close()

asyncio.run(main())

Receive Money

Initiates a mobile money payment request.

from redde.models.payment import ReceiveMoneyRequest

request = ReceiveMoneyRequest(
    amount=20,
    clientreference="order-001",
    clienttransid="txn-001",
    nickname="Payment",
    paymentoption="MTN",
    walletnumber="0240000000"
)

response = await client.receive_money(request)

Example Response

{
  "status": "OK",
  "transactionid": "123456",
  "checkouturl": "https://checkout.reddeonline.com/..."
}

Send Money (Cashout)

from redde.models.payment import SendMoneyRequest

request = SendMoneyRequest(
    amount=50,
    clientreference="withdrawal-001",
    clienttransid="txn-002",
    description="Customer withdrawal",
    nickname="Customer",
    paymentoption="MTN",
    walletnumber="0240000000"
)

response = await client.send_money(request)

Check Transaction Status

status = await client.get_status("123456")

print(status.status)
print(status.clienttransid)

Handling Responses

if response.status == "OK":
    print("Transaction initiated")

Or using helper:

if response.is_success:
    print("Transaction successful")

Error Handling

from redde.exceptions import ReddeApiException

try:
    response = await client.receive_money(request)

except ReddeApiException as e:
    print("API Error:", e.status_code)
    print("Response:", e.response)

Available Exceptions

  • ReddeException
  • ReddeConnectionException
  • ReddeTimeoutException
  • ReddeApiException
  • ReddeValidationException

Webhook Verification

from redde.security.webhook import verify_webhook_signature

is_valid = verify_webhook_signature(
    payload=raw_body,
    signature=signature_header,
    secret=webhook_secret
)

if not is_valid:
    raise Exception("Invalid webhook")

Logging

import logging

logging.basicConfig(level=logging.INFO)

Example logs:

INFO:redde:[436734ff] POST receive
INFO:redde:[436734ff] status=200 duration=105ms

Async Support

Supported frameworks:

  • FastAPI
  • Django Async
  • Flask (async)
  • Any asyncio-based service

Configuration

Default API endpoint:

https://api.reddeonline.com/v1

Override example:

client = AsyncReddeClient(
    api_key="API_KEY",
    app_id="APP_ID",
    base_url="https://sandbox.reddeonline.com/v1"
)

Requirements

  • Python 3.12.9
  • httpx
  • pydantic
  • tenacity

Testing

pytest

Security

  • Always verify webhooks
  • Never expose your API key publicly
  • Store credentials securely

License

MIT License