# Pay per call

> For AI agents: the index of these docs is at https://referalli.com/docs/llms.txt (every page it lists has a Markdown version like this one).

Pay partners for qualified phone calls with your own Twilio account, or any call tracker that can send a signed webhook.

Give each partner a tracking phone number. When a caller dials it and the call qualifies, the partner earns a flat amount, once. Referalli holds no telephony key: you connect your own Twilio account, or point CallRail, Ringba, Invoca, Retreaver or any tool that can POST JSON at a signed webhook.

## Turn it on

```bash
curl -X PATCH https://referalli.com/v1/programs/$PROGRAM \
  -H "Authorization: Bearer $KEY" -H "content-type: application/json" \
  -d '{"payPerCall": {"enabled": true, "amountMinor": 2500, "currency": "usd",
        "minDurationSec": 60, "dedupeHours": 24, "forwardTo": "+14155550100"}}'
```

A call pays the partner `amountMinor` when it was answered, lasted at least `minDurationSec` (default 60), and the same caller has not already had a paid call in this program within `dedupeHours` (default 24). The caller's number is never stored, only a hash. The earning goes through the normal ledger: the rule's hold, group hold, caps and a blocked partner apply, and a program whose latest commission rule is a draft earns nothing. Each call pays once, however often the provider redelivers it. `forwardTo` (E.164) is your real line, which Twilio numbers ring.

## Twilio

1. Connect your account. The auth token is sealed and never returned.

   ```bash
   curl -X PUT https://referalli.com/v1/call-connections/twilio \
     -H "Authorization: Bearer $KEY" -H "content-type: application/json" \
     -d '{"accountSid": "AC...", "authToken": "..."}'
   ```
2. Assign a partner a number. Referalli buys a US local number in your Twilio account (in `areaCode` if you send one) and points its voice URL at `https://referalli.com/webhooks/calls/twilio/<token>`:

   ```bash
   curl -X POST https://referalli.com/v1/programs/$PROGRAM/call-numbers \
     -H "Authorization: Bearer $KEY" -H "content-type: application/json" \
     -d '{"partnerId": "ptr_...", "areaCode": "415"}'
   ```

Calls to the number are checked against `X-Twilio-Signature` with your auth token, rung through to `forwardTo`, and recorded when the forwarded leg ends. `DELETE /v1/programs/{id}/call-numbers/{numberId}` releases the number in Twilio and stops tracking it.

## Any other call tracker (webhook)

1. `PUT /v1/call-connections/webhook` with `{}`. The response carries `webhookUrl` and a signing `secret`, shown once (PUT again to rotate).
2. Register a number you bought in your own provider: `POST /v1/programs/{id}/call-numbers` with `{"partnerId": "ptr_...", "number": "+14155550100"}`.
3. Have the tracker POST each finished call to `webhookUrl`:

   ```json
   { "callId": "rg_8a1f3c", "to": "+14155550100", "from": "+16505550123",
     "durationSec": 184, "status": "completed", "startedAt": "2026-11-18T10:12:00Z" }
   ```

   Sign the raw body: `X-Referalli-Signature: sha256=<hex HMAC-SHA256 of the raw body keyed with the secret>`.

   ```js
   const sig = 'sha256=' + crypto.createHmac('sha256', secret).update(rawBody).digest('hex');
   ```

`to` must be a number you assigned. `status` is `completed` or `answered` for a connected call; anything else is recorded as an unpaid call. The answer says whether it paid: `{ "qualified": true, "reason": null, "commissionId": "cme_..." }`, or why not (`too_short`, `repeat_caller`, `status`, `unknown_number`, `program_disabled`, `cap_reached`).

### CallRail, Ringba, Invoca, Retreaver

Each of these can send a webhook when a call ends. Create a webhook (CallRail "post-call webhook", Ringba "pixel", Invoca "signal", Retreaver "webhook") that POSTs the JSON above to your `webhookUrl`. If the tool cannot compute an HMAC itself, send its call event to a small function of yours that maps the fields and signs the body.

## Show the partner's number on your site

Visitors who arrive through a partner can see that partner's number instead of yours, so calls from your site count too. Add `data-calls="swap"` to the tracking script tag and mark each phone number with `data-referalli-phone`:

```html
<script src="https://referalli.com/t/<orgToken>/aff.js" data-calls="swap" async></script>

<a href="tel:+14155550100" data-referalli-phone>(415) 555-0100</a>
```

When the visitor has a live referral from a partner who has a number in a pay-per-call program, the script loads a small `calls.js` and replaces the text (and the `tel:` link) of the marked elements only. Everyone else sees your number. The number is cached for the browser session. Nothing loads without `data-calls="swap"`.

## See the calls

`GET /v1/calls?programId=...&partnerId=...` lists calls with `qualified` on each. Partners see their own numbers at `GET /v1/partner/call-numbers`.

---

## For AI agents

- This page for a human reader: https://referalli.com/docs/pay-per-call
- The whole space as one Markdown file: https://referalli.com/docs/llms-full.txt
- Live search + fetch over MCP: https://referalli.com/docs/_api/public/orgs/07f432f4-34b9-46a7-aaad-c0e395d2e4f9/spaces/2bf4f614-3630-4fbf-85f9-5ecafa6b7d97/mcp
  - Install (Claude CLI): `claude mcp add referalli --transport http https://referalli.com/docs/_api/public/orgs/07f432f4-34b9-46a7-aaad-c0e395d2e4f9/spaces/2bf4f614-3630-4fbf-85f9-5ecafa6b7d97/mcp`

This Markdown is the same content the page renders — safe to quote and to ground answers in.
