Skip to main content

Client

The ZenPays client is the main entry point for the SDK.

Constructor

import { ZenPays } from 'zenpays'

const zenpays = new ZenPays(config: ZenPaysConfig)

ZenPaysConfig

PropertyTypeRequiredDefaultDescription
apiKeystringYes-Your ZenPays API key
baseUrlstringNo'https://api.zenpays.com'API base URL
apiVersionstringNo'v1'API version
timeoutnumberNo30000Request timeout in ms
fetchtypeof fetchNoglobalThis.fetchCustom 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:

PropertyTypeDescription
paymentsPaymentsApiPayment intents and transactions
refundsRefundsApiRefund operations
payoutsPayoutsApiPayout operations
customersCustomersApiCustomer management
merchantsMerchantsApiMerchant settings, API keys, webhooks
walletWalletApiWallet balance and transactions
checkoutCheckoutApiCheckout sessions and on-ramp
analyticsAnalyticsApiAnalytics and reports
securitySecurityApi2FA and security settings
settlementsSettlementsApiSettlement 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.