Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit 2f6de24

Browse files
committed
Re-enable failed payment emails
1 parent e0a8e09 commit 2f6de24

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

billing/helpers.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from django.conf import settings
2+
from django.db.models import QuerySet
23
from shared.plan.constants import ENTERPRISE_CLOUD_USER_PLAN_REPRESENTATIONS
34

45
from codecov_auth.models import Owner
@@ -8,3 +9,17 @@ def on_enterprise_plan(owner: Owner) -> bool:
89
return settings.IS_ENTERPRISE or (
910
owner.plan in ENTERPRISE_CLOUD_USER_PLAN_REPRESENTATIONS.keys()
1011
)
12+
13+
14+
def get_all_admins_for_owners(owners: QuerySet[Owner]):
15+
admin_ids = set()
16+
for owner in owners:
17+
if owner.admins:
18+
admin_ids.update(owner.admins)
19+
20+
# Add the owner's email as well - for user owners, admins is empty.
21+
if owner.email:
22+
admin_ids.add(owner.ownerid)
23+
24+
admins: QuerySet[Owner] = Owner.objects.filter(pk__in=admin_ids)
25+
return admins

billing/views.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from rest_framework.views import APIView
1313
from shared.plan.service import PlanService
1414

15+
from billing.helpers import get_all_admins_for_owners
1516
from codecov_auth.models import Owner
1617
from services.task.task import TaskService
1718

@@ -66,17 +67,7 @@ def invoice_payment_failed(self, invoice: stripe.Invoice) -> None:
6667
self._log_updated(list(owners))
6768

6869
# Send failed payment email to all owner admins
69-
70-
admin_ids = set()
71-
for owner in owners:
72-
if owner.admins:
73-
admin_ids.update(owner.admins)
74-
75-
# Add the owner's email as well - for user owners, admins is empty.
76-
if owner.email:
77-
admin_ids.add(owner.ownerid)
78-
79-
admins: QuerySet[Owner] = Owner.objects.filter(pk__in=admin_ids)
70+
admins = get_all_admins_for_owners(owners)
8071

8172
task_service = TaskService()
8273
card = (
@@ -102,6 +93,15 @@ def invoice_payment_failed(self, invoice: stripe.Invoice) -> None:
10293
**template_vars,
10394
)
10495

96+
# temporary just making sure these look okay in the real world
97+
task_service.send_email(
98+
to_addr="[email protected]",
99+
subject="Your Codecov payment failed",
100+
template_name="failed-payment",
101+
name="spalmurray-codecov",
102+
**template_vars,
103+
)
104+
105105
def customer_subscription_deleted(self, subscription: stripe.Subscription) -> None:
106106
log.info(
107107
"Customer Subscription Deleted - Setting free plan and deactivating repos for stripe customer",

services/task/task.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,6 @@ def send_email(
402402
from_addr: str | None = None,
403403
**kwargs,
404404
):
405-
# Disabling this while we fix HTML templates.
406-
return
407405
# Templates can be found in worker/templates
408406
self._create_signature(
409407
"app.tasks.send_email.SendEmail",

0 commit comments

Comments
 (0)