Clavem

Documentation

Connecting Dodo Payments

Keep Dodo Payments for payments. Clavem listens to your Dodo business, or to several, and turns payments, renewals, cancellations and refunds into license changes.

How it fits together

Clavem never touches the payment. The customer pays in a Dodo Payments checkout, as they do today, and Dodo stays your merchant of record: it collects the money, the tax and the invoices. Dodo sends the events of your business to Clavem, which checks their signature and then issues, extends, expires or disables licenses to match. A license from a Dodo sale costs the same as one from a Stripe or Polar sale, on every plan and on Pay As You Go.

You connect a business by pasting an API key that you create in Dodo. Clavem registers its own webhook in that business, so there is nothing to set up in Dodo besides the key. Give the key only the permissions listed below: Clavem then reads products, payments and subscriptions, and it cannot refund payments, change your products or move money. The only things it creates at Dodo are its own webhook and, when a buyer renews their updates, a checkout for your renewal product.

Connect with an API key

  1. In Dodo Payments, open Developer, then API Keys, and create a key with the permissions below. Make it in test mode to try Clavem with your test business first.
  2. In Clavem, open Settings, then Payments. Under Dodo Payments, paste the key and choose Connect Dodo Payments.
  3. The business shows as connected, under its name and marked Live or Test. Link your products, below.
PermissionNeededWhat Clavem uses it for
Products (read)YesTo list the products you can link.
Subscriptions (read)YesTo keep a subscription license valid while it is paid.
Payments (read)YesTo see what was bought and by whom.
Brands (read)YesTo name your business.
Webhooks (write)YesSo Clavem can register its own webhook, and remove it when you disconnect.
Checkout sessions (write)YesTo open a checkout when a buyer renews their updates.
License keys (read)OptionalTo import the license keys you already sold from this connection.
Customers (read)OptionalTo import the buyer of each license key you already sold.
Entitlements (read)OptionalTo warn when a product also hands out Dodo’s own license key.

The key's prefix sets the mode: a key that starts with dodo_test_ opens your test business, one that starts with dodo_live_ your live business. Only an older key without a prefix asks you to choose the mode it was made in. When you connect, Clavem:

  1. Checks that Dodo accepts the key and that it may read products, subscriptions, payments and brands. If not, nothing is saved, and every missing permission is named. The business is named after its primary brand.
  2. Creates a webhook endpoint in that business, pointing at a private URL of the form https://clavem.io/api/dodo/hook/<a private id>, subscribed to the twelve events below. A key without Webhooks (write) stops here, and nothing is saved.
  3. Stores the key and the endpoint's signing secret, encrypted, with the encryption key held outside the database. The key is never shown again: Settings shows only its last 4 characters, and so does the API (token_hint).
Events subscribed
payment.succeeded
refund.succeeded
subscription.active
subscription.renewed
subscription.plan_changed
subscription.updated
subscription.on_hold
subscription.past_due
subscription.paused
subscription.cancelled
subscription.expired
subscription.failed

Checkout sessions (write) is not checked when you connect, because checking it would open a checkout. A key without it only fails when a buyer uses the renew button. The optional permissions are not needed to connect. Without License keys (read) or Customers (read), the business's keys cannot be imported from the connection, and without Entitlements (read), Clavem cannot warn about Dodo's own license keys. When the key lacks any of the three, Settings says so once it is connected.

Connect another business 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. Pasting a new key for a business that is already connected, in the same mode, connects it again: Clavem takes the new key and a new webhook, deletes the old webhook, and its product links stay.

Live and test mode

A connection is either live or test. Dodo keeps test mode apart from live mode, with its own keys, products and webhooks, and it is open from sign-up, before your business is verified. Every payment in a test business 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).

Your test and live products have different ids. Connect the live business next to the test one when you are ready, with a live key, and link the live products again. Disconnect the test business when you are done.

A payment issues a license only for a Dodo product you have linked to a Clavem product. In the dashboard, open the Clavem product, go to its Payments tab and, in the Dodo Payments section, choose the business (when you have several) and link a product. The list shows your Dodo products with their price and billing interval; archived ones are left out.

  • One link per Dodo product. A Dodo product has one price, so there is nothing finer to link. Linking the same Dodo 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 Dodo link names cannot be removed from the product until you change the link.
  • One payment account per product. A product sells through one Dodo business, Polar organization or Creem store. To move it, unlink its products first. A product can sell through a Stripe account and a Dodo business at the same time, for example while you move from one to the other.

A payment for a Dodo 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.

Quantities, add-ons and usage-based prices are not counted: a payment issues one license for each linked product in it, whatever the quantity or the number of seats. Set the device limit on the Clavem product or the license instead.

Dodo's own license keys. Clavem issues the keys, so remove the License Key entitlement from the Dodo products you link, or buyers get two keys. The Payments tab warns on every linked product that still has one, when the key has Entitlements (read). Keys Dodo already issued can be imported, so apps keep accepting them. While older builds of your app still check keys with Dodo, find out in Dodo what removing the entitlement does to the keys it already issued before you remove it.

What each event does

Every delivery is verified against the signing secret of your business's endpoint, and its timestamp must be within five minutes. Each delivery is processed once, so Dodo's retries are safe. If processing fails, Clavem answers with an error and Dodo retries it. Dodo does not send events in order, so for subscription events Clavem reads the subscription as Dodo has it now and applies that.

EventWhat Clavem does
payment.succeededa one-time purchaseIf the payment has an email address: creates the order and its private page, issues a license for each linked product in it, 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.
payment.succeededa subscription's first paymentThe subscription's sale, of the product and period it has at Dodo now, unless its start already issued the license (below): then the payment only fills in the order id and the amount. A subscription issues its license once, whichever of its events comes first.
payment.succeededa renewal
subscription.renewed
Moves the expiry of the subscription's licenses to its next billing date 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. Dodo sends both events for one renewal, and it is applied once.
payment.succeededan update renewalA payment made through the renew button extends the license's updates instead: see paid update renewal. It issues no license.
payment.succeededa plan change or an on-demand chargeNothing. The subscription events carry the change.
subscription.activeWhen the subscription is active as Dodo has it now, issues its license, as above. A buyer who starts a free trial gets the license at the start of the trial, before any payment, expiring at the subscription's next billing date plus three days. A subscription that comes back from on hold or a pause gets its licenses back.
subscription.updated
subscription.plan_changed
subscription.past_due
subscription.on_hold
subscription.paused
subscription.cancelled
subscription.expired
subscription.failed
Mirrors the subscription's status. active and past_due keep the licenses valid: past_due is Dodo's grace period, while it retries the payment. A subscription cancelled at the end of its period stays active until then, and so do its licenses. on_hold (a renewal failed), paused, cancelled, expired and failed expire them, and a later active brings them back. When the subscription moves to another linked Dodo product, its licenses move to the plan that link names.
refund.succeededFor a full refund: disables every license from the payment and marks the order refunded. A partial refund changes nothing, until partial refunds add up to the whole payment: then it counts as a full refund.

A license you disabled by hand stays disabled, whatever Dodo says. A payment 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 a subscription charge of a kind 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 payment in Dodo, and issue the license by hand if a sale was missed.

Subscriptions

A subscription license expires at its next billing date plus three days of grace, so a renewal that settles late does not lock a customer out. Each paid renewal 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 renewal is paid.

A customer who cancels keeps the license until the end of the period they paid for. A subscription that Dodo puts on hold because a renewal failed, or that is paused, ends the license, and it comes back when the subscription is active again. A new subscription after a cancellation is a new purchase and issues a new license.

Subscription events are matched to licenses by the Dodo subscription a license was issued under, and only on the business it came through. Licenses created by hand or imported have none, so subscription events never change them. The license in your dashboard links to its subscription and its payment in Dodo. The order page of a Dodo subscription license has no Manage your subscription link.

If Dodo stops accepting the key, for example after you deleted it in Dodo, sales keep issuing licenses. Until you paste a new key, 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 Dodo Payments. Create a one-time product with one fixed price in Dodo, not pay what you want, then on the Clavem product's Payments tab link it in the Dodo Payments 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 Dodo 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 payment moves updates_until forward by the product's period. It issues no license, creates no order and is not charged on Pay As You Go. Each Dodo payment counts once, however often Dodo 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 Dodo renewal: unlink the Stripe one first. Linking another Dodo 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 Dodo.
  • A refund of a renewal does not move the date back. Change it on the license if you need to.

Creating the checkout needs Checkout sessions (write) on the key. Clavem does not check it when you connect: without it the renew button fails, and the Activity entry names the permission. The Stripe Payment Link option of the update period is for Stripe only.

Import Dodo license keys

If Dodo 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 Dodo Payments.

  1. Choose the source: a connected business, which needs no key, or a pasted API key and its mode. A pasted key needs read access to license keys, customers and products; it is used for that import only and is never stored.
  2. Check the preview: the business's products.
  3. Match each Dodo product to a Clavem product, or let Clavem create a product with the same name.
  4. Import. The dashboard goes page by page, 100 keys a page, and a stopped run resumes where it ended.
  • Keys are kept as they are, with the buyer's email and name, the activation limit (none means unlimited) and the expiry date.
  • The status carries over. An active key is active when a device is on it, inactive otherwise; both are valid. An expired or disabled key stays so.
  • A key's instances become devices, under their Dodo id (lki_…), so an app that stored license_key_instance_id can send it as instance_id.
  • A test business'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 Dodo asks Clavem to slow down, nothing of that page is written. The dashboard waits the seconds Dodo asked for and continues.

Importing from a connected business needs License keys (read) and Customers (read) on its key. Dodo marks the list of license keys that Clavem reads as deprecated, so import soon. If it is gone, the file import takes over: see moving Dodo license keys to Clavem. 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 Dodo 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 a business 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 businesses and their products, link and unlink products, choose a product's business, and import a connected business's keys. Connecting and disconnecting stay in the dashboard: an API key is a secret that should not pass through a chat, and disconnecting deletes Clavem's webhook at Dodo.

Link a Dodo product to a product, on the Pro plan
curl https://clavem.io/v1/admin/payment-links \
  -H "Authorization: Bearer sk_clavem_…" \
  -H "Content-Type: application/json" \
  -d '{
    "product_id": 75,
    "connection_id": 5,
    "external_product_id": "pdt_0Nd…",
    "plan": "pro",
    "label": "Pro yearly"
  }'

Test it

  1. Create a test-mode API key in Dodo, connect it, and link a test product.
  2. Buy it through a Dodo checkout with the test card 4242 4242 4242 4242, expiry 06/32 and CVV 123.
  3. Open Licenses. The new license is there, marked as test, with its order page.
  4. In Dodo, open Developer, then Webhooks, and Clavem's endpoint. Recent deliveries should be 200.
  5. Refund the payment in full. The license becomes disabled.

Dodo has no test clock. To see a subscription renew without waiting, set its next_billing_date a minute ahead with PATCH /subscriptions/{id} in Dodo's API. You do not need Dodo's CLI (dodo wh listen) for any of this: Clavem's webhook is registered in your test business and receives its events directly.

Disconnecting and troubleshooting

Disconnecting deletes Clavem's webhook in that business and forgets the key. The Dodo products linked on that business 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 businesses are not affected. If Dodo could not delete the webhook, Clavem says so: remove it in Dodo under Developer, Webhooks. You can then delete the key in Dodo.

Refunds and subscription events follow the business an order came through. Orders of a disconnected business keep their licenses; connect it again and its later refunds and subscription events reach those orders again.

SymptomLikely cause
Dodo Payments did not accept this keyThe key was copied incompletely or has been deleted, or it belongs to the other mode: an older key without a prefix needs the mode it was made in.
This is a Dodo test mode key, but you chose live modeThe key's prefix and the mode you chose disagree. A key with a prefix needs no mode.
This key is missing a permissionThe key lacks one of the permissions named in the message. Create a key with every permission listed above and paste it.
Clavem could not register its webhook at Dodo PaymentsDodo refused to create the webhook, or could not be reached. The message gives Dodo's reason. A key without Webhooks (write) gets the missing-permission message above instead.
You can connect up to 25 payment accountsDisconnect one you no longer sell through.
Dodo Payments no longer accepts Clavem's API key for your businessThe key was deleted or changed in Dodo. Payments keep issuing licenses, but linking, renewals and imports need a working key: Settings marks the business Reconnect, and the API answers 409 with payment_reconnect_needed. Paste a new key for the same business; your product links are kept.
Dodo Payments is asking Clavem to slow downDodo's rate limit. Wait the seconds Dodo named and try again. The API answers 429 with provider_rate_limited and Retry-After.
A payment made no licenseThe Dodo product is not linked, or is linked on another business than the one the payment was made in, or the Clavem product is archived (see the unmapped entry in your Activity), or the payment had no email address (Sale skipped).
Buyers got two keysThe Dodo product still has a License Key entitlement. Remove it in Dodo.
No two-keys warning, though Dodo hands out keysThe key lacks Entitlements (read), so Clavem cannot see the entitlement. Connect again with a key that has it.
Payment event Clavem could not readDodo sent something Clavem does not understand. Check the payment in Dodo, issue the license by hand if needed, and tell us.
The renew button failsThe renewal product is no longer on sale in Dodo, or the key lacks Checkout sessions (write). The Activity names what Dodo said. Connect the business again with a key that has it.
Deliveries fail with 400 in DodoThe webhook's signing secret no longer matches, for example after the secret was rotated in Dodo. Paste the key again: Clavem registers a new webhook and keeps your product links.