Notifications for Payment Related actions
This commit is contained in:
parent
6162d000c6
commit
d2e75ca0e1
2 changed files with 24 additions and 0 deletions
|
|
@ -8,6 +8,8 @@ class EventType(Enum):
|
||||||
SYSTEM_DISABLE = auto()
|
SYSTEM_DISABLE = auto()
|
||||||
PROFILE_CREATED = auto()
|
PROFILE_CREATED = auto()
|
||||||
PROFILE_DELETED = auto()
|
PROFILE_DELETED = auto()
|
||||||
|
STATUS_UPDATE = auto()
|
||||||
|
RESUME_ACTIONS = auto()
|
||||||
|
|
||||||
class Notifications:
|
class Notifications:
|
||||||
_subscribers = {}
|
_subscribers = {}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ from core.services.payment_phase.payment_state import OverallPaymentCycle, Payme
|
||||||
from core.models.enum_models import ProtocolChoice, PaymentCategory
|
from core.models.enum_models import ProtocolChoice, PaymentCategory
|
||||||
from core.observers.ConnectionObserver import ConnectionObserver
|
from core.observers.ConnectionObserver import ConnectionObserver
|
||||||
from core.models.pydantic_models.type_checker import validate_model
|
from core.models.pydantic_models.type_checker import validate_model
|
||||||
|
from core.observers.Notifications import Notifications, EventType
|
||||||
from core.models.pydantic_models.ServerReply import SubscriptionInvoice
|
from core.models.pydantic_models.ServerReply import SubscriptionInvoice
|
||||||
from core.models.Subscription import Subscription
|
from core.models.Subscription import Subscription
|
||||||
from core.utils.type_checker import type_checker
|
from core.utils.type_checker import type_checker
|
||||||
|
|
@ -38,6 +39,9 @@ def _api_call_for_invoice(url: str, payload: dict, connection_observer: Connecti
|
||||||
|
|
||||||
logger.info(f"Doing the API call with this payload: {payload}")
|
logger.info(f"Doing the API call with this payload: {payload}")
|
||||||
|
|
||||||
|
notification = "Sending to API.."
|
||||||
|
Notifications.emit(EventType.STATUS_UPDATE, notification)
|
||||||
|
|
||||||
result = api_call_and_extraction(
|
result = api_call_and_extraction(
|
||||||
desired_type="data",
|
desired_type="data",
|
||||||
method=ApiCall.POST,
|
method=ApiCall.POST,
|
||||||
|
|
@ -107,6 +111,8 @@ def error_about_mismatch(category: PaymentCategory) -> Result:
|
||||||
def evaluate_repeat_cycle(payment_cycle: OverallPaymentCycle, profile_id: int) -> Result:
|
def evaluate_repeat_cycle(payment_cycle: OverallPaymentCycle, profile_id: int) -> Result:
|
||||||
if the_same_payment_cycle(payment_cycle=payment_cycle, profile_id=profile_id):
|
if the_same_payment_cycle(payment_cycle=payment_cycle, profile_id=profile_id):
|
||||||
logger.info("It's the same as before, returning the data")
|
logger.info("It's the same as before, returning the data")
|
||||||
|
notification = f"Resuming Profile {profile_id}'s Payment"
|
||||||
|
Notifications.emit(EventType.STATUS_UPDATE, notification)
|
||||||
return Result(valid=True, data=payment_cycle.billing_data)
|
return Result(valid=True, data=payment_cycle.billing_data)
|
||||||
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?"
|
||||||
|
|
@ -182,6 +188,8 @@ def start_new_payment_cycle(category: PaymentCategory, profile_id: Optional[int]
|
||||||
payment_cycle.begin()
|
payment_cycle.begin()
|
||||||
|
|
||||||
if payment_cycle.billing_data:
|
if payment_cycle.billing_data:
|
||||||
|
notification = "Starting Billing Cycle"
|
||||||
|
Notifications.emit(EventType.STATUS_UPDATE, notification)
|
||||||
return Result(valid=True, data=payment_cycle)
|
return Result(valid=True, data=payment_cycle)
|
||||||
|
|
||||||
return Result(valid=False, error_type=ResultError.UNKNOWN, message="Failed to create billing data.")
|
return Result(valid=False, error_type=ResultError.UNKNOWN, message="Failed to create billing data.")
|
||||||
|
|
@ -241,6 +249,10 @@ def return_pre_existing_invoice(billing_code: str, connection_observer: Connecti
|
||||||
|
|
||||||
result = _api_call_for_invoice(url=url, payload=payload, connection_observer=connection_observer)
|
result = _api_call_for_invoice(url=url, payload=payload, connection_observer=connection_observer)
|
||||||
|
|
||||||
|
if result.valid:
|
||||||
|
notification = "Got Pre-Existing Invoice"
|
||||||
|
Notifications.emit(EventType.STATUS_UPDATE, notification)
|
||||||
|
|
||||||
#-----------------------------
|
#-----------------------------
|
||||||
# EXPIRED? CLARIFY ON WHAT'S EXPIRED (TICKETS VS INDIVIDUAL)
|
# EXPIRED? CLARIFY ON WHAT'S EXPIRED (TICKETS VS INDIVIDUAL)
|
||||||
#-----------------------------
|
#-----------------------------
|
||||||
|
|
@ -321,6 +333,9 @@ def get_ticket_invoice(connection_observer: ConnectionObserver) -> Result:
|
||||||
billing_data.save()
|
billing_data.save()
|
||||||
|
|
||||||
payment_cycle.got_invoice = True
|
payment_cycle.got_invoice = True
|
||||||
|
|
||||||
|
notification = "Got Invoice"
|
||||||
|
Notifications.emit(EventType.STATUS_UPDATE, notification)
|
||||||
return Result(valid=True, data=final_invoice)
|
return Result(valid=True, data=final_invoice)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -386,6 +401,8 @@ def create_individual_invoice(payment_cycle: OverallPaymentCycle, connection_obs
|
||||||
|
|
||||||
result = _api_call_for_invoice(url=url, payload=payload, connection_observer=connection_observer)
|
result = _api_call_for_invoice(url=url, payload=payload, connection_observer=connection_observer)
|
||||||
if not result.valid:
|
if not result.valid:
|
||||||
|
notification = result.message
|
||||||
|
Notifications.emit(EventType.STATUS_UPDATE, notification)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
final_invoice = result.data
|
final_invoice = result.data
|
||||||
|
|
@ -498,6 +515,9 @@ def wipe_billing_cycle(inserted_profile_id: Optional[int] = None) -> Result:
|
||||||
# if no profile id was given, wipe it and move on:
|
# if no profile id was given, wipe it and move on:
|
||||||
if not inserted_profile_id:
|
if not inserted_profile_id:
|
||||||
payment_cycle.wipe()
|
payment_cycle.wipe()
|
||||||
|
notification = "Stopped Checking if Paid"
|
||||||
|
Notifications.emit(EventType.STATUS_UPDATE, notification)
|
||||||
|
Notifications.emit(EventType.RESUME_ACTIONS, True)
|
||||||
return Result(valid=True)
|
return Result(valid=True)
|
||||||
|
|
||||||
# from here on assume we were given a profile id
|
# from here on assume we were given a profile id
|
||||||
|
|
@ -565,6 +585,8 @@ def wipe_subscription(profile_id: int) -> Result:
|
||||||
|
|
||||||
profile.subscription = None
|
profile.subscription = None
|
||||||
ProfileController.update(profile)
|
ProfileController.update(profile)
|
||||||
|
notification = "Cleared Expired Subcription"
|
||||||
|
Notifications.emit(EventType.STATUS_UPDATE, notification)
|
||||||
return Result(valid=True)
|
return Result(valid=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue