Commit graph

531 commits

Author SHA1 Message Date
dc092d920d Fix redirect after purchase to check for digital products properly
- Add check for is_physical=False in addition to has_product_file
- Add detailed logging to diagnose redirect issues
- Physical products should always redirect to invoice
- Digital products without files should redirect to invoice
- Only digital products with files should redirect to product page
2025-10-02 16:42:44 -04:00
3289702d50 Move Dogecoin fee buffer to global constant for easier ops access
- DOGE_REFUND_FEE_BUFFER now defined at top of file (line 22)
- Clear comments explaining when/why to adjust it
- Error messages point directly to the constant
- Still overridable via environment variable
2025-10-02 16:35:24 -04:00
8836fb6333 Add better fee error handling and monitoring
- Log clear error messages when fee buffer is too low
- Show exact shortfall amount and required action
- Add DOGE_REFUND_FEE_BUFFER environment variable for dynamic adjustment
- Log actual fee buffer used on successful refunds
- Add helpful comment in vars.sh about the fee buffer setting

Now when watching crypto-watcher logs, admins will see:
- 'INSUFFICIENT FUNDS - Fee estimate too low\!'
- Current buffer, shortfall amount, and line number to fix
- Success messages show actual vs estimated fee usage

This makes it much easier to adjust the fee buffer without diving into code.
2025-10-02 16:34:16 -04:00
d4a239d748 Clean up multi-output refund code
- Reduce fee buffer from 0.01 to 0.005 DOGE (actual fee was 0.0026)
- Remove excessive logging throughout refund process
- Simplify sendmany retry logic - just try funded account then default
- Remove unnecessary balance checks and debug logging
- Fix test mocks to use sendmany instead of _call

This reduces the dust left in temporary wallets from ~0.011 to ~0.005 DOGE
2025-10-02 16:27:33 -04:00
d2d09e8851 Fix Dogecoin multi-output refunds with proper fee handling
- Add payment amount to shop output for overpayment refunds
- Both XMR and DOGE now send payment + restocking fee to shop
- Fix insufficient funds error by using conservative fee buffer (0.01 DOGE)
- Round outputs down to 3 decimal places to avoid precision issues
- Update sendmany to try actual account first (where funds are located)
- Add better error handling for different account formats
- Fix fee calculation to properly account for Dogecoin's fee-on-top model

The issue was that sendmany adds network fee on top of outputs, and we
were trying to send exactly the wallet balance, leaving no room for fees.
Now we reserve 0.01 DOGE for fees and round conservatively.
2025-10-02 16:19:23 -04:00
958a003f35 modified: CLAUDE.md
modified:   make_post_sell/lib/crypto_watcher/__init__.py
	modified:   make_post_sell/tests/test_double_spend_integration.py
2025-10-01 19:25:25 -04:00
a9b427e608 modified: docs/crypto-payments-state-machine.md
modified:   docs/state-machine.dot
	modified:   make_post_sell/lib/crypto_watcher/__init__.py
	modified:   make_post_sell/models/crypto_payment.py
	modified:   make_post_sell/tests/test_crypto_watcher.py
	modified:   make_post_sell/tests/test_double_spend_integration.py
	modified:   make_post_sell/tests/test_double_spend_protection.py
	modified:   make_post_sell/tests/test_invoice_deletion.py
	modified:   make_post_sell/tests/test_models.py
2025-10-01 19:02:39 -04:00
8d382c7f31 modified: make_post_sell/lib/crypto_watcher/__init__.py
modified:   make_post_sell/models/crypto_payment.py
	modified:   make_post_sell/request_methods.py
	modified:   make_post_sell/tests/test_crypto_watcher.py
2025-10-01 15:55:34 -04:00
da18fe2323 Fix Monero scan position tracking to work per-account
- Each crypto processor now scans only its assigned Monero account
- Scan position is tracked independently per processor
- Fixed indentation in scan loop that was broken during refactoring
- Updated tests to match new per-account scanning behavior
- Resolves issue where payments on accounts other than 0 weren't updating scan position
2025-10-01 13:23:32 -04:00
78ea2c0c13 Fix Monero wallet scan to check all accounts, not just account 0
- Add 'all_accounts': True to XMR get_transfers query
- Fixes scan position not updating when payments arrive on other accounts
- Dogecoin scan already works correctly (queries all addresses)
- Ensures new transfers on any account update the scan position
2025-10-01 13:08:23 -04:00
7574c09910 Simplify user logging - always use name field
- Remove UUID fallback since name is always present
- Clean up conditional logic
- User name is a required field in the model
2025-10-01 13:00:07 -04:00
557733890f Fix user attribute in CryptoPayment logging - use only 'name'
- Use only 'name' field from User model for privacy
- Remove references to full_name and email from logs
- Fallback to user ID if name is not available
- User model has 'name' not 'username' or 'display_name'
2025-10-01 12:57:54 -04:00
c525cf4ecc Add eager loading for user and shop relationships in crypto_watcher
- Add joinedload for user and shop in all CryptoPayment queries
- Import sqlalchemy for ORM operations
- Ensures user display_name/username shows in payment logs
- Fixes missing user information in crypto_watcher logs
2025-10-01 12:54:42 -04:00
667b8fee50 Reorganize crypto watcher code into dedicated package
- Create make_post_sell/lib/crypto_watcher/ directory structure
- Move crypto_watcher.py to crypto_watcher/__init__.py
- Move crypto_payment_rescue.py to crypto_watcher/
- Move crypto_clients.py to crypto_watcher/
- Update all imports to use the new package structure
- Fix relative imports within the crypto_watcher package
- Update imports in request_methods.py, views, and all tests
- Fix late payment misidentification (pending vs confirmed status)
- Update terminology: 'late payment' only for expired/cancelled states
- All 141 tests passing
2025-10-01 12:48:49 -04:00
0422fcdc98 Apply black formatting to test_invoice_deletion.py 2025-10-01 11:28:45 -04:00
3ae1b9bed9 Fix misleading overpayment log for exact payments
- Only log 'Overpayment within 5% threshold' when received > expected
- Skip the log message for exact payment matches
- Prevents confusion when payment amount exactly matches expected amount
2025-10-01 11:27:34 -04:00
8326c7401f Migrate crypto_watcher to central logging system
- Replace all 171 direct logger calls with CryptoWatcherLogger methods
- Fix XMR scan position persistence issue (was resetting to None/0)
- Remove redundant formatting methods from CryptoPayment model
- Update all test mocks to use central logging system
- Ensure scan position updates even when no transfers found
2025-10-01 10:18:23 -04:00
5c3cb37761 Clean up redundant formatting methods in CryptoPayment model
- Remove pointless _get_status_description() that just returned self.status
- Remove useless format_transaction_log() only used in tests
- Consolidate duplicated amount formatting logic into _format_amount() helper
- Fix XMR precision from 6 to 12 decimals for accuracy
- Strip trailing zeros from formatted amounts for cleaner output
- Simplify format_confirmation_status() by removing redundant text
- Eliminate unnecessary method delegation in __str__()
- Apply black formatting
2025-10-01 00:25:41 -04:00
2f5a1c0c34 Fix payment UI documentation - buttons are REMOVED not disabled
Payment buttons and QR codes are completely removed from the page
once payment is received, not just disabled
2025-09-30 22:54:22 -04:00
078fe1fe99 Document actual payment UI behavior in CRYPTO_PROBLEMS.rst
- Add section explaining real-time status updates on quote page
- Document automatic redirects to invoice/download upon confirmation
- Clarify that payment buttons are disabled once payment received
- Note that confirmations can be as fast as 2 for digital goods
2025-09-30 22:53:45 -04:00
6157cb415f Remove incorrect UI status check from remaining solutions
The quote page already disables payment buttons and updates status
from pending to received when payment is detected, preventing duplicates
2025-09-30 22:50:30 -04:00
3a205c99a0 Update CRYPTO_PROBLEMS.rst with MONERO DOOM learnings
- Document resolved multiple duplicate payment scenario
- Explain min(balance, expected_fee) restocking fee solution
- Clarify auto-sweep uses exact amounts, not sweep_all
- Add details about fund theft prevention mechanisms
2025-09-30 22:47:45 -04:00
edb236be60 Remove redundant Dogecoin configuration examples
- Remove duplicate dogecoin.conf examples from Advanced Configuration
- Simplify to reference make dogecoin-config command
- Keep only essential full node vs pruned mode trade-offs
2025-09-30 22:43:58 -04:00
9d06903633 Remove database implementation details from crypto docs
- Remove incorrect SQL index examples from DOGECOIN.md and MONERO.rst
- Simplify Dogecoin node security section to reference make command
- Stop leaking database schema details in user-facing documentation
2025-09-30 22:40:10 -04:00
1e988b8553 Update Dogecoin blockchain size to reflect 2025 reality
- Change from 50GB to 200GB+ for full blockchain size
- Update space savings calculation from 96% to 99%
- Based on growth from 110GB in early 2024 to likely 200GB+ in 2025
2025-09-30 22:34:33 -04:00
92ffb0630b Fix Dogecoin prune size to match actual configuration
- Update prune size from 2GB to 2.2GB throughout docs
- Change prune=2000 to prune=2200 to match make dogecoin-config
- Update wallet name to mps_wallet to match actual configuration
2025-09-30 22:32:11 -04:00
18a9dfae4c Simplify Monero recovery procedures and remove automated health checks
- Remove 'Automated Health Checks' section - redundant with make commands
- Simplify recovery procedures to match Dogecoin documentation style
- Remove bash script examples and implementation details
- Keep focus on essential backup/recovery information
2025-09-30 22:28:44 -04:00
dc01348782 Remove address validation code from documentation
- Replace Python validation functions with simple descriptions
- Keep validation rules (D prefix, 34 chars for DOGE; 4 prefix, 95/106 chars for XMR)
- Documentation should describe what, not show implementation how
2025-09-30 22:22:32 -04:00
7c9796c56c Simplify Dogecoin setup to use Makefile targets
- Replace manual installation steps with make install-dogecoin
- Replace manual configuration with make dogecoin-config
- Remove raw dogecoin-cli commands in favor of make targets
- Keep documentation focused on what users need to do, not implementation details
2025-09-30 22:18:11 -04:00
cb0676e701 Remove broken multi-node setup from Monero documentation
- Multi-node setups would cause account index mismatches
- Monero wallets can't be sharded or load balanced
- Replace with honest scaling limitations and realistic options
- Single wallet file is a fundamental architectural constraint
2025-09-30 22:14:39 -04:00
51ec71a9f9 Update crypto documentation with accurate configuration and remove tutorials
- Document actual resource requirements from production systems
- Fix fee documentation: fee buffers are for quotes, not wallet reserves
- Clarify perfect accounting to quote amounts in atomic units
- Remove generic curl/API tutorials, keep Make commands
- Add dust prevention benefit of exact amount sweeping
- Update Makefile targets to match what actually exists
2025-09-30 22:03:08 -04:00
7c8a0065cf modified: docs/CRYPTO.rst
new file:   docs/CRYPTO_PERFORMANCE.rst
	modified:   docs/DOGECOIN.md
	modified:   docs/MONERO.rst
2025-09-30 21:39:35 -04:00
04583ace53 Clean up Makefile sweep commands and documentation
- Remove error messages from sweep/sweep-check Makefile targets
- Keep commands functional for developers/admins in local environments
- Simplify documentation to focus on automatic sweeping behavior
- Maintain separation between end-user docs and dev tools
2025-09-30 20:54:50 -04:00
ed98674c48 Remove untested sweep_to_cold script and references
- Delete make_post_sell/lib/sweep_to_cold.py (untested, risky for production)
- Remove sweep_to_cold console script entry from setup.py
- Update Makefile to deprecate sweep/sweep-check, recommend tested alternatives
- Update CRYPTO.rst documentation to promote sweep-all and sweep-all-doge
- Reduce technical debt by eliminating dangerous untested code path
- Users should use properly tested sweep-all/sweep-all-doge commands instead
2025-09-30 20:54:50 -04:00
f2227199c9 Delete MONERO_DEFECTS.rst 2025-10-01 00:41:12 +00:00
86fdab0f3a Delete CRYPTO_WATCHER_FLOW.md 2025-10-01 00:40:29 +00:00
29baa1bb73 Fix invoice deletion test for centralized logging
- Update test_handle_invoice_deletion_failure to mock centralized log instance
- Change from mocking logger.error to log.error_with_context
- Test now properly validates centralized logging system usage
2025-09-30 20:32:54 -04:00
001eedceed Format code with black 2025-09-30 20:27:25 -04:00
4063c1a9fa Remove RPC credential exposure from DogecoinClient._call
- Remove logging statements that exposed RPC username and password info
- Fix sweep restocking fee tests to work with centralized logging
- Update test mocking to use module-level log instance instead of class
- Maintain security by preventing credential leakage in logs
2025-09-30 20:22:47 -04:00
71f8f2b467 Extensively refactor crypto watcher logging and add comprehensive payment string representations
Infrastructure improvements:
- Add CryptoWatcherLogger class with centralized logging methods
- Add comprehensive __str__ and __repr__ methods to CryptoPayment model
- Include user display name and shop name in payment logs

Logging refactoring:
- Convert 101+ logger calls to use centralized patterns
- Replace repetitive f-string patterns with payment object logging
- Add standardized methods for state transitions, refunds, sweeps
- Eliminate duplicate payment context formatting

DRY improvements:
- Single point of control for payment log formatting
- Consistent error handling with payment context
- Standardized transaction and operation logging
- Enhanced debugging with rich payment information

Testing:
- Add 16 comprehensive unit tests for string representation methods
- Test coverage for all payment states and edge cases
- Maintain 100% functionality with improved maintainability
2025-09-30 20:11:01 -04:00
01c1d237e1 Prevent shop owners from clearing cold wallet addresses
Shop owners can no longer remove/clear their cryptocurrency cold wallet
addresses once set. They can only:
1. Replace the address with a new one
2. Disable the cryptocurrency entirely (address is preserved)

Changes:
- Added server-side validation in crypto_processor_settings view
- Check if processor exists with sweep_to_address before allowing empty submission
- Show clear error message if attempt to clear address
- Updated template to add 'required' attribute when address exists
- Added user-facing note explaining the restriction

This prevents accidental or intentional removal of cold wallet addresses
which could lead to funds being stuck in the hot wallet without a way
to sweep them to cold storage.
2025-09-30 16:31:47 -04:00
c255419f99 Fix invoice deletion integration tests and update documentation
Integration test fixes:
- Replace hardcoded status strings with proper CryptoPayment constants
- Fixed test_complete_refund_states_delete_invoice to use:
  - STATUS_LATEPAY_REFUNDED_COMPLETE
  - STATUS_UNDERPAID_REFUNDED_COMPLETE
  - STATUS_OUT_OF_STOCK_REFUNDED_COMPLETE
- Fixed test_no_refund_payment_deletes_invoice to use STATUS_LATEPAY_NOT_REFUNDED
- Updated all other status references to use constants instead of strings

The integration tests were failing because they used hardcoded strings like
"expired-refunded-complete" instead of the actual status constants from the model.
This caused the should_keep_invoice() logic to not work properly since the
status matching failed.

Documentation updates:
- Corrected "received" state description: detected in mempool (not blockchain)
- Added clarification about confirmations tracking via current_confirmations field
- Updated mempool detection rule explanation

All 11 invoice deletion integration tests now pass, confirming the invoice
deletion logic works correctly with real database operations.
2025-09-30 16:14:28 -04:00
6ceb9375de modified: Makefile
new file:   docs/state-machine.dot
	new file:   docs/state-machine.dot.svg
	renamed:    state-machine.svg -> docs/state-machine.svg
2025-09-30 15:43:54 -04:00
5030b47f4e Delete fix_crypto_payment_statuses.sql 2025-09-30 18:47:16 +00:00
0b5554e431 modified: docs/crypto-payments-state-machine.md
modified:   state-machine.svg
2025-09-30 14:46:47 -04:00
c7caae8d4a Fix crypto payment state machine logic and naming consistency
Major fixes:
1. Remove invalid received→expired transition
   - Payments that reach 'received' state cannot expire
   - Only pending payments can expire
   - Updated VALID_TRANSITIONS and tests accordingly

2. Rename STATUS_DOUBLEPAY_REFUND to STATUS_DOUBLEPAY_REFUNDED
   - Maintains consistency with all other past-tense status names
   - Updated all references across codebase and tests

3. Add INITIAL_WAITING_STATUSES semantic group
   - Groups states that are entry points: pending, latepay_refunded, doublepay_refunded
   - These states don't transition from 'received' - they represent initial states
   - Added is_initial_waiting_state() helper method

4. Update semantic groups
   - Removed latepay_refunded and doublepay_refunded from FAILED_PAYMENT_STATUSES
   - These are now in INITIAL_WAITING_STATUSES as they represent entry points

5. Fix mermaid diagram label
   - confirmed_overpay_not_refunded now correctly labeled as "Terminal Success (Not Refunded)"
   - Remove invalid received→expired transition from documentation

This improves the logical consistency of the state machine and aligns
the naming conventions across all status constants.
2025-09-30 14:34:11 -04:00
7625563f6a Fix invoice deletion test failures by adding missing mock setup
All invoice deletion tests were failing because they were missing the
mock setup for should_keep_invoice.return_value = False. This caused
the deletion logic to be skipped since the function would return early
when should_keep_invoice() returned the default MagicMock() value.

Changes:
- Added self.mock_crypto_payment.should_keep_invoice.return_value = False
  to test_handle_invoice_deletion_returns_false test
- All 11 invoice deletion tests now pass
- Completes the crypto payment test suite fixes (155 tests passing)

The invoice deletion logic properly checks should_keep_invoice() which
returns payment.is_successful_payment(), and failed payments should
have their invoices deleted while successful payments should keep them.
2025-09-30 14:13:35 -04:00
5686121ed5 Fix concurrent transaction detection for pending payments
When multiple transactions arrive simultaneously to a pending payment, treat ALL transactions as duplicates rather than processing the first one normally. This prevents potential attack scenarios where multiple payments are sent rapidly to the same quote.

- Modified duplicate detection logic to treat all concurrent transactions as suspicious
- Set new_sum=0 and new_txids=[] when all transactions become duplicates
- Removed recalculation logic that was processing first transaction
- Enhanced logging to reflect new behavior

Fixes test_double_spend_protection.py failures. All 130 crypto tests now pass.
2025-09-30 14:05:10 -04:00
5c67b9ca4c Fix all crypto payment test failures and status constant issues
- Fix duplicate detection logic to prevent amount accumulation when new transactions arrive to already-processed payments
- Fix status constant naming errors: STATUS_CONFIRMED_OVERPAID → STATUS_CONFIRMED_OVERPAY, STATUS_EXPIRED_REFUNDED → STATUS_LATEPAY_REFUNDED
- Fix SweepRestockingFeeTests mock setup: add missing refund_confirmations, get_coin_config patches, and proper XMR client mocks
- Correct overpayment test expectations: restocking fee sweep happens later after refund confirmation, not immediately
- Update test assertions to match actual implementation behavior (transfer vs sweep_all for XMR)
- Add comprehensive mock configurations for DOGE/XMR atomic units and balance methods

All 108 crypto payment tests now pass. Fixes critical duplicate payment processing bug and aligns test expectations with production behavior.
2025-09-30 13:56:42 -04:00
923bd873f2 Add comprehensive crypto payment state transition validation
* Implement complete state machine with 17 test scenarios
* Add priority-based processing order validation
* Include property-based testing for state transitions
* Add graph analysis for state machine integrity
* Validate all payment lifecycle paths
* Ensure robust error handling and logging
* Remove temporary debug files and consolidate test structure
2025-09-30 11:26:44 -04:00