feat(pricing/ai): improve billing metered pricing + add pricing on ai chat (#14092)

## TODO:

- [x] display "yearly" or "monthly" wording everywhere it's needed
- [ ] Add button with "downgrade" or "upgrade" to save the change of
credits price + modal to validate
- [x] Add renewal date 
- [ ] Implement
https://docs.stripe.com/billing/subscriptions/subscription-schedules for
`switchFromYearlyToMonthly` and decrease number of credits
This commit is contained in:
Antoine Moreaux
2025-08-29 18:23:07 +02:00
committed by GitHub
parent 7df9094939
commit 1c4568c8b1
45 changed files with 2048 additions and 327 deletions
@@ -1,13 +1,9 @@
import { useSubscriptionStatus } from '@/workspace/hooks/useSubscriptionStatus';
import {
BillingProductKey,
SubscriptionStatus,
useGetMeteredProductsUsageQuery,
} from '~/generated-metadata/graphql';
export const useGetWorkflowNodeExecutionUsage = () => {
const subscriptionStatus = useSubscriptionStatus();
const { data, loading } = useGetMeteredProductsUsageQuery();
const workflowUsage = data?.getMeteredProductsUsage.find(
@@ -17,32 +13,15 @@ export const useGetWorkflowNodeExecutionUsage = () => {
if (loading === true || !workflowUsage) {
return {
usageQuantity: 0,
freeUsageQuantity: 0,
includedFreeQuantity: 10000,
paidUsageQuantity: 0,
usedCredits: 0,
grantedCredits: 10000,
unitPriceCents: 0,
totalCostCents: 0,
};
}
const includedFreeQuantity =
subscriptionStatus === SubscriptionStatus.Trialing
? workflowUsage.freeTrialQuantity
: workflowUsage.freeTierQuantity;
return {
usageQuantity: workflowUsage.usageQuantity,
freeUsageQuantity:
workflowUsage.usageQuantity > includedFreeQuantity
? includedFreeQuantity
: workflowUsage.usageQuantity,
includedFreeQuantity,
paidUsageQuantity:
workflowUsage.usageQuantity > includedFreeQuantity
? workflowUsage.usageQuantity - includedFreeQuantity
: 0,
usedCredits: workflowUsage.usedCredits,
grantedCredits: workflowUsage.grantedCredits,
unitPriceCents: workflowUsage.unitPriceCents,
totalCostCents: workflowUsage.totalCostCents,
};
};