Skip to main content

Khaime SDK

@khaime/sdk is an embeddable JavaScript library of Web Components that handle the full product-purchase flow — from showing a product to collecting payment — without sending the customer away from your page.

Three ways to take a payment

Pay Button

One-click checkout for a single product. Drop <khaime-pay-button> in and you’re done.

Storefront + Cart

Full catalog with multi-item cart and checkout — <khaime-storefront> + <khaime-cart-page>.

Programmatic

Create a checkout session on your server, render the payment UI on the client with sdk.createPayment().

Install

Load the script tag on every page that uses the SDK. It works the same in plain HTML, WordPress, and React or Vite apps (Lovable, Bolt, v0): put it in index.html and use window.KhaimeSDK.
In development, use https://api.khaimedev.com/sdk/v2/khaime.js. The SDK auto-detects the API base from the script URL.
The SDK is not published on npm. npm install @khaime/sdk fails: use the script tag.

Which key goes where

Khaime has two kinds of key. Using the wrong one in the wrong place is the most serious mistake you can make. Built with Lovable, Bolt or v0? In your Khaime dashboard open Your website and tap Copy for Lovable. It copies one chat prompt with your store ID and live storefront key already in it, and switches selling from your website on. See Build your store with Lovable. Your storefront key works from Lovable, Bolt and v0 preview addresses (*.lovable.app, *.lovableproject.com, *.bolt.host, *.webcontainer-api.io, *.vusercontent.net) and from every website you confirmed on Your website. When your shop is opened from a new address, Your website asks whether it is yours; tap Yes and it works there too. Subdomains are included, so myshop.com also allows www.myshop.com. Testing your website: there is no separate test key to put in a website. The pub_live_ key is the safe one for browser code. Test with a cheap real order, then refund it from Orders in Khaime. A pk_sandbox_ key is a private Partner API key like pk_live_: it stays on your server even while testing.
Browser code is public: anyone can open it and copy what is inside. A pk_ key in a website, in a NEXT_PUBLIC_ or VITE_ variable, or in a Lovable project file gives away your orders, customers and payouts.

Initialize

KhaimeSDK.init is idempotent — calling it a second time returns the same singleton instance. Call it before any Khaime element appears on the page; the elements use the key you give it here. The SDK registers four custom elements on init: <khaime-storefront>, <khaime-product-card>, <khaime-pay-button>, and <khaime-pricing>.

Currency

Shoppers switch currency only when the store sells in several currencies. A store in one currency shows that currency everywhere, with no currency picker: checkout refuses any other.
  • getProducts and getProduct price in the shopper’s chosen currency, else the one detected from their location (stores selling in several currencies), else the store’s own currency.
  • The cart always follows the currency the products came back in, so its prices and its label agree.
  • setCurrency throws for a store in one currency, or for a code not in options.
  • formatted_price is ready to show (for example KES 971.03, ₦12,500.00). Never format or convert prices yourself.

Options (variants)

Each product has variants: { id, name, price, formatted_price, sold_out, stock, variation_id, sub_variant_id }. price and formatted_price are the option’s full price (sale or list price plus the option’s add-ons) in the shopper’s currency. Pass the picked variant to sdk.cart().addItem(product, quantity, variant). Do not use the raw product_variation add-on amounts as prices.

What each flow covers

All three flows share the same backend (/api/v1/sdk/checkout/*), emit the same payment events, and support both embedded and redirect payment flows — the SDK routes to the right gateway based on the transaction currency.

Next steps