Fix session cookie bloat from crypto payment status tracking
Remove session-based status tracking that was storing crypto_payment_status_{payment_id}
for every payment, causing cookie size to exceed 4KB limit with 35+ payments.
- Remove: request.session[session_key] = current_status
- Remove: previous_status tracking via session
- Keep: Flash messages for status notifications (they don't bloat cookies)
Flash messages now trigger on every poll instead of just transitions, but this
prevents the cookie bloat issue. Client-side can handle transition detection if needed.
This commit is contained in:
parent
fcde8d94cf
commit
c9afd3b893
1 changed files with 66 additions and 82 deletions
|
|
@ -807,51 +807,43 @@ 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)
|
||||
# Flash messages for status (without storing in session)
|
||||
current_status = crypto_payment.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 = True
|
||||
if crypto_payment.invoice:
|
||||
for line_item in crypto_payment.invoice.line_items:
|
||||
if line_item.product and line_item.product.is_physical:
|
||||
has_digital = False
|
||||
break
|
||||
|
||||
# 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":
|
||||
if has_digital:
|
||||
request.session.flash(
|
||||
("Payment received! Waiting for confirmations...", "info")
|
||||
("Purchase completed! Download your files now!", "success")
|
||||
)
|
||||
elif current_status == "confirmed":
|
||||
# Check if it's a digital product by looking at line items
|
||||
has_digital = True
|
||||
if crypto_payment.invoice:
|
||||
for line_item in crypto_payment.invoice.line_items:
|
||||
if line_item.product and line_item.product.is_physical:
|
||||
has_digital = False
|
||||
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-overpay":
|
||||
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"))
|
||||
else:
|
||||
request.session.flash(("Purchase completed!", "success"))
|
||||
elif current_status == "confirmed-overpay":
|
||||
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),
|
||||
|
|
@ -904,51 +896,43 @@ 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)
|
||||
# Flash messages for status (without storing in session)
|
||||
current_status = crypto_payment.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 = True
|
||||
if crypto_payment.invoice:
|
||||
for line_item in crypto_payment.invoice.line_items:
|
||||
if line_item.product and line_item.product.is_physical:
|
||||
has_digital = False
|
||||
break
|
||||
|
||||
# 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":
|
||||
if has_digital:
|
||||
request.session.flash(
|
||||
("Payment received! Waiting for confirmations...", "info")
|
||||
("Purchase completed! Download your files now!", "success")
|
||||
)
|
||||
elif current_status == "confirmed":
|
||||
# Check if it's a digital product by looking at line items
|
||||
has_digital = True
|
||||
if crypto_payment.invoice:
|
||||
for line_item in crypto_payment.invoice.line_items:
|
||||
if line_item.product and line_item.product.is_physical:
|
||||
has_digital = False
|
||||
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-overpay":
|
||||
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"))
|
||||
else:
|
||||
request.session.flash(("Purchase completed!", "success"))
|
||||
elif current_status == "confirmed-overpay":
|
||||
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),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue