Changeset 2349223
- Timestamp:
- 07/30/2020 04:26:02 PM (6 years ago)
- Location:
- ezcount/trunk
- Files:
-
- 3 edited
-
EZcount.php (modified) (6 diffs)
-
EZcount_helpers.php (modified) (2 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
ezcount/trunk/EZcount.php
r2346759 r2349223 4 4 * Plugin URI: 5 5 * Description: invoicing, clearing and paypal integration plugin. 6 * Version: 1.8. 36 * Version: 1.8.4 7 7 * Author: EZcount 8 8 * Author URI: … … 24 24 add_action( 'plugins_loaded', 'init_ezcount_gateway_class', 0 ); 25 25 26 26 27 function init_ezcount_gateway_class() { 27 28 if ( ! class_exists( 'WC_Payment_Gateway' ) ) { 28 29 return; 29 30 } 31 30 32 31 33 /** … … 80 82 */ 81 83 public function init_form_fields() { 84 82 85 $env = array( 83 86 'demo.ezcount.co.il' => 'DEMO', … … 89 92 $current_user = wp_get_current_user(); 90 93 $defaultEmail = $current_user->user_email; 94 95 96 $integrationProblem=EZcount_helpers::testIntegration($this->environment,$this->api_key,$defaultEmail); 97 98 99 91 100 $this->form_fields = array( 92 101 'clearing_integration' => array( … … 165 174 'desc_tip' => true, 166 175 ), 167 'section_title ' => array(176 'section_title2' => array( 168 177 'title' => __( 'Other Settings', '' ), 169 178 'type' => 'title', … … 213 222 'desc_tip' => true 214 223 ), 215 216 224 ); 225 226 /** 227 * show the integration error 228 */ 229 if($integrationProblem){ 230 $this->form_fields=array_merge(array('integrationProblem' => array( 231 'title' => "INTEGRATION TESTING ERROR! please fix the next issue", 232 'description' => "$integrationProblem", 233 'type' => 'title', 234 )), $this->form_fields); 235 } 217 236 } 218 237 -
ezcount/trunk/EZcount_helpers.php
r2308563 r2349223 3 3 class EZcount_helpers { 4 4 static public $lastResponseDebugStr; 5 6 public static function testIntegration( $environment, $api_key, $developer_email ) { 7 if ( ! is_email( $developer_email ) ) { 8 return "a valid developer email is mandatory"; 9 } 10 if ( preg_match( "/^([a-f0-9]{64})$/", $api_key ) != 1 ) { 11 return "the api key is missing or in wrong format! $api_key"; 12 } 13 // call ezcount 14 $data["api_key"] = $api_key; 15 $data["developer_email"] = $developer_email; 16 $res = self::_sendJsonRequest( 'https://' . $environment . '/api/createDoc', $data ); 17 if ( ! $res ) { 18 return self::$lastResponseDebugStr; 19 } 20 /** 21 * invalid api key 22 */ 23 if($res->errNum==1){ 24 return $res->errMsg; 25 } 26 27 28 $success = wp_mail( $developer_email, 'EZcount plugin, test developer email', 'This email been sent as part of EZcount plugin integration testing' ); 29 if ( ! $success ) { 30 return "Email integration testing failed, please check your mail server, the function wp_mail is not working properly while trying to send email to $developer_email"; 31 } 32 33 // empty string means we are goot! 34 return ""; 35 } 5 36 6 37 public static function getApiBase() { … … 9 40 $zc_payment->init_form_fields(); 10 41 $zc_payment->init_settings(); 11 $environment = $zc_payment->get_option('environment'); 42 $environment = $zc_payment->get_option( 'environment' ); 43 12 44 return 'https://' . $environment . '/api/'; 13 45 } 14 46 15 public static function sendJsonRequest($url, $data = array()) { 47 private static function _sendJsonRequest( $url, $data = array() ) { 48 $content = json_encode( $data ); 49 $responseObj = $data = wp_remote_post( $url, 50 array( 51 'headers' => array( 'Content-Type' => 'application/json; charset=utf-8' ), 52 'body' => $content, 53 'method' => 'POST', 54 'data_format' => 'body', 55 'sslverify' => false, 56 ) ); 57 58 $jsonStr = wp_remote_retrieve_body( $responseObj ); 59 //connection problem 60 if ( is_wp_error( $responseObj ) || wp_remote_retrieve_response_code( $responseObj ) != 200 ) { 61 self::$lastResponseDebugStr = "Error in opening request, please check your Firewall, and check that CURL have permission to call the url " . $url . "\n response code" . wp_remote_retrieve_response_code( $responseObj ); 62 } else { 63 self::$lastResponseDebugStr = $jsonStr; 64 } 65 66 return json_decode( $jsonStr ); 67 } 68 69 public static function sendJsonRequest( $url, $data = array() ) { 16 70 //do validation 17 71 $zc_payment = new WC_Gateway_EZcount(); 18 72 $zc_payment->init_form_fields(); 19 73 $zc_payment->init_settings(); 20 $data["api_key"] = $zc_payment->get_option('api_key');21 $data["developer_email"] = $zc_payment->get_option( 'user_email');74 $data["api_key"] = $zc_payment->get_option( 'api_key' ); 75 $data["developer_email"] = $zc_payment->get_option( 'user_email' ); 22 76 23 $content = json_encode($data); 24 $responseObj = $data = wp_remote_post($url, array( 25 'headers' => array('Content-Type' => 'application/json; charset=utf-8'), 26 'body' => $content, 27 'method' => 'POST', 28 'data_format' => 'body', 29 'sslverify' => false, 30 )); 31 32 $jsonStr = wp_remote_retrieve_body($responseObj); 33 //connection problem 34 if (is_wp_error($responseObj) || wp_remote_retrieve_response_code($responseObj) != 200) { 35 self::$lastResponseDebugStr = "Error in opening request, please check your Firewall, and check that CURL have permission to call the url " . $url . "\n response code" . wp_remote_retrieve_response_code($responseObj); 36 } else { 37 self::$lastResponseDebugStr = $jsonStr; 38 } 39 return json_decode($jsonStr); 77 return self::_sendJsonRequest( $url, $data ); 40 78 } 41 79 42 static public function encrypt($plaintext, $key) { 43 $ivlen = openssl_cipher_iv_length($cipher = "AES-128-CBC"); 44 $iv = openssl_random_pseudo_bytes($ivlen); 45 $ciphertext_raw = openssl_encrypt($plaintext, $cipher, $key, $options = OPENSSL_RAW_DATA, $iv); 46 $hmac = hash_hmac('sha256', $ciphertext_raw, $key, $as_binary = true); 47 $ciphertext = base64_encode($iv . $hmac . $ciphertext_raw); 80 static public function encrypt( $plaintext, $key ) { 81 $ivlen = openssl_cipher_iv_length( $cipher = "AES-128-CBC" ); 82 $iv = openssl_random_pseudo_bytes( $ivlen ); 83 $ciphertext_raw = openssl_encrypt( $plaintext, $cipher, $key, $options = OPENSSL_RAW_DATA, $iv ); 84 $hmac = hash_hmac( 'sha256', $ciphertext_raw, $key, $as_binary = true ); 85 $ciphertext = base64_encode( $iv . $hmac . $ciphertext_raw ); 86 48 87 return $ciphertext; 49 88 } 50 89 51 static public function decrypt( $ciphertext, $key) {52 $c = base64_decode($ciphertext);53 $ivlen = openssl_cipher_iv_length($cipher = "AES-128-CBC");54 $iv = substr($c, 0, $ivlen);55 $hmac = substr($c, $ivlen, $sha2len = 32);56 $ciphertext_raw = substr($c, $ivlen + $sha2len);57 $original_plaintext = openssl_decrypt( $ciphertext_raw, $cipher, $key, $options = OPENSSL_RAW_DATA, $iv);58 $calcmac = hash_hmac('sha256', $ciphertext_raw, $key, $as_binary = true);59 if ( hash_equals($hmac, $calcmac))//PHP 5.6+ timing attack safe comparison90 static public function decrypt( $ciphertext, $key ) { 91 $c = base64_decode( $ciphertext ); 92 $ivlen = openssl_cipher_iv_length( $cipher = "AES-128-CBC" ); 93 $iv = substr( $c, 0, $ivlen ); 94 $hmac = substr( $c, $ivlen, $sha2len = 32 ); 95 $ciphertext_raw = substr( $c, $ivlen + $sha2len ); 96 $original_plaintext = openssl_decrypt( $ciphertext_raw, $cipher, $key, $options = OPENSSL_RAW_DATA, $iv ); 97 $calcmac = hash_hmac( 'sha256', $ciphertext_raw, $key, $as_binary = true ); 98 if ( hash_equals( $hmac, $calcmac ) )//PHP 5.6+ timing attack safe comparison 60 99 { 61 100 return $original_plaintext; 62 101 } 102 63 103 //failed to decrypt 64 104 return ''; -
ezcount/trunk/readme.txt
r2346759 r2349223 4 4 Tags : Invoicing and clearing for Woocommerce, by EasyCount. 5 5 Tested up to: 4.9.8 6 Version : 1.8. 36 Version : 1.8.4 7 7 Stable tag: trunk 8 8 Requires PHP: 5.4
Note: See TracChangeset
for help on using the changeset viewer.