From bb322be2523e86ab24d45f43be909cd4ee70e2a0 Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Sat, 27 Sep 2025 15:59:25 -0400 Subject: [PATCH] Fix invoice finalization for confirmed payments - always finalize CRITICAL FIX: Removes broken conditional logic that could leave confirmed payments in limbo without invoice finalization. BEFORE: Only finalized invoice if products were still locked AFTER: ALWAYS finalize invoice when payment moves to confirmed status This fixes the spaghetti code logic where payment 37ae9bf3-9bcf-11f0-a140-02dfe05770ee moved to confirmed status but invoice was never finalized because products appeared to already be unlocked. Invoice finalization handles: - Product unlocking - Email sending (purchase + sales) - Proper state management Much cleaner and more reliable than conditional finalization. --- make_post_sell/lib/crypto_watcher.py | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/make_post_sell/lib/crypto_watcher.py b/make_post_sell/lib/crypto_watcher.py index 42473dd..9b53c68 100644 --- a/make_post_sell/lib/crypto_watcher.py +++ b/make_post_sell/lib/crypto_watcher.py @@ -1531,21 +1531,8 @@ def process_payment( >= int(crypto_payment.confirmations_required) and crypto_payment.status == CryptoPayment.STATUS_RECEIVED ): - # Check if invoice needs finalization (products not unlocked yet) - invoice_needs_finalization = False - if crypto_payment.invoice and crypto_payment.invoice.line_items: - # Check if any products are still locked for this user - for line_item in crypto_payment.invoice.line_items: - if ( - line_item.product.get_userproduct_for_user( - crypto_payment.invoice.user - ) - is None - ): - invoice_needs_finalization = True - break - - if invoice_needs_finalization: + # ALWAYS finalize invoice when payment moves to confirmed + if crypto_payment.invoice: logger.info( f"Payment {crypto_payment.id} confirmed, finalizing invoice {crypto_payment.invoice.id}" )