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).
1. Prerequisites & Installation
Section titled “1. Prerequisites & Installation”Kirak communicates with Paystack directly via async REST API calls with httpx. No external Paystack SDK or additional pip package is required.
pip install "kirak"2. Credentials & Configuration
Section titled “2. Credentials & Configuration”Step 1: Obtain API Key
Section titled “Step 1: Obtain API Key”In the Paystack Dashboard:
- Navigate to Settings $\rightarrow$ API Keys & Webhooks.
- Copy your Secret Key (
sk_test_...in test mode,sk_live_...in live mode).
Step 2: Configure kirak.json
Section titled “Step 2: Configure kirak.json”{ "payments": { "default_provider": "paystack", "providers": { "paystack": { "type": "paystack", "environment": "test", "success_url": "https://your-domain.com/payment/success" } } }}Step 3: Set Environment Variables
Section titled “Step 3: Set Environment Variables”KIRAK_PAYMENT_PAYSTACK_SECRET_KEY=sk_test_...(Paystack uses the Secret Key both for API authentication and for HMAC-SHA512 webhook signature verification).
3. Configuring Webhooks
Section titled “3. Configuring Webhooks”In the Paystack Dashboard $\rightarrow$ Settings $\rightarrow$ API Keys & Webhooks:
- Set the Webhook URL for your environment to:
https://your-domain.com/payments/webhook/paystack - Paystack delivers all events to this endpoint. Kirak handles:
charge.successrefund.pending,refund.processing,refund.processed,refund.failed,refund.needs-attentionsubscription.create,invoice.update,invoice.payment_failed,subscription.not_renew,subscription.disablecharge.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, and52.214.14.220.
4. Usage Examples
Section titled “4. Usage Examples”4.1 One-Time Payment
Section titled “4.1 One-Time Payment”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"]4.2 Subscriptions
Section titled “4.2 Subscriptions”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_subscriptionwithat_period_end: Truereturns501 NOT_SUPPORTED.
4.3 Billing Portal (Manage Link)
Section titled “4.3 Billing Portal (Manage Link)”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"]4.4 Saved Cards & Off-Session Charges
Section titled “4.4 Saved Cards & Off-Session Charges”- 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",})5. Webhook Event Mapping
Section titled “5. Webhook Event Mapping”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 |