diff --git a/internal/server/server.go b/internal/server/server.go index e7e0c31..8fc18c2 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -6,14 +6,17 @@ import ( "attune-heart-therapy/internal/config" "attune-heart-therapy/internal/database" + "attune-heart-therapy/internal/handlers" + "attune-heart-therapy/internal/services" "github.com/gin-gonic/gin" ) type Server struct { - config *config.Config - db *database.DB - router *gin.Engine + config *config.Config + db *database.DB + router *gin.Engine + paymentHandler *handlers.PaymentHandler } func New(cfg *config.Config) *Server { @@ -51,6 +54,9 @@ func (s *Server) Initialize() error { return fmt.Errorf("failed to seed database: %w", err) } + // Initialize services and handlers + s.initializeServices() + log.Println("Server initialization completed successfully") return nil } @@ -117,18 +123,12 @@ func (s *Server) setupRoutes() { }) } - // Payment routes (will be implemented in later tasks) + // Payment routes payments := v1.Group("/payments") { - payments.POST("/intent", func(c *gin.Context) { - c.JSON(501, gin.H{"message": "Not implemented yet"}) - }) - payments.POST("/confirm", func(c *gin.Context) { - c.JSON(501, gin.H{"message": "Not implemented yet"}) - }) - payments.POST("/webhook", func(c *gin.Context) { - c.JSON(501, gin.H{"message": "Not implemented yet"}) - }) + payments.POST("/intent", s.paymentHandler.CreatePaymentIntent) + payments.POST("/confirm", s.paymentHandler.ConfirmPayment) + payments.POST("/webhook", s.paymentHandler.HandleWebhook) } // Admin routes (will be implemented in later tasks) @@ -141,6 +141,15 @@ func (s *Server) setupRoutes() { } } +// initializeServices sets up all services and handlers +func (s *Server) initializeServices() { + // Initialize payment service + paymentService := services.NewPaymentService(s.config) + + // Initialize payment handler + s.paymentHandler = handlers.NewPaymentHandler(paymentService) +} + // healthCheck handles the health check endpoint func (s *Server) healthCheck(c *gin.Context) { response := gin.H{