diff --git a/SimPay_jshandler.php b/SimPay_jshandler.php deleted file mode 100644 index 5597b42..0000000 --- a/SimPay_jshandler.php +++ /dev/null @@ -1,34 +0,0 @@ - 'No error has occurred', - JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded', - JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON', - JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded', - JSON_ERROR_SYNTAX => 'Syntax error', - JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded' - ); - - public static function encode($value, $options = 0) { - $result = json_encode($value, $options); - - if($result) { - return $result; - } - - throw new RuntimeException(static::$_messages[json_last_error()]); - } - - public static function decode($json, $assoc = false) { - $result = json_encode($json, $assoc); - - if($result) { - return $result; - } - - throw new RuntimeException(static::$_messages[json_last_error()]); - } - -} -?> \ No newline at end of file diff --git a/Simpay.php b/Simpay.php deleted file mode 100644 index eeeed07..0000000 --- a/Simpay.php +++ /dev/null @@ -1,93 +0,0 @@ -auth = array( - "auth" => array( - "key" => $key, - "secret" => $secret, - ) - ); - } - - public function url($value, $params = array()) - { - $data = json_encode(array('params'=>array_merge($this->auth, $params))); - $this->call = $this->request($data, "https://simpay.pl/api/".$value); - return $this->call; - } - - public function getStatus($params) - { - $this->response = $this->url('status', $params); - return $this->response; - } - - public function getServices() - { - $this->response = $this->url( 'get_services' ); - return $this->response; - } - - public function check() - { - if(isset($this->response) and is_array($this->response)) { - if(isset($this->response['respond']['status']) and $this->response['respond']['status']=='OK') { - return true; - } else if(isset($this->response['error']) and is_array($this->response['error'])) { - return false; - } - } else { - throw new Exception('Brak informacji na temat ostatniego zapytania'); - } - } - - public function error() - { - if(isset($this->response['error']) and is_array($this->response['error'])) { - return true; - } else { - return false; - } - } - - public function showError() - { - if(isset($this->response['error']) and is_array($this->response['error'])) { - return $this->response['error']; - } else { - throw new Exception('Brak bledu do pokazania'); - } - } - - private function request($data, $url) - { - $curl = curl_init(); - curl_setopt($curl, CURLOPT_URL, $url); - curl_setopt($curl, CURLOPT_POST, 1); - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($curl, CURLOPT_POSTFIELDS, $data); - curl_setopt($curl, CURLOPT_FAILONERROR, 1); - curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // developer only - $call = curl_exec($curl); - $response = json_decode($call, true); - $error = curl_errno($curl); - curl_close($curl); - - if ($error > 0) { - throw new RuntimeException('CURL ERROR Code:'.$error); - } - return $response; - } - - public function response() { - return $this->response; - } -} diff --git a/assets/img/sim.png b/assets/img/sim.png new file mode 100644 index 0000000..9367fb3 Binary files /dev/null and b/assets/img/sim.png differ diff --git a/assets/js/simpay.js b/assets/js/simpay.js new file mode 100644 index 0000000..cf82860 --- /dev/null +++ b/assets/js/simpay.js @@ -0,0 +1,9 @@ +jQuery("#usluga2").change(function () { + const selected = jQuery(this).find(':selected').val(); + + jQuery('.selectsms').hide(); + jQuery('#prices_' + selected).show(); + + console.log('test'); + +}); \ No newline at end of file diff --git a/functions.php b/functions.php deleted file mode 100644 index 39e1164..0000000 --- a/functions.php +++ /dev/null @@ -1,469 +0,0 @@ - '0.50', - '7136' => '1', - '7255' => '2', - '7355' => '3', - '7436' => '4', - '7536' => '5', - '7636' => '6', - '7736' => '7', - '7836' => '8', - '7936' => '9', - '91055' => '10', - '91155' => '11', - '91455' => '14', - '91664' => '16', - '91955' => '19', - '92055' => '20', - '92555' => '25' -); - -function simpay_create_db(){ - global $wpdb; - - add_option("simpay_key", ""); - add_option("simpay_secret", ""); - add_option("simpay-register-sms", ""); - add_option("simpay-register-numer", ""); - add_option("simpay-register-sekret", ""); - add_option("simpay-register-id", ""); - add_option("simpay-register-usluga", ""); - add_option("simpay-register-cena", ""); - add_option("simpay-hidden-sms", ""); - add_option("simpay-hidden-numer", ""); - add_option("simpay-hidden-sekret", ""); - add_option("simpay-hidden-id", ""); - add_option("simpay-hidden-usluga", ""); - add_option("simpay-hidden-cena", ""); - - $charset_collate = $wpdb->get_charset_collate(); - - $table_name = $wpdb->prefix . 'simpay'; - - $sql = "CREATE TABLE $table_name ( - id mediumint(9) NOT NULL AUTO_INCREMENT, - numer varchar(10) NOT NULL, - usluga varchar(160) NOT NULL, - id_uslugi varchar(160) NOT NULL, - UNIQUE KEY id (id) - ) $charset_collate;"; - - require_once (ABSPATH . 'wp-admin/includes/upgrade.php'); - - dbDelta($sql); -} - -// end -// admin menu - -function simpay_add_to_menu(){ - add_menu_page("SimPay", "SimPay", "manage_options", "simpay-ustawienia", "simpay_ustawienia_func", plugins_url( 'SimPay-WordPress/simico.png' ), null, 99); -} - -// end - -function simpay_register(){ - global $simpay_cennik; - - if (!empty(get_option("simpay-register-sms"))) { - echo ' -
- -
- '; - } -} - -function simpay_register_validate($errors, $sanitized_user_login, $user_email){ - try { - - if (empty($_POST['kod_sms']) || !empty($_POST['kod_sms']) && trim($_POST['kod_sms']) == '') { - $errors->add('first_name_error', __('ERROR: Wprowadz kod SMS.', 'mydomain')); - - return $errors; - } - - $codeSMS = trim( $_POST[ 'kod_sms' ] ); - - $codeSMS = filter_var( $codeSMS, FILTER_SANITIZE_STRING ); - - if( strlen( $codeSMS ) == 0 ){ - $errors->add('first_name_error', __('ERROR: Wprowadz kod SMS.', 'mydomain')); - - return $errors; - } - - $api = new SimPay(get_option('simpay_key') , get_option('simpay_secret') ); - - $api->getStatus(array( - 'service_id' => get_option("simpay-register-id") , - 'number' => get_option("simpay-register-numer") , - 'code' => $codeSMS - )); - - if ($api->check()) { - - // kod poprawny - - } - elseif ($api->error()) { - - // niepoprawny kod - - $errors->add('first_name_error', __('ERROR: Podany kod jest niepoprawny.', 'mydomain')); - } - } - catch(Exception $e) { - echo 'Error: ' . $e->getMessage(); - } - - return $errors; -} - -// admin functions - -function simpay_ustawienia_func(){ - global $wpdb; - global $simpay_cennik; - - if( !current_user_can( 'administrator' ) ){ - return; - } - - $api = new SimPay( get_option('simpay_key') , get_option('simpay_secret') ); - - if (!empty($_POST[ 'aktualizuj_key' ])) { - - if( !check_admin_referer( 'simpay' ) ){ - return; - } - - $apiKey = trim( $_POST[ 'api_key' ] ); - $apiSecret = trim( $_POST[ 'secret_key' ] ); - - if( filter_var( $apiKey, FILTER_SANITIZE_STRING ) !== FALSE && - filter_var( $apiSecret, FILTER_SANITIZE_STRING ) !== FALSE ){ - - update_option("simpay_key", $apiKey ); - update_option("simpay_secret", $apiSecret ); - } - } - - if (!empty($_POST[ 'aktualizuj_2' ])) { - - if( !check_admin_referer( 'simpay' ) ){ - return; - } - - $contextString = trim( $_POST[ 'usluga' ] ); - $priceString = trim( $_POST[ 'cena' ] ); - - $contextArray = explode( '|' , $contextString ); - $priceArray = explode( '|' , $priceString ); - - if( count( $contextArray ) != 2 ){ - return; - } - - if( count( $priceArray ) != 2 ){ - return; - } - - update_option("simpay-register-cena", $priceArray[1]); - update_option("simpay-register-numer", trim($priceArray[0])); - update_option("simpay-register-sms", trim('SIM.' . $contextArray[1])); - update_option("simpay-register-id", trim($contextArray[0])); - } - - if (!empty($_POST[ 'aktualizuj_3' ])) { - - if( !check_admin_referer( 'simpay' ) ){ - return; - } - - $contextString = trim( $_POST[ 'usluga' ] ); - $priceString = trim( $_POST[ 'cena' ] ); - - $contextArray = explode( '|' , $contextString ); - $priceArray = explode( '|' , $priceString ); - - if( count( $contextArray ) != 2 ){ - return; - } - - if( count( $priceArray ) != 2 ){ - return; - } - - $wpdb->insert($wpdb->prefix . "simpay", array( - 'numer' => $priceArray[0], - 'usluga' => $contextArray[1], - 'id_uslugi' => $contextArray[0], - )); - } - - $t_menu = ''; - - if (!empty($_GET["register"])) { - $t_menu = ''; - } - - echo ' -Usługa | -Kod | -Akcja | -
' . $value->numer . ':' . $value->usluga . ' | -- | - |
'; + print_r($array); + echo ''; + } +} \ No newline at end of file diff --git a/req/functions.php b/req/functions.php new file mode 100644 index 0000000..f3128b6 --- /dev/null +++ b/req/functions.php @@ -0,0 +1,13 @@ +get_charset_collate(); + $simpay_table_name = $wpdb->prefix . 'simpay'; + $query = "CREATE TABLE " . $simpay_table_name . " ( + id mediumint(9) NOT NULL AUTO_INCREMENT, + numer varchar(10) NOT NULL, + usluga varchar(160) NOT NULL, + prefix varchar(160) NOT NULL, + id_uslugi varchar(160) NOT NULL, + UNIQUE KEY id (id) + ) " . $charset_collate . ";"; + $wpdb->query($query); + +} + +function simpay_uninstall() { + + global $wpdb; + + /* + * Usuwanie wpisów z ustawień WP + */ + + delete_option("simpay_key"); + delete_option("simpay_secret"); + delete_option("simpay-register-sms"); + delete_option("simpay-register-numer"); + delete_option("simpay-register-sekret"); + delete_option("simpay-register-id"); + delete_option("simpay-register-usluga"); + delete_option("simpay-register-cena"); + delete_option("simpay-hidden-sms"); + delete_option("simpay-hidden-numer"); + delete_option("simpay-hidden-sekret"); + delete_option("simpay-hidden-id"); + delete_option("simpay-hidden-usluga"); + delete_option("simpay-hidden-cena"); + + /* + * Usuwanie tabeli z bazy danych + */ + + $prefix = $wpdb->prefix; + $simpay_table_name = $prefix . "simpay"; + $query = 'DROP TABLE '. $simpay_table_name; + $wpdb->query($query); + +} + +function simpay_menu_add() { + add_menu_page("SimPay", "SimPay", "manage_options", "simpay-ustawienia", "simpay_admin_settings", plugins_url('simpay-wordpress/assets/img/sim.png'), null, 99); +} + +function simpay_load_scripts() { + //wp_enqueue_script('simpay', plugins_url('assets/js/simpay.js', dirname(__FILE__)), array('jquery')); +} + +/* + * Formularz płatności przy rejestracji +*/ + +function simpay_register_form() { + global $simpay; + + $simpay_local = []; + $simpay_local['content'] = get_option("simpay-register-sms"); + $simpay_local['number'] = get_option("simpay-register-numer"); + + if (!empty(get_option("simpay-register-sms"))) { + echo '
'; + echo ''; + echo '
'; + } + +} + +function simpay_register_validate($errors, $sanitized_user_login, $user_email) { + global $simpay; + + try { + + if (empty($_POST['kod_sms']) || !empty($_POST['kod_sms']) && trim($_POST['kod_sms']) == '') { + $errors->add('first_name_error', __('ERROR: Wprowadz kod SMS.', 'mydomain')); + + return $errors; + } + + $codeSMS = trim($_POST['kod_sms']); + + if (strlen($codeSMS) == 0) { + $errors->add('first_name_error', __('ERROR: Wprowadz kod SMS.', 'mydomain')); + + return $errors; + } + + $simpay->getStatus([ + 'service_id' => get_option("simpay-register-id") , + 'number' => get_option("simpay-register-numer") , + 'code' => $codeSMS + ]); + + if ($simpay->check()) { + + // kod poprawny + + } elseif ($simpay->error()) { + + // niepoprawny kod + + $errors->add('first_name_error', __('ERROR: Podany kod jest niepoprawny.', 'mydomain')); + } + } + catch(Exception $e) { + echo 'Error: ' . $e->getMessage(); + } + + return $errors; +} + +/* + * Blokada zawartości posta, który jest płatny. +*/ + +function simpay_content($content) { + global $simpay; + global $wpdb; + + /* + * Wyświetlanie na stronie "głównej" + */ + + if (is_front_page()) { + $querystr = "SELECT * FROM " . $wpdb->prefix . "simpay"; + $uslugi = $wpdb->get_results($querystr, OBJECT); + foreach($uslugi as & $value) { + $content = preg_replace("%\[hidden_content_" . $value->id . "\](.*?)\[/hidden_content_" . $value->id . "\]%s", "Płatność dostępna wewnątrz wpisu", $content); + } + + return $content; + } + + if (!in_the_loop()) { + return $content; + } + + if (!is_singular()) { + return $content; + } + + if (!is_main_query()) { + return $content; + } + + if (strpos($content, '[hidden_content') > 0) { + preg_match('/\[hidden_content_(?Usługa | +Kod | +Akcja | +
' . $value->numer . ':' . $value->usluga . ' | ++ | + |