Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

More stripe migration

Matt Robertsbeeae4ca3353
diff --git a/app/handlers/billing.go b/app/handlers/billing.go
index 4f141bd48..12396db5c 100644
--- a/app/handlers/billing.go
+++ b/app/handlers/billing.go
@@ -27,6 +27,7 @@ func ManageBilling() web.HandlerFunc {
Data: web.Map{
"stripeCustomerID": billingState.Result.CustomerID,
"stripeSubscriptionID": billingState.Result.SubscriptionID,
+ "isPro": c.Tenant().IsPro,
},
})
}
diff --git a/app/handlers/webhooks/stripe.go b/app/handlers/webhooks/stripe.go
index bce7e3bea..6e013c010 100644
--- a/app/handlers/webhooks/stripe.go
+++ b/app/handlers/webhooks/stripe.go
@@ -6,11 +6,14 @@ import (
"github.com/getfider/fider/app/models/cmd"
"github.com/getfider/fider/app/models/dto"
+ "github.com/getfider/fider/app/models/enum"
+ "github.com/getfider/fider/app/models/query"
"github.com/getfider/fider/app/pkg/bus"
"github.com/getfider/fider/app/pkg/env"
"github.com/getfider/fider/app/pkg/errors"
"github.com/getfider/fider/app/pkg/log"
"github.com/getfider/fider/app/pkg/web"
+ "github.com/getfider/fider/app/tasks"
"github.com/stripe/stripe-go/v83"
"github.com/stripe/stripe-go/v83/webhook"
)
@@ -70,6 +73,18 @@ func handleCheckoutSessionCompleted(c *web.Context, event stripe.Event) error {
"TenantID": tenantID,
})
+ // Update UserList with new plan
+ if env.Config.UserList.Enabled {
+ getTenant := &query.GetTenantByDomain{Domain: strconv.Itoa(tenantID)}
+ if err := bus.Dispatch(c, getTenant); err == nil && getTenant.Result != nil {
+ c.Enqueue(tasks.UserListUpdateCompany(&dto.UserListUpdateCompany{
+ TenantID: tenantID,
+ Name: getTenant.Result.Name,
+ Plan: enum.PlanPro,
+ }))
+ }
+ }
+
return c.Ok(web.Map{})
}
@@ -105,5 +120,17 @@ func handleSubscriptionDeleted(c *web.Context, event stripe.Event) error {
"TenantID": tenantID,
})
+ // Update UserList with new plan
+ if env.Config.UserList.Enabled {
+ getTenant := &query.GetTenantByDomain{Domain: strconv.Itoa(tenantID)}
+ if err := bus.Dispatch(c, getTenant); err == nil && getTenant.Result != nil {
+ c.Enqueue(tasks.UserListUpdateCompany(&dto.UserListUpdateCompany{
+ TenantID: tenantID,
+ Name: getTenant.Result.Name,
+ Plan: enum.PlanFree,
+ }))
+ }
+ }
+
return c.Ok(web.Map{})
}
diff --git a/app/models/cmd/billing.go b/app/models/cmd/billing.go
index ea300d574..1ff09d32f 100644
--- a/app/models/cmd/billing.go
+++ b/app/models/cmd/billing.go
@@ -1,16 +1,11 @@
package cmd
-import (
- "time"
-)
-
type ActivateBillingSubscription struct {
TenantID int
}
type CancelBillingSubscription struct {
- TenantID int
- SubscriptionEndsAt time.Time
+ TenantID int
}
type ActivateStripeSubscription struct {
diff --git a/app/models/cmd/userlist.go b/app/models/cmd/userlist.go
index 2da89f581..29887000c 100644
--- a/app/models/cmd/userlist.go
+++ b/app/models/cmd/userlist.go
@@ -3,20 +3,20 @@ package cmd
import "github.com/getfider/fider/app/models/enum"
type UserListCreateCompany struct {
- Name string
- TenantId int
- SignedUpAt string
- BillingStatus string
- Subdomain string
- UserId int
- UserEmail string
- UserName string
+ Name string
+ TenantId int
+ SignedUpAt string
+ Plan enum.Plan
+ Subdomain string
+ UserId int
+ UserEmail string
+ UserName string
}
type UserListUpdateCompany struct {
- TenantId int
- Name string
- BillingStatus enum.BillingStatus
+ TenantId int
+ Name string
+ Plan enum.Plan
}
type UserListUpdateUser struct {
diff --git a/app/models/dto/userlist.go b/app/models/dto/userlist.go
index 8679684d9..2eb183f14 100644
--- a/app/models/dto/userlist.go
+++ b/app/models/dto/userlist.go
@@ -3,7 +3,7 @@ package dto
import "github.com/getfider/fider/app/models/enum"
type UserListUpdateCompany struct {
- TenantID int
- Name string
- BillingStatus enum.BillingStatus
+ TenantID int
+ Name string
+ Plan enum.Plan
}
diff --git a/app/models/entity/billing.go b/app/models/entity/billing.go
index 6c05577e5..294eb84de 100644
--- a/app/models/entity/billing.go
+++ b/app/models/entity/billing.go
@@ -1,16 +1,5 @@
package entity
-import (
- "time"
-
- "github.com/getfider/fider/app/models/enum"
-)
-
-type BillingState struct {
- Status enum.BillingStatus `json:"status"`
- SubscriptionEndsAt *time.Time `json:"subscriptionEndsAt"`
-}
-
type BillingSubscription struct {
UpdateURL string `json:"updateURL"`
CancelURL string `json:"cancelURL"`
diff --git a/app/models/entity/tenant.go b/app/models/entity/tenant.go
index 788013c0d..ae1dd009b 100644
--- a/app/models/entity/tenant.go
+++ b/app/models/entity/tenant.go
@@ -4,22 +4,23 @@ import "github.com/getfider/fider/app/models/enum"
// Tenant represents a tenant
type Tenant struct {
- ID int `json:"id"`
- Name string `json:"name"`
- Subdomain string `json:"subdomain"`
- Invitation string `json:"invitation"`
- WelcomeMessage string `json:"welcomeMessage"`
- CNAME string `json:"cname"`
- Status enum.TenantStatus `json:"status"`
- Locale string `json:"locale"`
- IsPrivate bool `json:"isPrivate"`
- LogoBlobKey string `json:"logoBlobKey"`
- CustomCSS string `json:"-"`
- AllowedSchemes string `json:"allowedSchemes"`
- IsEmailAuthAllowed bool `json:"isEmailAuthAllowed"`
- IsFeedEnabled bool `json:"isFeedEnabled"`
- PreventIndexing bool `json:"preventIndexing"`
- IsModerationEnabled bool `json:"isModerationEnabled"`
+ ID int `json:"id"`
+ Name string `json:"name"`
+ Subdomain string `json:"subdomain"`
+ Invitation string `json:"invitation"`
+ WelcomeMessage string `json:"welcomeMessage"`
+ CNAME string `json:"cname"`
+ Status enum.TenantStatus `json:"status"`
+ Locale string `json:"locale"`
+ IsPrivate bool `json:"isPrivate"`
+ LogoBlobKey string `json:"logoBlobKey"`
+ CustomCSS string `json:"-"`
+ AllowedSchemes string `json:"allowedSchemes"`
+ IsEmailAuthAllowed bool `json:"isEmailAuthAllowed"`
+ IsFeedEnabled bool `json:"isFeedEnabled"`
+ PreventIndexing bool `json:"preventIndexing"`
+ IsModerationEnabled bool `json:"isModerationEnabled"`
+ IsPro bool `json:"isPro"`
}
func (t *Tenant) IsDisabled() bool {
diff --git a/app/models/enum/billing.go b/app/models/enum/billing.go
deleted file mode 100644
index e5ba540f8..000000000
--- a/app/models/enum/billing.go
+++ /dev/null
@@ -1,26 +0,0 @@
-package enum
-
-type BillingStatus int
-
-var (
- //BillingActive is used for tenants with an active subscription
- BillingActive BillingStatus = 2
- //BillingCancelled is used for tenants that had an active subscription, but have cancelled it
- BillingCancelled BillingStatus = 3
- //BillingFreeForever is used for tenants that are on a forever free plan
- BillingFreeForever BillingStatus = 4
- //BillingOpenCollective is used for tenants that have an active open collective subsription
- BillingOpenCollective BillingStatus = 5
-)
-
-var billingStatusIDs = map[BillingStatus]string{
- BillingActive: "active",
- BillingCancelled: "cancelled",
- BillingFreeForever: "free_forever",
- BillingOpenCollective: "open_collective",
-}
-
-// String returns the string version of the billing status
-func (status BillingStatus) String() string {
- return billingStatusIDs[status]
-}
diff --git a/app/models/enum/plan.go b/app/models/enum/plan.go
new file mode 100644
index 000000000..606d8a222
--- /dev/null
+++ b/app/models/enum/plan.go
@@ -0,0 +1,20 @@
+package enum
+
+type Plan int
+
+var (
+ //PlanFree is used for tenants on the free plan
+ PlanFree Plan = 1
+ //PlanPro is used for tenants on the pro plan
+ PlanPro Plan = 2
+)
+
+var planIDs = map[Plan]string{
+ PlanFree: "free",
+ PlanPro: "pro",
+}
+
+// String returns the string version of the plan
+func (p Plan) String() string {
+ return planIDs[p]
+}
diff --git a/app/models/query/billing.go b/app/models/query/billing.go
index 1a2b6a88f..1a5a5c42b 100644
--- a/app/models/query/billing.go
+++ b/app/models/query/billing.go
@@ -4,11 +4,6 @@ import (
"github.com/getfider/fider/app/models/entity"
)
-type GetBillingState struct {
- // Output
- Result *entity.BillingState
-}
-
type GetBillingSubscription struct {
SubscriptionID string
diff --git a/app/pkg/dbx/setup.sql b/app/pkg/dbx/setup.sql
index 17badcfb8..da434a116 100644
--- a/app/pkg/dbx/setup.sql
+++ b/app/pkg/dbx/setup.sql
@@ -2,8 +2,8 @@ TRUNCATE TABLE blobs RESTART IDENTITY CASCADE;
TRUNCATE TABLE logs RESTART IDENTITY CASCADE;
TRUNCATE TABLE tenants RESTART IDENTITY CASCADE;
-INSERT INTO tenants (name, subdomain, created_at, cname, invitation, welcome_message, status, is_private, custom_css, logo_bkey, locale, is_email_auth_allowed, is_feed_enabled, prevent_indexing, is_moderation_enabled)
-VALUES ('Demonstration', 'demo', now(), '', '', '', 1, false, '', '', 'en', true, true, false, false);
+INSERT INTO tenants (name, subdomain, created_at, cname, invitation, welcome_message, status, is_private, custom_css, logo_bkey, locale, is_email_auth_allowed, is_feed_enabled, prevent_indexing, is_moderation_enabled, is_pro)
+VALUES ('Demonstration', 'demo', now(), '', '', '', 1, false, '', '', 'en', true, true, false, false, false);
INSERT INTO users (name, email, tenant_id, created_at, role, status, avatar_type, avatar_bkey)
VALUES ('Jon Snow', '[email protected]', 1, now(), 3, 1, 2, '');
@@ -18,8 +18,8 @@ VALUES (2, 1, 'google', 'GO5678', now());
INSERT INTO users (name, email, tenant_id, created_at, role, status, avatar_type, avatar_bkey)
VALUES ('Sansa Stark', '[email protected]', 1, now(), 1, 1, 2, '');
-INSERT INTO tenants (name, subdomain, created_at, cname, invitation, welcome_message, status, is_private, custom_css, logo_bkey, locale, is_email_auth_allowed, is_feed_enabled, prevent_indexing, is_moderation_enabled)
-VALUES ('Avengers', 'avengers', now(), 'feedback.avengers.com', '', '', 1, false, '', '', 'en', true, true, false, false);
+INSERT INTO tenants (name, subdomain, created_at, cname, invitation, welcome_message, status, is_private, custom_css, logo_bkey, locale, is_email_auth_allowed, is_feed_enabled, prevent_indexing, is_moderation_enabled, is_pro)
+VALUES ('Avengers', 'avengers', now(), 'feedback.avengers.com', '', '', 1, false, '', '', 'en', true, true, false, false, false);
INSERT INTO users (name, email, tenant_id, created_at, role, status, avatar_type, avatar_bkey)
VALUES ('Tony Stark', '[email protected]', 2, now(), 3, 1, 2, '');
@@ -31,18 +31,15 @@ VALUES ('The Hulk', '[email protected]', 2, now(), 1, 1, 2, '');
INSERT INTO user_providers (user_id, tenant_id, provider, provider_uid, created_at)
VALUES (5, 2, 'google', 'GO1111', now());
--- Create a tenant with a cancelled subscription
-INSERT INTO tenants (name, subdomain, created_at, cname, invitation, welcome_message, status, is_private, custom_css, logo_bkey, locale, is_email_auth_allowed, is_feed_enabled, prevent_indexing, is_moderation_enabled )
-VALUES ('Cancelled Subscription', 'cancelled-sub', now(), 'feedback.cancelled-sub.com', '', '', 1, false, '', '', 'en', true, true, false, false);
-INSERT INTO tenants_billing (tenant_id, status, subscription_ends_at)
-VALUES (3, 3, now());
+INSERT INTO tenants (name, subdomain, created_at, cname, invitation, welcome_message, status, is_private, custom_css, logo_bkey, locale, is_email_auth_allowed, is_feed_enabled, prevent_indexing, is_moderation_enabled, is_pro)
+VALUES ('Orange Inc', 'orange', now(), 'feedback.orange.com', '', '', 1, false, '', '', 'en', true, true, false, false, false);
INSERT INTO users (name, email, tenant_id, created_at, role, status, avatar_type, avatar_bkey)
-VALUES ('Cancelled Admin', '[email protected]', 3, now(), 3, 1, 2, '');
+VALUES ('Orange Admin', '[email protected]', 3, now(), 3, 1, 2, '');
INSERT INTO user_providers (user_id, tenant_id, provider, provider_uid, created_at)
VALUES (6, 3, 'facebook', 'FB3333', now());
-INSERT INTO tenants (name, subdomain, created_at, cname, invitation, welcome_message, status, is_private, custom_css, logo_bkey, locale, is_email_auth_allowed, is_feed_enabled, prevent_indexing, is_moderation_enabled)
-VALUES ('Demonstration German', 'german', now(), '', '', '', 1, false, '', '', 'de', true, true, false, false);
+INSERT INTO tenants (name, subdomain, created_at, cname, invitation, welcome_message, status, is_private, custom_css, logo_bkey, locale, is_email_auth_allowed, is_feed_enabled, prevent_indexing, is_moderation_enabled, is_pro)
+VALUES ('Demonstration German', 'german', now(), '', '', '', 1, false, '', '', 'de', true, true, false, false, false);
INSERT INTO users (name, email, tenant_id, created_at, role, status, avatar_type, avatar_bkey)
VALUES ('Jon Snow', '[email protected]', 4, now(), 3, 1, 2, '');
diff --git a/app/services/sqlstore/dbEntities/billing.go b/app/services/sqlstore/dbEntities/billing.go
index f89679a56..4e70f4878 100644
--- a/app/services/sqlstore/dbEntities/billing.go
+++ b/app/services/sqlstore/dbEntities/billing.go
@@ -1,31 +1,10 @@
package dbEntities
import (
- "context"
-
- "github.com/getfider/fider/app/models/entity"
- "github.com/getfider/fider/app/models/enum"
"github.com/getfider/fider/app/pkg/dbx"
)
-type BillingState struct {
- Status int `db:"status"`
- SubscriptionEndsAt dbx.NullTime `db:"subscription_ends_at"`
-}
-
type StripeBillingState struct {
StripeCustomerID dbx.NullString `db:"stripe_customer_id"`
StripeSubscriptionID dbx.NullString `db:"stripe_subscription_id"`
}
-
-func (s *BillingState) ToModel(ctx context.Context) *entity.BillingState {
- model := &entity.BillingState{
- Status: enum.BillingStatus(s.Status),
- }
-
- if s.SubscriptionEndsAt.Valid {
- model.SubscriptionEndsAt = &s.SubscriptionEndsAt.Time
- }
-
- return model
-}
diff --git a/app/services/sqlstore/dbEntities/tenant.go b/app/services/sqlstore/dbEntities/tenant.go
index 49f1b078c..85f3a3811 100644
--- a/app/services/sqlstore/dbEntities/tenant.go
+++ b/app/services/sqlstore/dbEntities/tenant.go
@@ -22,6 +22,7 @@ type Tenant struct {
IsFeedEnabled bool `db:"is_feed_enabled"`
PreventIndexing bool `db:"prevent_indexing"`
IsModerationEnabled bool `db:"is_moderation_enabled"`
+ IsPro bool `db:"is_pro"`
}
func (t *Tenant) ToModel() *entity.Tenant {
@@ -46,6 +47,7 @@ func (t *Tenant) ToModel() *entity.Tenant {
IsFeedEnabled: t.IsFeedEnabled,
PreventIndexing: t.PreventIndexing,
IsModerationEnabled: t.IsModerationEnabled,
+ IsPro: t.IsPro,
}
return tenant
diff --git a/app/services/sqlstore/postgres/billing.go b/app/services/sqlstore/postgres/billing.go
index 516045d7b..d10d4c2d9 100644
--- a/app/services/sqlstore/postgres/billing.go
+++ b/app/services/sqlstore/postgres/billing.go
@@ -13,41 +13,11 @@ import (
"github.com/getfider/fider/app/services/sqlstore/dbEntities"
)
-func getBillingState(ctx context.Context, q *query.GetBillingState) error {
- return using(ctx, func(trx *dbx.Trx, tenant *entity.Tenant, user *entity.User) error {
- q.Result = nil
-
- state := dbEntities.BillingState{}
- err := trx.Get(&state,
- `SELECT
- subscription_ends_at,
- status
- FROM tenants_billing
- WHERE tenant_id = $1`, tenant.ID)
-
- if err != nil {
- return err
- }
-
- q.Result = state.ToModel(ctx)
- return nil
- })
-}
-
func activateBillingSubscription(ctx context.Context, c *cmd.ActivateBillingSubscription) error {
return using(ctx, func(trx *dbx.Trx, _ *entity.Tenant, _ *entity.User) error {
_, err := trx.Execute(`
- UPDATE tenants_billing
- SET subscription_ends_at = null, status = $2
- WHERE tenant_id = $1
- `, c.TenantID, enum.BillingActive)
- if err != nil {
- return errors.Wrap(err, "failed activate billing subscription")
- }
-
- _, err = trx.Execute(`
UPDATE tenants
- SET status = $2
+ SET is_pro = true, status = $2
WHERE id = $1
`, c.TenantID, enum.TenantActive)
if err != nil {
@@ -61,13 +31,14 @@ func activateBillingSubscription(ctx context.Context, c *cmd.ActivateBillingSubs
func cancelBillingSubscription(ctx context.Context, c *cmd.CancelBillingSubscription) error {
return using(ctx, func(trx *dbx.Trx, _ *entity.Tenant, _ *entity.User) error {
_, err := trx.Execute(`
- UPDATE tenants_billing
- SET subscription_ends_at = $2, status = $3
- WHERE tenant_id = $1
- `, c.TenantID, c.SubscriptionEndsAt, enum.BillingCancelled)
+ UPDATE tenants
+ SET is_pro = false
+ WHERE id = $1
+ `, c.TenantID)
if err != nil {
- return errors.Wrap(err, "failed cancel billing subscription")
+ return errors.Wrap(err, "failed to set tenant to free plan")
}
+
return nil
})
}
@@ -100,14 +71,24 @@ func getStripeBillingState(ctx context.Context, q *query.GetStripeBillingState)
func activateStripeSubscription(ctx context.Context, c *cmd.ActivateStripeSubscription) error {
return using(ctx, func(trx *dbx.Trx, _ *entity.Tenant, _ *entity.User) error {
_, err := trx.Execute(`
- INSERT INTO tenants_billing (tenant_id, status, stripe_customer_id, stripe_subscription_id)
- VALUES ($1, 0, $2, $3)
+ INSERT INTO tenants_billing (tenant_id, stripe_customer_id, stripe_subscription_id)
+ VALUES ($1, $2, $3)
ON CONFLICT (tenant_id) DO UPDATE
SET stripe_customer_id = $2, stripe_subscription_id = $3
`, c.TenantID, c.CustomerID, c.SubscriptionID)
if err != nil {
return errors.Wrap(err, "failed to activate stripe subscription")
}
+
+ _, err = trx.Execute(`
+ UPDATE tenants
+ SET is_pro = true
+ WHERE id = $1
+ `, c.TenantID)
+ if err != nil {
+ return errors.Wrap(err, "failed to set tenant to pro plan")
+ }
+
return nil
})
}
@@ -122,6 +103,16 @@ func cancelStripeSubscription(ctx context.Context, c *cmd.CancelStripeSubscripti
if err != nil {
return errors.Wrap(err, "failed to cancel stripe subscription")
}
+
+ _, err = trx.Execute(`
+ UPDATE tenants
+ SET is_pro = false
+ WHERE id = $1
+ `, c.TenantID)
+ if err != nil {
+ return errors.Wrap(err, "failed to set tenant to free plan")
+ }
+
return nil
})
}
diff --git a/app/services/sqlstore/postgres/postgres.go b/app/services/sqlstore/postgres/postgres.go
index b1a67eef8..ea34d695a 100644
--- a/app/services/sqlstore/postgres/postgres.go
+++ b/app/services/sqlstore/postgres/postgres.go
@@ -137,7 +137,6 @@ func (s Service) Init() {
bus.AddHandler(deleteWebhook)
bus.AddHandler(markWebhookAsFailed)
- bus.AddHandler(getBillingState)
bus.AddHandler(activateBillingSubscription)
bus.AddHandler(cancelBillingSubscription)
bus.AddHandler(getStripeBillingState)
diff --git a/app/services/sqlstore/postgres/tenant.go b/app/services/sqlstore/postgres/tenant.go
index 5cc88510e..8f5fb358c 100644
--- a/app/services/sqlstore/postgres/tenant.go
+++ b/app/services/sqlstore/postgres/tenant.go
@@ -195,15 +195,6 @@ func createTenant(ctx context.Context, c *cmd.CreateTenant) error {
return err
}
- if env.IsBillingEnabled() {
- _, err := trx.Execute(
- `INSERT INTO tenants_billing (tenant_id, status)
- VALUES ($1, $2)`, id, enum.BillingActive)
- if err != nil {
- return err
- }
- }
-
byDomain := &query.GetTenantByDomain{Domain: c.Subdomain}
err = bus.Dispatch(ctx, byDomain)
c.Result = byDomain.Result
@@ -216,7 +207,7 @@ func getFirstTenant(ctx context.Context, q *query.GetFirstTenant) error {
tenant := dbEntities.Tenant{}
err := trx.Get(&tenant, `
- SELECT id, name, subdomain, cname, invitation, locale, welcome_message, status, is_private, logo_bkey, custom_css, allowed_schemes, is_email_auth_allowed, is_feed_enabled, is_moderation_enabled, prevent_indexing
+ SELECT id, name, subdomain, cname, invitation, locale, welcome_message, status, is_private, logo_bkey, custom_css, allowed_schemes, is_email_auth_allowed, is_feed_enabled, is_moderation_enabled, prevent_indexing, is_pro
FROM tenants
ORDER BY id LIMIT 1
`)
@@ -234,7 +225,7 @@ func getTenantByDomain(ctx context.Context, q *query.GetTenantByDomain) error {
tenant := dbEntities.Tenant{}
err := trx.Get(&tenant, `
- SELECT id, name, subdomain, cname, invitation, locale, welcome_message, status, is_private, logo_bkey, custom_css, allowed_schemes, is_email_auth_allowed, is_feed_enabled, is_moderation_enabled, prevent_indexing
+ SELECT id, name, subdomain, cname, invitation, locale, welcome_message, status, is_private, logo_bkey, custom_css, allowed_schemes, is_email_auth_allowed, is_feed_enabled, is_moderation_enabled, prevent_indexing, is_pro
FROM tenants t
WHERE subdomain = $1 OR subdomain = $2 OR cname = $3
ORDER BY cname DESC
diff --git a/app/services/userlist/userlist.go b/app/services/userlist/userlist.go
index 8b0020aad..ae737f3cd 100644
--- a/app/services/userlist/userlist.go
+++ b/app/services/userlist/userlist.go
@@ -153,9 +153,9 @@ func updateUserListCompany(ctx context.Context, c *cmd.UserListUpdateCompany) er
Name: c.Name,
}
- if c.BillingStatus > 0 {
+ if c.Plan > 0 {
company.Properties = map[string]interface{}{
- "billing_status": c.BillingStatus.String(),
+ "plan": c.Plan.String(),
}
}
@@ -174,8 +174,8 @@ func createUserListCompany(ctx context.Context, c *cmd.UserListCreateCompany) er
Name: c.Name,
SignedUpAt: c.SignedUpAt,
Properties: map[string]interface{}{
- "billing_status": c.BillingStatus,
- "subdomain": c.Subdomain,
+ "plan": c.Plan.String(),
+ "subdomain": c.Subdomain,
},
Users: []UserListUser{
{
diff --git a/app/services/userlist/userlist_test.go b/app/services/userlist/userlist_test.go
index d775c9f9c..e02a674bb 100644
--- a/app/services/userlist/userlist_test.go
+++ b/app/services/userlist/userlist_test.go
@@ -36,14 +36,14 @@ func TestCreateTenant_Success(t *testing.T) {
reset()
createCompanyCmd := &cmd.UserListCreateCompany{
- Name: "Fider",
- UserId: 1,
- UserEmail: "[email protected]",
- UserName: "Jon Snow",
- TenantId: 1,
- SignedUpAt: time.Now().Format(time.UnixDate),
- BillingStatus: "active",
- Subdomain: "got",
+ Name: "Fider",
+ UserId: 1,
+ UserEmail: "[email protected]",
+ UserName: "Jon Snow",
+ TenantId: 1,
+ SignedUpAt: time.Now().Format(time.UnixDate),
+ Plan: enum.PlanFree,
+ Subdomain: "got",
}
err := bus.Dispatch(ctx, createCompanyCmd)
@@ -61,9 +61,9 @@ func TestUpdateTenant_Success(t *testing.T) {
reset()
updateCompanyCmd := &cmd.UserListUpdateCompany{
- Name: "Fider",
- TenantId: 1,
- BillingStatus: enum.BillingActive,
+ Name: "Fider",
+ TenantId: 1,
+ Plan: enum.PlanPro,
}
err := bus.Dispatch(ctx, updateCompanyCmd)
@@ -75,15 +75,15 @@ func TestUpdateTenant_Success(t *testing.T) {
Expect(httpclientmock.RequestsHistory[0].Header.Get("Content-Type")).Equals("application/json")
}
-func TestUpdateTenant_BillingStatusUpdatedIfSet(t *testing.T) {
+func TestUpdateTenant_PlanUpdatedIfSet(t *testing.T) {
RegisterT(t)
env.Config.HostMode = "multi"
reset()
updateCompanyCmd := &cmd.UserListUpdateCompany{
- Name: "Fider",
- TenantId: 1,
- BillingStatus: enum.BillingActive,
+ Name: "Fider",
+ TenantId: 1,
+ Plan: enum.PlanPro,
}
err := bus.Dispatch(ctx, updateCompanyCmd)
@@ -92,15 +92,15 @@ func TestUpdateTenant_BillingStatusUpdatedIfSet(t *testing.T) {
Expect(httpclientmock.RequestsHistory).HasLen(1)
body, _ := io.ReadAll(httpclientmock.RequestsHistory[0].Body)
- containsBillingStatus := strings.Contains(string(body), "billing_status")
- Expect(containsBillingStatus).IsTrue()
+ containsPlan := strings.Contains(string(body), "plan")
+ Expect(containsPlan).IsTrue()
- // Also check we're using the enum string, not the int value
- Expect(strings.Contains(string(body), "billing_status\":\"active\"")).IsTrue()
+ // Check we're sending the plan value
+ Expect(strings.Contains(string(body), "plan\":\"pro\"")).IsTrue()
}
-func TestUpdateTenant_BillingStatusNotUpdatedIfNotSet(t *testing.T) {
+func TestUpdateTenant_PlanNotUpdatedIfNotSet(t *testing.T) {
RegisterT(t)
env.Config.HostMode = "multi"
reset()
@@ -116,8 +116,8 @@ func TestUpdateTenant_BillingStatusNotUpdatedIfNotSet(t *testing.T) {
Expect(httpclientmock.RequestsHistory).HasLen(1)
body, _ := io.ReadAll(httpclientmock.RequestsHistory[0].Body)
- containsBillingStatus := strings.Contains(string(body), "billing_status")
- Expect(containsBillingStatus).IsFalse()
+ containsPlan := strings.Contains(string(body), "plan")
+ Expect(containsPlan).IsFalse()
}
func TestUpdateTenant_NameShouldUpdateIfSet(t *testing.T) {
diff --git a/app/tasks/userlist.go b/app/tasks/userlist.go
index e7aed5579..8d2f1ef8a 100644
--- a/app/tasks/userlist.go
+++ b/app/tasks/userlist.go
@@ -18,15 +18,21 @@ func UserListCreateCompany(tenant entity.Tenant, user entity.User) worker.Task {
"Tenant": tenant.Name,
"User": user.Email,
})
+
+ plan := enum.PlanFree
+ if tenant.IsPro {
+ plan = enum.PlanPro
+ }
+
if err := bus.Dispatch(c, &cmd.UserListCreateCompany{
- Name: tenant.Name,
- TenantId: tenant.ID,
- SignedUpAt: time.Now().Format(time.RFC3339),
- BillingStatus: enum.BillingActive.String(),
- Subdomain: tenant.Subdomain,
- UserId: user.ID,
- UserEmail: user.Email,
- UserName: user.Name,
+ Name: tenant.Name,
+ TenantId: tenant.ID,
+ SignedUpAt: time.Now().Format(time.RFC3339),
+ Plan: plan,
+ Subdomain: tenant.Subdomain,
+ UserId: user.ID,
+ UserEmail: user.Email,
+ UserName: user.Name,
}); err != nil {
return c.Failure(err)
}
@@ -40,9 +46,9 @@ func UserListUpdateCompany(action *dto.UserListUpdateCompany) worker.Task {
"Tenant": action.Name,
})
if err := bus.Dispatch(c, &cmd.UserListUpdateCompany{
- TenantId: action.TenantID,
- Name: action.Name,
- BillingStatus: action.BillingStatus,
+ TenantId: action.TenantID,
+ Name: action.Name,
+ Plan: action.Plan,
}); err != nil {
return c.Failure(err)
}
diff --git a/migrations/202511251600_migrate_to_plan_system.sql b/migrations/202511251600_migrate_to_plan_system.sql
new file mode 100644
index 000000000..89b2fe50c
--- /dev/null
+++ b/migrations/202511251600_migrate_to_plan_system.sql
@@ -0,0 +1,16 @@
+-- Migrate from billing status to simple plan system
+-- Active status (2) becomes Pro plan, all others become Free plan
+
+-- Add is_pro column to tenants table
+ALTER TABLE tenants ADD COLUMN is_pro BOOLEAN NOT NULL DEFAULT false;
+
+-- Migrate existing data: Active billing status (2) -> Pro plan
+UPDATE tenants t
+SET is_pro = true
+FROM tenants_billing tb
+WHERE t.id = tb.tenant_id
+AND tb.status = 2;
+
+-- Drop unused columns from tenants_billing
+ALTER TABLE tenants_billing DROP COLUMN IF EXISTS status;
+ALTER TABLE tenants_billing DROP COLUMN IF EXISTS subscription_ends_at;
diff --git a/public/models/billing.ts b/public/models/billing.ts
deleted file mode 100644
index 2165c934d..000000000
--- a/public/models/billing.ts
+++ /dev/null
@@ -1,6 +0,0 @@
-export enum BillingStatus {
- Active = 2,
- Cancelled = 3,
- FreeForever = 4,
- OpenCollective = 5,
-}
diff --git a/public/models/identity.ts b/public/models/identity.ts
index 6b6f68063..d05692e54 100644
--- a/public/models/identity.ts
+++ b/public/models/identity.ts
@@ -13,6 +13,7 @@ export interface Tenant {
isEmailAuthAllowed: boolean
isFeedEnabled: boolean
isModerationEnabled: boolean
+ isPro: boolean
}
export enum TenantStatus {
diff --git a/public/models/index.ts b/public/models/index.ts
index 6fd4e25bb..50493048b 100644
--- a/public/models/index.ts
+++ b/public/models/index.ts
@@ -1,6 +1,5 @@
export * from "./post"
export * from "./identity"
export * from "./settings"
-export * from "./billing"
export * from "./notification"
export * from "./webhook"
diff --git a/public/pages/Administration/pages/ManageBilling.page.tsx b/public/pages/Administration/pages/ManageBilling.page.tsx
index 9557fb02f..fc31c4a25 100644
--- a/public/pages/Administration/pages/ManageBilling.page.tsx
+++ b/public/pages/Administration/pages/ManageBilling.page.tsx
@@ -10,6 +10,7 @@ import "./ManageBilling.page.scss"
interface ManageBillingPageProps {
stripeCustomerID: string
stripeSubscriptionID: string
+ isPro: boolean
}
interface PlanCardProps {
@@ -73,7 +74,7 @@ const PlanCard = (props: PlanCardProps) => {
const ManageBillingPage = (props: ManageBillingPageProps) => {
const [isLoading, setIsLoading] = useState(false)
- const hasSubscription = !!props.stripeSubscriptionID
+ const isPro = props.isPro
const openPortal = async () => {
setIsLoading(true)
@@ -109,11 +110,11 @@ const ManageBillingPage = (props: ManageBillingPageProps) => {
period="month"
description="Perfect for getting started with feedback collection."
features={freeFeatures}
- isCurrent={!hasSubscription}
+ isCurrent={!isPro}
buttonText="Downgrade"
buttonVariant="secondary"
- onButtonClick={hasSubscription ? openPortal : undefined}
- isLoading={isLoading && hasSubscription}
+ onButtonClick={isPro ? openPortal : undefined}
+ isLoading={isLoading && isPro}
/>
<PlanCard
@@ -122,11 +123,11 @@ const ManageBillingPage = (props: ManageBillingPageProps) => {
period="month"
description="For teams that need advanced features and support."
features={proFeatures}
- isCurrent={hasSubscription}
+ isCurrent={isPro}
isHighlighted={true}
- buttonText={hasSubscription ? "Manage Billing" : "Upgrade to Pro"}
+ buttonText={isPro ? "Manage Billing" : "Upgrade to Pro"}
buttonVariant="primary"
- onButtonClick={hasSubscription ? openPortal : startCheckout}
+ onButtonClick={isPro ? openPortal : startCheckout}
isLoading={isLoading}
/>
</div>