Skip to content

Commit f3eda95

Browse files
committed
Support free tier, support changing free to paid, support changing canceled sub
Signed-off-by: Alexey Zinoviev <[email protected]>
1 parent 73d8518 commit f3eda95

File tree

24 files changed

+243
-86
lines changed

24 files changed

+243
-86
lines changed

packages/payment-client/src/client.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//
1515

1616
import { concatLink, type WorkspaceUuid } from '@hcengineering/core'
17-
import { CreateSubscriptionResponse, SubscribeRequest, CheckoutStatus, SubscriptionData } from './types'
17+
import { CheckoutResponse, SubscribeRequest, CheckoutStatus, SubscriptionData } from './types'
1818
import { 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
/**

packages/payment-client/src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ export interface SubscribeRequest {
4141
}
4242

4343
/**
44-
* Subscription creation response
44+
* Checkout creation response
4545
* Contains checkout details for payment
4646
*/
47-
export interface CreateSubscriptionResponse {
47+
export interface CheckoutResponse {
4848
checkoutId: string // Checkout session ID
4949
checkoutUrl: string // URL to redirect user to for payment
5050
}

plugins/billing-assets/lang/cs.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@
2727
"UnlimitedUsers": "Neomezení uživatelé",
2828
"UnlimitedObjects": "Neomezené Huly objekty",
2929
"Upgrade": "Upgradovat",
30+
"Subscribe": "Přihlásit se",
3031
"Monthly": "Měsíčně",
3132
"Acitve": "Aktivní",
33+
"NoActivePlan": "Žádný aktivní plán",
34+
"SelectPlanToBegin": "Chcete-li začít, vyberte plán níže",
3235
"SubscriptionEnds": "Do {date}",
3336
"SubscriptionRenews": "Obnovení: {date}",
3437
"SubscriptionValidUntil": "Platné do {date}",

plugins/billing-assets/lang/de.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@
2727
"UnlimitedUsers": "Unbegrenzte Benutzer",
2828
"UnlimitedObjects": "Unbegrenzte Huly-Objekte",
2929
"ChangePlan": "Plan ändern",
30+
"Subscribe": "Abonnieren",
3031
"Monthly": "Monatlich",
3132
"Active": "Aktiv",
33+
"NoActivePlan": "Kein aktiver Plan",
34+
"SelectPlanToBegin": "Wählen Sie unten einen Plan aus, um zu beginnen",
3235
"SubscriptionEnds": "Bis {date}",
3336
"SubscriptionRenews": "Nächste Erneuerung: {date}",
3437
"SubscriptionValidUntil": "Gültig bis {date}",

plugins/billing-assets/lang/en.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@
2727
"UnlimitedUsers": "Unlimited users",
2828
"UnlimitedObjects": "Unlimited Huly objects",
2929
"ChangePlan": "Change plan",
30+
"Subscribe": "Subscribe",
3031
"Monthly": "Monthly",
3132
"Active": "Active",
33+
"NoActivePlan": "No active plan",
34+
"SelectPlanToBegin": "Select a plan below to get started",
3235
"SubscriptionEnds": "Until {date}",
3336
"SubscriptionRenews": "Next renewal: {date}",
3437
"SubscriptionValidUntil": "Valid until {date}",

plugins/billing-assets/lang/es.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"UnlimitedUsers": "Usuarios ilimitados",
2828
"UnlimitedObjects": "Objetos Huly ilimitados",
2929
"ChangePlan": "Cambiar plan",
30+
"Subscribe": "Suscribirse",
3031
"Monthly": "Mensual",
3132
"Active": "Activo",
3233
"SubscriptionEnds": "Hasta {date}",
@@ -46,6 +47,8 @@
4647
"UncancelDescription": "Su suscripción se reactivará y continuará desde el final del período de facturación actual.",
4748
"PriceDifference": "Diferencia de precio: {amount}",
4849
"DialogCancel": "Cancelar",
49-
"DialogConfirm": "Confirmar"
50+
"DialogConfirm": "Confirmar",
51+
"NoActivePlan": "Sin plan activo",
52+
"SelectPlanToBegin": "Selecciona un plan a continuación para comenzar"
5053
}
5154
}

plugins/billing-assets/lang/fr.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@
2727
"UnlimitedUsers": "Utilisateurs illimités",
2828
"UnlimitedObjects": "Objets Huly illimités",
2929
"ChangePlan": "Changer de plan",
30+
"Subscribe": "S'abonner",
3031
"Monthly": "Mensuel",
3132
"Active": "Actif",
33+
"NoActivePlan": "Aucun plan actif",
34+
"SelectPlanToBegin": "Sélectionnez un plan ci-dessous pour commencer",
3235
"SubscriptionEnds": "Jusqu'au {date}",
3336
"SubscriptionRenews": "Prochain renouvellement: {date}",
3437
"SubscriptionValidUntil": "Valide jusqu'au {date}",

plugins/billing-assets/lang/it.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@
2727
"UnlimitedUsers": "Utenti illimitati",
2828
"UnlimitedObjects": "Oggetti Huly illimitati",
2929
"ChangePlan": "Cambia piano",
30+
"Subscribe": "Sottoscrivi",
3031
"Monthly": "Mensile",
3132
"Active": "Attivo",
33+
"NoActivePlan": "Nessun piano attivo",
34+
"SelectPlanToBegin": "Seleziona un piano di seguito per iniziare",
3235
"SubscriptionEnds": "Fino al {date}",
3336
"SubscriptionRenews": "Prossimo rinnovo: {date}",
3437
"SubscriptionValidUntil": "Valido fino al {date}",

plugins/billing-assets/lang/ja.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"UnlimitedUsers": "無制限のユーザー",
2828
"UnlimitedObjects": "無制限のHulyオブジェクト",
2929
"ChangePlan": "プラン変更",
30+
"Subscribe": "購読",
3031
"Monthly": "月額",
3132
"Active": "アクティブ",
3233
"SubscriptionEnds": "{date}まで",
@@ -46,6 +47,8 @@
4647
"UncancelDescription": "サブスクリプションが再度有効化され、現在の請求期間の終了から継続します。",
4748
"PriceDifference": "価格差: {amount}",
4849
"DialogCancel": "キャンセル",
49-
"DialogConfirm": "確認"
50+
"DialogConfirm": "確認",
51+
"NoActivePlan": "アクティブなプランなし",
52+
"SelectPlanToBegin": "下記からプランを選択して開始してください"
5053
}
5154
}

plugins/billing-assets/lang/pt.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@
2727
"UnlimitedUsers": "Usuários ilimitados",
2828
"UnlimitedObjects": "Objetos Huly ilimitados",
2929
"ChangePlan": "Alterar plano",
30+
"Subscribe": "Assinar",
3031
"Monthly": "Mensal",
3132
"Active": "Ativo",
33+
"NoActivePlan": "Nenhum plano ativo",
34+
"SelectPlanToBegin": "Selecione um plano abaixo para começar",
3235
"SubscriptionEnds": "Até {date}",
3336
"SubscriptionRenews": "Próxima renovação: {date}",
3437
"SubscriptionValidUntil": "Válido até {date}",

0 commit comments

Comments
 (0)