Skip to main content

SDKs

The SDKs wrap the REST API and handle authentication and the sandbox/live switch for you.

Install​

pip install intasend-python

Authenticate​

Pass your publishable key, your secret key (server side only) and whether you're testing. Set test to false with live keys.

from intasend import APIService

service = APIService(token="<SECRET_KEY>", publishable_key="<PUBLISHABLE_KEY>", test=True)

For checkout only, the publishable key is enough. Leave the secret key out of anything that runs in a browser or app.

Examples​

Checkout​

Creates a checkout and returns the payment url.

response = service.collect.checkout(
phone_number="254712345678", email="[email protected]", amount=1500, currency="KES",
comment="Order 123", redirect_url="https://example.com/thank-you",
)
print(response.get("url"))

M-Pesa STK Push​

Sends an STK Push prompt to the customer's phone.

response = service.collect.mpesa_stk_push(
phone_number="254712345678", email="[email protected]", amount=10, narrative="Purchase",
)

Payment status​

Pass the invoice_id from the checkout or STK Push response. See checking payment status.

response = service.collect.status(invoice_id="<INVOICE_ID>")

Packages​