Skip to main content

Client

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

Constructor

import { ZenPays } from '@zenxdigitalholdings/zenpays'

const zenpays = new ZenPays(config: ZenPaysConfig)

Configuration

JavaScript

PropertyTypeRequiredDefaultDescription
apiKeystringYes-Your ZenPays API key
baseUrlstringNo'https://api.zenpayz.com'API base URL
apiVersionstringNo'v1'API version
timeoutnumberNo30000Request timeout in ms
fetchtypeof fetchNoglobalThis.fetchCustom fetch function

Python

PropertyTypeRequiredDefaultDescription
api_keystrYes-Your ZenPays API key
base_urlstrNoAuto-detectedAPI base URL
timeoutintNo30Request timeout in seconds
secret_saltstrNoNoneHMAC secret for request signing

Factory Function

import { createClient } from '@zenxdigitalholdings/zenpays'

const zenpays = createClient({
apiKey: 'your-api-key',
})

Properties

version

Returns the SDK version.

console.log(zenpays.version) // '0.5.0'

API Modules

The client provides access to all API modules:

PropertyTypeDescription
analyticsAnalyticsApiReporting and aggregate metrics
authAuthApiAPI key and session operations
chargebacksChargebacksApiDisputes and evidence submission
checkoutCheckoutApiCheckout sessions and on-ramp
customersCustomersApiCustomer management
invoicesInvoicesApiInvoice creation and delivery
ledgerLedgerApiDouble-entry ledger and reconciliation
merchantsMerchantsApiWebhooks, bank accounts, IP whitelist
offRampOffRampApiCrypto-to-fiat conversion
paymentLinksPaymentLinksApiShareable payment links
paymentsPaymentsApiPayment intents and transactions
payoutIntents(object)Payout-intent shorthands — see below
payoutsPayoutsApiPayout operations
rampIntentsRampIntentsApiOn/off-ramp intent lifecycle
refundsRefundsApiRefund operations
securitySecurityApi2FA and security settings
settlementsSettlementsApiSettlement management
subscriptionsSubscriptionsApiPlans, stored methods, recurring billing
tenantHostnamesTenantHostnamesApiWhite-label hostname mapping
vendorsVendorsApiVendor accounts, commissions, referrals
walletWalletApiWallet balance and transactions
Python parity

The Python SDK currently implements analytics, checkout, customers, merchants, payments, payouts, refunds, security, settlements, and wallet. The remaining namespaces are JavaScript-only — call the REST endpoints directly from Python.

payoutIntents

payoutIntents is a convenience object, not an API class. Each property forwards to the correspondingly named method on payouts:

PropertyForwards to
payoutIntents.createpayouts.createPayoutIntent
payoutIntents.confirmpayouts.confirmPayoutIntent
payoutIntents.getpayouts.getPayoutIntent
payoutIntents.listpayouts.listPayoutIntents
payoutIntents.cancelpayouts.cancelPayoutIntent

Webhook Helpers

Signature verification is exported at the package root rather than hung off the client, so it can run in a webhook route with no API key present:

import { constructWebhookEvent, verifyWebhookSignature } from '@zenxdigitalholdings/zenpays'

See the signature verification guide.

Example

import { ZenPays } from '@zenxdigitalholdings/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()

Context Manager

JavaScript doesn't require explicit resource cleanup.

Error Handling

All API methods throw typed errors:

import {
AuthenticationError,
AuthorizationError,
ConfigurationError,
NetworkError,
NotFoundError,
PaymentError,
RateLimitError,
ValidationError,
ZenPaysError,
} from '@zenxdigitalholdings/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.