Python SDK - Payments#

M-Pesa (STK push) and Snippe (mobile money, hosted checkout).

Settings#

db.payments.get_settings()

db.payments.update_settings(
    mpesa_consumer_key="...",
    mpesa_consumer_secret="...",
    snippe_api_key="...",
)
Python

M-Pesa STK push#

db.payments.stk_push(
    phone="+255712345678",
    amount=5000,
    description="Order #123",
)
Python

The customer authorizes on their phone; RafikiDB receives the callback and records the transaction.

Snippe#

# Direct mobile money payment
db.payments.snippe_initiate(
    amount=5000,
    phone="+255712345678",
    first_name="Asha",
    last_name="Mwinyi",
    email="asha@example.com",
    order_id="ORD-123",
)

# Hosted checkout session
db.payments.snippe_session(
    amount=25000,
    description="Checkout",
    redirect_url="https://myapp.com/thanks",
    customer_name="Asha Mwinyi",
    customer_phone="+255712345678",
    expires_in=3600,
)
Python

Status and transactions#

db.payments.snippe_status(reference)
db.payments.list_transactions()
db.payments.get_transaction(transaction_id)
Python

Payment callbacks are HMAC-signed like webhooks.

Next: Errors.