@@ -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 ;
@@ -45,7 +46,7 @@ export class StripeService {
45
46
46
47
async findCustomerByAttributionId ( attributionId : string ) : Promise < Stripe . Customer | undefined > {
47
48
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" ] } ) ;
49
50
if ( result . data . length > 1 ) {
50
51
throw new Error ( `Found more than one Stripe customer for query '${ query } '` ) ;
51
52
}
@@ -167,11 +168,16 @@ export class StripeService {
167
168
if ( ! priceId ) {
168
169
throw new Error ( `No Stripe Price ID configured for currency '${ currency } '` ) ;
169
170
}
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
+ }
170
175
const startOfNextMonth = new Date ( new Date ( ) . toISOString ( ) . slice ( 0 , 7 ) + "-01" ) ; // First day of this month (YYYY-MM-01)
171
176
startOfNextMonth . setMonth ( startOfNextMonth . getMonth ( ) + 1 ) ; // Add one month
172
177
await this . getStripe ( ) . subscriptions . create ( {
173
178
customer : customer . id ,
174
179
items : [ { price : priceId } ] ,
180
+ automatic_tax : { enabled : isAutomaticTaxSupported } ,
175
181
billing_cycle_anchor : Math . round ( startOfNextMonth . getTime ( ) / 1000 ) ,
176
182
} ) ;
177
183
}
0 commit comments