Skip to content

Revert "[stripe] Use AttributionID metadat when querying for customers" #12765

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions components/server/ee/src/user/stripe-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import { AttributionId } from "@gitpod/gitpod-protocol/lib/attribution";
const POLL_CREATED_CUSTOMER_INTERVAL_MS = 1000;
const POLL_CREATED_CUSTOMER_MAX_ATTEMPTS = 30;

const ATTRIBUTION_ID_METADATA_KEY = "attributionId";

@injectable()
export class StripeService {
@inject(Config) protected readonly config: Config;
Expand All @@ -36,15 +34,11 @@ export class StripeService {
}

async findCustomerByUserId(userId: string): Promise<Stripe.Customer | undefined> {
return this.findCustomerByQuery(
`metadata['${ATTRIBUTION_ID_METADATA_KEY}']:'${AttributionId.render({ kind: "user", userId })}'`,
);
return this.findCustomerByQuery(`metadata['userId']:'${userId}'`);
}

async findCustomerByTeamId(teamId: string): Promise<Stripe.Customer | undefined> {
return this.findCustomerByQuery(
`metadata['${ATTRIBUTION_ID_METADATA_KEY}']:'${AttributionId.render({ kind: "team", teamId })}'`,
);
return this.findCustomerByQuery(`metadata['teamId']:'${teamId}'`);
}

async findCustomerByQuery(query: string): Promise<Stripe.Customer | undefined> {
Expand All @@ -64,7 +58,9 @@ export class StripeService {
email: User.getPrimaryEmail(user),
name: User.getName(user),
metadata: {
ATTRIBUTION_ID_METADATA_KEY: AttributionId.render({ kind: "user", userId: user.id }),
// userId is deprecated, use attributionId where possible
userId: user.id,
attributionId: AttributionId.render({ kind: "user", userId: user.id }),
},
});
// Wait for the customer to show up in Stripe search results before proceeding
Expand All @@ -88,7 +84,9 @@ export class StripeService {
email: User.getPrimaryEmail(user),
name: userName ? `${userName} (${team.name})` : team.name,
metadata: {
ATTRIBUTION_ID_METADATA_KEY: AttributionId.render({ kind: "team", teamId: team.id }),
// teamId is deprecated, use attributionId where possible
teamId: team.id,
attributionId: AttributionId.render({ kind: "team", teamId: team.id }),
},
});
// Wait for the customer to show up in Stripe search results before proceeding
Expand Down