PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.10.14
ووسلام – همگام سازی ووکامرس و باسلام v1.10.14
1.10.19 1.10.20 1.10.18 1.10.17 1.10.15 1.10.14 1.10.13 1.10.12 1.10.10 1.10.9 1.10.8 1.10.7 1.10.6 1.10.5 1.10.4 1.10.3 1.10.2 1.10.1 1.10.0 1.9.2 1.9.1 1.9.0 1.8.8 1.8.5 1.8.6 All 53 releases
sync-basalam / includes / Services / VendorInfoService.php

VendorInfoService.php in ووسلام – همگام سازی ووکامرس و باسلام 1.10.14, at includes/Services/VendorInfoService.php

55 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SyncBasalam\Services;
4
5 use SyncBasalam\Admin\Settings\SettingsConfig;
6 use SyncBasalam\Admin\Settings;
7 use SyncBasalam\Config\Endpoints;
8 use SyncBasalam\Logger\Logger;
9
10 defined('ABSPATH') || exit;
11
12 class VendorInfoService
13 {
14 private $apiService;
15 private $basalamToken;
16 private $basalamVendorId;
17
18 public function __construct()
19 {
20 $this->apiService = syncBasalamContainer()->get(ApiServiceManager::class);
21 $this->basalamToken = Settings::getSettings(SettingsConfig::TOKEN);
22 $this->basalamVendorId = Settings::getSettings(SettingsConfig::VENDOR_ID);
23 }
24
25 public function FetchVendorInfo()
26 {
27 // Credentials can change during an OAuth callback in the same request.
28 $this->basalamToken = Settings::getSettings(SettingsConfig::TOKEN);
29 $this->basalamVendorId = Settings::getSettings(SettingsConfig::VENDOR_ID);
30
31 if (!$this->basalamToken || !$this->basalamVendorId) {
32 return null;
33 }
34
35 try {
36 $apiUrl = sprintf(Endpoints::VENDOR_INFO, $this->basalamVendorId);
37 $FetchVendorInfo = $this->apiService->get($apiUrl, ['Authorization' => 'Bearer ' . $this->basalamToken]);
38
39 if (!is_array($FetchVendorInfo) || !isset($FetchVendorInfo['body'])) {
40 return null;
41 }
42
43 $vendorInfo = json_decode($FetchVendorInfo['body'], true);
44 if (!is_array($vendorInfo)) {
45 return null;
46 }
47
48 return $vendorInfo;
49 } catch (\Exception $e) {
50 Logger::error('خطا در دریافت اطلاعات فروشنده: ' . $e->getMessage());
51 return null;
52 }
53 }
54 }
55