- Add subscription module (models, service, tests) - Plans: Free, Creator ($9.99/mo), Premium ($19.99/mo) - Features: subscribe, cancel, reactivate, change billing cycle - 14-day trial for Premium plan - Upgrade immediate, downgrade at period end - Invoice tracking and history - Handler tests for auth and validation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
35 lines
1.1 KiB
Go
35 lines
1.1 KiB
Go
package api
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"veza-backend-api/internal/core/subscription"
|
|
"veza-backend-api/internal/handlers"
|
|
)
|
|
|
|
// setupSubscriptionRoutes configures routes for subscription plans management (v0.12.1)
|
|
func (r *APIRouter) setupSubscriptionRoutes(router *gin.RouterGroup) {
|
|
svc := subscription.NewService(r.db.GormDB, r.logger)
|
|
handler := handlers.NewSubscriptionHandler(svc, r.logger)
|
|
|
|
group := router.Group("/subscriptions")
|
|
|
|
// Public: list available plans
|
|
group.GET("/plans", handler.ListPlans)
|
|
group.GET("/plans/:id", handler.GetPlan)
|
|
|
|
// Protected: user subscription management
|
|
if r.config.AuthMiddleware != nil {
|
|
protected := group.Group("")
|
|
protected.Use(r.config.AuthMiddleware.RequireAuth())
|
|
r.applyCSRFProtection(protected)
|
|
|
|
protected.GET("/me", handler.GetMySubscription)
|
|
protected.POST("/subscribe", handler.Subscribe)
|
|
protected.POST("/cancel", handler.CancelSubscription)
|
|
protected.POST("/reactivate", handler.ReactivateSubscription)
|
|
protected.PUT("/billing-cycle", handler.ChangeBillingCycle)
|
|
protected.GET("/invoices", handler.GetInvoices)
|
|
protected.GET("/history", handler.GetSubscriptionHistory)
|
|
}
|
|
}
|