upgrade: Make it possible to upgrade to a provided tier.

Main work is maintaining context during various redirects and
and passing the context to the final upgrade process.
This commit is contained in:
Aman Agrawal 2023-12-18 12:02:36 +00:00 committed by Tim Abbott
parent 1326619b77
commit d962814a30
619 changed files with 97 additions and 29 deletions

View File

@ -587,6 +587,7 @@ class UpgradePageParams(TypedDict):
monthly_price: int
seat_count: int
billing_base_url: str
tier: int
class UpgradePageSessionTypeSpecificContext(TypedDict):
@ -959,12 +960,18 @@ class BillingSession(ABC):
def create_card_update_session_for_upgrade(
self,
manual_license_management: bool,
tier: int,
) -> Dict[str, Any]:
metadata = self.get_metadata_for_stripe_update_card()
customer = self.update_or_create_stripe_customer()
cancel_url = f"{self.billing_session_url}/upgrade/"
if manual_license_management:
cancel_url = f"{self.billing_session_url}/upgrade/?manual_license_management=true"
# URL when user cancels the card update session.
base_cancel_url = f"{self.billing_session_url}/upgrade/"
params = {
"manual_license_management": str(manual_license_management).lower(),
"tier": str(tier),
}
cancel_url = f"{base_cancel_url}?{urlencode(params)}"
stripe_session = stripe.checkout.Session.create(
cancel_url=cancel_url,
@ -979,6 +986,7 @@ class BillingSession(ABC):
customer=customer,
type=Session.CARD_UPDATE_FROM_UPGRADE_PAGE,
is_manual_license_management_upgrade_session=manual_license_management,
tier=tier,
)
return {
"stripe_session_url": stripe_session.url,
@ -1914,6 +1922,7 @@ class BillingSession(ABC):
),
"seat_count": seat_count,
"billing_base_url": self.billing_base_url,
"tier": tier,
},
"using_min_licenses_for_plan": using_min_licenses_for_plan,
"min_licenses_for_plan": min_licenses_for_plan,

View File

@ -0,0 +1,17 @@
# Generated by Django 4.2.8 on 2023-12-18 09:39
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("corporate", "0028_zulipsponsorshiprequest_requested_plan"),
]
operations = [
migrations.AddField(
model_name="session",
name="tier",
field=models.SmallIntegerField(null=True),
),
]

View File

@ -119,6 +119,9 @@ class Session(models.Model):
# Did the user opt to manually manage licenses before clicking on update button?
is_manual_license_management_upgrade_session = models.BooleanField(default=False)
# CustomerPlan tier that the user is upgrading to.
tier = models.SmallIntegerField(null=True)
def get_status_as_string(self) -> str:
return {Session.CREATED: "created", Session.COMPLETED: "completed"}[self.status]
@ -136,6 +139,7 @@ class Session(models.Model):
session_dict[
"is_manual_license_management_upgrade_session"
] = self.is_manual_license_management_upgrade_session
session_dict["tier"] = self.tier
event = self.get_last_associated_event()
if event is not None:
session_dict["event_handler"] = event.get_event_handler_details_as_dict()

Some files were not shown because too many files have changed in this diff Show More