diff --git a/gui/v2/actions/payment_actions.py b/gui/v2/actions/payment_actions.py index 8a8603b..451158a 100644 --- a/gui/v2/actions/payment_actions.py +++ b/gui/v2/actions/payment_actions.py @@ -120,7 +120,14 @@ def gui_starts_invoice(invoice_ui_caller: Callable, timer_resume_caller: Callabl # insert function here to get it via the data inside. return error_msg else: - return return_pre_existing_invoice(billing_code=billing_code, connection_observer=connection_observer) + pre_existing = return_pre_existing_invoice(billing_code=billing_code, connection_observer=connection_observer) + logger.info(f"Inside GUI's start of invoice, with {pre_existing.error_type}") + if not pre_existing.valid and pre_existing.error_type == ResultError.PAID and payment_cycle.category == PaymentCategory.TICKET: + logger.info("Navigating to ticket prep page") + return Result(valid=True, error_type=NAVIGATE_TO, navigate_to="ticket_prep") + else: + logger.info("returning normally..") + return pre_existing notification = "Fetching Invoice.." Notifications.emit(EventType.STATUS_UPDATE, notification) diff --git a/gui/v2/actions/ticket_actions.py b/gui/v2/actions/ticket_actions.py index 47a4f0d..f2834ce 100644 --- a/gui/v2/actions/ticket_actions.py +++ b/gui/v2/actions/ticket_actions.py @@ -122,10 +122,16 @@ def fetch_ticket_invoice(ui_caller: Callable): def start_bulk_ticket_prep(ui_caller: Callable) -> Result: """After paid for, start the actual math""" + logger.info("Starting a bulk ticket prep") ticket_cycle = TicketPaymentData() how_many_profiles = ticket_cycle.how_many_profiles - return take_action( + if not ticket_cycle.paid: + logger.error("Not yet paid") + return Result(valid=False, error_type=ResultError.NAVIGATE_TO, navigate_to="id", message="Tickets are not yet paid for, yet the prep started.") + + logger.info("Threading to prepare_tickets") + take_action( action=prepare_tickets, ui_caller=ui_caller, how_many_profiles=how_many_profiles, diff --git a/gui/v2/infrastructure/action_registry.py b/gui/v2/infrastructure/action_registry.py index 0e60ab3..c3bb9b4 100644 --- a/gui/v2/infrastructure/action_registry.py +++ b/gui/v2/infrastructure/action_registry.py @@ -1,6 +1,7 @@ from core.models.Result import Result, ResultError from core.controllers.SyncController import new_sync from core.services.subscriptions.subscriptions_by_protocol import wipe_billing_cycle +# from core.services.payment_phase.check_payment_loop import mark_as_paid # from gui.v2.actions.payment_actions import stop_payment_timer ENUM_MAP = { @@ -8,6 +9,7 @@ ENUM_MAP = { ResultError.NEED_SYNC: (new_sync), ResultError.ACTIVE_BILLING: (wipe_billing_cycle), ResultError.EXPIRED_INVOICE: (wipe_billing_cycle), + # ResultError.PAID: (mark_as_paid), ResultError.INVALID_API_REPLY: None, ResultError.ENCRYPTION: None } diff --git a/gui/v2/ui/pages/Page.py b/gui/v2/ui/pages/Page.py index 60eba85..26af8e4 100755 --- a/gui/v2/ui/pages/Page.py +++ b/gui/v2/ui/pages/Page.py @@ -1,3 +1,7 @@ +from core.models.Result import Result, ResultError +from core.errors.logger import logger + + from gui.v2.ui.popups.error_popup import ErrorPopup from gui.v2.infrastructure.ThreadSafetyTool import ThreadSafetyTool @@ -117,16 +121,28 @@ class Page(QWidget): @mainthread def show_a_popup(self, message: str, title: str = "Error"): """Display a popup with an error""" - error_popup = ErrorPopup( - choice=False, - title=title, - message=message, - end_app = False, - on_answer = None, - passed_result = None, - ) - error_popup.show() + # MISTAKE CATCHER: + if isinstance(message, Result): + final_message = message.message + title = message.error_type.value + else: + final_message = message + + # FINAL REAL CHECK + if isinstance(final_message, str) and isinstance(title, str): + error_popup = ErrorPopup( + choice=False, + title=title, + message=final_message, + end_app = False, + on_answer = None, + passed_result = None, + ) + + error_popup.show() + else: + logger.error("Show a popup was sent non valid strings to display.") def display_error(self, whats_wrong: DataError, whats_it_called: str, the_thing: Any): diff --git a/gui/v2/ui/pages/id_page.py b/gui/v2/ui/pages/id_page.py index 347c130..10bf768 100755 --- a/gui/v2/ui/pages/id_page.py +++ b/gui/v2/ui/pages/id_page.py @@ -11,6 +11,7 @@ from PyQt6 import QtCore # core # from core.models.enum_models import PaymentCategory from core.services.prepare_tickets.ticket_tracker import delete_ticket_data +from core.services.payment_phase.payment_state import TicketPaymentData from core.models.Result import Result # from core.services.payment_phase.ticket_config_tools import do_we_have_billing_id @@ -198,8 +199,18 @@ class IdPage(Page): return billing_code = payment_cycle.billing_code + paid = TicketPaymentData().paid - if billing_code: + print(f"paid {paid}") + + if paid: + print("paid going to prep..") + self.custom_window.navigator.navigate("ticket_prep") + # prep_page = self.custom_window.navigator.get_cached("ticket_prep") + # if prep_page is not None: + # prep_page.start_prep() + + elif billing_code: self._prompt_existing_tickets(billing_code) else: self._continue_multiple_flow() diff --git a/gui/v2/ui/pages/payments2.py b/gui/v2/ui/pages/payments2.py index c904319..3478f3a 100644 --- a/gui/v2/ui/pages/payments2.py +++ b/gui/v2/ui/pages/payments2.py @@ -4,7 +4,7 @@ from core.services.payment_phase.payment_state import PaymentData from core.models.pydantic_models.ServerReply import SubscriptionInvoice from core.models.invoice.TicketInvoice import TicketInvoice from core.models.enum_models import Currency -from core.models.Result import Result +from core.models.Result import Result, ResultError from core.observers.Notifications import Notifications, EventType # GUI @@ -273,6 +273,8 @@ class PaymentDetailsPage(Page): def receive_invoice(self, invoice_result: Result): """Callback for the background API thread to update the UI""" + print("receive_invoice is recieving the invoice result") + if not invoice_result: self.display_error( whats_wrong=DataError.BLANK, @@ -290,6 +292,21 @@ class PaymentDetailsPage(Page): return if not invoice_result.valid: + # Paid already, then navigate away: + if invoice_result.error_type == ResultError.PAID: + print("already paid") + print("already paid") + print("already paid") + print("already paid") + if paying_for_tickets(): + print("triggering ticketing confirmed") + self.ticket_payment_confirmed() + else: + self.update_status.update_status('Paid. Please proceed.') + self.custom_window.navigator.navigate("menu") + return + + # otherwise display the error: self.update_status.update_status(str(invoice_result.error_type.value)) self.show_a_popup(str(invoice_result.message)) return @@ -463,22 +480,25 @@ class PaymentDetailsPage(Page): def regular_payment_confirmed(self, billing_code: str): """Conclude a regular payment by putting the billing code on the final confirmation window.""" + print("calling regular_payment_confirmed") payment_page = self.custom_window.navigator.get_cached("payment_confirmed") if payment_page is not None: for line in self.text_fields: line.setText('') payment_page.set_billing_code(billing_code) + self.custom_window.navigator.navigate("payment_confirmed") else: print("PaymentConfirmed page not found") + self.update_status.update_status('Paid. Please proceed.') + self.custom_window.navigator.navigate("menu") def ticket_payment_confirmed(self): """Conclude a ticket payment by forwarding to the prep page.""" - # self.ticketing = False self.update_status.update_status('Payment received.') self.custom_window.navigator.navigate("ticket_prep") - prep_page = self.custom_window.navigator.get_cached("ticket_prep") - if prep_page is not None: - prep_page.start_prep() + # prep_page = self.custom_window.navigator.get_cached("ticket_prep") + # if prep_page is not None: + # prep_page.start_prep() diff --git a/gui/v2/ui/pages/ticket_prep_page.py b/gui/v2/ui/pages/ticket_prep_page.py index 9c3da0f..104880b 100755 --- a/gui/v2/ui/pages/ticket_prep_page.py +++ b/gui/v2/ui/pages/ticket_prep_page.py @@ -23,6 +23,7 @@ class TicketPrepPage(Page): self._terminal_bound = False self._tickets_ready = False self.setup_initial_layout() + self.active_prep = False self.start_prep() def setup_initial_layout(self): @@ -62,10 +63,13 @@ class TicketPrepPage(Page): self.status_label.setText("Preparing tickets...") self.update_status.update_status("Preparing tickets...") - # Actually Start it: - start_bulk_ticket_prep(ui_caller=self.on_prep_done) + if not self.active_prep: + # Actually Start it: + start_bulk_ticket_prep(ui_caller=self.on_prep_done) + self.active_prep = True def on_prep_done(self, result: Result): + print(f"on_prep_done called with {result}") self.continue_button.setEnabled(True) if not result or not isinstance(result, Result):