diff --git a/components/server/ee/src/user/stripe-service.ts b/components/server/ee/src/user/stripe-service.ts index 9f1d4465b2c0c9..c4e4d129ddb0ae 100644 --- a/components/server/ee/src/user/stripe-service.ts +++ b/components/server/ee/src/user/stripe-service.ts @@ -16,9 +16,6 @@ import { } from "../../../src/prometheus-metrics"; import { BillingServiceClient, BillingServiceDefinition } from "@gitpod/usage-api/lib/usage/v1/billing.pb"; -const POLL_CREATED_CUSTOMER_INTERVAL_MS = 1000; -const POLL_CREATED_CUSTOMER_MAX_ATTEMPTS = 30; - @injectable() export class StripeService { @inject(Config) protected readonly config: Config; @@ -58,34 +55,6 @@ export class StripeService { } } - async createCustomerForAttributionId( - attributionId: string, - preferredCurrency: string, - billingEmail?: string, - billingName?: string, - ): Promise { - if (await this.findCustomerByAttributionId(attributionId)) { - throw new Error(`A Stripe customer already exists for '${attributionId}'`); - } - // Create the customer in Stripe - const customer = await reportStripeOutcome("customers_create", () => { - return this.getStripe().customers.create({ - email: billingEmail, - name: billingName, - metadata: { attributionId, preferredCurrency }, - }); - }); - // Wait for the customer to show up in Stripe search results before proceeding - let attempts = 0; - while (!(await this.findCustomerByAttributionId(attributionId))) { - await new Promise((resolve) => setTimeout(resolve, POLL_CREATED_CUSTOMER_INTERVAL_MS)); - if (++attempts > POLL_CREATED_CUSTOMER_MAX_ATTEMPTS) { - throw new Error(`Could not confirm Stripe customer creation for '${attributionId}'`); - } - } - return customer.id; - } - async setDefaultPaymentMethodForCustomer(customerId: string, setupIntentId: string): Promise { const setupIntent = await reportStripeOutcome("intent_retrieve", () => { return this.getStripe().setupIntents.retrieve(setupIntentId); diff --git a/components/server/ee/src/workspace/gitpod-server-impl.ts b/components/server/ee/src/workspace/gitpod-server-impl.ts index f89b357c92f97d..b678f2173ba9a4 100644 --- a/components/server/ee/src/workspace/gitpod-server-impl.ts +++ b/components/server/ee/src/workspace/gitpod-server-impl.ts @@ -116,7 +116,6 @@ import { EntitlementService, MayStartWorkspaceResult } from "../../../src/billin import { BillingMode } from "@gitpod/gitpod-protocol/lib/billing-mode"; import { BillingModes } from "../billing/billing-mode"; import { UsageServiceDefinition } from "@gitpod/usage-api/lib/usage/v1/usage.pb"; -import { getExperimentsClientForBackend } from "@gitpod/gitpod-protocol/lib/experiments/configcat-server"; import { BillingServiceClient, BillingServiceDefinition } from "@gitpod/usage-api/lib/usage/v1/billing.pb"; @injectable() @@ -2112,48 +2111,20 @@ export class GitpodServerEEImpl extends GitpodServerImpl { const billingEmail = User.getPrimaryEmail(user); const billingName = attrId.kind === "team" ? team!.name : User.getName(user); - - const isCreateStripeCustomerOnUsageEnabled = await getExperimentsClientForBackend().getValueAsync( - "createStripeCustomersOnUsage", - false, - { - user: user, - teamId: team ? team.id : undefined, - }, - ); - if (isCreateStripeCustomerOnUsageEnabled) { + try { try { - try { - // customer already exists, we don't need to create a new one. - await this.billingService.getStripeCustomer({ attributionId }); - return; - } catch (e) {} - - await this.billingService.createStripeCustomer({ - attributionId, - currency, - email: billingEmail, - name: billingName, - }); + // customer already exists, we don't need to create a new one. + await this.billingService.getStripeCustomer({ attributionId }); return; - } catch (error) { - log.error(`Failed to create Stripe customer profile for '${attributionId}'`, error); - throw new ResponseError( - ErrorCodes.INTERNAL_SERVER_ERROR, - `Failed to create Stripe customer profile for '${attributionId}'`, - ); - } - } + } catch (e) {} - try { - if (!(await this.stripeService.findCustomerByAttributionId(attributionId))) { - await this.stripeService.createCustomerForAttributionId( - attributionId, - currency, - billingEmail, - billingName, - ); - } + await this.billingService.createStripeCustomer({ + attributionId, + currency, + email: billingEmail, + name: billingName, + }); + return; } catch (error) { log.error(`Failed to create Stripe customer profile for '${attributionId}'`, error); throw new ResponseError(