Commit graph

471 commits

Author SHA1 Message Date
b5930694c7 Add is_finalized() method and make payment confirmation flow idempotent
* Add is_finalized() method to CryptoPayment model that checks:
  - Status in confirmed states (STATUS_CONFIRMED, STATUS_CONFIRMED_OVERPAID, STATUS_CONFIRMED_OVERPAID_REFUNDED)
  - Received amount >= expected amount (handles overpayments)
  - Current confirmations >= required confirmations

* Make process_confirmed_payment() idempotent and resumable:
  - Check is_finalized() before attempting to finalize invoice
  - Check refund_tx_hash before attempting refunds
  - Only set terminal status at function end when all operations succeed
  - Keep payments in STATUS_CONFIRMED_OVERPAID if refunds fail (allows retry)

* Fix logging errors by safely handling None process results
* Update test mocks to include required fields and new function signatures
* All 94 crypto watcher tests now pass

This allows failed refunds to be retried without re-delivering products to customers or losing funds.
2025-09-29 13:29:00 -04:00
446a7c3526 Fix comprehensive DOGE payment processing issues
- Fix DOGE amount parsing precision in get_dogecoin_incoming_transfers
- Fix payment comparison logic to use new_sum directly instead of adding to received_amount
- Fix PaymentRescue to use coin-specific clients and RPC calls
- Fix Decimal/float type conversion in wallet scanning
- Add proper balance checking for DOGE vs XMR clients
- Implement coin-specific refund mechanisms (sendtoaddress vs transfer)
- Fix confirmation requirements to use coin-specific values

Resolves underpayment detection bug where DOGE amounts were parsed as 4 koinu
instead of proper atomic units, causing false underpayment flags.
2025-09-29 11:50:53 -04:00
d1173d4848 Fix DOGE refunds using wrong client - critical bug fix
- PaymentRescue was using whatever client was passed in (usually Monero)
- Now gets coin-specific client based on payment.coin_type
- DOGE refunds will use DOGE client, XMR refunds use XMR client
- Fixes 404/500 errors when attempting DOGE refunds

This was causing DOGE refunds to fail because they were trying to call
sendtoaddress on the Monero RPC endpoint instead of Dogecoin RPC.
2025-09-29 10:23:11 -04:00
35780e4245 Implement DOGE refund support in crypto payment rescue
- Add coin-specific refund logic (XMR uses transfer, DOGE uses sendtoaddress)
- Fix confirmation threshold logging to use coin-specific requirements
- Improve refund amount logging to show correct coin type and atomic units
- DOGE refunds now use sendtoaddress RPC instead of failing with 404

Note: Crypto watcher needs restart to pick up changes
2025-09-29 10:20:08 -04:00
5df297eade Fix hardcoded confirmation requirements in crypto payment rescue
- Use coin-specific confirmation requirements from get_coin_config
- DOGE refunds now process at 2 confirmations instead of 10
- Improve logging to show correct coin type and atomic units
- Still need to implement DOGE-specific refund mechanism (currently uses XMR transfer RPC)
2025-09-29 10:18:44 -04:00
3d7289d517 Fix DOGE underpayment detection and XMR exact payment regression
Critical fixes:
1. DOGE amount normalization in scan_wallet_for_double_or_late_payments
   - Convert DOGE amounts from listsinceblock to atomic units (koinu)
   - Prevents amounts like 4.38281195 DOGE being parsed as 4 koinu

2. DOGE confirmation updates in update_payment_confirmations_only
   - Implement proper confirmation tracking using gettransaction RPC
   - Allows DOGE refunds to process at 2 confirmations (not 10)

3. Fix XMR exact payment regression
   - Use new_sum directly for first payments (don't add to received_amount)
   - We don't allow multiple payments, so blockchain amount is authoritative
   - Fixes exact XMR payments being incorrectly flagged as underpaid

4. Update coin-specific confirmation requirements
   - DOGE uses 2 confirmations (not 10) for refunds
   - Add confirmations_required to COIN_CONFIGS

5. Add comprehensive debug logging for amount comparisons
   - Helps diagnose precision and comparison issues

This should fix both the DOGE "4 koinu" bug and XMR exact payments
being flagged as underpaid when using QR code payments.
2025-09-29 10:16:38 -04:00
e2392c0132 Fix DOGE amount parsing precision bug in get_dogecoin_incoming_transfers
- Add explicit float() conversion for DOGE amounts before multiplying by 1e8
- This fixes precision issues where amounts like 4.38281195 DOGE were being
  converted to 4 koinu instead of 438281195 koinu
- Add regression test for precise DOGE amounts to prevent future issues
- Resolves underpayment detection false positives for valid DOGE payments

The root cause was tx.get("amount") returning string values that when
multiplied by 100000000 resulted in incorrect integer conversions.
2025-09-29 08:47:36 -04:00
3e9066273a Add crypto logos to checkout UI and clean up sweep scripts
- Add Monero and Dogecoin logo images to static assets
- Update cart_checkout.j2 to display crypto logos on payment buttons
- Update crypto_checkout.j2 to show logos in checkout headers
- Remove duplicate sweep script files (dogecoin-sweep-all.sh, sweep-all-doge.sh)
- Update CLAUDE.md with development standards and testing guidelines
2025-09-29 08:22:49 -04:00
a4dba0b98a Fix failing TransactionMatchingIntegrationTests and add invoice null check
- Fix process_payment to check for null invoice before calling finalize_invoice
- Update TransactionMatchingIntegrationTests to use real Invoice objects instead of None
- Add explicit dbsession.flush() calls after process_payment in tests to ensure transaction persistence
- Update test expectations from STATUS_RECEIVED to STATUS_CONFIRMED for sufficient confirmations
- Add comprehensive documentation explaining transaction flow and test methodology
- Fix shop name uniqueness issues in test setup with UUID-based names

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-29 08:13:36 -04:00
2865a95130 Fix critical crypto watcher transaction matching bug
Fixed issue where Dogecoin scanner was incorrectly matching old processed
transactions to new payments, causing cross-payment contamination. Added
comprehensive transaction deduplication logic that:

- Skips transactions already processed for current payment
- Prevents transactions from being matched to multiple payments
- Maintains database integrity during wallet scanning

Added unit tests in TransactionMatchingTests class and integration tests
in TransactionMatchingIntegrationTests class to prevent regression.

Resolves production issue where dust transactions were being incorrectly
matched to new payment addresses.
2025-09-29 07:29:44 -04:00
b2da59c346 Add Dogecoin (DOGE) payment support mention to README 2025-09-29 06:50:49 -04:00
f1f7572063 Implement crypto quote locking mechanism and fix test failures
- Add check_user_has_pending_quotes() function to prevent infinite pending quotes
- Block new crypto quotes when user has pending/received payments
- Flash warning message and redirect to crypto history for pending quotes
- Disable Monero/Dogecoin buttons in checkout when user has pending quotes
- Fix integration test email mocking to prevent MagicMock string errors
- Fix underpayment test assertion to handle status transition variations
2025-09-29 06:43:19 -04:00
0faa20ba4f Fix DOGE payment underpayment detection and refund processing
- Fix early detection logic to use new_sum instead of received_amount for underpayment check
- Fix hardcoded XMR atomic units (1e12) used for DOGE refunds, use correct coin-specific units
- Add comprehensive tests for atomic unit conversions for DOGE (1e8) and XMR (1e12)
- Prevent false underpayment detection when dust or corrupted amounts exist in database

This fixes production issue where valid DOGE payments were incorrectly marked as underpaid
due to comparing old stored amount instead of new incoming transaction amount.
2025-09-29 06:15:56 -04:00
62e098a131 Fix digital product detection in crypto payment status views
- Replace non-existent download_instructions attribute with proper is_physical check
- Assume digital by default and only mark as non-digital if any product is physical
- Fixes AttributeError during crypto payment finalization for both XMR and DOGE
2025-09-28 17:22:39 -04:00
7885ed5d76 Fix make serve binding and add missing DogecoinClient methods
- Remove config modification logic from make serve to respect existing listen settings
- Remove --reload flag to test remote host binding
- Add missing listsinceblock method to DogecoinClient and MockDogecoinClient for late payment scanning
- Update Dogecoin auto sweep test expectations to match new 0.002 DOGE fee buffer (was 0.1 DOGE)
2025-09-28 17:17:25 -04:00
27a8109f47 Fix make serve to properly override listen address
Use pserve config override syntax: listen=0.0.0.0:6501
instead of invalid --bind flag. This forces the server to bind
to all interfaces on port 6501 for external access during development.
2025-09-28 17:03:23 -04:00
505b3b9ea8 modified: development.ini 2025-09-28 17:02:07 -04:00
1d75cfdcc6 Fix make serve to respect 0.0.0.0:6501 bind address
The --reload flag was ignoring the listen = 0.0.0.0:6501 setting
in development.ini. Added explicit --bind=0.0.0.0:6501 to make serve
target to ensure development server binds to all interfaces on port 6501.

This allows external access to the dev server for testing.
2025-09-28 17:01:44 -04:00
3b27bb55ce Add Dogecoin production support: sweep-all-doge and getblockhash method
1. Added getblockhash() method to DogecoinClient for late payment scanning
   - Fixes 'DogecoinClient' object has no attribute 'getblockhash' error
   - Required for crypto watcher to scan for missed payments

2. Added sweep-all-doge Makefile target for dust collection
   - Sweeps ALL spendable Dogecoin balance to cold storage
   - Uses sendtoaddress with subtractfeefromamount=true for complete sweep
   - Includes safety confirmations and balance checks
   - Perfect for cleaning up dust from hot wallet

Usage:
  COLD_WALLET_ADDRESS=DYourColdAddress make sweep-all-doge

Critical for production Dogecoin deployment and hot wallet management.
2025-09-28 16:49:13 -04:00
2a73a631bc Add missing getblockhash method to DogecoinClient for late payment scanning
The crypto watcher's late payment scanner was failing with:
'DogecoinClient' object has no attribute 'getblockhash'

Added getblockhash() method to both DogecoinClient and MockDogecoinClient:
- Uses standard Bitcoin RPC getblockhash call with block height parameter
- Enables proper Dogecoin late payment detection in production
- Required for crypto watcher to scan for missed payments

Critical for production Dogecoin support.
2025-09-28 16:48:15 -04:00
c3a3039c00 Fix crypto watcher sweep fee estimation to match quote logic
The crypto watcher was using uncapped fee estimation (1.77 DOGE/KB) when
sweeping funds, causing ~1 DOGE fees instead of the capped quote fees.

Applied same optimizations as quote system:
- Use 6 block target instead of 2 blocks for cheaper fees
- Reduce transaction size estimate from 0.5KB to 0.25KB
- Cap fee rate at 0.1 DOGE/KB maximum
- Use 0.002 DOGE fallback instead of 0.1 DOGE

This ensures backend sweep fees match the frontend quote fees,
preventing excessive sweep costs that eat into payment amounts.
2025-09-28 16:44:31 -04:00
a3baa48e57 Format crypto views file with black 2025-09-28 16:34:44 -04:00
830ff7fc48 Cap excessive Dogecoin fee rates to prevent overcharging
The estimatesmartfee RPC was returning inflated fee rates (3+ DOGE/KB)
causing fees of ~/bin/bash.20 instead of expected ~/bin/bash.024.

Added fee rate cap of 0.1 DOGE/KB which results in:
- Max fee: 0.1 * 0.25KB * 2 = 0.05 DOGE (~/bin/bash.011)
- Much closer to wallet estimates of ~0.102 DOGE (~/bin/bash.024)
- Still covers inbound + outbound transaction costs

This prevents customers from being overcharged due to temporary
network fee spikes or misconfigured fee estimation.
2025-09-28 16:31:45 -04:00
b46b387460 Fix UUID handling in debug route using uuid_str property
UUID objects need to use .uuid_str property to get string representation,
as documented in CLAUDE.md. Using str() on UUID objects doesn't work properly.
2025-09-28 16:26:16 -04:00
d8e4f725de Add logging to Dogecoin fee estimation to debug fallback usage
Added comprehensive logging to see if fee estimation is:
- Using dynamic network fees from estimatesmartfee RPC
- Consistently falling back to hardcoded 0.004 DOGE fee
- Encountering RPC errors

This will help determine if high fees are due to fallback usage
vs actual network conditions.
2025-09-28 16:24:30 -04:00
e3bfb8e4f0 Improve Dogecoin fee estimation to reduce overly high fees
The fee estimation was calculating ~/bin/bash.20 fees when it should be much lower.

Changes:
- Use 6 block target (~1 hour) instead of 2 blocks for cheaper estimates
- Reduce transaction size estimate from 0.5KB to 0.25KB (more realistic for DOGE)
- Lower fallback fee from 0.01 DOGE to 0.002 DOGE (~/bin/bash.0006 vs /bin/bash.003)
- Update development.ini default to match new lower fallback

This should reduce typical fee estimates from ~/bin/bash.20 to ~/bin/bash.02-0.05 range,
making Dogecoin payments more cost-effective for users while still covering
both inbound and sweep transaction costs.
2025-09-28 16:21:07 -04:00
2a3b007299 Remove confusing atomic unit display from crypto checkout
Removed the 'Received: X / Y piconero' display that was showing raw atomic units
(piconero for XMR, koinu for DOGE) which confused users during testing.

Changes:
- Removed HTML div showing received/expected atomic units
- Removed JavaScript variables and logic for updating atomic unit display
- Users now see only human-readable cryptocurrency amounts

This improves UX by showing only meaningful amounts users can understand.
2025-09-28 16:17:57 -04:00
6afd6764d9 Add temporary read-only debug route for crypto wallet scanning issue
TEMPORARY: /crypto/debug/wallet-scan endpoint to diagnose why late payment
scanner shows 'No transfers found' while wallet actually has transactions.

READ-ONLY route that:
- Shows crypto processor count and scan positions
- Tests wallet RPC with same parameters as scanner
- Compares transfer counts to identify if issue is RPC or scanner logic
- Masks sensitive data (shop IDs, amounts, addresses)

TODO: Comment out this route when debugging is complete.
2025-09-28 15:53:35 -04:00
b776d1cd7e Add comprehensive logging to crypto payment scanner for production debugging
The late payment scanner stopped finding payments after double payment fixes.
Added detailed logging to diagnose the issue:

- Log each processor's scan position and calculated height
- Log minimum scan position used for wallet queries
- Log exact RPC query parameters sent to wallet
- Log all transfers found with height, amount, confirmations, subaddress
- Log payment lookup results for each transfer
- Log late payment decision logic with accept/reject reasons

This will reveal if:
- Scan positions are too high and skipping late payments
- Transfers are found but not matched to payment records
- Payments are found but rejected by late payment logic

Critical for debugging production issue where real customer funds
may not be getting processed due to missed late payments.
2025-09-28 15:36:18 -04:00
c1a936539e deleted: debug_auth_headers.py
deleted:    debug_digest_details.py
	deleted:    debug_monero_auth.py
	renamed:    CRYPTO_WATCHER_FLOW.md -> docs/CRYPTO_WATCHER_FLOW.md
	deleted:    test_digest_auth_local.py
	deleted:    test_dogecoin_client.py
	deleted:    test_monero_auth.py
	deleted:    test_monero_client.py
	deleted:    test_requests_lib.py
	deleted:    test_urllib_variants.py
2025-09-28 15:26:42 -04:00
e3b022e2c5 Fix Jinja2 template syntax error - replace break with proper logic
Fixed template syntax error where {% break %} is not supported in Jinja2.
Replaced with proper Jinja2 pattern using set variable and conditional check
to find first available thumbnail for Open Graph images.

Changes:
- Use {%- set og_thumbnail = none %} and conditional assignment
- Check og_thumbnail is none to ensure only first match is used
- Maintains same functionality with valid Jinja2 syntax

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-28 15:14:16 -04:00
fe8388bc52 Improve Open Graph images to use first available thumbnail
Enhanced social media sharing by updating og:image meta tags to use the first
available thumbnail (thumbnail1-4) instead of hardcoding thumbnail1. This ensures
better social media previews on Slack, Twitter, Facebook when products don't have
thumbnail1 but have other thumbnails available.

Updated templates:
- product.j2: Smart thumbnail fallback for product pages
- content.j2: Smart thumbnail fallback for content pages

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-28 15:06:01 -04:00
6ecff9e1ef Add Monero (XMR) payment support mention to README
Updated intro description to mention that Make Post Sell accepts both
credit cards and Monero (XMR) payments for better feature visibility.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-28 14:18:01 -04:00
5b74503abf modified: make_post_sell/tests/test_double_spend_integration.py 2025-09-28 13:58:29 -04:00
b6fed206ce Add integration test for duplicate payment confirmation count update bug
This test reproduces the exact issue where duplicate payments weren't getting
their confirmation counts updated in the main processing loop, causing stuck refunds.

The test:
- Creates a duplicate payment with STATUS_DOUBLEPAY_REFUND and 0 confirmations
- Mocks blockchain data showing the transaction has 15 confirmations
- Calls process_payment() to simulate the main processing cycle
- Asserts that current_confirmations gets updated from 0 to 15

This test would have caught the bug where duplicate payments remained stuck
at 0 confirmations despite transactions having 10+ confirmations on blockchain.

Currently FAILS (as expected) since the fix hasn't been fully verified.
The test will pass once the confirmation update logic is working correctly.
2025-09-28 13:10:46 -04:00
c4eaacb453 Fix duplicate payment confirmation count update in main processing loop
The previous fix for update_payment_confirmations_only only worked for REFUND_PENDING_STATUSES,
but duplicate payments in STATUS_DOUBLEPAY_REFUND were being processed in the main loop
without updating their confirmation counts.

Added confirmation count updates directly in the duplicate payment processing logic:
- After finding specific duplicate transactions for XMR payments
- After fetching transaction details for other coin types
- Logs the confirmation count change for debugging

This ensures duplicate payments get their confirmation counts updated during processing,
allowing stuck refunds to proceed when transactions have sufficient confirmations.

Production logs showed payment stuck at "incoming: 0/2" despite transaction having 10+ confirmations.
This fix will update the count to show actual confirmations from the blockchain.
2025-09-28 12:35:53 -04:00
784112f591 Add unit tests for duplicate payment confirmation counting fix
Added 3 comprehensive unit tests to CryptoWatcherUnitTests class:

1. test_update_payment_confirmations_only_duplicate_payment
   - Tests that duplicate payments use specific transaction confirmation count
   - Simulates scenario with multiple transactions where min() would give wrong result
   - Verifies it finds specific txid from tx_hashes and uses its confirmation count

2. test_update_payment_confirmations_only_regular_payment
   - Tests that regular payments still use min() confirmation logic
   - Ensures backward compatibility for non-duplicate payments

3. test_update_payment_confirmations_only_duplicate_payment_not_found
   - Tests fallback behavior when specific transaction ID is not found
   - Verifies warning is logged and falls back to min() logic

These tests ensure the bug fix for stuck duplicate payment refunds is working correctly
and will prevent regression of the confirmation counting logic.
2025-09-28 12:23:24 -04:00
4f34d0079c Fix duplicate payment confirmation counting bug that prevented refunds
The update_payment_confirmations_only function was using min() across ALL transactions
to the same address instead of checking the specific transaction for duplicate payments.

This caused duplicate payments with old, confirmed transactions to show 0 confirmations
if there were newer unconfirmed transactions to the same address.

Fixed by:
- Checking if payment is STATUS_DOUBLEPAY_REFUND
- Looking up the specific transaction ID from tx_hashes
- Using confirmation count for that specific transaction only
- Falling back to min() for regular payments

This will allow stuck duplicate payment refunds to proceed once their specific
transaction has 10+ confirmations.
2025-09-28 12:13:44 -04:00
bc46e960a5 Fix test failure in double spend protection test
- Mock send_purchase_email and send_sale_email in test_original_payment_moves_to_confirmed_despite_duplicates
- Test was failing with TypeError: unsupported format string passed to MagicMock.__format__ when finalize_invoice called email functions
- Now that payments properly reach confirmed status and call finalize_invoice, tests need to mock the email functions
2025-09-28 11:55:06 -04:00
cb25dec3ef Add integration test to catch critical finalize_invoice parameter bug
- Added test_process_payment_confirmation_flow_integration to catch the AttributeError: 'Invoice' object has no attribute 'invoice' bug
- Test sets up realistic payment scenario and verifies finalize_invoice is called correctly during confirmation flow
- Uses DummyRequest instead of over-mocked objects to trigger real function calls
- Test would have caught the production bug where finalize_invoice was called with crypto_payment.invoice instead of crypto_payment
- Verified test catches the bug when code is broken and passes when code is fixed
2025-09-28 11:49:11 -04:00
859f9b07cc Fix critical finalize_invoice function call bug
Line 1670 was incorrectly calling:
  finalize_invoice(env_request, crypto_payment.invoice)

Should be:
  finalize_invoice(env_request, crypto_payment)

This was causing AttributeError: 'Invoice' object has no attribute 'invoice'
when processing confirmed payments, breaking the entire payment confirmation flow.
2025-09-28 11:10:51 -04:00
7a5340e139 Fix duplicate payment email sending and improve test robustness
- Fix ShopContextRequestWrapper to handle missing attributes gracefully with getattr default
- Add send_refund_email mock to test_full_payment_flow_with_double_spend test
- Update test to check for both STATUS_DOUBLEPAY_REFUND and STATUS_DOUBLEPAY_REFUND_COMPLETE
- Duplicate payments now properly send refund emails with correct shop domain context
- Email sending failures no longer prevent duplicate payment processing completion

This resolves the test failure where duplicate payments were being created but not
committed due to email sending errors in test environments.
2025-09-28 10:36:53 -04:00
b1d78856d3 Add UI status display for duplicate payment refund statuses
- Add doublepay-refund status: 'Duplicate Payment - Refunding' (orange)
- Add doublepay-refund-complete status: '✓ Duplicate Payment - Refunded' (orange)
- Add missing no-refund-complete status: '✓ No Refund Possible' (red)

All 17 crypto payment status enums now have proper UI display with colors:
- Green: successful payments
- Orange: all refund statuses
- Yellow: pending payments
- Blue: received payments
- Red: no-refund scenarios
- Gray: terminal failures

Completed refunds now show checkmark instead of gray fallback color.
2025-09-28 10:17:55 -04:00
5f0e67b8cd Fix duplicate payment status transition and email domain issues
- Add status transition to STATUS_DOUBLEPAY_REFUND_COMPLETE after successful refund
- Keep STATUS_DOUBLEPAY_REFUND status for failed refunds to enable retries
- Fix refund email domain by using create_shop_context_request for proper shop context
- Add comprehensive test for duplicate payment refund status transitions
- Consolidate test logic to reduce complexity while maintaining coverage

This prevents infinite refund retry loops for successful refunds while allowing
retries for failed refunds due to insufficient funds. Email notifications now
use the correct shop domain instead of localhost.
2025-09-28 10:12:20 -04:00
0d996ac31a Fix STATUS_DOUBLEPAY_REFUND to be processed as active payment
The issue was that STATUS_DOUBLEPAY_REFUND was in REFUND_PENDING_STATUSES,
which meant the crypto watcher only monitored confirmations but never
initiated the actual refund processing.

Moved STATUS_DOUBLEPAY_REFUND from REFUND_PENDING_STATUSES to ACTIVE_STATUSES
so that duplicate payments are processed through the main payment flow where
the refund logic is located.

This should fix the stuck duplicate payment that wasn't being refunded
despite having 650+ confirmations and a valid refund address.
2025-09-28 09:51:19 -04:00
040ae0e271 Fix json import scope issue in process_payment function
The json import was inside a conditional block but needed later in the function.
Moved import to top of function to fix UnboundLocalError.

All crypto_watcher and double_spend_protection tests now pass.
2025-09-28 08:54:58 -04:00
80b1789aa7 Fix duplicate payment refund processing by querying historical transactions
The issue was that incoming_transfers was empty because duplicate payments
need to look up their specific historical transaction IDs, not just current
scanning window transfers.

Changes:
- Query historical transfers using stored tx_hashes for duplicate payments
- Use filter_by_height=False to get ALL transfers for the subaddress
- Find specific duplicate transaction by matching stored transaction IDs
- Add detailed logging to show transaction lookup results

This should fix the stuck doublepay-refund payment that has a valid
refund address but wasn't processing because no incoming transfers
were found in the current scanning window.
2025-09-28 08:45:18 -04:00
88fc266be3 Add debug logging for doublepay refund processing
This will help diagnose why the refund isn't being processed:
- Shows refund_address status
- Shows incoming_transfers count
- Shows payment_rescue availability
- Shows client availability

Deploy this to see which condition is failing.
2025-09-28 08:38:56 -04:00
30a5088ea0 Fix duplicate payment refunds by inheriting user's saved refund address
- Add UserCryptoRefundAddress import and lookup function
- Update _create_duplicate_payment to lookup saved refund address
- Fix refund processing to check saved addresses if not set on payment
- Add test for refund address inheritance
- Add Makefile target for sweeping all wallet funds (sweep-all)

This fixes the issue where duplicate payments weren't being refunded
because they had no refund_address set. Now the system will:
1. First check if original payment has refund_address
2. If not, lookup user's saved refund address for that coin type
3. Use the found address for the duplicate payment record

Also added sweep-all target to collect dust from all accounts.
2025-09-28 08:35:08 -04:00
7a1dcfb7e4 Fix critical crypto payment processing issues in duplicate detection path
- Fix confirmed payments stuck in limbo when duplicates detected
- Add email sending for confirmed payments using boolean flags
- Add auto-sweep processing for confirmed payments
- Always finalize invoice when payment moves to confirmed status
- Add comprehensive unit tests for confirmed payment email handling
- Ensure original payment can move to confirmed despite ongoing duplicates
- Prevent double refunds while ensuring payments show in history

This fixes production issues where:
- Payments got 5+ confirmations but stayed in "received" status
- No purchase/sales emails sent for confirmed payments
- Auto-sweep skipped for confirmed payments with duplicates
- Invoice finalization conditional logic caused limbo states

Tests added:
- test_confirmed_payment_with_ongoing_duplicates_sends_emails
- test_confirmed_payment_skips_emails_if_already_sent
- test_original_payment_moves_to_confirmed_despite_duplicates
2025-09-27 19:17:18 -04:00