Skip to main content

Overview

The Paystack 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.
string
required
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):
The constructor will throw an error if the secret key doesn’t start with sk_live_ or sk_test_.

Properties

Once instantiated, the Paystack class provides access to the following module properties:

transaction

Transaction
Provides methods for interacting with Paystack’s Transaction API. Initialize, verify, list, and manage transactions.View Transaction API Reference →

transfer

Transfer
Provides methods for interacting with Paystack’s Transfer API. Initiate, finalize, and manage transfers to bank accounts.View Transfer API Reference →

recipient

Recipient
Provides methods for interacting with Paystack’s Transfer Recipient API. Create and manage transfer recipients.View Recipient API Reference →

split

Split
Provides methods for managing transaction splits on your integration. Create and manage split payment configurations.View Split API Reference →

virtualAccount

VirtualAccount
Provides methods for interacting with Paystack’s Dedicated Virtual Account API. Create and manage dedicated virtual accounts.View Virtual Account API Reference →

verification

Verification
Provides methods for verifying various Paystack entities. Resolve account numbers, validate accounts, and verify card BINs.View Verification API Reference →

miscellaneous

Miscellaneous
Provides methods for accessing miscellaneous Paystack data. List supported banks, countries, and states.View Miscellaneous API Reference →

webhook

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:
All modules extend the Fetcher base class which handles HTTP requests to the Paystack API at https://api.paystack.co.