Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprocate getProductPrices query in front end #10397

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

anamarn
Copy link
Contributor

@anamarn anamarn commented Feb 21, 2025

TLDR:
Deprecate getProductPrices in the frontEnd and replace it with BillingBaseProductPrices.

In order to test:

  • Have the environment variable IS_BILLING_ENABLED set to true and add the other required environment variables for Billing to work
  • Do a database reset (to ensure that the new feature flag is properly added and that the billing tables are created)
  • Run the command: npx nx run twenty-server:command billing:sync-plans-data (if you don't do that the products and prices will not be present in the database)
  • Run the server , the frontend, the worker, and the stripe listen command (stripe listen --forward-to http://localhost:3000/billing/webhooks)
  • Buy a subscription for acme workspace the choose your plan should be using the new front end endpoint

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This PR deprecates the getProductPrices query in favor of a new BillingBaseProductPrices query, streamlining the billing system's architecture.

  • Added new BILLING_BASE_PRODUCT_PRICES query in /packages/twenty-front/src/modules/billing/graphql/billingBaseProductPrices.ts to fetch plan-based pricing information
  • Added getPlanKeyFromSubscription utility in /packages/twenty-server/src/engine/core-modules/billing/utils/get-plan-key-from-subscription.util.ts to dynamically map subscription metadata to plan keys
  • Updated ChooseYourPlan component to use the new query structure with plan-based filtering
  • Improved error messaging in billing-plan.service.ts to guide users on running billing:sync-products command when base product is missing
  • Removed deprecated BillingProductPricesOutput DTO and related query implementations

9 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines +100 to +109
const baseProductPrices = plans?.plans
?.find((plan) => plan.planKey === BillingPlanKey.PRO)
?.baseProduct.prices?.filter(
(
price,
): price is NonNullable<typeof price> & {
recurringInterval: SubscriptionInterval;
unitAmount: number;
} => price !== null && 'recurringInterval' in price,
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Type guard could fail silently if price has unitAmount but not recurringInterval. Consider splitting the type check.

Suggested change
const baseProductPrices = plans?.plans
?.find((plan) => plan.planKey === BillingPlanKey.PRO)
?.baseProduct.prices?.filter(
(
price,
): price is NonNullable<typeof price> & {
recurringInterval: SubscriptionInterval;
unitAmount: number;
} => price !== null && 'recurringInterval' in price,
);
const baseProductPrices = plans?.plans
?.find((plan) => plan.planKey === BillingPlanKey.PRO)
?.baseProduct.prices?.filter(
(
price,
): price is NonNullable<typeof price> & {
recurringInterval: SubscriptionInterval;
unitAmount: number;
} => price !== null && 'recurringInterval' in price && 'unitAmount' in price,
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant