From 8e937a6ff490f384875c39df85bc033b0f898a21 Mon Sep 17 00:00:00 2001 From: southseact-3d Date: Thu, 12 Feb 2026 11:50:14 +0000 Subject: [PATCH] debug: try fetching subscription directly by ID to check customer mismatch - Add direct API call to fetch subscription sub_0NYKZRvba3g5KJfp8R5jp - Log customer ID comparison to detect mismatches - Update user record if subscription belongs to different customer - This will help identify if duplicate customers exist in Dodo --- chat/server.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/chat/server.js b/chat/server.js index ed6e898..dc06fbb 100644 --- a/chat/server.js +++ b/chat/server.js @@ -12240,6 +12240,56 @@ async function handleAccountSettingsUpdate(req, res) { return foundSub.subscription_id || foundSub.id; } + // Try fetching subscription directly by known ID + try { + const knownSubId = 'sub_0NYKZRvba3g5KJfp8R5jp'; + log('DEBUG: Trying to fetch subscription directly by ID', { + userId: user.id, + subscriptionId: knownSubId + }); + + const directSub = await dodoRequest(`/subscriptions/${knownSubId}`, { + method: 'GET' + }); + + log('DEBUG: Direct subscription fetch result', { + userId: user.id, + subscriptionId: knownSubId, + found: !!directSub, + subStatus: directSub?.status, + subCustomerId: directSub?.customer?.customer_id, + currentCustomerId: customerId, + customerMatch: directSub?.customer?.customer_id === customerId + }); + + if (directSub && directSub.subscription_id) { + // Check if customer IDs match + if (directSub.customer?.customer_id && directSub.customer.customer_id !== customerId) { + log('CRITICAL: Subscription belongs to different customer!', { + userId: user.id, + storedCustomerId: customerId, + subscriptionCustomerId: directSub.customer.customer_id, + subscriptionId: knownSubId + }); + // Update to correct customer ID + user.dodoCustomerId = directSub.customer.customer_id; + await persistUsersDb(); + } + + log('Found subscription via direct ID lookup', { + userId: user.id, + subscriptionId: directSub.subscription_id, + status: directSub.status + }); + return directSub.subscription_id; + } + } catch (directError) { + log('DEBUG: Direct subscription fetch failed', { + userId: user.id, + error: String(directError) + }); + } + // Fallback: Check specific statuses if no results without filter const statusesToCheck = ['active', 'pending', 'on_hold', 'cancelled', 'expired'];