package handlers import ( "net/http" "rmser/internal/infrastructure/yookassa" "rmser/internal/services/billing" "rmser/pkg/logger" "github.com/gin-gonic/gin" "go.uber.org/zap" ) type BillingHandler struct { service *billing.Service } func NewBillingHandler(s *billing.Service) *BillingHandler { return &BillingHandler{service: s} } func (h *BillingHandler) YooKassaWebhook(c *gin.Context) { var event yookassa.WebhookEvent if err := c.ShouldBindJSON(&event); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": "invalid json"}) return } logger.Log.Info("YooKassa Webhook received", zap.String("event", event.Event), zap.String("payment_id", event.Object.ID), ) if err := h.service.ProcessWebhook(c.Request.Context(), event); err != nil { logger.Log.Error("Failed to process webhook", zap.Error(err)) c.JSON(http.StatusInternalServerError, gin.H{"status": "error"}) return } c.JSON(http.StatusOK, gin.H{"status": "ok"}) }