Quickstart

Install the SDK, authenticate, and accept your first mobile-money payment.

Never expose API keys in browser code. Use NezaHubCheckoutClient (@nezahub/sdk/checkout) for customer-facing pages.

Install

PythonNode.js
Packagenezahub@nezahub/sdk
Installpip install nezahubnpm install @nezahub/sdk
Min versionPython 3.10+Node 18+

Authenticate

from nezahub import NezaHubClient

client = NezaHubClient(api_key="nz_test_xxx")
health = client.health()
print(health["status"])

Accept a payment

Create a product and price, set charge distribution with ChargePreset, start checkout with PaymentCurrency and MnoSlug, confirm STK push, then poll until complete.

from nezahub import (
    ChargePreset,
    MarketCountryCode,
    MnoSlug,
    PaymentCurrency,
    PriceType,
    charge_distribution_from_preset,
)
from nezahub.checkout import NezaHubCheckoutClient
from nezahub.flows import poll_checkout_complete

product = client.products.create(name="Airtime", active=True)
price = client.prices.create(
    product["id"],
    type=PriceType.ONE_OFF,
    unit_amount="1000",
    currency=PaymentCurrency.KES,
)

client.prices.update(
    product["id"],
    price["id"],
    charge_distribution=charge_distribution_from_preset(
        ChargePreset.MARKETPLACE_STANDARD,
        [MarketCountryCode.KE],
    ),
)

session = client.checkout.sessions.create(
    price_id=price["id"],
    customer_phone="+254712345678",
    payment_currency=PaymentCurrency.KES,
    mno=MnoSlug.MPESA,
)

checkout = NezaHubCheckoutClient()
checkout.confirm(session["id"], mno=MnoSlug.MPESA)
poll_checkout_complete(checkout, session["id"])
In test mode, STK push completes asynchronously. Poll with poll_checkout_complete() until the session status is complete, or handle a payment.success webhook in production.

Environment variables

export NEZAHUB_API_KEY=nz_test_...
export NEZAHUB_ACCESS_TOKEN=...   # optional, after JWT login

# SDK default API host: https://api.nezahub.com (test and live keys use the same host)