diff --git a/.changeset/mean-cougars-obey.md b/.changeset/mean-cougars-obey.md new file mode 100644 index 00000000000..1ba730abd8d --- /dev/null +++ b/.changeset/mean-cougars-obey.md @@ -0,0 +1,6 @@ +--- +'@clerk/clerk-js': minor +'@clerk/types': minor +--- + +Add `getPlan` by id to the billing namespace. diff --git a/packages/clerk-js/src/core/modules/commerce/CommerceBilling.ts b/packages/clerk-js/src/core/modules/commerce/CommerceBilling.ts index 5426968522b..f454e9ff848 100644 --- a/packages/clerk-js/src/core/modules/commerce/CommerceBilling.ts +++ b/packages/clerk-js/src/core/modules/commerce/CommerceBilling.ts @@ -4,6 +4,7 @@ import type { CommerceCheckoutJSON, CommercePaymentJSON, CommercePaymentResource, + CommercePlanJSON, CommercePlanResource, CommerceProductJSON, CommerceStatementJSON, @@ -39,6 +40,14 @@ export class CommerceBilling implements CommerceBillingNamespace { return defaultProduct?.plans.map(plan => new CommercePlan(plan)) || []; }; + getPlan = async (params: { id: string }): Promise => { + const plan = (await BaseResource._fetch({ + path: `/commerce/plans/${params.id}`, + method: 'GET', + })) as unknown as CommercePlanJSON; + return new CommercePlan(plan); + }; + getSubscriptions = async ( params: GetSubscriptionsParams, ): Promise> => { diff --git a/packages/types/src/commerce.ts b/packages/types/src/commerce.ts index 8b27f61d081..3caf459548d 100644 --- a/packages/types/src/commerce.ts +++ b/packages/types/src/commerce.ts @@ -10,6 +10,7 @@ type WithOptionalOrgType = T & { export interface CommerceBillingNamespace { getPaymentAttempts: (params: GetPaymentAttemptsParams) => Promise>; getPlans: (params?: GetPlansParams) => Promise; + getPlan: (params: { id: string }) => Promise; getSubscriptions: (params: GetSubscriptionsParams) => Promise>; getStatements: (params: GetStatementsParams) => Promise>; startCheckout: (params: CreateCheckoutParams) => Promise;