Licers

← All articles

StripePaymentsLicensingNode.jsTutorial

How to Sell Software With Stripe and Deliver License Keys Automatically

Licers Team · 2026-11-24

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

  1. A customer pays through a Payment Link or Checkout.
  2. Stripe calls your webhook.
  3. The call is verified, so nobody can fake a sale.
  4. A key is created for the right product and emailed.
  5. Later, a renewal extends it, and a refund revokes it.
  6. 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:

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

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.

Related guides

How to License and Sell an Electron App

Electron apps ship as readable JavaScript, so where you put the license check matters. Complete main process code, what it stops, and what it does not.

How to Protect a Unity Game You Sell Outside Steam

Outside Steam there is no built-in DRM, so a paid download is one copy away from being free. Here is how to add license keys to a Unity game without annoying the people who paid.

How to Add License Keys to a C# Desktop App (WPF and WinForms)

A complete example for WPF and WinForms. Check the key at startup, ask for one when there is none, remember it, and let paying customers keep working when they are offline.

Protect your software with Licers

Signed validation, floating licenses, offline files, and more — free to start.

Get started free