diff --git a/admin/partials/ssbhesabix-admin-setting.php b/admin/partials/ssbhesabix-admin-setting.php index 55b8a74..d2562ae 100644 --- a/admin/partials/ssbhesabix-admin-setting.php +++ b/admin/partials/ssbhesabix-admin-setting.php @@ -208,8 +208,8 @@ class Ssbhesabix_Setting {
settingSetChangeHook( $url, $hookPassword ); - + if ( is_object( $response ) ) { if ( $response->Success ) { update_option( 'ssbhesabix_live_mode', 1 ); - update_option( 'ssbhesabix_business_expired', 0 ); - + update_option( 'ssbhesabix_account_bid', $response->bid ); + update_option( 'ssbhesabix_account_year', $response->year ); //set the last log ID if is not set $lastChanges = get_option( 'ssbhesabix_last_log_check_id' ); if ( ! $lastChanges ) { diff --git a/includes/class-ssbhesabix-activator.php b/includes/class-ssbhesabix-activator.php index 886dc7a..71e98b1 100644 --- a/includes/class-ssbhesabix-activator.php +++ b/includes/class-ssbhesabix-activator.php @@ -29,6 +29,8 @@ class Ssbhesabix_Activator { add_option('ssbhesabix_webhook_password', bin2hex(openssl_random_pseudo_bytes(16))); add_option('ssbhesabix_last_log_check_id', 0); add_option('ssbhesabix_live_mode', 0); + add_option('ssbhesabix_live_mode', 0); + add_option('ssbhesabix_live_mode', 0); add_option('ssbhesabix_debug_mode', 0); add_option('ssbhesabix_contact_address_status', 1); add_option('ssbhesabix_contact_node_family', 'مشتریان فروشگاه آن‌لاین'); @@ -40,7 +42,9 @@ class Ssbhesabix_Activator { add_option('ssbhesabix_do_not_submit_product_automatically', "no"); add_option('ssbhesabix_do_not_update_product_price_in_hesabix', "no"); add_option('ssbhesabix_contact_add_additional_checkout_fields_hesabix', 1); - + add_option('ssbhesabix_account_bid', 1); + add_option('ssbhesabix_account_year', 1); + self::ssbhesabix_create_database_table(); } //=============================================================================================================== diff --git a/includes/class-ssbhesabix-api.php b/includes/class-ssbhesabix-api.php index 209e5b6..4e0efcc 100644 --- a/includes/class-ssbhesabix-api.php +++ b/includes/class-ssbhesabix-api.php @@ -24,13 +24,10 @@ class Ssbhesabix_Api $apiAddress = get_option('ssbhesabix_api_address', 0); - if($apiAddress == 1) $endpoint = 'http://next.hesabix.ir/' . $method; + if($apiAddress == 1) $endpoint = 'https://next.hesabix.ir/' . $method; $body = array_merge(array( - 'apiKey' => get_option('ssbhesabix_account_api'), - 'userId' => get_option('ssbhesabix_account_username'), - 'password' => get_option('ssbhesabix_account_password'), - 'loginToken' => get_option('ssbhesabix_account_login_token') ? get_option('ssbhesabix_account_login_token') : '', + 'API-KEY' => get_option('ssbhesabix_account_api'), ), $data); //Debug mode @@ -42,6 +39,9 @@ class Ssbhesabix_Api 'body' => wp_json_encode($body), 'headers' => array( 'Content-Type' => 'application/json', + 'API-KEY' => get_option('ssbhesabix_account_api'), + 'activeBid' => get_option('ssbhesabix_account_bid'), + 'activeYear' => get_option('ssbhesabix_account_year'), ), 'timeout' => 60, 'redirection' => 5, @@ -52,10 +52,8 @@ class Ssbhesabix_Api ); //HesabixLogService::writeLogObj($options); - $wp_remote_post = wp_remote_post($endpoint, $options); $result = json_decode(wp_remote_retrieve_body($wp_remote_post)); - //Debug mode if (get_option('ssbhesabix_debug_mode')) { HesabixLogService::log(array("Debug Mode - Result: " . print_r($result, true))); @@ -67,40 +65,7 @@ class Ssbhesabix_Api if ($result == null) { return 'No response from Hesabix'; } else { - if (!isset($result->Success)) { - switch ($result->errorCode) { - case '100': - return 'InternalServerError'; - case '101': - return 'TooManyRequests'; - case '103': - return 'MissingData'; - case '104': - return 'MissingParameter' . '. ErrorMessage: ' . $result->ErrorMessage; - case '105': - return 'ApiDisabled'; - case '106': - return 'UserIsNotOwner'; - case '107': - return 'BusinessNotFound'; - case '108': - return 'BusinessExpired'; - case '110': - return 'IdMustBeZero'; - case '111': - return 'IdMustNotBeZero'; - case '112': - return 'ObjectNotFound' . '. ErrorMessage: ' . $result->ErrorMessage; - case '113': - return 'MissingApiKey'; - case '114': - return 'ParameterIsOutOfRange' . '. ErrorMessage: ' . $result->ErrorMessage; - case '190': - return 'ApplicationError' . '. ErrorMessage: ' . $result->ErrorMessage; - } - } else { - return $result; - } + return $result; } return false; } @@ -398,8 +363,7 @@ class Ssbhesabix_Api //Settings functions public function settingSetChangeHook($url, $hookPassword) { - $method = 'api/settings/chack-api'; - echo 11; + $method = 'hooks/setting/SetChangeHook'; $data = array( 'url' => $url, 'hookPassword' => $hookPassword, diff --git a/includes/class-ssbhesabix.php b/includes/class-ssbhesabix.php index 7b6c02e..f376f61 100644 --- a/includes/class-ssbhesabix.php +++ b/includes/class-ssbhesabix.php @@ -61,8 +61,8 @@ class Ssbhesabix */ public function __construct() { - if (defined('SSBHESABFA_VERSION')) { - $this->version = SSBHESABFA_VERSION; + if (defined('SSBHESABIX_VERSION')) { + $this->version = SSBHESABIX_VERSION; } else { $this->version = '2.0.93'; }