| 1 |
<?php |
| 2 |
|
| 3 |
namespace SyncBasalam\Admin\Settings; |
| 4 |
|
| 5 |
use SyncBasalam\Queue\Tasks\Debug; |
| 6 |
use SyncBasalam\Actions\Controller\ProductActions\CancelDebug; |
| 7 |
use SyncBasalam\Services\WebhookService; |
| 8 |
use SyncBasalam\Services\VendorInfoService; |
| 9 |
|
| 10 |
defined('ABSPATH') || exit; |
| 11 |
|
| 12 |
class SettingsPageHandler |
| 13 |
{ |
| 14 |
public static function saveSettings() |
| 15 |
{ |
| 16 |
$data = isset($_POST['sync_basalam_settings']) ? array_map('sanitize_text_field', wp_unslash($_POST['sync_basalam_settings'])) : []; |
| 17 |
|
| 18 |
if ($data) { |
| 19 |
SettingsManager::updateSettings($data); |
| 20 |
|
| 21 |
if (!empty($data[SettingsConfig::DEVELOPER_MODE]) && $data[SettingsConfig::DEVELOPER_MODE] === 'true') { |
| 22 |
$debugTask = new Debug(); |
| 23 |
$debugTask->schedule(); |
| 24 |
} else { |
| 25 |
(new CancelDebug())(); |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
if (isset($_POST['get_token']) && $_POST['get_token'] == 1) { |
| 30 |
self::redirectToOAuth(); |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
private static function redirectToOAuth() |
| 35 |
{ |
| 36 |
$OAuthManger = new OAuthManager(); |
| 37 |
$oauthUrls = $OAuthManger->getOAuthUrls(); |
| 38 |
|
| 39 |
wp_redirect($oauthUrls['url_req_token']); |
| 40 |
exit(); |
| 41 |
} |
| 42 |
|
| 43 |
public static function handleOauthCallback() |
| 44 |
{ |
| 45 |
$oauthSaved = OAuthManager::saveOauthData(); |
| 46 |
|
| 47 |
if ($oauthSaved) { |
| 48 |
$webhookService = new WebhookService(); |
| 49 |
$webhookService->setupWebhook(); |
| 50 |
$vendorInfoService = new VendorInfoService(); |
| 51 |
$vendorInfoService->FetchVendorInfo(); |
| 52 |
} |
| 53 |
|
| 54 |
$onboardingCompleted = get_option('sync_basalam_onboarding_completed'); |
| 55 |
|
| 56 |
if (!$onboardingCompleted) { |
| 57 |
wp_redirect(admin_url('admin.php?page=basalam-onboarding&step=3')); |
| 58 |
} else { |
| 59 |
wp_redirect(admin_url('admin.php?page=sync_basalam')); |
| 60 |
} |
| 61 |
exit(); |
| 62 |
} |
| 63 |
} |
| 64 |
|