Two products, one Stripe event, and the branch that must come first
Notifio sells two things. A lifetime licence for the monitoring and email alerts, and a one-time upgrade that unlocks auto-reply, where the app fills in and submits the listing's own contact form for you. Both are 20 pounds. Neither is a subscription. That means our entire Stripe integration listens for exactly one event: /** * Both products are one-time payments, so `checkout.session.completed`…
Notifio sells two products - a lifetime licence for monitoring and email alerts, and a one-time upgrade that unlocks auto-reply. Both products cost 20 pounds and are one-time payments, so the Stripe integration listens for only one event: checkout.session.completed. The discriminator between the two products is metadata, set at session creation, with `kind` indicating whether it's an upgrade or new licence purchase.
The licence branch was written first, assuming any completed session is a purchase of a new licence. However, this is incorrect for an upgrade, as the customer already has a licence and a token. The upgrade branch is written to handle this specific case, ensuring the customer only receives one activation code for the product they own.
The upgrade branch is placed before the licence branch to prevent issuing a second licence and activation email to customers who have already purchased it. The code also handles idempotency, ensuring that a Stripe webhook retry does not double-apply the upgrade. The upgrade is only available to customers who have an existing, active licence, and the code checks for this before starting the Stripe Checkout session.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.