Skip to content

Commit f2a6641

Browse files
authored
chore(clerk-js, types): Add clerk.billing.getPlan() (#6230)
1 parent 524c5e0 commit f2a6641

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

.changeset/mean-cougars-obey.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@clerk/clerk-js': minor
3+
'@clerk/types': minor
4+
---
5+
6+
Add `getPlan` by id to the billing namespace.

packages/clerk-js/src/core/modules/commerce/CommerceBilling.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {
44
CommerceCheckoutJSON,
55
CommercePaymentJSON,
66
CommercePaymentResource,
7+
CommercePlanJSON,
78
CommercePlanResource,
89
CommerceProductJSON,
910
CommerceStatementJSON,
@@ -39,6 +40,14 @@ export class CommerceBilling implements CommerceBillingNamespace {
3940
return defaultProduct?.plans.map(plan => new CommercePlan(plan)) || [];
4041
};
4142

43+
getPlan = async (params: { id: string }): Promise<CommercePlanResource> => {
44+
const plan = (await BaseResource._fetch({
45+
path: `/commerce/plans/${params.id}`,
46+
method: 'GET',
47+
})) as unknown as CommercePlanJSON;
48+
return new CommercePlan(plan);
49+
};
50+
4251
getSubscriptions = async (
4352
params: GetSubscriptionsParams,
4453
): Promise<ClerkPaginatedResponse<CommerceSubscriptionResource>> => {

packages/types/src/commerce.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type WithOptionalOrgType<T> = T & {
1010
export interface CommerceBillingNamespace {
1111
getPaymentAttempts: (params: GetPaymentAttemptsParams) => Promise<ClerkPaginatedResponse<CommercePaymentResource>>;
1212
getPlans: (params?: GetPlansParams) => Promise<CommercePlanResource[]>;
13+
getPlan: (params: { id: string }) => Promise<CommercePlanResource>;
1314
getSubscriptions: (params: GetSubscriptionsParams) => Promise<ClerkPaginatedResponse<CommerceSubscriptionResource>>;
1415
getStatements: (params: GetStatementsParams) => Promise<ClerkPaginatedResponse<CommerceStatementResource>>;
1516
startCheckout: (params: CreateCheckoutParams) => Promise<CommerceCheckoutResource>;

0 commit comments

Comments
 (0)