* wip * fix: claue reveiew commentsd * add seed test * fix: seed test plus subscriptin undefined in webhook * chore: udpate triggr * Integration test + HWM seed script * add feature flag for hmw * Remove redudant docs * feat: add hwm-seating feature flag for high water mark billing - Add new hwm-seating feature flag to control HWM billing logic - Update HighWaterMarkService to use hwm-seating flag - Update SeatChangeTrackingService to use hwm-seating flag - Update BillingPeriodService to use hwm-seating flag - Add flag to migration SQL - Enable flag in seed script and integration test Co-Authored-By: Claude Opus 4.5 <[email protected]> * fix: add hwm-seating to useFlags and fix test mocks - Add hwm-seating to useFlags.ts initial data - Add shouldApplyHighWaterMark mock to TeamBillingService tests Co-Authored-By: Claude Opus 4.5 <[email protected]> * fix test * feat: move to invoice paid subscription * fix: transactions for transiants updates + reusable util * fix: address Cubic AI review feedback for HWM billing - Fix dotenv import hoisting in seed-hwm-test.ts by using side-effect import - Remove logging of sensitive information (password/emails) in seed script - Fix incorrect newHighWaterMark return value when update is not performed Co-Authored-By: unknown <> * add additional unit tests * improve DI * fix migration + restore package.json trigger update * feat:move to featurerepo+update tests * fix mocks * fix DI calls * revert faeturerepo to featuresrepository * fix: pass featureRepository to BillingPeriodService and HighWaterMarkService - Fix TeamBillingService.ts: pass featureRepository to BillingPeriodService constructor - Fix _invoice.upcoming.ts: pass featureRepository to HighWaterMarkService constructor - Fix hwm-webhook-utils.ts: pass featureRepository to HighWaterMarkService constructor These services require featureRepository for feature flag checks but production call sites were missing this required dependency, causing runtime errors. Addresses Cubic AI review feedback on PR #27559 Co-Authored-By: unknown <> * fix import * update feature repo usage to features * remove test thats mocking the wrong stuff * revert RegularBookingService changes * remove hide branding * remove change in redudant file --------- Co-authored-by: Claude Opus 4.5 <[email protected]> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
58 lines
1.8 KiB
TypeScript
58 lines
1.8 KiB
TypeScript
import { getBillingProviderService } from "@calcom/features/ee/billing/di/containers/Billing";
|
|
import { HighWaterMarkService } from "@calcom/features/ee/billing/service/highWaterMark/HighWaterMarkService";
|
|
import logger from "@calcom/lib/logger";
|
|
|
|
import type { SWHMap } from "./__handler";
|
|
|
|
type Data = SWHMap["invoice.upcoming"]["data"];
|
|
|
|
const log = logger.getSubLogger({ prefix: ["stripe-webhook-invoice-upcoming"] });
|
|
|
|
const handler = async (data: Data) => {
|
|
const invoice = data.object;
|
|
|
|
// Only handle subscription invoices
|
|
if (!invoice.subscription) {
|
|
log.debug("Not a subscription invoice, skipping");
|
|
return { success: false, message: "Not a subscription invoice" };
|
|
}
|
|
|
|
const subscriptionId =
|
|
typeof invoice.subscription === "string" ? invoice.subscription : invoice.subscription.id;
|
|
|
|
log.info("Processing invoice.upcoming webhook", {
|
|
invoiceId: invoice.id,
|
|
subscriptionId,
|
|
customerId: typeof invoice.customer === "string" ? invoice.customer : invoice.customer?.id,
|
|
});
|
|
|
|
const billingService = getBillingProviderService();
|
|
const highWaterMarkService = new HighWaterMarkService({
|
|
logger: log,
|
|
billingService,
|
|
});
|
|
|
|
try {
|
|
const applied = await highWaterMarkService.applyHighWaterMarkToSubscription(subscriptionId);
|
|
|
|
if (applied) {
|
|
log.info("Successfully applied high water mark before renewal", {
|
|
subscriptionId,
|
|
});
|
|
return { success: true, highWaterMarkApplied: true };
|
|
}
|
|
|
|
log.debug("No high water mark update needed", { subscriptionId });
|
|
return { success: true, highWaterMarkApplied: false };
|
|
} catch (error) {
|
|
log.error("Failed to apply high water mark", {
|
|
subscriptionId,
|
|
error,
|
|
});
|
|
// Return success: false but don't throw - we don't want to fail the webhook
|
|
return { success: false, error: String(error) };
|
|
}
|
|
};
|
|
|
|
export default handler;
|