The @zenobia/client package is a JavaScript SDK that provides the core client-side functionality for integrating Zenobia Pay into any website or application. This public npm package enables merchants to easily add "Pay with Zenobia" buttons and payment flows to their sites.
This package provides:
- Core payment SDK functionality
- QR code generation for payments
- Event handling and callbacks
- Cross-platform JavaScript support
- Framework-agnostic implementation
npm install @zenobia/clientor
yarn add @zenobia/client- Payment Integration: Simple API for payment initiation
- QR Code Generation: Built-in QR code creation for payment links
- Event System: Comprehensive event handling for payment lifecycle
- Lightweight: Minimal dependencies, optimized bundle size
- TypeScript Support: Full type definitions included
- Cross-Browser: Works in all modern browsers
import { ZenobiaClient } from '@zenobia/client'
// Initialize the client
const client = new ZenobiaClient({
merchantId: 'your-merchant-id',
environment: 'production' // or 'sandbox'
})
// Create a payment
const payment = await client.createPayment({
amount: 100.00,
orderId: 'order-123',
description: 'Purchase from My Store'
})
// Generate QR code
const qrCode = await client.generateQRCode(payment.id)<script src="https://zenobiapay.com/embed/latest/zenobia-pay.js"></script>
<script>
const client = new ZenobiaPay.Client({
merchantId: 'your-merchant-id'
})
</script>new ZenobiaClient(config: ClientConfig)Config Options:
merchantId(string, required): Your Zenobia merchant IDenvironment(string): 'production' or 'sandbox' (default: 'production')apiUrl(string): Custom API endpoint (optional)
createPayment(options: PaymentOptions): Promise<Payment>Creates a new payment transfer.
Options:
amount(number): Payment amount in dollarsorderId(string): Your internal order IDdescription(string): Payment descriptionmetadata(object): Additional metadata (optional)
generateQRCode(paymentId: string, options?: QROptions): Promise<string>Generates a QR code for a payment.
Options:
size(number): QR code size in pixels (default: 256)format(string): 'svg' or 'png' (default: 'svg')margin(number): QR code margin (default: 4)
getPaymentStatus(paymentId: string): Promise<PaymentStatus>Retrieves the current status of a payment.
cancelPayment(paymentId: string): Promise<void>Cancels a pending payment.
client.on('payment.success', (data) => {
console.log('Payment successful:', data)
})
client.on('payment.failed', (data) => {
console.log('Payment failed:', data)
})
client.on('payment.cancelled', (data) => {
console.log('Payment cancelled:', data)
})Available Events:
payment.initiated: Payment process startedpayment.pending: Waiting for user actionpayment.success: Payment completed successfullypayment.failed: Payment failedpayment.cancelled: Payment cancelled by usererror: General error occurred
import { generateQRCode } from '@zenobia/client'
const qrCodeDataUrl = await generateQRCode(paymentUrl, {
size: 300,
margin: 10
})
// Display in img tag
document.getElementById('qr-code').src = qrCodeDataUrlconst qrCode = await client.generateQRCode(paymentId, {
size: 400,
format: 'svg',
margin: 8,
color: {
dark: '#000000',
light: '#FFFFFF'
},
logo: 'https://yoursite.com/logo.png'
})try {
const payment = await client.createPayment({
amount: 100.00,
orderId: 'order-123'
})
} catch (error) {
if (error.code === 'INVALID_AMOUNT') {
console.error('Invalid payment amount')
} else if (error.code === 'NETWORK_ERROR') {
console.error('Network error, please retry')
} else {
console.error('Payment failed:', error.message)
}
}Error Codes:
INVALID_AMOUNT: Payment amount is invalidINVALID_MERCHANT: Merchant ID not foundNETWORK_ERROR: Network request failedPAYMENT_NOT_FOUND: Payment ID doesn't existUNAUTHORIZED: Authentication failed
Full TypeScript definitions are included:
import {
ZenobiaClient,
PaymentOptions,
Payment,
PaymentStatus,
ClientConfig
} from '@zenobia/client'
const config: ClientConfig = {
merchantId: 'merchant-123',
environment: 'sandbox'
}
const client = new ZenobiaClient(config)
const options: PaymentOptions = {
amount: 100.00,
orderId: 'order-123',
description: 'Test payment'
}
const payment: Payment = await client.createPayment(options)- Chrome 60+
- Firefox 55+
- Safari 11+
- Edge 79+
- Mobile browsers (iOS Safari, Chrome Mobile)
npm run buildThis creates:
dist/index.js- CommonJS builddist/index.esm.js- ES Modules builddist/index.d.ts- TypeScript definitions
npm testTo publish a new version:
npx changeset
npm run releaseThe release script will:
- Run
changeset versionto bump versions - Commit and push changes with tags
- Build the package
- Run
changeset publishto publish to npm
For development:
VITE_API_URL=https://api.zenobiapay.com
VITE_SANDBOX_URL=https://sandbox.zenobiapay.comThe package uses Vite for building:
// vite.config.js
export default {
build: {
lib: {
entry: 'src/index.js',
name: 'ZenobiaClient',
formats: ['es', 'cjs']
}
}
}- Never expose secret keys in client-side code
- Always validate payment amounts server-side
- Use HTTPS in production
- Implement webhook signature verification
- Load SDK asynchronously when possible
- Cache QR codes for repeated use
- Use event delegation for multiple buttons
- Minimize SDK calls in loops
// Recommended initialization pattern
let client;
async function initializeZenobia() {
if (!client) {
client = new ZenobiaClient({
merchantId: process.env.ZENOBIA_MERCHANT_ID,
environment: process.env.NODE_ENV === 'production' ? 'production' : 'sandbox'
})
}
return client
}
// Use throughout your app
const zenobia = await initializeZenobia()Before:
<script src="https://zenobiapay.com/zenobia-pay.js"></script>
<script>
window.ZenobiaPay.init({ merchantId: '123' })
</script>After:
import { ZenobiaClient } from '@zenobia/client'
const client = new ZenobiaClient({ merchantId: '123' })- Module not found: Ensure package is installed correctly
- CORS errors: Check API endpoint configuration
- QR code not generating: Verify payment ID is valid
- Events not firing: Check event listener syntax
const client = new ZenobiaClient({
merchantId: 'test-merchant',
debug: true // Enables console logging
})See CHANGELOG.md for version history.
MIT License - see LICENSE for details.
- Documentation: https://docs.zenobiapay.com
- NPM Package: https://www.npmjs.com/package/@zenobia/client
- Issues: GitHub Issues
- Support: support@zenobiapay.com