Skip to content

Commit 0b542ad

Browse files
committed
[server] Enable automatic tax on new Stripe subscriptions for customers in supported regions
1 parent d5777ab commit 0b542ad

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Stripe from "stripe";
99
import { Team, User } from "@gitpod/gitpod-protocol";
1010
import { Config } from "../../../src/config";
1111
import { AttributionId } from "@gitpod/gitpod-protocol/lib/attribution";
12+
import { log } from "@gitpod/gitpod-protocol/lib/util/logging";
1213

1314
const POLL_CREATED_CUSTOMER_INTERVAL_MS = 1000;
1415
const POLL_CREATED_CUSTOMER_MAX_ATTEMPTS = 30;
@@ -45,7 +46,7 @@ export class StripeService {
4546

4647
async findCustomerByAttributionId(attributionId: string): Promise<Stripe.Customer | undefined> {
4748
const query = `metadata['${ATTRIBUTION_ID_METADATA_KEY}']:'${attributionId}'`;
48-
const result = await this.getStripe().customers.search({ query });
49+
const result = await this.getStripe().customers.search({ query, expand: ["data.tax"] });
4950
if (result.data.length > 1) {
5051
throw new Error(`Found more than one Stripe customer for query '${query}'`);
5152
}
@@ -167,11 +168,16 @@ export class StripeService {
167168
if (!priceId) {
168169
throw new Error(`No Stripe Price ID configured for currency '${currency}'`);
169170
}
171+
const isAutomaticTaxSupported = customer.tax?.automatic_tax === "supported";
172+
if (!isAutomaticTaxSupported) {
173+
log.warn("Automatic Stripe tax is not supported for this customer", { customer });
174+
}
170175
const startOfNextMonth = new Date(new Date().toISOString().slice(0, 7) + "-01"); // First day of this month (YYYY-MM-01)
171176
startOfNextMonth.setMonth(startOfNextMonth.getMonth() + 1); // Add one month
172177
await this.getStripe().subscriptions.create({
173178
customer: customer.id,
174179
items: [{ price: priceId }],
180+
automatic_tax: { enabled: isAutomaticTaxSupported },
175181
billing_cycle_anchor: Math.round(startOfNextMonth.getTime() / 1000),
176182
});
177183
}

0 commit comments

Comments
 (0)