# Refunds, transfers, and which webhook actually updates access

This article was first published on [AppContinuity](https://appcontinuity.com/articles/refunds-transfers-and-which-webhook-updates-access/).

Official RevenueCat docs already list every webhook event type. This piece is about the exact stack — React + Capacitor, Supabase Auth, Stripe on the web, RevenueCat on iPhone and Android — and the narrow question founders hit after the first successful purchase: **which event should change “is this person paid?” in your database**, especially when money moves backward (a refund) or sideways (a transfer or alias).

It follows [why a Stripe subscriber hits a Capacitor paywall](https://appcontinuity.com/articles/why-a-stripe-subscriber-hits-a-paywall/) and [mapping Supabase Auth user IDs to RevenueCat](https://appcontinuity.com/articles/mapping-supabase-auth-to-revenuecat/). Those cover attaching the web subscription and identifying the signed-in user. This one is the webhook file you write after that.

## The failure mode

You handled `INITIAL_PURCHASE` and maybe `RENEWAL`. Production looks fine for a week. Then one of these shows up:

- A customer is refunded through Apple, Google, or Stripe. Your admin UI still says premium.

- User A buys on a phone. User B logs into the same phone and suddenly has premium. Or A loses it without a cancellation email.

- Someone buys while anonymous, then creates a Supabase account. Your webhook log is quiet. Support asks why the new user id has no row.

- A Stripe subscription is canceled in the Customer Portal. RevenueCat still shows an active entitlement until the period ends — or, if the Stripe attach is missing, it never updates at all.

Each case is a different event (or a non-event). Treating “any webhook → set paid=true” is how access drifts.

> A printable [Capacitor + RevenueCat + Stripe entitlement checklist](https://appcontinuity.com/checklist/) covers the cases in this article, as a free PDF.

## One entitlement, three writers

On this stack, three systems can honestly disagree for a few seconds:

1. **Store / Stripe** — Apple, Google, or Stripe’s own subscription state.

2. **RevenueCat** — `CustomerInfo` / `GET /subscribers` for an App User ID.

3. **Your Supabase row** — whatever you wrote last from a webhook or a client flag.

AppContinuity’s rule: **(3) may only change because of (2), and (2) is refreshed after the webhook, not guessed from the event name alone.** RevenueCat’s own webhook guide says the same thing: call `GET /subscribers` after receiving any webhook, because event payloads are not a uniform snapshot. The Capacitor app reads entitlements for UX; the API trusts the server row (or a server-side RevenueCat check), never a client boolean.

## Alias vs transfer (why your TRANSFER handler never runs)

Two different identity moves get confused constantly.

**Alias (anonymous → `logIn(customId)`).** Purchase on `$RCAnonymousID:…`, then `Purchases.logIn({ appUserID: supabaseUser.id })`. RevenueCat merges those ids onto **one customer**. You will **not** get a `TRANSFER` webhook. Both ids appear as aliases on the same subscriber. New projects also will not get the legacy `SUBSCRIBER_ALIAS` event — that type is deprecated. If your backend only inserts rows keyed by the custom id when it sees `INITIAL_PURCHASE`, the anonymous purchase already fired that event under the anonymous id. After `logIn`, sync from the app to your API and run `GET /subscribers`, and resolve aliases on every later webhook.

**Transfer (receipt moves between customers).** Typical case: restore (or certain login paths) while project restore behavior is “Transfer to new App User ID.” RevenueCat sends `TRANSFER` with `transferred_from` and `transferred_to`. Current docs are explicit: the webhook is delivered only for the destination user, the event body is identical, and it still lists both sides. There is **no** separate `EXPIRATION` for the loser and `RENEWAL` for the winner in that moment. Handle `TRANSFER` itself, then re-fetch subscriber state for every id in `transferred_from` and `transferred_to`.

If you require Supabase login before purchase and you do not want shared-phone entitlement theft, set restore behavior to **Keep with original App User ID** and teach support / `RECEIPT_ALREADY_IN_USE`. That choice belongs next to your Auth wiring, not only in a webhook file.

## Which webhook should flip access

Use this as a working map for an entitlement-gated Capacitor app. Always confirm against current [RevenueCat event types and fields](https://www.revenuecat.com/docs/integrations/webhooks/event-types-and-fields) — names are stable, but fields evolve. There is **no `REFUND` event type** in current webhooks. Refunds arrive as `CANCELLATION`.

*Which RevenueCat webhook should change the Supabase entitlement row*

| Situation | Event(s) you must handle | What to write in Supabase |
| --- | --- | --- |
| First store or RevenueCat-tracked purchase | `INITIAL_PURCHASE` (sometimes `NON_RENEWING_PURCHASE` for lifetime or promo) | Mark entitled **after** `GET /subscribers` shows the entitlement active for that app user id |
| Subscription continued | `RENEWAL` | Refresh expiration / still entitled |
| User canceled but the period is not over | `CANCELLATION` with `cancel_reason` such as `UNSUBSCRIBE` | Store “won’t renew”; do **not** revoke early. Access stays until `EXPIRATION` |
| Refund or revoke | `CANCELLATION`, typically with `cancel_reason: CUSTOMER_SUPPORT`. `price` may be negative. Fires only when the **latest** subscription period is refunded. App Store only: `REFUND_REVERSED` if a refund is later reversed | **Re-fetch, then write what RevenueCat says.** A refund does not always turn auto-renew off, so do not revoke from the event name alone |
| Period ended, or billing failed and any grace period ended | `EXPIRATION` | Revoke the entitlement |
| Charge failed | `BILLING_ISSUE` (often paired with `CANCELLATION` / `cancel_reason=BILLING_ERROR`) | Do not treat this as expired. Keep access through a grace period if you have one; revoke on `EXPIRATION` |
| Pause (Google Play) | `SUBSCRIPTION_PAUSED` means the pause is **scheduled** for the end of the current period | Do **not** revoke on this event. Revoke only on `EXPIRATION` with `expiration_reason: SUBSCRIPTION_PAUSED` |
| Product change | `PRODUCT_CHANGE` | Re-read entitlements. A period-end downgrade is not in effect immediately |
| Receipt moved across app user ids | `TRANSFER` (one delivery, for the destination user, with both id lists in the body) | Revoke `transferred_from`, grant `transferred_to` after `GET /subscribers` on both |
| Anonymous aliased into a Supabase user | No `TRANSFER` (and no `SUBSCRIBER_ALIAS` on new projects) | Sync on `logIn`, and use aliases on any later webhook |

**Stripe-specific:** attaching a web subscription is not a StoreKit restore. Your server sends the Stripe subscription to RevenueCat (`POST /receipts` / track external purchases) with the **same** `app_user_id` you use in `Purchases.logIn`. Stripe’s own webhooks update *your* billing tables; **RevenueCat** still needs the attach (and then RevenueCat webhooks / subscriber reads) before the Capacitor app should unlock. A Customer Portal cancel should show up as `CANCELLATION` (usually `UNSUBSCRIBE`) and, at period end, `EXPIRATION`. A Stripe or RevenueCat Billing refund is the `CUSTOMER_SUPPORT` cancellation path. If a portal cancel never appears in RevenueCat, you have an integration gap, not a Capacitor bug.

## Recommended handler shape

Pseudo-flow that survives retries:

```
on webhook(event):
  verify authorization header (and HMAC signature if enabled)
  idempotency_key = event.id   # retries reuse the same id
  ids = affected_app_user_ids(event)  # transferred_from/to and aliases when present
  for id in ids:
    subscriber = GET /v1/subscribers/{id}
    entitled = entitlement_active(subscriber, "your_entitlement_id")
    upsert supabase entitlements for supabase_user = map_rc_id_to_supabase(id, subscriber.aliases)
         set entitled, source_event=event.type, checked_at=now()
  return 200 quickly
```

Notes that prevent support tickets:

- **Idempotency:** RevenueCat retries, and retries reuse the same `event.id` and `event_timestamp_ms`. Processing `INITIAL_PURCHASE` twice must not double-grant side effects (emails, credits).

- **Re-fetch:** Event payloads differ by type. `GET /subscribers` makes every handler the same shape ([webhooks overview](https://www.revenuecat.com/docs/integrations/webhooks)).

- **Alias map:** Store every alias you see so anonymous ids and custom ids resolve to one Supabase user. Search both `original_app_user_id` and `aliases`.

- **Client cache:** Capacitor `CustomerInfo` can look premium offline for a grace period; `logOut` clears it. UX can use cache; your API should not.

## Refunds without theater

A refund is not “set a flag from the App Store email.” Sequence that works:

1. The store or Stripe reports a refund. RevenueCat records it as `CANCELLATION` (typically `CUSTOMER_SUPPORT`) when it is the latest period — not as a `REFUND` event, and not for refunds of earlier periods.

2. Your handler re-fetches subscriber state. If the entitlement is gone, clear it for the mapped Supabase user. If auto-renew is still on, keep what RevenueCat reports.

3. The next app launch (or customer-info listener) shows the paywall.

If you only listen to Stripe `charge.refunded` and forget RevenueCat, the iPhone build can stay unlocked until a stale cache dies. If you only listen to RevenueCat and never reconcile Stripe seats, your web app drifts the other way. Same entitlement id on both paths.

## Sandbox cases that prove the webhook file

Before you trust production (a mirror of the Integration acceptance suite):

1. Purchase → row entitled.

2. Refund (sandbox) → row revoked without reinstalling, once RevenueCat shows the entitlement gone.

3. Anonymous purchase → `logIn(supabase id)` → **no** `TRANSFER`, but the server row exists for the Supabase user after your sync.

4. User A entitled → `logOut` → User B login → B not entitled (with keep-with-original, or after you handle `TRANSFER` correctly).

5. Stripe attach for user A → Capacitor for A unlocks; B does not.

6. Replay the same webhook delivery twice → one idempotent write.

A printable list of these cases: [the free entitlement checklist](https://appcontinuity.com/checklist/).

## Short checklist

- Decide restore behavior before you write webhook code.

- Handle `TRANSFER` explicitly; do not expect a paired expiration and renewal. Update both id lists from the one destination delivery.

- Do not expect `TRANSFER` (or `SUBSCRIBER_ALIAS`) on an anonymous alias; sync on `logIn`.

- After every webhook, `GET /subscribers` and write entitlements from that.

- Idempotent on `event.id`.

- Map aliases to one Supabase user.

- There is no `REFUND` webhook; refunds arrive as `CANCELLATION`. Revoke when RevenueCat says the entitlement is gone, on web and mobile together.

- Do not revoke on `SUBSCRIPTION_PAUSED` or on a normal cancel before `EXPIRATION`.

- Stripe cancel and attach are part of the same entitlement story, not a second premium boolean.

## Sources

- RevenueCat webhooks: [https://www.revenuecat.com/docs/integrations/webhooks](https://www.revenuecat.com/docs/integrations/webhooks)

- RevenueCat event types and fields (including cancellation reasons): [https://www.revenuecat.com/docs/integrations/webhooks/event-types-and-fields](https://www.revenuecat.com/docs/integrations/webhooks/event-types-and-fields)

- RevenueCat common webhook flows: [https://www.revenuecat.com/docs/integrations/webhooks/event-flows](https://www.revenuecat.com/docs/integrations/webhooks/event-flows)

- RevenueCat restore behavior: [https://www.revenuecat.com/docs/projects/restore-behavior](https://www.revenuecat.com/docs/projects/restore-behavior)

- RevenueCat identifying customers: [https://www.revenuecat.com/docs/customers/identifying-customers](https://www.revenuecat.com/docs/customers/identifying-customers)

- RevenueCat Stripe external purchases: [https://www.revenuecat.com/docs/web/integrations/stripe/track-external-purchases](https://www.revenuecat.com/docs/web/integrations/stripe/track-external-purchases)

- RevenueCat Stripe server notifications: [https://www.revenuecat.com/docs/platform-resources/server-notifications/stripe-server-notifications](https://www.revenuecat.com/docs/platform-resources/server-notifications/stripe-server-notifications)


If you are wiring this stack yourself, the free [Capacitor + RevenueCat + Stripe entitlement checklist](https://appcontinuity.com/checklist/) is a printable PDF of the cases above. The canonical version of this article lives at https://appcontinuity.com/articles/refunds-transfers-and-which-webhook-updates-access/.

