License keys
Issue license keys with every purchase, let buyers activate them in your extension, limit devices with seats, and validate keys from your own server.
License keys give buyers a second way to unlock a purchase: instead of restoring with their email, they paste a key into your extension. Use them for team purchases, machines without email, or when you want to cap how many devices one purchase can use.
Enable license keys
-
Open Sell → Products and edit the product.
-
Turn on License keys and choose the options:
- Seat limit: how many installs can be activated at once. Default
3; choose Unlimited for no cap. - Duration: leave empty for keys that never expire, or set a number of days. For one-time prices the key and the purchase expire that many days after payment.
- Seat limit: how many installs can be activated at once. Default
-
Save. New purchases of any price on this product now get a key. Existing orders don’t receive keys retroactively; issue one manually if needed.
The product setting is stored as license: { "enabled": true, "seatLimit": 3, "durationDays": null }. bill.getPlans() returns license: { enabled, seatLimit } on each plan, so your paywall can say “Use on up to 3 devices”.
Activate a key in your extension
<!-- options.html -->
<form id="license-form">
<label for="license-key">License key</label>
<input id="license-key" placeholder="XXXX-XXXX-XXXX-XXXX" autocomplete="off" spellcheck="false" />
<button type="submit">Activate</button>
</form>
<p id="license-message" role="status"></p>
<script type="module" src="options.js"></script>
// options.js
import { bill } from './bill'
const form = document.getElementById('license-form')
const input = document.getElementById('license-key')
const message = document.getElementById('license-message')
form.addEventListener('submit', async (event) => {
event.preventDefault()
try {
await bill.activateLicense(input.value.trim().toUpperCase(), 'Work laptop')
message.textContent = 'License activated.'
} catch (err) {
message.textContent = err.code === 'seat_limit_reached'
? `This key is already used on ${err.details.seatsUsed} of ${err.details.seatLimit} devices. Remove a device in the customer portal, then try again.`
: err.message
}
})
The shared bill client is set up in the Quick start. The Paywall UI already includes a license key field for products with keys enabled.
bill.activateLicense(key, label?) attaches the key to the current install and resolves with the updated UserState. The optional label is a device name shown to the buyer in the portal and to you in the dashboard. After a successful activation user.paid is true, user.plan.type is 'license', user.entitlements contains the product’s entitlement key, and license.activated is emitted.
Activation fails with an ExtensionBillError. Branch on its code:
| Code | Status | Meaning |
|---|---|---|
license_not_found | 404 | No key with that value exists in this environment. |
license_revoked | 409 | The key was revoked (refund, chargeback or by you). |
license_expired | 409 | The key’s expiresAt is in the past. |
seat_limit_reached | 409 | All seats are in use. details is { seatLimit, seatsUsed }. |
License fields on the user
user.license is null unless a key is activated on this install:
| Field | Type | Meaning |
|---|---|---|
last4 | string | Last four characters of the key. |
status | string | active, revoked or expired. |
seatLimit | number | null | Maximum activations; null means unlimited. |
seatsUsed | number | Current activations, including this one. |
expiresAt | string | null | ISO expiry, or null for no expiry. |
Deactivate
bill.deactivateLicense() removes the activation from the current install, frees the seat, emits license.deactivated, and resolves with the updated UserState. Give users a “Remove from this device” button so they can move their key to a new computer without contacting you.
How buyers get a key
Keys look like 7KQ2-M9XD-4RTB-H8VE: four groups of four characters from an alphabet without ambiguous characters (no I, L, O or U), so they’re easy to read aloud and retype.
When a purchase of a license-enabled product is paid:
- The key is shown once on the hosted checkout success page, with a copy button.
- The key is emailed to the buyer when Settings → Emails → License keys is on (
emails.licenseKeys, on by default). - The
license.createdevent is sent to your webhooks. - The buyer can reveal it again later in the customer portal.
ExtensionBill stores the key, but the dashboard and API only show its last four characters (last4) after issuance. For a subscription, the key stays valid while the subscription grants access. The install that completed the checkout gets access straight away and doesn’t need to activate the key; keys are for the buyer’s other devices and anyone they share the purchase with.
Seats and devices
Each install that activates a key uses one seat. Activating the same key again on the same install doesn’t use another seat. When all seats are taken, a new activation fails with seat_limit_reached until a seat is freed by:
- the extension calling
bill.deactivateLicense()on a device, - the buyer clicking Remove device in the customer portal, or
- you removing the activation in the dashboard.
Uninstalling the extension does not free a seat automatically, because the activation belongs to the key. Tell buyers to remove old devices from the portal.
Manage keys in the dashboard
Open Customers → Licenses to search keys by customer email or last four characters and filter by status. On a license you can:
- Revoke: the key stops working everywhere and
license.revokedis emitted. Installs that activated it lose access on their next refresh. - Reinstate: a revoked key becomes active again.
- Change seats or expiry: raise or lower
seatLimit, or set or clearexpiresAt. Lowering the limit below the current activations keeps existing devices but blocks new activations until enough are removed. - Remove an activation: frees one seat, the same as the buyer clicking Remove device.
Every change is recorded in the audit log.
A full refund revokes the key along with the purchase’s access. On a partial refund you choose whether the buyer keeps access. A reversed payment (chargeback lost) also revokes it. See Refunds & disputes.
Issue a key manually
Use Customers → Licenses → Issue license for comped copies, giveaways, bulk deals or orders made before you enabled keys. Enter the customer email, product, and optionally a seat limit and expiry date. The key is shown once in a dialog; copy it before closing. The customer record is created if it doesn’t exist yet, and license.created is emitted.
Validate a key on your server
If your extension talks to your own backend, validate keys there with a secret API key (Developers → API keys). Never put sk_ keys in the extension.
curl https://api.extensionbill.com/v1/licenses/7KQ2-M9XD-4RTB-H8VE/validate \
-H "Authorization: Bearer sk_test_…"
{
"valid": true,
"status": "active",
"product": { "id": "66f1c2a9e4b0a1d2c3b4a5f6", "name": "Pro", "entitlementKey": "pro" },
"seatLimit": 3,
"seatsUsed": 2,
"expiresAt": null
}
valid is true only when the key exists in the key’s environment and its status is active. Sandbox keys only validate with sk_test_ keys, and live keys with sk_live_. See the Server API reference.
Events
| Event | Sent when |
|---|---|
license.created | A key is issued by a purchase or manually. |
license.activated | An install activates a key. |
license.deactivated | An activation is removed by the extension, the buyer or you. |
license.revoked | A key is revoked by you, a full refund or a reversal. |
Payloads and signature verification are in Webhooks.
Customize
Show the active key and a remove button
Add this to the activation snippet above, with a #license-active block holding a #license-summary paragraph and a “Remove from this device” button:
// options.js (additions)
const active = document.getElementById('license-active')
const summary = document.getElementById('license-summary')
function render(user) {
const { license } = user
form.hidden = Boolean(license)
active.hidden = !license
if (!license) return
const seats = license.seatLimit === null
? `${license.seatsUsed} devices`
: `${license.seatsUsed} of ${license.seatLimit} devices`
const expiry = license.expiresAt ? `, expires ${new Date(license.expiresAt).toLocaleDateString()}` : ''
summary.textContent = `Key ending in ${license.last4} (${license.status}), used on ${seats}${expiry}.`
}
document.getElementById('license-deactivate').addEventListener('click', async () => {
try {
await bill.deactivateLicense()
message.textContent = 'License removed from this device.'
} catch {
message.textContent = 'Could not remove the license. Try again.'
}
})
bill.onChange(render)
render(await bill.getUser())
Friendlier errors and device labels
- Map each code in the error table to your own message, for example
license_not_found: “That key was not found. Check it for typos.” Fall back to a “check your connection” message for anything else. - Pass a meaningful device label, for example
navigator.userAgentData?.platform ?? navigator.platform, so buyers recognize devices in the portal.