> ## Documentation Index
> Fetch the complete documentation index at: https://paystack-sdk.efobi.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Paystack Class

> The main entry point for the Paystack TypeScript SDK

## 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.

<ParamField path="secretKey" type="string" required>
  Your Paystack secret key. Must start with `sk_live_` for production or `sk_test_` for testing.
</ParamField>

<CodeGroup>
  ```typescript Test Environment theme={null}
  import { Paystack } from '@paystackly/core';

  const paystack = new Paystack('sk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
  ```

  ```typescript Production Environment theme={null}
  import { Paystack } from '@paystackly/core';

  const paystack = new Paystack('sk_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
  ```
</CodeGroup>

### Validation

The constructor validates the secret key format using Zod schema validation (from src/index.ts:34-42):

```typescript theme={null}
const secretKeySchema = z
  .string()
  .startsWith("sk_live_")
  .or(z.string().startsWith("sk_test_"));
if (!secretKeySchema.safeParse(secretKey).success) {
  throw new Error(
    "Invalid secret key. It must start with 'sk_live_' or 'sk_test_'.",
  );
}
```

<Warning>
  The constructor will throw an error if the secret key doesn't start with `sk_live_` or `sk_test_`.
</Warning>

## Properties

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

### transaction

<ResponseField name="transaction" type="Transaction">
  Provides methods for interacting with Paystack's Transaction API. Initialize, verify, list, and manage transactions.

  [View Transaction API Reference →](/api-reference/transaction)
</ResponseField>

### transfer

<ResponseField name="transfer" type="Transfer">
  Provides methods for interacting with Paystack's Transfer API. Initiate, finalize, and manage transfers to bank accounts.

  [View Transfer API Reference →](/api-reference/transfer)
</ResponseField>

### recipient

<ResponseField name="recipient" type="Recipient">
  Provides methods for interacting with Paystack's Transfer Recipient API. Create and manage transfer recipients.

  [View Recipient API Reference →](/api-reference/recipient)
</ResponseField>

### split

<ResponseField name="split" type="Split">
  Provides methods for managing transaction splits on your integration. Create and manage split payment configurations.

  [View Split API Reference →](/api-reference/split)
</ResponseField>

### virtualAccount

<ResponseField name="virtualAccount" type="VirtualAccount">
  Provides methods for interacting with Paystack's Dedicated Virtual Account API. Create and manage dedicated virtual accounts.

  [View Virtual Account API Reference →](/api-reference/virtual-account)
</ResponseField>

### verification

<ResponseField name="verification" type="Verification">
  Provides methods for verifying various Paystack entities. Resolve account numbers, validate accounts, and verify card BINs.

  [View Verification API Reference →](/api-reference/verification)
</ResponseField>

### miscellaneous

<ResponseField name="miscellaneous" type="Miscellaneous">
  Provides methods for accessing miscellaneous Paystack data. List supported banks, countries, and states.

  [View Miscellaneous API Reference →](/api-reference/miscellaneous)
</ResponseField>

### webhook

<ResponseField name="webhook" type="Webhook">
  Provides methods for verifying and processing Paystack webhooks. Handle incoming webhook events securely.

  [View Webhook API Reference →](/api-reference/webhook)
</ResponseField>

## Usage Examples

### Basic Initialization

From the SDK test suite (src/tests/sdk.test.ts:5-15):

```typescript theme={null}
import { Paystack } from '@paystackly/core';

const secret = "sk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
const paystack = new Paystack(secret);

// All modules are automatically initialized and available
console.log(paystack.miscellaneous);  // Miscellaneous instance
console.log(paystack.split);           // Split instance
console.log(paystack.transaction);     // Transaction instance
console.log(paystack.transfer);        // Transfer instance
console.log(paystack.verification);    // Verification instance
console.log(paystack.webhook);         // Webhook instance
```

### Using Multiple Modules

```typescript theme={null}
import { Paystack } from '@paystackly/core';

const paystack = new Paystack('sk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');

// Initialize a transaction
const transaction = await paystack.transaction.initialize({
  email: 'customer@email.com',
  amount: 10000, // Amount in kobo (100 NGN)
});

// List available banks
const banks = await paystack.miscellaneous.listBanks({
  country: 'nigeria',
});

// Verify an account number
const account = await paystack.verification.resolveAccount({
  account_number: '0123456789',
  bank_code: '058',
});
```

## Error Handling

### Invalid Secret Key

```typescript theme={null}
import { Paystack } from '@paystackly/core';

try {
  // This will throw an error
  const paystack = new Paystack('invalid_key');
} catch (error) {
  console.error(error.message);
  // "Invalid secret key. It must start with 'sk_live_' or 'sk_test_'."
}
```

<Note>
  All module properties are automatically instantiated when you create a Paystack instance. You don't need to initialize them separately.
</Note>

## Module Initialization

Behind the scenes (from src/index.ts:43-51), the constructor initializes all modules with the secret key and base URL:

```typescript theme={null}
this.secretKey = secretKey;
this.transaction = new Transaction(this.secretKey, this.baseUrl);
this.split = new Split(this.secretKey, this.baseUrl);
this.virtualAccount = new VirtualAccount(this.secretKey, this.baseUrl);
this.webhook = new Webhook(this.secretKey, this.baseUrl);
this.verification = new Verification(this.secretKey, this.baseUrl);
this.miscellaneous = new Miscellaneous(this.secretKey, this.baseUrl);
this.transfer = new Transfer(this.secretKey, this.baseUrl);
this.recipient = new Recipient(this.secretKey, this.baseUrl);
```

All modules extend the `Fetcher` base class which handles HTTP requests to the Paystack API at `https://api.paystack.co`.
