Skip to content

Commit 6805549

Browse files
committed
[server] Enable automatic tax on new Stripe subscriptions for customers in supported regions
1 parent 920d71b commit 6805549

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

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

Lines changed: 10 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;
@@ -158,18 +159,26 @@ export class StripeService {
158159
async createSubscriptionForCustomer(customerId: string): Promise<void> {
159160
const customer = await this.getStripe().customers.retrieve(customerId, { expand: ["tax"] });
160161
if (!customer || customer.deleted) {
161-
throw new Error(`Stripe customer '${customerId}' was deleted`);
162+
throw new Error(`Stripe customer '${customerId}' could not be found`);
162163
}
163164
const currency = customer.metadata.preferredCurrency || "USD";
164165
const priceId = this.config?.stripeConfig?.usageProductPriceIds[currency];
165166
if (!priceId) {
166167
throw new Error(`No Stripe Price ID configured for currency '${currency}'`);
167168
}
169+
const isAutomaticTaxSupported = customer.tax?.automatic_tax === "supported";
170+
if (!isAutomaticTaxSupported) {
171+
log.warn("Automatic Stripe tax is not supported for this customer", {
172+
customerId,
173+
taxInformation: customer.tax,
174+
});
175+
}
168176
const startOfNextMonth = new Date(new Date().toISOString().slice(0, 7) + "-01"); // First day of this month (YYYY-MM-01)
169177
startOfNextMonth.setMonth(startOfNextMonth.getMonth() + 1); // Add one month
170178
await this.getStripe().subscriptions.create({
171179
customer: customer.id,
172180
items: [{ price: priceId }],
181+
automatic_tax: { enabled: isAutomaticTaxSupported },
173182
billing_cycle_anchor: Math.round(startOfNextMonth.getTime() / 1000),
174183
});
175184
}

0 commit comments

Comments
 (0)