Skip to content

Commit 9430291

Browse files
committed
[server] Remove createStripeCustomer, handled by usage instead
1 parent 91dea2e commit 9430291

File tree

2 files changed

+11
-71
lines changed

2 files changed

+11
-71
lines changed

components/server/ee/src/user/stripe-service.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ import {
1616
} from "../../../src/prometheus-metrics";
1717
import { BillingServiceClient, BillingServiceDefinition } from "@gitpod/usage-api/lib/usage/v1/billing.pb";
1818

19-
const POLL_CREATED_CUSTOMER_INTERVAL_MS = 1000;
20-
const POLL_CREATED_CUSTOMER_MAX_ATTEMPTS = 30;
21-
2219
@injectable()
2320
export class StripeService {
2421
@inject(Config) protected readonly config: Config;
@@ -58,34 +55,6 @@ export class StripeService {
5855
}
5956
}
6057

61-
async createCustomerForAttributionId(
62-
attributionId: string,
63-
preferredCurrency: string,
64-
billingEmail?: string,
65-
billingName?: string,
66-
): Promise<string> {
67-
if (await this.findCustomerByAttributionId(attributionId)) {
68-
throw new Error(`A Stripe customer already exists for '${attributionId}'`);
69-
}
70-
// Create the customer in Stripe
71-
const customer = await reportStripeOutcome("customers_create", () => {
72-
return this.getStripe().customers.create({
73-
email: billingEmail,
74-
name: billingName,
75-
metadata: { attributionId, preferredCurrency },
76-
});
77-
});
78-
// Wait for the customer to show up in Stripe search results before proceeding
79-
let attempts = 0;
80-
while (!(await this.findCustomerByAttributionId(attributionId))) {
81-
await new Promise((resolve) => setTimeout(resolve, POLL_CREATED_CUSTOMER_INTERVAL_MS));
82-
if (++attempts > POLL_CREATED_CUSTOMER_MAX_ATTEMPTS) {
83-
throw new Error(`Could not confirm Stripe customer creation for '${attributionId}'`);
84-
}
85-
}
86-
return customer.id;
87-
}
88-
8958
async setDefaultPaymentMethodForCustomer(customerId: string, setupIntentId: string): Promise<void> {
9059
const setupIntent = await reportStripeOutcome("intent_retrieve", () => {
9160
return this.getStripe().setupIntents.retrieve(setupIntentId);

components/server/ee/src/workspace/gitpod-server-impl.ts

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ import { EntitlementService, MayStartWorkspaceResult } from "../../../src/billin
116116
import { BillingMode } from "@gitpod/gitpod-protocol/lib/billing-mode";
117117
import { BillingModes } from "../billing/billing-mode";
118118
import { UsageServiceDefinition } from "@gitpod/usage-api/lib/usage/v1/usage.pb";
119-
import { getExperimentsClientForBackend } from "@gitpod/gitpod-protocol/lib/experiments/configcat-server";
120119
import { BillingServiceClient, BillingServiceDefinition } from "@gitpod/usage-api/lib/usage/v1/billing.pb";
121120

122121
@injectable()
@@ -2112,48 +2111,20 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
21122111

21132112
const billingEmail = User.getPrimaryEmail(user);
21142113
const billingName = attrId.kind === "team" ? team!.name : User.getName(user);
2115-
2116-
const isCreateStripeCustomerOnUsageEnabled = await getExperimentsClientForBackend().getValueAsync(
2117-
"createStripeCustomersOnUsage",
2118-
false,
2119-
{
2120-
user: user,
2121-
teamId: team ? team.id : undefined,
2122-
},
2123-
);
2124-
if (isCreateStripeCustomerOnUsageEnabled) {
2114+
try {
21252115
try {
2126-
try {
2127-
// customer already exists, we don't need to create a new one.
2128-
await this.billingService.getStripeCustomer({ attributionId });
2129-
return;
2130-
} catch (e) {}
2131-
2132-
await this.billingService.createStripeCustomer({
2133-
attributionId,
2134-
currency,
2135-
email: billingEmail,
2136-
name: billingName,
2137-
});
2116+
// customer already exists, we don't need to create a new one.
2117+
await this.billingService.getStripeCustomer({ attributionId });
21382118
return;
2139-
} catch (error) {
2140-
log.error(`Failed to create Stripe customer profile for '${attributionId}'`, error);
2141-
throw new ResponseError(
2142-
ErrorCodes.INTERNAL_SERVER_ERROR,
2143-
`Failed to create Stripe customer profile for '${attributionId}'`,
2144-
);
2145-
}
2146-
}
2119+
} catch (e) {}
21472120

2148-
try {
2149-
if (!(await this.stripeService.findCustomerByAttributionId(attributionId))) {
2150-
await this.stripeService.createCustomerForAttributionId(
2151-
attributionId,
2152-
currency,
2153-
billingEmail,
2154-
billingName,
2155-
);
2156-
}
2121+
await this.billingService.createStripeCustomer({
2122+
attributionId,
2123+
currency,
2124+
email: billingEmail,
2125+
name: billingName,
2126+
});
2127+
return;
21572128
} catch (error) {
21582129
log.error(`Failed to create Stripe customer profile for '${attributionId}'`, error);
21592130
throw new ResponseError(

0 commit comments

Comments
 (0)