добавлен биллинг и тарифы

добавлена интеграция с юкасса
This commit is contained in:
2025-12-24 09:06:19 +03:00
parent b4ce819931
commit 5f35d7a75f
15 changed files with 745 additions and 212 deletions

View File

@@ -13,12 +13,14 @@ import (
"rmser/config"
"rmser/internal/infrastructure/db"
"rmser/internal/infrastructure/ocr_client"
"rmser/internal/infrastructure/yookassa"
"rmser/internal/transport/http/middleware"
tgBot "rmser/internal/transport/telegram"
// Repositories
accountPkg "rmser/internal/infrastructure/repository/account"
billingPkg "rmser/internal/infrastructure/repository/billing"
catalogPkg "rmser/internal/infrastructure/repository/catalog"
draftsPkg "rmser/internal/infrastructure/repository/drafts"
invoicesPkg "rmser/internal/infrastructure/repository/invoices"
@@ -31,6 +33,7 @@ import (
"rmser/internal/infrastructure/rms"
// Services
billingServicePkg "rmser/internal/services/billing"
draftsServicePkg "rmser/internal/services/drafts"
ocrServicePkg "rmser/internal/services/ocr"
recServicePkg "rmser/internal/services/recommend"
@@ -68,6 +71,7 @@ func main() {
// 4. Repositories
accountRepo := accountPkg.NewRepository(database)
billingRepo := billingPkg.NewRepository(database)
catalogRepo := catalogPkg.NewRepository(database)
recipesRepo := recipesPkg.NewRepository(database)
invoicesRepo := invoicesPkg.NewRepository(database)
@@ -82,25 +86,29 @@ func main() {
// 6. Services
pyClient := ocr_client.NewClient(cfg.OCR.ServiceURL)
ykClient := yookassa.NewClient(cfg.YooKassa.ShopID, cfg.YooKassa.SecretKey)
billingService := billingServicePkg.NewService(billingRepo, accountRepo, ykClient)
syncService := sync.NewService(rmsFactory, accountRepo, catalogRepo, recipesRepo, invoicesRepo, opsRepo, supplierRepo)
recService := recServicePkg.NewService(recRepo)
ocrService := ocrServicePkg.NewService(ocrRepo, catalogRepo, draftsRepo, accountRepo, pyClient, cfg.App.StoragePath)
draftsService := draftsServicePkg.NewService(draftsRepo, ocrRepo, catalogRepo, accountRepo, supplierRepo, rmsFactory)
draftsService := draftsServicePkg.NewService(draftsRepo, ocrRepo, catalogRepo, accountRepo, supplierRepo, rmsFactory, billingService)
// 7. Handlers
draftsHandler := handlers.NewDraftsHandler(draftsService)
billingHandler := handlers.NewBillingHandler(billingService)
ocrHandler := handlers.NewOCRHandler(ocrService)
recommendHandler := handlers.NewRecommendationsHandler(recService)
settingsHandler := handlers.NewSettingsHandler(accountRepo, catalogRepo)
// 8. Telegram Bot (Передаем syncService)
if cfg.Telegram.Token != "" {
bot, err := tgBot.NewBot(cfg.Telegram, ocrService, syncService, accountRepo, rmsFactory, cryptoManager)
bot, err := tgBot.NewBot(cfg.Telegram, ocrService, syncService, billingService, accountRepo, rmsFactory, cryptoManager)
if err != nil {
logger.Log.Fatal("Ошибка создания Telegram бота", zap.Error(err))
}
settingsHandler.SetNotifier(bot) // Внедряем зависимость
billingService.SetNotifier(bot)
settingsHandler.SetNotifier(bot)
go bot.Start()
defer bot.Stop()
}
@@ -111,6 +119,8 @@ func main() {
}
r := gin.Default()
r.POST("/api/webhooks/yookassa", billingHandler.YooKassaWebhook)
corsConfig := cors.DefaultConfig()
corsConfig.AllowAllOrigins = true
corsConfig.AllowMethods = []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"}