Server & Mobile · iOS & Android

Expo, React Native & Swift (Hosted Return Sheet)

Open a hosted Stripe Checkout sheet (/p/[publicKey]) via expo-web-browser or ASWebAuthenticationSession for US App Store external web checkouts, PWAs, CLI/bot links, and unified Web + Mobile credit balances.

App Store Storefront Compliance (US vs. International)

External web-checkout links to Stripe (0% Apple fee) are permitted on the US iOS App Store (Storefront === 'USA'). Apple still enforces Guideline 3.1.1 on non-US storefronts based on the user's App Store account country (not IP address) — so if you distribute globally, check the native Storefront inside your app before showing the external sheet, and route non-US storefronts to StoreKit / RevenueCat (calling credits.grantCredits() from your backend IAP webhook to credit the same wallet).

Live Hosted Sheet Preview

Every project automatically hosts a mobile-optimized Stripe Checkout (Card, Apple Pay & Link) sheet at /p/[publicKey]:

1. Expo Storefront-Aware Client Trigger

app/api/credits/mobile-sheet/route.ts (Your Backend)
import { NextRequest, NextResponse } from 'next/server';
import { CreditKitClient } from '@/lib/creditkit';

const credits = new CreditKitClient({
  apiKey: process.env.CREDITKIT_SECRET_KEY!, // sk_test_... or sk_live_...
  publicKey: process.env.NEXT_PUBLIC_CREDITKIT_KEY!, // pk_test_... or pk_live_...
});

async function getMobileSession(_req: NextRequest): Promise<{ userId: string } | null> {
  return { userId: 'usr_mobile_123' };
}

export async function POST(req: NextRequest) {
  const session = await getMobileSession(req);
  if (!session?.userId) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });

  const sheetUrl = credits.getMobileTopUpUrl('myapp://credits-unlocked', {
    userId: session.userId,
  });
  return NextResponse.json({ sheetUrl });
}
lib/openMobileCreditSheet.ts (Expo / React Native)
import * as WebBrowser from 'expo-web-browser';

export async function triggerCreditTopUp(
  authToken: string, // Your app's signed-in user JWT
  storefrontCountry: string, // From StoreKit Storefront.current.countryCode
  presentNativeStoreKitPaywall: () => Promise<void>
) {
  // 1. US App Store storefront -> fetch signed sheet URL & open Stripe sheet (0% Apple fee)
  if (storefrontCountry === 'USA') {
    const returnUrl = 'myapp://credits-unlocked';
    const { sheetUrl } = await fetch('https://api.yourapp.com/api/credits/mobile-sheet', {
      method: 'POST',
      headers: { Authorization: `Bearer ${authToken}` },
    }).then((r) => r.json());

    const result = await WebBrowser.openAuthSessionAsync(sheetUrl, returnUrl);
    if (result.type === 'success' && result.url) {
      // Deep link returns ?credits_added=500&balance=550
      console.log('Unlocked mobile credits via Stripe:', result.url);
    }
    return;
  }

    // 2. Non-US App Store storefronts -> fall back to native StoreKit / RevenueCat IAP
  await presentNativeStoreKitPaywall();
}
CreditSheetCoordinator.swift (Native Swift / SwiftUI)
import AuthenticationServices

func openCreditSheet(sheetURL: URL, context: ASWebAuthenticationPresentationContextProviding) {
  let session = ASWebAuthenticationSession(
    url: sheetURL,
    callbackURLScheme: "myapp"
  ) { callbackURL, error in
    guard error == nil, let callbackURL else { return }
    // callbackURL: myapp://credits-unlocked?credits_added=500&balance=550
    print("Unlocked mobile credits:", callbackURL.absoluteString)
  }
  session.prefersEphemeralWebBrowserSession = false
  session.presentationContextProvider = context
  session.start()
}

2. Syncing StoreKit / Google Play IAP Webhooks on Your Server

app/api/webhooks/revenuecat/route.ts
import { CreditKitClient } from '@/lib/creditkit';

const credits = new CreditKitClient({
  apiKey: process.env.CREDITKIT_SECRET_KEY!, // sk_live_... (or sk_test_... in sandbox)
});

// Inside your verified StoreKit / RevenueCat webhook handler:
await credits.grantCredits({
  userId: event.app_user_id,
  amount: 100,
  reason: 'apple_iap_100_pack',
});