Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 31, 2025

Implements automated email reminders sent 7 days before yearly subscriptions renew, configurable per-organization.

Changes

Database Schema

  • Added subscription_renewal_reminder boolean to OrganizationCustomerEmailSettings (defaults to false)
  • Added renewal_reminder_sent_at timestamp to Subscription model to prevent duplicate sends

Backend Service

  • SubscriptionService.send_renewal_reminders() queries subscriptions with current_period_end 7 days out, eagerly loading product/organization via joins to avoid N+1
  • SubscriptionService.send_renewal_reminder_email() sends reminder using existing customer email infrastructure
  • Scheduled task runs daily at 9 AM UTC via @actor(cron_trigger=CronTrigger(hour=9, minute=0))
  • Only processes Polar-managed subscriptions (excludes stripe_subscription_id != null)
  • Only processes yearly intervals (filters on recurring_interval == year)

Frontend

  • Added "Subscription renewal reminder" toggle to organization customer email settings
  • React email template subscription_renewal_reminder.tsx with customer portal link

Example Query

statement = (
    repository.get_base_statement()
    .join(Product, Subscription.product_id == Product.id)
    .join(Organization, Product.organization_id == Organization.id)
    .where(
        Subscription.active.is_(True),
        Subscription.recurring_interval == SubscriptionRecurringInterval.year,
        Subscription.current_period_end >= reminder_date,
        Subscription.current_period_end < reminder_date + timedelta(days=1),
        Subscription.renewal_reminder_sent_at.is_(None),
        Subscription.stripe_subscription_id.is_(None),
    )
    .options(
        contains_eager(Subscription.product).contains_eager(Product.organization),
        selectinload(Subscription.customer),
    )
)

Testing

Comprehensive test coverage in test_renewal_reminders.py validates:

  • Reminder sent for eligible yearly subscriptions
  • Organization opt-in respected
  • Monthly subscriptions excluded
  • Duplicate prevention via renewal_reminder_sent_at
  • Stripe-managed subscriptions excluded
Original prompt

This section details on the original issue you should resolve

<issue_title>Send reminders before subscription renewals</issue_title>
<issue_description>### Feature request

Is your feature request related to a problem?

Customers with a yearly subscription want a reminder message before their subscriptions renews. Help me configure that one.

Describe the solution you'd like

I would like to send a reminder to all users on the yearly subscription. The reminder should be sent 7 days before renewal and it's an opt-in feature for the organizations.

</issue_description>

<agent_instructions>Act as a Staff Engineer. Properly plan this and then implement the right solution.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@vercel
Copy link

vercel bot commented Oct 31, 2025

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

2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
polar Ignored Ignored Preview Oct 31, 2025 3:56pm
polar-sandbox Ignored Ignored Preview Oct 31, 2025 3:56pm

Copilot AI and others added 4 commits October 31, 2025 15:34
Co-authored-by: psincraian <17912624+psincraian@users.noreply.github.com>
Co-authored-by: psincraian <17912624+psincraian@users.noreply.github.com>
Co-authored-by: psincraian <17912624+psincraian@users.noreply.github.com>
Co-authored-by: psincraian <17912624+psincraian@users.noreply.github.com>
Copilot AI changed the title [WIP] Add reminders for yearly subscription renewals Add subscription renewal reminders for yearly subscriptions Oct 31, 2025
Copilot AI requested a review from psincraian October 31, 2025 16:04
Copilot finished work on behalf of psincraian October 31, 2025 16:04
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.

Send reminders before subscription renewals

2 participants