1414//
1515
1616import { concatLink , type WorkspaceUuid } from '@hcengineering/core'
17- import { CreateSubscriptionResponse , SubscribeRequest , CheckoutStatus , SubscriptionData } from './types'
17+ import { CheckoutResponse , SubscribeRequest , CheckoutStatus , SubscriptionData } from './types'
1818import { PaymentError , NetworkError } from './error'
1919
2020/**
@@ -57,7 +57,7 @@ export class PaymentClient {
5757 * @param request - Subscription request details
5858 * @returns Checkout details with URL for payment
5959 */
60- async createSubscription ( workspace : WorkspaceUuid , request : SubscribeRequest ) : Promise < CreateSubscriptionResponse > {
60+ async createSubscription ( workspace : WorkspaceUuid , request : SubscribeRequest ) : Promise < CheckoutResponse > {
6161 const path = `/api/v1/subscriptions/${ workspace } /subscribe`
6262 const url = new URL ( concatLink ( this . endpoint , path ) )
6363 const body = JSON . stringify ( request )
@@ -66,7 +66,7 @@ export class PaymentClient {
6666 headers : { ...this . headers } ,
6767 body
6868 } )
69- return ( await response . json ( ) ) as CreateSubscriptionResponse
69+ return ( await response . json ( ) ) as CheckoutResponse
7070 }
7171
7272 /**
@@ -113,11 +113,13 @@ export class PaymentClient {
113113
114114 /**
115115 * Update a subscription to a different plan
116+ * For free-to-paid upgrades, returns CheckoutResponse (requires checkout)
117+ * For paid-to-paid updates, returns SubscriptionData (direct update)
116118 * @param subscriptionId - Subscription ID to update
117119 * @param plan - New plan name
118- * @returns Updated subscription details
120+ * @returns CheckoutResponse for free-to-paid upgrades or updated SubscriptionData for direct updates
119121 */
120- async updateSubscriptionPlan ( subscriptionId : string , plan : string ) : Promise < SubscriptionData > {
122+ async updateSubscriptionPlan ( subscriptionId : string , plan : string ) : Promise < SubscriptionData | CheckoutResponse > {
121123 const path = `/api/v1/subscriptions/${ subscriptionId } /updatePlan`
122124 const url = new URL ( concatLink ( this . endpoint , path ) )
123125 const body = JSON . stringify ( { plan } )
@@ -126,7 +128,7 @@ export class PaymentClient {
126128 headers : { ...this . headers } ,
127129 body
128130 } )
129- return ( await response . json ( ) ) as SubscriptionData
131+ return ( await response . json ( ) ) as ( SubscriptionData | CheckoutResponse )
130132 }
131133
132134 /**
0 commit comments