Files
orderPRO/bin/cron.php
Jacek Pyziak af052e1ff5 feat: add Shoppro payment status synchronization service
- Implemented ShopproPaymentStatusSyncService to handle payment status synchronization between Shoppro and Orderpro.
- Added methods for resolving watched status codes, finding candidate orders, and syncing individual order payments.
- Introduced ShopproStatusMappingRepository for managing status mappings between Shoppro and Orderpro.
- Created ShopproStatusSyncService to facilitate synchronization of order statuses from Shoppro to Orderpro.
2026-03-08 20:41:10 +01:00

123 lines
4.1 KiB
PHP

<?php
declare(strict_types=1);
use App\Core\Application;
use App\Modules\Cron\AllegroOrdersImportHandler;
use App\Modules\Cron\AllegroStatusSyncHandler;
use App\Modules\Cron\AllegroTokenRefreshHandler;
use App\Modules\Cron\CronRepository;
use App\Modules\Cron\CronRunner;
use App\Modules\Cron\ShopproOrdersImportHandler;
use App\Modules\Cron\ShopproPaymentStatusSyncHandler;
use App\Modules\Cron\ShopproStatusSyncHandler;
use App\Modules\Orders\OrderImportRepository;
use App\Modules\Orders\OrdersRepository;
use App\Modules\Settings\AllegroApiClient;
use App\Modules\Settings\AllegroIntegrationRepository;
use App\Modules\Settings\AllegroOrderImportService;
use App\Modules\Settings\AllegroOrdersSyncService;
use App\Modules\Settings\AllegroOrderSyncStateRepository;
use App\Modules\Settings\AllegroOAuthClient;
use App\Modules\Settings\AllegroStatusSyncService;
use App\Modules\Settings\AllegroStatusMappingRepository;
use App\Modules\Settings\ShopproApiClient;
use App\Modules\Settings\ShopproIntegrationsRepository;
use App\Modules\Settings\ShopproOrdersSyncService;
use App\Modules\Settings\ShopproPaymentStatusSyncService;
use App\Modules\Settings\ShopproStatusSyncService;
use App\Modules\Settings\ShopproStatusMappingRepository;
/** @var Application $app */
$app = require dirname(__DIR__) . '/bootstrap/app.php';
$limit = 20;
foreach (array_slice($argv, 1) as $arg) {
if (preg_match('/^--limit=(\d+)$/', (string) $arg, $matches) === 1) {
$limit = max(1, min(100, (int) ($matches[1] ?? 20)));
}
}
$cronRepository = new CronRepository($app->db());
$integrationRepository = new AllegroIntegrationRepository(
$app->db(),
(string) $app->config('app.integrations.secret', '')
);
$oauthClient = new AllegroOAuthClient();
$apiClient = new AllegroApiClient();
$statusMappingRepository = new AllegroStatusMappingRepository($app->db());
$orderImportService = new AllegroOrderImportService(
$integrationRepository,
$oauthClient,
$apiClient,
new OrderImportRepository($app->db()),
$statusMappingRepository,
new OrdersRepository($app->db())
);
$ordersSyncService = new AllegroOrdersSyncService(
$integrationRepository,
new AllegroOrderSyncStateRepository($app->db()),
$oauthClient,
$apiClient,
$orderImportService
);
$shopproSyncService = new ShopproOrdersSyncService(
new ShopproIntegrationsRepository(
$app->db(),
(string) $app->config('app.integrations.secret', '')
),
new AllegroOrderSyncStateRepository($app->db()),
new ShopproApiClient(),
new OrderImportRepository($app->db()),
new ShopproStatusMappingRepository($app->db()),
new OrdersRepository($app->db())
);
$shopproStatusSyncService = new ShopproStatusSyncService(
new ShopproIntegrationsRepository(
$app->db(),
(string) $app->config('app.integrations.secret', '')
),
$shopproSyncService
);
$shopproPaymentSyncService = new ShopproPaymentStatusSyncService(
new ShopproIntegrationsRepository(
$app->db(),
(string) $app->config('app.integrations.secret', '')
),
new ShopproApiClient(),
new OrdersRepository($app->db()),
$app->db()
);
$runner = new CronRunner(
$cronRepository,
$app->logger(),
[
'allegro_token_refresh' => new AllegroTokenRefreshHandler(
$integrationRepository,
$oauthClient
),
'allegro_orders_import' => new AllegroOrdersImportHandler(
$ordersSyncService
),
'allegro_status_sync' => new AllegroStatusSyncHandler(
new AllegroStatusSyncService(
$cronRepository,
$orderImportService,
$app->db()
)
),
'shoppro_orders_import' => new ShopproOrdersImportHandler(
$shopproSyncService
),
'shoppro_order_status_sync' => new ShopproStatusSyncHandler(
$shopproStatusSyncService
),
'shoppro_payment_status_sync' => new ShopproPaymentStatusSyncHandler(
$shopproPaymentSyncService
),
]
);
$result = $runner->run($limit);
fwrite(STDOUT, json_encode($result, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . PHP_EOL);