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#

bash
npm install @cashsdk/web

Configure#

Call configure once when your app boots, using your publishable key.

ts
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.

ts
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.

ts
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.

ts
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.

ts
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:

ts
const result = await CashSDK.restorePurchases();

if (result.entitlements.pro?.isActive) {
  unlockPro();
}

Next steps#