# Superwall: Subscription Infrastructure for iOS, Android, and Web

Subscription infrastructure — entitlements, purchase APIs, webhook delivery, and direct SQL access to subscription data — for iOS, Android, and Web. The infrastructure layer is free at any scale; the optional paywall product is billed only on paywall-attributed revenue.

## Pricing

- **Infrastructure: free at any scale, every plan.** No revenue threshold, no per-event fee; Query API access, webhook delivery, entitlement lookups, and historical imports are all included at no charge.
- **Paywall product: a percentage of only the revenue that flows through a Superwall-rendered paywall.** Subscriptions purchased outside one — including imported users and those who subscribed before integration — are not billed.

Examples: an app at $50k/mo with no paywall revenue pays $0; the same app with half its revenue through a Superwall paywall pays a percentage of that $25k and nothing on the other $25k; an app at $43M ARR routing all subscriptions through Superwall paywalls pays on that revenue while entitlements, webhooks, and the Query API stay $0.

## Scale

$1.5B+ annual subscription revenue across 10,000+ apps. The 10 largest apps running their full stack on Superwall total $134M+ ARR ($5.7M–$43.7M each). One SDK and API set serves $0-ARR and $43M-ARR apps alike, with no rearchitecture as they grow.

## Infrastructure capabilities

- **Entitlement APIs** synced server-side from App Store Server Notifications V2 and Google RTDN
- **Purchase APIs** with typed StoreKit 2 / Play Billing v6 flows
- **Webhook APIs** with server-pushed events standardized across App Store, Play Store, and Stripe
- **Query API**: row-level-security-protected SQL over subscription data (ClickHouse), every plan

Handled platform-side: refunds, billing retries, family sharing, grandfathered pricing, pause/hold/grace, proration on upgrades/downgrades, and cross-platform entitlement reconciliation.

## Migration

Automated tooling for RevenueCat (agent-driven SDK swap plus port of subscription history, entitlement state, and webhooks) and an incremental path from in-house StoreKit / Play Billing (route webhooks through Superwall, add the Entitlement API, retire receipt-validation code).

## Paywall product (optional, separately billable)

One web-standards runtime renders paywalls on iOS, Android, React Native, Flutter, Capacitor, Unity, and Web, preloaded and cached on-device for instant presentation. Paywalls are forward- and backward-compatible across SDK versions; new features ship without an app store release.

## Architecture

Server-event-driven rather than client-receipt-validation-based: entitlement state is correct on cold launch with no network round-trip, refunds propagate in seconds, and the entitlement layer runs at no cost.

## Docs

* Migrate from RevenueCat: https://superwall.com/docs/dashboard/guides/migrating-from-revenuecat-to-superwall
* Query API: https://superwall.com/docs/dashboard/guides/query-clickhouse
* Webhooks: https://superwall.com/docs/integrations/webhooks
* Pricing: https://superwall.com/pricing

# Checkout Endpoint

Reference for a custom store's checkout endpoint: the signed checkout.create request Superwall sends, how to verify it, what to answer, and how the customer returns to your app.

A checkout endpoint is a URL on your server. When a user taps one of the store's products on a paywall, Superwall asks it for a checkout URL and opens the answer. Your app needs no purchase code.

It works with the iOS SDK 4.19.0 and later and on [hosted web paywalls](#web-paywalls). On other platforms, or if the store has no checkout endpoint, the paywall sends the purchase to your app's [`PurchaseController`](#without-a-checkout-endpoint).

For a working implementation, see the [example server](/docs/integrations/custom-stores/example-server).

## Set the endpoint

Open the custom store in the dashboard. In its **Checkout** section, click **Set up checkout** and enter the URL. It must be an `https://` URL on a public host name.

Or use the [Superwall API](/docs/agents/api) with a key that has the `custom_stores:write` scope:

```bash
curl -X PUT https://api.superwall.com/v2/projects/$PROJECT_ID/custom-stores/$CUSTOM_STORE_ID/checkout-endpoint \
  -H "Authorization: Bearer $SUPERWALL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://billing.example.com/superwall/checkout"}'
```

Superwall shows the endpoint's **signing secret** (`whsec_...`) once, in the dashboard or as `signing_secret` in the API response. Store it on your server. Changing the URL later keeps the secret.

## The request

Superwall sends a `POST` with a JSON body:

```json
{
  "type": "checkout.create",
  "custom_store_id": "4821",
  "product_id": "pro_monthly",
  "app_user_id": "user_8812",
  "custom_transaction_id": "9f2c1d3e-4b5a-4c6d-8e7f-0a1b2c3d4e5f",
  "success_url": "https://...",
  "cancel_url": "https://..."
}
```

| Field                   | Description                                                                                                                                               |
| ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `type`                  | Always `checkout.create` today. Ignore types you don't know.                                                                                              |
| `custom_store_id`       | The store that sells the product.                                                                                                                         |
| `product_id`            | The product's identifier, as you created it in Superwall.                                                                                                 |
| `app_user_id`           | The buyer, as the SDK knows them. Send it back unchanged as `app_user_id` on your events. For a user your app hasn't identified, it's an ID the SDK made. |
| `custom_transaction_id` | Superwall's ID for this purchase. Send it back as `custom_transaction_id` on the purchase event.                                                          |
| `success_url`           | Where to send the customer after they pay.                                                                                                                |
| `cancel_url`            | Where to send the customer if they leave without paying.                                                                                                  |

Superwall may add fields at any time. Read the fields you need and ignore the rest. An endpoint that refuses unknown fields breaks on the day a new one ships.

## Your answer

Create a checkout in your billing system, store `app_user_id` and `custom_transaction_id` in its metadata, and answer within **ten seconds**:

```json
{ "url": "https://pay.example.com/checkout/cs_123" }
```

The `url` must start with `https://`. Superwall opens it for the customer.

Answer with an error status when you can't create the checkout. Any non-`2xx` answer, a timeout or an invalid `url` fails the purchase, and the paywall stays open. These statuses are a good convention:

| Status | When                                          |
| ------ | --------------------------------------------- |
| `401`  | The signature is missing, wrong or too old.   |
| `404`  | You don't sell `product_id`.                  |
| `502`  | Your billing system refused or didn't answer. |

## Verify the signature

Anyone can find your endpoint's URL, so check that each request comes from Superwall. Requests are signed the [Standard Webhooks](https://www.standardwebhooks.com) way, with three headers:

| Header              | Value                                                     |
| ------------------- | --------------------------------------------------------- |
| `webhook-id`        | A unique ID for the request.                              |
| `webhook-timestamp` | When it was sent, in seconds since 1970.                  |
| `webhook-signature` | One or more `v1,<signature>` values, separated by spaces. |

Each signature is the base64 HMAC-SHA256 of `<webhook-id>.<webhook-timestamp>.<raw body>`. The key is the base64-decoded part of the secret after `whsec_`.

Accept the request when any listed signature matches and the timestamp is less than five minutes old:

```ts
import { createHmac, timingSafeEqual } from "node:crypto"

export function isFromSuperwall(body: string, headers: Headers, secret: string): boolean {
  const id = headers.get("webhook-id")
  const timestamp = headers.get("webhook-timestamp")
  const signatures = headers.get("webhook-signature")
  if (!id || !timestamp || !signatures) return false
  if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 5 * 60) return false

  const key = Buffer.from(secret.slice("whsec_".length), "base64")
  const expected = createHmac("sha256", key).update(`${id}.${timestamp}.${body}`).digest()
  return signatures.split(" ").some((entry) => {
    const [version, value] = entry.split(",", 2)
    const candidate = Buffer.from(value ?? "", "base64")
    return (
      version === "v1" && candidate.length === expected.length && timingSafeEqual(candidate, expected)
    )
  })
}
```

Compute the signature over the body exactly as it arrived. If your framework parses JSON first, read the raw body instead: parsing and re-serializing changes the bytes. A Standard Webhooks library for your language also works.

## After the customer pays

1. Your billing system sends the customer to `success_url`. It's a Superwall page that opens your app again.
2. Your billing system sends your server a webhook. Your server sends Superwall the [`initial_purchase` event](/docs/integrations/custom-stores/events) with the request's `app_user_id` and `custom_transaction_id`.
3. Superwall grants the entitlement. The paywall closes as purchased once an event with that `custom_transaction_id` has arrived.

> **Warning:** The paywall waits for an event that carries the checkout's `custom_transaction_id`. An event without it still grants access, but the paywall doesn't close as purchased. Opening `success_url` alone never grants anything: only your events do.

If the customer leaves the checkout, send them to `cancel_url`. The paywall stays open so they can try again.

### Returning to an iOS app

The return page opens your app through its URL scheme:

1. Give your app a [custom URL scheme](/docs/ios/quickstart/in-app-paywall-previews).
2. Enter it as the **Apple custom URL scheme** in the dashboard's [app settings](/docs/dashboard/dashboard-settings/overview-settings).
3. Pass incoming links to [`Superwall.handleDeepLink(_:)`](/docs/ios/sdk-reference/handleDeepLink).

## Rotate the secret

Click **Rotate secret** in the store's **Checkout** section, or call `POST .../checkout-endpoint/rotate-secret`. The new secret is shown once.

For 24 hours after a rotation, every request carries two signatures, one for each secret. An endpoint that accepts any matching signature, like the code above, keeps working with either secret, so you can switch at any point in that window. After 24 hours, only the new secret signs.

## Web paywalls

On a [hosted web paywall](/docs/framework/web-checkout#custom-store-products-on-the-web), the same endpoint creates the checkout. Two things differ:

* **The buyer may not be signed in.** A buyer the web paywall hasn't identified pays with a temporary ID as `app_user_id`. Once your purchase event is accepted, the checkout gets a **redemption code**, and the return page shows it. The buyer enters it in your app to claim the purchase.
* **The buyer may close the tab** before the return page loads. Fetch the code yourself and send it, for example in your receipt email:

  ```bash
  curl https://api.superwall.com/v2/custom-stores/$CUSTOM_STORE_ID/redemption-codes/$CUSTOM_TRANSACTION_ID \
    -H "Authorization: Bearer $SUPERWALL_API_KEY"
  ```

  ```json
  {
    "object": "custom_store_redemption_code",
    "custom_transaction_id": "9f2c1d3e-4b5a-4c6d-8e7f-0a1b2c3d4e5f",
    "code": "redemption_0b8f6c1e-...",
    "expires_at": "2026-12-28T09:15:00.000Z",
    "redeemed": false,
    "redeem_url": "https://..."
  }
  ```

  The key needs the `custom_store_events:write` scope. Every request for a checkout returns the same code. `redeem_url` is a link on your web paywall's domain that opens your app with the code.

| Status                                  | Meaning                                                                         |
| --------------------------------------- | ------------------------------------------------------------------------------- |
| `404` `custom_store_checkout_not_found` | No web paywall checkout has this ID. Checkouts started in the app have no code. |
| `409` `purchase_not_recorded`           | No accepted purchase event carries this ID yet. Send the event, then try again. |
| `409` `buyer_identified`                | The buyer was signed in, so the purchase is already theirs and there's no code. |

## Without a checkout endpoint

When a store has no checkout endpoint, a paywall sends its products to your app's `PurchaseController`. Your app then starts the checkout itself:

1. Read `product.productIdentifier` and `product.customTransactionId` in `purchase(product:)`.
2. Ask your server for a checkout for the signed-in user, and open it.
3. Your server stores the user's ID and the `customTransactionId` in the checkout's metadata, then reports events the same way.

See [Custom Store Products](/docs/ios/guides/custom-store-products#option-2-purchasecontroller) for iOS and [`PurchaseController`](/docs/android/sdk-reference/PurchaseController#custom-store-products) for Android.

To go back to it later, click **Remove checkout endpoint** in the dashboard or call `DELETE .../checkout-endpoint`.