Libraries
Three for JavaScript, open source under the MIT licence, at 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. To run one exact release, use its own address and integrity hash from the release notes:
<script src="https://js.shipbill.io/v1.0.0/shipbill.js"
integrity="sha384-…" crossorigin="anonymous"></script>@shipbill/js
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
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, typed; events are typed by their
type. - An
Idempotency-Keyon every POST, and retries after network failures, rate limits, and server errors. - Errors as classes by type (
ShipBillInvalidRequestError, …), each withcode,param, andrequestId. webhooks.verifyrefuses a signature older than five minutes;webhooks.signmakes 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 | 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.
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: a method for every operation and a type for every object, never written by hand.
- Named by the specification. Each operation's
x-shipbill-sdkgives 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_refundedispayments.markRefundedin JavaScript and stayspayments.mark_refundedin Python. Operations marked"browser"belong to shipbill.js only. - An
Idempotency-Keyon 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_afterwhilehas_more. - Errors as one class per error type, each with
code,param, and the request ID, and one more for a connection that failed. - Webhooks:
webhooks.verifyon the raw body, readingt=…,v1=…, accepting any of severalv1values, refusing a signature more than 300 seconds either side of now, and comparing in constant time;webhooks.signfor testing a receiver. It gives every answer in 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 asshipbill-node/1.0.0 node/22.11.0. - Checked against the API: the specification's version is kept in the repository, a
contractcommand fetches the specification and the signature cases again and fails on any difference, and alivetest runs against test mode when a test key is set. - Released the same way:
v*tags on a protectedmain, published by trusted publishing with provenance, under the MIT licence, withSECURITY.md,CHANGELOG.md, and a README in the same order as the JavaScript one.