Start free
Docs › SDKs

Web SDK

Sell subscriptions on your website or web app with Stripe, and unlock the same entitlements in your iOS and Android apps.

Before you start, set up Stripe web checkout, add a Web app to your project and create its SDK key (web_…) in Project → Apps. Never use a secret key (sk_…) in a website.

Install

<script src="https://pay.appwind.ai/static/sdk/appwind-pay.js"></script>

Or download it for your bundler: import { Purchases } from "./appwind-pay.js". It has no dependencies.

Configure

const { Purchases } = window.AppwindPay;
const purchases = Purchases.configure({ apiKey: "web_…", appUserId: currentUser?.id });

Without appUserId the browser gets an anonymous ID. Call purchases.changeUser(id) after sign-in to move it to your user.

Check access

if (await purchases.isEntitledTo("pro")) showProContent();

const info = await purchases.getCustomerInfo();
info.entitlements.active.pro?.expirationDate;

Sell

const { current } = await purchases.getOfferings();
for (const pkg of current.availablePackages) {
  const p = pkg.webBillingProduct?.currentPrice;   // { amount, currency, formattedPrice, period, freeTrialDays }
  addButton(`${pkg.identifier} — ${p?.formattedPrice}`, () => purchases.purchase({ rcPackage: pkg }));
}

purchase() opens Stripe Checkout. When the buyer comes back, call this on page load:

const info = await purchases.handleCheckoutReturn({ entitlement: "pro" });   // waits until the purchase shows up
if (info?.entitlements.active.pro) showThanks();

Other calls

Call What it does
purchases.manageSubscription() Opens Stripe's customer portal
purchases.setAttributes({ $email: "…" }) Customer attributes
purchases.logOut() A new anonymous user in this browser
purchases.addCustomerInfoUpdateListener(fn) Called when access changes
purchases.track("paywall_impression", {...}) Paywall analytics

Calls retry on network errors and switch to fallbackServers if you pass them.