Improved error handling for billing conflicts of individual profiles at the same time

This commit is contained in:
SimplifiedPrivacy 2026-10-20 15:42:13 -04:00
parent 5c3be8803a
commit 6162d000c6
2 changed files with 34 additions and 8 deletions

View file

@ -23,6 +23,7 @@ class ResultError(Enum):
UNPAID = "unpaid" UNPAID = "unpaid"
EXPIRED_SUB = "expired_sub" EXPIRED_SUB = "expired_sub"
ACTIVE_BILLING = "active_billing" ACTIVE_BILLING = "active_billing"
BILLING_CONFLICT = "billing_conflict"
STATE_CONFLICT = "state_conflict" STATE_CONFLICT = "state_conflict"
ZOMBIE_CONNECTION = "zombie_connection" ZOMBIE_CONNECTION = "zombie_connection"
TICKET = "ticket" TICKET = "ticket"

View file

@ -18,6 +18,7 @@ from core.errors.error_shortcuts import not_supported
# generic # generic
from datetime import datetime from datetime import datetime
from typing import Optional from typing import Optional
from functools import partial
def invalid_server_format() -> Result: def invalid_server_format() -> Result:
@ -110,7 +111,8 @@ def evaluate_repeat_cycle(payment_cycle: OverallPaymentCycle, profile_id: int) -
else: else:
error_msg = f"You activated profile {profile_id}, but profile {payment_cycle.billing_data.instance_id} has active billing, stop that?" error_msg = f"You activated profile {profile_id}, but profile {payment_cycle.billing_data.instance_id} has active billing, stop that?"
logger.error(error_msg) logger.error(error_msg)
return Result(valid=False, error_type=ResultError.ACTIVE_BILLING, message=error_msg) func_choice = partial(wipe_billing_cycle)
return Result(valid=False, function_choice=func_choice, error_type=ResultError.BILLING_CONFLICT, message=error_msg)
@type_checker @type_checker
@ -218,6 +220,8 @@ def return_pre_existing_invoice(billing_code: str, connection_observer: Connecti
"""This billing_code already got an invoice, but needs to fetch that data from the server again.""" """This billing_code already got an invoice, but needs to fetch that data from the server again."""
logger.info("Fetching a pre-existing invoice..") logger.info("Fetching a pre-existing invoice..")
payment_cycle = OverallPaymentCycle()
payment_cycle.active = True
if category == PaymentCategory.TICKET: if category == PaymentCategory.TICKET:
payload = { payload = {
@ -422,7 +426,21 @@ def paying_for_tickets() -> bool:
return False return False
def get_current_billing_data(category: Optional[PaymentCategory] = None) -> Result: # def start_new_process_if_already(profile_id: int)
# # Is there currently a process?
# payment_cycle = OverallPaymentCycle()
# if not payment_cycle and not category:
# error_msg = "There is no current billing cycle AND no category provided."
# return Result(valid=False, error_type=ResultError.INVALID_INPUT, message=error_msg)
# billing_data = payment_cycle.billing_data
# if not billing_data:
def get_current_billing_data(category: Optional[PaymentCategory] = None, profile_id: Optional[int] = None) -> Result:
""" """
Goal: Goal:
Get whatever current billing data is relevant by the overall cycle, for either billing category Get whatever current billing data is relevant by the overall cycle, for either billing category
@ -438,14 +456,21 @@ def get_current_billing_data(category: Optional[PaymentCategory] = None) -> Resu
error_msg = "There is no current billing cycle AND no category provided." error_msg = "There is no current billing cycle AND no category provided."
return Result(valid=False, error_type=ResultError.INVALID_INPUT, message=error_msg) return Result(valid=False, error_type=ResultError.INVALID_INPUT, message=error_msg)
# if not payment_cycle and category:
billing_data = payment_cycle.billing_data billing_data = payment_cycle.billing_data
if not billing_data: if not billing_data:
error_msg = "There is no current billing data." if profile_id and category:
return Result(valid=False, error_type=ResultError.INVALID_INPUT, message=error_msg) logger.info("starting a new cycle..")
return start_new_payment_cycle(category=category, profile_id=profile_id)
# else:
# error_msg = "Do you want to start a new billing cycle?"
# if not category:
# category = PaymentCategory.INDIVIDUAL
# new_choice = partial(start_new_payment_cycle, category=category, profile_id=profile_id)
# return Result(valid=False, function_choice=new_choice, error_type=ResultError.INVALID_INPUT, message=error_msg)
else:
error_msg = "Please restart the billing for this profile."
return Result(valid=False, error_type=ResultError.NAVIGATE_TO, navigate_to="menu", message=error_msg)
return Result(valid=True, data=billing_data) return Result(valid=True, data=billing_data)
@ -623,4 +648,4 @@ def return_pre_existing_payment_data(profile_id: int, subscription: Subscription
def evaluate_ticketing() -> bool: def evaluate_ticketing() -> bool:
setup = ConfigurationController.are_tickets_setup() setup = ConfigurationController.are_tickets_setup()
return setup return setup