# sync-basalam/1.10.14/includes/Services/Orders/FetchOrdersService.php

ووسلام – همگام سازی ووکامرس و باسلام, version 1.10.14. 75 lines.

- Page: https://pluginprobe.com/plugins/sync-basalam/1.10.14/code/includes/Services/Orders/FetchOrdersService.php
- Raw: https://pluginprobe.com/plugins/sync-basalam/1.10.14/raw/includes/Services/Orders/FetchOrdersService.php
- Modified: 2026-09-08T09:08:34+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/sync-basalam/1.10.14/code/includes/Services/Orders/FetchOrdersService.php#L10-L20`.

```php
<?php

namespace SyncBasalam\Services\Orders;

use SyncBasalam\Config\Endpoints;
use SyncBasalam\Services\ApiServiceManager;
use SyncBasalam\Logger\Logger;
use SyncBasalam\Jobs\Exceptions\RetryableException;
use SyncBasalam\Jobs\Exceptions\NonRetryableException;

defined('ABSPATH') || exit;

class FetchOrdersService
{
    private string $url;
    private $apiService;

    public function __construct()
    {
        $this->url = Endpoints::VENDOR_PARCELS;
        $this->apiService = syncBasalamContainer()->get(ApiServiceManager::class);
    }

    public function fetchPage(int $day = 7, $cursor = null): array
    {
        $timestamp = current_time('timestamp', true) - ($day * 24 * 60 * 60);
        $isoDate = gmdate('c', $timestamp);

        $url = $this->url . '?per_page=10&created_at%5Bgte%5D=' . urlencode($isoDate);

        if ($cursor) $url .= '&cursor=' . urlencode($cursor);

        try {
            $response = $this->apiService->get($url);

            if (!isset($response['body'])) {
                return [
                    'success' => false,
                    'orders' => [],
                    'next_cursor' => null,
                    'message' => 'پاسخی از API دریافت نشد.'
                ];
            }

            $bodyData = json_decode($response['body'], true);

            if (!isset($bodyData['data'])) {
                return [
                    'success' => false,
                    'orders' => [],
                    'next_cursor' => null,
                    'message' => 'داده‌ای در پاسخ API یافت نشد.'
                ];
            }

            $nextCursor = $bodyData['next_cursor'] ?? null;

            Logger::debug("دریافت صفحه سفارشات: " . count($bodyData['data']) . " سفارش، cursor بعدی: " . ($nextCursor ?: 'ندارد'));

            return [
                'success' => true,
                'orders' => $bodyData['data'],
                'next_cursor' => $nextCursor,
                'message' => null
            ];
        } catch (RetryableException $e) {
            throw $e;
        } catch (NonRetryableException $e) {
            throw $e;
        } catch (\Throwable $th) {
            throw $th;
        }
    }
}

```
