PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.9.2
ووسلام – همگام سازی ووکامرس و باسلام v1.9.2
1.10.21 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 All 54 releases
sync-basalam / includes / Services / Hamsalam / FetchHamsalamBusinessId.php

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

65 lines 1.9 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\Hamsalam;
4
5 use SyncBasalam\Admin\Settings\SettingsConfig;
6 use SyncBasalam\Admin\Settings\SettingsManager;
7 use SyncBasalam\Config\Endpoints;
8 use SyncBasalam\Services\ApiServiceManager;
9
10 defined('ABSPATH') || exit;
11
12 class FetchHamsalamBusinessId
13 {
14 private $url;
15 private $settings;
16 private $hamsalmToken;
17
18 public function __construct()
19 {
20 $this->settings = syncBasalamSettings()->getSettings();
21 $this->url = Endpoints::HAMSALAM_BUSINESSES;
22 $this->hamsalmToken = SettingsManager::getSettings(SettingsConfig::HAMSALAM_TOKEN);
23 }
24
25 public function fetch()
26 {
27 try {
28 $apiService = syncBasalamContainer()->get(ApiServiceManager::class);
29
30 $header = ['Authorization' => 'Bearer ' . $this->hamsalmToken];
31
32 $response = $apiService->get($this->url, $header);
33
34 if (!$response || !isset($response['body'])) return ('خطا در دریافت اطلاعات از ه�
35 سلا�
36 ');
37
38 $businesses = json_decode($response['body'], true);
39
40 $domain = get_site_url();
41 $vendorId = $this->settings[SettingsConfig::VENDOR_ID];
42 $businessId = null;
43
44 if (!isset($businesses['data']) || !is_array($businesses['data'])) return null;
45
46 foreach ($businesses['data'] as $business) {
47 if ($business['platform'] == 'wordpress' && $domain == $business['domain'] && $vendorId == $business['vendor_id']) {
48 $businessId = $business['id'];
49 break;
50 }
51 }
52 if ($businessId) {
53 $data = [SettingsConfig::HAMSALAM_BUSINESS_ID => $businessId];
54
55 SettingsManager::updateSettings($data);
56 return $businessId;
57 }
58
59 return null;
60 } catch (\Exception) {
61 return null;
62 }
63 }
64 }
65