Skip to content

feat: checkout recovery email - #4854

Draft
richiemcilroy wants to merge 9 commits into
mainfrom
building/checkout-recovery-email-ecc81bc4
Draft

richiemcilroy wants to merge 9 commits into
mainfrom
building/checkout-recovery-email-ecc81bc4

Conversation

@richiemcilroy

@richiemcilroy richiemcilroy commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

When a Cap Pro checkout expires, Cap can now send one short follow-up email that links straight back to checkout with the same plan and seats.

What changes

  • The Stripe webhook handles checkout.session.expired. It sends only when the session belongs to an existing Cap account that is not on Pro (own subscription, Pro seat or license), has no newer checkout or purchase since, has not had this email in the last 30 days, and is subscribed to Cap emails. Guests without an account get nothing.
  • A send record per user makes repeat and concurrent deliveries send at most once. A failed send releases the record so Stripe's retry can try again.
  • The email comes from Richie, with an unsubscribe link and one-click unsubscribe headers. Unsubscribing goes through a signed link and updates the same consent Cap's other marketing emails use.
  • Checkouts opened from the email carry a checkoutSource tag on the Stripe session and in the checkout and purchase analytics events.

Rollout

  • Off by default. Set CHECKOUT_RECOVERY_EMAILS=true to enable.
  • The production Stripe webhook endpoint needs the checkout.session.expired event added.
  • Adds the checkout_recovery_emails table.

Testing

  • Unit tests for every send rule, duplicate and concurrent delivery, retry after a failed send, the rebuilt checkout link, the email copy and the unsubscribe token.

Confidence Score: 4/5RetriggerView in Greptile

The latest ordering fix looks sound, but the missing migration and the repository requirement for marketing copy still need to be addressed before merging.

Findings

  1. P1 Recovery table has no migration ▶
  2. P2 Marketing copy lives here ▶
Fix with agent prompt
### Issue 1
packages/database/schema.ts:176-180
`checkout_recovery_emails` has no generated migration, snapshot, or journal change. Enabling recovery on a database built from the committed migrations makes `lastSentAt` fail because the table does not exist. `AGENTS.md` requires these generated artifacts alongside every schema change. Run `bun run db:generate` and commit its output before merging.

### Issue 2
packages/database/emails/checkout-recovery.tsx:47-50
This adds marketing email copy to `packages/database/emails/`, but `AGENTS.md` says marketing and lifecycle copy belongs in the private marketing repository. This directory is reserved for transactional emails. Move the recovery copy to the required repository and keep only the necessary runtime connection here. This repository requirement must be satisfied before merging.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Adds an opt-in checkout recovery email with the buyer’s plan and seats, consent checks, signed unsubscribe links, and recovery attribution.

  • Eligible people get one email after a Cap Pro checkout expires.
  • Cap email links let people unsubscribe from marketing emails.
  • Recovery checkouts keep their source tag through purchase analytics.

Reviews (3) · Last reviewed commit: "fix: break ties between checkouts create..." · Reviewed by Greptile

@vercel

vercel Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
cap-status Skipped Skipped Dec 4, 2026 2:36pm UTC

@richiemcilroy

Copy link
Copy Markdown
Member Author

hey @greptileai, please re-review the PR

Comment on lines +176 to +180
export const checkoutRecoveryEmails = mysqlTable("checkout_recovery_emails", {
userId: nanoId("userId").notNull().primaryKey().$type<User.UserId>(),
checkoutSessionId: varchar("checkoutSessionId", { length: 255 }).notNull(),
sentAt: datetime("sentAt", { mode: "date" }).notNull(),
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Recovery table has no migration

checkout_recovery_emails has no generated migration, snapshot, or journal change. Enabling recovery on a database built from the committed migrations makes lastSentAt fail because the table does not exist. AGENTS.md requires these generated artifacts alongside every schema change. Run bun run db:generate and commit its output before merging.

Context Used: AGENTS.md (source)

Knowledge Base Used: Database schema and migrations

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/database/schema.ts
Line: 176-180

Comment:
**Recovery table has no migration**

`checkout_recovery_emails` has no generated migration, snapshot, or journal change. Enabling recovery on a database built from the committed migrations makes `lastSentAt` fail because the table does not exist. `AGENTS.md` requires these generated artifacts alongside every schema change. Run `bun run db:generate` and commit its output before merging.

**Context Used:** AGENTS.md ([source](https://github.com/capsoftware/cap/blob/main/AGENTS.md))

**Knowledge Base Used:** [Database schema and migrations](https://app.greptile.com/-/switch-tenant?tenant=cap&next=%2Fcustom-context%2Fknowledge-base%2Fcapsoftware%2Fcap%2F-%2Fdocs%2Fdatabase-schema-and-migrations.md)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Comment thread apps/web/lib/marketing-consent.ts Resolved
Comment thread apps/web/lib/checkout/recovery.ts Resolved
Comment on lines +47 to +50
<Text className="text-sm leading-6 text-black">
I saw you started upgrading to Cap Pro but didn't get to the end.
You picked {choice}, and the button below takes you straight back
to it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Marketing copy lives here

This adds marketing email copy to packages/database/emails/, but AGENTS.md says marketing and lifecycle copy belongs in the private marketing repository. This directory is reserved for transactional emails. Move the recovery copy to the required repository and keep only the necessary runtime connection here. This repository requirement must be satisfied before merging.

Context Used: AGENTS.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/database/emails/checkout-recovery.tsx
Line: 47-50

Comment:
**Marketing copy lives here**

This adds marketing email copy to `packages/database/emails/`, but `AGENTS.md` says marketing and lifecycle copy belongs in the private marketing repository. This directory is reserved for transactional emails. Move the recovery copy to the required repository and keep only the necessary runtime connection here. This repository requirement must be satisfied before merging.

**Context Used:** AGENTS.md ([source](https://github.com/capsoftware/cap/blob/main/AGENTS.md))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@vercel
vercel Bot temporarily deployed to Preview – cap-status December 4, 2026 14:33 Inactive
@richiemcilroy

Copy link
Copy Markdown
Member Author

hey @greptileai, please re-review the PR

Comment thread apps/web/lib/checkout/recovery.ts Resolved
@vercel
vercel Bot temporarily deployed to Preview – cap-status December 4, 2026 14:36 Inactive
@richiemcilroy

Copy link
Copy Markdown
Member Author

hey @greptileai, please re-review the PR

This branch was successfully deployed

1 active and 1 inactive deployments
Preview – cap-web — 28fd3d6c Deployed Dec 4, 2026 by vercel[bot]
Preview – cap-status — 28fd3d6c Deployed Dec 4, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant