Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wild-rice-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/backend': minor
---

Get user's subscription via BillingApi.
13 changes: 13 additions & 0 deletions packages/backend/src/api/endpoints/BillingApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { AbstractAPI } from './AbstractApi';

const basePath = '/commerce';
const organizationBasePath = '/organizations';
const userBasePath = '/users';

type GetOrganizationListParams = ClerkPaginationRequest<{
payerType: 'org' | 'user';
Expand Down Expand Up @@ -59,4 +60,16 @@ export class BillingAPI extends AbstractAPI {
path: joinPaths(organizationBasePath, organizationId, 'billing', 'subscription'),
});
}

/**
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change.
* It is advised to pin the SDK version to avoid breaking changes.
*/
public async getUserBillingSubscription(userId: string) {
this.requireId(userId);
return this.request<CommerceSubscription>({
method: 'GET',
path: joinPaths(userBasePath, userId, 'billing', 'subscription'),
});
}
Comment on lines +64 to +74
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add explicit return type and enrich JSDoc

Public APIs must declare explicit return types; also document param/returns in JSDoc.

   /**
-   * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change.
-   * It is advised to pin the SDK version to avoid breaking changes.
+   * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change.
+   * It is advised to pin the SDK version to avoid breaking changes.
+   *
+   * @param userId - The Clerk user ID.
+   * @returns The user's billing subscription.
    */
-  public async getUserBillingSubscription(userId: string) {
+  public async getUserBillingSubscription(userId: string): Promise<CommerceSubscription> {
     this.requireId(userId);
     return this.request<CommerceSubscription>({
       method: 'GET',
       path: joinPaths(userBasePath, userId, 'billing', 'subscription'),
     });
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/**
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change.
* It is advised to pin the SDK version to avoid breaking changes.
*/
public async getUserBillingSubscription(userId: string) {
this.requireId(userId);
return this.request<CommerceSubscription>({
method: 'GET',
path: joinPaths(userBasePath, userId, 'billing', 'subscription'),
});
}
/**
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change.
* It is advised to pin the SDK version to avoid breaking changes.
*
* @param userId - The Clerk user ID.
* @returns The user's billing subscription.
*/
public async getUserBillingSubscription(userId: string): Promise<CommerceSubscription> {
this.requireId(userId);
return this.request<CommerceSubscription>({
method: 'GET',
path: joinPaths(userBasePath, userId, 'billing', 'subscription'),
});
}
🤖 Prompt for AI Agents
In packages/backend/src/api/endpoints/BillingApi.ts around lines 64 to 74, the
public method getUserBillingSubscription lacks an explicit return type and its
JSDoc is minimal; update the method signature to declare an explicit return type
(Promise<CommerceSubscription>) and expand the JSDoc to include @param {string}
userId description and @returns {Promise<CommerceSubscription>} description,
ensuring the docstring mentions experimental status and potential null/undefined
behavior if applicable.

}
Loading