fix: remove hardcoded subscription ID and rely on API queries

- Removed hardcoded subscription ID from code
- Rely on API queries to find subscriptions by customer or through fallback search
- Added proper logging to diagnose customer/subscription mismatches
This commit is contained in:
southseact-3d
2026-02-12 11:51:51 +00:00
parent 8e937a6ff4
commit 1e30e07ed5

View File

@@ -12240,55 +12240,6 @@ 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'];