mirror of
https://github.com/serty2005/rmser.git
synced 2026-02-05 03:12:34 -06:00
добавлен биллинг и тарифы
добавлена интеграция с юкасса
This commit is contained in:
40
internal/transport/http/handlers/billing.go
Normal file
40
internal/transport/http/handlers/billing.go
Normal file
@@ -0,0 +1,40 @@
|
||||
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"})
|
||||
}
|
||||
Reference in New Issue
Block a user