Skip to content

fix: prevent quota exhaustion and improve payment/payout reliability - #1296

Closed
maikNeta wants to merge 2 commits into
Smartdevs17:mainfrom
maikNeta:fix/issues-1024-1159-1160-1162-payout-gateway-reliability
Closed

maikNeta wants to merge 2 commits into
Smartdevs17:mainfrom
maikNeta:fix/issues-1024-1159-1160-1162-payout-gateway-reliability

Conversation

@maikNeta

Copy link
Copy Markdown
Contributor

Summary

This PR addresses critical issues in payment retry logic, gateway integration reliability, payment correctness, and payout handling.

Changes

  1. Issue Fix failed payout retry exhausting provider quota #1024: Fix failed payout retry exhausting provider quota

    • Added QuotaService to track provider request quotas (hourly and daily limits)
    • Implements quota enforcement in PaymentRetryService to prevent exhausting provider limits
    • Quota tracking prevents retry loops from overwhelming providers
    • Supports configurable burst limits and automatic reset
  2. Issue Improve gateway integrations (iteration 6) #1162: Improve gateway integrations (iteration 6)

    • Created GatewayIntegrationService with enhanced error classification
    • Implements circuit breaker pattern for provider resilience
    • Adds request deduplication and caching for idempotent operations
    • Provides granular error handling (rate limit, timeout, auth, etc.)
  3. Issue Fix payment correctness bugs (iteration 5) #1159: Fix payment correctness bugs (iteration 5)

    • Added PaymentCorrectnessService for payment state validation
    • Enforces valid state transitions (pending → processing/cancelled, etc.)
    • Validates payment records for data consistency
    • Provides consistency reporting and automatic cleanup of old records
  4. Issue Improve payout reliability (iteration 6) #1160: Improve payout reliability (iteration 6)

    • Created PayoutReliabilityService with idempotency support
    • Detects and recovers stuck payouts
    • Tracks payout attempts and status transitions
    • Provides metrics on success rates and stuck payouts
    • Prevents duplicate payouts via idempotency keys

Technical Details

  • QuotaService: Tracks per-provider request counts, resets hourly/daily
  • GatewayIntegrationService: Circuit breaker (5 failures → open for 60s), error classification, request caching
  • PaymentCorrectnessService: Enforces valid state machine transitions, validates payment data
  • PayoutReliabilityService: Idempotent payout creation, stuck payout detection (1hr timeout), max 5 retry attempts

All services are designed to be thread-safe and work with async operations.

Testing

  • Quota service tested with rate limit scenarios
  • Payment state transitions validated against state machine
  • Payout idempotency verified with duplicate requests
  • Circuit breaker tested with failure scenarios

Closes #1024
Closes #1159
Closes #1160
Closes #1162

…cument key rotation windows

- fiat-crypto: bind a rate lock to the user who created it and consume it on
  first use, so the same lock can no longer be confirmed twice (duplicate
  conversions) or confirmed by a different user than the one who locked it.
- webhooks: add an in-flight guard around the delivery worker's 1s ticker so
  a slow or backlogged pass can never overlap with the next tick and deliver
  the same webhook twice.
- WEBHOOK_VERIFICATION.md: document the overlap/retention/replay-tolerance
  windows WebhookKeyRegistry actually enforces during key rotation, which
  were implemented but never written down.

Closes #1278,
Closes #1279,
Closes #1280,
Closes #1281.
…fix payment correctness, enhance payout reliability
@vercel

vercel Bot commented Oct 17, 2026

Copy link
Copy Markdown

@maikNeta is attempting to deploy a commit to the smartdevs17's projects Team on Vercel.

A member of the Team first needs to authorize it.

@maikNeta

Copy link
Copy Markdown
Contributor Author

Closed in favor of focused PR #1297 which properly integrates with upstream #1295

@maikNeta maikNeta closed this Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant