Skip to main content

LipaTally developers

Build with the LipaTally API

Guides, examples and API references to help you build and launch a secure integration.

Integration guide

Build your first payment integration

Follow the request lifecycle from application setup to a verified payment result. Keep credentials server-side and use the API contract for complete schemas.

  • Sandbox first
  • Server-side requests
  • Idempotent payments

Get started

Make your first sandbox M-Pesa request

Use provider-recognized sandbox credentials and a test MSISDN. This guide describes the flow; it does not initiate a payment.

  1. 01

    Create a sandbox application

    Issue a sandbox API key scoped to the permissions your service needs.

  2. 02

    Enable M-Pesa collection

    An authorized operator configures approved sandbox references and enables STK_PUSH.

  3. 03

    Send an idempotent request

    Call the API from your server with a unique idempotency key for the purchase.

  4. 04

    Verify the payment state

    Read the payment status; an accepted request is not proof that payment succeeded.

Ready to configure your integration? Create an account to set up an application, permissions and provider configuration. Create an account

Access control

Authentication and tenant scope

Use a server-side API key with the minimum permissions required for each integration.

Supported authentication

  • Bearer session
  • X-API-Key

Organization scope

An API key is scoped to its organization, application and environment. Do not send X-Organization-Id with an API key.

Session-authenticated requests select the organization with X-Organization-Id. Never expose API keys in browser code, mobile apps, public repositories or customer-facing pages.

Environment safety

Keep sandbox and production separate

SANDBOX and PRODUCTION applications, API keys, provider accounts, and approved credential references are isolated.

SANDBOX

Build and test

  • Use a dedicated sandbox application and API key.
  • Configure only approved sandbox provider credential references.
  • Use test MSISDNs accepted by the configured provider environment.
PRODUCTION

Go live deliberately

  • Create a separate production application and key; environments cannot be switched.
  • Wait for production access and provider references to be approved.
  • Validate publicly reachable HTTPS callbacks with your operator.
Production requests may move real money or incur provider charges. Never reuse sandbox keys or provider credentials in production, or production credentials in sandbox.

Payments

M-Pesa collection

Your service calls the versioned LipaTally API; LipaTally connects to the provider server-side.

Supported M-Pesa collection channels
Channel What it does
STK_PUSH Prompts a customer on their phone and lets your service track the resulting payment state.
PAYBILL Collection channel available when enabled for the application.
TILL Collection channel available when enabled for the application.
  • Payment API requests use amount; KES M-Pesa amounts must represent whole shillings.
  • Configure a public HTTPS callback for the correct environment.
  • Provider credential values and references are not displayed in this portal.
  • C2B/B2C initiation, refunds, reversals, reconciliation reports and verified callback state transitions are not available in this integration.

Provider endpoint selection is handled server-side from the application's environment. Obtain the approved public API origin from your operator; never use an internal service hostname.

Request example

Create a payment from your server

Use an API key scoped with payments:write. Set API_ORIGIN to the operator-approved public origin, without the /api/v1 path.

Example amount KES 1,500.00 Replace the customer placeholder only with an authorized sandbox test number.
cURL · Create payment
curl --request POST "$API_ORIGIN/api/v1/payments" \
  --header "X-API-Key: $API_KEY" \
  --header "Idempotency-Key: $IDEMPOTENCY_KEY" \
  --header "Content-Type: application/json" \
  --data '{
    "merchant_reference": "ORDER-12345",
    "amount": "1500",
    "currency": "KES",
    "msisdn": "2547XXXXXXXX",
    "channel": "STK_PUSH",
    "description": "Order 12345"
  }'

Accepted response excerpt

The response is wrapped in data and meta. This excerpt omits payment, attempt and event fields; the OpenAPI contract contains the full response schema.

PENDING
{
  "data": {
    "id": "123e4567-e89b-12d3-a456-426614174000",
    "merchant_reference": "ORDER-12345",
    "status": "PENDING"
  },
  "meta": {
    "request_id": "request-id"
  }
}

Reliability

Read status and retry safely

A timeout or accepted request can leave the outcome unresolved. Check the payment before retrying.

A PENDING or UNKNOWN result is not success. Do not fulfill an order based only on an HTTP success code.
cURL · Read payment
curl --request GET "$API_ORIGIN/api/v1/payments/$PAYMENT_ID" \
  --header "X-API-Key: $API_KEY"
  • Use the same idempotency key only when retrying the same logical payment request.
  • Check the payment's current state before retrying after an ambiguous response.
  • Include meta.request_id when asking your operator to investigate.
  • Fulfill only after the payment reaches an authoritative successful state in the platform.

Error response shape

Use the HTTP status and error.code for handling. Details and messages can vary by error.

{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "A human-readable explanation",
    "details": []
  },
  "meta": {
    "request_id": "request-id"
  }
}

Reference

API reference

Use the OpenAPI contract for complete request, response and validation schemas.

Method Endpoint Required scope Purpose
POST /api/v1/payments payments:write Create a payment request for the application's enabled channel.
GET /api/v1/payments/{payment_id} payments:read Read the current payment state, attempts, events and receipt evidence.
GET /api/v1/payments payments:read Search payments using filters such as application, status and merchant reference.
The OpenAPI schema is not publicly available for this deployment. Contact your platform operator for the approved API contract.