diff --git a/.env.example b/.env.example
index ddd0dd9e9b..dee4d6d081 100644
--- a/.env.example
+++ b/.env.example
@@ -201,6 +201,7 @@ NEXT_PUBLIC_STRIPE_PREMIUM_PLAN_PRICE=
NEXT_PUBLIC_IS_PREMIUM_NEW_PLAN=0
NEXT_PUBLIC_STRIPE_PREMIUM_NEW_PLAN_PRICE=
STRIPE_TEAM_MONTHLY_PRICE_ID=
+NEXT_PUBLIC_STRIPE_CREDITS_PRICE_ID=
STRIPE_TEAM_PRODUCT_ID=
# It is a price ID in the product with id STRIPE_ORG_PRODUCT_ID
STRIPE_ORG_MONTHLY_PRICE_ID=
diff --git a/.github/workflows/cron-checkSmsPrices.yml b/.github/workflows/cron-checkSmsPrices.yml
new file mode 100644
index 0000000000..3275314adb
--- /dev/null
+++ b/.github/workflows/cron-checkSmsPrices.yml
@@ -0,0 +1,23 @@
+name: Cron - checkSmsPrices
+
+on:
+ # "Scheduled workflows run on the latest commit on the default or base branch."
+ # — https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows#schedule
+ schedule:
+ # Runs “every minute” (see https://crontab.guru)
+ - cron: "* * * * *"
+jobs:
+ cron-checkSmsPrices:
+ env:
+ APP_URL: ${{ secrets.APP_URL }}
+ CRON_API_KEY: ${{ secrets.CRON_API_KEY }}
+ runs-on: ubuntu-latest
+ steps:
+ - name: cURL request
+ if: ${{ env.APP_URL && env.CRON_API_KEY }}
+ run: |
+ curl ${{ secrets.APP_URL }}/api/cron/checkSmsPrices \
+ -X POST \
+ -H 'content-type: application/json' \
+ -H 'authorization: ${{ secrets.CRON_API_KEY }}' \
+ --fail
diff --git a/apps/web/app/api/cron/checkSmsPrices/route.ts b/apps/web/app/api/cron/checkSmsPrices/route.ts
new file mode 100644
index 0000000000..efddc35487
--- /dev/null
+++ b/apps/web/app/api/cron/checkSmsPrices/route.ts
@@ -0,0 +1,112 @@
+import { defaultResponderForAppDir } from "app/api/defaultResponderForAppDir";
+import type { NextRequest } from "next/server";
+import { NextResponse } from "next/server";
+
+import dayjs from "@calcom/dayjs";
+import * as twilio from "@calcom/features/ee/workflows/lib/reminders/providers/twilioProvider";
+import { IS_SMS_CREDITS_ENABLED } from "@calcom/lib/constants";
+import logger from "@calcom/lib/logger";
+import prisma from "@calcom/prisma";
+import { CreditType } from "@calcom/prisma/enums";
+
+async function postHandler(req: NextRequest) {
+ const apiKey = req.headers.get("authorization") || req.nextUrl.searchParams.get("apiKey");
+
+ if (process.env.CRON_API_KEY !== apiKey) {
+ return NextResponse.json({ message: "Not authenticated" }, { status: 401 });
+ }
+
+ if (!IS_SMS_CREDITS_ENABLED) {
+ return NextResponse.json({ ok: true, message: "SMS credits not enabled" });
+ }
+
+ const smsLogsWithoutPrice = await prisma.creditExpenseLog.findMany({
+ where: {
+ credits: null,
+ smsSid: {
+ not: null,
+ },
+ date: {
+ gte: dayjs().subtract(1, "hour").toDate(),
+ },
+ },
+ select: {
+ smsSid: true,
+ id: true,
+ },
+ });
+
+ let pricesUpdated = 0;
+ const { CreditService } = await import("@calcom/features/ee/billing/credit-service");
+
+ const creditService = new CreditService();
+
+ await Promise.allSettled(
+ smsLogsWithoutPrice.map(async (log) => {
+ if (!log.smsSid) return;
+
+ try {
+ const price = await twilio.getPriceForSMS(log.smsSid);
+ const credits = price ? creditService.calculateCreditsFromPrice(price) : null;
+ if (!credits) return;
+
+ const updatedLog = await prisma.creditExpenseLog.update({
+ where: { id: log.id },
+ data: { credits },
+ select: {
+ creditBalance: {
+ select: {
+ id: true,
+ additionalCredits: true,
+ teamId: true,
+ },
+ },
+ creditType: true,
+ },
+ });
+
+ if (updatedLog.creditType === CreditType.ADDITIONAL) {
+ const decrementValue =
+ credits <= updatedLog.creditBalance.additionalCredits
+ ? credits
+ : updatedLog.creditBalance.additionalCredits;
+
+ await prisma.creditBalance.update({
+ where: { id: updatedLog.creditBalance.id },
+ data: {
+ additionalCredits: {
+ decrement: decrementValue,
+ },
+ },
+ });
+ }
+
+ if (!updatedLog.creditBalance.teamId) {
+ logger.error(`teamId missing for expense log ${log.id}`);
+ return;
+ }
+
+ const teamCredits = await creditService.getAllCreditsForTeam(updatedLog.creditBalance.teamId);
+
+ const remainingMonthlyCredits = Math.max(0, teamCredits.totalRemainingMonthlyCredits);
+
+ await creditService.handleLowCreditBalance({
+ teamId: updatedLog.creditBalance.teamId ?? 0,
+ remainingCredits: remainingMonthlyCredits + teamCredits.additionalCredits,
+ });
+
+ pricesUpdated++;
+ } catch (err) {
+ logger.error(`Failed to process SMS log ${log.smsSid}`, err);
+ await prisma.creditExpenseLog.update({
+ where: { id: log.id },
+ data: { credits: 0 },
+ });
+ }
+ })
+ );
+
+ return NextResponse.json({ ok: true, pricesUpdated });
+}
+
+export const POST = defaultResponderForAppDir(postHandler);
diff --git a/apps/web/modules/settings/billing/billing-view.tsx b/apps/web/modules/settings/billing/billing-view.tsx
index 25e0bbf435..d1098b9027 100644
--- a/apps/web/modules/settings/billing/billing-view.tsx
+++ b/apps/web/modules/settings/billing/billing-view.tsx
@@ -4,8 +4,10 @@ import { usePathname } from "next/navigation";
import { WEBAPP_URL } from "@calcom/lib/constants";
import { useLocale } from "@calcom/lib/hooks/useLocale";
-import { Button } from "@calcom/ui/components/button";
import classNames from "@calcom/ui/classNames";
+import { Button } from "@calcom/ui/components/button";
+
+import BillingCredits from "~/settings/billing/components/BillingCredits";
interface CtaRowProps {
title: string;
@@ -58,9 +60,9 @@ const BillingView = () => {
{t("billing_portal")}
-
-
-
+
+
+