From fcf4fe03de0f0bd96ffab39bcea3d86f30c28180 Mon Sep 17 00:00:00 2001 From: Dotan Simha Date: Mon, 25 Mar 2024 10:50:26 +0200 Subject: [PATCH] Bug fixes for subscription management page (#4326) --- .../api/src/modules/billing/module.graphql.ts | 1 + .../api/src/modules/billing/resolvers.ts | 29 +++++ .../view/manage-subscription.tsx | 112 ++++++++++-------- .../[organizationId]/view/subscription.tsx | 1 + .../billing/BillingPaymentMethod.tsx | 6 +- 5 files changed, 94 insertions(+), 55 deletions(-) diff --git a/packages/services/api/src/modules/billing/module.graphql.ts b/packages/services/api/src/modules/billing/module.graphql.ts index 3618c8cf8..c0e7ede3d 100644 --- a/packages/services/api/src/modules/billing/module.graphql.ts +++ b/packages/services/api/src/modules/billing/module.graphql.ts @@ -8,6 +8,7 @@ export default gql` type BillingConfiguration { hasActiveSubscription: Boolean! + canUpdateSubscription: Boolean! hasPaymentIssues: Boolean! paymentMethod: BillingPaymentMethod billingAddress: BillingDetails diff --git a/packages/services/api/src/modules/billing/resolvers.ts b/packages/services/api/src/modules/billing/resolvers.ts index af4460cf1..1c2df3891 100644 --- a/packages/services/api/src/modules/billing/resolvers.ts +++ b/packages/services/api/src/modules/billing/resolvers.ts @@ -40,6 +40,18 @@ export const resolvers: BillingModule.Resolvers = { Organization: { plan: org => (org.billingPlan || 'HOBBY') as BillingPlanType, billingConfiguration: async (org, _args, { injector }) => { + if (org.billingPlan === 'ENTERPRISE') { + return { + hasActiveSubscription: true, + canUpdateSubscription: false, + hasPaymentIssues: false, + paymentMethod: null, + billingAddress: null, + invoices: null, + upcomingInvoice: null, + }; + } + const billingRecord = await injector .get(BillingProvider) .getOrganizationBillingParticipant({ organization: org.id }); @@ -47,6 +59,21 @@ export const resolvers: BillingModule.Resolvers = { if (!billingRecord) { return { hasActiveSubscription: false, + canUpdateSubscription: true, + hasPaymentIssues: false, + paymentMethod: null, + billingAddress: null, + invoices: null, + upcomingInvoice: null, + }; + } + + // This is a special case where customer is on Pro and doesn't have a record for external billing. + // This happens when the customer is paying through an external system and not through Stripe. + if (org.billingPlan === 'PRO' && billingRecord.externalBillingReference === 'wire') { + return { + hasActiveSubscription: true, + canUpdateSubscription: false, hasPaymentIssues: false, paymentMethod: null, billingAddress: null, @@ -62,6 +89,7 @@ export const resolvers: BillingModule.Resolvers = { if (!subscriptionInfo) { return { hasActiveSubscription: false, + canUpdateSubscription: true, hasPaymentIssues: false, paymentMethod: null, billingAddress: null, @@ -85,6 +113,7 @@ export const resolvers: BillingModule.Resolvers = { return { hasActiveSubscription: subscriptionInfo.subscription !== null, + canUpdateSubscription: subscriptionInfo.subscription !== null, hasPaymentIssues, paymentMethod: subscriptionInfo.paymentMethod?.card || null, billingAddress: subscriptionInfo.paymentMethod?.billing_details || null, diff --git a/packages/web/app/pages/[organizationId]/view/manage-subscription.tsx b/packages/web/app/pages/[organizationId]/view/manage-subscription.tsx index a4273a838..b7fd8fcae 100644 --- a/packages/web/app/pages/[organizationId]/view/manage-subscription.tsx +++ b/packages/web/app/pages/[organizationId]/view/manage-subscription.tsx @@ -27,6 +27,7 @@ const ManageSubscriptionInner_OrganizationFragment = graphql(` } billingConfiguration { hasPaymentIssues + canUpdateSubscription paymentMethod { __typename } @@ -324,7 +325,10 @@ function Inner(props: { Choose Your Plan - {plan === BillingPlanType.Pro && ( -
- Define your reserved volume -

- Pro plan requires to defined quota of reported operations. -

-

- Pick a volume a little higher than you think you'll need to avoid being rate - limited. -

-

- Don't worry, you can always adjust it later. -

-
- -
- 1M - 100M - 200M - 300M + {plan === BillingPlanType.Pro && + organization.billingConfiguration.canUpdateSubscription && ( +
+ Define your reserved volume +

+ Pro plan requires to defined quota of reported operations. +

+

+ Pick a volume a little higher than you think you'll need to avoid being rate + limited. +

+

+ Don't worry, you can always adjust it later. +

+
+ +
+ 1M + 100M + 200M + 300M +
-
- )} + )} -
- -
- {plan === BillingPlanType.Pro && plan !== organization.plan ? ( -
- Discount - setCouponCode(e.target.value)} - placeholder="Code" - /> -
- ) : null} -
-
{error && }
{renderActions()}
+ + {organization.billingConfiguration.canUpdateSubscription ? ( +
+ +
+ {plan === BillingPlanType.Pro && plan !== organization.plan ? ( +
+ Discount + setCouponCode(e.target.value)} + placeholder="Code" + /> +
+ ) : null} +
+
+ ) : null}
diff --git a/packages/web/app/pages/[organizationId]/view/subscription.tsx b/packages/web/app/pages/[organizationId]/view/subscription.tsx index 90134ab6a..46a51fbe6 100644 --- a/packages/web/app/pages/[organizationId]/view/subscription.tsx +++ b/packages/web/app/pages/[organizationId]/view/subscription.tsx @@ -31,6 +31,7 @@ const SubscriptionPage_OrganizationFragment = graphql(` } billingConfiguration { hasPaymentIssues + canUpdateSubscription invoices { id } diff --git a/packages/web/app/src/components/organization/billing/BillingPaymentMethod.tsx b/packages/web/app/src/components/organization/billing/BillingPaymentMethod.tsx index 17b6de477..c31c39160 100644 --- a/packages/web/app/src/components/organization/billing/BillingPaymentMethod.tsx +++ b/packages/web/app/src/components/organization/billing/BillingPaymentMethod.tsx @@ -114,9 +114,9 @@ export const BillingPaymentMethod = ({ {mutation.fetching ? ( 'Loading...' ) : ( - <> - Stripe Billing Dashboard - +
+ Stripe Billing Dashboard +
)}