@@ -9,6 +9,7 @@ import Stripe from "stripe";
9
9
import { Team , User } from "@gitpod/gitpod-protocol" ;
10
10
import { Config } from "../../../src/config" ;
11
11
import { AttributionId } from "@gitpod/gitpod-protocol/lib/attribution" ;
12
+ import { log } from "@gitpod/gitpod-protocol/lib/util/logging" ;
12
13
13
14
const POLL_CREATED_CUSTOMER_INTERVAL_MS = 1000 ;
14
15
const POLL_CREATED_CUSTOMER_MAX_ATTEMPTS = 30 ;
@@ -164,18 +165,26 @@ export class StripeService {
164
165
async createSubscriptionForCustomer ( customerId : string ) : Promise < void > {
165
166
const customer = await this . getStripe ( ) . customers . retrieve ( customerId , { expand : [ "tax" ] } ) ;
166
167
if ( ! customer || customer . deleted ) {
167
- throw new Error ( `Stripe customer '${ customerId } ' was deleted ` ) ;
168
+ throw new Error ( `Stripe customer '${ customerId } ' could not be found ` ) ;
168
169
}
169
170
const currency = customer . metadata . preferredCurrency || "USD" ;
170
171
const priceId = this . config ?. stripeConfig ?. usageProductPriceIds [ currency ] ;
171
172
if ( ! priceId ) {
172
173
throw new Error ( `No Stripe Price ID configured for currency '${ currency } '` ) ;
173
174
}
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
+ }
174
182
const startOfNextMonth = new Date ( new Date ( ) . toISOString ( ) . slice ( 0 , 7 ) + "-01" ) ; // First day of this month (YYYY-MM-01)
175
183
startOfNextMonth . setMonth ( startOfNextMonth . getMonth ( ) + 1 ) ; // Add one month
176
184
await this . getStripe ( ) . subscriptions . create ( {
177
185
customer : customer . id ,
178
186
items : [ { price : priceId } ] ,
187
+ automatic_tax : { enabled : isAutomaticTaxSupported } ,
179
188
billing_cycle_anchor : Math . round ( startOfNextMonth . getTime ( ) / 1000 ) ,
180
189
} ) ;
181
190
}
0 commit comments