forked from Support/sp-hydra-veil-gui
88 lines
No EOL
3 KiB
Python
88 lines
No EOL
3 KiB
Python
# core
|
|
from core.controllers.tickets.TicketPayController import initiate_payment
|
|
from core.services.subscriptions.subscriptions_by_protocol import start_billing_state
|
|
from core.services.payment_phase.payment_state import OverallPaymentCycle, TicketPaymentData
|
|
from core.models.enum_models import PaymentType, PaymentCategory
|
|
from core.controllers.tickets.UseTicketController import get_unused_tickets
|
|
from core.models.Result import Result, ResultError
|
|
# from core.controllers.ProfileController import ProfileController
|
|
from core.errors.logger import logger
|
|
|
|
# gui
|
|
from gui.v2.infrastructure.ThreadSafetyTool import ThreadSafetyTool
|
|
from gui.v2.infrastructure.take_plumbing_action import take_action
|
|
from gui.v2.infrastructure.setup_observers import connection_observer, ticket_observer
|
|
|
|
from typing import Callable
|
|
|
|
|
|
|
|
def start_ticket(ui_caller: Callable) -> Result:
|
|
logger.info("started ticketing billing state")
|
|
return take_action(
|
|
action=start_billing_state,
|
|
ui_caller=ui_caller,
|
|
category=PaymentCategory.TICKET
|
|
)
|
|
|
|
|
|
def fetch_ticket_invoice(invoice_ui_caller: Callable, timer_resume_caller: Callable) -> str | None:
|
|
"""Start the Ticketing process on the background thread with the relevant billing data."""
|
|
|
|
logger.info("fetching ticket invoice..")
|
|
|
|
payment_cycle = OverallPaymentCycle()
|
|
|
|
if not payment_cycle:
|
|
"No payment cycle, and therefore no data."
|
|
|
|
# already existing but wrong format:
|
|
if payment_cycle.category != PaymentCategory.TICKET:
|
|
return "Wrong payment cycle category."
|
|
|
|
billing_data = payment_cycle.instance
|
|
|
|
if not billing_data:
|
|
return "No billing data"
|
|
|
|
# if not isinstance(billing_data, TicketPaymentData):
|
|
# return "Billing data in the wrong format."
|
|
|
|
which_key = billing_data.which_key
|
|
currency = billing_data.currency
|
|
how_many_profiles = billing_data.how_many_profiles
|
|
|
|
# Fetch (this function will complain if missing data):
|
|
take_action(
|
|
action=initiate_payment,
|
|
ui_caller=invoice_ui_caller,
|
|
how_many_profiles=how_many_profiles,
|
|
which_key=which_key,
|
|
which_cryptocurrency=currency,
|
|
ticket_observer=ticket_observer,
|
|
connection_observer=connection_observer,
|
|
bypass_existing=True,
|
|
)
|
|
logger.info("Initiated payment")
|
|
|
|
|
|
def get_ticket_data() -> Result:
|
|
"""This is running in the background ALREADY. Get a list of unused tickets from core"""
|
|
|
|
ticket_results = get_unused_tickets()
|
|
valid = ticket_results.get('valid')
|
|
|
|
if not valid:
|
|
message = ticket_results.get('message')
|
|
if not message:
|
|
message = "Error gathering ticket data"
|
|
Result(valid=False, error_type=ResultError.MISSING_FILE, message=message)
|
|
|
|
raw_tickets = ticket_results.get('data')
|
|
print(f"raw_tickets is {raw_tickets}")
|
|
if not raw_tickets:
|
|
Result(valid=True, data=raw_tickets, message="No tickets available.")
|
|
|
|
formatted_data = [(f"Ticket #{t}", t) for t in raw_tickets]
|
|
print(f"formatted_data is {formatted_data}")
|
|
return Result(valid=True, data=formatted_data) |