implement paywall (#161)
* implement core foundation * inject deps * fix incorrect migration * tail migration * use transaction for migration * fix: inject deps for tests * cleanup billing management for admin * upgrade stripe sdk to v85 * set price env variables * cleanup billing management * allow multiple dev windows * fix: settings scroll * feat: show nice video thumbnail in listview * feat: implement freemium restrictions * remove unnecessary comments * refactor * docs * format * tweak network settings better hierarchy
This commit was merged in pull request #161.
This commit is contained in:
+26
-9
@@ -12,6 +12,7 @@ import (
|
||||
pbaero "github.com/flowy-live/llink/genproto/aero"
|
||||
"github.com/flowy-live/llink/internal"
|
||||
"github.com/flowy-live/llink/internal/auth"
|
||||
"github.com/flowy-live/llink/internal/billing"
|
||||
"github.com/flowy-live/llink/internal/db"
|
||||
"github.com/flowy-live/llink/internal/depot"
|
||||
"github.com/flowy-live/llink/internal/handler"
|
||||
@@ -35,14 +36,11 @@ func main() {
|
||||
port := utils.MustGetEnv("PORT")
|
||||
gcsBucket := utils.MustGetEnv("GCS_BUCKET")
|
||||
|
||||
// Initialize database
|
||||
db.Init()
|
||||
defer db.Cleanup()
|
||||
|
||||
// Initialize Redis for auth
|
||||
redisClient := redisForAuth()
|
||||
|
||||
// Initialize GCS client
|
||||
ctx := context.Background()
|
||||
storageClient, err := storage.NewClient(ctx)
|
||||
if err != nil {
|
||||
@@ -64,10 +62,23 @@ func main() {
|
||||
defer aeroServer.Close()
|
||||
aeroSvc := pbaero.NewPrimaryClient(aeroServer)
|
||||
|
||||
// Initialize services
|
||||
authSvc := auth.NewAuthService(redisClient, aeroSvc)
|
||||
humanSvc := human.NewService(db.Pool())
|
||||
networkSvc := network.NewService(db.Pool(), aeroSvc)
|
||||
|
||||
billingSvc, err := billing.NewService(ctx, db.Pool(), billing.Config{
|
||||
SecretKey: utils.MustGetEnv("STRIPE_SECRET_KEY"),
|
||||
WebhookSecret: utils.MustGetEnv("STRIPE_WEBHOOK_SECRET"),
|
||||
PriceMonthlyID: utils.MustGetEnv("STRIPE_PRICE_PRO_MONTHLY"),
|
||||
PriceAnnualID: utils.MustGetEnv("STRIPE_PRICE_PRO_ANNUAL"),
|
||||
SuccessURL: utils.MustGetEnv("BILLING_SUCCESS_URL"),
|
||||
CancelURL: utils.MustGetEnv("BILLING_CANCEL_URL"),
|
||||
})
|
||||
if err != nil {
|
||||
slog.Error("failed to initialize billing service", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
networkSvc := network.NewService(db.Pool(), aeroSvc, billingSvc)
|
||||
particleSvc := particle.NewService(db.Pool(), networkSvc)
|
||||
depotSvc := depot.NewService(db.Pool(), storageClient, depot.Config{
|
||||
GoogleServiceAccountEmail: utils.MustGetEnv("GOOGLE_SERVICE_ACCOUNT_EMAIL"),
|
||||
@@ -76,7 +87,6 @@ func main() {
|
||||
waitlistSvc := waitlist.NewService(db.Pool(), aeroSvc)
|
||||
livekitClient := livekit.NewClient()
|
||||
|
||||
// Initialize Firestore client (for webhook-driven updates)
|
||||
gcpProject := utils.MustGetEnv("GCP_PROJECT")
|
||||
firestoreClient, err := firestore.NewClient(ctx, gcpProject)
|
||||
if err != nil {
|
||||
@@ -85,10 +95,8 @@ func main() {
|
||||
}
|
||||
defer firestoreClient.Close()
|
||||
|
||||
// Initialize handler
|
||||
h := handler.NewHandler(authSvc, humanSvc, networkSvc, particleSvc, depotSvc, waitlistSvc, livekitClient, firestoreClient)
|
||||
h := handler.NewHandler(authSvc, humanSvc, networkSvc, particleSvc, depotSvc, waitlistSvc, billingSvc, livekitClient, firestoreClient)
|
||||
|
||||
// Helper to wrap handlers with auth middleware
|
||||
withAuth := func(hf http.HandlerFunc) http.Handler {
|
||||
return middleware.Auth(authSvc)(http.HandlerFunc(hf))
|
||||
}
|
||||
@@ -108,6 +116,7 @@ func main() {
|
||||
mux.HandleFunc("POST /auth/sign-in", h.SignIn)
|
||||
mux.HandleFunc("POST /waitlist", h.AddToWaitlist)
|
||||
mux.HandleFunc("POST /livekit/webhook", h.HandleLivekitWebhook)
|
||||
mux.HandleFunc("POST /webhooks/stripe", h.HandleStripeWebhook)
|
||||
|
||||
// ==========================================================================
|
||||
// Protected routes (auth required)
|
||||
@@ -127,6 +136,14 @@ func main() {
|
||||
mux.Handle("POST /networks/{id}/members", withAuth(h.AddMembersToNetwork))
|
||||
// mux.Handle("DELETE /networks/{id}/members/{humanId}", withAuth(h.RemoveMemberFromNetwork))
|
||||
|
||||
// Billing (network admin only; admin check happens inside each handler)
|
||||
mux.Handle("GET /networks/{id}/billing", withAuth(h.GetNetworkBilling))
|
||||
mux.Handle("POST /networks/{id}/billing/checkout-session", withAuth(h.CreateCheckoutSession))
|
||||
mux.Handle("POST /networks/{id}/billing/portal-session", withAuth(h.CreatePortalSession))
|
||||
|
||||
// Freemium usage (any network member)
|
||||
mux.Handle("GET /networks/{id}/usage", withAuth(h.GetNetworkUsage))
|
||||
|
||||
// Network Invitations
|
||||
mux.Handle("GET /networks/{id}/invitations", withAuth(h.ListInvitationsForNetwork))
|
||||
mux.Handle("DELETE /networks/{id}/invitations", withAuth(h.RevokeInvitation))
|
||||
|
||||
Reference in New Issue
Block a user