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
This commit is contained in:
@@ -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'];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user