I added Stripe payments to several of my AI products in 2026: credit packs, monthly and yearly plans, and one-time purchases. The ContentFast build alone took about 30 pull requests in July 2026, and Every Mood Studio taught me more between February and September. Almost every mistake was silent. Nothing crashed. A payment went through, and the product either did not notice or gave too much.
Below are the mistakes behind the rules I use now, from ContentFast and Every Mood Studio, with what caused each one and how it was fixed. Lovable wrote my first Stripe integration, and the mistakes came from code both Lovable and Claude Code wrote and from my own first specs. So this is also a checklist for anyone whose AI writes their billing.
The five rules that fixed most of it
Most of my Stripe problems came from credits moving at the wrong moment. Five rules fixed most of them:
- 1The app in the browser never grants credits or plans. Only server code does
- 2Subscription credits are granted only when an invoice is paid (
invoice.paid), for a new subscription, a renewal or an upgrade, and one-time packs only once per recorded checkout session - 3Every credit change is one database step that locks the account row and records what caused it
- 4Plan changes and cancellations are my own screens, not Stripe's portal switches
- 5A Sync with Stripe button reads the live subscription and repairs anything a webhook missed
The rest of this post is the mistakes behind these rules.
Payments that did not turn into credits
Four mistakes left, or could have left, a payment without credits. The first one hit a real customer.
The $200 pack that stayed empty
Right after I added payments to Every Mood Studio, someone bought a $200 credit pack. The payment went through, the credits never reached the account, and the customer could not reach me, because I had not set up any way to write to me. I sorted it out, and that day taught me more than any course.
- Rule: a way for customers to reach me goes live before the first payment, and every purchase is tested end to end in live mode
A Stripe API version that moved a field
New Stripe accounts use the newest API version. In version 2025-03-31.basil, Stripe removed the subscription field from the invoice and moved it to invoice.parent.subscription_details.subscription. My webhook read the old field, got nothing and stopped: the plan updated and no credits were granted, with no error anywhere.
- Fix: read the subscription id from both places
- Also moved:
current_period_endwent from the subscription to its items, so read both - Source: the Stripe changelog for 2025-03-31.basil (opens in a new tab), checked November 2026
An AI-written webhook with two identical cases
In July 2026, a one-time purchase in ContentFast went through and granted nothing. The generated webhook had two case "checkout.session.completed" labels in one switch. JavaScript only ever runs the first, so the second, the one for one-time purchases, could never run.
- Fix: one case, with a branch inside for a payment or a subscription
- Rule: a person reads every generated webhook switch
Credits charged for a job that failed
In ContentFast, credits were taken before a post was published, and when the delivery failed, the credits stayed spent.
- Fix: cheap checks run before charging, credits come back automatically when a job fails, and returned credits go into the bucket that never expires, because the next refill resets monthly credits
Credits granted twice or forever
In Every Mood Studio and ContentFast, other mistakes went the other way: credits given twice, given for nothing, or given back by accident.
The same payment granted twice
Stripe says it may deliver the same event more than once and does not promise the order. Two events for the same payment arrived together, both checked that the invoice was new, both passed, and the ledger showed two identical entries of 3,000 credits.
- Fix: claim the invoice in one database update that only succeeds once: set the last invoice id where it is different or not set yet
- Watch out: in SQL, comparing with NULL, a value that is not set yet, is never true, so without the "not set yet" part the very first payment never grants
- Source: Stripe webhooks documentation (opens in a new tab), checked November 2026
One-time purchases with no record to check
Subscriptions in Stripe come with invoices that can be checked off once. One-time purchases do not, so without a record of which checkout session was already granted, a repeated event could grant again.
- Fix: write every grant to a ledger with the checkout session id, and skip any session id that is already there
Credits for cancelling and un-cancelling
Every cancel and resume in the billing portal refilled the account. The refill was tied to customer.subscription.updated, which fires on any change, including a cancellation that is undone.
- Fix: subscription updates only sync the plan and its status, and credits move only on a paid invoice or a real change of price
A spend and a payment that undid each other
In September 2026 I found that the Every Mood Studio webhook read the credit balance, did the sum in code and wrote it back. A video spending credits in the same fraction of a second was undone, and a refund processed during a new purchase could erase the purchase.
- Fix: every credit change is one database function that locks the row and computes from the balances as they are
- Rule: if that function fails, the webhook answers with an error so Stripe sends the event again
Free credits collected again and again
People opened account after account in Every Mood Studio to collect the free credits. Now free credits come once per device.
Subscriptions that charged or ended wrongly
Six mistakes were about subscriptions: charges nobody confirmed, a plan that would have ended, and credits that came or went at the wrong time.
A plan button that charged in one click
Clicking Switch to upgrade charged the card at once, because my upgrade code asked Stripe to charge for the new plan immediately.
- Fix: a confirmation with the amount on the button, for example "Pay $39 and upgrade", with different words for an upgrade, charged now, and a downgrade, charged nothing until the period ends
A second subscription from a second checkout
An account that already had a plan went through checkout again and ended up with two active subscriptions and two charges.
- Fix: before creating a checkout, look up the existing subscription, and if it is active, send the customer to the billing portal instead
A free account charged $99
An account I had given free access was upgraded and charged the full $99. Its subscription had passed through a subscription schedule for a planned downgrade, and the schedule had dropped the discount.
- Rule: never give yourself or partners free access with discounts. A founder flag in the database gives the top plan and switches billing off for that account
A cancellation that a downgrade did not clear
An account was cancelled, then a downgrade was chosen. My database said the downgrade was scheduled, Stripe still had the cancellation, and the subscription would have ended at the end of the period.
- Fix: every plan change explicitly clears a pending cancellation, and "keep my plan" undoes both the schedule and the cancellation
Yearly plans refilled once a year
Credits were granted on each paid invoice, and a yearly plan pays once a year, so a yearly customer would get 1 refill instead of 12.
- Fix: a daily job refills monthly credits on each customer's own 30-day cycle, for monthly and yearly plans alike
Credits wiped the moment a subscription was cancelled
A subscription cancelled immediately from the Stripe dashboard deleted its credits the same second, although the period had been paid for.
- Fix: keep the credits until the end of the paid period and let an hourly job expire them, except after a failed or disputed payment
Setup mistakes before the first customer
Three mistakes can happen before anyone pays:
- Test mode is not live mode: products, prices, coupons, webhooks and the portal settings do not carry over, so every one is recreated in live mode and a full purchase is tested there
- Price ids live in settings, not in code: and the amounts in the Stripe dashboard are checked against the pricing page, because a typo can sell a $39 plan for $15
- The billing portal has its own switches: whether customers can switch plans and cancel there is set in the portal settings (Stripe documentation (opens in a new tab), checked November 2026). I keep plan switching off, so the portal never applies its own proration over my upgrade rules, and I build my own cancel screen
What the customer should see
Most billing questions from customers disappear when the screens answer them first. The habits I keep in my credit products:
- The cost on the button itself, like "5 credits" or "Pay $39 and upgrade"
- The date the cycle started and the date credits expire
- A readable history of credits, in plain words
- A banner for a scheduled change, with one click to undo it
- A Sync with Stripe button for the customer to press when something looks wrong
- When a card is declined, a clear line that the plan did not change and nothing was charged
Questions founders ask me about Stripe
Why are credits not added after a Stripe payment?
In my products, the causes I found were a field that Stripe API version 2025-03-31.basil moved and an AI-written webhook with two identical case labels. Check the event in Stripe's log first, then the field names in your webhook, then your switch statement.
Should credits be granted on checkout.session.completed or invoice.paid?
For subscriptions, I use checkout.session.completed only to link the Stripe customer and subscription to the account, and grant credits on invoice.paid. One-time purchases have no invoice chain, so they are granted on the checkout session, with its id written down so it is never granted twice.
Can Lovable set up Stripe payments for me?
Yes. Lovable wrote my first Stripe integration. Payments, webhooks and credits are the parts I now have a person read line by line before launch, whichever tool wrote them.
Taking payments in your app
If your app takes payments and you are not sure the webhooks are right, tell me what you sell, how people pay and what has gone wrong so far, in a short brief. The ways I work all start from that brief.
Published 27 November 2026. From my own products: ContentFast (July 2026) and Every Mood Studio (February to September 2026). Stripe behaviour checked in November 2026 against the Stripe changelog, webhooks and customer portal documentation.


