@@ -28,7 +28,7 @@ import {
2828} from '../../resources/internal' ;
2929
3030export class Billing implements BillingNamespace {
31- static readonly #pathRoot = '/commerce ' ;
31+ static readonly #pathRoot = '/billing ' ;
3232 static path ( subPath : string , param ?: { orgId ?: string } ) : string {
3333 const { orgId } = param || { } ;
3434 const prefix = orgId ? `/organizations/${ orgId } ` : '/me' ;
@@ -39,7 +39,7 @@ export class Billing implements BillingNamespace {
3939 const { for : forParam , ...safeParams } = params || { } ;
4040 const searchParams = { ...safeParams , payer_type : forParam === 'organization' ? 'org' : 'user' } ;
4141 return await BaseResource . _fetch ( {
42- path : `/commerce /plans` ,
42+ path : `${ Billing . #pathRoot } /plans` ,
4343 method : 'GET' ,
4444 search : convertPageToOffsetSearchParams ( searchParams ) ,
4545 } ) . then ( res => {
@@ -55,15 +55,15 @@ export class Billing implements BillingNamespace {
5555 // Inconsistent API
5656 getPlan = async ( params : { id : string } ) : Promise < BillingPlanResource > => {
5757 const plan = ( await BaseResource . _fetch ( {
58- path : `/commerce /plans/${ params . id } ` ,
58+ path : `${ Billing . #pathRoot } /plans/${ params . id } ` ,
5959 method : 'GET' ,
6060 } ) ) as unknown as BillingPlanJSON ;
6161 return new BillingPlan ( plan ) ;
6262 } ;
6363
6464 getSubscription = async ( params : GetSubscriptionParams ) : Promise < BillingSubscriptionResource > => {
6565 return await BaseResource . _fetch ( {
66- path : params . orgId ? `/organizations/ ${ params . orgId } /commerce/ subscription` : `/me/commerce/subscription` ,
66+ path : Billing . path ( `/ subscription`, { orgId : params . orgId } ) ,
6767 method : 'GET' ,
6868 } ) . then ( res => new BillingSubscription ( res ?. response as BillingSubscriptionJSON ) ) ;
6969 } ;
@@ -72,7 +72,7 @@ export class Billing implements BillingNamespace {
7272 const { orgId, ...rest } = params ;
7373
7474 return await BaseResource . _fetch ( {
75- path : orgId ? `/organizations/ ${ orgId } /commerce/ statements` : `/me/commerce/statements` ,
75+ path : Billing . path ( `/ statements`, { orgId } ) ,
7676 method : 'GET' ,
7777 search : convertPageToOffsetSearchParams ( rest ) ,
7878 } ) . then ( res => {
@@ -89,9 +89,7 @@ export class Billing implements BillingNamespace {
8989 getStatement = async ( params : { id : string ; orgId ?: string } ) : Promise < BillingStatementResource > => {
9090 const statement = (
9191 await BaseResource . _fetch ( {
92- path : params . orgId
93- ? `/organizations/${ params . orgId } /commerce/statements/${ params . id } `
94- : `/me/commerce/statements/${ params . id } ` ,
92+ path : Billing . path ( `/statements/${ params . id } ` , { orgId : params . orgId } ) ,
9593 method : 'GET' ,
9694 } )
9795 ) ?. response as unknown as BillingStatementJSON ;
@@ -104,7 +102,7 @@ export class Billing implements BillingNamespace {
104102 const { orgId, ...rest } = params ;
105103
106104 return await BaseResource . _fetch ( {
107- path : orgId ? `/organizations/ ${ orgId } /commerce/ payment_attempts` : `/me/commerce/payment_attempts` ,
105+ path : Billing . path ( `/ payment_attempts`, { orgId } ) ,
108106 method : 'GET' ,
109107 search : convertPageToOffsetSearchParams ( rest ) ,
110108 } ) . then ( res => {
@@ -119,9 +117,7 @@ export class Billing implements BillingNamespace {
119117
120118 getPaymentAttempt = async ( params : { id : string ; orgId ?: string } ) : Promise < BillingPaymentResource > => {
121119 const paymentAttempt = ( await BaseResource . _fetch ( {
122- path : params . orgId
123- ? `/organizations/${ params . orgId } /commerce/payment_attempts/${ params . id } `
124- : `/me/commerce/payment_attempts/${ params . id } ` ,
120+ path : Billing . path ( `/payment_attempts/${ params . id } ` , { orgId : params . orgId } ) ,
125121 method : 'GET' ,
126122 } ) ) as unknown as BillingPaymentJSON ;
127123 return new BillingPayment ( paymentAttempt ) ;
@@ -131,7 +127,7 @@ export class Billing implements BillingNamespace {
131127 const { orgId, ...rest } = params ;
132128 const json = (
133129 await BaseResource . _fetch < BillingCheckoutJSON > ( {
134- path : orgId ? `/organizations/ ${ orgId } /commerce/ checkouts` : `/me/commerce/checkouts` ,
130+ path : Billing . path ( `/ checkouts`, { orgId } ) ,
135131 method : 'POST' ,
136132 body : rest as any ,
137133 } )
0 commit comments