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..cb61eef0f88 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.#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: `/commerce/plans/${params.id}`, + path: `${Billing.#pathRoot}/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/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;