Skip to content

Commit 98b5f19

Browse files
committed
[server] Enable automatic tax on new Stripe subscriptions for customers in supported regions
1 parent 355704d commit 98b5f19

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

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

+10-1
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;
@@ -164,18 +165,26 @@ export class StripeService {
164165
async createSubscriptionForCustomer(customerId: string): Promise<void> {
165166
const customer = await this.getStripe().customers.retrieve(customerId, { expand: ["tax"] });
166167
if (!customer || customer.deleted) {
167-
throw new Error(`Stripe customer '${customerId}' was deleted`);
168+
throw new Error(`Stripe customer '${customerId}' could not be found`);
168169
}
169170
const currency = customer.metadata.preferredCurrency || "USD";
170171
const priceId = this.config?.stripeConfig?.usageProductPriceIds[currency];
171172
if (!priceId) {
172173
throw new Error(`No Stripe Price ID configured for currency '${currency}'`);
173174
}
175+
const isAutomaticTaxSupported = customer.tax?.automatic_tax === "supported";
176+
if (!isAutomaticTaxSupported) {
177+
log.warn("Automatic Stripe tax is not supported for this customer", {
178+
customerId,
179+
taxInformation: customer.tax,
180+
});
181+
}
174182
const startOfNextMonth = new Date(new Date().toISOString().slice(0, 7) + "-01"); // First day of this month (YYYY-MM-01)
175183
startOfNextMonth.setMonth(startOfNextMonth.getMonth() + 1); // Add one month
176184
await this.getStripe().subscriptions.create({
177185
customer: customer.id,
178186
items: [{ price: priceId }],
187+
automatic_tax: { enabled: isAutomaticTaxSupported },
179188
billing_cycle_anchor: Math.round(startOfNextMonth.getTime() / 1000),
180189
});
181190
}

0 commit comments

Comments
 (0)