Subscription expiration check tools
This commit is contained in:
parent
5dee318aa4
commit
469268651b
3 changed files with 36 additions and 3 deletions
|
|
@ -20,6 +20,10 @@ class ResultError(Enum):
|
||||||
PERMISSION = "permission"
|
PERMISSION = "permission"
|
||||||
SUBSCRIPTION = "subscription"
|
SUBSCRIPTION = "subscription"
|
||||||
EXPIRED = "expired" # meant for invoice
|
EXPIRED = "expired" # meant for invoice
|
||||||
|
UNPAID = "unpaid"
|
||||||
|
EXPIRED_SUB = "expired_sub"
|
||||||
|
ACTIVE_BILLING = "active_billing"
|
||||||
|
STATE_CONFLICT = "state_conflict"
|
||||||
TICKET = "ticket"
|
TICKET = "ticket"
|
||||||
NO_TICKET = "no_ticket"
|
NO_TICKET = "no_ticket"
|
||||||
ALREADY_EXISTS = "already_exists"
|
ALREADY_EXISTS = "already_exists"
|
||||||
|
|
@ -40,10 +44,7 @@ class ResultError(Enum):
|
||||||
NEED_SYNC = "need_sync"
|
NEED_SYNC = "need_sync"
|
||||||
WRONG_LOCATION = "wrong_location"
|
WRONG_LOCATION = "wrong_location"
|
||||||
SERVER_SIDE = "server_side"
|
SERVER_SIDE = "server_side"
|
||||||
UNPAID = "unpaid"
|
|
||||||
MTU = "mtu"
|
MTU = "mtu"
|
||||||
ACTIVE_BILLING = "active_billing"
|
|
||||||
STATE_CONFLICT = "state_conflict"
|
|
||||||
TOR_NEEDED = "tor_needed"
|
TOR_NEEDED = "tor_needed"
|
||||||
NAVIGATE_TO = "navigate_to"
|
NAVIGATE_TO = "navigate_to"
|
||||||
UNKNOWN = "unknown"
|
UNKNOWN = "unknown"
|
||||||
|
|
|
||||||
|
|
@ -447,6 +447,21 @@ def get_profile_subscription(profile_id: int, save_pending: Optional[bool] = Fal
|
||||||
return profile.subscription
|
return profile.subscription
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def wipe_subscription(profile_id: int) -> Result:
|
||||||
|
"""Wipe a given profile's subscription."""
|
||||||
|
|
||||||
|
profile = ProfileController.get(profile_id)
|
||||||
|
if not profile:
|
||||||
|
error_msg = f"Invalid profile id of {profile_id}"
|
||||||
|
logger.error(error_msg)
|
||||||
|
return Result(valid=False, message=error_msg, error_type=ResultError.INVALID_INPUT)
|
||||||
|
|
||||||
|
profile.subscription = None
|
||||||
|
ProfileController.update(profile)
|
||||||
|
return Result(valid=True)
|
||||||
|
|
||||||
|
|
||||||
def mark_as_paid() -> Result:
|
def mark_as_paid() -> Result:
|
||||||
"""Conclude the payment phase"""
|
"""Conclude the payment phase"""
|
||||||
|
|
||||||
|
|
|
||||||
17
core/utils/check_if_time_lapsed.py
Normal file
17
core/utils/check_if_time_lapsed.py
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
from core.errors.logger import logger
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
def check_if_time_lapsed(insert_date: datetime|str) -> bool:
|
||||||
|
logger.info(f"We are evaluating if this date is expired: {insert_date}")
|
||||||
|
|
||||||
|
# Remove timezone awareness if present
|
||||||
|
if hasattr(insert_date, 'tzinfo') and insert_date.tzinfo is not None:
|
||||||
|
insert_date = insert_date.replace(tzinfo=None)
|
||||||
|
|
||||||
|
# Parse string to datetime if needed
|
||||||
|
if isinstance(insert_date, str):
|
||||||
|
insert_date = datetime.fromisoformat(insert_date)
|
||||||
|
|
||||||
|
# Compare with current time
|
||||||
|
return datetime.now() > insert_date
|
||||||
Loading…
Reference in a new issue