Skip to main content

Configuration

Learn how to configure the ZenPays SDK for your environment.

Configuration Options

import { ZenPays } from 'zenpays'

const zenpays = new ZenPays({
// Required: Your API key
apiKey: 'your-api-key',

// Optional: API base URL (defaults to production)
baseUrl: 'https://api.zenpays.com',

// Optional: API version (defaults to 'v1')
apiVersion: 'v1',

// Optional: Request timeout in milliseconds (defaults to 30000)
timeout: 30000,

// Optional: Custom fetch implementation
fetch: customFetch,
})

Environment Configuration

Production

const zenpays = new ZenPays({
apiKey: process.env.ZENPAYS_LIVE_API_KEY!,
})

Sandbox/Testing

const zenpays = new ZenPays({
apiKey: process.env.ZENPAYS_TEST_API_KEY!,
baseUrl: 'https://sandbox.zenpays.com',
})

Configuration Options Reference

OptionTypeDefaultDescription
apiKeystringRequiredYour ZenPays API key
baseUrlstring'https://api.zenpays.com'API base URL
apiVersionstring'v1'API version to use
timeoutnumber30000Request timeout in milliseconds
fetchtypeof fetchglobalThis.fetchCustom fetch implementation

Using Environment Variables

We recommend storing your API keys in environment variables:

# .env
ZENPAYS_API_KEY=zp_live_xxxxx
ZENPAYS_TEST_API_KEY=zp_test_xxxxx
// Use test key in development
const apiKey = process.env.NODE_ENV === 'production'
? process.env.ZENPAYS_API_KEY
: process.env.ZENPAYS_TEST_API_KEY

const zenpays = new ZenPays({ apiKey: apiKey! })

Custom Fetch Implementation

You can provide a custom fetch implementation for special use cases:

import nodeFetch from 'node-fetch'
import { ZenPays } from 'zenpays'

// For older Node.js versions without native fetch
const zenpays = new ZenPays({
apiKey: 'your-api-key',
fetch: nodeFetch as unknown as typeof fetch,
})

Timeout Configuration

Adjust timeouts for different scenarios:

// Longer timeout for batch operations
const zenpays = new ZenPays({
apiKey: 'your-api-key',
timeout: 120000, // 2 minutes
})

Multiple Instances

Create multiple client instances for different environments or merchants:

// Production client
const prodClient = new ZenPays({
apiKey: process.env.ZENPAYS_LIVE_KEY!,
})

// Sandbox client for testing
const testClient = new ZenPays({
apiKey: process.env.ZENPAYS_TEST_KEY!,
baseUrl: 'https://sandbox.zenpays.com',
})

// Use the appropriate client based on context
const client = isTestMode ? testClient : prodClient

Type Safety

The SDK is fully typed. Get IntelliSense and type checking:

import type { ZenPaysConfig } from 'zenpays'
import { ZenPays } from 'zenpays'

// Type-safe configuration
const config: ZenPaysConfig = {
apiKey: 'your-api-key',
timeout: 30000,
}

const zenpays = new ZenPays(config)

Next Steps