diff --git a/gui/v2/ui/pages/ticket_crypto_picker_page.py b/gui/v2/ui/pages/ticket_crypto_picker_page.py index 2c79f00..4194bd1 100755 --- a/gui/v2/ui/pages/ticket_crypto_picker_page.py +++ b/gui/v2/ui/pages/ticket_crypto_picker_page.py @@ -1,12 +1,15 @@ import os -from PyQt6.QtWidgets import QButtonGroup, QMessageBox, QPushButton +from PyQt6.QtWidgets import QApplication, QButtonGroup, QMessageBox, QPushButton from PyQt6.QtGui import QIcon from PyQt6.QtCore import QSize from PyQt6 import QtCore from core.services.prepare_tickets.ticket_tracker import delete_ticket_data +from core.controllers.tickets.TicketPayController import check_if_paid +from core.models.Result import Result, ResultError +from gui.v2.infrastructure.setup_observers import connection_observer, ticket_observer from gui.v2.ui.pages.Page import Page from gui.v2.ui.popups.message_box import style_message_box, mark_confirm_button from gui.v2.workers.ticketing_worker_thread import TicketingWorkerThread @@ -63,6 +66,28 @@ class TicketCryptoPickerPage(Page): currency = selected_button.property('currency') self.start_initiate_payment(currency) + def check_if_paid_for_existing(self, temp_billing_code): + self.update_status.update_status("Checking if paid...") + result = check_if_paid(temp_billing_code, ticket_observer, connection_observer) + if isinstance(result, dict) and result.get('valid') and result.get('payment_status') == 'paid': + self.update_status.update_status("Already Paid!") + self.custom_window.navigator.navigate("ticket_prep") + prep_page = self.custom_window.navigator.get_cached("ticket_prep") + if prep_page: + prep_page.start_prep() + else: + self.update_status.update_status("Not yet paid.") + clipboard = QApplication.clipboard() + clipboard.setText(temp_billing_code) + not_paid_msg = f"The billing code is not yet showing paid for {temp_billing_code}. Right now, your clipboard has the billing code, to paste it in any text editor. If you did pay, either wait longer for blockchain confirmation, or contact customer support with the code in your clipboard now." + info = QMessageBox(self) + info.setWindowTitle("Not Paid") + info.setText(not_paid_msg) + info.setStandardButtons(QMessageBox.StandardButton.Ok) + style_message_box(info) + mark_confirm_button(info.button(QMessageBox.StandardButton.Ok)) + info.exec() + def start_initiate_payment(self, currency): self.update_status.update_status("Initiating payment...") self.worker = TicketingWorkerThread('INITIATE_PAYMENT', params={ @@ -80,67 +105,69 @@ class TicketCryptoPickerPage(Page): self.update_status.update_status("Could not initiate payment.") return - if not getattr(invoice, 'is_valid', False): + if not invoice.valid: return self._handle_api_errors(invoice) + # error_code = getattr(invoice, 'error_code', None) self.custom_window.navigator.navigate("payment_details") payment_page = self.custom_window.navigator.get_cached("payment_details") if payment_page is not None: - payment_page.set_ticket_invoice(invoice, self.selected_plan) + payment_page.set_ticket_invoice(invoice.data, self.selected_plan) - def _handle_api_errors(self, invoice): - error_code = getattr(invoice, 'error_code', None) - if error_code == "already_exists" and not self.bypass_existing: - self._prompt_wipe_existing() + def _handle_api_errors(self, invoice: Result): + error_code = invoice.error_type + if error_code == ResultError.ALREADY_EXISTS and not self.bypass_existing: + self._prompt_wipe_existing(invoice) return - elif error_code == "billing_code_exists" and not self.bypass_existing: + elif error_code == ResultError.BILLING_CODE_EXISTS and not self.bypass_existing: temp_billing_code = getattr(invoice, 'temp_billing_code', None) - self._prompt_wipe_existing(temp_billing_code) - return + print(f"temp_billing_code is {temp_billing_code}") + if temp_billing_code: + self._prompt_wipe_billingcode(temp_billing_code) + return + else: + self._prompt_wipe_billingcode("NONE") + return else: - error_msg = getattr(invoice, 'final_error_msg', None) or error_code or "Could not initiate payment." + error_msg = invoice.message + # msg = getattr(invoice, 'final_error_msg', None) or error_code self.update_status.update_status(error_msg) return - def _prompt_wipe_existing(self, temp_billing_code=None): + def _prompt_wipe_existing(self, invoice): msg = QMessageBox(self) - if temp_billing_code: - msg.setWindowTitle("Existing billing code found") - msg.setText("You already have a ticket billing code. Use it, or wipe it and start over?") - use_button = msg.addButton("Use existing", QMessageBox.ButtonRole.AcceptRole) - wipe_button = msg.addButton("Wipe and start over", QMessageBox.ButtonRole.DestructiveRole) - cancel_button = msg.addButton("Cancel", QMessageBox.ButtonRole.RejectRole) - mark_confirm_button(use_button) - else: - msg.setWindowTitle("Existing tickets found") - msg.setText("You already have ticket data. Wipe it and start over?") - use_button = None - wipe_button = msg.addButton("Wipe and start over", QMessageBox.ButtonRole.DestructiveRole) - cancel_button = msg.addButton("Cancel", QMessageBox.ButtonRole.RejectRole) - mark_confirm_button(wipe_button) + msg.setWindowTitle("Existing tickets found") + msg.setText("You already have ticket data. Wipe it and start over?") + msg.setStandardButtons(QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No) style_message_box(msg) - msg.exec() - clicked = msg.clickedButton() - if temp_billing_code and clicked == use_button: - self.update_status.update_status("Reusing existing billing code") - self.custom_window.navigator.navigate("payment_details") - payment_page = self.custom_window.navigator.get_cached("payment_details") - if payment_page is not None: - payment_page.resume_ticket_billing(temp_billing_code) - return - if clicked == wipe_button: - self._restart_payment_after_wipe() + mark_confirm_button(msg.button(QMessageBox.StandardButton.Yes)) + result = msg.exec() + if result == QMessageBox.StandardButton.Yes: + self.bypass_existing = True + delete_ticket_data() + currency_btn = self.buttonGroup.checkedButton() + if currency_btn: + self.start_initiate_payment(currency_btn.property('currency')) else: self.update_status.update_status("Cancelled.") - def _restart_payment_after_wipe(self): - if not delete_ticket_data(): - self.update_status.update_status("Could not wipe ticket data.") - return - self.bypass_existing = False - currency_btn = self.buttonGroup.checkedButton() - if currency_btn: - self.start_initiate_payment(currency_btn.property('currency')) + def _prompt_wipe_billingcode(self, temp_billing_code): + msg = QMessageBox(self) + msg.setWindowTitle("Existing billing code found") + msg.setText("You already have a ticket billing code. Do you want to use it? Only hit YES if you ALREADY paid.") + msg.setStandardButtons(QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No) + style_message_box(msg) + mark_confirm_button(msg.button(QMessageBox.StandardButton.Yes)) + result = msg.exec() + if result == QMessageBox.StandardButton.Yes: + self.update_status.update_status("Reusing same code") + self.check_if_paid_for_existing(temp_billing_code) + else: + self.bypass_existing = True + delete_ticket_data() + currency_btn = self.buttonGroup.checkedButton() + if currency_btn: + self.start_initiate_payment(currency_btn.property('currency')) def on_error(self, msg): self.update_status.update_status(f"Payment error: {msg}")