@@ -28,7 +28,7 @@ import {
28
28
} from '../../resources/internal' ;
29
29
30
30
export class Billing implements BillingNamespace {
31
- static readonly #pathRoot = '/commerce ' ;
31
+ static readonly #pathRoot = '/billing ' ;
32
32
static path ( subPath : string , param ?: { orgId ?: string } ) : string {
33
33
const { orgId } = param || { } ;
34
34
const prefix = orgId ? `/organizations/${ orgId } ` : '/me' ;
@@ -39,7 +39,7 @@ export class Billing implements BillingNamespace {
39
39
const { for : forParam , ...safeParams } = params || { } ;
40
40
const searchParams = { ...safeParams , payer_type : forParam === 'organization' ? 'org' : 'user' } ;
41
41
return await BaseResource . _fetch ( {
42
- path : `/commerce/ plans` ,
42
+ path : Billing . path ( '/ plans' ) ,
43
43
method : 'GET' ,
44
44
search : convertPageToOffsetSearchParams ( searchParams ) ,
45
45
} ) . then ( res => {
@@ -55,15 +55,15 @@ export class Billing implements BillingNamespace {
55
55
// Inconsistent API
56
56
getPlan = async ( params : { id : string } ) : Promise < BillingPlanResource > => {
57
57
const plan = ( await BaseResource . _fetch ( {
58
- path : `/commerce/ plans/${ params . id } `,
58
+ path : Billing . path ( `/ plans/${ params . id } `) ,
59
59
method : 'GET' ,
60
60
} ) ) as unknown as BillingPlanJSON ;
61
61
return new BillingPlan ( plan ) ;
62
62
} ;
63
63
64
64
getSubscription = async ( params : GetSubscriptionParams ) : Promise < BillingSubscriptionResource > => {
65
65
return await BaseResource . _fetch ( {
66
- path : params . orgId ? `/organizations/ ${ params . orgId } /commerce/ subscription` : `/me/commerce/subscription` ,
66
+ path : Billing . path ( `/ subscription`, { orgId : params . orgId } ) ,
67
67
method : 'GET' ,
68
68
} ) . then ( res => new BillingSubscription ( res ?. response as BillingSubscriptionJSON ) ) ;
69
69
} ;
@@ -72,7 +72,7 @@ export class Billing implements BillingNamespace {
72
72
const { orgId, ...rest } = params ;
73
73
74
74
return await BaseResource . _fetch ( {
75
- path : orgId ? `/organizations/ ${ orgId } /commerce/ statements` : `/me/commerce/statements` ,
75
+ path : Billing . path ( `/ statements`, { orgId } ) ,
76
76
method : 'GET' ,
77
77
search : convertPageToOffsetSearchParams ( rest ) ,
78
78
} ) . then ( res => {
@@ -89,9 +89,7 @@ export class Billing implements BillingNamespace {
89
89
getStatement = async ( params : { id : string ; orgId ?: string } ) : Promise < BillingStatementResource > => {
90
90
const statement = (
91
91
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 } ) ,
95
93
method : 'GET' ,
96
94
} )
97
95
) ?. response as unknown as BillingStatementJSON ;
@@ -104,7 +102,7 @@ export class Billing implements BillingNamespace {
104
102
const { orgId, ...rest } = params ;
105
103
106
104
return await BaseResource . _fetch ( {
107
- path : orgId ? `/organizations/ ${ orgId } /commerce/ payment_attempts` : `/me/commerce/payment_attempts` ,
105
+ path : Billing . path ( `/ payment_attempts`, { orgId } ) ,
108
106
method : 'GET' ,
109
107
search : convertPageToOffsetSearchParams ( rest ) ,
110
108
} ) . then ( res => {
@@ -119,9 +117,7 @@ export class Billing implements BillingNamespace {
119
117
120
118
getPaymentAttempt = async ( params : { id : string ; orgId ?: string } ) : Promise < BillingPaymentResource > => {
121
119
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 } ) ,
125
121
method : 'GET' ,
126
122
} ) ) as unknown as BillingPaymentJSON ;
127
123
return new BillingPayment ( paymentAttempt ) ;
@@ -131,7 +127,7 @@ export class Billing implements BillingNamespace {
131
127
const { orgId, ...rest } = params ;
132
128
const json = (
133
129
await BaseResource . _fetch < BillingCheckoutJSON > ( {
134
- path : orgId ? `/organizations/ ${ orgId } /commerce/ checkouts` : `/me/commerce/checkouts` ,
130
+ path : Billing . path ( `/ checkouts`, { orgId } ) ,
135
131
method : 'POST' ,
136
132
body : rest as any ,
137
133
} )
0 commit comments