add billing threshold + specific trial free credits (#11533)
In this PR : - set billing thresholds after subscription creation (not possible during billing checkout) - add specific free trial workflow credit quantities + set them in subscription item + check them when receiving stripe alert event closes : https://github.com/twentyhq/core-team-issues/issues/682
This commit is contained in:
@ -147,7 +147,8 @@ export type BillingEndTrialPeriodOutput = {
|
||||
|
||||
export type BillingMeteredProductUsageOutput = {
|
||||
__typename?: 'BillingMeteredProductUsageOutput';
|
||||
includedFreeQuantity: Scalars['Float'];
|
||||
freeTierQuantity: Scalars['Float'];
|
||||
freeTrialQuantity: Scalars['Float'];
|
||||
periodEnd: Scalars['DateTime'];
|
||||
periodStart: Scalars['DateTime'];
|
||||
productKey: BillingProductKey;
|
||||
@ -2587,7 +2588,7 @@ export type EndSubscriptionTrialPeriodMutation = { __typename?: 'Mutation', endS
|
||||
export type GetMeteredProductsUsageQueryVariables = Exact<{ [key: string]: never; }>;
|
||||
|
||||
|
||||
export type GetMeteredProductsUsageQuery = { __typename?: 'Query', getMeteredProductsUsage: Array<{ __typename?: 'BillingMeteredProductUsageOutput', productKey: BillingProductKey, usageQuantity: number, includedFreeQuantity: number, unitPriceCents: number, totalCostCents: number }> };
|
||||
export type GetMeteredProductsUsageQuery = { __typename?: 'Query', getMeteredProductsUsage: Array<{ __typename?: 'BillingMeteredProductUsageOutput', productKey: BillingProductKey, usageQuantity: number, freeTierQuantity: number, freeTrialQuantity: number, unitPriceCents: number, totalCostCents: number }> };
|
||||
|
||||
export type SwitchSubscriptionToYearlyIntervalMutationVariables = Exact<{ [key: string]: never; }>;
|
||||
|
||||
@ -4252,7 +4253,8 @@ export const GetMeteredProductsUsageDocument = gql`
|
||||
getMeteredProductsUsage {
|
||||
productKey
|
||||
usageQuantity
|
||||
includedFreeQuantity
|
||||
freeTierQuantity
|
||||
freeTrialQuantity
|
||||
unitPriceCents
|
||||
totalCostCents
|
||||
}
|
||||
|
||||
@ -5,7 +5,8 @@ export const GET_METERED_PRODUCTS_USAGE = gql`
|
||||
getMeteredProductsUsage {
|
||||
productKey
|
||||
usageQuantity
|
||||
includedFreeQuantity
|
||||
freeTierQuantity
|
||||
freeTrialQuantity
|
||||
unitPriceCents
|
||||
totalCostCents
|
||||
}
|
||||
|
||||
@ -1,9 +1,13 @@
|
||||
import { useSubscriptionStatus } from '@/workspace/hooks/useSubscriptionStatus';
|
||||
import {
|
||||
BillingProductKey,
|
||||
SubscriptionStatus,
|
||||
useGetMeteredProductsUsageQuery,
|
||||
} from '~/generated/graphql';
|
||||
|
||||
export const useGetWorkflowNodeExecutionUsage = () => {
|
||||
const subscriptionStatus = useSubscriptionStatus();
|
||||
|
||||
const { data, loading } = useGetMeteredProductsUsageQuery();
|
||||
|
||||
const workflowUsage = data?.getMeteredProductsUsage.find(
|
||||
@ -22,16 +26,21 @@ export const useGetWorkflowNodeExecutionUsage = () => {
|
||||
};
|
||||
}
|
||||
|
||||
const includedFreeQuantity =
|
||||
subscriptionStatus === SubscriptionStatus.Trialing
|
||||
? workflowUsage.freeTrialQuantity
|
||||
: workflowUsage.freeTierQuantity;
|
||||
|
||||
return {
|
||||
usageQuantity: workflowUsage.usageQuantity,
|
||||
freeUsageQuantity:
|
||||
workflowUsage.usageQuantity > workflowUsage.includedFreeQuantity
|
||||
? workflowUsage.includedFreeQuantity
|
||||
workflowUsage.usageQuantity > includedFreeQuantity
|
||||
? includedFreeQuantity
|
||||
: workflowUsage.usageQuantity,
|
||||
includedFreeQuantity: workflowUsage.includedFreeQuantity,
|
||||
includedFreeQuantity,
|
||||
paidUsageQuantity:
|
||||
workflowUsage.usageQuantity > workflowUsage.includedFreeQuantity
|
||||
? workflowUsage.usageQuantity - workflowUsage.includedFreeQuantity
|
||||
workflowUsage.usageQuantity > includedFreeQuantity
|
||||
? workflowUsage.usageQuantity - includedFreeQuantity
|
||||
: 0,
|
||||
unitPriceCents: workflowUsage.unitPriceCents,
|
||||
totalCostCents: workflowUsage.totalCostCents,
|
||||
|
||||
Reference in New Issue
Block a user