Skip to main content

Client Reference

The ZendFiClient class is the core of the SDK. It provides methods for every ZendFi API operation with built-in retries, idempotency, and typed responses.

Constructor

Configuration Options

apiKey
string
Your ZendFi API key. Falls back to ZENDFI_API_KEY env var.
baseURL
string
default:"https://api.zendfi.tech"
API base URL. Override for self-hosted or proxy setups.
environment
string
default:"auto-detected"
development, staging, or production. Auto-detected from NODE_ENV.
mode
string
default:"auto-detected"
test or live. Auto-detected from API key prefix.
timeout
number
default:"30000"
Request timeout in milliseconds.
retries
number
default:"3"
Number of retry attempts for failed requests (5xx and network errors).
idempotencyEnabled
boolean
default:"true"
Automatically generate idempotency keys for POST requests.
debug
boolean
default:"false"
Log all requests and responses to the console.

Payments

createPayment

Creates a new payment and returns a checkout URL.
Returns
Payment
Payment object with id, status, payment_url, checkout_url, qr_code, expires_at, and more.

getPayment

Retrieves a payment by ID.

Creates a shareable checkout URL.

With payment splits (wallet recipients)

Automatically distribute payments across multiple wallets:

With payment splits (bank account recipients)

Enable NGN bank deposits via PAJ bank account integration:
For bank recipients, the SDK accepts recipient_bank_id plus aliases recipient_bank, bank_identifier, and bank_code. For wallet recipients, you can target a sub-account directly with sub_account_id (or alias recipient_sub_account) instead of recipient_wallet.

With a pre-filled customer object

When you supply a customer object the checkout page skips the email / info collection step entirely and shows a single “Continue to Pay” button instead. The customer data is passed directly into the payment flow (including the onramp initiation). The link is automatically locked to max_uses = 1.

Sub Accounts

Sub-account methods are documented in detail on SDK Sub Accounts.

createSubAccount

listSubAccounts

getSubAccount / getSubAccountBalance

mintSubAccountDelegationToken

freezeSubAccount / closeSubAccount

drainSubAccount / withdrawFromSubAccount


Subscriptions

createSubscriptionPlan

Defines a recurring billing plan.

getSubscriptionPlan

createSubscription

Subscribes a customer to a plan.

getSubscription

cancelSubscription


Installment Plans

createInstallmentPlan

Splits a purchase into scheduled payments.

getInstallmentPlan

listInstallmentPlans

listCustomerInstallmentPlans

cancelInstallmentPlan


Invoices

createInvoice

Creates a professional invoice.

With onramp enabled

When onramp: true, the payment link generated by sendInvoice() will use the PAJ onramp flow (NGN bank transfer → USDC settlement) instead of a direct crypto payment.

getInvoice

listInvoices

sendInvoice

Sends the invoice to the customer via email.

Webhooks

verifyWebhook

Verifies the HMAC-SHA256 signature of an incoming webhook.
Always pass the raw request body as the payload, not the parsed JSON. Parsing and re-serializing can alter whitespace and break the signature.

Retry and Idempotency

The client automatically retries failed requests:
  • 5xx errors: Retried up to retries times with exponential backoff (2n2^n seconds)
  • Network errors: Retried with the same backoff logic
  • 4xx errors: Never retried (these indicate client-side issues)
Idempotency keys are generated automatically for all POST requests when idempotencyEnabled is true (the default). This prevents duplicate charges from retried requests.

Debug Mode

Enable debug logging to see all requests and responses:
Output: