PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / trunk
ووسلام – همگام سازی ووکامرس و باسلام vtrunk
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 1.8.7 1.8.4 1.7.6 All 50 releases
sync-basalam / includes / Config / Endpoints.php

Endpoints.php in ووسلام – همگام سازی ووکامرس و باسلام trunk, at includes/Config/Endpoints.php

175 lines 6.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SyncBasalam\Config;
4
5 defined('ABSPATH') || exit;
6
7 final class Endpoints
8 {
9 // Base hosts
10 const OPENAPI_BASE = 'https://openapi.basalam.com';
11 const ORDER_BASE = 'https://order-processing.basalam.com';
12 const CORE_BASE = 'https://core.basalam.com';
13 const UPLOAD_BASE = 'https://uploadio.basalam.com';
14 const CATEGORY_BASE = 'https://categorydetection.basalam.com';
15 const APPS_BASE = 'https://apps-api.basalam.com';
16 const HAMSALAM_BASE = 'https://api.hamsalam.ir/api/v1';
17 const BASALAM_ACCOUNTS = 'https://basalam.com/accounts/sso';
18
19 // Products
20
21 /** GET all categories */
22 const CATEGORIES = self::OPENAPI_BASE . '/v1/categories';
23
24 /** GET category attributes — sprintf($url, $categoryId) */
25 const CATEGORY_ATTRIBUTES = self::OPENAPI_BASE . '/v1/categories/%d/attributes?exclude_multi_selects=true';
26
27 /** POST create product for a vendor — sprintf($url, $vendorId) */
28 const PRODUCT_CREATE = self::OPENAPI_BASE . '/v1/vendors/%d/products';
29
30 /** PATCH update an existing product — sprintf($url, $basalamProductId) */
31 const PRODUCT_UPDATE = self::OPENAPI_BASE . '/v1/products/%d';
32
33 /** PATCH update a single variation of a product — sprintf($url, $basalamProductId, $basalamVariationId) */
34 const PRODUCT_VARIATION_UPDATE = self::CORE_BASE . '/v4/products/%d/variations/%d';
35
36 /** POST batch-update products for a vendor */
37 const PRODUCT_BATCH_UPDATE = self::OPENAPI_BASE . '/v1/vendors/%d/products/batch-updates?continue_on_error=true';
38
39 /** GET vendor information — sprintf($url, $vendorId) */
40 const VENDOR_INFO = self::OPENAPI_BASE . '/v1/vendors/%d';
41
42 /** GET category-detection prediction — append encoded title as query param */
43 const CATEGORY_DETECT = self::CATEGORY_BASE . '/category_detection/api_v2.0/predict/';
44
45 /** POST initialize a product media upload */
46 const MEDIA_UPLOAD_REQUEST = self::UPLOAD_BASE . '/v3/media/upload-request';
47
48 /** POST complete a product media upload */
49 const MEDIA_UPLOAD_COMPLETE = self::UPLOAD_BASE . '/v3/media/complete';
50
51 /** GET product media upload status — sprintf($url, $fileId) */
52 const MEDIA_UPLOAD_STATUS = self::UPLOAD_BASE . '/v3/media/status/%s';
53
54 /** GET product data list */
55 const PRODUCTS_DATA = self::CORE_BASE . '/v4/products';
56
57 /** GET commission percentage */
58 const COMMISSION = self::CORE_BASE . '/api_v2/commission/get_percent';
59
60 /** GET full category tree with max preparation days (core v3) */
61 const CATEGORIES_PREPARATION = self::CORE_BASE . '/v3/categories';
62
63 /** GET/POST/PATCH/DELETE webhooks */
64 const WEBHOOKS = self::OPENAPI_BASE . '/v1/webhooks';
65
66 /** GET vendor parcels (orders) */
67 const VENDOR_PARCELS = self::OPENAPI_BASE . '/v1/vendor-parcels';
68
69 // Orders
70
71 /** POST confirm order (set preparation) */
72 const ORDER_CONFIRM = self::ORDER_BASE . '/v1/vendor/set-preparation-order';
73
74 /** POST cancel order */
75 const ORDER_CANCEL = self::ORDER_BASE . '/v1/vendor/set-cancel';
76
77 /** GET/POST cancel request for a specific order — sprintf($url, $orderId) */
78 const ORDER_CANCEL_REQUEST = self::ORDER_BASE . '/v1/vendor/order/%d/cancel-request';
79
80 /** POST delay / overdue agreement request */
81 const ORDER_DELAY = self::ORDER_BASE . '/v1/vendor/orders/%d/new-agreement';
82
83 /** POST set order as shipped (with tracking code) */
84 const ORDER_TRACKING = self::ORDER_BASE . '/v2/vendor/set-posted-order';
85
86 /** GET/POST auto-confirm automation config */
87 const ORDER_AUTO_CONFIRM_CONFIG = self::ORDER_BASE . '/v1/vendor/automation-config';
88
89 /** GET/PATCH specific order — sprintf($url, $vendorId, $invoiceId) */
90 const ORDER_DETAIL = self::ORDER_BASE . '/v2/vendors/%d/orders/%d';
91
92 // Discounts
93
94 /** GET/POST vendor discounts — sprintf($url, $vendorId) */
95 const VENDOR_DISCOUNTS = self::OPENAPI_BASE . '/v1/vendors/%d/discounts';
96
97 // Hamsalam
98
99 /** GET OAuth proxy data */
100 const HAMSALAM_OAUTH_DATA = self::HAMSALAM_BASE . '/basalam-proxy/wp-oauth-data';
101
102 /** POST OAuth get-token proxy */
103 const HAMSALAM_OAUTH_TOKEN = self::HAMSALAM_BASE . '/basalam-proxy/wp-get-token';
104
105 /** GET plugin version detail */
106 const HAMSALAM_VERSION_DETAIL = self::HAMSALAM_BASE . '/wp-sites/version-detail';
107
108 /** GET announcements */
109 const HAMSALAM_ANNOUNCEMENTS = self::HAMSALAM_BASE . '/announcements';
110
111 /** GET/POST all-businesses */
112 const HAMSALAM_BUSINESSES = self::HAMSALAM_BASE . '/all-businesses';
113
114 /** GET Hamsalam auth token */
115 const HAMSALAM_AUTH_TOKEN = self::HAMSALAM_BASE . '/auth/basalam/get-token';
116
117 // Tickets (Hamsalam)
118
119 /** GET/POST ticket list */
120 const TICKET_LIST = self::HAMSALAM_BASE . '/tickets';
121
122 /** GET ticket subjects */
123 const TICKET_SUBJECTS = self::HAMSALAM_BASE . '/tickets/subjects';
124
125 /** GET single ticket — sprintf($url, $ticketId) */
126 const TICKET_DETAIL = self::HAMSALAM_BASE . '/tickets/%d';
127
128 /** POST ticket reply items — sprintf($url, $ticketId) */
129 const TICKET_ITEMS = self::HAMSALAM_BASE . '/tickets/%d/ticket-items';
130
131 /** PUT encrypted business site access — sprintf($url, $businessId) */
132 const BUSINESS_SITE_ACCESS = self::HAMSALAM_BASE . '/businesses/%d/site-access';
133
134 /** POST upload ticket media */
135 const TICKET_MEDIA_UPLOAD = self::HAMSALAM_BASE . '/media';
136
137 // App Store
138
139 /** POST app review */
140 const APP_REVIEW = self::APPS_BASE . '/v1/apps/13/reviews';
141
142 /**
143 * Replace only the Hamsalam base URL when a local/test override exists.
144 * Production keeps using the compile-time constants above.
145 */
146 public static function resolve(string $url): string
147 {
148 if (!defined('SYNC_BASALAM_HAMSALAM_BASE_URL')) {
149 return $url;
150 }
151
152 $override = rtrim(
153 (string) constant('SYNC_BASALAM_HAMSALAM_BASE_URL'),
154 '/'
155 );
156 if ($override === '' || strpos($url, self::HAMSALAM_BASE) !== 0) {
157 return $url;
158 }
159
160 return $override . substr($url, strlen(self::HAMSALAM_BASE));
161 }
162
163 // Helpers
164
165 /** Build the SSO login URL */
166 public static function oauthLoginUrl(string $clientId, string $scopes, string $redirectUri, string $siteUrl): string
167 {
168 return self::BASALAM_ACCOUNTS
169 . '?client_id=' . $clientId
170 . '&scope=' . $scopes
171 . '&redirect_uri=' . $redirectUri
172 . '&state=' . $siteUrl;
173 }
174 }
175