Billing SDK

Method reference

Every method on the Faurya Billing SDK client, what it does and which API endpoint it calls.

Method reference

import { createFauryaBilling } from "@faurya/billing";

const faurya = createFauryaBilling();

Every method returns a promise and accepts an optional last argument { signal, timeoutMs, maxRetries } (per-request options).

Payments and goals

MethodWhat it doesRetried automatically
faurya.payments.create(params)Record one payment.Rate limits only
faurya.payments.delete(filters)Permanently delete payments by transaction_id, faurya_visitor_id or time range.Rate limits only
faurya.goals.create(params)Record a goal for a visitor.Rate limits only

Guide: Payments and goals · API: Create payment, Delete payment, Create goal

Billing

All billing.* calls are safe to repeat and are retried automatically.

MethodWhat it does
billing.customers.upsert(id, params?)Create or update a customer. Fields you leave out are kept.
billing.customers.retrieve(id)Read a customer, its linked visitor count and its subscriptions.
billing.plans.upsert(id, params)Create or update a plan (name and cadence).
billing.plans.retrieve(id)Read a plan.
billing.invoices.upsert(id, params)Create an invoice, or replace it while it's still unpaid.
billing.invoices.retrieve(id)Read an invoice with its lines, transactions and calculated status.
billing.invoices.setStatus(id, "voided" | "written_off")Void or write off an invoice. Final.
billing.transactions.upsert(id, params)Record a payment, refund, chargeback or chargeback reversal.
billing.transactions.retrieve(id)Read a transaction.
billing.subscriptionEvents.record(id, params)Record a cancellation, pause, scheduled change or retraction.
billing.subscriptions.retrieve(id)Read a subscription's MRR, status, history and whether it counts as a subscriber.

id is always your own id for that object.

Guides: Subscriptions and invoices, Subscription lifecycle · API: Billing API

Response shape

Every upsert, record and setStatus call resolves to:

{
  object: "invoice",       // the kind of object
  external_id: "inv_1042", // your id
  created: true,           // true only the first time (not on setStatus)
  data: { ... },           // the object as Faurya stored it
  warnings: [],            // non-fatal notes, e.g. VISITOR_PENDING
  request_id: "req_...",   // quote this to support
}

Every retrieve call resolves to the same without created and warnings.

Bulk import

MethodWhat it does
billing.imports.run(items, options?)Do the whole import: open, upload in batches, commit and wait. Accepts arrays, generators and async generators.
billing.imports.create({ external_id? })Open an import.
billing.imports.uploadItems(importId, items)Upload 1–1,000 items.
billing.imports.commit(importId)Close the import and start processing.
billing.imports.cancel(importId)Abandon an import.
billing.imports.retrieve(importId)Check an import's status, counts and failures.
billing.imports.waitForCompletion(importId, options?)Wait until the import finishes.

Guide: Bulk import · API: Bulk import

Exports

ExportWhat it is
createFauryaBilling(options?) / FauryaBillingThe client
FauryaError and its subclassesSee Errors and retries
isTerminalImportStatus(status)true when an import has finished
SDK_VERSIONThe installed SDK version
Types (InvoiceUpsertParams, Subscription, ImportItem…)Every request and response type