How it fits together
Clavem never touches the payment. The customer pays in a Polar checkout, as they do today, and Polar stays your merchant of record: it collects the money, the tax and the invoices. Polar sends the events of your organization to Clavem, which checks their signature and then issues, extends, expires or disables licenses to match. A license from a Polar sale costs the same as one from a Stripe sale, on every plan and on Pay As You Go.
There are two ways to connect. Connect with Polar signs you in at Polar, where you choose the organization and approve: nothing to create or paste. An Organization Access Token works too, if you prefer it. Both issue licenses the same way, and in both cases Clavem registers its own webhook in your organization.
Clavem reads orders, subscriptions, refunds, customers and products. It cannot refund orders, change your products or move money. The only things it creates at Polar are its own webhook and, when a buyer renews their updates, a checkout for your renewal product.
Connect with Polar
- Open Settings in the dashboard, then Payments, and choose Connect with Polar. To try it in Polar's sandbox first, choose Connect Polar sandbox.
- Polar opens. Choose the organization and approve the permissions Clavem asks for.
- Polar sends you back to Clavem, and the organization shows as connected, marked Live or Sandbox. Link your products, below.
On the way back Clavem reads which organization you chose, registers its webhook there and stores the sign-in's tokens, encrypted, with the encryption key held outside the database. If Polar grants fewer permissions than Clavem asks for, nothing is connected and you are told so: connect again and approve all of them. A sign-in has to be finished within 10 minutes and works once.
Connect another organization the same way: each one gets its own webhook, and each product sells through one of them. One Clavem account can connect up to 25 payment accounts. Connecting an organization that is already connected, in the same mode, connects it again: Clavem takes the new sign-in, and its product links stay.
Or: an Organization Access Token
In Polar, open your organization's settings and create an Organization Access Token with exactly these scopes. Make it on sandbox.polar.sh for a sandbox organization. The same scopes are what Connect with Polar asks for.
| Scope | What Clavem uses it for |
|---|---|
organizations:read | To know which organization the token belongs to. |
products:read | To list the products you can link. |
benefits:read | To warn about a Polar license key benefit and to import keys by benefit. |
orders:read | To see what was bought and by whom. |
subscriptions:read | To keep a subscription license valid while it is paid. |
customers:read | For the buyer’s name and email. |
refunds:read | To disable a license when its order is refunded. |
checkouts:write | To open a checkout when a buyer renews their updates. |
webhooks:read | To check the webhook Clavem registered. |
webhooks:write | So Clavem can register its own webhook, and remove it when you disconnect. |
license_keys:read | To import the license keys you already sold. |
Then open Settings, Payments, and Or paste an access token. Choose the mode the token was made in, Live or Sandbox, and paste it (it starts with polar_oat_). Clavem then:
- Checks that Polar accepts the token, that it opens exactly one organization, and that it has every
:readscope above. If not, nothing is saved, and a missing scope is named. The two write scopes are not checked here: a missingwebhooks:writeshows up in the next step, and a missingcheckouts:writeonly when a buyer uses the renew button. - Creates a webhook endpoint in that organization, pointing at a private URL of the form
https://clavem.io/api/polar/hook/<a private id>, subscribed to the nine events below. - Stores the token and the endpoint's signing secret, encrypted. The token is never shown again: Settings shows only its last 4 characters, and so does the API (
token_hint).
order.paid
order.updated
order.refunded
subscription.created
subscription.active
subscription.updated
subscription.canceled
subscription.uncanceled
subscription.revokedPasting a new token for an organization that is already connected, in the same mode, replaces the old one and keeps the product links. That is also how you bring back a token connection that needs a reconnect.
Live and sandbox
A connection is either live or sandbox. A sandbox organization, on Polar's sandbox at sandbox.polar.sh, is Polar's test mode, and every order there issues a test license: it has test_mode: true, its token carries test: true, and it expires at most 7 days after it was issued, an expiry that renewals never move later. Test licenses are free on Pay As You Go and are left out of analytics. A release build of your app should refuse them (see test-mode licenses).
Polar's sandbox and live organizations are separate, with their own product ids. Connect the live organization next to the sandbox one when you are ready, and link the live products again. Disconnect the sandbox when you are done.
Link Polar products
An order issues a license only for a Polar product you have linked to a Clavem product. In the dashboard, open the Clavem product, go to its Payments tab and, in the Polar section, choose the organization (when you have several) and Link a Polar product. The list shows your Polar products with their price and billing interval; archived ones are left out.
- One link per Polar product. A Polar product has one price, so there is nothing finer to link. Linking the same Polar product again changes its link, and linking it to another Clavem product moves it there.
- A variant name, optional. It becomes the variant name on the license.
- A plan, optional, once the Clavem product has plans. Licenses bought through the link are on it. A plan that a Polar link names cannot be removed from the product until you change the link.
- One organization per product. A product sells through one Polar organization. To move it, unlink its Polar products first. A product can sell through a Stripe account and a Polar organization at the same time, for example while you move from one to the other.
An order of a Polar product that is not linked, or that is linked to an archived Clavem product, issues nothing and shows up in your Activity as Sale of an unmapped product, so you can fix the link and see what you missed.
Seat-based and metered prices are not supported as such: an order of such a product issues one license, whatever the number of seats. Set the device limit on the Clavem product or the license instead.
Polar's own license keys. Clavem issues the keys, so remove Polar's license key benefit from the products you link, or buyers get two keys. The Payments tab warns on every linked product that still has that benefit. Keys Polar already issued can be imported, so apps keep accepting them. While older builds of your app still check keys with Polar, find out in Polar what removing the benefit does to the keys it already granted before you remove it.
What each event does
Every delivery is verified against the signing secret of your organization's endpoint, and its timestamp must be within five minutes. Each delivery is processed once, so Polar's retries are safe. If processing fails, Clavem answers with an error and Polar retries it. Events can arrive out of order, so for subscription events Clavem reads the subscription as Polar has it now and applies that.
| Event | What Clavem does |
|---|---|
order.paida purchase | If the order has an email address: creates the order and its private page, issues a license for the linked product, and emails the buyer the key and the order link. The license follows the product's validity: perpetual, or a number of days. Pay As You Go is charged, or the order is held, exactly as for a Stripe sale. A live purchase also converts the buyer's free trial of the same product, when it was started with the same email address. |
order.paida new subscription | The subscription's sale, unless its start already issued the license (below): then the order only fills in the order id and the amount. A subscription issues its license once, whichever of its events comes first. |
order.paida renewal cycle | Moves the expiry of the subscription's licenses to the end of the new period plus three days, and revives any that had expired. Only while the subscription still grants access: a late renewal never brings back one that has ended. |
order.paidan update renewal | An order made by the renew button extends the license's updates instead: see paid update renewal. It issues no license. |
order.paida plan change or a usage charge | Nothing. The subscription events carry the change. |
order.updatedwith status paid | The same as order.paid, as a backup in case order.paid is lost. A sale is recorded once per order either way, and a renewal applied once, whichever of the two arrives first. An order Clavem cannot read is reported once, by order.paid. With any other status it does nothing: refunds come as order.refunded. |
subscription.createdsubscription.active | When the subscription is active or trialing and Polar still has it granting access now, issues its license, as above. A buyer who starts a free trial in Polar gets the license at the start of the trial, expiring at the end of the subscription's current period plus three days. |
subscription.updatedsubscription.canceledsubscription.uncanceled | Mirrors the subscription's status. active, trialing and past_due keep the licenses valid, and past_due stays valid while Polar retries the payment. A subscription canceled at the end of its period keeps them valid until then. unpaid, incomplete_expired, paused and trial_ended expire them, and a later status that grants access again brings them back. When the subscription moves to another linked Polar product, its licenses move to the plan that link names. |
subscription.revoked | Expires the subscription's licenses at once. |
order.refunded | For a full refund: disables every license from the order and marks the order refunded. A partial refund changes nothing. |
A license you disabled by hand stays disabled, whatever Polar says. An order without an email address issues nothing and shows up in your Activity as Sale skipped. Plan limits never stop these events: a paid order always issues its license, even over your plan's limit. Only manual creation and imports pause.
An event Clavem cannot read is never dropped silently. If a delivery has a shape Clavem does not understand, for example an order with a reason it does not know, it shows up in your Activity as Payment event Clavem could not read, with its type and delivery id. Look at the order in Polar, and issue the license by hand if a sale was missed.
Subscriptions
A subscription license expires at the end of its current period plus three days of grace, so a renewal that settles late does not lock a customer out. Each paid cycle moves the expiry forward. Clavem evaluates expiry whenever the license is read and runs no background job, so the API reports expired the moment the date passes, and active again as soon as the next cycle is paid.
A customer who cancels keeps the license until the end of the period they paid for. When Polar revokes the subscription, the license expires. A new subscription after that is a new purchase and issues a new license.
Subscription events are matched to licenses by the Polar subscription a license was issued under, and only on the organization it came through. Licenses created by hand or imported have none, so subscription events never change them. The order page of a subscription license has a Manage your subscription link to Polar, and the license in your dashboard links to the order in Polar.
If Polar stops accepting Clavem's access (the connection shows Reconnect), orders keep issuing licenses. Until you reconnect, subscription events are applied from the event alone, carefully: an expiry only moves later, and an expired license is not brought back.
Paid update renewal
A product with an update period can renew through Polar. Create a one-time product with a fixed price in Polar, then on the Clavem product's Payments tab link it in the Polar section with Renewal switched on.
- The order page then shows Renew updates on each license whose updates end, except a subscription's, whose updates come with the subscription. The button opens a Polar checkout that Clavem creates for the renewal product, with the buyer's email filled in and a signed reference in its metadata. After paying, the buyer comes back to their order page.
- The paid order moves
updates_untilforward by the product's period. It issues no license, creates no order and is not charged on Pay As You Go. Each Polar order counts once, however often Polar sends it. - A product has one renewal across Stripe, Polar, Dodo Payments and Creem, because the button needs exactly one. A product that has a Stripe renewal price cannot get a Polar renewal: unlink the Stripe one first. Linking another Polar renewal product replaces the one before.
- A purchase of the renewal product without the button's reference issues no license; the Activity shows it as unmapped.
- Clavem reads the renewal product's price when you link it. Link it again after you change the price in Polar.
- A refund of a renewal does not move the date back. Change it on the license if you need to.
Creating the checkout needs the checkouts:write scope, which Connect with Polar asks for and an access token needs too. Clavem does not check it when you paste a token: without it the renew button fails, and the Activity entry names the scope. The Stripe Payment Link option of the update period is for Stripe only.
Import Polar license keys
If Polar has been issuing keys for you, bring them over, so an app that switches its check to Clavem keeps accepting every key already sold. Open Import in the dashboard and choose Polar.
- Choose the source: a connected organization, which needs no token, or a pasted Organization Access Token and its mode. A pasted token is used for that import only and is never stored.
- Check the preview: the organization's license key benefits and how many keys each has.
- Match each benefit to a Clavem product, or let Clavem create a product with the benefit's name.
- Import. The dashboard goes page by page: 40 keys a page for a sandbox organization, 100 for a live one.
- Keys are kept as they are, prefix included, with the buyer's email and name, the activation limit (none means unlimited) and the expiry date.
- The status carries over. A granted key is active when it has an activation or a use reported to Polar, inactive otherwise. A revoked or disabled key is disabled.
- A granted key's activations become devices, under their Polar activation id, so an app that stored the
activation_idcan send it asinstance_id. - A sandbox organization's keys become test licenses.
- It is safe to run again. Keys already in your account are skipped, and a key that belongs to another Clavem account is reported as a conflict and left alone. Nothing is emailed.
- If Polar asks Clavem to slow down, nothing of that page is written. The dashboard waits the seconds Polar asked for and continues.
Imported keys count against your plan like any other, and on Pay As You Go up to 10,000 imported licenses are free (see what an import costs). An imported key is not tied to a Polar subscription, so subscription events never change it: if the key belongs to a subscription, set its expiry or disable it in Clavem when the subscription ends.
Admin API and MCP
Once an organization is connected, everything else can be done from a script with the management API, or by asking an assistant through the MCP server: list the connected organizations and their products, link and unlink products, choose a product's organization, and import a connected organization's keys. Connecting and disconnecting stay in the dashboard: Connect with Polar is a sign-in in your browser, a token is a secret that should not pass through a chat, and disconnecting deletes Clavem's webhook at Polar.
curl https://clavem.io/v1/admin/payment-links \
-H "Authorization: Bearer sk_clavem_…" \
-H "Content-Type: application/json" \
-d '{
"product_id": 75,
"external_product_id": "e1f7c0d2-…",
"plan": "pro",
"label": "Pro yearly"
}'Test it
- Connect a sandbox organization with Connect Polar sandbox, or a sandbox token, and link a sandbox product.
- Buy it through its Polar checkout with the test card
4242 4242 4242 4242, any future expiry date and any CVC. - Open Licenses. The new license is there, marked as test, with its order page.
- In Polar, open your organization's webhooks and Clavem's endpoint. Recent deliveries should be
200. - Refund the order in full. The license becomes
disabled.
Disconnecting and troubleshooting
Disconnecting deletes Clavem's webhook in that organization and, for a Connect with Polar connection, revokes Clavem's access at Polar; for a token connection Clavem forgets the token. The Polar products linked on that organization are unlinked from your Clavem products, so link them again if you connect it again. Licenses and orders already issued stay as they are. Other connected organizations are not affected. If Polar could not delete the webhook, Clavem says so: remove it in Polar under Settings, Webhooks.
Refunds and subscription events follow the organization an order came through. Orders of a disconnected organization keep their licenses; connect it again and its later refunds and subscription events reach those orders again.
| Symptom | Likely cause |
|---|---|
| Polar did not grant every permission Clavem asks for | Some permissions were not approved at Polar. Connect again and approve all of them. |
| That sign-in expired or was already used | More than 10 minutes passed, or the sign-in was finished already. Choose Connect with Polar again. |
| Polar did not accept this token | The token was copied incompletely, has been revoked or expired, or was made in the other mode: a sandbox token needs Sandbox, a live token Live. |
| This token is missing a scope | The token lacks one of the read scopes, named in the message. Create a new Organization Access Token with every scope listed above. |
| This token opens more than one Polar organization | Use an Organization Access Token, which belongs to one organization. |
| Clavem could not register its webhook at Polar | The token lacks the webhooks:write scope. |
| You can connect up to 25 payment accounts | Disconnect one you no longer sell through. |
| The organization shows Reconnect | Polar no longer accepts Clavem's access, for example after the token was revoked. Orders keep issuing licenses, but linking, renewals and imports need it back. Reconnect, or paste a new token; your product links are kept. |
| Polar is asking Clavem to slow down | Polar's rate limit. Wait the seconds Polar named and try again. The API answers 429 with provider_rate_limited and Retry-After. |
| An order made no license | The Polar product is not linked, or is linked on another organization than the one the order was made in, or the Clavem product is archived (see the unmapped entry in your Activity), or the order had no email address (Sale skipped). |
| Buyers got two keys | The Polar product still has Polar's license key benefit. Remove it in Polar. |
| Payment event Clavem could not read | Polar sent something Clavem does not understand. Check the order in Polar, issue the license by hand if needed, and tell us. |
| The renew button fails | The renewal product is no longer on sale in Polar, or the connection may not create checkouts (checkouts:write). The Activity names what Polar said. Reconnect the organization if it needs it. |
| Deliveries fail with 400 in Polar | The webhook's signing secret no longer matches, for example after the endpoint was changed in Polar. Disconnect and connect again, then link the products again. |