# Libraries

Three for JavaScript, open source under the MIT licence, at [github.com/shipbill/shipbill-js](https://github.com/shipbill/shipbill-js). None is required: the API is plain HTTP and JSON.

| Library | For | Get it |
| --- | --- | --- |
| `shipbill.js` | Your pages: the checkout over the page, buy buttons, price previews | `<script src="https://js.shipbill.io/v1/shipbill.js">` |
| `@shipbill/js` | Apps with a bundler (React, Vite, Next.js): loads shipbill.js, typed | `npm install @shipbill/js` |
| `@shipbill/node` | Your server (Node 20.3+ or Bun): every API call, typed, and the webhook check | `npm install @shipbill/node` |

## shipbill.js

Served from `js.shipbill.io/v1/`, which always has the current 1.x release. It holds no secret and no payment logic; it opens the checkout from `pay.shipbill.io` in a frame and listens only to that frame.

|  |  |
| --- | --- |
| `ShipBill.init(publishableKey)` | Needed for buy buttons and price previews. A secret key is refused. |
| `ShipBill.checkout.open(clientToken, callbacks)` | Opens a checkout your server created. Callbacks: `onReady`, `onComplete`, `onClose`, `onError`. |
| `ShipBill.checkout.open({ product, quantity, customerEmail, reference }, callbacks)` | Opens a checkout for one of your products, as a buy button does. |
| `ShipBill.checkout.close()` | Closes the open checkout. |
| `ShipBill.prices.get([productIds])` | Prices as the checkout would show this visitor: up to 20 products. |

Buy buttons are described in [Buy button](https://shipbill.io/docs/buy-button). To run one exact release, use its own address and integrity hash from the release notes:

```html
<script src="https://js.shipbill.io/v1.0.0/shipbill.js"
        integrity="sha384-…" crossorigin="anonymous"></script>
```

## @shipbill/js

```ts
import { loadShipBill } from "@shipbill/js";

const shipbill = await loadShipBill("pk_live_…"); // null during server-side rendering
shipbill?.checkout.open(clientToken, { onComplete: () => refreshAccount() });
```

`@shipbill/js/react` has `useShipBill(publishableKey)`. The script still comes from `js.shipbill.io`, so fixes reach your site without a new build.

## @shipbill/node

```ts
import { ShipBill } from "@shipbill/node";

const shipbill = new ShipBill(process.env.SHIPBILL_SECRET_KEY);

const session = await shipbill.checkout.sessions.create({ line_items: [{ product: "prod_…" }] });
const page = await shipbill.payments.list({ reference: "order_1001" });          // one page
for await (const event of shipbill.events.list({ created_after: since })) { … }  // every page
const event = shipbill.webhooks.verify(rawBody, signatureHeader, signingSecret);
```

- A method for every operation in the [API reference](https://shipbill.io/docs/api), typed; events are typed by their `type`.
- An `Idempotency-Key` on every POST, and retries after network failures, rate limits, and server errors.
- Errors as classes by type (`ShipBillInvalidRequestError`, …), each with `code`, `param`, and `requestId`.
- `webhooks.verify` refuses a signature older than five minutes; `webhooks.sign` makes one for testing your receiver.

## By language

One repository for each language, each with its own releases and changelog.

| Language | Repository | Packages |
| --- | --- | --- |
| JavaScript and TypeScript | [shipbill/shipbill-js](https://github.com/shipbill/shipbill-js) | `shipbill.js`, `@shipbill/js`, `@shipbill/node` |
| Python | Planned, not yet available | `shipbill` on PyPI |

Until there is one for your language, every call is plain HTTPS with a bearer key; check webhook signatures as described in [Webhooks](https://shipbill.io/docs/webhooks#signature).

## Building one for another language

Every ShipBill library follows the same rules, so a call, a retry, or a webhook check behaves the same in each. A library for another language meets all of them:

- **Generated from the specification**, [api.shipbill.io/v1/openapi.json](https://api.shipbill.io/v1/openapi.json): a method for every operation and a type for every object, never written by hand.
- **Named by the specification.** Each operation's `x-shipbill-sdk` gives its resource and method in lower-case words joined by underscores, dotted for a nested resource, and the library writes the words in its language's case: `payments.mark_refunded` is `payments.markRefunded` in JavaScript and stays `payments.mark_refunded` in Python. Operations marked `"browser"` belong to shipbill.js only.
- **An `Idempotency-Key` on every POST**, a new random one unless the caller gives one, so a retry never acts twice.
- **Retries:** after a network failure or a 500, 502, 503, or 504, for GET and POST only; after a 429, for any method, waiting `Retry-After` (a minute at most). Two retries at most, three tries in all, otherwise waiting 0.5 s, then 1 s, less up to a quarter at random.
- **Lists** that are one page when awaited and every item when iterated, following `starting_after` while `has_more`.
- **Errors** as one class per [error type](https://shipbill.io/docs/errors), each with `code`, `param`, and the request ID, and one more for a connection that failed.
- **Webhooks:** `webhooks.verify` on the raw body, reading `t=…,v1=…`, accepting any of several `v1` values, refusing a signature more than 300 seconds either side of now, and comparing in constant time; `webhooks.sign` for testing a receiver. It gives every answer in [api.shipbill.io/v1/webhook-signature-vectors.json](https://api.shipbill.io/v1/webhook-signature-vectors.json), the cases ShipBill's own signer writes.
- **A User-Agent** of `shipbill-<library>/<version>` and the runtime with its version, such as `shipbill-node/1.0.0 node/22.11.0`.
- **Checked against the API:** the specification's version is kept in the repository, a `contract` command fetches the specification and the signature cases again and fails on any difference, and a `live` test runs against test mode when a test key is set.
- **Released the same way:** `v*` tags on a protected `main`, published by trusted publishing with provenance, under the MIT licence, with `SECURITY.md`, `CHANGELOG.md`, and a README in the same order as the JavaScript one.

Last checked against the product on 17 October 2026.
