Skip to content

Commit 4ba5904

Browse files
jeffdyerclaude
andcommitted
Add diagnostic logging to tryAutoRecharge
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 144aacd commit 4ba5904

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

src/lib/usage-service.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,16 @@ async function tryAutoRecharge(uid: string): Promise<boolean> {
9494
try {
9595
// Get billing settings
9696
const settingsDoc = await db.collection('users').doc(uid).collection('settings').doc('billing').get();
97-
if (!settingsDoc.exists) return false;
97+
if (!settingsDoc.exists) {
98+
console.log('Auto-recharge: no billing settings for user', uid);
99+
return false;
100+
}
98101

99102
const settings = settingsDoc.data();
100-
if (!settings?.autoRecharge) return false;
103+
if (!settings?.autoRecharge) {
104+
console.log('Auto-recharge: disabled for user', uid);
105+
return false;
106+
}
101107

102108
// Check monthly block limit — reset counter if last recharge was in a previous month
103109
let blocksUsed = settings.overageBlocksUsedThisPeriod || 0;
@@ -110,15 +116,24 @@ async function tryAutoRecharge(uid: string): Promise<boolean> {
110116
});
111117
}
112118
const limit = settings.autoRechargeLimit || 1;
113-
if (blocksUsed >= limit) return false;
119+
if (blocksUsed >= limit) {
120+
console.log('Auto-recharge: block limit reached for user', uid, blocksUsed, '>=', limit);
121+
return false;
122+
}
114123

115124
// Get user data
116125
const userDoc = await db.collection('users').doc(uid).get();
117126
const userData = userDoc.data();
118-
if (!userData?.stripeCustomerId) return false;
127+
if (!userData?.stripeCustomerId) {
128+
console.log('Auto-recharge: no Stripe customer for user', uid);
129+
return false;
130+
}
119131

120132
const plan = userData.subscription?.plan || 'demo';
121-
if (plan === 'demo') return false;
133+
if (plan === 'demo') {
134+
console.log('Auto-recharge: demo plan for user', uid);
135+
return false;
136+
}
122137

123138
const pricing = OVERAGE_PRICING[plan];
124139
if (!pricing) return false;

0 commit comments

Comments
 (0)