solve sethook part

This commit is contained in:
Hesabix 2024-01-12 18:04:59 +00:00
parent bb5115f04b
commit 3cecfbed74
4 changed files with 19 additions and 51 deletions

View file

@ -208,8 +208,8 @@ class Ssbhesabix_Setting {
<form id="ssbhesabix_form" enctype="multipart/form-data" action="" method="post"> <form id="ssbhesabix_form" enctype="multipart/form-data" action="" method="post">
<?php <?php
global $plugin_version; global $plugin_version;
if (defined('SSBHESABFA_VERSION')) { if (defined('SSBHESABIX_VERSION')) {
$plugin_version = constant('SSBHESABFA_VERSION'); $plugin_version = constant('SSBHESABIX_VERSION');
} }
$server_php_version = phpversion(); $server_php_version = phpversion();
$plugin_php_version = '8.1'; $plugin_php_version = '8.1';
@ -1628,12 +1628,12 @@ class Ssbhesabix_Setting {
$ssbhesabix_api = new Ssbhesabix_Api(); $ssbhesabix_api = new Ssbhesabix_Api();
$response = $ssbhesabix_api->settingSetChangeHook( $url, $hookPassword ); $response = $ssbhesabix_api->settingSetChangeHook( $url, $hookPassword );
if ( is_object( $response ) ) { if ( is_object( $response ) ) {
if ( $response->Success ) { if ( $response->Success ) {
update_option( 'ssbhesabix_live_mode', 1 ); 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 //set the last log ID if is not set
$lastChanges = get_option( 'ssbhesabix_last_log_check_id' ); $lastChanges = get_option( 'ssbhesabix_last_log_check_id' );
if ( ! $lastChanges ) { if ( ! $lastChanges ) {

View file

@ -29,6 +29,8 @@ class Ssbhesabix_Activator {
add_option('ssbhesabix_webhook_password', bin2hex(openssl_random_pseudo_bytes(16))); add_option('ssbhesabix_webhook_password', bin2hex(openssl_random_pseudo_bytes(16)));
add_option('ssbhesabix_last_log_check_id', 0); 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_live_mode', 0);
add_option('ssbhesabix_debug_mode', 0); add_option('ssbhesabix_debug_mode', 0);
add_option('ssbhesabix_contact_address_status', 1); add_option('ssbhesabix_contact_address_status', 1);
add_option('ssbhesabix_contact_node_family', 'مشتریان فروشگاه آن‌لاین'); 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_submit_product_automatically', "no");
add_option('ssbhesabix_do_not_update_product_price_in_hesabix', "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_contact_add_additional_checkout_fields_hesabix', 1);
add_option('ssbhesabix_account_bid', 1);
add_option('ssbhesabix_account_year', 1);
self::ssbhesabix_create_database_table(); self::ssbhesabix_create_database_table();
} }
//=============================================================================================================== //===============================================================================================================

View file

@ -24,13 +24,10 @@ class Ssbhesabix_Api
$apiAddress = get_option('ssbhesabix_api_address', 0); $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( $body = array_merge(array(
'apiKey' => get_option('ssbhesabix_account_api'), 'API-KEY' => 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') : '',
), $data); ), $data);
//Debug mode //Debug mode
@ -42,6 +39,9 @@ class Ssbhesabix_Api
'body' => wp_json_encode($body), 'body' => wp_json_encode($body),
'headers' => array( 'headers' => array(
'Content-Type' => 'application/json', '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, 'timeout' => 60,
'redirection' => 5, 'redirection' => 5,
@ -52,10 +52,8 @@ class Ssbhesabix_Api
); );
//HesabixLogService::writeLogObj($options); //HesabixLogService::writeLogObj($options);
$wp_remote_post = wp_remote_post($endpoint, $options); $wp_remote_post = wp_remote_post($endpoint, $options);
$result = json_decode(wp_remote_retrieve_body($wp_remote_post)); $result = json_decode(wp_remote_retrieve_body($wp_remote_post));
//Debug mode //Debug mode
if (get_option('ssbhesabix_debug_mode')) { if (get_option('ssbhesabix_debug_mode')) {
HesabixLogService::log(array("Debug Mode - Result: " . print_r($result, true))); HesabixLogService::log(array("Debug Mode - Result: " . print_r($result, true)));
@ -67,40 +65,7 @@ class Ssbhesabix_Api
if ($result == null) { if ($result == null) {
return 'No response from Hesabix'; return 'No response from Hesabix';
} else { } else {
if (!isset($result->Success)) { return $result;
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 false; return false;
} }
@ -398,8 +363,7 @@ class Ssbhesabix_Api
//Settings functions //Settings functions
public function settingSetChangeHook($url, $hookPassword) public function settingSetChangeHook($url, $hookPassword)
{ {
$method = 'api/settings/chack-api'; $method = 'hooks/setting/SetChangeHook';
echo 11;
$data = array( $data = array(
'url' => $url, 'url' => $url,
'hookPassword' => $hookPassword, 'hookPassword' => $hookPassword,

View file

@ -61,8 +61,8 @@ class Ssbhesabix
*/ */
public function __construct() public function __construct()
{ {
if (defined('SSBHESABFA_VERSION')) { if (defined('SSBHESABIX_VERSION')) {
$this->version = SSBHESABFA_VERSION; $this->version = SSBHESABIX_VERSION;
} else { } else {
$this->version = '2.0.93'; $this->version = '2.0.93';
} }