Where Lemon Squeezy custom_data goes in Stripe
If your app passes checkout[custom][user_id] to Lemon Squeezy and reads meta.custom_data.user_id in a webhook, that lookup does not work on a Stripe event. Stripe has no meta.custom_data. You set client_reference_id or metadata yourself, on the object whose events you will read. A handler that is not updated can take a payment and fail to find which user paid.
Field map
| Lemon Squeezy | Stripe Checkout Session (API) | Stripe Payment Link (URL) |
|---|---|---|
checkout[custom][user_id] | client_reference_id or metadata[user_id] | client_reference_id |
checkout[email] | customer_email (or an existing customer, not both) | prefilled_email |
checkout[discount_code] | discounts (takes a coupon or promotion code ID) | prefilled_promo_code |
meta.custom_data in webhooks | data.object.metadata / data.object.client_reference_id | same, on checkout.session.completed |
Sources: Lemon Squeezy custom data and pre-filled fields; Stripe Checkout Session API and Payment Link URL parameters.
The renewal trap: Session metadata is not Subscription metadata
Lemon Squeezy includes your custom data on order, subscription and license key events. Stripe does not automatically copy metadata between related objects, apart from listed exceptions. Metadata on a Checkout Session shows up on checkout.session.completed, but not on the Subscription it creates. For subscriptions, set it in both places:
curl https://api.stripe.com/v1/checkout/sessions \
-u "$STRIPE_SECRET_KEY:" \
-d mode=subscription \
-d "line_items[0][price]={{PRICE_ID}}" \
-d "line_items[0][quantity]=1" \
-d "managed_payments[enabled]=true" \
-d client_reference_id=user_123 \
-d "metadata[user_id]=user_123" \
-d "subscription_data[metadata][user_id]=user_123" \
--data-urlencode "success_url=https://example.com/success"
Then read it from the right place in each handler:
| Stripe event | Where your ID is |
|---|---|
checkout.session.completed | data.object.metadata.user_id or data.object.client_reference_id |
customer.subscription.updated / .deleted | data.object.metadata.user_id |
invoice.paid / invoice.payment_failed | data.object.parent.subscription_details.metadata.user_id (path depends on your API version) |
For one-time purchases, if you also need the ID on the PaymentIntent, use payment_intent_data[metadata][user_id]. Check the payment status before granting access; delayed methods confirm later with checkout.session.async_payment_succeeded.
Payment Links: invalid IDs are dropped silently
https://buy.stripe.com/{{YOUR_LINK}}?client_reference_id=user_123&prefilled_email=jane%40example.com
client_reference_idaccepts letters, numbers, dashes and underscores, up to 200 characters. Stripe says invalid values are silently dropped and the page still works. An email address, or an ID such asorg:42, is not a valid value.- There is no URL equivalent of arbitrary
checkout[custom][...]fields. If you passed several values, store them in your database under one reference ID and pass that ID, or create Checkout Sessions on your server. - The ID arrives on
checkout.session.completed. For subscriptions, save the link between your user, the Stripe customer ID and the subscription ID at that moment, so later events can be matched. - Buyers can edit URL parameters. Do not treat the ID as proof of who someone is, and keep secrets out of it.
Replacing the checkout overlay (lemon.js)
Lemon Squeezy’s overlay opens from .lemonsqueezy-button links. Its comparison guide lists Stripe Checkout and Payment Links for Managed Payments, so plan to replace those buttons:
- Smallest change: point each button at a Payment Link. Buyers leave your page to pay.
- Per-user data: have your server create a Checkout Session and redirect to its
url. - Keep buyers on your site: use Stripe’s embedded Checkout page. It is not a drop-in overlay; you build the container and the server endpoint.
Remove lemon.js, the window.createLemonSqueezy() calls and any Checkout.Success handlers from the new purchase path. Grant access from verified webhooks, not from a browser event or a success-page visit.
Existing subscribers
Do not assume subscriptions moved by the Migration Toolkit carry your old custom_data as Stripe metadata. The subscription migration guide we read does not say that they do. Export your user-to-subscription mapping from your own database first, download the subscription mapping report from the Migration Hub, and add any missing metadata to the Stripe subscriptions after checking the matches. Keep Lemon Squeezy webhooks running for subscriptions that have not moved.
Test before switching
- Buy a one-time product and a subscription in a Stripe sandbox, through every button and link you ship.
- Confirm the user ID appears in each event your handler reads, including a renewal invoice and a cancellation.
- Try your longest and strangest real user ID in a Payment Link.
- Make your handler log and alert when the ID is missing instead of skipping the event.
Related
See 11 Migration Hub gotchas (including the webhook event table), the migration checklist, and fixes for unsupported parameters and missing product tax codes.
The paid Cutover Kit is a printable PDF with a migration schedule, link and subscriber worksheets, test scripts and customer notice templates.