stripe: Change stripe email on the upgrade page if available.

This commit is contained in:
Aman Agrawal 2024-09-18 17:55:11 +00:00 committed by Tim Abbott
parent 9a4a07d933
commit 4d8e6ba094
3 changed files with 28 additions and 11 deletions

View File

@ -671,7 +671,7 @@ class SponsorshipRequestSessionSpecificContext(TypedDict):
class UpgradePageContext(TypedDict): class UpgradePageContext(TypedDict):
customer_name: str customer_name: str
email: str stripe_email: str
exempt_from_license_number_check: bool exempt_from_license_number_check: bool
free_trial_end_date: str | None free_trial_end_date: str | None
is_demo_organization: bool is_demo_organization: bool
@ -2728,9 +2728,17 @@ class BillingSession(ABC):
) )
flat_discount, flat_discounted_months = self.get_flat_discount_info(customer) 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 = { context: UpgradePageContext = {
"customer_name": customer_specific_context["customer_name"], "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, "exempt_from_license_number_check": exempt_from_license_number_check,
"free_trial_end_date": free_trial_end_date, "free_trial_end_date": free_trial_end_date,
"is_demo_organization": customer_specific_context["is_demo_organization"], "is_demo_organization": customer_specific_context["is_demo_organization"],

View File

@ -2798,14 +2798,23 @@ class StripeTest(StripeTestCase):
self.assertEqual(response.status_code, 302) self.assertEqual(response.status_code, 302)
self.assertEqual(response["Location"], "http://zulip.testserver/sponsorship") self.assertEqual(response["Location"], "http://zulip.testserver/sponsorship")
stripe_customer_id = "cus_123"
# Avoid contacting stripe as we only want to check redirects here. # Avoid contacting stripe as we only want to check redirects here.
with patch( with (
patch(
"corporate.lib.stripe.customer_has_credit_card_as_default_payment_method", "corporate.lib.stripe.customer_has_credit_card_as_default_payment_method",
return_value=False, 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.plan_type = Realm.PLAN_TYPE_LIMITED
user.realm.save() 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/") response = self.client_get("/upgrade/")
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)

View File

@ -42,7 +42,7 @@
{% if is_free_trial_invoice_expired_notice %} {% if is_free_trial_invoice_expired_notice %}
Your free trial of {{ free_trial_invoice_expired_notice_page_plan_name }} has expired. 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> <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. 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. Once the invoice has been paid, reload this page to see billing details.
{% else %} {% else %}
@ -53,7 +53,7 @@
{% if scheduled_upgrade_invoice_amount_due %} {% if scheduled_upgrade_invoice_amount_due %}
for ${{ scheduled_upgrade_invoice_amount_due }} for ${{ scheduled_upgrade_invoice_amount_due }}
{% endif %} {% 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. 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 %} {% endif %}
</div> </div>
@ -75,7 +75,7 @@
{% if page_params.free_trial_days %} {% if page_params.free_trial_days %}
<div class="not-editable-realm-field"> <div class="not-editable-realm-field">
{% if page_params.setup_payment_by_invoice %} {% 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 }}. please pay your invoice before your free trial ends on {{ free_trial_end_date }}.
{% else %} {% else %}
Add a credit card to start your <b>{{ page_params.free_trial_days }}-day free trial</b> of Add a credit card to start your <b>{{ page_params.free_trial_days }}-day free trial</b> of
@ -346,10 +346,10 @@
<br /> <br />
{% if page_params.free_trial_days %} {% if page_params.free_trial_days %}
<br /> <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. This is your last chance to update the billing information on your invoice.
{% else %} {% else %}
Your invoice will be sent to <b>{{email}}</b>. Your invoice will be sent to <b>{{ stripe_email }}</b>.
{% endif %} {% endif %}
</p> </p>
</main> </main>