MCPcopy Create free account
hub / github.com/FlowiseAI/Flowise / getFeaturesByPlan

Method getFeaturesByPlan

packages/server/src/StripeManager.ts:73–116  ·  view source on GitHub ↗
(subscriptionId: string, withoutCache: boolean = false)

Source from the content-addressed store, hash-verified

71 }
72
73 public async getFeaturesByPlan(subscriptionId: string, withoutCache: boolean = false) {
74 if (!this.stripe || !subscriptionId) {
75 return {}
76 }
77
78 if (!withoutCache) {
79 const subscriptionData = await this.cacheManager.getSubscriptionDataFromCache(subscriptionId)
80 if (subscriptionData?.features) {
81 return subscriptionData.features
82 }
83 }
84
85 const subscription = await this.stripe.subscriptions.retrieve(subscriptionId, {
86 timeout: 5000
87 })
88 const items = subscription.items.data
89 if (items.length === 0) {
90 return {}
91 }
92
93 const productId = items[0].price.product as string
94 const product = await this.stripe.products.retrieve(productId, {
95 timeout: 5000
96 })
97 const productMetadata = product.metadata
98
99 if (!productMetadata || Object.keys(productMetadata).length === 0) {
100 return {}
101 }
102
103 const features: Record<string, string> = {}
104 for (const key in productMetadata) {
105 if (key.startsWith('feat:')) {
106 features[key] = productMetadata[key]
107 }
108 }
109
110 await this.cacheManager.updateSubscriptionDataToCache(subscriptionId, {
111 features,
112 subsriptionDetails: this.getSubscriptionObject(subscription)
113 })
114
115 return features
116 }
117
118 public async createStripeCustomerPortalSession(req: Request) {
119 if (!this.stripe) {

Callers 4

configMethod · 0.45
switchWorkspaceMethod · 0.45
verifyAndLoginFunction · 0.45

Tested by

no test coverage detected