Client
The ZenPays client is the main entry point for the SDK.
Constructor
import { ZenPays } from 'zenpays'
const zenpays = new ZenPays(config: ZenPaysConfig)
ZenPaysConfig
| Property | Type | Required | Default | Description |
|---|---|---|---|---|
apiKey | string | Yes | - | Your ZenPays API key |
baseUrl | string | No | 'https://api.zenpays.com' | API base URL |
apiVersion | string | No | 'v1' | API version |
timeout | number | No | 30000 | Request timeout in ms |
fetch | typeof fetch | No | globalThis.fetch | Custom fetch function |
Factory Function
import { createClient } from 'zenpays'
const zenpays = createClient({
apiKey: 'your-api-key',
})
Properties
version
Returns the SDK version.
console.log(zenpays.version) // '0.1.0'
API Modules
The client provides access to all API modules:
| Property | Type | Description |
|---|---|---|
payments | PaymentsApi | Payment intents and transactions |
refunds | RefundsApi | Refund operations |
payouts | PayoutsApi | Payout operations |
customers | CustomersApi | Customer management |
merchants | MerchantsApi | Merchant settings, API keys, webhooks |
wallet | WalletApi | Wallet balance and transactions |
checkout | CheckoutApi | Checkout sessions and on-ramp |
analytics | AnalyticsApi | Analytics and reports |
security | SecurityApi | 2FA and security settings |
settlements | SettlementsApi | Settlement management |
Example
import { ZenPays } from 'zenpays'
const zenpays = new ZenPays({
apiKey: process.env.ZENPAYS_API_KEY!,
})
// Use any API module
const balance = await zenpays.wallet.getBalance()
const customers = await zenpays.customers.list()
const analytics = await zenpays.analytics.getDashboardOverview()
Error Handling
All API methods throw typed errors:
import {
AuthenticationError,
AuthorizationError,
ConfigurationError,
NetworkError,
NotFoundError,
PaymentError,
RateLimitError,
ValidationError,
ZenPaysError,
} from 'zenpays'
try {
await zenpays.payments.getPaymentIntent('invalid-id')
}
catch (error) {
if (error instanceof NotFoundError) {
console.log('Payment intent not found')
}
else if (error instanceof AuthenticationError) {
console.log('Invalid API key')
}
}
See the Error Handling guide for more details.