Installation
Install and configure the HivePay SDK for your project.
Package Installation
pnpm add @hivepay/client
npm install @hivepay/client
yarn add @hivepay/client
bun add @hivepay/client
composer require hivepay/client
ESM Import
The SDK is distributed as an ESM module:
import { HivePay } from '@hivepay/client';
import { HivePay } from '@hivepay/client';
const { HivePay } = require('@hivepay/client');
Creating a Client
With API Key
Most operations require an API key:
import { HivePay } from '@hivepay/client';
const hivepay = new HivePay({
apiKey: 'sk_live_xxxxxxxxxxxxx'
});
Without API Key
Registration doesn't require an API key:
import { HivePay } from '@hivepay/client';
// Create public client
const publicClient = new HivePay();
// Register a merchant
const result = await publicClient.merchants.register({
name: 'My Store',
hiveAccount: 'mystore'
});
// Create authenticated client from result
const authClient = publicClient.withApiKey(result.apiKey);
Configuration Options
Full Configuration
const hivepay = new HivePay({
apiKey: 'sk_live_xxxxxxxxxxxxx',
webhookSecret: 'whsec_xxxxxxxxxxxxx', // For webhook verification
endpoint: 'https://hivepay.me', // Default
timeout: 30000 // 30 seconds
});
Custom Endpoint
For self-hosted deployments:
const hivepay = new HivePay({
apiKey: 'sk_live_xxxxxxxxxxxxx',
endpoint: 'https://your-hivepay-instance.com'
});
Environment Variables
Store your API key securely using environment variables:
// .env
HIVEPAY_API_KEY=sk_live_xxxxxxxxxxxxx
HIVEPAY_WEBHOOK_SECRET=whsec_xxxxxxxxxxxxx
// app.ts
import { HivePay } from '@hivepay/client';
const hivepay = new HivePay({
apiKey: process.env.HIVEPAY_API_KEY!,
webhookSecret: process.env.HIVEPAY_WEBHOOK_SECRET!
});
require('dotenv').config();
const { HivePay } = require('@hivepay/client');
const hivepay = new HivePay({
apiKey: process.env.HIVEPAY_API_KEY,
webhookSecret: process.env.HIVEPAY_WEBHOOK_SECRET
});
TypeScript Configuration
The SDK includes TypeScript definitions. No additional @types package is needed.
Recommended tsconfig.json settings:
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "bundler",
"esModuleInterop": true,
"strict": true
}
}
Browser Usage
The SDK works in modern browsers with native fetch support:
<script type="module">
import { HivePay } from 'https://esm.sh/@hivepay/client';
const hivepay = new HivePay({ apiKey: 'sk_live_xxx' });
// ...
</script>
Security Warning
Never expose your API key in client-side code! Use a backend server to create payments, then pass the checkout URL to the frontend.
Verifying Installation
Test your installation:
import { HivePay } from '@hivepay/client';
const hivepay = new HivePay({ apiKey: process.env.HIVEPAY_API_KEY! });
async function testConnection() {
try {
const merchant = await hivepay.merchants.getCurrent();
console.log('Connected as:', merchant.name);
} catch (error) {
console.error('Connection failed:', error);
}
}
testConnection();
Next Steps
- Payments API - Create and manage payments
- Merchants API - Manage merchant accounts
- Billing API - Read your monthly billing summary and outstanding invoices
- Error Handling - Handle errors gracefully