api_url = rtrim(get_option('ifnex_api_url', 'http://localhost:8000/api/v1'), '/'); $this->api_key = get_option('ifnex_api_key', ''); } public function track_shipment($awb_no) { if (empty($this->api_key)) { return new WP_Error('no_api_key', 'API Key تنظیم نشده است.'); } $url = $this->api_url . '/track/' . urlencode($awb_no); $args = array( 'headers' => array( 'Authorization' => 'Bearer ' . $this->api_key, 'Accept' => 'application/json', ), 'timeout' => 30, ); $response = wp_remote_get($url, $args); if (is_wp_error($response)) { return $response; } $body = wp_remote_retrieve_body($response); $data = json_decode($body, true); if ($response['response']['code'] === 404) { return new WP_Error('not_found', 'مرسوله‌ای با این کد پیدا نشد.'); } if ($response['response']['code'] !== 200) { return new WP_Error('api_error', 'خطا در ارتباط با API: ' . ($data['message'] ?? 'Unknown error')); } return $data; } }