@@ -3,26 +3,47 @@ import type {
33 __experimental_CommerceCheckoutJSON ,
44 __experimental_CommercePlanResource ,
55 __experimental_CommerceProductJSON ,
6+ __experimental_CommerceSubscriptionJSON ,
7+ __experimental_CommerceSubscriptionResource ,
68 __experimental_CreateCheckoutParams ,
79 __experimental_GetPlansParams ,
810 ClerkPaginatedResponse ,
911} from '@clerk/types' ;
1012
11- import { convertPageToOffsetSearchParams } from '../../../utils/convertPageToOffsetSearchParams' ;
12- import { __experimental_CommerceCheckout , __experimental_CommercePlan , BaseResource } from '../../resources/internal' ;
13+ import {
14+ __experimental_CommerceCheckout ,
15+ __experimental_CommercePlan ,
16+ __experimental_CommerceSubscription ,
17+ BaseResource ,
18+ } from '../../resources/internal' ;
1319
1420export class __experimental_CommerceBilling implements __experimental_CommerceBillingNamespace {
1521 getPlans = async ( params ?: __experimental_GetPlansParams ) : Promise < __experimental_CommercePlanResource [ ] > => {
1622 const { data : products } = ( await BaseResource . _fetch ( {
1723 path : `/commerce/products` ,
1824 method : 'GET' ,
19- search : convertPageToOffsetSearchParams ( params ) ,
25+ search : { payerType : params ?. subscriberType || '' } ,
2026 } ) ) as unknown as ClerkPaginatedResponse < __experimental_CommerceProductJSON > ;
2127
2228 const defaultProduct = products . find ( product => product . is_default ) ;
2329 return defaultProduct ?. plans . map ( plan => new __experimental_CommercePlan ( plan ) ) || [ ] ;
2430 } ;
2531
32+ getSubscriptions = async ( ) : Promise < ClerkPaginatedResponse < __experimental_CommerceSubscriptionResource > > => {
33+ return await BaseResource . _fetch ( {
34+ path : `/me/subscriptions` ,
35+ method : 'GET' ,
36+ } ) . then ( res => {
37+ const { data : subscriptions , total_count } =
38+ res ?. response as unknown as ClerkPaginatedResponse < __experimental_CommerceSubscriptionJSON > ;
39+
40+ return {
41+ total_count,
42+ data : subscriptions . map ( subscription => new __experimental_CommerceSubscription ( subscription ) ) ,
43+ } ;
44+ } ) ;
45+ } ;
46+
2647 startCheckout = async ( params : __experimental_CreateCheckoutParams ) => {
2748 const json = (
2849 await BaseResource . _fetch < __experimental_CommerceCheckoutJSON > ( {
0 commit comments