From 3aa3a073715b8a470126b4110d60d86f756c2605 Mon Sep 17 00:00:00 2001 From: panteliselef Date: Thu, 25 Sep 2025 12:45:16 +0300 Subject: [PATCH 1/2] chore(clerk-js,backend): Replace `/commerce` endpoints with `/billing` endpoints --- .changeset/young-nails-matter.md | 6 +++++ .../backend/src/api/endpoints/BillingApi.ts | 2 +- .../src/core/modules/billing/namespace.ts | 22 ++++++++----------- .../src/core/resources/BillingCheckout.ts | 5 ++--- .../core/resources/BillingPaymentSource.ts | 9 +++----- .../src/core/resources/BillingSubscription.ts | 5 ++--- 6 files changed, 23 insertions(+), 26 deletions(-) create mode 100644 .changeset/young-nails-matter.md diff --git a/.changeset/young-nails-matter.md b/.changeset/young-nails-matter.md new file mode 100644 index 00000000000..86e94acb714 --- /dev/null +++ b/.changeset/young-nails-matter.md @@ -0,0 +1,6 @@ +--- +'@clerk/clerk-js': patch +'@clerk/backend': patch +--- + +Replace `/commerce` endpoints with `/billing` endpoints. diff --git a/packages/backend/src/api/endpoints/BillingApi.ts b/packages/backend/src/api/endpoints/BillingApi.ts index 1a4dbf7ed33..c14d3a5edf5 100644 --- a/packages/backend/src/api/endpoints/BillingApi.ts +++ b/packages/backend/src/api/endpoints/BillingApi.ts @@ -7,7 +7,7 @@ import type { BillingSubscriptionItem } from '../resources/CommerceSubscriptionI import type { PaginatedResourceResponse } from '../resources/Deserializer'; import { AbstractAPI } from './AbstractApi'; -const basePath = '/commerce'; +const basePath = '/billing'; const organizationBasePath = '/organizations'; const userBasePath = '/users'; diff --git a/packages/clerk-js/src/core/modules/billing/namespace.ts b/packages/clerk-js/src/core/modules/billing/namespace.ts index 86ac5aeadad..b35930609ec 100644 --- a/packages/clerk-js/src/core/modules/billing/namespace.ts +++ b/packages/clerk-js/src/core/modules/billing/namespace.ts @@ -28,7 +28,7 @@ import { } from '../../resources/internal'; export class Billing implements BillingNamespace { - static readonly #pathRoot = '/commerce'; + static readonly #pathRoot = '/billing'; static path(subPath: string, param?: { orgId?: string }): string { const { orgId } = param || {}; const prefix = orgId ? `/organizations/${orgId}` : '/me'; @@ -39,7 +39,7 @@ export class Billing implements BillingNamespace { const { for: forParam, ...safeParams } = params || {}; const searchParams = { ...safeParams, payer_type: forParam === 'organization' ? 'org' : 'user' }; return await BaseResource._fetch({ - path: `/commerce/plans`, + path: Billing.path('/plans'), method: 'GET', search: convertPageToOffsetSearchParams(searchParams), }).then(res => { @@ -55,7 +55,7 @@ export class Billing implements BillingNamespace { // Inconsistent API getPlan = async (params: { id: string }): Promise => { const plan = (await BaseResource._fetch({ - path: `/commerce/plans/${params.id}`, + path: Billing.path(`/plans/${params.id}`), method: 'GET', })) as unknown as BillingPlanJSON; return new BillingPlan(plan); @@ -63,7 +63,7 @@ export class Billing implements BillingNamespace { getSubscription = async (params: GetSubscriptionParams): Promise => { return await BaseResource._fetch({ - path: params.orgId ? `/organizations/${params.orgId}/commerce/subscription` : `/me/commerce/subscription`, + path: Billing.path(`/subscription`, { orgId: params.orgId }), method: 'GET', }).then(res => new BillingSubscription(res?.response as BillingSubscriptionJSON)); }; @@ -72,7 +72,7 @@ export class Billing implements BillingNamespace { const { orgId, ...rest } = params; return await BaseResource._fetch({ - path: orgId ? `/organizations/${orgId}/commerce/statements` : `/me/commerce/statements`, + path: Billing.path(`/statements`, { orgId }), method: 'GET', search: convertPageToOffsetSearchParams(rest), }).then(res => { @@ -89,9 +89,7 @@ export class Billing implements BillingNamespace { getStatement = async (params: { id: string; orgId?: string }): Promise => { const statement = ( await BaseResource._fetch({ - path: params.orgId - ? `/organizations/${params.orgId}/commerce/statements/${params.id}` - : `/me/commerce/statements/${params.id}`, + path: Billing.path(`/statements/${params.id}`, { orgId: params.orgId }), method: 'GET', }) )?.response as unknown as BillingStatementJSON; @@ -104,7 +102,7 @@ export class Billing implements BillingNamespace { const { orgId, ...rest } = params; return await BaseResource._fetch({ - path: orgId ? `/organizations/${orgId}/commerce/payment_attempts` : `/me/commerce/payment_attempts`, + path: Billing.path(`/payment_attempts`, { orgId }), method: 'GET', search: convertPageToOffsetSearchParams(rest), }).then(res => { @@ -119,9 +117,7 @@ export class Billing implements BillingNamespace { getPaymentAttempt = async (params: { id: string; orgId?: string }): Promise => { const paymentAttempt = (await BaseResource._fetch({ - path: params.orgId - ? `/organizations/${params.orgId}/commerce/payment_attempts/${params.id}` - : `/me/commerce/payment_attempts/${params.id}`, + path: Billing.path(`/payment_attempts/${params.id}`, { orgId: params.orgId }), method: 'GET', })) as unknown as BillingPaymentJSON; return new BillingPayment(paymentAttempt); @@ -131,7 +127,7 @@ export class Billing implements BillingNamespace { const { orgId, ...rest } = params; const json = ( await BaseResource._fetch({ - path: orgId ? `/organizations/${orgId}/commerce/checkouts` : `/me/commerce/checkouts`, + path: Billing.path(`/checkouts`, { orgId }), method: 'POST', body: rest as any, }) diff --git a/packages/clerk-js/src/core/resources/BillingCheckout.ts b/packages/clerk-js/src/core/resources/BillingCheckout.ts index 3e640287771..81b052a5d1f 100644 --- a/packages/clerk-js/src/core/resources/BillingCheckout.ts +++ b/packages/clerk-js/src/core/resources/BillingCheckout.ts @@ -13,6 +13,7 @@ import type { import { unixEpochToDate } from '@/utils/date'; import { billingTotalsFromJSON } from '../../utils'; +import { Billing } from '../modules/billing/namespace'; import { BillingPayer } from './BillingPayer'; import { BaseResource, BillingPaymentMethod, BillingPlan } from './internal'; @@ -62,9 +63,7 @@ export class BillingCheckout extends BaseResource implements BillingCheckoutReso return retry( () => this._basePatch({ - path: this.payer.organizationId - ? `/organizations/${this.payer.organizationId}/commerce/checkouts/${this.id}/confirm` - : `/me/commerce/checkouts/${this.id}/confirm`, + path: Billing.path(`/checkouts/${this.id}/confirm`, { orgId: this.payer.organizationId }), body: params as any, }), { diff --git a/packages/clerk-js/src/core/resources/BillingPaymentSource.ts b/packages/clerk-js/src/core/resources/BillingPaymentSource.ts index cb47f12d87a..baf988ec618 100644 --- a/packages/clerk-js/src/core/resources/BillingPaymentSource.ts +++ b/packages/clerk-js/src/core/resources/BillingPaymentSource.ts @@ -9,6 +9,7 @@ import type { RemovePaymentMethodParams, } from '@clerk/types'; +import { Billing } from '../modules/billing/namespace'; import { BaseResource, DeletedObject } from './internal'; export class BillingPaymentMethod extends BaseResource implements BillingPaymentMethodResource { @@ -47,9 +48,7 @@ export class BillingPaymentMethod extends BaseResource implements BillingPayment const { orgId } = params ?? {}; const json = ( await BaseResource._fetch({ - path: orgId - ? `/organizations/${orgId}/commerce/payment_sources/${this.id}` - : `/me/commerce/payment_sources/${this.id}`, + path: Billing.path(`/payment_sources/${this.id}`, { orgId }), method: 'DELETE', }) )?.response as unknown as DeletedObjectJSON; @@ -60,9 +59,7 @@ export class BillingPaymentMethod extends BaseResource implements BillingPayment public async makeDefault(params?: MakeDefaultPaymentMethodParams) { const { orgId } = params ?? {}; await BaseResource._fetch({ - path: orgId - ? `/organizations/${orgId}/commerce/payers/default_payment_source` - : `/me/commerce/payers/default_payment_source`, + path: Billing.path(`/payers/default_payment_source`, { orgId }), method: 'PUT', body: { payment_source_id: this.id } as any, }); diff --git a/packages/clerk-js/src/core/resources/BillingSubscription.ts b/packages/clerk-js/src/core/resources/BillingSubscription.ts index 1c2a5754f18..1e0a9f9c846 100644 --- a/packages/clerk-js/src/core/resources/BillingSubscription.ts +++ b/packages/clerk-js/src/core/resources/BillingSubscription.ts @@ -13,6 +13,7 @@ import type { import { unixEpochToDate } from '@/utils/date'; import { billingMoneyAmountFromJSON } from '../../utils'; +import { Billing } from '../modules/billing/namespace'; import { BaseResource, BillingPlan, DeletedObject } from './internal'; export class BillingSubscription extends BaseResource implements BillingSubscriptionResource { @@ -110,9 +111,7 @@ export class BillingSubscriptionItem extends BaseResource implements BillingSubs const { orgId } = params; const json = ( await BaseResource._fetch({ - path: orgId - ? `/organizations/${orgId}/commerce/subscription_items/${this.id}` - : `/me/commerce/subscription_items/${this.id}`, + path: Billing.path(`/subscription_items/${this.id}`, { orgId }), method: 'DELETE', }) )?.response as unknown as DeletedObjectJSON; From c5090604612da78e0738ab9b7562b53a67fa59c3 Mon Sep 17 00:00:00 2001 From: panteliselef Date: Sat, 11 Oct 2025 00:34:34 +0300 Subject: [PATCH 2/2] fix --- packages/clerk-js/src/core/modules/billing/namespace.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/clerk-js/src/core/modules/billing/namespace.ts b/packages/clerk-js/src/core/modules/billing/namespace.ts index b35930609ec..cb61eef0f88 100644 --- a/packages/clerk-js/src/core/modules/billing/namespace.ts +++ b/packages/clerk-js/src/core/modules/billing/namespace.ts @@ -39,7 +39,7 @@ export class Billing implements BillingNamespace { const { for: forParam, ...safeParams } = params || {}; const searchParams = { ...safeParams, payer_type: forParam === 'organization' ? 'org' : 'user' }; return await BaseResource._fetch({ - path: Billing.path('/plans'), + path: `${Billing.#pathRoot}/plans`, method: 'GET', search: convertPageToOffsetSearchParams(searchParams), }).then(res => { @@ -55,7 +55,7 @@ export class Billing implements BillingNamespace { // Inconsistent API getPlan = async (params: { id: string }): Promise => { const plan = (await BaseResource._fetch({ - path: Billing.path(`/plans/${params.id}`), + path: `${Billing.#pathRoot}/plans/${params.id}`, method: 'GET', })) as unknown as BillingPlanJSON; return new BillingPlan(plan);