Custom Stores

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. On other platforms, or if the store has no checkout endpoint, the paywall sends the purchase to your app's PurchaseController.

For a working implementation, see the 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 with a key that has the custom_stores:write scope:

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:

{
  "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://..."
}
FieldDescription
typeAlways checkout.create today. Ignore types you don't know.
custom_store_idThe store that sells the product.
product_idThe product's identifier, as you created it in Superwall.
app_user_idThe 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_idSuperwall's ID for this purchase. Send it back as custom_transaction_id on the purchase event.
success_urlWhere to send the customer after they pay.
cancel_urlWhere 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:

{ "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:

StatusWhen
401The signature is missing, wrong or too old.
404You don't sell product_id.
502Your 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 way, with three headers:

HeaderValue
webhook-idA unique ID for the request.
webhook-timestampWhen it was sent, in seconds since 1970.
webhook-signatureOne 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:

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 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.

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.
  2. Enter it as the Apple custom URL scheme in the dashboard's app settings.
  3. Pass incoming links to Superwall.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, 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:

    curl https://api.superwall.com/v2/custom-stores/$CUSTOM_STORE_ID/redemption-codes/$CUSTOM_TRANSACTION_ID \
      -H "Authorization: Bearer $SUPERWALL_API_KEY"
    {
      "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.

StatusMeaning
404 custom_store_checkout_not_foundNo web paywall checkout has this ID. Checkouts started in the app have no code.
409 purchase_not_recordedNo accepted purchase event carries this ID yet. Send the event, then try again.
409 buyer_identifiedThe 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 for iOS and PurchaseController for Android.

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

How is this guide?

On this page