Skip to main content

Configuration

Learn how to configure the ZenPays SDK for your environment.

Configuration Options

import { ZenPays } from '@zenxdigitalholdings/zenpays'

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

// Optional: API base URL (defaults to production)
baseUrl: 'https://api.zenpayz.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

JavaScript

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

Python

OptionTypeDefaultDescription
api_keystrRequiredYour ZenPays API key
base_urlstrAuto-detectedAPI base URL
timeoutint30Request timeout in seconds
secret_saltstrNoneHMAC secret for request signing

Environment Auto-Detection:

  • zp_live_*https://api.zenpayz.com
  • zp_test_*https://api.test.zenpays.com
  • zp_dev_*https://api.dev.zenpays.com

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! })

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

Context Manager Support

The JavaScript SDK doesn't require explicit cleanup, but you can implement similar patterns if needed.

Type Safety

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

import type { ZenPaysConfig } from '@zenxdigitalholdings/zenpays'
import { ZenPays } from '@zenxdigitalholdings/zenpays'

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

const zenpays = new ZenPays(config)

HMAC Request Signing

HMAC signing is not currently supported in the JavaScript SDK.

Next Steps