af3857a209
* feat(gatekeeper): add gatekeeper module feature flag * feat(gatekeeper): add workspace pricing table domain * feat(gatekeeper): add checkout session creation * feat(gatekeeper): verify stripe signature * wip(gatekeeper): checkout callbacks * feat(gatekeeper): add unlimited and academia plan types * refactor(envHelper): getStringFromEnv helper * chore(gatekeeper): add future todos * feat(gatekeeper): add productId to the subscription domain * feat(gatekeeper): add in memory repositories * feat(gatekeeper): add more errors * feat(gatekeeper): complete checkout session service * feat(gatekeeper): add stripe client implementation * feat(gatekeeper): add checkout session completion webhook callback path * feat(gendo): fix not needing env vars if gendo module is not enabled * feat(gatekeeper): require a license for billing * chore(gatekeeper): cleanup before testing * feat(gatekeeper): subscriptionData parsing model * ci: add billing integration and gatekeeper modules to test config * test(gatekeeper): add checkout service tests * feat(gatekeeper): make completeCheckout callback idempotent properly * feat(gatekeeper): move to knex based repositories * test(gatekeeper): billing repository tests * feat(gatekeeper): add yearly billing cycle toggle * feat(ci): add stripe integration context to test job * feat(billingPage): conditionally render the checkout CTAs * fix(gatekeeper): remove flaky test condition * feat(helm): add billing integration feature flag * WIP billing gql api * feat(gatekeeper): cancel checkout session api * feat(gatekeeper): handle existing checkout sessions, when trying to create a new one * feat(gatekeeper): add workspace plans gql api * feat(gatekeeper): handle cancelation and subscription updates * fix(gatekeeper): scope initialization * fix(gatekeeper): eliminate stripe client import sideeffect * fix(gatekeeper): eliminate stripe client import sideeffect 2 * fix(mainConstants): fitler gatekeeper scopes with feature flag
46 lines
1.8 KiB
TypeScript
46 lines
1.8 KiB
TypeScript
import { GetWorkspacePlanPrice } from '@/modules/gatekeeper/domain/billing'
|
|
import {
|
|
WorkspacePlanBillingIntervals,
|
|
WorkspacePricingPlans
|
|
} from '@/modules/gatekeeper/domain/workspacePricing'
|
|
import { getStringFromEnv, getStripeApiKey } from '@/modules/shared/helpers/envHelper'
|
|
import { Stripe } from 'stripe'
|
|
|
|
let stripeClient: Stripe | undefined = undefined
|
|
|
|
export const getStripeClient = () => {
|
|
if (!stripeClient) stripeClient = new Stripe(getStripeApiKey(), { typescript: true })
|
|
return stripeClient
|
|
}
|
|
|
|
export const workspacePlanPrices = (): Record<
|
|
WorkspacePricingPlans,
|
|
Record<WorkspacePlanBillingIntervals, string> & { productId: string }
|
|
> => ({
|
|
guest: {
|
|
productId: getStringFromEnv('WORKSPACE_GUEST_SEAT_STRIPE_PRODUCT_ID'),
|
|
monthly: getStringFromEnv('WORKSPACE_MONTHLY_GUEST_SEAT_STRIPE_PRICE_ID'),
|
|
yearly: getStringFromEnv('WORKSPACE_YEARLY_GUEST_SEAT_STRIPE_PRICE_ID')
|
|
},
|
|
team: {
|
|
productId: getStringFromEnv('WORKSPACE_TEAM_SEAT_STRIPE_PRODUCT_ID'),
|
|
monthly: getStringFromEnv('WORKSPACE_MONTHLY_TEAM_SEAT_STRIPE_PRICE_ID'),
|
|
yearly: getStringFromEnv('WORKSPACE_YEARLY_TEAM_SEAT_STRIPE_PRICE_ID')
|
|
},
|
|
pro: {
|
|
productId: getStringFromEnv('WORKSPACE_PRO_SEAT_STRIPE_PRODUCT_ID'),
|
|
monthly: getStringFromEnv('WORKSPACE_MONTHLY_PRO_SEAT_STRIPE_PRICE_ID'),
|
|
yearly: getStringFromEnv('WORKSPACE_YEARLY_PRO_SEAT_STRIPE_PRICE_ID')
|
|
},
|
|
business: {
|
|
productId: getStringFromEnv('WORKSPACE_BUSINESS_SEAT_STRIPE_PRODUCT_ID'),
|
|
monthly: getStringFromEnv('WORKSPACE_MONTHLY_BUSINESS_SEAT_STRIPE_PRICE_ID'),
|
|
yearly: getStringFromEnv('WORKSPACE_YEARLY_BUSINESS_SEAT_STRIPE_PRICE_ID')
|
|
}
|
|
})
|
|
|
|
export const getWorkspacePlanPrice: GetWorkspacePlanPrice = ({
|
|
workspacePlan,
|
|
billingInterval
|
|
}) => workspacePlanPrices()[workspacePlan][billingInterval]
|