@bachs/js
v0.2.0
Published
The Bachs browser SDK. Load the Bachs overlay checkout with one import, fully typed.
Maintainers
Readme
@bachs/js
The Bachs browser SDK. Open the Bachs overlay checkout on your own site, fully typed, without sending your customer away from your page.
Bachs is payments and billing infrastructure for internet businesses.
Install
npm install @bachs/jsOr load the script directly (no build step):
<script src="https://checkout.bachs.io/bachs.js"></script>Usage
Create a checkout session on your server (with your secret key), then open the overlay in the browser with the returned token:
import { loadBachs } from "@bachs/js";
const bachs = await loadBachs();
bachs.Checkout.open({
token: "AbC123xyz", // from your server-side create-checkout call
onEvent: (event) => {
if (event.type === "checkout.completed") {
// Payment succeeded. Fulfil the order off your own webhook, not this event.
console.log("done", event.data);
}
},
});The card form and tokenization live in the Bachs-hosted checkout loaded inside the overlay iframe, so your page never touches card data.
API
loadBachs({ baseUrl? })— injectbachs.jsand resolve the typedBachsobject.Bachs.Checkout.open({ token | checkoutUrl, onEvent?, options? })— open the overlay.Bachs.Checkout.close()— close it.Bachs.Checkout.isOpen()— is the overlay open.
Events (onEvent)
checkout.opened, checkout.loaded, checkout.ready, checkout.completed,
checkout.failed, checkout.expired, checkout.closed, checkout.error.
Treat your webhooks as the source of truth for fulfilment. Client events can be missed if the customer closes the tab.
Docs
https://docs.bachs.io
License
MIT
