Expo? The SDK includes a config plugin. It works in any development or
production build (npx expo run:ios / eas build). It is not available in
Expo Go, since in-app purchases require native modules.
React Native SDK
One TypeScript API for in-app purchases and paywalls across iOS and Android.
The CashSDK React Native SDK gives you a single, fully typed API that runs on both iOS (StoreKit 2) and Android (Play Billing). Fetch offerings, run purchases, and read entitlements with the same code on every platform.
Install#
npm install @cashsdk/react-native
For a bare React Native project, install the native iOS pods:
cd ios && pod install
Configure#
Call configure once at the root of your app, before rendering any screen that
reads entitlements. Use your publishable key.
import { CashSDK } from "@cashsdk/react-native";
CashSDK.configure({ apiKey: "pk_live_..." });
export default function App() {
return <RootNavigator />;
}
Only publishable keys (pk_live_… / pk_test_…) belong in your app bundle.
Keep secret keys (csk_sk_…) on your backend.
Use it in a component#
Fetch offerings on mount, present them, and complete a purchase. The result carries the customer's updated entitlements.
import { useEffect, useState } from "react";
import { View, Text, Pressable } from "react-native";
import { CashSDK, type Offering } from "@cashsdk/react-native";
export function Paywall({ onUnlock }: { onUnlock: () => void }) {
const [offering, setOffering] = useState<Offering>();
const [busy, setBusy] = useState(false);
useEffect(() => {
CashSDK.offerings().then(setOffering);
}, []);
async function buy() {
if (!offering) return;
setBusy(true);
try {
const result = await CashSDK.purchase(offering.monthly);
if (result.entitlements.pro?.isActive) onUnlock();
} finally {
setBusy(false);
}
}
return (
<View>
<Text>Unlock Pro</Text>
<Pressable disabled={busy} onPress={buy}>
<Text>{offering?.monthly.localizedPrice ?? "…"}</Text>
</Pressable>
<Pressable onPress={() => CashSDK.restorePurchases()}>
<Text>Restore purchases</Text>
</Pressable>
</View>
);
}
Check entitlements#
Read entitlements from any purchase or restore result to gate features.
if (result.entitlements.pro?.isActive) {
unlockPro();
}
Restore purchases#
Let customers recover access on a new device or after a reinstall.
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.
CashSDK.identify("u_812");