@@ -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 ;
@@ -158,18 +159,26 @@ export class StripeService {
158
159
async createSubscriptionForCustomer ( customerId : string ) : Promise < void > {
159
160
const customer = await this . getStripe ( ) . customers . retrieve ( customerId , { expand : [ "tax" ] } ) ;
160
161
if ( ! customer || customer . deleted ) {
161
- throw new Error ( `Stripe customer '${ customerId } ' was deleted ` ) ;
162
+ throw new Error ( `Stripe customer '${ customerId } ' could not be found ` ) ;
162
163
}
163
164
const currency = customer . metadata . preferredCurrency || "USD" ;
164
165
const priceId = this . config ?. stripeConfig ?. usageProductPriceIds [ currency ] ;
165
166
if ( ! priceId ) {
166
167
throw new Error ( `No Stripe Price ID configured for currency '${ currency } '` ) ;
167
168
}
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
+ }
168
176
const startOfNextMonth = new Date ( new Date ( ) . toISOString ( ) . slice ( 0 , 7 ) + "-01" ) ; // First day of this month (YYYY-MM-01)
169
177
startOfNextMonth . setMonth ( startOfNextMonth . getMonth ( ) + 1 ) ; // Add one month
170
178
await this . getStripe ( ) . subscriptions . create ( {
171
179
customer : customer . id ,
172
180
items : [ { price : priceId } ] ,
181
+ automatic_tax : { enabled : isAutomaticTaxSupported } ,
173
182
billing_cycle_anchor : Math . round ( startOfNextMonth . getTime ( ) / 1000 ) ,
174
183
} ) ;
175
184
}
0 commit comments