Skip to content

Web script

kasskeep-web.js is a zero-dependency ES module. It ships next to the SDK tarball (dist-release/kasskeep-web.js with type definitions). Copy it into your web project. It also sets globalThis.KasskeepWeb.

It works in three situations:

Mode When What happens
native Inside a shell that injected KASSKEEP_WEBVIEW_INJECTED_JS Calls go over the WebView bridge to the native SDK
test_store A plain browser after configureTestStore Calls go to the test store with the public key
unavailable A plain browser isAvailable() is false; use web checkout instead

KasskeepWeb.mode() returns the current mode.

import KasskeepWeb from "./vendor/kasskeep-web.js";
if (KasskeepWeb.isAvailable()) {
await KasskeepWeb.setAppUserId(userUuid);
const [coins] = await KasskeepWeb.getProducts(["com.example.game.coins_300"], "inapp");
const result = await KasskeepWeb.purchase({ productId: coins.productId, type: "inapp", consumable: true });
if (result.status === "completed") refreshWalletFromServer();
}
Function Notes
isAvailable() True inside the native shell, or once the test store is configured
getProducts(ids, type, opts?), getCustomer(opts?), setAppUserId(id, opts?) Default timeout 20 seconds
purchase(request, opts?), restore(opts?) Default timeout 300 seconds, because the store sheet waits for the user
configure({ timeoutMs?, purchaseTimeoutMs? }) Changes the defaults; opts.timeoutMs overrides per call
configureTestStore({ baseUrl, apiKey, appUserId, prices?, outcome?, fetch? } | null) Direct test store access from a browser
configureCheckout({ baseUrl, apiKey, appUserId, fetch? } | null) Direct web checkout access
checkout({ channel, productId, successUrl, cancelUrl, quantity?, redirect? }) Creates a Checkout Session and redirects
ads.showRewarded({ adUnit, customData? }) Over the bridge in the shell
configureTestAds({ baseUrl, apiKey, appUserId, outcome?, network? }) Test ads from a plain browser

Errors reject with KasskeepWebError. Its code is the native error code or one of unavailable, timeout, method_not_allowed, unsupported_version, bridge_error. A timeout does not cancel a native purchase, so confirm outcomes from your server, not from the page.

KasskeepWeb.configureCheckout({ baseUrl: "https://api.kasskeep.com", apiKey: "pk_...", appUserId: user.id });
await KasskeepWeb.checkout({
channel: "stripe",
productId: "pro_monthly",
successUrl: "https://play.example.com/shop/done?session={CHECKOUT_SESSION_ID}",
cancelUrl: "https://play.example.com/shop",
});

checkout calls POST /v1/checkout and then location.assign(url). With redirect: false it resolves { url, sessionId } instead. It never goes through the native bridge.

The browser calls Kasskeep directly, so the app needs its page origin in cors_origins. See CORS.