Overview
ThePaystack class is the main entry point for the Paystack TypeScript SDK. It provides access to all Paystack APIs through module properties, each representing a different Paystack service.
Constructor
Paystack(secretKey)
Creates a new instance of the Paystack SDK.Your Paystack secret key. Must start with
sk_live_ for production or sk_test_ for testing.Validation
The constructor validates the secret key format using Zod schema validation (from src/index.ts:34-42):Properties
Once instantiated, the Paystack class provides access to the following module properties:transaction
Provides methods for interacting with Paystack’s Transaction API. Initialize, verify, list, and manage transactions.View Transaction API Reference →
transfer
Provides methods for interacting with Paystack’s Transfer API. Initiate, finalize, and manage transfers to bank accounts.View Transfer API Reference →
recipient
Provides methods for interacting with Paystack’s Transfer Recipient API. Create and manage transfer recipients.View Recipient API Reference →
split
Provides methods for managing transaction splits on your integration. Create and manage split payment configurations.View Split API Reference →
virtualAccount
Provides methods for interacting with Paystack’s Dedicated Virtual Account API. Create and manage dedicated virtual accounts.View Virtual Account API Reference →
verification
Provides methods for verifying various Paystack entities. Resolve account numbers, validate accounts, and verify card BINs.View Verification API Reference →
miscellaneous
Provides methods for accessing miscellaneous Paystack data. List supported banks, countries, and states.View Miscellaneous API Reference →
webhook
Provides methods for verifying and processing Paystack webhooks. Handle incoming webhook events securely.View Webhook API Reference →
Usage Examples
Basic Initialization
From the SDK test suite (src/tests/sdk.test.ts:5-15):Using Multiple Modules
Error Handling
Invalid Secret Key
All module properties are automatically instantiated when you create a Paystack instance. You don’t need to initialize them separately.
Module Initialization
Behind the scenes (from src/index.ts:43-51), the constructor initializes all modules with the secret key and base URL:Fetcher base class which handles HTTP requests to the Paystack API at https://api.paystack.co.
