Files
sealos/service/pkg
Jiahui f2bb5a88b4 fix(account): prevent multi-region conflicts in invoice.created webhook handling (#6565)
This commit resolves the issue where multiple regions simultaneously process
the same invoice.created event, causing Stripe API errors:
"This invoice is already finalized, you can't re-finalize a non-draft invoice."

Changes:
1. Add region check in handleWorkspaceSubscriptionInvoiceCreated
   - Only process events belonging to the current region
   - Skip events from other regions with appropriate logging
   - Use existing checkIsLocalEvent function for consistency

2. Add fault tolerance in ConfirmInvoice for FinalizeInvoice
   - Detect "already finalized" errors gracefully
   - Re-fetch invoice status when finalized by another region
   - Continue processing instead of failing

Impact:
- Eliminates race conditions in multi-region deployments
- Ensures only one region processes each invoice.created event
- Provides graceful fallback for edge cases
- Maintains backward compatibility with idempotent behavior

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

Co-authored-by: Claude <noreply@anthropic.com>
2026-01-22 10:38:50 +08:00
..