Web purchases use a web processor (Stripe, and other supported providers)
rather than an app store. When you call identify with the same
app_user_id, entitlements bought on the web unify with those bought on iOS
and Android — one customer, one set of entitlements everywhere.
Web SDK
Sell subscriptions on the web with Stripe checkout and entitlements that unify with mobile.
The CashSDK Web SDK brings the same offerings-and-entitlements API to the browser. Purchases run through a web processor — Stripe checkout by default — and the entitlements they grant are the same ones your mobile apps read.
Install#
npm install @cashsdk/web
Configure#
Call configure once when your app boots, using your publishable key.
import { CashSDK } from "@cashsdk/web";
CashSDK.configure({ apiKey: "pk_live_..." });
Publishable keys (pk_live_… / pk_test_…) are safe in browser code. Never
expose secret keys (csk_sk_…) — those stay on your server.
Fetch offerings#
An offering holds the packages you present on a pricing page, such as monthly
and annual.
const offering = await CashSDK.offerings();
const monthly = offering.monthly;
const annual = offering.annual;
Purchase with Stripe checkout#
Pass a package to purchase. The SDK opens Stripe checkout, and on return
CashSDK validates the payment and resolves with the customer's updated
entitlements.
const result = await CashSDK.purchase(offering.monthly);
if (result.entitlements.pro?.isActive) {
unlockPro();
}
Check entitlements#
Read entitlements from a purchase result — or from the current customer — to gate access.
if (result.entitlements.pro?.isActive) {
// Show premium content
} else {
// Show the pricing page
}
Identify the customer#
Link the SDK to your own user ID. This is what unifies web and mobile purchases: sign a customer in on the web with the same ID they use in your app, and their entitlements line up automatically.
CashSDK.identify("u_812");
Restore access#
Because web entitlements are keyed to the customer, signing in and calling
identify restores everything they own. You can also force a refresh:
const result = await CashSDK.restorePurchases();
if (result.entitlements.pro?.isActive) {
unlockPro();
}