# Superwall

Use Superwall as the financial event source for an app in [Integrations](https://submetry.com/app/integrations). Each app can have one active financial provider. Disconnect its RevenueCat webhook before activating Superwall; disconnecting Submetry’s integration does not change your RevenueCat account.

## Configure the webhook

1. Copy the app-specific webhook URL from the Superwall card.
2. In Superwall → Integrations → Webhooks, add that URL.
3. Copy its Signing Secret (`whsec_…`) into Submetry. Optionally bind the numeric Superwall Application ID to reject messages for another app.
4. Save. The card shows “En attente du webhook” until a valid signed delivery is actually persisted.
5. Trigger a real sandbox purchase and use “Vérifier la réception” to see the last event and receipt time.

Superwall does not send arbitrary test webhooks. Local StoreKit configuration purchases do not produce App Store Server Notifications; use the provider’s supported sandbox/TestFlight workflow. Select the matching sandbox environment in Submetry.

## Authenticity and duplication

Submetry verifies Svix HMAC-SHA256 over the exact raw request body and `svix-id` / `svix-timestamp` headers before parsing or ingestion. Delivery timestamps outside a five-minute window are rejected. Signature rotation lists are supported. The webhook secret is encrypted at rest and never returned to the browser. Superwall’s `data.id` is the event idempotency key, so retries and replayed deliveries cannot double-count a persisted event.

## Revenue and subscription states

Superwall initial purchases, trial starts/conversions, renewals, cancellations, expirations, billing issues, product changes, pauses and uncancellations are normalized to the shared subscription event contract. Negative prices are refunds. Gross amount uses Superwall’s actual USD `price`; actual net proceeds use `proceeds`, remaining absent if the provider omits them. No platform commission is estimated. The original provider payload is stored internally for reconciliation.

Use the same ID in your app’s Submetry SDK and Superwall. `originalAppUserId` can be absent for older integrations or purchases without an app user identity. Those events retain their financial values but cannot be attributed to a specific installation without a real matching identity.

## Endpoints

Authenticated app access: `GET`, `PATCH /v1/apps/APP_ID/integrations/superwall`. Configure with `{"signing_secret":"whsec_…","application_id":"123"}`; disconnect with `{"disconnect":true}`. Signed provider delivery: `POST /v1/integrations/superwall?app_id=APP_ID`.

Local tests cover signatures, stale-body rejection, encrypted configuration, provider conflicts, normalization and duplicate delivery. A live Superwall delivery requires your signing secret and a real provider event.

References: [Superwall webhooks](https://superwall.com/docs/integrations/webhooks), [Svix signature verification](https://docs.svix.com/receiving/verifying-payloads/how-manual).
