Overview
ThePaystackAdapter implements the PaymentAdapter interface to process payments through Paystack’s API. It specializes in African payment methods including cards, bank transfers, and mobile money wallets across Nigeria, Ghana, South Africa, and Kenya.
Class Signature
Constructor
Configuration
Paystack secret key (starts with
sk_test_ or sk_live_).Required. Throws VaultConfigError if not provided.Paystack webhook secret for signature verification. Falls back to
secretKey if not provided.Optional. Used in handleWebhook() method.Custom Paystack API base URL.Default:
"https://api.paystack.co"Request timeout in milliseconds.Default:
15000 (15 seconds)Custom fetch implementation for testing or special network requirements.Default: global
fetchConfiguration Example
Supported Capabilities
Payment Methods
Credit and debit cards including Visa, Mastercard, and Verve.Supports tokenized cards and raw card details with full PCI compliance.
Direct bank transfers and bank account debits.Available in Nigeria (NGN), Ghana (GHS), South Africa (ZAR), and Kenya (KES).
Mobile money wallets popular in African markets.Includes M-Pesa, MTN Mobile Money, Vodafone Cash, and other regional providers.
Supported Currencies
5 currencies covering African and international markets:- Nigeria: NGN (Naira)
- Ghana: GHS (Cedi)
- South Africa: ZAR (Rand)
- Kenya: KES (Shilling)
- International: USD
Supported Countries
4 African countries:- NG - Nigeria
- GH - Ghana
- ZA - South Africa
- KE - Kenya
Methods
Implements allPaymentAdapter interface methods:
charge()- Initiates a Paystack chargeauthorize()- Creates a charge with authorization intentcapture()- Captures an authorized payment using authorization coderefund()- Processes a full or partial refundvoid()- Cancels a transaction via refundgetStatus()- Verifies transaction statuslistPaymentMethods()- Returns available payment methodshandleWebhook()- Verifies and processes Paystack webhook events
Webhook Events
The adapter maps Paystack webhook events to VaultSaaS event types:| Paystack Event | VaultSaaS Event |
|---|---|
charge.success | payment.completed |
charge.failed | payment.failed |
charge.pending | payment.pending |
refund.processed / refund.success | payment.refunded |
refund.pending | payment.partially_refunded |
dispute.create / charge.dispute.create | payment.disputed |
dispute.resolve / charge.dispute.resolve | payment.dispute_resolved |
transfer.success | payout.completed |
transfer.failed | payout.failed |
Webhook Verification
Paystack webhooks are verified using HMAC-SHA512 signatures:- Signature header:
x-paystack-signature - Algorithm: HMAC-SHA512 of raw payload
- Secret:
webhookSecret(or falls back tosecretKey)
Status Mapping
Paystack transaction statuses are mapped to VaultSaaS statuses:| Paystack Status | VaultSaaS Status |
|---|---|
success | completed |
pending / ongoing / queued | pending |
abandoned | cancelled |
failed / reversed | failed |
Error Handling
The adapter enriches errors with Paystack-specific context:Provider Metadata
Payment results include Paystack-specific metadata:Special Considerations
Customer Email Required
Paystack requires a customer email address for all charge and authorize operations:Capture Implementation
Paystack doesn’t have a native “capture” endpoint. The adapter implements capture by:- Verifying the original transaction to get the authorization code
- Creating a new charge using the
charge_authorizationendpoint
capture() method requires the original transaction to have an authorization code and customer email.
Response Envelope
Paystack wraps all responses in an envelope:status field.
Usage Examples
Card Payment (Nigeria)
Bank Transfer (Ghana)
Mobile Money Wallet (Kenya)
Authorize and Capture
Currency Precision
Paystack uses subunits for amounts:- NGN: Amount in kobo (1 Naira = 100 kobo)
- GHS: Amount in pesewas (1 Cedi = 100 pesewas)
- ZAR: Amount in cents (1 Rand = 100 cents)
- KES: Amount in cents (1 Shilling = 100 cents)
- USD: Amount in cents (1 Dollar = 100 cents)