db, $this->integrationSecret); $oauthClient = new AllegroOAuthClient(); $tokenManager = new AllegroTokenManager($integrationRepository, $oauthClient); $apiClient = new AllegroApiClient(); $statusMappingRepository = new AllegroStatusMappingRepository($this->db); $ordersRepository = new OrdersRepository($this->db); $allegroSyncStateRepository = new AllegroOrderSyncStateRepository($this->db); $orderImportService = new AllegroOrderImportService( $integrationRepository, $tokenManager, $apiClient, new OrderImportRepository($this->db), $statusMappingRepository, $ordersRepository ); $ordersSyncService = new AllegroOrdersSyncService( $integrationRepository, $allegroSyncStateRepository, $tokenManager, $apiClient, $orderImportService ); $shopproIntegrationsRepo = new ShopproIntegrationsRepository($this->db, $this->integrationSecret); $shopproApiClient = new ShopproApiClient(); $shopproSyncStateRepo = new ShopproOrderSyncStateRepository($this->db); $shopproStatusMappingRepo = new ShopproStatusMappingRepository($this->db); $shopproSyncService = new ShopproOrdersSyncService( $shopproIntegrationsRepo, $shopproSyncStateRepo, $shopproApiClient, new OrderImportRepository($this->db), $shopproStatusMappingRepo, $ordersRepository, new ShopproOrderMapper(), new ShopproProductImageResolver($shopproApiClient) ); $shopproStatusSyncService = new ShopproStatusSyncService( $shopproIntegrationsRepo, $shopproSyncService, $shopproApiClient, $shopproSyncStateRepo, $shopproStatusMappingRepo, $this->db ); $shopproPaymentSyncService = new ShopproPaymentStatusSyncService( $shopproIntegrationsRepo, new ShopproApiClient(), $ordersRepository, $this->db ); $automationService = $this->buildAutomationService($ordersRepository); return new CronRunner( $cronRepository, $logger, [ 'allegro_token_refresh' => new AllegroTokenRefreshHandler( $integrationRepository, $oauthClient ), 'allegro_orders_import' => new AllegroOrdersImportHandler( $ordersSyncService ), 'allegro_status_sync' => new AllegroStatusSyncHandler( new AllegroStatusSyncService( $cronRepository, $orderImportService, $apiClient, $tokenManager, $statusMappingRepository, $allegroSyncStateRepository, $integrationRepository, $this->db ) ), 'shoppro_orders_import' => new ShopproOrdersImportHandler( $shopproSyncService ), 'shoppro_order_status_sync' => new ShopproStatusSyncHandler( $shopproStatusSyncService ), 'shoppro_payment_status_sync' => new ShopproPaymentStatusSyncHandler( $shopproPaymentSyncService ), 'shipment_tracking_sync' => new ShipmentTrackingHandler( new ShipmentTrackingRegistry([ new InpostTrackingService( new InpostIntegrationRepository($this->db, $this->integrationSecret) ), new ApaczkaTrackingService( new ApaczkaApiClient(), new ApaczkaIntegrationRepository($this->db, $this->integrationSecret) ), new AllegroTrackingService( new InpostIntegrationRepository($this->db, $this->integrationSecret) ), ]), new ShipmentPackageRepository($this->db), $automationService ), 'automation_history_cleanup' => new AutomationHistoryCleanupHandler( new AutomationExecutionLogRepository($this->db) ), ] ); } private function buildAutomationService(OrdersRepository $ordersRepository): AutomationService { $automationRepository = new AutomationRepository($this->db); $executionLogRepository = new AutomationExecutionLogRepository($this->db); $companySettingsRepository = new CompanySettingsRepository($this->db); $emailTemplateRepository = new EmailTemplateRepository($this->db); $emailMailboxRepository = new EmailMailboxRepository( $this->db, new IntegrationSecretCipher($this->integrationSecret) ); $template = new Template( $this->basePath . '/resources/views', new Translator($this->basePath . '/resources/lang', 'pl') ); $emailService = new EmailSendingService( $this->db, $ordersRepository, $emailTemplateRepository, $emailMailboxRepository, new VariableResolver(new ShipmentPackageRepository($this->db)), new AttachmentGenerator( new ReceiptRepository($this->db), new ReceiptConfigRepository($this->db), $template ) ); return new AutomationService( $automationRepository, $executionLogRepository, $emailService, $ordersRepository, $companySettingsRepository, new ReceiptRepository($this->db), new ReceiptConfigRepository($this->db), new ShipmentPackageRepository($this->db) ); } }