forked from Support/sp-hydra-veil-gui
Subscription expiration checks refactored
This commit is contained in:
parent
db9553a0f5
commit
17c6a8e258
1 changed files with 21 additions and 1 deletions
|
|
@ -2,7 +2,8 @@
|
||||||
from core.services.profiles.profile_connections import enable_profile #, disable_profile
|
from core.services.profiles.profile_connections import enable_profile #, disable_profile
|
||||||
from core.controllers.ProfileController import ProfileController
|
from core.controllers.ProfileController import ProfileController
|
||||||
from core.models.Configuration import Configuration, ConnectionChoice
|
from core.models.Configuration import Configuration, ConnectionChoice
|
||||||
from core.services.subscriptions.subscriptions_by_protocol import get_profile_subscription, start_new_payment_cycle
|
from core.services.subscriptions.subscriptions_by_protocol import get_profile_subscription, start_new_payment_cycle, wipe_subscription
|
||||||
|
from core.utils.check_if_time_lapsed import check_if_time_lapsed
|
||||||
from core.models.enum_models import PaymentCategory
|
from core.models.enum_models import PaymentCategory
|
||||||
from core.utils.type_checker import type_checker
|
from core.utils.type_checker import type_checker
|
||||||
from core.models.Result import Result, ResultError
|
from core.models.Result import Result, ResultError
|
||||||
|
|
@ -62,6 +63,16 @@ def navigate_to_new_sub_page() -> Result:
|
||||||
return Result(valid=False, error_type=ResultError.NAVIGATE_TO, navigate_to="id", message="No subscription. Pick a payment method.")
|
return Result(valid=False, error_type=ResultError.NAVIGATE_TO, navigate_to="id", message="No subscription. Pick a payment method.")
|
||||||
|
|
||||||
|
|
||||||
|
@register_action(ResultError.EXPIRED_SUB)
|
||||||
|
def wipe_expired_subscription(profile_id: int) -> Result:
|
||||||
|
"""Call core to wipe a subscription, then navigate to the billing page"""
|
||||||
|
wiped = wipe_subscription(profile_id)
|
||||||
|
if wiped.valid:
|
||||||
|
return navigate_to_new_sub_page()
|
||||||
|
else:
|
||||||
|
return wiped
|
||||||
|
|
||||||
|
|
||||||
def filter_subscription(profile_id: int) -> Result:
|
def filter_subscription(profile_id: int) -> Result:
|
||||||
"""Evaluate if this profile has a subscription that's ready to connect."""
|
"""Evaluate if this profile has a subscription that's ready to connect."""
|
||||||
|
|
||||||
|
|
@ -81,6 +92,15 @@ def filter_subscription(profile_id: int) -> Result:
|
||||||
logger.info(f"Returning the error of start_result {start_result}")
|
logger.info(f"Returning the error of start_result {start_result}")
|
||||||
return start_result
|
return start_result
|
||||||
|
|
||||||
|
expiration_date = subscription.expires_at
|
||||||
|
if not expiration_date:
|
||||||
|
# auto check tickets would be here.
|
||||||
|
return navigate_to_new_sub_page()
|
||||||
|
|
||||||
|
expired = check_if_time_lapsed(expiration_date)
|
||||||
|
if expired:
|
||||||
|
return Result(valid=False, error_type=ResultError.EXPIRED_SUB, message="This subscription is expired, would you like to wipe it and get a new one?")
|
||||||
|
|
||||||
# has a valid sub:
|
# has a valid sub:
|
||||||
logger.info(f"Profile id {profile_id} has a valid subscription ready to go..")
|
logger.info(f"Profile id {profile_id} has a valid subscription ready to go..")
|
||||||
return Result(valid=True)
|
return Result(valid=True)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue