> ## Documentation Index
> Fetch the complete documentation index at: https://docs.affixo.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Connect Polar

> Paste one Polar token and Affixo tracks your Polar sales, renewals, refunds and chargebacks on its own. No webhook to copy and no server code.

If you sell through [Polar](https://polar.sh), you don't need to write any code to run your affiliate program. You paste one Polar token into Affixo. Affixo checks it, adds its own webhook in your Polar account, and from then on every paid order, renewal, refund and chargeback comes in by itself and pays (or takes back) the right commission.

```mermaid theme={null}
flowchart TD
  A["Affiliate link"] --> B["Your site with the Affixo snippet"]
  B --> C["Polar checkout (carries the visitor id)"]
  C --> D["Polar sends the order to Affixo"]
  D --> E["Commission for the affiliate"]
```

Affixo only reads your Polar sales. It never charges your customers, never moves money in Polar, and never pays your affiliates for you.

## Before you start

You need:

* **The Affixo snippet** on every page of your site, as described in [Integrate Affixo tracking](https://docs.affixo.dev/integrate.md). It is what tells Polar which affiliate sent the buyer.
* **A program with a commission set**, so a sale has something to pay.
* **Admin access to your Polar organization**, to create the token.
* **Billing access in Affixo**, to change how your workspace takes payments.

> [!WARNING]
>
> **One processor per account.** A workspace takes its sales from Stripe, from Polar, or from your own server, never more than one. If this workspace has already used Stripe, it can't switch to Polar. Use a new workspace for your Polar products, or contact support if you think the Stripe link is a mistake.
>
> While your workspace is set to Polar, Affixo doesn't book live sales sent by your own server through `/v1/track/sale` or `/postback`, so one purchase can't pay two commissions. Those calls get a `409` with the error `processor_connected`, so turn your server's sale reporting off. Test sales, leads and refunds still work.

## Step 1: Create a Polar token

In Polar, open **Settings → Access Tokens** and create an **organization access token**. Tick these permissions and no others:

| Permission | Why Affixo needs it |
| - | - |
| `orders:read` | Read each paid order and its amount |
| `refunds:read` | Read refunds, so commissions on refunded orders shrink |
| `products:read` | Name the product on each sale |
| `subscriptions:read` | Link renewals to the first sale, for recurring commissions |
| `disputes:read` | Check for chargebacks (Polar doesn't send them as webhooks) |
| `webhooks:write` | Add, and later remove, Affixo's one webhook in your Polar account |

Copy the token when Polar shows it. It starts with `polar_oat_`.

If you give the token an expiry date, put a reminder in your calendar to reconnect with a new token before it runs out. Polar's own guide is [Organization access tokens](https://polar.sh/docs/integrate/oat).

> [!TIP]
>
> None of these permissions lets Affixo create orders, issue refunds or move money. Polar doesn't tell Affixo which permissions a token has, so we can't check this for you: a token that can also write orders, refunds or products would still connect, and could change your Polar account if it ever leaked. Tick only the permissions above.

## Step 2: Paste it into Affixo

1. In Affixo, open **Settings → Payments & products** and choose **I use Polar**.
2. Pick **Live** for your real store. (Use **Sandbox** for a Polar sandbox token, see [Test it with the Polar sandbox](#test-it-with-the-polar-sandbox).)
3. Paste the token and click **Connect Polar**.

Affixo then:

```mermaid theme={null}
flowchart TD
  A["You paste the token"] --> B["Affixo checks it with Polar"]
  B -->|"Wrong token or a missing permission"| X["Nothing is saved. You see what to fix."]
  B -->|"OK"| C["Token stored encrypted"]
  C --> D["Affixo adds one webhook named Affixo in Polar"]
  D --> E["Connected"]
```

You'll see the connection as **Connected**, with the last 4 characters of the token and the time of the last event from Polar. Affixo never shows the token again. In Polar, the new webhook appears under **Settings → Webhooks**. Leave it there: it is how your sales reach Affixo.

## Step 3: Your Polar checkout links

**Checkout links on your site work as they are.** When the snippet sees a link to a Polar checkout, it adds the visitor's id to it as Polar's `reference_id`. Polar keeps that id on the order, and Affixo uses it to find the affiliate.

The snippet recognises links to `buy.polar.sh`, Polar checkout pages on `polar.sh`, and Polar checkout links (`api.polar.sh/v1/checkout-links/...`), plus their sandbox versions. The links have to be on a page where the snippet is installed.

**If your server creates checkouts with Polar's API**, there's no link for the snippet to tag. Pass the visitor id yourself:

```js theme={null}
// In the browser, before you call your server
const visitorId = await window.Affixo.ready();
// Send visitorId to your server with the order, then when you create the checkout:
// metadata: { affixo_visitor_id: visitorId }
```

> [!NOTE]
>
> If you already put your own `reference_id` on a checkout link, the snippet leaves it alone. Sales from that link can then only be matched by the buyer's email, if they signed up as a lead first. See [Attribution](https://docs.affixo.dev/attribution.md).

## What Affixo books

```mermaid theme={null}
flowchart LR
  P1["Order paid"] --> S["Sale + commission"]
  P2["Renewal paid"] --> R["Renewal sale + recurring commission"]
  P3["Order refunded"] --> F["Commission reduced or reversed"]
  P4["Chargeback"] --> C["Commission reversed"]
  P5["Dispute won"] --> W["Commission restored"]
```

| In Polar | In Affixo |
| - | - |
| An order is paid | A sale on the order's amount after discounts and before tax. The commission follows your campaign's rules. |
| A \$0 order (a free trial, a 100% discount) | A lead, not a sale. It earns nothing, but later renewals still credit the same affiliate. |
| A subscription renews | A new sale for the same affiliate, paid if your campaign pays recurring commissions. |
| An order is partly refunded | The commission shrinks in proportion. A $5 sale with $2 refunded pays commission on \$3. |
| An order is fully refunded | The commission is reversed. |
| A chargeback is opened or lost | The commission is reversed. |
| A dispute is won | The commission is restored. |

Polar doesn't send dispute webhooks, so Affixo checks your Polar disputes every 15 minutes. A chargeback can take that long to show.

Each Polar event is booked once, however many times Polar sends it.

## Test it with the Polar sandbox

Polar has a separate [sandbox](https://sandbox.polar.sh) with test cards. Connect it in Affixo as its own **Sandbox** connection. Sandbox sales book as **test sales** with test commissions, which are never paid and never counted in reports, payouts or alerts.

> [!WARNING]
>
> **Start every sandbox purchase from a test visit.** Affixo keeps test and live data apart: a sandbox sale only matches a test click, and a normal visit is a live click. If you click an affiliate link the usual way and then pay in the sandbox, the sale arrives but credits no one.

```mermaid theme={null}
flowchart TD
  A["Open yoursite.com/?ref=CODE&_sa_test=1"] --> B["Test click recorded"]
  B --> C["Buy with a Polar sandbox checkout link"]
  C --> D["Test sale + test commission on Referrals"]
```

1. In the Polar sandbox, create a product and a checkout link, and put the link on a page of your site that has the snippet. (A test page is fine.)
2. Create a sandbox organization access token with the same permissions as in step 1.
3. In Affixo, choose **Sandbox** on **Settings → Payments & products**, paste the sandbox token and click **Connect Polar sandbox**.
4. Open your site through an affiliate's link with `_sa_test=1` added, for example `https://yoursite.com/?ref=jane&_sa_test=1`. That marks your visit as a test for the next 30 minutes in that browser. See [Test links](https://docs.affixo.dev/sa-js.md#test-links).
5. Click the Polar checkout link and pay with Polar's test card `4242 4242 4242 4242`, any future expiry and any CVC.
6. Within a few seconds the sale shows on **Referrals** as a test sale, credited to that affiliate. The **Check it works** box on the Polar screen also says **Sandbox events are arriving**.
7. To test refunds, refund part of the order in the Polar sandbox and watch the commission shrink.

A sandbox connection doesn't count as your payments being connected. Connect **Live** before you launch.

## Change or remove the connection

* **Rotate the token:** create a new token in Polar, then paste it with **Reconnect live** (or **Reconnect sandbox**). Affixo adds the new webhook before it removes the old one, so no sale is missed. The new token must be for the same Polar organization.
* **Disconnect:** click **Disconnect** on the connection. Affixo removes its webhook in Polar and deletes the token. New sales stop coming in until you reconnect. Sales already booked stay as they are.
* **Stop using Polar:** after disconnecting, **Use Stripe or another processor**, at the top of the page, takes you back to the list of options. This only works until your first real (live) Polar sale. After that the workspace stays on Polar.

## Troubleshooting

| What you see | What to do |
| - | - |
| "That doesn't look like a Polar organization access token" | You pasted something else, often a password your browser filled in. Copy the token from Polar again. It starts with `polar_oat_`. |
| "Polar didn't accept that token" | The token is wrong, expired or revoked, or it's a sandbox token in **Live** (or the other way round). |
| "That token is missing the ... permission" | Create a new token with every permission in step 1 ticked. |
| "That token is for a different Polar organization" | You're reconnecting with a token from another Polar organization. Disconnect first, then connect the new one. |
| Your server gets `409 processor_connected` | The workspace takes its sales from Polar. Turn off your server's sale reporting. See [One processor per account](#before-you-start). |
| "This Polar account is already connected to another Affixo workspace" | A live Polar organization can be connected to one workspace at a time. Disconnect it in the other workspace, then connect it here. If you can't get into that workspace, contact support. |
| "Another connect attempt changed this connection while we were working" | Someone (or another tab) was connecting at the same time and that attempt failed. Nothing was saved. Connect again. |
| "Stripe has already been used on this workspace" | See [One processor per account](#before-you-start). |
| The connection says **Needs attention** | Polar stopped accepting the token Affixo has, usually because it was revoked or expired. Reconnect with a new token. |
| A sandbox sale shows up with no affiliate | The visit wasn't a test visit. Start again from a `?_sa_test=1` link (step 4 of the sandbox test). |
| A live sale shows up with no affiliate | The buyer didn't come through an affiliate link, the link wasn't on a page with the snippet, or the checkout was made through Polar's API without `metadata.affixo_visitor_id`. |
| No events at all | Check the **Affixo** webhook is still under **Settings → Webhooks** in Polar. If someone deleted it, reconnect with **Reconnect live**. |

Still stuck? Contact support and include the Polar order id.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.