@@ -119,6 +119,7 @@ import { UsageServiceDefinition } from "@gitpod/usage-api/lib/usage/v1/usage.pb"
119
119
import { BillingServiceClient , BillingServiceDefinition } from "@gitpod/usage-api/lib/usage/v1/billing.pb" ;
120
120
import { IncrementalPrebuildsService } from "../prebuilds/incremental-prebuilds-service" ;
121
121
import { ConfigProvider } from "../../../src/workspace/config-provider" ;
122
+ import { getExperimentsClientForBackend } from "@gitpod/gitpod-protocol/lib/experiments/configcat-server" ;
122
123
123
124
@injectable ( )
124
125
export class GitpodServerEEImpl extends GitpodServerImpl {
@@ -2177,9 +2178,10 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
2177
2178
2178
2179
const user = this . checkAndBlockUser ( "subscribeToStripe" ) ;
2179
2180
2181
+ let team : Team | undefined ;
2180
2182
try {
2181
2183
if ( attrId . kind === "team" ) {
2182
- const team = await this . guardTeamOperation ( attrId . teamId , "update" ) ;
2184
+ team = await this . guardTeamOperation ( attrId . teamId , "update" ) ;
2183
2185
await this . ensureStripeApiIsAllowed ( { team } ) ;
2184
2186
} else {
2185
2187
await this . ensureStripeApiIsAllowed ( { user } ) ;
@@ -2189,8 +2191,21 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
2189
2191
throw new Error ( `No Stripe customer profile for '${ attributionId } '` ) ;
2190
2192
}
2191
2193
2192
- await this . stripeService . setDefaultPaymentMethodForCustomer ( customerId , setupIntentId ) ;
2193
- await this . stripeService . createSubscriptionForCustomer ( customerId , attributionId ) ;
2194
+ const createStripeSubscriptionOnUsage = await getExperimentsClientForBackend ( ) . getValueAsync (
2195
+ "createStripeSubscriptionOnUsage" ,
2196
+ false ,
2197
+ {
2198
+ user : user ,
2199
+ teamId : team ? team . id : undefined ,
2200
+ } ,
2201
+ ) ;
2202
+
2203
+ if ( createStripeSubscriptionOnUsage ) {
2204
+ await this . billingService . createStripeSubscription ( { attributionId, setupIntentId, usageLimit } ) ;
2205
+ } else {
2206
+ await this . stripeService . setDefaultPaymentMethodForCustomer ( customerId , setupIntentId ) ;
2207
+ await this . stripeService . createSubscriptionForCustomer ( customerId , attributionId ) ;
2208
+ }
2194
2209
2195
2210
// Creating a cost center for this customer
2196
2211
const { costCenter } = await this . usageService . setCostCenter ( {
0 commit comments