Add auto-sweep to duplicate detection path for confirmed payments

CRITICAL FIX: Auto-sweep was being skipped when payments moved to CONFIRMED
status via the duplicate detection path due to early return.

- Add auto-sweep logic to duplicate detection path before return
- Check if payment is CONFIRMED, has sweep address, and hasn't been swept
- Ensures funds are swept to cold storage even when duplicates are detected
- Maintains same sweep logic as normal payment processing path

This fixes the issue where payment 37ae9bf3-9bcf-11f0-a140-02dfe05770ee moved
to confirmed status but funds were never swept because the duplicate detection
path returned early before reaching auto-sweep logic.
This commit is contained in:
Russell Ballestrini 2025-09-27 15:55:44 -04:00
parent 46c18d938d
commit 307680dd7c

View file

@ -1610,6 +1610,25 @@ def process_payment(
f"Failed to send sales email for payment {crypto_payment.id}: {e}"
)
# Auto-sweep confirmed payments that haven't been swept yet
if (
client
and crypto_payment.status == CryptoPayment.STATUS_CONFIRMED
and crypto_payment.shop_sweep_to_address
and not crypto_payment.is_swept
):
logger.info(f"Payment {crypto_payment.id} confirmed - attempting sweep")
try:
sweep_success = auto_sweep_payment(
client, crypto_payment, env_request.dbsession
)
if sweep_success and crypto_payment.is_swept:
logger.info(f"Payment {crypto_payment.id} swept successfully")
except Exception as e:
logger.error(
f"Auto-sweep failed for confirmed payment {crypto_payment.id}: {e}"
)
env_request.dbsession.add(crypto_payment)
return