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 inindex.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.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.
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.
getProductsandgetProductprice 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.
setCurrencythrows for a store in one currency, or for a code not inoptions.formatted_priceis ready to show (for exampleKES 971.03,₦12,500.00). Never format or convert prices yourself.
Options (variants)
Each product hasvariants: { 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
- Start with the Pay Button quickstart — shortest path to a working payment.
- Review the events reference to hook into product clicks, cart updates, and payment outcomes.
- Always verify payments server-side via webhooks before fulfilling an order.
