Skip to content

Commit 3aa3a07

Browse files
committed
chore(clerk-js,backend): Replace /commerce endpoints with /billing endpoints
1 parent 1a2eee6 commit 3aa3a07

File tree

6 files changed

+23
-26
lines changed

6 files changed

+23
-26
lines changed

.changeset/young-nails-matter.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
'@clerk/backend': patch
4+
---
5+
6+
Replace `/commerce` endpoints with `/billing` endpoints.

packages/backend/src/api/endpoints/BillingApi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { BillingSubscriptionItem } from '../resources/CommerceSubscriptionI
77
import type { PaginatedResourceResponse } from '../resources/Deserializer';
88
import { AbstractAPI } from './AbstractApi';
99

10-
const basePath = '/commerce';
10+
const basePath = '/billing';
1111
const organizationBasePath = '/organizations';
1212
const userBasePath = '/users';
1313

packages/clerk-js/src/core/modules/billing/namespace.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
} from '../../resources/internal';
2929

3030
export 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.path('/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.path(`/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
})

packages/clerk-js/src/core/resources/BillingCheckout.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type {
1313
import { unixEpochToDate } from '@/utils/date';
1414

1515
import { billingTotalsFromJSON } from '../../utils';
16+
import { Billing } from '../modules/billing/namespace';
1617
import { BillingPayer } from './BillingPayer';
1718
import { BaseResource, BillingPaymentMethod, BillingPlan } from './internal';
1819

@@ -62,9 +63,7 @@ export class BillingCheckout extends BaseResource implements BillingCheckoutReso
6263
return retry(
6364
() =>
6465
this._basePatch({
65-
path: this.payer.organizationId
66-
? `/organizations/${this.payer.organizationId}/commerce/checkouts/${this.id}/confirm`
67-
: `/me/commerce/checkouts/${this.id}/confirm`,
66+
path: Billing.path(`/checkouts/${this.id}/confirm`, { orgId: this.payer.organizationId }),
6867
body: params as any,
6968
}),
7069
{

packages/clerk-js/src/core/resources/BillingPaymentSource.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {
99
RemovePaymentMethodParams,
1010
} from '@clerk/types';
1111

12+
import { Billing } from '../modules/billing/namespace';
1213
import { BaseResource, DeletedObject } from './internal';
1314

1415
export class BillingPaymentMethod extends BaseResource implements BillingPaymentMethodResource {
@@ -47,9 +48,7 @@ export class BillingPaymentMethod extends BaseResource implements BillingPayment
4748
const { orgId } = params ?? {};
4849
const json = (
4950
await BaseResource._fetch({
50-
path: orgId
51-
? `/organizations/${orgId}/commerce/payment_sources/${this.id}`
52-
: `/me/commerce/payment_sources/${this.id}`,
51+
path: Billing.path(`/payment_sources/${this.id}`, { orgId }),
5352
method: 'DELETE',
5453
})
5554
)?.response as unknown as DeletedObjectJSON;
@@ -60,9 +59,7 @@ export class BillingPaymentMethod extends BaseResource implements BillingPayment
6059
public async makeDefault(params?: MakeDefaultPaymentMethodParams) {
6160
const { orgId } = params ?? {};
6261
await BaseResource._fetch({
63-
path: orgId
64-
? `/organizations/${orgId}/commerce/payers/default_payment_source`
65-
: `/me/commerce/payers/default_payment_source`,
62+
path: Billing.path(`/payers/default_payment_source`, { orgId }),
6663
method: 'PUT',
6764
body: { payment_source_id: this.id } as any,
6865
});

packages/clerk-js/src/core/resources/BillingSubscription.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type {
1313
import { unixEpochToDate } from '@/utils/date';
1414

1515
import { billingMoneyAmountFromJSON } from '../../utils';
16+
import { Billing } from '../modules/billing/namespace';
1617
import { BaseResource, BillingPlan, DeletedObject } from './internal';
1718

1819
export class BillingSubscription extends BaseResource implements BillingSubscriptionResource {
@@ -110,9 +111,7 @@ export class BillingSubscriptionItem extends BaseResource implements BillingSubs
110111
const { orgId } = params;
111112
const json = (
112113
await BaseResource._fetch({
113-
path: orgId
114-
? `/organizations/${orgId}/commerce/subscription_items/${this.id}`
115-
: `/me/commerce/subscription_items/${this.id}`,
114+
path: Billing.path(`/subscription_items/${this.id}`, { orgId }),
116115
method: 'DELETE',
117116
})
118117
)?.response as unknown as DeletedObjectJSON;

0 commit comments

Comments
 (0)