update: Removed the broken duplicate _prompt_wipe_billingcode flow

This commit is contained in:
JOhn 2026-08-21 11:47:06 -04:00
parent bd6a9a4893
commit 8a0a1fc74d

View file

@ -1,15 +1,13 @@
import os import os
import shutil
from PyQt6.QtWidgets import QApplication, QButtonGroup, QMessageBox, QPushButton from PyQt6.QtWidgets import QButtonGroup, QMessageBox, QPushButton
from PyQt6.QtGui import QIcon from PyQt6.QtGui import QIcon
from PyQt6.QtCore import QSize from PyQt6.QtCore import QSize
from PyQt6 import QtCore from PyQt6 import QtCore
from core.services.prepare_tickets.ticket_tracker import delete_ticket_data from core.Constants import Constants
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.pages.Page import Page
from gui.v2.ui.popups.message_box import style_message_box, mark_confirm_button from gui.v2.ui.popups.message_box import style_message_box, mark_confirm_button
from gui.v2.workers.ticketing_worker_thread import TicketingWorkerThread from gui.v2.workers.ticketing_worker_thread import TicketingWorkerThread
@ -66,28 +64,6 @@ class TicketCryptoPickerPage(Page):
currency = selected_button.property('currency') currency = selected_button.property('currency')
self.start_initiate_payment(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): def start_initiate_payment(self, currency):
self.update_status.update_status("Initiating payment...") self.update_status.update_status("Initiating payment...")
self.worker = TicketingWorkerThread('INITIATE_PAYMENT', params={ self.worker = TicketingWorkerThread('INITIATE_PAYMENT', params={
@ -105,69 +81,82 @@ class TicketCryptoPickerPage(Page):
self.update_status.update_status("Could not initiate payment.") self.update_status.update_status("Could not initiate payment.")
return return
if not invoice.valid: if not getattr(invoice, 'is_valid', False):
return self._handle_api_errors(invoice) return self._handle_api_errors(invoice)
# error_code = getattr(invoice, 'error_code', None)
self.custom_window.navigator.navigate("payment_details") self.custom_window.navigator.navigate("payment_details")
payment_page = self.custom_window.navigator.get_cached("payment_details") payment_page = self.custom_window.navigator.get_cached("payment_details")
if payment_page is not None: if payment_page is not None:
payment_page.set_ticket_invoice(invoice.data, self.selected_plan) payment_page.set_ticket_invoice(invoice, self.selected_plan)
def _handle_api_errors(self, invoice: Result): def _handle_api_errors(self, invoice):
error_code = invoice.error_type error_code = getattr(invoice, 'error_code', None)
if error_code == ResultError.ALREADY_EXISTS and not self.bypass_existing: if error_code == "already_exists" and not self.bypass_existing:
self._prompt_wipe_existing(invoice) self._prompt_wipe_existing()
return return
elif error_code == ResultError.BILLING_CODE_EXISTS and not self.bypass_existing: elif error_code == "billing_code_exists" and not self.bypass_existing:
temp_billing_code = getattr(invoice, 'temp_billing_code', None) temp_billing_code = getattr(invoice, 'temp_billing_code', None)
print(f"temp_billing_code is {temp_billing_code}") self._prompt_wipe_existing(temp_billing_code)
if temp_billing_code: return
self._prompt_wipe_billingcode(temp_billing_code)
return
else:
self._prompt_wipe_billingcode("NONE")
return
else: else:
error_msg = invoice.message error_msg = getattr(invoice, 'final_error_msg', None) or error_code or "Could not initiate payment."
# msg = getattr(invoice, 'final_error_msg', None) or error_code
self.update_status.update_status(error_msg) self.update_status.update_status(error_msg)
return return
def _prompt_wipe_existing(self, invoice): def _prompt_wipe_existing(self, temp_billing_code=None):
msg = QMessageBox(self) msg = QMessageBox(self)
msg.setWindowTitle("Existing tickets found") if temp_billing_code:
msg.setText("You already have ticket data. Wipe it and start over?") msg.setWindowTitle("Existing billing code found")
msg.setStandardButtons(QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No) 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)
style_message_box(msg) style_message_box(msg)
mark_confirm_button(msg.button(QMessageBox.StandardButton.Yes)) msg.exec()
result = msg.exec() clicked = msg.clickedButton()
if result == QMessageBox.StandardButton.Yes: if temp_billing_code and clicked == use_button:
self.bypass_existing = True self.update_status.update_status("Reusing existing billing code")
delete_ticket_data() self.custom_window.navigator.navigate("payment_details")
currency_btn = self.buttonGroup.checkedButton() payment_page = self.custom_window.navigator.get_cached("payment_details")
if currency_btn: if payment_page is not None:
self.start_initiate_payment(currency_btn.property('currency')) payment_page.resume_ticket_billing(temp_billing_code)
return
if clicked == wipe_button:
self._restart_payment_after_wipe()
else: else:
self.update_status.update_status("Cancelled.") self.update_status.update_status("Cancelled.")
def _prompt_wipe_billingcode(self, temp_billing_code): def _restart_payment_after_wipe(self):
msg = QMessageBox(self) if not self._delete_ticket_data():
msg.setWindowTitle("Existing billing code found") return
msg.setText("You already have a ticket billing code. Do you want to use it? Only hit YES if you ALREADY paid.") self.bypass_existing = False
msg.setStandardButtons(QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No) currency_btn = self.buttonGroup.checkedButton()
style_message_box(msg) if currency_btn:
mark_confirm_button(msg.button(QMessageBox.StandardButton.Yes)) self.start_initiate_payment(currency_btn.property('currency'))
result = msg.exec()
if result == QMessageBox.StandardButton.Yes: def _delete_ticket_data(self):
self.update_status.update_status("Reusing same code") paths = [
self.check_if_paid_for_existing(temp_billing_code) Constants.TICKET_TRACKER_PATH,
else: os.path.join(Constants.HV_TICKETING_CONFIG_HOME, "billing_choices.json"),
self.bypass_existing = True ]
delete_ticket_data() try:
currency_btn = self.buttonGroup.checkedButton() for path in paths:
if currency_btn: if os.path.exists(path):
self.start_initiate_payment(currency_btn.property('currency')) os.remove(path)
if os.path.isdir(Constants.HV_TICKETING_DATA_HOME):
shutil.rmtree(Constants.HV_TICKETING_DATA_HOME)
return True
except OSError as error:
self.update_status.update_status(f"Could not wipe ticket data: {error}")
return False
def on_error(self, msg): def on_error(self, msg):
self.update_status.update_status(f"Payment error: {msg}") self.update_status.update_status(f"Payment error: {msg}")