Skip to content

Paystack Setup & Integration Guide

The paystack provider integrates Paystack Standard, Subscriptions, Customer Manage Link (Billing Portal), Saved Cards, and Dispute Ingestion into the Kirak payments runtime across African and global markets (NGN, GHS, KES, ZAR, USD, XOF, EGP, RWF).


Kirak communicates with Paystack directly via async REST API calls with httpx. No external Paystack SDK or additional pip package is required.

Terminal window
pip install "kirak"

In the Paystack Dashboard:

  1. Navigate to Settings $\rightarrow$ API Keys & Webhooks.
  2. Copy your Secret Key (sk_test_... in test mode, sk_live_... in live mode).
{
"payments": {
"default_provider": "paystack",
"providers": {
"paystack": {
"type": "paystack",
"environment": "test",
"success_url": "https://your-domain.com/payment/success"
}
}
}
}
Terminal window
KIRAK_PAYMENT_PAYSTACK_SECRET_KEY=sk_test_...

(Paystack uses the Secret Key both for API authentication and for HMAC-SHA512 webhook signature verification).


In the Paystack Dashboard $\rightarrow$ Settings $\rightarrow$ API Keys & Webhooks:

  1. Set the Webhook URL for your environment to: https://your-domain.com/payments/webhook/paystack
  2. Paystack delivers all events to this endpoint. Kirak handles:
    • charge.success
    • refund.pending, refund.processing, refund.processed, refund.failed, refund.needs-attention
    • subscription.create, invoice.update, invoice.payment_failed, subscription.not_renew, subscription.disable
    • charge.dispute.create, charge.dispute.remind, charge.dispute.resolve

[!TIP] Optional Proxy IP Allowlist: For high-security environments, you can restrict incoming traffic to Paystack’s official webhook egress IP addresses: 52.31.139.75, 52.49.173.169, and 52.214.14.220.


Amounts are passed in minor units (e.g. kobo for NGN; 250,000 kobo = NGN 2,500.00):

result = await kirak.payments.initiate_payment({
"provider": "paystack",
"user_id": "usr_600",
"amount": 250000, # ₦2,500.00 in kobo
"currency": "NGN",
"name": "Course Access",
"type": "one_time",
"payment_email": "buyer@example.com", # Required by Paystack
})
checkout_url = result["data"]["url"]

Subscriptions link to a Paystack Plan code (PLN_...):

result = await kirak.payments.initiate_payment({
"provider": "paystack",
"user_id": "usr_600",
"amount": 0, # Price determined by Paystack Plan
"currency": "NGN",
"name": "Pro Monthly",
"type": "subscription",
"subscription_plan_id": "PLN_gx2ef52msaege5x",
"payment_email": "buyer@example.com",
})

[!WARNING] Cancellation Behavior: Paystack’s API only supports immediate cancellation. Calling cancel_subscription with at_period_end: True returns 501 NOT_SUPPORTED.

Returns Paystack’s customer subscription manage link, allowing users to update their payment card or cancel:

portal = await kirak.payments.get_billing_portal({
"user_id": "usr_600",
"provider": "paystack",
})
manage_link = portal["data"]["portal_url"]
  • Save a reusable authorization during one-time checkout (save_payment_method: True).
  • Charge the saved card headless via charge_off_session (Admin / System only):
result = await kirak.payments.charge_off_session({
"provider": "paystack",
"user_id": "usr_600",
"amount": 500000, # ₦5,000.00
"currency": "NGN",
"name": "Cloud Storage Overage",
"idempotency_key": "paystack-charge-usr600-oct",
})

Normalized event Gateway Events Description
payment_completed charge.success Transaction approved and settled
payment_failed invoice.payment_failed Payment failed
subscription_renewed invoice.update (status="paid") Subscription cycle billed
subscription_cancelled subscription.disable, subscription.not_renew Subscription canceled
refund_completed refund.processed Refund settled
dispute_created charge.dispute.create Dispute filed
dispute_updated charge.dispute.remind, charge.dispute.resolve Dispute status updated
payment_method_saved charge.success (with reusable authorization) Card vaulted