Stripe has no license keys. To deliver one for every sale, something has to listen for Stripe's checkout.session.completed event, create a key, and send it to the buyer. You can connect a licensing service that does this, or write the webhook yourself. Both are below, including the part most tutorials leave out: refunds, renewals and events that arrive twice.
What has to happen
- A customer pays through a Payment Link or Checkout.
- Stripe calls your webhook.
- The call is verified, so nobody can fake a sale.
- A key is created for the right product and emailed.
- Later, a renewal extends it, and a refund revokes it.
- Your app checks the key when it starts.
Option A: connect it, no code
In Licers, open Store & Portal, add a Stripe connection and copy its endpoint URL. In Stripe, go to Developers → Webhooks, add that URL, and select:
checkout.session.completedcheckout.session.async_payment_succeededinvoice.paidcustomer.subscription.deletedcharge.refunded
Copy the endpoint's signing secret (whsec_…) into Licers and add a rule: which product the key is for, how many devices, when it expires, and any entitlements. The rule is matched by the Payment Link's id. No Stripe secret key is needed.
If you create Checkout Sessions in code, name the product in the metadata and use the same word in the rule:
const session = await stripe.checkout.sessions.create({
mode: 'payment',
line_items: [{ price: 'price_123', quantity: 1 }],
success_url: 'https://example.com/thanks',
metadata: { licers_product: 'myapp-pro' }, // the rule matches this
});
The Stripe page has the details.
Option B: write the webhook
This is a complete endpoint with Express. It verifies the event, waits for the money, creates a key through the API and has it emailed to the buyer.
import express from 'express';
import Stripe from 'stripe';
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
const app = express();
const done = new Set(); // use your database: this is lost on a restart
async function createKey(email, name) {
const res = await fetch('https://licers.com/api/manage/licenses', {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.LICERS_API_KEY}`, 'Content-Type': 'application/json' },
body: JSON.stringify({
product_id: process.env.LICERS_PRODUCT_ID,
max_hwids: 2,
customer_email: email,
customer_name: name,
email_customer: true, // Licers emails the key
}),
});
if (!res.ok) throw new Error(`Licers answered ${res.status}`);
}
// Stripe signs the raw bytes, so this route must not use express.json().
app.post('/stripe', express.raw({ type: 'application/json' }), async (req, res) => {
let event;
try {
event = stripe.webhooks.constructEvent(req.body, req.headers['stripe-signature'], process.env.STRIPE_WEBHOOK_SECRET);
} catch {
return res.status(400).send('Bad signature');
}
const paid = event.type === 'checkout.session.async_payment_succeeded'
|| (event.type === 'checkout.session.completed' && event.data.object.payment_status !== 'unpaid');
const session = event.data.object;
if (paid && !done.has(session.id)) {
try {
done.add(session.id);
await createKey(session.customer_details.email, session.customer_details.name);
} catch (err) {
done.delete(session.id);
console.error(err);
return res.status(500).send('Try again'); // Stripe will retry
}
}
res.send('ok');
});
app.listen(3000);
The API key comes from API & Webhooks in the dashboard. Keep it on your server. Your app only ever needs the public key.
The edge cases
- The same event arrives twice. Stripe retries until you answer with a 2xx status, and can repeat a delivery anyway. Remember the session id in a database, or a buyer gets two keys.
- Paid later. With bank debits and similar methods,
checkout.session.completedcan arrive withpayment_status: "unpaid". Wait forcheckout.session.async_payment_succeeded. - Raw body. If any JSON parser touches the request first, the signature never matches.
- Renewals. For subscriptions,
invoice.paidis the moment to extend the key to the end of the paid period, plus a few days of grace for a retried card. - Cancelled.
customer.subscription.deletedmeans it has ended. Until then, the customer paid for the time that is left. - Refunds.
charge.refundedalso fires for a partial refund. Revoke only when the charge'srefundedistrue. - Lost emails. Somebody's key will land in spam. Let customers look up their keys without writing to you.
Option A handles all of these, which is the main reason to use it.
Test it before you sell
Use Stripe's test mode with its own webhook endpoint and signing secret. Create a test Payment Link, pay with the card 4242 4242 4242 4242, and check that the key arrives. Then refund it and check that the key is revoked. Use a real inbox of your own.
Check the key in your app
Selling the key is half of it. Your app still has to ask whether it is valid, and verify that the answer is signed. There are SDKs for Python, Node.js, C#, Unity, Android, Rust, Go and C++.
Frequently asked questions
Can Stripe generate license keys?
No. Stripe handles the payment. A webhook, a connected service or an automation tool has to create the key and deliver it.
Do I need a server to deliver license keys with Stripe?
Not with a connected service, which receives the webhook for you. If you write your own webhook you need somewhere to run it, such as a small server or a serverless function.
How do I revoke a license key when a payment is refunded?
Listen for charge.refunded, check that the charge's refunded field is true, and revoke the key that belongs to that payment. A partial refund should normally leave the key working.
Does this work with Stripe subscriptions?
Yes. Create the key at checkout, extend it on every invoice.paid, and let it expire when the subscription ends.