Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
stripe: Change stripe email on the upgrade page if available.
Aman Agrawal4d8e6ba09439
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.pyindex 801ec6a8abb..1ea8d82abcf 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: strexempt_from_license_number_check: boolfree_trial_end_date: str | Noneis_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.pyindex 3dcb1a7ae63..01bc19f2175 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="[email protected]"),+ ),):user.realm.plan_type = Realm.PLAN_TYPE_LIMITEDuser.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.htmlindex 9010438cafd..573a1e9b922 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.<a href="{{ pay_by_invoice_payments_page }}" target="_blank" rel="noopener noreferrer">An invoice</a>- for ${{ scheduled_upgrade_invoice_amount_due }} has been sent to <b>{{email}}</b>.+ for ${{ scheduled_upgrade_invoice_amount_due }} has been sent to <b>{{ stripe_email }}</b>.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 <b>{{email}}</b>.+ has been sent to <b>{{ stripe_email }}</b>.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 %}</div>@@ -75,7 +75,7 @@{% if page_params.free_trial_days %}<div class="not-editable-realm-field">{% if page_params.setup_payment_by_invoice %}- An invoice will immediately be sent to <b>{{email}}</b>. To ensure continuous access to Zulip Basic,+ An invoice will immediately be sent to <b>{{ stripe_email }}</b>. To ensure continuous access to Zulip Basic,please pay your invoice before your free trial ends on {{ free_trial_end_date }}.{% else %}Add a credit card to start your <b>{{ page_params.free_trial_days }}-day free trial</b> of@@ -346,10 +346,10 @@<br />{% if page_params.free_trial_days %}<br />- Starting free trial will immediately send an invoice to <b>{{email}}</b>.+ Starting free trial will immediately send an invoice to <b>{{ stripe_email }}</b>.This is your last chance to update the billing information on your invoice.{% else %}- Your invoice will be sent to <b>{{email}}</b>.+ Your invoice will be sent to <b>{{ stripe_email }}</b>.{% endif %}</p></main>