# `RevenueCat.Webhook`
[🔗](https://github.com/metacircu1ar/revenue_cat/blob/main/lib/revenue_cat/webhook.ex#L1)

RevenueCat webhook ingestion with deduplication and Ecto-backed persistence helpers.

This module:

- validates and extracts webhook event payload fields
- inserts or fetches webhook event rows idempotently by `external_id`
- executes host-defined event handling exactly once per event row
- marks rows as processed/failed with sync attempt metadata

## Required options

- `:repo` - your Ecto repo module
- `:schema` - your webhook event schema module
- `:handle_event_fun` - function `(event_map, event_meta_map) -> :ok | {:error, reason}`

## Optional options

- `:create_changeset_fun` - defaults to `RevenueCat.Ecto.WebhookEvent.create_changeset/2`
- `:external_id_constraint_name` - unique index/constraint name for `external_id` (default: `"revenuecat_webhook_events_external_id_idx"`)
- `:synced_changeset_fun` - defaults to `RevenueCat.Ecto.WebhookEvent.synced_changeset/2`
- `:failed_changeset_fun` - defaults to `RevenueCat.Ecto.WebhookEvent.failed_changeset/2`
- `:lock_event_fun` - lock/load function for transaction safety
- `:now_fun` - timestamp factory returning `DateTime.t()` or `NaiveDateTime.t()`

# `webhook_result`

```elixir
@type webhook_result() :: :processed | :duplicate
```

# `process`

```elixir
@spec process(
  map(),
  keyword()
) :: {:ok, webhook_result()} | {:error, term()}
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
