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
This commit is contained in:
parent
21265667ac
commit
66d6f72e3e
1 changed files with 92 additions and 0 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue