fix(stripe): remove dead syncUserPlan call to deleted backend /api/users/:userId/plan route
The Python backend users.py route was deleted in the backend cleanup. Plan updates are already handled by authRepo.updatePlan() inline in each webhook handler — the syncUserPlan fetch was redundant dead code.
This commit is contained in:
parent
d829c41fd4
commit
daccbaea6c
@ -20,26 +20,6 @@ import * as authRepo from '../auth/repository.js';
|
||||
import * as subRepo from '../subscriptions/repository.js';
|
||||
import type { SubscriptionDoc } from '../subscriptions/types.js';
|
||||
|
||||
const BACKEND_URL = process.env.BACKEND_URL || 'http://localhost:8000';
|
||||
|
||||
/** Sync plan change back to the backend users container (best-effort). */
|
||||
async function syncUserPlan(
|
||||
userId: string,
|
||||
plan: string,
|
||||
log?: { warn: (...args: unknown[]) => void }
|
||||
): Promise<void> {
|
||||
try {
|
||||
await fetch(`${BACKEND_URL}/api/users/${userId}/plan`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ plan }),
|
||||
});
|
||||
} catch (err) {
|
||||
// Best-effort — don't fail the webhook if backend is unreachable
|
||||
(log ?? console).warn(`Failed to sync plan to backend for ${userId}:`, err);
|
||||
}
|
||||
}
|
||||
|
||||
export async function stripeRoutes(app: FastifyInstance) {
|
||||
// ── Checkout ──────────────────────────────────────────────
|
||||
app.post('/stripe/checkout', async (req, reply) => {
|
||||
@ -153,9 +133,6 @@ export async function stripeRoutes(app: FastifyInstance) {
|
||||
await authRepo.updatePlan(userId, eventProductId, plan as SubscriptionDoc['plan']);
|
||||
}
|
||||
|
||||
// Sync plan to backend users container
|
||||
await syncUserPlan(userId, plan, app.log);
|
||||
|
||||
// Record payment
|
||||
if (session.amount_total && session.amount_total > 0) {
|
||||
await subRepo.createPayment({
|
||||
@ -195,8 +172,6 @@ export async function stripeRoutes(app: FastifyInstance) {
|
||||
currentPeriodEnd: new Date(sub.current_period_end * 1000).toISOString(),
|
||||
});
|
||||
await authRepo.updatePlan(existing.userId, effectiveProductId, updatedPlan);
|
||||
// Sync plan to backend users container
|
||||
await syncUserPlan(existing.userId, updatedPlan, app.log);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -215,8 +190,6 @@ export async function stripeRoutes(app: FastifyInstance) {
|
||||
cancelAtPeriodEnd: false,
|
||||
});
|
||||
await authRepo.updatePlan(existing.userId, effectiveProductId, 'free');
|
||||
// Sync plan downgrade to backend users container
|
||||
await syncUserPlan(existing.userId, 'free', app.log);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user