Skip to content

JavaScript and TypeScript SDK

Install @arbiro/sdk for Node 22+, edge runtimes and browsers. Typed API client, idempotent retries, webhook verification, money helpers and a React button.

@arbiro/sdk is the official client. It has no runtime dependencies: it uses fetch and Web Crypto, so it runs on Node 22+, Deno, Bun, edge runtimes and in the browser (only the webhook and money helpers belong in the browser; the client needs a secret key).

npm install @arbiro/sdk
pnpm add @arbiro/sdk

Client

import { Arbiro, ArbiroError } from "@arbiro/sdk";

const arbiro = new Arbiro({
  apiKey: process.env.ARBIRO_API_KEY!, // arb_test_... or arb_live_...
  // baseUrl: "https://arbiro.com", maxRetries: 2, timeoutMs: 30_000
});

const account = await arbiro.account.retrieve(); // { merchant_id, livemode }
Resource Methods
paymentLinks create, list, retrieve
checkoutSessions create, retrieve(id, clientSecret)
payments list, retrieve, all (async iterator); addTracking is not available yet (physical goods)
deliveries redeemToken
disputes list, retrieve, uploadEvidence, createEvidenceUpload, completeEvidenceUpload, listEvidence, appeal
webhookEndpoints create, list, disable, sendTest, deliveries
events list, retrieve, trigger (Test Mode), deliveries, resend

For Python, see the Python SDK.

Retries and idempotency

Every POST gets an Idempotency-Key (a random UUID unless you pass idempotencyKey). Network errors, 429 and 5xx answers are retried with backoff using the same key, so a retry never creates a second object. Pass your own key, such as the order id, to make retries safe across process restarts:

await arbiro.checkoutSessions.create({ amount: 25_000_000n, token: "USDC", category: "digital", success_url }, { idempotencyKey: "order_1042" });

Errors

API errors throw ArbiroError with status, code (stable, machine-readable), message and requestId. Network failures have status 0 and code network_error.

try {
  await arbiro.payments.retrieve(paymentId);
} catch (error) {
  if (error instanceof ArbiroError && error.status === 404) {
    // unknown payment for this key and mode
  }
}

Money helpers

Amounts are bigint in atomic units or strings of digits on the wire. Never use floating point for money.

import { fromAtomic, toAtomic } from "@arbiro/sdk/money";

toAtomic("10.50"); // 10_500_000n
fromAtomic("50010000"); // "50.01"

Webhooks

import { constructEvent, verifySignature } from "@arbiro/sdk/webhooks";

const event = await constructEvent(rawBody, request.headers.get("Arbiro-Signature"), secret);

constructEvent throws WebhookSignatureError for a missing, wrong or stale signature and returns an event typed by event.type. See Webhooks.

React

import { ArbiroCheckoutButton } from "@arbiro/sdk/react";

<ArbiroCheckoutButton createSession={() => fetch("/api/checkout", { method: "POST" }).then((r) => r.json())} />;

The button only redirects to https://arbiro.com/pay/... (or the checkoutOrigin you pass). See Hosted checkout.

Updated