diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py index 801ec6a8ab..1ea8d82abc 100644 --- a/corporate/lib/stripe.py +++ b/corporate/lib/stripe.py @@ -671,7 +671,7 @@ class SponsorshipRequestSessionSpecificContext(TypedDict): class UpgradePageContext(TypedDict): customer_name: str - email: str + stripe_email: str exempt_from_license_number_check: bool free_trial_end_date: str | None is_demo_organization: bool @@ -2728,9 +2728,17 @@ class BillingSession(ABC): ) flat_discount, flat_discounted_months = self.get_flat_discount_info(customer) + + # Invoice is sent to stripe email. + stripe_email = customer_specific_context["email"] + if customer is not None and customer.stripe_customer_id is not None: + stripe_customer = stripe_get_customer(customer.stripe_customer_id) + if type(stripe_customer.email) is str: + stripe_email = stripe_customer.email + context: UpgradePageContext = { "customer_name": customer_specific_context["customer_name"], - "email": customer_specific_context["email"], + "stripe_email": stripe_email, "exempt_from_license_number_check": exempt_from_license_number_check, "free_trial_end_date": free_trial_end_date, "is_demo_organization": customer_specific_context["is_demo_organization"], diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.py index 3dcb1a7ae6..01bc19f217 100644 --- a/corporate/tests/test_stripe.py +++ b/corporate/tests/test_stripe.py @@ -2798,14 +2798,23 @@ class StripeTest(StripeTestCase): self.assertEqual(response.status_code, 302) self.assertEqual(response["Location"], "http://zulip.testserver/sponsorship") + stripe_customer_id = "cus_123" # Avoid contacting stripe as we only want to check redirects here. - with patch( - "corporate.lib.stripe.customer_has_credit_card_as_default_payment_method", - return_value=False, + with ( + patch( + "corporate.lib.stripe.customer_has_credit_card_as_default_payment_method", + return_value=False, + ), + patch( + "stripe.Customer.retrieve", + return_value=Mock(id=stripe_customer_id, email="test@zulip.com"), + ), ): user.realm.plan_type = Realm.PLAN_TYPE_LIMITED user.realm.save() - customer = Customer.objects.create(realm=user.realm, stripe_customer_id="cus_123") + customer = Customer.objects.create( + realm=user.realm, stripe_customer_id=stripe_customer_id + ) response = self.client_get("/upgrade/") self.assertEqual(response.status_code, 200) diff --git a/templates/corporate/billing/upgrade.html b/templates/corporate/billing/upgrade.html index 9010438caf..573a1e9b92 100644 --- a/templates/corporate/billing/upgrade.html +++ b/templates/corporate/billing/upgrade.html @@ -42,7 +42,7 @@ {% if is_free_trial_invoice_expired_notice %} Your free trial of {{ free_trial_invoice_expired_notice_page_plan_name }} has expired. An invoice - for ${{ scheduled_upgrade_invoice_amount_due }} has been sent to {{email}}. + for ${{ scheduled_upgrade_invoice_amount_due }} has been sent to {{ stripe_email }}. To reactivate your {{ free_trial_invoice_expired_notice_page_plan_name }} plan, please pay the amount due. Once the invoice has been paid, reload this page to see billing details. {% else %} @@ -53,7 +53,7 @@ {% if scheduled_upgrade_invoice_amount_due %} for ${{ scheduled_upgrade_invoice_amount_due }} {% endif %} - has been sent to {{email}}. + has been sent to {{ stripe_email }}. To complete the plan upgrade process, please pay the amount due. Once the invoice has been paid, reload this page to see billing details. {% endif %} @@ -75,7 +75,7 @@ {% if page_params.free_trial_days %}