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
In test mode, completion is asynchronous after STK push. Poll until the session status is complete, retrieve the succeeded transaction, or rely on a payment.success webhook.
from nezahub.flows import poll_checkout_complete, poll_transaction_for_session
poll_checkout_complete(checkout, session["id"], poll_timeout=45.0)
txn = poll_transaction_for_session(client, session["id"])