From 66d6f72e3e44e8062cd564dcedda2bbc164fbd0b Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Thu, 25 Sep 2025 08:27:40 -0400 Subject: [PATCH] Add flash messages for crypto payment status transitions - Display 'Payment received\!' when payment is first detected - Show 'Purchase completed\!' when confirmed (with 'Download now\!' for digital products) - Add specific messages for overpayments, refunds, cancellations and expired quotes - Track status transitions in session to show messages only on status changes - Messages will appear on redirect to /u/purchases or /u/crypto-quotes pages --- make_post_sell/views/crypto.py | 92 ++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/make_post_sell/views/crypto.py b/make_post_sell/views/crypto.py index 705dd48..b18a464 100644 --- a/make_post_sell/views/crypto.py +++ b/make_post_sell/views/crypto.py @@ -679,6 +679,52 @@ def crypto_xmr_status(request): if not crypto_payment: return HTTPBadRequest("payment not found") + # Track previous status in session to detect transitions + session_key = f"crypto_payment_status_{payment_id}" + previous_status = request.session.get(session_key) + current_status = crypto_payment.status + + # Update session with current status + request.session[session_key] = current_status + + # Flash messages for status transitions + if previous_status != current_status: + if current_status == "received": + request.session.flash( + ("Payment received! Waiting for confirmations...", "info") + ) + elif current_status == "confirmed": + # Check if it's a digital product by looking at line items + has_digital = False + if crypto_payment.invoice: + for line_item in crypto_payment.invoice.line_items: + if line_item.product and line_item.product.download_instructions: + has_digital = True + break + + if has_digital: + request.session.flash( + ("Purchase completed! Download your files now!", "success") + ) + else: + request.session.flash(("Purchase completed!", "success")) + elif current_status == "confirmed-overpaid": + request.session.flash( + ("Purchase completed! Overpayment will be refunded.", "success") + ) + elif current_status == "expired": + request.session.flash(("Payment quote expired.", "warning")) + elif current_status in [ + "expired-refunded", + "underpaid-refunded", + "out-of-stock-refunded", + ]: + request.session.flash( + ("Refund initiated. Please allow time for processing.", "info") + ) + elif current_status == "cancelled": + request.session.flash(("Payment cancelled.", "info")) + payload = { "payment_id": str(crypto_payment.id), "status": crypto_payment.status, @@ -729,6 +775,52 @@ def crypto_doge_status(request): if not crypto_payment: return HTTPBadRequest("payment not found") + # Track previous status in session to detect transitions + session_key = f"crypto_payment_status_{payment_id}" + previous_status = request.session.get(session_key) + current_status = crypto_payment.status + + # Update session with current status + request.session[session_key] = current_status + + # Flash messages for status transitions (same as XMR) + if previous_status != current_status: + if current_status == "received": + request.session.flash( + ("Payment received! Waiting for confirmations...", "info") + ) + elif current_status == "confirmed": + # Check if it's a digital product by looking at line items + has_digital = False + if crypto_payment.invoice: + for line_item in crypto_payment.invoice.line_items: + if line_item.product and line_item.product.download_instructions: + has_digital = True + break + + if has_digital: + request.session.flash( + ("Purchase completed! Download your files now!", "success") + ) + else: + request.session.flash(("Purchase completed!", "success")) + elif current_status == "confirmed-overpaid": + request.session.flash( + ("Purchase completed! Overpayment will be refunded.", "success") + ) + elif current_status == "expired": + request.session.flash(("Payment quote expired.", "warning")) + elif current_status in [ + "expired-refunded", + "underpaid-refunded", + "out-of-stock-refunded", + ]: + request.session.flash( + ("Refund initiated. Please allow time for processing.", "info") + ) + elif current_status == "cancelled": + request.session.flash(("Payment cancelled.", "info")) + payload = { "payment_id": str(crypto_payment.id), "status": crypto_payment.status,