Or jump from this list on a smaller screen.

This is a page from the Audivra documentation. Developer exportsindex: http://127.0.0.1:3000/docs/llms.txt, full corpus: http://127.0.0.1:3000/docs/llms-full.txt, OpenAPI: http://127.0.0.1:3000/docs/openapi.json, Postman: http://127.0.0.1:3000/docs/postman.json. Press ⌘K to search docs.

Accept M-Pesa via Paystack webhook

Let Kenyan users pay with M-Pesa through Paystack — checkout redirect, webhook verification, and plan upgrade on charge.success.

Developers
~20 min

Outcome: Live M-Pesa checkout that upgrades the user plan when Paystack fires charge.success to your webhook.

  1. 1

    Create a Paystack account and keys

    Register at Paystack and enable Kenya (KES) collections including Mobile Money / M-Pesa.

    Copy your secret key and set PAYSTACK_SECRET_KEY in .env. Generate a webhook secret for PAYSTACK_WEBHOOK_SECRET.

  2. 2

    Start checkout from your app

    Call POST /api/billing/checkout with provider paystack and region africa. The user is redirected to Paystack’s hosted page where they choose M-Pesa.

    cURL — initiate checkout
    curl -X POST https://audivra.dev/api/billing/checkout \
      -H "Cookie: session=…" \
      -H "Content-Type: application/json" \
      -d '{"plan":"creator","provider":"paystack","region":"africa"}'
    
    # → { "ok": true, "url": "https://checkout.paystack.com/…", "mode": "redirect" }
  3. 3

    Expose your webhook URL

    In Paystack Dashboard → Settings → Webhooks, set URL to https://your-domain.com/api/webhooks/paystack.

    Subscribe to charge.success. For local dev, use ngrok or Cloudflare Tunnel to forward HTTPS to localhost:3000.

    Paystack webhook URL
    https://audivra.dev/api/webhooks/paystack
  4. 4

    Verify signatures in production

    Audivra verifies x-paystack-signature as HMAC-SHA512 of the raw body using PAYSTACK_SECRET_KEY. Production accepts HMAC only; PAYSTACK_WEBHOOK_SECRET shared-secret comparison is a local-dev fallback.

    On charge.success, the handler dedupes by data.reference, maps customer email → profile, and applies the purchased plan.

    .env
    PAYSTACK_SECRET_KEY=sk_live_…
    PAYSTACK_WEBHOOK_SECRET=whsec_…
    DEFAULT_PAYMENT_PROVIDER=paystack
  5. 5

    Confirm the upgrade

    After a test M-Pesa payment, check /app/billing — credits and plan tier should update within seconds.

    Use Paystack test mode first; switch to live keys only after end-to-end verification.

    Flutterwave is an alternative for pan-African M-Pesa + MTN rails — see the Billing API for provider options.

Related reference

/docs/api/billing

/docs/api/webhooks

/docs/concepts/credits