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

Commit e65453a

Browse files
committed
get ready to test on stage
1 parent d13cceb commit e65453a

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

billing/views.py

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,40 @@ def invoice_payment_failed(self, invoice: stripe.Invoice) -> None:
104104
payment_intent = stripe.PaymentIntent.retrieve(
105105
invoice["payment_intent"], expand=["payment_method"]
106106
)
107-
card = (
108-
payment_intent.payment_method.card
109-
if payment_intent.payment_method
110-
and not isinstance(payment_intent.payment_method, str)
111-
else None
112-
)
107+
113108
template_vars = {
114109
"amount": invoice.total / 100,
115-
"card_type": card.brand if card else None,
116-
"last_four": card.last4 if card else None,
117110
"cta_link": invoice.hosted_invoice_url,
118111
"date": datetime.now().strftime("%B %-d, %Y"),
119112
}
120113

114+
if payment_intent.payment_method and not isinstance(
115+
payment_intent.payment_method, str
116+
):
117+
payment_method = payment_intent.payment_method
118+
payment_method_type = payment_method.type
119+
120+
if payment_method_type == "card":
121+
card = payment_method.card
122+
template_vars.update(
123+
{
124+
"is_credit_card": True,
125+
"is_bank_account": False,
126+
"card_type": card.brand if card else None,
127+
"last_four": card.last4 if card else None,
128+
}
129+
)
130+
elif payment_method_type == "us_bank_account":
131+
bank = payment_method.us_bank_account
132+
template_vars.update(
133+
{
134+
"is_credit_card": False,
135+
"is_bank_account": True,
136+
"bank_name": bank.get("bank_name") if bank else None,
137+
"bank_last_four": bank.get("last4") if bank else None,
138+
}
139+
)
140+
121141
for admin in admins:
122142
if admin.email:
123143
task_service.send_email(
@@ -130,10 +150,10 @@ def invoice_payment_failed(self, invoice: stripe.Invoice) -> None:
130150

131151
# temporary just making sure these look okay in the real world
132152
task_service.send_email(
133-
to_addr="spencer.murray@sentry.io",
153+
to_addr="ajay.singh@sentry.io",
134154
subject="Your Codecov payment failed",
135155
template_name="failed-payment",
136-
name="spalmurray-codecov",
156+
name="ajay-singh-codecov",
137157
**template_vars,
138158
)
139159

0 commit comments

Comments
 (0)