mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	corporate: Pass plan_tier parameter to process_initial_upgrade.
Updates `process_initial_upgrade` to take a plan_tier parameter, so that information can be specific to the type of BillingSession. Note that ideally the plan tier would be passed as metadata to the stripe.checkout.Session, but in order to do so, we need to be able to update the generated stripe fixtures for tests. So for now, we set the plan tier directly in the stripe event handler code.
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							3e550364c6
						
					
				
				
					commit
					928cb7e09e
				
			@@ -746,7 +746,7 @@ class RealmBillingSession(BillingSession):
 | 
			
		||||
            plan_type = Realm.PLAN_TYPE_STANDARD_FREE
 | 
			
		||||
        elif tier == CustomerPlan.STANDARD:
 | 
			
		||||
            plan_type = Realm.PLAN_TYPE_STANDARD
 | 
			
		||||
        elif tier == CustomerPlan.PLUS:
 | 
			
		||||
        elif tier == CustomerPlan.PLUS:  # nocoverage # Plus plan doesn't use this code path yet.
 | 
			
		||||
            plan_type = Realm.PLAN_TYPE_PLUS
 | 
			
		||||
        else:
 | 
			
		||||
            raise AssertionError("Unexpected tier")
 | 
			
		||||
@@ -1059,6 +1059,7 @@ def do_deactivate_remote_server(remote_server: RemoteZulipServer) -> None:
 | 
			
		||||
@catch_stripe_errors
 | 
			
		||||
def process_initial_upgrade(
 | 
			
		||||
    user: UserProfile,
 | 
			
		||||
    plan_tier: int,
 | 
			
		||||
    licenses: int,
 | 
			
		||||
    automanage_licenses: bool,
 | 
			
		||||
    billing_schedule: int,
 | 
			
		||||
@@ -1075,7 +1076,7 @@ def process_initial_upgrade(
 | 
			
		||||
        period_end,
 | 
			
		||||
        price_per_license,
 | 
			
		||||
    ) = compute_plan_parameters(
 | 
			
		||||
        CustomerPlan.STANDARD,
 | 
			
		||||
        plan_tier,
 | 
			
		||||
        automanage_licenses,
 | 
			
		||||
        billing_schedule,
 | 
			
		||||
        customer.default_discount,
 | 
			
		||||
@@ -1099,7 +1100,7 @@ def process_initial_upgrade(
 | 
			
		||||
            "discount": customer.default_discount,
 | 
			
		||||
            "billing_cycle_anchor": billing_cycle_anchor,
 | 
			
		||||
            "billing_schedule": billing_schedule,
 | 
			
		||||
            "tier": CustomerPlan.STANDARD,
 | 
			
		||||
            "tier": plan_tier,
 | 
			
		||||
        }
 | 
			
		||||
        if free_trial:
 | 
			
		||||
            plan_params["status"] = CustomerPlan.FREE_TRIAL
 | 
			
		||||
@@ -1151,7 +1152,7 @@ def process_initial_upgrade(
 | 
			
		||||
        )
 | 
			
		||||
        stripe.Invoice.finalize_invoice(stripe_invoice)
 | 
			
		||||
 | 
			
		||||
    billing_session.do_change_plan_type(tier=CustomerPlan.STANDARD)
 | 
			
		||||
    billing_session.do_change_plan_type(tier=plan_tier)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def update_license_ledger_for_manual_plan(
 | 
			
		||||
 
 | 
			
		||||
@@ -12,7 +12,7 @@ from corporate.lib.stripe import (
 | 
			
		||||
    ensure_customer_does_not_have_active_plan,
 | 
			
		||||
    process_initial_upgrade,
 | 
			
		||||
)
 | 
			
		||||
from corporate.models import Event, PaymentIntent, Session
 | 
			
		||||
from corporate.models import CustomerPlan, Event, PaymentIntent, Session
 | 
			
		||||
from zerver.models import get_active_user_profile_by_id_in_realm
 | 
			
		||||
 | 
			
		||||
billing_logger = logging.getLogger("corporate.stripe")
 | 
			
		||||
@@ -102,6 +102,7 @@ def handle_checkout_session_completed_event(
 | 
			
		||||
        billing_session.update_or_create_stripe_customer(payment_method)
 | 
			
		||||
        process_initial_upgrade(
 | 
			
		||||
            user,
 | 
			
		||||
            CustomerPlan.STANDARD,
 | 
			
		||||
            int(stripe_session.metadata["licenses"]),
 | 
			
		||||
            stripe_session.metadata["license_management"] == "automatic",
 | 
			
		||||
            int(stripe_session.metadata["billing_schedule"]),
 | 
			
		||||
@@ -151,6 +152,7 @@ def handle_payment_intent_succeeded_event(
 | 
			
		||||
 | 
			
		||||
    process_initial_upgrade(
 | 
			
		||||
        user,
 | 
			
		||||
        CustomerPlan.STANDARD,
 | 
			
		||||
        int(metadata["licenses"]),
 | 
			
		||||
        metadata["license_management"] == "automatic",
 | 
			
		||||
        int(metadata["billing_schedule"]),
 | 
			
		||||
 
 | 
			
		||||
@@ -627,6 +627,7 @@ class StripeTestCase(ZulipTestCase):
 | 
			
		||||
        ) -> Any:
 | 
			
		||||
            return process_initial_upgrade(
 | 
			
		||||
                self.example_user("hamlet"),
 | 
			
		||||
                CustomerPlan.STANDARD,
 | 
			
		||||
                licenses,
 | 
			
		||||
                automanage_licenses,
 | 
			
		||||
                billing_schedule,
 | 
			
		||||
 
 | 
			
		||||
@@ -142,6 +142,7 @@ def upgrade(
 | 
			
		||||
        else:
 | 
			
		||||
            process_initial_upgrade(
 | 
			
		||||
                user,
 | 
			
		||||
                CustomerPlan.STANDARD,
 | 
			
		||||
                licenses,
 | 
			
		||||
                automanage_licenses,
 | 
			
		||||
                billing_schedule,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user