stripe: Delete fixed price plan offer if customer on comp access plan.

Updates delete_fixed_price_plan to use the same structure as
configure_fixed_price_plan. If there is a customer plan and it's
billable, then we delete the configured CustomerPlan object. If
there is no customer plan or it's a complimentary access plan, we
delete the configured CustomerPlanOffer object.
This commit is contained in:
Lauryn Menard
2025-02-27 13:04:58 +01:00
committed by Tim Abbott
parent 9ad3159e48
commit c4e3ccafa2
2 changed files with 98 additions and 15 deletions

View File

@@ -1561,21 +1561,21 @@ class BillingSession(ABC):
customer = self.get_customer()
assert customer is not None
current_plan = get_current_plan_by_customer(customer)
if current_plan is None:
fixed_price_offer = CustomerPlanOffer.objects.filter(
customer=customer, status=CustomerPlanOffer.CONFIGURED
if current_plan is not None and self.check_plan_tier_is_billable(current_plan.tier):
fixed_price_next_plan = CustomerPlan.objects.filter(
customer=customer,
status=CustomerPlan.NEVER_STARTED,
fixed_price__isnull=False,
).first()
assert fixed_price_offer is not None
fixed_price_offer.delete()
return "Fixed-price plan offer deleted"
fixed_price_next_plan = CustomerPlan.objects.filter(
customer=customer,
status=CustomerPlan.NEVER_STARTED,
fixed_price__isnull=False,
assert fixed_price_next_plan is not None
fixed_price_next_plan.delete()
return "Fixed-price scheduled plan deleted"
fixed_price_offer = CustomerPlanOffer.objects.filter(
customer=customer, status=CustomerPlanOffer.CONFIGURED
).first()
assert fixed_price_next_plan is not None
fixed_price_next_plan.delete()
return "Fixed-price scheduled plan deleted"
assert fixed_price_offer is not None
fixed_price_offer.delete()
return "Fixed-price plan offer deleted"
def update_customer_sponsorship_status(self, sponsorship_pending: bool) -> str:
customer = self.get_customer()