@@ -60,7 +60,9 @@ export class BackgroundCheckBillingService {
6060 } ) ;
6161
6262 if ( ! session . url ) {
63- throw new BadRequestException ( 'Failed to create Stripe Checkout session.' ) ;
63+ throw new BadRequestException (
64+ 'Failed to create Stripe Checkout session.' ,
65+ ) ;
6466 }
6567
6668 return { url : session . url } ;
@@ -82,8 +84,13 @@ export class BackgroundCheckBillingService {
8284 throw new BadRequestException ( 'Checkout session is not complete.' ) ;
8385 }
8486
85- if ( session . metadata ?. organizationId && session . metadata . organizationId !== organizationId ) {
86- throw new BadRequestException ( 'Checkout session does not belong to this organization.' ) ;
87+ if (
88+ session . metadata ?. organizationId &&
89+ session . metadata . organizationId !== organizationId
90+ ) {
91+ throw new BadRequestException (
92+ 'Checkout session does not belong to this organization.' ,
93+ ) ;
8794 }
8895
8996 const stripeCustomerId = this . extractStripeId ( session . customer ) ;
@@ -98,12 +105,16 @@ export class BackgroundCheckBillingService {
98105
99106 const setupIntent = session . setup_intent ;
100107 if ( ! setupIntent || typeof setupIntent === 'string' ) {
101- throw new BadRequestException ( 'Checkout session is missing a setup intent.' ) ;
108+ throw new BadRequestException (
109+ 'Checkout session is missing a setup intent.' ,
110+ ) ;
102111 }
103112
104113 const paymentMethodId = this . extractStripeId ( setupIntent . payment_method ) ;
105114 if ( ! paymentMethodId ) {
106- throw new BadRequestException ( 'Setup intent is missing a payment method.' ) ;
115+ throw new BadRequestException (
116+ 'Setup intent is missing a payment method.' ,
117+ ) ;
107118 }
108119
109120 await stripe . customers . update ( stripeCustomerId , {
@@ -146,7 +157,9 @@ export class BackgroundCheckBillingService {
146157 } ) ;
147158
148159 if ( ! billing ) {
149- throw new NotFoundException ( 'No billing record found for this organization.' ) ;
160+ throw new NotFoundException (
161+ 'No billing record found for this organization.' ,
162+ ) ;
150163 }
151164
152165 const portalSession = await stripe . billingPortal . sessions . create ( {
@@ -192,16 +205,24 @@ export class BackgroundCheckBillingService {
192205 return customer . id ;
193206 }
194207
195- async getBackgroundCheckPrice ( ) : Promise < { id : string ; unitAmount : number ; currency : string } > {
208+ async getBackgroundCheckPrice ( ) : Promise < {
209+ id : string ;
210+ unitAmount : number ;
211+ currency : string ;
212+ } > {
196213 const priceId = process . env . STRIPE_BACKGROUND_CHECK_PRICE_ID ;
197214 if ( ! priceId ) {
198- throw new BadRequestException ( 'Background check pricing is not configured. Contact support.' ) ;
215+ throw new BadRequestException (
216+ 'Background check pricing is not configured. Contact support.' ,
217+ ) ;
199218 }
200219
201220 const stripe = this . stripeService . getClient ( ) ;
202221 const price = await stripe . prices . retrieve ( priceId ) ;
203222 if ( price . unit_amount === null || price . unit_amount === undefined ) {
204- throw new BadRequestException ( 'Background check pricing is not configured. Contact support.' ) ;
223+ throw new BadRequestException (
224+ 'Background check pricing is not configured. Contact support.' ,
225+ ) ;
205226 }
206227
207228 return {
@@ -213,7 +234,9 @@ export class BackgroundCheckBillingService {
213234
214235 private validateRedirectUrl ( url : string ) : void {
215236 const appUrl =
216- process . env . NEXT_PUBLIC_APP_URL || process . env . APP_URL || process . env . BETTER_AUTH_URL ;
237+ process . env . NEXT_PUBLIC_APP_URL ||
238+ process . env . APP_URL ||
239+ process . env . BETTER_AUTH_URL ;
217240 if ( ! appUrl ) {
218241 throw new BadRequestException ( 'App URL is not configured on the server.' ) ;
219242 }
@@ -226,11 +249,15 @@ export class BackgroundCheckBillingService {
226249 }
227250
228251 if ( parsed . origin !== new URL ( appUrl ) . origin ) {
229- throw new BadRequestException ( 'Redirect URL must belong to the application origin.' ) ;
252+ throw new BadRequestException (
253+ 'Redirect URL must belong to the application origin.' ,
254+ ) ;
230255 }
231256 }
232257
233- private extractStripeId ( value : string | { id ?: string } | null ) : string | null {
258+ private extractStripeId (
259+ value : string | { id ?: string } | null ,
260+ ) : string | null {
234261 if ( ! value ) return null ;
235262 if ( typeof value === 'string' ) return value ;
236263 return value . id ?? null ;
@@ -254,8 +281,13 @@ export class BackgroundCheckBillingService {
254281
255282 const stripe = this . stripeService . getClient ( ) ;
256283 const customer = await stripe . customers . retrieve ( stripeCustomerId ) ;
257- if ( customer . deleted || customer . metadata ?. organizationId !== organizationId ) {
258- throw new BadRequestException ( 'Checkout session does not belong to this organization.' ) ;
284+ if (
285+ customer . deleted ||
286+ customer . metadata ?. organizationId !== organizationId
287+ ) {
288+ throw new BadRequestException (
289+ 'Checkout session does not belong to this organization.' ,
290+ ) ;
259291 }
260292 }
261293}
0 commit comments