feat(stripe): lifecycle emails: abandoned-checkout follow-up and customer trial-ending email (row 6 of app#2044)
Implements row 6 of recoupable/app#2044 (abandoned-checkout follow-up only). No docs change: nothing here is a public endpoint; the send is a webhook side effect.
What ships
| Event | Before | Now |
|---|---|---|
checkout.session.expired (subscription mode) | not handled | processCheckoutSessionExpired starts abandonedCheckoutWorkflow (Vercel Workflow): sleep(24h) then sendAbandonedCheckoutEmail. Plain-text founder note ("Want a hand setting up your first report?") from FOUNDER_FROM_EMAIL (Patrick from Recoup <sweetman@recoupable.dev>) with replyTo sweetmantech@gmail.com. Suppressed when the email already holds an active/trialing subscription (hasActiveSubscriptionForEmail), idempotent per session id via the email_send_log marker {"type":"abandoned_checkout_email","session_id":...}. Payment-mode (top-up) sessions and sessions without an email are ignored. |
customer.subscription.trial_will_end | Telegram sales note only | Unchanged — Telegram sales note only. Customer trial-ending email removed (decision 2026-08-30: cancel-forward notice invites churn; Stripe receipt covers conversion). |
Assumptions (from the app#2044 contract)
- 24h delay is a constant (
ABANDONED_CHECKOUT_EMAIL_DELAY_MS). - Starter and Pro are the only subscription plans;
metadata.planon the session names it (defaults to Pro when absent).
Action for Sweets before merge
checkout.session.expired is already on the live webhook endpoint we_1TWH8F00JObOnOb5jvCF6ido. No new env vars.
Tests
Red→green for buildAbandonedCheckoutEmail (plain text), sendAbandonedCheckoutEmail (from + replyTo), hasActiveSubscriptionForEmail, abandonedCheckoutWorkflow, processCheckoutSessionExpired, plus processSubscriptionTrialWillEnd (Telegram only) and webhook handler suites.
Preview verification posted in comments.
Summary by cubic
Ships row 6 of recoupable/app#2044: checkout.session.expired now sends a plain-text founder follow-up 24 hours after an abandoned subscription checkout, asking what outcome they wanted rather than which plan they started. customer.subscription.trial_will_end stays Telegram-only since a cancel-forward notice invites churn.
What changed
checkout.session.expiredin subscription mode with an email lowercases it and starts a Vercel Workflow that sleeps 24h before sending; payment-mode sessions and sessions without an email are ignored.- The plain-text email comes from
FOUNDER_FROM_EMAILwith a Gmail reply-to, names the abandoned plan (defaults to Pro), and links to LinkedIn and recoupable.dev. - The send is idempotent per session via an
email_send_logmarker plus a Resend idempotency key, and is skipped when the email already has an active, trialing, or past_due subscription. - A case-insensitive account lookup links the log row when an account exists; the workflow run id is logged with the session id.
Migration
- Add
checkout.session.expiredto the live Stripe webhook endpoint (Developers > Webhooks) or the abandoned-checkout path never fires in production.
Summary by CodeRabbit
-
New Features
- Added follow-up emails for abandoned subscription checkouts after a 24-hour delay.
- Added trial-ending emails summarizing usage, pricing, cancellation details, and billing access.
-
Improvements
- Added safeguards to prevent duplicate messages and avoid contacting customers who have already subscribed.
- Checkout expiration events now trigger the appropriate follow-up automatically.
- Trial-ending notifications continue alongside existing sales alerts.
- Improved lifecycle email tracking and usage calculations for more accurate messaging.