Getting Started
Prerequisites
Before using the Afriex SDK, ensure you have:
- Node.js installed (v20 or later)
- A valid Afriex API Key (contact support to obtain one)
Installation
Install the package via your preferred package manager:
npm install @afriex/sdkBasic Usage
1. Import the SDK
import { AfriexSDK, Environment } from "@afriex/sdk";2. Initialize the client
const afriex = new AfriexSDK({
apiKey: process.env.AFRIEX_API_KEY,
environment: "staging", // 'staging' or 'production'
});3. Make a request
// Create a customer
const customer = await afriex.customers.create({
fullName: "John Doe",
email: "john@example.com",
phone: "+1234567890",
countryCode: "US",
});
// Get balance
const balances = await afriex.balance.getBalance({
currencies: ["USD", "NGN"],
});
console.log("Customer:", customer);
console.log("Balances:", balances);Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | Required | Your Afriex API key. |
environment | string | 'production' | Target environment ('staging' or 'production'). |
webhookPublicKey | string | - | Afriex public key for webhook verification. |
retryConfig | RetryConfig | { maxRetries: 0 } | Configuration for request retries. |
Retry Configuration
By default, retries are disabled. You can enable them by passing a retryConfig:
const afriex = new AfriexSDK({
apiKey: "...",
retryConfig: {
maxRetries: 3,
retryDelay: 1000, // 1 second
retryableStatusCodes: [408, 429, 500, 502, 503, 504],
},
});Server URLs
| Environment | URL |
|---|---|
| Staging | https://sandbox.api.afriex.com |
| Production | https://api.afriex.com |