# Referrals with RevenueCat

A header token Bolt Claw makes, plus RevenueCat's own signing: in-app purchases, renewals and refunds on every store.

Connect RevenueCat and every in-app purchase, renewal and refund on iOS,
Android and the web reaches the program, credited to the partner whose link or
code brought the customer.

## Add a webhook integration

1. Open the program, **Setup**, **Billing**, **RevenueCat**. Bolt Claw makes an
   **Authorization header value** and shows it **once**: copy it now. Copy the
   endpoint URL too.
2. In RevenueCat: **Project settings**, **Integrations**, **Webhooks**. Paste the
   URL, and the header value as the Authorization header.
3. Recommended: turn on RevenueCat's webhook signing and paste its signing secret
   on the card. The header value alone proves who sent a request, but not what it
   said; with the secret, every delivery's body is checked too, within five
   minutes.

Lost the header value? **Make new ones** on the card replaces it; the old one
stops working at once, so paste the new one into RevenueCat straight away.

## Pass the referral

Set subscriber attributes before the purchase. RevenueCat sends them with every
event.

```swift
Purchases.shared.attribution.setAttributes([
  "boltclaw_ref": ref,
  "boltclaw_customer_id": "acme-user-10442",
])
```

The customer is your own id from the attributes, else RevenueCat's original
app user id. `INITIAL_PURCHASE` and `NON_RENEWING_PURCHASE` are sales, `RENEWAL`
is a renewal, and `TEST` events are ignored.

## Refunds

RevenueCat reports a refund as a `CANCELLATION` for customer support with a
negative price: it takes back that share of the commission. There is no dispute
event.

## Offer codes

An offer code arrives as its text, so a purchase made with a partner's code is
credited to them.

## Test mode

RevenueCat says whether each event is from the sandbox or production; a sandbox
purchase is recorded as test data.

## Check it works

On the program's **Setup** tab, the **Billing** row of the setup status turns
`Connected` with the first verified event, and says when a delivery was refused
(nearly always the wrong secret). Then press **Send a test sale** to see a
click, a signup, a sale and a refund go through your rules with test data, or
make a real test purchase with a sandbox account. See [Connect your billing system](https://boltclaw.ai/docs/referral-setup)
for the whole setup status and what test data never does.

<!-- https://boltclaw.ai/docs/referral-billing-revenuecat as markdown. Generated from openapi.yaml; API version 1.22.0. -->
<!-- Every /docs page answers as markdown: add .md to its path, or send Accept: text/markdown. -->
