Checkout
Checkout sessions, STK push, payment links, and polling for completion.
Use
NezaHubCheckoutClient (@nezahub/sdk/checkout) in the browser. No API key required for confirm() and payment-link flows.Server-side session
Use PaymentCurrency and MnoSlug enums, e.g. PaymentCurrency.KES with MnoSlug.Mpesa in Kenya.
from nezahub import MnoSlug, PaymentCurrency
session = client.checkout.sessions.create(
price_id=price["id"],
customer_phone="+254712345678",
payment_currency=PaymentCurrency.KES,
mno=MnoSlug.MPESA,
agent_id=agent["id"], # optional
)Confirm STK push
from nezahub import MnoSlug
from nezahub.checkout import NezaHubCheckoutClient
checkout = NezaHubCheckoutClient()
checkout.confirm(session["id"], mno=MnoSlug.MPESA, customer_phone="+254712345678")Payment links
Pass country as a MarketCountryCode when previewing link pricing.
from nezahub import MarketCountryCode
from nezahub.checkout import NezaHubCheckoutClient
checkout = NezaHubCheckoutClient()
link = client.payment_links.create(price_id=price["id"])
preview = checkout.get_link(link["url_slug"], country=MarketCountryCode.KE)
session = checkout.start_from_link(
link["url_slug"],
customer_phone="+254712345678",
)Poll for completion
With **test API keys** (nz_test_…), STK confirm completes synchronously: poll the session until status is complete. No transaction or balance is created. payment.success webhooks include test_mode: true and omit a real transaction_id. With **live** keys, completion is asynchronous—poll the session or wait for a webhook, then load the succeeded transaction.
from nezahub.flows import poll_checkout_complete, poll_transaction_for_session
poll_checkout_complete(checkout, session["id"], poll_timeout=45.0)
# Live keys only — test keys do not create transactions
txn = poll_transaction_for_session(client, session["id"])