Comprehensive fixes to prevent customer ID mismatches: 1. **Checkout creation now passes customer_id** (lines 13669, 13064, 13503): - All checkouts (subscription, topup, PAYG) now call ensureDodoCustomer() first - Pass existing customer_id to checkout body to prevent Dodo from creating duplicates - Added customerId to metadata for tracking 2. **Subscription confirmation validates customer consistency** (line 13843): - Logs warning when checkout returns different customer_id than stored - Tracks which customer_id was used in checkout metadata - Prevents silent customer ID overwrites 3. **ensureDodoCustomer handles multiple customers per email** (line 6774): - Logs warning when multiple customers found for same email - Checks ALL customers for active subscriptions - Selects customer with active subscriptions if multiple exist - Returns first customer only if no active subscriptions found 4. **Added missing return statements** (lines 12417, 12448): - Prevents double response errors after successful plan changes This ensures that: - New subscriptions use existing customers instead of creating duplicates - Plan changes work correctly even with multiple subscriptions - Customer ID mismatches are detected and logged - The correct customer (one with active subscriptions) is always used
729 KiB
729 KiB