Capacitor SDK

Add in-app purchases and paywalls to your Capacitor or Ionic app with one TypeScript API for iOS and Android.

The Capacitor plugin is on the roadmap and is not published yet. cashsdk-capacitor does not resolve from any registry today, so the code on this page describes the intended API rather than a package you can install.

Shipping now? Use the iOS or Android SDK, which are available today. To be notified when this one lands, contact support@cashsdk.com.

The CashSDK Capacitor plugin gives Ionic and Capacitor apps one fully typed TypeScript API that runs on iOS (StoreKit 2) and Android (Play Billing). Fetch offerings, run purchases, and read entitlements with the same code on both platforms.

Install#

Install the plugin and sync it into your native projects:

bash
npm install cashsdk-capacitor
npx cap sync

cap sync copies the plugin's native iOS and Android code into your Xcode and Gradle projects. Re-run it after any dependency change.

Configure#

Call configure once when your app boots, for example in main.ts or your root component, using your publishable key.

ts
import { CashSDK } from "cashsdk-capacitor";

CashSDK.configure({ publishableKey: "csk_pk_…" });

Publishable keys (csk_pk_… / csk_pk_…) are safe to ship. Never expose secret keys (csk_sk_…). Those stay on your server.

Fetch offerings#

An offering holds the packages you present on a paywall, such as monthly and annual.

ts
const offering = await CashSDK.offerings();

const monthly = offering.monthly;
const annual = offering.annual;

Purchase#

Pass a package to purchase. CashSDK drives the native store flow, validates the receipt server-side, and resolves with the customer's updated entitlements.

ts
const result = await CashSDK.purchase(offering.monthly);

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

Use it in a component#

Fetch the offering on mount, present its packages, and unlock on success. This example uses Ionic React, but the same calls work in Angular or Vue.

tsx
import { useEffect, useState } from "react";
import { IonButton, IonSpinner } from "@ionic/react";
import { CashSDK, type Offering } from "cashsdk-capacitor";

export function Paywall({ onUnlock }: { onUnlock: () => void }) {
  const [offering, setOffering] = useState<Offering>();

  useEffect(() => {
    CashSDK.offerings().then(setOffering);
  }, []);

  async function buy() {
    if (!offering) return;
    const result = await CashSDK.purchase(offering.monthly);
    if (result.entitlements.pro?.isActive) onUnlock();
  }

  if (!offering) return <IonSpinner />;

  return (
    <IonButton onClick={buy}>
      Unlock Pro for {offering.monthly.localizedPrice}
    </IonButton>
  );
}

Check entitlements#

Read entitlements from any purchase or restore result to gate features.

ts
if (result.entitlements.pro?.isActive) {
  // Show premium content
} else {
  // Show the paywall
}

Restore purchases#

Let customers recover access on a new device or after a reinstall.

ts
const result = await CashSDK.restorePurchases();

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

Identify the customer#

Link the SDK to your own user ID so entitlements follow the customer across devices and platforms. Call identify after sign-in.

ts
CashSDK.identify("u_812");

Next steps#