Update credit_billing.ts

This commit is contained in:
Nicolas 2024-10-16 01:06:10 -03:00
parent ffbf16048f
commit e5a5ca2446

View File

@ -58,10 +58,12 @@ export async function supaCheckTeamCredits(chunk: AuthCreditUsageChunk, team_id:
// In case chunk.price_credits is undefined, set it to a large number to avoid mistakes
const totalPriceCredits = chunk.price_credits ?? 100000000;
// Removal of + credits
const creditUsagePercentage = creditsWillBeUsed / totalPriceCredits;
const creditUsagePercentage = chunk.adjusted_credits_used / totalPriceCredits;
// Compare the adjusted total credits used with the credits allowed by the plan
if (creditsWillBeUsed > totalPriceCredits) {
// Only notify if their actual credits (not what they will use) used is greater than the total price credits
if(chunk.adjusted_credits_used > totalPriceCredits) {
sendNotification(
team_id,
NotificationType.LIMIT_REACHED,
@ -69,6 +71,7 @@ export async function supaCheckTeamCredits(chunk: AuthCreditUsageChunk, team_id:
chunk.sub_current_period_end,
chunk
);
}
return { success: false, message: "Insufficient credits. For more credits, you can upgrade your plan at https://firecrawl.dev/pricing.", remainingCredits: chunk.remaining_credits, chunk };
} else if (creditUsagePercentage >= 0.8 && creditUsagePercentage < 1) {
// Send email notification for approaching credit limit