/novalnetpayments.php

  1. <?php 
  2. /** 
  3. * Plugin Name: Woocommerce Payment Gateway by Novalnet 
  4. * Plugin URI: http://www.novalnet.com/modul/woocommerce 
  5. * Description: Adds Novalnet Payment Gateway to Woocommerce e-commerce plugin 
  6. * Author: Novalnet 
  7. * Author URI: https://www.novalnet.de 
  8. *  
  9. * Version: 1.1.0 
  10. * Requires at least: 3.3 
  11. * Tested up to: 3.6.1 
  12. * 
  13. * Text Domain: woocommerce-novalnetpayment 
  14. * Domain Path: /languages/ 
  15. *  
  16. * License: GPLv2 
  17. */ 
  18.  
  19. /** Plugin installation starts */ 
  20. register_activation_hook(__FILE__, 'novalnetpayments_activation'); 
  21. register_deactivation_hook(__FILE__, 'novalnetpayments_deactivation'); 
  22.  
  23. /** Initiate admin notice display */ 
  24. add_action('admin_notices', 'novalnetpayments_admin_notices'); 
  25.  
  26. if (!function_exists('novalnetpayments_activation')) { 
  27.  
  28. function novalnetpayments_activation() { 
  29. //register uninstaller 
  30. register_uninstall_hook(__FILE__, 'novalnetpayments_uninstall'); 
  31.  
  32. } // End novalnetpayments_activation() 
  33.  
  34. } #Endif 
  35.  
  36. if (!function_exists('novalnetpayments_deactivation')) { 
  37.  
  38. function novalnetpayments_deactivation() { 
  39. // actions to perform once on plugin deactivation go here  
  40.  
  41. } // End novalnetpayments_deactivation() 
  42.  
  43. } #Endif 
  44.  
  45. if (!function_exists('novalnetpayments_uninstall')) { 
  46.  
  47. function novalnetpayments_uninstall() { 
  48. //actions to perform once on plugin uninstall go here 
  49.  
  50. } // End novalnetpayments_uninstall() 
  51.  
  52. } #Endif 
  53.  
  54. /** 
  55. * Display admin notice at back-end during plugin activation 
  56. */ 
  57. function novalnetpayments_admin_notices() { 
  58. if (!is_plugin_active('woocommerce/woocommerce.php')) { 
  59. echo '<div id="notice" class="error"><p>'; 
  60. echo '<b>' . __('Woocommerce Payment Gateway by Novalnet', 'woocommerce-novalnetpayment') . '</b> ' . __('add-on requires', 'woocommerce-novalnetpayment') . ' ' . '<a href="http://www.woothemes.com/woocommerce/" target="_new">' . __('WooCommerce', 'woocommerce-novalnetpayment') . '</a>' . ' ' . __('plugin. Please install and activate it.', 'woocommerce-novalnetpayment'); 
  61. echo '</p></div>', "\n"; 
  62. } #Endif 
  63.  
  64. } // End novalnetpayments_admin_notices() 
  65.  
  66. /** Plugin installation ends */ 
  67. $novalnet_payment_methods = array('novalnet_banktransfer', 'novalnet_cc', 'novalnet_cc3d', 'novalnet_elv_at', 'novalnet_elv_de', 'novalnet_ideal', 'novalnet_invoice', 'novalnet_paypal', 'novalnet_prepayment', 'novalnet_tel'); 
  68.  
  69. /** 
  70. * Get active network plugins 
  71. */ 
  72. if (!function_exists('nn_active_nw_plugins')) { 
  73.  
  74. function nn_active_nw_plugins() { 
  75. if (!is_multisite()) 
  76. return false; 
  77. $nn_activePlugins = (get_site_option('active_sitewide_plugins')) ? array_keys(get_site_option('active_sitewide_plugins')) : array(); 
  78. return $nn_activePlugins; 
  79. } // End nn_active_nw_plugins() 
  80.  
  81. } #Endif 
  82.  
  83. add_action('plugins_loaded', 'novalnetpayments_Load', 0); 
  84.  
  85. /** 
  86. * Initial plugin load 
  87. */ 
  88. function novalnetpayments_Load() { 
  89.  
  90. /** Load Novalnet language translations */ 
  91. load_plugin_textdomain('woocommerce-novalnetpayment', false, dirname(plugin_basename(__FILE__)) . '/languages/'); 
  92.  
  93. /** verify whether woocommerce is an active plugin before initializing Novlanet Payment Gateway */ 
  94. if (in_array('woocommerce/woocommerce.php', (array) get_option('active_plugins')) || in_array('woocommerce/woocommerce.php', (array) nn_active_nw_plugins())) { 
  95.  
  96. if (!class_exists('WC_Payment_Gateway')) 
  97. return; 
  98.  
  99. if (!class_exists('novalnetpayments')) { 
  100.  
  101. /** 
  102. * Common class for Novalnet Payment Gateway 
  103. */ 
  104. class novalnetpayments extends WC_Payment_Gateway { 
  105.  
  106. /** Novalnet Payment urls */ 
  107. var $novalnet_paygate_url = 'https://payport.novalnet.de/paygate.jsp'; 
  108. var $novalnet_cc_form_display_url = 'https://payport.novalnet.de/direct_form.jsp'; 
  109. var $novalnet_online_transfer_payport_url = 'https://payport.novalnet.de/online_transfer_payport'; 
  110. var $novlanet_cc3d_payport_url = 'https://payport.novalnet.de/global_pci_payport'; 
  111. var $novlanet_paypal_payport_url = 'https://payport.novalnet.de/paypal_payport'; 
  112. var $novlanet_tel_second_call_url = 'https://payport.novalnet.de/nn_infoport.xml'; 
  113.  
  114. /** Novalnet Payment keys */ 
  115. var $payment_key_for_cc_family = 6; 
  116. var $payment_key_for_at_family = 8; 
  117. var $payment_key_for_de_family = 2; 
  118. var $payment_key_for_invoice_prepayment = 27; 
  119. var $payment_key_for_tel = 18; 
  120. var $payment_key_for_paypal = 34; 
  121. var $payment_key_for_online_transfer = 33; 
  122. var $payment_key_for_ideal = 49; 
  123.  
  124. /** Novalnet Payment method arrays */ 
  125. var $front_end_form_available_array = array('novalnet_cc', 'novalnet_cc3d', 'novalnet_elv_de', 'novalnet_elv_at'); 
  126. var $manual_check_limit_not_available_array = array('novalnet_banktransfer', 'novalnet_ideal', 'novalnet_invoice', 'novalnet_prepayment', 'novalnet_paypal', 'novalnet_tel'); 
  127. var $return_url_parameter_for_array = array('novalnet_banktransfer', 'novalnet_cc3d', 'novalnet_ideal', 'novalnet_paypal'); 
  128. var $encode_applicable_for_array = array('novalnet_banktransfer', 'novalnet_ideal', 'novalnet_paypal'); 
  129. var $user_variable_parameter_for_arrray = array('novalnet_banktransfer', 'novalnet_paypal', 'novalnet_ideal'); 
  130. var $language_supported_array = array('en', 'de'); 
  131.  
  132. /** 
  133. * Telephone payment second call request 
  134. */ 
  135. public function do_make_second_call_for_novalnet_telephone($order_id) { 
  136.  
  137. global $woocommerce; 
  138. $order = new WC_Order($order_id); 
  139.  
  140. /** validate Telephone second call mandatory parameters */ 
  141. if (isset($this->vendor_id) && $this->vendor_id != null && isset($this->auth_code) && $this->auth_code != null && isset($_SESSION['novalnet_tel_tid']) && $_SESSION['novalnet_tel_tid'] != null && isset($this->language) && $this->language != null) { 
  142.  
  143. ### Process the payment to infoport ## 
  144. $urlparam = '<nnxml><info_request><vendor_id>' . $this->vendor_id . '</vendor_id>'; 
  145. $urlparam .= '<vendor_authcode>' . $this->auth_code . '</vendor_authcode>'; 
  146. $urlparam .= '<request_type>NOVALTEL_STATUS</request_type><tid>' . $_SESSION['novalnet_tel_tid'] . '</tid>'; 
  147. $urlparam .= '<lang>' . strtoupper($this->language) . '</lang></info_request></nnxml>'; 
  148. list($errno, $errmsg, $data) = $this->perform_https_request($this->second_call_url, $urlparam);  
  149. if (strstr($data, '<novaltel_status>')) { 
  150. preg_match('/novaltel_status>?([^<]+)/i', $data, $matches); 
  151. $aryResponse['status'] = $matches[1]; 
  152. preg_match('/novaltel_status_message>?([^<]+)/i', $data, $matches); 
  153. $aryResponse['status_desc'] = $matches[1]; 
  154. } #Endif  
  155.  
  156. else { 
  157. $aryPaygateResponse = explode('&', $data); 
  158. foreach ($aryPaygateResponse as $key => $value) { 
  159. if ($value != "") { 
  160. $aryKeyVal = explode("=", $value); 
  161. $aryResponse[$aryKeyVal[0]] = $aryKeyVal[1]; 
  162. } #Endif 
  163. } #Endforeach 
  164. } #Endelse 
  165.  
  166. $aryResponse['tid'] = $_SESSION['novalnet_tel_tid']; 
  167. $aryResponse['test_mode'] = $_SESSION['novalnet_tel_test_mode']; 
  168. $aryResponse['order_no'] = ltrim($order->get_order_number(), __('#', 'hash before order number', 'woocommerce-novalnetpayment')); 
  169. $aryResponse['inputval1'] = $order_id; 
  170.  
  171. // Manual Testing 
  172. // $aryResponse['status_desc'] = __('Successful', 'woocommerce-novalnetpayment'); 
  173. // $aryResponse['status'] = 100; 
  174. // Manual Testing 
  175.  
  176. return($this->do_check_novalnet_status($aryResponse)); 
  177.  
  178. } #Endif 
  179.  
  180. else { 
  181. $this->do_unset_novalnet_telephone_sessions(); 
  182. $this->do_check_and_add_novalnet_errors_and_messages(__('Basic Parameter Missing', 'woocommerce-novalnetpayment'), 'error'); 
  183. return($this->do_return_redirect_page_for_pay_or_thanks_page('success', $woocommerce->cart->get_checkout_url()));  
  184. } #Endelse 
  185.  
  186. } // End do_make_second_call_for_novalnet_telephone() 
  187.  
  188. /** 
  189. * Clears Telephone payment session value 
  190. */ 
  191. public function do_unset_novalnet_telephone_sessions() { 
  192.  
  193. unset($_SESSION['novalnet_tel_tid']); 
  194. unset($_SESSION['novalnet_tel_test_mode']); 
  195. unset($_SESSION['novalnet_tel_amount']); 
  196.  
  197. } // End do_unset_novalnet_telephone_sessions() 
  198.  
  199. /** 
  200. * process Telephone payment server response 
  201. */ 
  202. public function do_check_novalnet_tel_payment_status(&$aryResponse, $order) { 
  203. global $woocommerce; 
  204. $new_line = "<br />"; 
  205.  
  206. if ($aryResponse['status'] == 100 && $aryResponse['tid']) { 
  207. $aryResponse['status_desc'] = ''; 
  208. if (!isset($_SESSION['novalnet_tel_tid'])) 
  209. $_SESSION['novalnet_tel_tid'] = $aryResponse['tid']; 
  210. $_SESSION['novalnet_tel_test_mode'] = $aryResponse['test_mode']; 
  211. $_SESSION['novalnet_tel_amount'] = $this->amount; 
  212. } #Endif 
  213.  
  214. elseif ($aryResponse['status'] == 19) 
  215. unset($_SESSION['novalnet_tel_tid']); 
  216.  
  217. else 
  218. $status = $aryResponse['status']; 
  219.  
  220. if ($aryResponse['status'] == 100) { 
  221. $sess_tel = trim($aryResponse['novaltel_number']); 
  222. if ($sess_tel) { 
  223. $aryTelDigits = str_split($sess_tel, 4); 
  224. $count = 0; 
  225. $str_sess_tel = ''; 
  226. foreach ($aryTelDigits as $ind => $digits) { 
  227. $count++; 
  228. $str_sess_tel .= $digits; 
  229. if ($count == 1) 
  230. $str_sess_tel .= '-'; 
  231. else 
  232. $str_sess_tel .= ' '; 
  233. } #Endforeach 
  234.  
  235. $str_sess_tel = trim($str_sess_tel); 
  236. if ($str_sess_tel) 
  237. $sess_tel = $str_sess_tel; 
  238. } #Endif 
  239.  
  240. $this->do_check_and_add_novalnet_errors_and_messages(__('Following steps are required to complete your payment:', 'woocommerce-novalnetpayment') . $new_line . $new_line . __('Step 1: Please call the telephone number displayed:', 'woocommerce-novalnetpayment') . ' ' . $sess_tel . $new_line . str_replace('{amount}', $order->get_formatted_order_total(), __('* This call will cost {amount} (including VAT) and it is possible only for German landline connection! *', 'woocommerce-novalnetpayment')) . $new_line . $new_line . __('Step 2: Please wait for the beep and then hang up the listeners.', 'woocommerce-novalnetpayment') . $new_line . __('After your successful call, please proceed with the payment.', 'woocommerce-novalnetpayment'), 'message'); 
  241. return($this->do_return_redirect_page_for_pay_or_thanks_page('success', $woocommerce->cart->get_checkout_url())); 
  242. } #Endif 
  243.  
  244. else { 
  245.  
  246. $this->do_check_and_add_novalnet_errors_and_messages($aryResponse['status_desc'], 'error'); 
  247. return($this->do_return_redirect_page_for_pay_or_thanks_page('success', $woocommerce->cart->get_checkout_url())); 
  248.  
  249. } #Endelse 
  250.  
  251. } // End do_check_novalnet_tel_payment_status() 
  252.  
  253. /** 
  254. * Validate cart amount 
  255. */ 
  256. public function do_validate_amount() { 
  257.  
  258. global $woocommerce; 
  259.  
  260. if ($this->amount < 99 || $this->amount > 1000) { 
  261.  
  262. $this->do_check_and_add_novalnet_errors_and_messages(__('Amounts below 0, 99 Euros and above 10, 00 Euros cannot be processed and are not accepted!', 'woocommerce-novalnetpayment'), 'error'); 
  263. return($this->do_return_redirect_page_for_pay_or_thanks_page('success', $woocommerce->cart->get_checkout_url())); 
  264.  
  265. } #Endif 
  266.  
  267. } // End do_validate_amount() 
  268.  
  269. /** 
  270. * Validate amount variations in cart 
  271. */ 
  272. public function do_validate_amount_variations() { 
  273.  
  274. global $woocommerce; 
  275.  
  276. if (isset($_SESSION['novalnet_tel_amount']) && $_SESSION['novalnet_tel_amount'] != $this->amount) { 
  277.  
  278. $this->do_unset_novalnet_telephone_sessions(); 
  279. $this->do_check_and_add_novalnet_errors_and_messages(__('You have changed the order amount after receiving telephone number, please try again with a new call', 'woocommerce-novalnetpayment'), 'error'); 
  280. return($this->do_return_redirect_page_for_pay_or_thanks_page('success', $woocommerce->cart->get_checkout_url())); 
  281.  
  282. } #Endif 
  283.  
  284. return(''); 
  285.  
  286. } // End do_validate_amount_variations() 
  287.  
  288. /** 
  289. * Process data after paygate response 
  290. */ 
  291. public function do_prepare_to_novalnet_paygate($order) { 
  292.  
  293. list($errno, $errmsg, $data) = $this->perform_https_request($this->payport_or_paygate_url, $this->payment_parameters); 
  294. $aryResponse = array(); 
  295.  
  296. #capture the result and message and other parameters from response data '$data' in an array 
  297. $aryPaygateResponse = explode('&', $data); 
  298.  
  299. foreach ($aryPaygateResponse as $key => $value) {  
  300. if ($value != "") { 
  301. $aryKeyVal = explode("=", $value); 
  302. $aryResponse[$aryKeyVal[0]] = $aryKeyVal[1]; 
  303. } #Endif  
  304. } #Endforeach 
  305. return($aryResponse); 
  306.  
  307. } // End do_prepare_to_novalnet_paygate() 
  308.  
  309. /** 
  310. * process parameters before sending to server 
  311. */ 
  312. public function do_necessary_actions_before_prepare_to_novalnet_payport_or_paygate($order) { 
  313. $this->user_ip = $this->getRealIpAddr(); 
  314. $this->do_check_curl_installed_or_not(); 
  315. $this->do_format_amount($order->order_total); 
  316. $this->do_check_novalnet_backend_data_validation_from_frontend(); 
  317. $this->do_check_and_assign_manual_check_limit(); 
  318. $this->do_check_shop_parameter($order); 
  319. $this->do_form_payment_parameters($order); 
  320. } // End do_necessary_actions_before_prepare_to_novalnet_payport_or_paygate() 
  321.  
  322. /** 
  323. * Generate Novalnet secure form 
  324. */ 
  325. public function get_novalnet_form_html($order) { 
  326.  
  327. global $woocommerce; 
  328. $novalnet_args_array = array(); 
  329.  
  330. foreach ($this->payment_parameters as $key => $value) { 
  331. $novalnet_args_array[] = '<input type="hidden" name="' . esc_attr($key) . '" id="' . esc_attr($key) . '" value="' . esc_attr($value) . '" />'; 
  332. } #Endforeach 
  333.  
  334. $woocommerce->add_inline_js(' 
  335. jQuery("body").block({ 
  336. message: "<img src=\"' . esc_url(apply_filters('woocommerce_ajax_loader_url', $woocommerce->plugin_url() . '/assets/images/ajax-loader.gif')) . '\" alt=\"' . __('Redirecting...', 'woocommerce-novalnetpayment') . '…\" style=\"float:left; margin-right: 10px;\" />' . __('You will be redirected to Novalnet AG in a few seconds. <br>', 'woocommerce-novalnetpayment') . '",  
  337. baseZ: 99999,  
  338. overlayCSS: 
  339. background: "#fff",  
  340. opacity: 0.6 
  341. },  
  342. css: { 
  343. padding: 20,  
  344. textAlign: "center",  
  345. color: "#555",  
  346. border: "3px solid #aaa",  
  347. backgroundColor:"#fff",  
  348. cursor: "wait",  
  349. lineHeight: "32px" 
  350. }); 
  351. jQuery("#submit_novalnet_payment_form").click(); 
  352. '); 
  353.  
  354. return '<form id="frmnovalnet" name="frmnovalnet" action="' . $this->payport_or_paygate_url . '" method="post" target="_top">' . implode('', $novalnet_args_array) . ' 
  355. <input type="submit" class="button-alt" id="submit_novalnet_payment_form" value="' . __('Pay via Novalnet', 'woocommerce-novalnetpayment') . '" /> <a class="button cancel" href="' . esc_url($order->get_cancel_order_url()) . '">' . __('Cancel order & restore cart', 'woocommerce-novalnetpayment') . '</a> 
  356. </form>'; 
  357.  
  358. } // End get_novalnet_form_html() 
  359.  
  360. /** 
  361. * Validate curl extension 
  362. */ 
  363. public function do_check_curl_installed_or_not() { 
  364.  
  365. global $woocommerce; 
  366.  
  367. if (!function_exists('curl_init') && !in_array($this->novalnet_payment_method, $this->return_url_parameter_for_array)) { 
  368. $this->do_check_and_add_novalnet_errors_and_messages(__('You need to activate the CURL function on your server, please check with your hosting provider.', 'woocommerce-novalnetpayment'), 'error'); 
  369. wp_safe_redirect($woocommerce->cart->get_checkout_url()); 
  370. exit(); 
  371.  
  372. } #Endif 
  373.  
  374. } // End do_check_curl_installed_or_not() 
  375.  
  376. /** 
  377. * Validate shop address field parameter  
  378. */ 
  379. public function do_check_shop_parameter($order) { 
  380.  
  381. global $woocommerce; 
  382. $nn_tmp_name = array(); 
  383.  
  384. if (isset($order)) { 
  385.  
  386. $nn_first_name = isset($order->billing_first_name) ? trim($order->billing_first_name) : null; 
  387. $nn_last_name = isset($order->billing_last_name) ? trim($order->billing_last_name) : null; 
  388. $this->shop_nn_email = isset($order->billing_email) ? trim($order->billing_email) : null; 
  389.  
  390. /** Get customer first and last name */ 
  391. if ($nn_first_name != null && $nn_last_name != null) { 
  392. $this->shop_nn_first_name = $nn_first_name; 
  393. $this->shop_nn_last_name = $nn_last_name; 
  394. } #Endif  
  395.  
  396. elseif ($nn_first_name != null && $nn_last_name == null) { 
  397. $full_name = $nn_first_name; 
  398. $nn_tmp_name = explode(' ', $full_name, 2); 
  399. if (count($nn_tmp_name) == 1) { 
  400. $this->shop_nn_first_name = $nn_tmp_name[0]; 
  401. $this->shop_nn_last_name = $nn_tmp_name[0]; 
  402. } #Endif 
  403. else { 
  404. $this->shop_nn_first_name = $nn_tmp_name[0]; 
  405. $this->shop_nn_last_name = $nn_tmp_name[1]; 
  406. } #Endelse 
  407. } #Endelseif 
  408.  
  409. elseif ($nn_first_name == null && $nn_last_name != null) { 
  410. $full_name = $nn_last_name; 
  411. $nn_tmp_name = explode(' ', $full_name, 2); 
  412. if (count($nn_tmp_name) == 1) { 
  413. $this->shop_nn_first_name = $nn_tmp_name[0]; 
  414. $this->shop_nn_last_name = $nn_tmp_name[0]; 
  415. } #Endif  
  416. else { 
  417. $this->shop_nn_first_name = $nn_tmp_name[0]; 
  418. $this->shop_nn_last_name = $nn_tmp_name[1]; 
  419. } #Endelse 
  420. } #Endelseif 
  421.  
  422. elseif ($nn_first_name == null && $nn_last_name == null) { 
  423. $this->shop_nn_first_name = $nn_first_name; 
  424. $this->shop_nn_last_name = $nn_last_name; 
  425. } #Endelseif  
  426.  
  427. /** Novalnet validation for basic address fields (returns true only if the user modified default workflow) */ 
  428. if ($this->shop_nn_first_name == null || $this->shop_nn_last_name == null || $this->shop_nn_email == null) { 
  429. $this->do_check_and_add_novalnet_errors_and_messages(__('Please enter the customer name / email.', 'woocommerce-novalnetpayment'), 'error'); 
  430. wp_safe_redirect($woocommerce->cart->get_checkout_url()); 
  431. exit(); 
  432. } #Endif 
  433.  
  434. } #Endif 
  435.  
  436. } // End do_check_shop_parameter() 
  437.  
  438. /** 
  439. * Collects novalnet payment parameters 
  440. */ 
  441. public function do_form_payment_parameters($order) { 
  442. $this->get_backend_hash_parameter_array(); 
  443. $this->get_backend_variation_parameter_array(); 
  444. $this->get_user_variable_parameter_array(); 
  445. $this->get_return_url_parameter_array(); 
  446. $this->get_backend_additional_parameter_array($order); 
  447. $this->get_backend_common_parameter_array($order);  
  448. } // End do_form_payment_parameters() 
  449.  
  450. /** 
  451. * Get back-end hash parameter 
  452. */ 
  453. public function get_backend_hash_parameter_array() { 
  454.  
  455. if (in_array($this->novalnet_payment_method, $this->encode_applicable_for_array)) { 
  456. $this->auth_code = $this->encode($this->auth_code); 
  457. $this->product_id = $this->encode($this->product_id); 
  458. $this->tariff_id = $this->encode($this->tariff_id); 
  459. $this->amount = $this->encode($this->amount); 
  460. $this->test_mode = $this->encode($this->test_mode); 
  461. $this->unique_id = $this->encode($this->unique_id); 
  462.  
  463. if (isset($this->api_username)) 
  464. $this->api_username = $this->encode($this->api_username); 
  465.  
  466. if (isset($this->api_password)) 
  467. $this->api_password = $this->encode($this->api_password); 
  468.  
  469. if (isset($this->api_signature)) 
  470. $this->api_signature = $this->encode($this->api_signature); 
  471.  
  472. $hash = $this->hash(array('authcode' => $this->auth_code, 'product_id' => $this->product_id, 'tariff' => $this->tariff_id, 'amount' => $this->amount, 'test_mode' => $this->test_mode, 'uniqid' => $this->unique_id)); 
  473. $this->payment_parameters['hash'] = $hash; 
  474. } #Endif 
  475.  
  476. } // End get_backend_hash_parameter_array() 
  477.  
  478. /** 
  479. * Get back-end variation parameter 
  480. */ 
  481. public function get_backend_variation_parameter_array() { 
  482.  
  483. $this->payment_parameters['vendor'] = $this->vendor_id; 
  484. $this->payment_parameters['product'] = $this->product_id; 
  485. $this->payment_parameters['tariff'] = $this->tariff_id; 
  486. $this->payment_parameters['auth_code'] = $this->auth_code; 
  487.  
  488. } // End get_backend_variation_parameter_array() 
  489.  
  490. /** 
  491. * Get user variable parameter 
  492. */ 
  493. public function get_user_variable_parameter_array() { 
  494.  
  495. if (in_array($this->novalnet_payment_method, $this->user_variable_parameter_for_arrray)) 
  496. $this->payment_parameters['user_variable_0'] = site_url(); 
  497.  
  498. } // End get_user_variable_parameter_array() 
  499.  
  500. /** 
  501. * Get return url parameter  
  502. */ 
  503. public function get_return_url_parameter_array() { 
  504.  
  505. $return_url = get_permalink(get_option('woocommerce_checkout_page_id')); 
  506.  
  507. if (in_array($this->novalnet_payment_method, $this->return_url_parameter_for_array)) { 
  508. $this->payment_parameters['return_url'] = $return_url; 
  509. $this->payment_parameters['return_method'] = 'POST'; 
  510. $this->payment_parameters['error_return_url'] = $return_url; 
  511. $this->payment_parameters['error_return_method'] = 'POST'; 
  512. $this->payment_parameters['novalnet_payment_method'] = $this->novalnet_payment_method; 
  513. } #Endif 
  514.  
  515. } // End get_return_url_parameter_array() 
  516.  
  517. /** 
  518. * Get back-end additional parameters 
  519. */ 
  520. public function get_backend_additional_parameter_array($order) { 
  521.  
  522. if ($this->novalnet_payment_method == 'novalnet_invoice' || $this->novalnet_payment_method == 'novalnet_prepayment') { 
  523. $this->invoice_type = strtoupper(substr($this->novalnet_payment_method, strpos($this->novalnet_payment_method, '_') + 1, strlen($this->novalnet_payment_method))); 
  524. $this->invoice_ref = "BNR-" . $this->product_id . "-" . ltrim($order->get_order_number(), __('#', 'hash before order number', 'woocommerce-novalnetpayment')); 
  525. $this->payment_parameters['invoice_type'] = $this->invoice_type; 
  526. $this->payment_parameters['invoice_ref'] = $this->invoice_ref; 
  527.  
  528. } #Endif 
  529.  
  530. if ($this->novalnet_payment_method == 'novalnet_invoice') { 
  531.  
  532. if (is_numeric($this->payment_duration)) { 
  533.  
  534. if ($this->payment_duration > 0) { 
  535. $this->due_date = date("Y-m-d", mktime(0, 0, 0, date("m"), (date("d") + $this->payment_duration), date("Y"))); 
  536. } #Endif  
  537.  
  538. else 
  539. $this->due_date = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d"), date("Y"))); 
  540.  
  541. } #Endif 
  542.  
  543. else 
  544. $this->due_date = ''; 
  545.  
  546. $this->payment_parameters['due_date'] = $this->due_date; 
  547. $this->payment_parameters['end_date'] = $this->due_date; 
  548.  
  549. } #Endif 
  550.  
  551. if ($this->novalnet_payment_method == 'novalnet_paypal') { 
  552. $this->payment_parameters['api_user'] = $this->api_username; 
  553. $this->payment_parameters['api_pw'] = $this->api_password; 
  554. $this->payment_parameters['api_signature'] = $this->api_signature; 
  555. } #Endif 
  556.  
  557. if ($this->novalnet_payment_method == 'novalnet_elv_de' || $this->novalnet_payment_method == 'novalnet_elv_at') { 
  558. $this->payment_parameters['bank_account_holder'] = $_SESSION['bank_account_holder']; 
  559. $this->payment_parameters['bank_account'] = $_SESSION['bank_account']; 
  560. $this->payment_parameters['bank_code'] = $_SESSION['bank_code']; 
  561.  
  562. if ($this->novalnet_payment_method == 'novalnet_elv_de') 
  563. $this->payment_parameters['acdc'] = isset($_SESSION['acdc']) ? 1 : 0; 
  564.  
  565. unset($_SESSION['bank_account_holder']); 
  566. unset($_SESSION['bank_account']); 
  567. unset($_SESSION['bank_code']); 
  568.  
  569. if (isset($_SESSION['acdc'])) 
  570. unset($_SESSION['acdc']); 
  571.  
  572. } #Endif 
  573.  
  574. if ($this->novalnet_payment_method == 'novalnet_cc3d' || $this->novalnet_payment_method == 'novalnet_cc') { 
  575.  
  576. $this->payment_parameters['cc_holder'] = isset($_SESSION['cc_holder']) ? $_SESSION['cc_holder'] : null; 
  577. $this->payment_parameters['cc_no'] = isset($_SESSION['cc_number']) ? $_SESSION['cc_number'] : null; 
  578. $this->payment_parameters['cc_exp_month'] = isset($_SESSION['exp_month']) ? $_SESSION['exp_month'] : null; 
  579. $this->payment_parameters['cc_exp_year'] = isset($_SESSION['exp_year']) ? $_SESSION['exp_year'] : null; 
  580. $this->payment_parameters['cc_cvc2'] = isset($_SESSION['cvv_cvc']) ? $_SESSION['cvv_cvc'] : null; 
  581.  
  582. if ($this->novalnet_payment_method == 'novalnet_cc') { 
  583.  
  584. $this->payment_parameters['unique_id'] = $_SESSION['nn_unique_id']; 
  585. $this->payment_parameters['pan_hash'] = $_SESSION['nn_cardno_id']; 
  586.  
  587. } #Endif 
  588.  
  589. unset($_SESSION['cc_holder']); 
  590. unset($_SESSION['cc_number']); 
  591. unset($_SESSION['exp_month']); 
  592. unset($_SESSION['exp_year']); 
  593. unset($_SESSION['cvv_cvc']); 
  594. unset($_SESSION['nn_unique_id']); 
  595. unset($_SESSION['nn_cardno_id']); 
  596.  
  597. } #Endif 
  598.  
  599. } // End get_backend_additional_parameter_array() 
  600.  
  601. /** 
  602. * Get common payment parameters (for all payment methods) 
  603. */ 
  604. public function get_backend_common_parameter_array($order) { 
  605.  
  606. /** Novalnet common payment parameters */ 
  607. $this->payment_parameters['key'] = $this->payment_key; 
  608. $this->payment_parameters['test_mode'] = $this->test_mode; 
  609. $this->payment_parameters['uniqid'] = $this->unique_id; 
  610. $this->payment_parameters['session'] = session_id(); 
  611. $this->payment_parameters['currency'] = get_woocommerce_currency(); 
  612. $this->payment_parameters['first_name'] = $this->shop_nn_first_name; 
  613. $this->payment_parameters['last_name'] = $this->shop_nn_last_name; 
  614. $this->payment_parameters['gender'] = 'u'; 
  615. $this->payment_parameters['email'] = $this->shop_nn_email; 
  616. $this->payment_parameters['street'] = $order->billing_address_1; 
  617. $this->payment_parameters['search_in_street'] = 1; 
  618. $this->payment_parameters['city'] = $order->billing_city; 
  619. $this->payment_parameters['zip'] = $order->billing_postcode; 
  620. $this->payment_parameters['lang'] = strtoupper($this->language); 
  621. $this->payment_parameters['country'] = $order->billing_country; 
  622. $this->payment_parameters['country_code'] = $order->billing_country; 
  623. $this->payment_parameters['tel'] = $order->billing_phone; 
  624. // $this->payment_parameters['fax'] = ""; 
  625. // $this->payment_parameters['birthday'] = ; 
  626. $this->payment_parameters['remote_ip'] = $this->user_ip; 
  627.  
  628. /** Added support for official Woocommerce Sequential Order nubmer(pro) plugin */ 
  629. $this->payment_parameters['order_no'] = ltrim($order->get_order_number(), __('#', 'hash before order number', 'woocommerce-novalnetpayment')); 
  630. $this->payment_parameters['input1'] = 'nnshop_nr'; 
  631. $this->payment_parameters['inputval1'] = $order->id; 
  632.  
  633. $this->payment_parameters['customer_no'] = $order->user_id > 0 ? $order->user_id : __('Guest', 'woocommerce-novalnetpayment'); 
  634. $this->payment_parameters['use_utf8'] = 1; 
  635. $this->payment_parameters['amount'] = $this->amount; 
  636.  
  637. } // End get_backend_common_parameter_array() 
  638.  
  639. /** 
  640. * process data before payport sever 
  641. */ 
  642. public function do_prepare_to_novalnet_payport($order) { 
  643.  
  644. if (!isset($_SESSION['novalnet_receipt_page_got'])) { 
  645.  
  646. echo '<p>' . __('Thank you for your order, please click the button below to pay with Novalnet.', 'woocommerce-novalnetpayment') . '</p>'; 
  647. echo $this->get_novalnet_form_html($order); 
  648. $_SESSION['novalnet_receipt_page_got'] = 1; 
  649.  
  650. } #Endif 
  651.  
  652. } // End do_prepare_to_novalnet_payport() 
  653.  
  654. /** 
  655. * display error and message 
  656. */  
  657. public function do_check_and_add_novalnet_errors_and_messages($message, $message_type = 'error') { 
  658.  
  659. global $woocommerce; 
  660.  
  661. switch ($message_type) { 
  662. case 'error': 
  663. if (is_object($woocommerce->session)) 
  664. $woocommerce->session->errors = $message; 
  665. else 
  666. $_SESSION['errors'][] = $message; 
  667. $woocommerce->add_error($message); 
  668. break; 
  669. case 'message': 
  670. if (is_object($woocommerce->session)) 
  671. $woocommerce->session->messages = $message; 
  672. else 
  673. $_SESSION['messages'][] = $message; 
  674. $woocommerce->add_message($message); 
  675. break; 
  676. } #Endswitchcase 
  677.  
  678. } // End do_check_and_add_novalnet_errors_and_messages() 
  679.  
  680. /** 
  681. * Validate credit card form fields 
  682. */ 
  683. public function do_validate_cc_form_elements($cc_holder, $cc_number, $exp_month, $exp_year, $cvv_cvc, $cc_type = null, $unique_id = null, $pan_hash = null) { 
  684.  
  685. global $woocommerce; 
  686. $error = ''; 
  687.  
  688. if ($this->novalnet_payment_method == 'novalnet_cc') { 
  689.  
  690. if ($cc_holder == '' || $this->is_invalid_holder_name($cc_holder) || (($exp_month == '' || $exp_year == date('Y')) && $exp_month < date('m')) || $exp_year == '' || $exp_year < date('Y') || $cvv_cvc == '' || strlen($cvv_cvc) < 3 || strlen($cvv_cvc) > 4 || !$this->is_digits($cvv_cvc) || $pan_hash == '' || $unique_id == '') 
  691. $error = true; 
  692.  
  693. if (!$cc_type) 
  694. $error = true;  
  695. } #Endif 
  696.  
  697. elseif ($this->novalnet_payment_method == 'novalnet_cc3d') { 
  698.  
  699. if ($cc_holder == '' || $this->is_invalid_holder_name($cc_holder) || $cc_number == '' || strlen($cc_number) < 12 || !$this->is_digits($cc_number) || (($exp_month == '' || $exp_year == date('Y')) && $exp_month < date('m')) || $exp_year == '' || $exp_year < date('Y') || $cvv_cvc == '' || strlen($cvv_cvc) < 3 || strlen($cvv_cvc) > 4 || !$this->is_digits($cvv_cvc)) 
  700. $error = true; 
  701.  
  702. } #Endelseif 
  703.  
  704. if ($error) { 
  705.  
  706. $this->do_check_and_add_novalnet_errors_and_messages(__('Please enter valid credit card details!', 'woocommerce-novalnetpayment'), 'error'); 
  707. return($this->do_return_redirect_page_for_pay_or_thanks_page('success', $woocommerce->cart->get_checkout_url())); 
  708.  
  709. } #Endif  
  710.  
  711. else { 
  712.  
  713. $_SESSION['cc_holder'] = $cc_holder; 
  714. $_SESSION['cc_number'] = $cc_number; 
  715. $_SESSION['exp_month'] = $exp_month; 
  716. $_SESSION['exp_year'] = $exp_year; 
  717. $_SESSION['cvv_cvc'] = $cvv_cvc; 
  718.  
  719. if ($this->novalnet_payment_method == 'novalnet_cc') { 
  720. $_SESSION['nn_unique_id'] = $unique_id; 
  721. $_SESSION['nn_cardno_id'] = $pan_hash; 
  722. } #Endif 
  723.  
  724. return(''); 
  725.  
  726. } #Endelse 
  727.  
  728. } // End do_validate_cc_form_elements() 
  729.  
  730. /** 
  731. * validate Direct Debit form fields 
  732. */ 
  733. public function do_validate_elv_at_elv_de_form_elements($bank_account_holder, $bank_account, $bank_code, $acdc = '') { 
  734. global $woocommerce; 
  735.  
  736. $error = ''; 
  737.  
  738. if ($bank_account_holder == '' || $this->is_invalid_holder_name($bank_account_holder) || $bank_account == '' || strlen($bank_account) < 5 || !$this->is_digits($bank_account) || $bank_code == '' || strlen($bank_code) < 3 || !$this->is_digits($bank_code)) 
  739. $error = __('Please enter valid account details!', 'woocommerce-novalnetpayment'); 
  740.  
  741. elseif ($this->novalnet_payment_method == 'novalnet_elv_de' && $this->acdc == 'yes' && $acdc == '') 
  742. $error = __('Please enable credit rating check', 'woocommerce-novalnetpayment'); 
  743.  
  744. if ($error) { 
  745. $this->do_check_and_add_novalnet_errors_and_messages($error, 'error'); 
  746. return($this->do_return_redirect_page_for_pay_or_thanks_page('success', $woocommerce->cart->get_checkout_url())); 
  747. } #Endif 
  748.  
  749. else { 
  750.  
  751. $_SESSION['bank_account_holder'] = $bank_account_holder; 
  752. $_SESSION['bank_account'] = $bank_account; 
  753. $_SESSION['bank_code'] = $bank_code; 
  754.  
  755. if (isset($acdc)) 
  756. $_SESSION['acdc'] = $acdc; 
  757.  
  758. return(''); 
  759.  
  760. } #Endelse 
  761.  
  762. } // End do_validate_elv_at_elv_de_form_elements() 
  763.  
  764. /** 
  765. * process novalnet payment methods 
  766. */ 
  767. public function do_process_payment_from_novalnet_payments($order_id) { 
  768. $order = new WC_Order($order_id); 
  769.  
  770. if ($this->novalnet_payment_method == 'novalnet_tel') { 
  771.  
  772. $this->do_necessary_actions_before_prepare_to_novalnet_payport_or_paygate($order); 
  773. $return = $this->do_validate_amount_variations(); 
  774.  
  775. if ($return) 
  776. return($return); 
  777.  
  778. if (empty($_SESSION['novalnet_tel_tid'])) { 
  779. $return = $this->do_validate_amount(); 
  780.  
  781. if ($return) 
  782. return($return); 
  783.  
  784. $aryResponse = $this->do_prepare_to_novalnet_paygate($order); 
  785.  
  786. return($this->do_check_novalnet_tel_payment_status($aryResponse, $order)); 
  787.  
  788. } #Endif  
  789.  
  790. else 
  791. return($this->do_make_second_call_for_novalnet_telephone($order_id)); 
  792. } #Endif  
  793.  
  794. elseif (in_array($this->novalnet_payment_method, $this->return_url_parameter_for_array)) { 
  795.  
  796. if ($this->novalnet_payment_method == 'novalnet_cc3d') { 
  797.  
  798. $return = $this->do_validate_cc_form_elements(trim($_REQUEST['cc3d_holder'], '&'), str_replace(' ', '', $_REQUEST['cc3d_number']), $_REQUEST['cc3d_exp_month'], $_REQUEST['cc3d_exp_year'], str_replace(' ', '', $_REQUEST['cvv_cvc'])); 
  799.  
  800. if ($return) 
  801. return($return); 
  802.  
  803. } #Endif 
  804.  
  805. return($this->do_return_redirect_page_for_pay_or_thanks_page('success', $this->do_build_redirect_url($order, 'pay'))); 
  806.  
  807. } #Endelseif 
  808.  
  809. else { 
  810.  
  811. if ($this->novalnet_payment_method == 'novalnet_cc') { 
  812.  
  813. $return = $this->do_validate_cc_form_elements(trim($_REQUEST['cc_holder'], '&'), null, $_REQUEST['cc_exp_month'], $_REQUEST['cc_exp_year'], str_replace(' ', '', $_REQUEST['cc_cvv_cvc']), $_REQUEST['cc_type'], $_REQUEST['nn_unique_id'], $_REQUEST['nn_cardno_id']); 
  814.  
  815. if ($return) 
  816. return($return); 
  817.  
  818. } #Endif 
  819.  
  820. elseif ($this->novalnet_payment_method == 'novalnet_elv_at') { 
  821.  
  822. $return = $this->do_validate_elv_at_elv_de_form_elements(trim($_REQUEST['bank_account_holder_at'], '&'), str_replace(' ', '', $_REQUEST['bank_account_at']), str_replace(' ', '', $_REQUEST['bank_code_at'])); 
  823.  
  824. if ($return) 
  825. return($return); 
  826.  
  827. } #Endelseif  
  828.  
  829. elseif ($this->novalnet_payment_method == 'novalnet_elv_de') { 
  830.  
  831. $return = $this->do_validate_elv_at_elv_de_form_elements(trim($_REQUEST['bank_account_holder_de'], '&'), str_replace(' ', '', $_REQUEST['bank_account_de']), str_replace(' ', '', $_REQUEST['bank_code_de']), isset($_REQUEST['acdc']) ? $_REQUEST['acdc'] : null); 
  832.  
  833. if ($return) 
  834. return($return); 
  835.  
  836. } #Endelseif 
  837.  
  838. $this->do_necessary_actions_before_prepare_to_novalnet_payport_or_paygate($order); 
  839. $aryResponse = $this->do_prepare_to_novalnet_paygate($order); 
  840. return($this->do_check_novalnet_status($aryResponse)); 
  841.  
  842. } #Endelse 
  843.  
  844. } // End do_process_payment_from_novalnet_payments() 
  845.  
  846. /** 
  847. * get url for direct form payment methods 
  848. */ 
  849. public function do_return_redirect_page_for_pay_or_thanks_page($result, $redirect_url) { 
  850.  
  851. return array( 
  852. 'result' => $result,  
  853. 'redirect' => $redirect_url 
  854. ); 
  855. } // End do_return_redirect_page_for_pay_or_thanks_page() 
  856.  
  857. /** 
  858. * Validate back-end data 
  859. */ 
  860. public function do_check_novalnet_backend_data_validation_from_frontend() { 
  861.  
  862. global $woocommerce; 
  863. $error = ''; 
  864.  
  865. if (!$this->vendor_id || !$this->product_id || !$this->tariff_id || !$this->auth_code || (isset($this->key_password) && !$this->key_password) || (isset($this->api_username) && !$this->api_username) || (isset($this->api_password) && !$this->api_password) || (isset($this->api_signature) && !$this->api_signature)) 
  866. $error = __('Basic Parameter Missing', 'woocommerce-novalnetpayment'); 
  867.  
  868. if (isset($this->manual_check_limit) && $this->manual_check_limit > 0) { 
  869.  
  870. if (empty($this->product_id_2) || empty($this->tariff_id_2)) 
  871. $error = __('Product-ID2 and/or Tariff-ID2 missing!', 'woocommerce-novalnetpayment'); 
  872.  
  873. } #Endif 
  874.  
  875. if ($error) { 
  876.  
  877. $this->do_check_and_add_novalnet_errors_and_messages($error, 'error'); 
  878. wp_safe_redirect($woocommerce->cart->get_checkout_url()); 
  879. exit(); 
  880.  
  881. } #Endif 
  882.  
  883. } // End do_check_novalnet_backend_data_validation_from_frontend() 
  884.  
  885. /** 
  886. * build redirect url for direct form payment methods 
  887. */ 
  888. public function do_build_redirect_url($order, $page) { 
  889.  
  890. return(add_query_arg('order', $order->id, add_query_arg('key', $order->order_key, get_permalink(woocommerce_get_page_id($page))))); 
  891. }  
  892. // End do_build_redirect_url() 
  893.  
  894. /** 
  895. * Get pci compliant secure credit card form from Novalnet server  
  896. */ 
  897. public function do_check_is_any_request_to_print_cc_iframe() { 
  898.  
  899. if ($this->novalnet_payment_method == 'novalnet_cc' && isset($_SERVER['HTTP_REFERER']) && !strstr($_SERVER['HTTP_REFERER'], 'wp-admin')) { 
  900.  
  901. $this->payport_or_paygate_form_display = $this->payment_details['novalnet_cc']['payport_or_paygate_form_display']; 
  902.  
  903. $form_parameters = array( 
  904. 'nn_lang_nn' => strtoupper($this->language),  
  905. 'nn_vendor_id_nn' => $this->vendor_id,  
  906. 'nn_product_id_nn' => $this->product_id,  
  907. 'nn_payment_id_nn' => $this->payment_key 
  908. ); 
  909.  
  910. list($errno, $errmsg, $data) = $this->perform_https_request($this->payport_or_paygate_form_display, $form_parameters); 
  911.  
  912. file_put_contents(ABSPATH . '/wp-content/plugins/woocommerce-novalnet-gateway/includes/novalnet_cc_iframe.html', $data); 
  913.  
  914. } #Endif 
  915.  
  916. } // End do_check_is_any_request_to_print_cc_iframe() 
  917.  
  918. /** 
  919. * Display direct debit form fields 
  920. */ 
  921. public function do_print_form_elements_for_novalnet_elv_de_at($suffix) { 
  922.  
  923. $payment_field_html = '<div> </div><div> 
  924. <div style="float:left;width:50%;">' . __('Account holder', 'woocommerce-novalnetpayment') . ':<span style="color:red;">*</span></div> 
  925. <div style="float:left;width:50%;"><input type="text" name="bank_account_holder_' . $suffix . '" id="bank_account_holder_' . $suffix . '" value="" autocomplete="off" /></div> 
  926. <div style="clear:both;"> </div> 
  927. <div style="float:left;width:50%;">' . __('Account number', 'woocommerce-novalnetpayment') . ':<span style="color:red;">*</span></div> 
  928. <div style="float:left;width:50%;"><input type="text" name="bank_account_' . $suffix . '" id="bank_account_' . $suffix . '" value="" autocomplete="off" /></div> 
  929. <div style="clear:both;"> </div> 
  930. <div style="float:left;width:50%;">' . __('Bankcode', 'woocommerce-novalnetpayment') . ':<span style="color:red;">*</span></div> 
  931. <div style="float:left;width:50%;"><input type="text" name="bank_code_' . $suffix . '" id="bank_code_' . $suffix . '" value="" autocomplete="off" /></div>'; 
  932.  
  933. if ($suffix == 'de' && $this->acdc == 'yes') { 
  934. $payment_field_html.=' 
  935. <div style="clear:both;"> </div> 
  936. <div style="float:left;width:50%;"><a id="acdc_link" href="javascript:show_acdc_info();" onclick="show_acdc_info();">' . __('Your credit rating is checked by us', 'woocommerce-novalnetpayment') . '</a>:<span style="color:red;">*</span></div> 
  937. <div style="float:left;width:50%;"><input type="checkbox" name="acdc" id="acdc" class="inputbox" value="1" /></div> 
  938. <script type="text/javascript" language="javascript"> 
  939. function show_acdc_info() { 
  940. urlpopup="' . (is_ssl() ? 'https://www.novalnet.de/img/acdc_info.png' : 'http://www.novalnet.de/img/acdc_info.png') . '"; 
  941. w="550";h="300"; 
  942. x=250;y=100;  
  943. //x=screen.availWidth/2-w/2;y=screen.availHeight/2-h/2;  
  944. showbaby=window.open(urlpopup, "showbaby", "toolbar=0, location=0, directories=0, status=0, menubar=0, resizable=1, width="+w+", height="+h+", left="+x+", top="+y+", screenX="+x+", screenY="+y); 
  945. showbaby.focus();  
  946. </script> 
  947. '; 
  948. } #Endif 
  949.  
  950. $payment_field_html.='<div style="clear:both;"> </div></div>'; 
  951.  
  952. return($payment_field_html); 
  953.  
  954. } // End do_print_form_elements_for_novalnet_elv_de_at() 
  955.  
  956. /** 
  957. * validate novalnet configuration parameter 
  958. */ 
  959. public function novalnet_backend_validation_from_backend($request) { 
  960.  
  961. /** Get woocommerce Novalnet configuration settings */ 
  962. $vendor_id = $request['woocommerce_' . $this->novalnet_payment_method . '_merchant_id']; 
  963. $auth_code = $request['woocommerce_' . $this->novalnet_payment_method . '_auth_code']; 
  964. $product_id = $request['woocommerce_' . $this->novalnet_payment_method . '_product_id']; 
  965. $tariff_id = $request['woocommerce_' . $this->novalnet_payment_method . '_tariff_id']; 
  966. $payment_duration = isset($request['woocommerce_' . $this->novalnet_payment_method . '_payment_duration']) ? $request['woocommerce_' . $this->novalnet_payment_method . '_payment_duration'] : null; 
  967. $key_password = isset($request['woocommerce_' . $this->novalnet_payment_method . '_key_password']) ? $request['woocommerce_' . $this->novalnet_payment_method . '_key_password'] : null; 
  968. $api_username = isset($request['woocommerce_' . $this->novalnet_payment_method . '_api_username']) ? $request['woocommerce_' . $this->novalnet_payment_method . '_api_username'] : null; 
  969. $api_password = isset($request['woocommerce_' . $this->novalnet_payment_method . '_api_password']) ? $request['woocommerce_' . $this->novalnet_payment_method . '_api_password'] : null; 
  970. $api_signature = isset($request['woocommerce_' . $this->novalnet_payment_method . '_api_signature']) ? $request['woocommerce_' . $this->novalnet_payment_method . '_api_signature'] : null; 
  971. $manual_check_limit = isset($request['woocommerce_' . $this->novalnet_payment_method . '_manual_check_limit']) ? $request['woocommerce_' . $this->novalnet_payment_method . '_manual_check_limit'] : null; 
  972. $product_id_2 = isset($request['woocommerce_' . $this->novalnet_payment_method . '_product_id_2']) ? $request['woocommerce_' . $this->novalnet_payment_method . '_product_id_2'] : null; 
  973. $tariff_id_2 = isset($request['woocommerce_' . $this->novalnet_payment_method . '_tariff_id_2']) ? $request['woocommerce_' . $this->novalnet_payment_method . '_tariff_id_2'] : null; 
  974.  
  975. /** woocommerce Novalnet configuration validation */ 
  976. foreach ($this->language_supported_array as $language) { 
  977.  
  978. if (!$request['woocommerce_' . $this->novalnet_payment_method . '_title_' . $language]) 
  979. return(__('Please enter valid Payment Title', 'woocommerce-novalnetpayment')); 
  980.  
  981. } #Endforeach 
  982.  
  983. if (isset($vendor_id) && !$vendor_id) 
  984. return(__('Please enter valid Novalnet Merchant ID', 'woocommerce-novalnetpayment')); 
  985.  
  986. if (isset($auth_code) && !$auth_code) 
  987. return(__('Please enter valid Novalnet Merchant Authorisation code', 'woocommerce-novalnetpayment')); 
  988.  
  989. if (isset($product_id) && (!$product_id || !$this->is_digits($product_id))) 
  990. return(__('Please enter valid Novalnet Product ID', 'woocommerce-novalnetpayment')); 
  991.  
  992. if (isset($tariff_id) && (!$tariff_id || !$this->is_digits($tariff_id))) 
  993. return(__('Please enter valid Novalnet Tariff ID', 'woocommerce-novalnetpayment')); 
  994.  
  995. if (isset($payment_duration) && $payment_duration && !$this->is_digits($payment_duration)) 
  996. return(__('Please enter valid Payment period in days', 'woocommerce-novalnetpayment')); 
  997.  
  998. if (isset($key_password) && !$key_password) 
  999. return(__('Please enter valid Novalnet Payment access key', 'woocommerce-novalnetpayment')); 
  1000.  
  1001. if (isset($api_username) && !$api_username) 
  1002. return(__('Please enter valid PayPal API username', 'woocommerce-novalnetpayment')); 
  1003.  
  1004. if (isset($api_password) && !$api_password) 
  1005. return(__('Please enter valid PayPal API password', 'woocommerce-novalnetpayment')); 
  1006.  
  1007. if (isset($api_signature) && !$api_signature) 
  1008. return(__('Please enter valid PayPal API signature', 'woocommerce-novalnetpayment')); 
  1009.  
  1010. if (isset($manual_check_limit) && $manual_check_limit && !$this->is_digits($manual_check_limit)) 
  1011. return(__('Please enter valid Manual checking amount', 'woocommerce-novalnetpayment')); 
  1012.  
  1013. if (isset($manual_check_limit) && $manual_check_limit && $this->is_digits($manual_check_limit)) { 
  1014.  
  1015. if (isset($product_id_2) && (!$product_id_2 || !$this->is_digits($product_id_2))) 
  1016. return(__('Please enter valid Novalnet Second Product ID', 'woocommerce-novalnetpayment')); 
  1017.  
  1018. if (isset($tariff_id_2) && (!$tariff_id_2 || !$this->is_digits($tariff_id_2))) 
  1019. return(__('Please enter valid Novalnet Second Tariff ID', 'woocommerce-novalnetpayment')); 
  1020.  
  1021. } #Endif  
  1022.  
  1023. if (isset($tariff_id_2) && $tariff_id_2 && !$this->is_digits($tariff_id_2)) 
  1024. return(__('Please enter valid Novalnet Second Tariff ID', 'woocommerce-novalnetpayment')); 
  1025.  
  1026. if (isset($product_id_2) && $product_id_2 && !$this->is_digits($product_id_2)) 
  1027. return(__('Please enter valid Novalnet Second Product ID', 'woocommerce-novalnetpayment')); 
  1028. return(''); 
  1029.  
  1030. } // End novalnet_backend_validation_from_backend() 
  1031.  
  1032. /** 
  1033. * Validate payment gateway settings 
  1034. */ 
  1035. public function do_check_novalnet_backend_data_validation_from_backend($request) { 
  1036.  
  1037. if (isset($request['save']) && isset($request['subtab']) && ($request['subtab'] == '#gateway-' . $this->novalnet_payment_method || isset($request['section']) && $request['section'] == $this->novalnet_payment_method)) { 
  1038.  
  1039. $is_backend_error = $this->novalnet_backend_validation_from_backend($request); 
  1040.  
  1041. if ($is_backend_error) { 
  1042.  
  1043. $redirect = get_admin_url() . 'admin.php?' . http_build_query($_GET); 
  1044. $redirect = remove_query_arg('saved'); 
  1045. $redirect = add_query_arg('wc_error', urlencode(esc_attr($is_backend_error)), $redirect); 
  1046.  
  1047. if (!empty($request['subtab'])) 
  1048. $redirect = add_query_arg('subtab', esc_attr(str_replace('#', '', $request['subtab'])), $redirect); 
  1049. wp_safe_redirect($redirect); 
  1050. exit(); 
  1051.  
  1052. } #Endif 
  1053.  
  1054. } #Endif  
  1055.  
  1056. elseif (isset($request['saved']) && isset($_GET['wc_error'])) { 
  1057.  
  1058. $redirect = get_admin_url() . 'admin.php?' . http_build_query($_GET); 
  1059. $redirect = remove_query_arg('wc_error'); 
  1060. $redirect = add_query_arg('saved', urlencode(esc_attr('true')), $redirect); 
  1061. wp_safe_redirect($redirect); 
  1062. exit(); 
  1063.  
  1064. } #Endelseif 
  1065.  
  1066. } // End do_check_novalnet_backend_data_validation_from_backend() 
  1067.  
  1068. /** 
  1069. * Initialize language for payment methods 
  1070. */ 
  1071. public function do_initialize_novalnet_language() { 
  1072.  
  1073. $language_locale = get_bloginfo('language'); 
  1074. $this->language = strtoupper(substr($language_locale, 0, 2)) ? strtoupper(substr($language_locale, 0, 2)) : 'en'; 
  1075. $this->language = in_array(strtolower($this->language), $this->language_supported_array) ? $this->language : 'en'; 
  1076.  
  1077. } // End do_initialize_novalnet_language() 
  1078.  
  1079. /** 
  1080. * trim server resonse 
  1081. */ 
  1082. public function do_trim_array_values(&$array) { 
  1083.  
  1084. if (isset($array) && is_array($array)) 
  1085.  
  1086. foreach ($array as $key => $val) { 
  1087. if (!is_array($val)) 
  1088. $array[$key] = trim($val); 
  1089. } #Endforeach 
  1090.  
  1091. } // End do_trim_array_values() 
  1092.  
  1093. /** 
  1094. * set-up configuration details for payment methods 
  1095. */ 
  1096. public function do_make_payment_details_array() { 
  1097.  
  1098. $this->payment_details = array( 
  1099.  
  1100. /** Novalnet BankTransfer Payment Method */ 
  1101. 'novalnet_banktransfer' => array( 
  1102. 'payment_key' => $this->payment_key_for_online_transfer,  
  1103. 'payport_or_paygate_url' => $this->novalnet_online_transfer_payport_url,  
  1104. 'second_call_url' => '',  
  1105. 'payment_name' => __('Instant Bank Transfer', 'woocommerce-novalnetpayment'),  
  1106. 'payment_logo' => __('www.novalnet.de/img/sofort_Logo_en.png', 'woocommerce-novalnetpayment') 
  1107. ),  
  1108.  
  1109. /** Novalnet Credit Card Payment Method */ 
  1110. 'novalnet_cc' => array( 
  1111. 'payment_key' => $this->payment_key_for_cc_family,  
  1112. 'payport_or_paygate_url' => $this->novalnet_paygate_url,  
  1113. 'payport_or_paygate_form_display' => $this->novalnet_cc_form_display_url,  
  1114. 'second_call_url' => '',  
  1115. 'payment_name' => __('Credit Card', 'woocommerce-novalnetpayment'),  
  1116. 'payment_logo' => __('www.novalnet.de/img/creditcard_small.jpg', 'woocommerce-novalnetpayment') 
  1117. ),  
  1118.  
  1119. /** Novalnet Credit Card 3D Secure Payment Method */ 
  1120. 'novalnet_cc3d' => array( 
  1121. 'payment_key' => $this->payment_key_for_cc_family,  
  1122. 'payport_or_paygate_url' => $this->novlanet_cc3d_payport_url,  
  1123. 'second_call_url' => '',  
  1124. 'payment_name' => __('Credit Card 3D Secure', 'woocommerce-novalnetpayment'),  
  1125. 'payment_logo' => __('www.novalnet.de/img/creditcard_small.jpg', 'woocommerce-novalnetpayment') 
  1126. ),  
  1127.  
  1128. /** Novalnet Direct Debit Austria Payment Method */ 
  1129. 'novalnet_elv_at' => array( 
  1130. 'payment_key' => $this->payment_key_for_at_family,  
  1131. 'payport_or_paygate_url' => $this->novalnet_paygate_url,  
  1132. 'second_call_url' => '',  
  1133. 'payment_name' => __('Direct Debit Austria', 'woocommerce-novalnetpayment'),  
  1134. 'payment_logo' => __('www.novalnet.de/img/ELV_Logo.png', 'woocommerce-novalnetpayment') 
  1135. ),  
  1136.  
  1137. /** Novalnet Direct Debit German Payment Method */ 
  1138. 'novalnet_elv_de' => array( 
  1139. 'payment_key' => $this->payment_key_for_de_family,  
  1140. 'payport_or_paygate_url' => $this->novalnet_paygate_url,  
  1141. 'second_call_url' => '',  
  1142. 'payment_name' => __('Direct Debit German', 'woocommerce-novalnetpayment'),  
  1143. 'payment_logo' => __('www.novalnet.de/img/ELV_Logo.png', 'woocommerce-novalnetpayment') 
  1144. ),  
  1145.  
  1146. /** Novalnet iDEAL Payment Method */ 
  1147. 'novalnet_ideal' => array( 
  1148. 'payment_key' => $this->payment_key_for_ideal,  
  1149. 'payport_or_paygate_url' => $this->novalnet_online_transfer_payport_url,  
  1150. 'second_call_url' => '',  
  1151. 'payment_name' => __('iDEAL', 'woocommerce-novalnetpayment'),  
  1152. 'payment_logo' => __('www.novalnet.de/img/ideal_payment_small.png', 'woocommerce-novalnetpayment') 
  1153. ),  
  1154.  
  1155. /** Novalnet Invoice Payment Method */ 
  1156. 'novalnet_invoice' => array( 
  1157. 'payment_key' => $this->payment_key_for_invoice_prepayment,  
  1158. 'payport_or_paygate_url' => $this->novalnet_paygate_url,  
  1159. 'second_call_url' => '',  
  1160. 'payment_name' => __('Invoice', 'woocommerce-novalnetpayment'),  
  1161. 'payment_logo' => __('www.novalnet.de/img/kauf-auf-rechnung.jpg', 'woocommerce-novalnetpayment') 
  1162. ),  
  1163.  
  1164. /** Novalnet PayPal Payment Method */ 
  1165. 'novalnet_paypal' => array( 
  1166. 'payment_key' => $this->payment_key_for_paypal,  
  1167. 'payport_or_paygate_url' => $this->novlanet_paypal_payport_url,  
  1168. 'second_call_url' => '',  
  1169. 'payment_name' => __('PayPal', 'woocommerce-novalnetpayment'),  
  1170. 'payment_logo' => __('www.novalnet.de/img/paypal-small.png', 'woocommerce-novalnetpayment') 
  1171. ),  
  1172.  
  1173. /** Novalnet Prepayment Payment Method */ 
  1174. 'novalnet_prepayment' => array( 
  1175. 'payment_key' => $this->payment_key_for_invoice_prepayment,  
  1176. 'payport_or_paygate_url' => $this->novalnet_paygate_url,  
  1177. 'second_call_url' => '',  
  1178. 'payment_name' => __('Prepayment', 'woocommerce-novalnetpayment'),  
  1179. 'payment_logo' => __('www.novalnet.de/img/vorauskasse.jpg', 'woocommerce-novalnetpayment') 
  1180. ),  
  1181.  
  1182. /** Novalnet Telephone Payment Method */ 
  1183. 'novalnet_tel' => array( 
  1184. 'payment_key' => $this->payment_key_for_tel,  
  1185. 'payport_or_paygate_url' => $this->novalnet_paygate_url,  
  1186. 'second_call_url' => $this->novlanet_tel_second_call_url,  
  1187. 'payment_name' => __('Telephone Payment', 'woocommerce-novalnetpayment'),  
  1188. 'payment_logo' => __('www.novalnet.de/img/novaltel_logo.png', 'woocommerce-novalnetpayment') 
  1189. ); 
  1190.  
  1191. } // End do_make_payment_details_array() 
  1192.  
  1193. /** 
  1194. * Assign variables to payment parameters 
  1195. */ 
  1196. public function do_assign_config_vars_to_members() { 
  1197.  
  1198. // trim settigns array 
  1199. $this->do_trim_array_values($this->settings); 
  1200.  
  1201. $this->do_make_payment_details_array(); 
  1202.  
  1203. /** assign basic configuration parameters */ 
  1204. $this->test_mode = $this->settings['test_mode']; 
  1205. $this->vendor_id = $this->settings['merchant_id']; 
  1206. $this->auth_code = $this->settings['auth_code']; 
  1207. $this->product_id = $this->settings['product_id']; 
  1208. $this->tariff_id = $this->settings['tariff_id']; 
  1209. $this->payment_key = $this->payment_details[$this->novalnet_payment_method]['payment_key']; 
  1210.  
  1211. /** assign payment url for each payment methods */ 
  1212. $this->payport_or_paygate_url = $this->payment_details[$this->novalnet_payment_method]['payport_or_paygate_url']; 
  1213. $this->second_call_url = $this->payment_details[$this->novalnet_payment_method]['second_call_url']; 
  1214.  
  1215. /** assign additional configuration parameters */ 
  1216. if (isset($this->settings['key_password']) && $this->settings['key_password']) 
  1217. $this->key_password = $this->settings['key_password']; 
  1218.  
  1219. if (isset($this->settings['acdc']) && $this->settings['acdc']) 
  1220. $this->acdc = $this->settings['acdc']; 
  1221.  
  1222. if (isset($this->settings['payment_duration'])) 
  1223. $this->payment_duration = $this->settings['payment_duration']; 
  1224.  
  1225. if (isset($this->settings['manual_check_limit']) && $this->settings['manual_check_limit']) 
  1226. $this->manual_check_limit = str_replace(array(' ', ', ', '.'), '', $this->settings['manual_check_limit']); 
  1227.  
  1228. if (isset($this->settings['product_id_2']) && $this->settings['product_id_2']) 
  1229. $this->product_id_2 = $this->settings['product_id_2']; 
  1230.  
  1231. if (isset($this->settings['tariff_id_2']) && $this->settings['tariff_id_2']) 
  1232. $this->tariff_id_2 = $this->settings['tariff_id_2']; 
  1233.  
  1234. if (isset($this->settings['api_username']) && $this->settings['api_username']) 
  1235. $this->api_username = $this->settings['api_username']; 
  1236.  
  1237. if (isset($this->settings['api_password']) && $this->settings['api_password']) 
  1238. $this->api_password = $this->settings['api_password']; 
  1239.  
  1240. if (isset($this->settings['api_signature']) && $this->settings['api_signature']) 
  1241. $this->api_signature = $this->settings['api_signature']; 
  1242.  
  1243. $this->unique_id = uniqid(); 
  1244. $this->method_title = $this->payment_details[$this->novalnet_payment_method]['payment_name']; 
  1245. $this->title = $this->settings['title_' . strtolower($this->language)]; 
  1246. $this->description = $this->settings['description_' . strtolower($this->language)]; 
  1247. $this->payment_logo = $this->settings['payment_logo']; 
  1248. $this->icon = (is_ssl() ? 'https://' : 'http://') . $this->payment_details[$this->novalnet_payment_method]['payment_logo']; 
  1249.  
  1250. } // End do_assign_config_vars_to_members() 
  1251.  
  1252. /** 
  1253. * Validate account digits 
  1254. */ 
  1255. public function is_digits($element) { 
  1256.  
  1257. return(preg_match("/^[0-9]+$/", $element)); 
  1258. } // End is_digits() 
  1259.  
  1260. /** 
  1261. * Validate account holder name 
  1262. */ 
  1263. public function is_invalid_holder_name($element) { 
  1264.  
  1265. return preg_match("/[#%\^<>@$=*!]/", $element); 
  1266. } // End is_invalid_holder_name() 
  1267.  
  1268. /** 
  1269. * Format amount in cents 
  1270. */ 
  1271. public function do_format_amount($amount) { 
  1272.  
  1273. $this->amount = str_replace(', ', '', number_format($amount, 2)) * 100; 
  1274. } // End do_format_amount() 
  1275.  
  1276. /** 
  1277. * Assign Manual Check-Limit  
  1278. */ 
  1279. public function do_check_and_assign_manual_check_limit() { 
  1280.  
  1281. if (isset($this->manual_check_limit) && $this->manual_check_limit && $this->amount >= $this->manual_check_limit) { 
  1282.  
  1283. if ($this->product_id_2 && $this->tariff_id_2) { 
  1284. $this->product_id = $this->product_id_2; 
  1285. $this->tariff_id = $this->tariff_id_2; 
  1286. } #Endif 
  1287.  
  1288. } #Endif 
  1289. } // End do_check_and_assign_manual_check_limit() 
  1290.  
  1291. /** 
  1292. * Get Server Response message 
  1293. */ 
  1294. public function do_get_novalnet_response_text($request) { 
  1295.  
  1296. return(isset($request['status_text']) ? $request['status_text'] : (isset($request['status_desc']) ? $request['status_desc'] : __('Successful', 'woocommerce-novalnetpayment'))); 
  1297.  
  1298. } // End do_get_novalnet_response_text() 
  1299.  
  1300. /** 
  1301. * Successful payment 
  1302. */ 
  1303. public function do_novalnet_success($request, $message) { 
  1304.  
  1305. global $woocommerce; 
  1306.  
  1307. // trim request array 
  1308. $this->do_trim_array_values($request);  
  1309.  
  1310. $order_no = $request['inputval1'];  
  1311. $woo_seq_nr = $request['order_no']; 
  1312.  
  1313. if (in_array($this->novalnet_payment_method, $this->encode_applicable_for_array)) 
  1314. $request['test_mode'] = $this->decode($request['test_mode']);  
  1315.  
  1316. if($this->novalnet_payment_method == 'novalnet_cc3d') { 
  1317. $this->amount = $request['amount']; 
  1318. $this->do_check_and_assign_manual_check_limit();  
  1319. } #Endif 
  1320.  
  1321. $order = new WC_Order($order_no); 
  1322.  
  1323. /** add Novalnet Transaction details to order notes */ 
  1324. $new_line = "\n"; 
  1325. $novalnet_comments = $new_line . $this->title . $new_line; 
  1326. $novalnet_comments .= __('Novalnet Transaction ID', 'woocommerce-novalnetpayment') . ': ' . $request['tid'] . $new_line; 
  1327. $novalnet_comments .= ((isset($request['test_mode']) && $request['test_mode'] == 1) || (isset($this->test_mode) && $this->test_mode == 1)) ? __('Test order', 'woocommerce-novalnetpayment') : ''; 
  1328.  
  1329. /** add additional information for Prepayment and Invoice order */ 
  1330. if ($this->novalnet_payment_method == 'novalnet_invoice' || $this->novalnet_payment_method == 'novalnet_prepayment') { 
  1331.  
  1332. $novalnet_comments .= $request['test_mode'] ? $new_line . $new_line : $new_line; 
  1333. $novalnet_comments .= __('Please transfer the amount to the following information to our payment service Novalnet AG', 'woocommerce-novalnetpayment') . $new_line; 
  1334. if ($this->novalnet_payment_method == 'novalnet_invoice' && is_numeric($this->payment_duration)) 
  1335. $novalnet_comments.= __('Due date', 'woocommerce-novalnetpayment') . " : " . date_i18n(get_option('date_format'), strtotime($this->due_date)) . $new_line;  
  1336. $novalnet_comments.= __('Account holder : Novalnet AG', 'woocommerce-novalnetpayment') . $new_line; 
  1337. $novalnet_comments.= __('Account number', 'woocommerce-novalnetpayment') . " : " . $request['invoice_account'] . $new_line; 
  1338. $novalnet_comments.= __('Bankcode', 'woocommerce-novalnetpayment') . " : " . $request['invoice_bankcode'] . $new_line; 
  1339. $novalnet_comments.= __('Bank', 'woocommerce-novalnetpayment') . " : " . $request['invoice_bankname'] . " " . trim($request['invoice_bankplace']) . $new_line; 
  1340. $novalnet_comments.= __('Amount', 'woocommerce-novalnetpayment') . " : " . strip_tags($order->get_formatted_order_total()) . $new_line; 
  1341. $novalnet_comments.= __('Reference : TID', 'woocommerce-novalnetpayment') . " " . $request['tid'] . $new_line . $new_line; 
  1342. $novalnet_comments.= __('Only for international transfers :', 'woocommerce-novalnetpayment') . $new_line; 
  1343. $novalnet_comments.= __('IBAN', 'woocommerce-novalnetpayment') . " : " . $request['invoice_iban'] . $new_line; 
  1344. $novalnet_comments.= __('SWIFT / BIC', 'woocommerce-novalnetpayment') . " : " . $request['invoice_bic'] . $new_line; 
  1345.  
  1346. } #Endif 
  1347.  
  1348. if ($order->customer_note) 
  1349. $order->customer_note.= $new_line; 
  1350.  
  1351. if ($this->novalnet_payment_method == 'novalnet_invoice' || $this->novalnet_payment_method == 'novalnet_prepayment') { 
  1352.  
  1353. $order->customer_note .= html_entity_decode($novalnet_comments, ENT_QUOTES, 'UTF-8'); 
  1354.  
  1355. if (version_compare($woocommerce->version, '2.0.0', '<')) 
  1356. $order->customer_note = utf8_encode($order->customer_note); 
  1357.  
  1358. } #Endif 
  1359.  
  1360. else 
  1361. $order->customer_note .= html_entity_decode($novalnet_comments, ENT_QUOTES, 'UTF-8'); 
  1362.  
  1363. /** Update Novalnet Transaction details into shop database */ 
  1364. $nn_order_notes = array( 
  1365. 'ID' => $order_no,  
  1366. 'post_excerpt' => $order->customer_note 
  1367. ); 
  1368. wp_update_post($nn_order_notes); 
  1369.  
  1370. // adds order note 
  1371. $order->add_order_note($order->customer_note); 
  1372.  
  1373. if (isset($request['novalnet_payment_method']) && isset($request['status']) && $request['novalnet_payment_method'] == 'novalnet_paypal' && $request['status'] == 90) { 
  1374.  
  1375. // Empty awaiting payment session 
  1376. if (!empty($woocommerce->session->order_awaiting_payment)) 
  1377. unset($woocommerce->session->order_awaiting_payment); 
  1378.  
  1379. $nn_order_status = $this->order_status; 
  1380.  
  1381. apply_filters('woocommerce_payment_complete_order_status', $nn_order_status, $order_no); 
  1382.  
  1383. // Update order status 
  1384. $order->update_status($nn_order_status, $message); 
  1385.  
  1386. add_post_meta($order_no, '_paid_date', current_time('mysql'), true); 
  1387.  
  1388. $nn_order = array( 
  1389. 'ID' => $order_no,  
  1390. 'post_date' => current_time('mysql', 0),  
  1391. 'post_date_gmt' => current_time('mysql', 1) 
  1392. ); 
  1393. wp_update_post($nn_order); 
  1394.  
  1395. if (apply_filters('woocommerce_payment_complete_reduce_order_stock', true, $order_no)) 
  1396.  
  1397. // Reduce stock levels 
  1398. $order->reduce_order_stock(); 
  1399.  
  1400. do_action('woocommerce_payment_complete', $order_no); 
  1401.  
  1402. } #Endif 
  1403.  
  1404. else  
  1405. // make the payment complete 
  1406. $order->payment_complete(); 
  1407.  
  1408. // Remove cart 
  1409. $woocommerce->cart->empty_cart(); 
  1410.  
  1411. // send acknoweldgement call to Novalnet server 
  1412. $this->post_back_param($request, $woo_seq_nr); 
  1413.  
  1414. // successful message display 
  1415. $this->do_check_and_add_novalnet_errors_and_messages($message, 'message'); 
  1416.  
  1417. // Clears the Novalnet Telephone payment session 
  1418. $this->do_unset_novalnet_telephone_sessions(); 
  1419.  
  1420. // Return thankyou redirect 
  1421. if (in_array($this->novalnet_payment_method, $this->return_url_parameter_for_array)) { 
  1422.  
  1423. wp_safe_redirect(add_query_arg('key', $order->order_key, add_query_arg('order', $order_no, get_permalink(woocommerce_get_page_id('thanks'))))); 
  1424. exit(); 
  1425.  
  1426. } #Endif  
  1427.  
  1428. else 
  1429. return($this->do_return_redirect_page_for_pay_or_thanks_page('success', $this->do_build_redirect_url($order, 'thanks'))); 
  1430.  
  1431. } // End do_novalnet_success() 
  1432.  
  1433. /** 
  1434. * Order Cancellation 
  1435. */ 
  1436. public function do_novalnet_cancel($request, $message) { 
  1437.  
  1438. global $woocommerce; 
  1439.  
  1440. // trim request array 
  1441. $this->do_trim_array_values($request); 
  1442.  
  1443. $order_no = $request['inputval1'];  
  1444. $order = new WC_Order($order_no); 
  1445.  
  1446. $new_line = "\n"; 
  1447. $novalnet_comments = $this->title . $new_line; 
  1448. $novalnet_comments .= $message . $new_line; 
  1449.  
  1450. if ($order->customer_note) 
  1451. $order->customer_note .= $new_line; 
  1452.  
  1453. $order->customer_note .= html_entity_decode($novalnet_comments, ENT_QUOTES, 'UTF-8'); 
  1454.  
  1455. /** Update order cancellation details into database */ 
  1456. $nn_order_notes = array( 
  1457. 'ID' => $order_no,  
  1458. 'post_excerpt' => $order->customer_note 
  1459. ); 
  1460. wp_update_post($nn_order_notes); 
  1461.  
  1462. // adds order note 
  1463. $order->add_order_note($order->customer_note); 
  1464.  
  1465. // Cancel the order 
  1466. $order->cancel_order($message); 
  1467.  
  1468. // Order cancellation message display 
  1469. do_action('woocommerce_cancelled_order', $order_no); 
  1470. $this->do_check_and_add_novalnet_errors_and_messages($message, 'error'); 
  1471.  
  1472. // clears telephone payment session 
  1473. $this->do_unset_novalnet_telephone_sessions(); 
  1474.  
  1475. if (in_array($this->novalnet_payment_method, $this->return_url_parameter_for_array)) { 
  1476. wp_safe_redirect($woocommerce->cart->get_checkout_url()); 
  1477. exit(); 
  1478. } #Endif 
  1479. else 
  1480. return($this->do_return_redirect_page_for_pay_or_thanks_page('success', $woocommerce->cart->get_checkout_url())); 
  1481.  
  1482. } // End do_novalnet_cancel() 
  1483.  
  1484. /** 
  1485. * Transfer data via curl library (consists of various protocols) 
  1486. */ 
  1487. public function perform_https_request($url, $form) { 
  1488.  
  1489. global $globaldebug; 
  1490.  
  1491. if ($globaldebug) 
  1492. print "<BR>perform_https_request: $url<BR>\n\r\n"; 
  1493. if ($globaldebug) 
  1494. print "perform_https_request: $form<BR>\n\r\n"; 
  1495.  
  1496. ## some prerquisites for the connection 
  1497. $ch = curl_init($url); 
  1498.  
  1499. // a non-zero parameter tells the library to do a regular HTTP post. 
  1500. curl_setopt($ch, CURLOPT_POST, 1); 
  1501.  
  1502. // add POST fields  
  1503. curl_setopt($ch, CURLOPT_POSTFIELDS, $form);  
  1504.  
  1505. // don't allow redirects 
  1506. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); 
  1507.  
  1508. // decomment it if you want to have effective ssl checking 
  1509. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
  1510.  
  1511. // decomment it if you want to have effective ssl checking 
  1512. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
  1513.  
  1514. // return into a variable 
  1515. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
  1516.  
  1517. // maximum time, in seconds, that you'll allow the CURL functions to take 
  1518. curl_setopt($ch, CURLOPT_TIMEOUT, 240); 
  1519.  
  1520. // payment proxy 
  1521. if (isset($this->payment_proxy)) 
  1522. curl_setopt($ch, CURLOPT_PROXY, $this->payment_proxy); 
  1523.  
  1524. ## establish connection 
  1525. $data = curl_exec($ch); 
  1526.  
  1527. ## determine if there were some problems on cURL execution 
  1528. $errno = curl_errno($ch); 
  1529. $errmsg = curl_error($ch); 
  1530.  
  1531. ###bug fix for PHP 4.1.0/4.1.2 (curl_errno() returns high negative value in case of successful termination) 
  1532. if ($errno < 0) 
  1533. $errno = 0; 
  1534.  
  1535. ##bug fix for PHP 4.1.0/4.1.2 
  1536. if ($globaldebug) { 
  1537. print_r(curl_getinfo($ch)); 
  1538. echo "<BR><BR>\n\n\nperform_https_request: cURL error number:" . $errno . "<BR>\n"; 
  1539. echo "\n\n\nperform_https_request: cURL error:" . $errmsg . "<BR>\n"; 
  1540. } #Endif 
  1541.  
  1542. #close connection 
  1543. curl_close($ch); 
  1544.  
  1545. if ($globaldebug) 
  1546. print "<BR>\n" . $data; 
  1547.  
  1548. ## read and return data from novalnet paygate 
  1549. return array($errno, $errmsg, $data); 
  1550.  
  1551. } // End perform_https_request() 
  1552.  
  1553. /** 
  1554. * Generate Hash parameter value ($h contains encoded data) 
  1555. */ 
  1556. public function hash($h) { 
  1557.  
  1558. if (!$h) 
  1559. return'Error: no data'; 
  1560. if (!function_exists('md5')) { 
  1561. return'Error: func n/a'; 
  1562. } #Endif 
  1563. return md5($h['authcode'] . $h['product_id'] . $h['tariff'] . $h['amount'] . $h['test_mode'] . $h['uniqid'] . strrev($this->key_password)); 
  1564.  
  1565. } // End hash() 
  1566.  
  1567. /** 
  1568. * Validate Hash parameter 
  1569. */ 
  1570. public function checkHash(&$request) { 
  1571.  
  1572. $h['authcode'] = $request['auth_code']; #encoded 
  1573. $h['product_id'] = $request['product']; #encoded 
  1574. $h['tariff'] = $request['tariff']; #encoded  
  1575. $h['amount'] = $request['amount']; #encoded 
  1576. $h['test_mode'] = $request['test_mode']; #encoded 
  1577. $h['uniqid'] = $request['uniqid']; #encoded 
  1578.  
  1579. if (!$request) 
  1580. return false; #'Error: no data 
  1581.  
  1582. if ($request['hash2'] != $this->hash($h)) 
  1583. return false; 
  1584.  
  1585. return true; 
  1586.  
  1587. } // End checkHash() 
  1588.  
  1589. /** 
  1590. * Encode payment parameters 
  1591. */ 
  1592. public function encode($data) { 
  1593.  
  1594. $data = trim($data); 
  1595.  
  1596. if ($data == '') 
  1597. return'Error: no data'; 
  1598.  
  1599. if (!function_exists('base64_encode') or !function_exists('pack') or !function_exists('crc32')) 
  1600. return'Error: func n/a'; 
  1601.  
  1602. try { 
  1603. $crc = sprintf('%u', crc32($data)); # %u is a must for ccrc32 returns a signed value 
  1604. $data = $crc . "|" . $data; 
  1605. $data = bin2hex($data . $this->key_password); 
  1606. $data = strrev(base64_encode($data)); 
  1607. } catch (Exception $e) { 
  1608. echo('Error: ' . $e); 
  1609. return $data; 
  1610.  
  1611. } // End encode() 
  1612.  
  1613. /** 
  1614. * Decode payment parameters 
  1615. */ 
  1616. public function decode($data) { 
  1617.  
  1618. $data = trim($data); 
  1619.  
  1620. if ($data == '') 
  1621. return'Error: no data'; 
  1622.  
  1623. if (!function_exists('base64_decode') or !function_exists('pack') or !function_exists('crc32')) 
  1624. return'Error: func n/a'; 
  1625.  
  1626. try { 
  1627. $data = base64_decode(strrev($data)); 
  1628. $data = pack("H" . strlen($data), $data); 
  1629. $data = substr($data, 0, stripos($data, $this->key_password)); 
  1630. $pos = strpos($data, "|"); 
  1631.  
  1632. if ($pos === false) 
  1633. return("Error: CKSum not found!"); 
  1634.  
  1635. $crc = substr($data, 0, $pos); 
  1636. $value = trim(substr($data, $pos + 1)); 
  1637. if ($crc != sprintf('%u', crc32($value))) 
  1638. return("Error; CKSum invalid!"); 
  1639.  
  1640. return $value; 
  1641. } catch (Exception $e) { 
  1642. echo('Error: ' . $e); 
  1643.  
  1644. } // End decode() 
  1645.  
  1646. /** 
  1647. * Validate current user's IP address 
  1648. */ 
  1649. public function isPublicIP($value) { 
  1650.  
  1651. if (!$value || count(explode('.', $value)) != 4) 
  1652. return false; 
  1653. return !preg_match('~^((0|10|172\.16|192\.168|169\.254|255|127\.0)\.)~', $value); 
  1654.  
  1655. } // End isPublicIP() 
  1656.  
  1657. /** 
  1658. * Get the real Ip Adress of the User 
  1659. */ 
  1660. public function getRealIpAddr() { 
  1661.  
  1662. if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $this->isPublicIP($_SERVER['HTTP_X_FORWARDED_FOR'])) 
  1663. return $_SERVER['HTTP_X_FORWARDED_FOR']; 
  1664.  
  1665. if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $iplist = explode(', ', $_SERVER['HTTP_X_FORWARDED_FOR'])) { 
  1666.  
  1667. if ($this->isPublicIP($iplist[0])) 
  1668. return $iplist[0]; 
  1669.  
  1670. } #Endif 
  1671.  
  1672. if (isset($_SERVER['HTTP_CLIENT_IP']) && $this->isPublicIP($_SERVER['HTTP_CLIENT_IP'])) 
  1673. return $_SERVER['HTTP_CLIENT_IP']; 
  1674.  
  1675. if (isset($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']) && $this->isPublicIP($_SERVER['HTTP_X_CLUSTER_CLIENT_IP'])) 
  1676. return $_SERVER['HTTP_X_CLUSTER_CLIENT_IP']; 
  1677.  
  1678. if (isset($_SERVER['HTTP_FORWARDED_FOR']) && $this->isPublicIP($_SERVER['HTTP_FORWARDED_FOR'])) 
  1679. return $_SERVER['HTTP_FORWARDED_FOR']; 
  1680.  
  1681. return $_SERVER['REMOTE_ADDR']; 
  1682.  
  1683. } // End getRealIpAddr() 
  1684.  
  1685. /** 
  1686. * Process Novalnet server response 
  1687. */ 
  1688. public function do_check_novalnet_status($request) { 
  1689.  
  1690. if (isset($request['status'])) { 
  1691.  
  1692. if ($request['status'] == 100) 
  1693. return($this->do_novalnet_success($request, $this->do_get_novalnet_response_text($request))); 
  1694.  
  1695. elseif (isset($request['novalnet_payment_method']) && $request['novalnet_payment_method'] == 'novalnet_paypal' && $request['status'] == 90) { 
  1696.  
  1697. $this->order_status = 'processing'; 
  1698. return($this->do_novalnet_success($request, $this->do_get_novalnet_response_text($request))); 
  1699.  
  1700. } #Endelseif 
  1701.  
  1702. else 
  1703. return($this->do_novalnet_cancel($request, $this->do_get_novalnet_response_text($request))); 
  1704.  
  1705. } #Endif 
  1706.  
  1707. } // End do_check_novalnet_status() 
  1708.  
  1709. /** 
  1710. * validate novalnet server response 
  1711. */ 
  1712. public function do_check_novalnet_payment_status() { 
  1713.  
  1714. if (isset($_REQUEST['status']) && isset($_REQUEST['novalnet_payment_method']) && in_array($_REQUEST['novalnet_payment_method'], $this->return_url_parameter_for_array)) { 
  1715.  
  1716. if (isset($_REQUEST['hash'])) { 
  1717.  
  1718. if (!$this->checkHash($_REQUEST)) { 
  1719.  
  1720. $message = $this->do_get_novalnet_response_text($_REQUEST) . ' - ' . __('Check Hash failed.', 'woocommerce-novalnetpayment'); 
  1721. $this->do_novalnet_cancel($_REQUEST, $message); 
  1722.  
  1723. } #Endif 
  1724.  
  1725. else 
  1726. $this->do_check_novalnet_status($_REQUEST); 
  1727.  
  1728. } #Endif 
  1729.  
  1730. else 
  1731. $this->do_check_novalnet_status($_REQUEST); 
  1732.  
  1733. } #Endif 
  1734.  
  1735. } // End do_check_novalnet_payment_status() 
  1736.  
  1737. /** 
  1738. * Send acknowledgement parameters to Novalnet server after successful transaction  
  1739. */ 
  1740. public function post_back_param($request, $order_id) { 
  1741.  
  1742. /** basic validation for post back parameter */ 
  1743. if (isset($this->vendor_id) && $this->vendor_id != null && isset($this->product_id) && $this->product_id != null && isset($this->payment_key) && $this->payment_key != null && isset($this->tariff_id) && $this->tariff_id != null && isset($this->auth_code) && $this->auth_code != null && isset($request['tid']) && $request['tid'] != null && isset($order_id) && $order_id != null) { 
  1744.  
  1745. $urlparam = 'vendor=' . $this->vendor_id . '&product=' . $this->product_id . '&key=' . $this->payment_key . '&tariff=' . $this->tariff_id . '&auth_code=' . $this->auth_code . '&status=100&tid=' . $request['tid'] . '&order_no=' . $order_id; 
  1746.  
  1747. if ($this->novalnet_payment_method == 'novalnet_invoice' || $this->novalnet_payment_method == 'novalnet_prepayment') 
  1748. $urlparam .='&invoice_ref=' . "BNR-" . $this->product_id . "-" . $order_id; 
  1749.  
  1750. list($errno, $errmsg, $data) = $this->perform_https_request($this->novalnet_paygate_url, $urlparam);  
  1751.  
  1752. } #Endif 
  1753.  
  1754. } // End post_back_param() 
  1755.  
  1756. /** 
  1757. * Constructor for Novalnet gateway 
  1758. *  
  1759. * @access public 
  1760. * @return void 
  1761. */ 
  1762. public function __construct() { 
  1763.  
  1764. global $woocommerce; 
  1765.  
  1766. if (!isset($_SESSION)) 
  1767. session_start(); 
  1768.  
  1769. if (isset($_REQUEST)) 
  1770. $this->do_trim_array_values($_REQUEST); 
  1771.  
  1772. // called after all plugins have loaded 
  1773. add_action('plugins_loaded', array(&$this, 'plugins_loaded')); 
  1774.  
  1775. $this->novalnet_payment_method = $this->id = get_class($this); 
  1776. $this->has_fields = true; 
  1777.  
  1778. // Load the form fields. 
  1779. $this->init_form_fields(); 
  1780.  
  1781. // Load the settings. 
  1782. $this->init_settings(); 
  1783.  
  1784. $this->do_initialize_novalnet_language(); 
  1785. $this->do_assign_config_vars_to_members(); 
  1786.  
  1787. // Logs 
  1788. if (isset($this->debug) && $this->debug == 'yes') 
  1789. $this->log = $woocommerce->logger(); 
  1790.  
  1791. if (!$this->is_valid_for_use()) 
  1792. $this->enabled = false; 
  1793.  
  1794. // novalnet page sessions 
  1795. if (isset($_SESSION['novalnet_receipt_page_got'])) 
  1796. unset($_SESSION['novalnet_receipt_page_got']); 
  1797. if (isset($_SESSION['novalnet_thankyou_page_got'])) 
  1798. unset($_SESSION['novalnet_thankyou_page_got']); 
  1799.  
  1800. add_action('init', array(&$this, 'do_check_novalnet_payment_status')); 
  1801.  
  1802. if (isset($_REQUEST)) 
  1803. $this->do_check_novalnet_backend_data_validation_from_backend($_REQUEST); 
  1804.  
  1805. // actions to perform 
  1806. add_action('woocommerce_successful_request', array(&$this, 'successful_request')); 
  1807. add_action('woocommerce_thankyou_' . $this->novalnet_payment_method, array(&$this, 'thankyou_page')); 
  1808. add_action('woocommerce_receipt_' . $this->novalnet_payment_method, array(&$this, 'receipt_page')); 
  1809. add_action('woocommerce_update_options_payment_gateways', array(&$this, 'process_admin_options')); 
  1810. add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); 
  1811.  
  1812. /** basic validation for iframe request parameter */ 
  1813. if (isset($this->vendor_id) && $this->vendor_id != null && isset($this->product_id) && $this->product_id != null && isset($this->auth_code) && $this->auth_code != null && isset($this->payment_key) && $this->payment_key != null && isset($this->language) && $this->language != null) { 
  1814.  
  1815. $this->nn_cc_check = true; 
  1816.  
  1817. /** Novalnet Credit card iframe server request */ 
  1818. $this->do_check_is_any_request_to_print_cc_iframe(); 
  1819.  
  1820. } #Endif 
  1821.  
  1822. else 
  1823. $this->nn_cc_check = false; 
  1824.  
  1825. } // End __construct() 
  1826.  
  1827. /** 
  1828. * thank you page 
  1829. */ 
  1830. public function thankyou_page($order_id) { 
  1831.  
  1832. if (!isset($_SESSION['novalnet_thankyou_page_got'])) { 
  1833.  
  1834. $order = new WC_Order($order_id); 
  1835. echo wpautop('<strong>' . __('Transaction Information:', 'woocommerce-novalnetpayment') . '</strong>'); 
  1836. echo wpautop(wptexturize($order->customer_note)); 
  1837. $_SESSION['novalnet_thankyou_page_got'] = 1; 
  1838.  
  1839. } #Endif 
  1840.  
  1841. } // End thankyou_page() 
  1842.  
  1843. /** 
  1844. * set current 
  1845. */ 
  1846. public function set_current() { 
  1847.  
  1848. $this->chosen = true; 
  1849. } // End set_current() 
  1850.  
  1851. /** 
  1852. * Displays payment method icon 
  1853. */ 
  1854. public function get_icon() { 
  1855.  
  1856. $icon_html = ''; 
  1857.  
  1858. if ($this->payment_logo) 
  1859. $icon_html = '<a href="' . (strtolower($this->language) == 'de' ? 'https://www.novalnet.de' : 'http://www.novalnet.com') . '" alt="' . __('novalnet.com', 'woocommerce-novalnetpayment') . '" target="_new"><img height ="30" src="' . $this->icon . '" alt="' . $this->method_title . '" /></a>'; 
  1860.  
  1861. return($icon_html); 
  1862.  
  1863. } // End get_icon() 
  1864.  
  1865. /** 
  1866. * Displays Novalnet Logo icon 
  1867. */ 
  1868. public function get_title() { 
  1869.  
  1870. return($this->title); 
  1871. } // End get_title() 
  1872.  
  1873. /** 
  1874. * Payment field to display description and additional info in the checkout form  
  1875. */ 
  1876. public function payment_fields() { 
  1877.  
  1878. // payment description 
  1879. if ($this->description) 
  1880. echo wpautop(wptexturize($this->description)); 
  1881.  
  1882. // test order notice 
  1883. if ($this->test_mode == 1) { 
  1884. $test_notice = __('Please Note: This transaction will run on TEST MODE and the amount will not be charged', 'woocommerce-novalnetpayment'); 
  1885. echo wpautop('<strong><font color="red">' . $test_notice . '</font></strong>'); 
  1886. } #Endif 
  1887.  
  1888. // payment form 
  1889. switch ($this->novalnet_payment_method) { 
  1890.  
  1891. case 'novalnet_cc': 
  1892. if (isset($this->nn_cc_check) && $this->nn_cc_check == true) { 
  1893.  
  1894. /** Novalnet Credit Card Payment form */ 
  1895. print '<br /><div id="loading_iframe_div" style="display:;"><img alt="' . __('Loading...', 'woocommerce-novalnetpayment') . '" src="' . (is_ssl() ? 'https://www.novalnet.de/img/novalnet-loading-icon.gif' : 'http://www.novalnet.de/img/novalnet-loading-icon.gif') . '"></div><input type="hidden" name="cc_type" id="cc_type" value="" /><input type="hidden" name="cc_holder" id="cc_holder" value="" /><input type="hidden" name="cc_exp_month" id="cc_exp_month" value="" /><input type="hidden" name="cc_exp_year" id="cc_exp_year" value="" /><input type="hidden" name="cc_cvv_cvc" id="cc_cvv_cvc" value="" /><input type="hidden" id="original_vendor_id" value="' . ($this->vendor_id) . '" /><input type="hidden" id="original_vendor_authcode" value="' . ($this->auth_code) . '" /><input type="hidden" id="original_customstyle_css" value="" /><input type="hidden" id="original_customstyle_cssval" value="" /><input type="hidden" name="nn_unique_id" id="nn_unique_id" value="" /><input type="hidden" name="nn_cardno_id" id="nn_cardno_id" value="" /><iframe onLoad="doHideLoadingImageAndDisplayIframe(this);" name="novalnet_cc_iframe" id="novalnet_cc_iframe" src="' . site_url() . '/wp-content/plugins/woocommerce-novalnet-gateway/includes/novalnet_cc_iframe.html" scrolling="no" frameborder="0" style="width:100%; height:280px; border:none; display:none;"></iframe>  
  1896. <script type="text/javascript" language="javascript"> 
  1897. function doHideLoadingImageAndDisplayIframe(element) { 
  1898. document.getElementById("loading_iframe_div").style.display = "none"; 
  1899. element.style.display = ""; 
  1900. var iframe = (element.contentWindow || element.contentDocument); 
  1901. if (iframe.document) iframe = iframe.document; 
  1902. iframe.getElementById("novalnetCc_cc_type").onchange = function() { 
  1903. doAssignIframeElementsValuesToFormElements(iframe); 
  1904. iframe.getElementById("novalnetCc_cc_owner").onkeyup = function() { 
  1905. doAssignIframeElementsValuesToFormElements(iframe); 
  1906. iframe.getElementById("novalnetCc_expiration").onchange = function() { 
  1907. doAssignIframeElementsValuesToFormElements(iframe); 
  1908. iframe.getElementById("novalnetCc_expiration_yr").onchange = function() { 
  1909. doAssignIframeElementsValuesToFormElements(iframe); 
  1910. iframe.getElementById("novalnetCc_cc_cid").onkeyup = function() { 
  1911. doAssignIframeElementsValuesToFormElements(iframe); 
  1912.  
  1913. function doAssignIframeElementsValuesToFormElements(iframe) { 
  1914. document.getElementById("cc_type").value = iframe.getElementById("novalnetCc_cc_type").value; 
  1915. document.getElementById("cc_holder").value = iframe.getElementById("novalnetCc_cc_owner").value; 
  1916. document.getElementById("cc_exp_month").value = iframe.getElementById("novalnetCc_expiration").value; 
  1917. document.getElementById("cc_exp_year").value = iframe.getElementById("novalnetCc_expiration_yr").value; 
  1918. document.getElementById("cc_cvv_cvc").value = iframe.getElementById("novalnetCc_cc_cid").value; 
  1919. var novalnetHiddenId = "novalnet_cc_formid"; 
  1920. var getInputForm = document.getElementById("original_vendor_id"); 
  1921. if (getInputForm.form.getAttribute("id") == null || getInputForm.form.getAttribute("id") == "") { 
  1922. getInputForm.form.setAttribute("id", novalnetHiddenId); 
  1923. getFormId = getInputForm.form.getAttribute("id"); 
  1924. } else { 
  1925. getFormId = getInputForm.form.getAttribute("id"); 
  1926. window.addEventListener ? window.addEventListener("load", nn_cc, false) : window.attachEvent && window.attachEvent("onload", nn_cc); 
  1927.  
  1928. function nn_cc() { 
  1929. document.forms[getFormId].onclick = function() { 
  1930. var iform = document.getElementById("novalnet_cc_iframe"); 
  1931. var novalnet_cc_iframe = (iform.contentWindow || iform.contentDocument); 
  1932. if (novalnet_cc_iframe.document) novalnet_cc_iframe = novalnet_cc_iframe.document; 
  1933. if (novalnet_cc_iframe.getElementById("nncc_cardno_id").value != null) { 
  1934. document.getElementById("nn_cardno_id").value = novalnet_cc_iframe.getElementById("nncc_cardno_id").value; 
  1935. document.getElementById("nn_unique_id").value = novalnet_cc_iframe.getElementById("nncc_unique_id").value; 
  1936. </script> 
  1937. '; 
  1938. } #Endif  
  1939.  
  1940. else 
  1941. echo wpautop('<strong><font color="red">' . __('Basic Parameter Missing', 'woocommerce-novalnetpayment') . '</font></strong>'); 
  1942. break; 
  1943.  
  1944. case 'novalnet_cc3d': 
  1945.  
  1946. /** Novalnet Credit Card 3D Secure Payment form */ 
  1947. $payment_field_html = '<div> </div><div> 
  1948. <div style="float:left;width:50%;">' . __('Credit card holder', 'woocommerce-novalnetpayment') . ':<span style="color:red;">*</span></div> 
  1949. <div style="float:left;width:50%;"><input type="text" name="cc3d_holder" id="cc3d_holder" value="" autocomplete="off" /></div> 
  1950. <div style="clear:both;"> </div> 
  1951. <div style="float:left;width:50%;">' . __('Card number', 'woocommerce-novalnetpayment') . ':<span style="color:red;">*</span></div> 
  1952. <div style="float:left;width:50%;"><input type="text" name="cc3d_number" id="cc3d_number" value="" autocomplete="off" /></div> 
  1953. <div style="clear:both;"> </div> 
  1954. <div style="float:left;width:50%;">' . __('Expiration Date', 'woocommerce-novalnetpayment') . ':<span style="color:red;">*</span></div> 
  1955. <div style="float:left;width:50%;"> 
  1956. <select name="cc3d_exp_month" id="cc3d_exp_month"> 
  1957. <option value="">' . __('Month', 'woocommerce-novalnetpayment') . '</option> 
  1958. <option value="1">' . __('January', 'woocommerce-novalnetpayment') . '</option> 
  1959. <option value="2">' . __('February', 'woocommerce-novalnetpayment') . '</option> 
  1960. <option value="3">' . __('March', 'woocommerce-novalnetpayment') . '</option> 
  1961. <option value="4">' . __('April', 'woocommerce-novalnetpayment') . '</option> 
  1962. <option value="5">' . __('May', 'woocommerce-novalnetpayment') . '</option> 
  1963. <option value="6">' . __('June', 'woocommerce-novalnetpayment') . '</option> 
  1964. <option value="7">' . __('July', 'woocommerce-novalnetpayment') . '</option> 
  1965. <option value="8">' . __('August', 'woocommerce-novalnetpayment') . '</option> 
  1966. <option value="9">' . __('September', 'woocommerce-novalnetpayment') . '</option> 
  1967. <option value="10">' . __('October', 'woocommerce-novalnetpayment') . '</option> 
  1968. <option value="11">' . __('November', 'woocommerce-novalnetpayment') . '</option> 
  1969. <option value="12">' . __('December', 'woocommerce-novalnetpayment') . '</option> 
  1970. </select>  
  1971. <select name="cc3d_exp_year" id="cc3d_exp_year"> 
  1972. <option value="">' . __('Year', 'woocommerce-novalnetpayment') . '</option>'; 
  1973.  
  1974. for ($iYear = date('Y'); $iYear < date('Y') + 6; $iYear++) { 
  1975. $payment_field_html.='<option value="' . $iYear . '">' . $iYear . '</option>'; 
  1976. } #Endfor 
  1977.  
  1978. $payment_field_html.='</select> 
  1979. </div> 
  1980. <div style="clear:both;"> </div> 
  1981. <div style="float:left;width:50%;">' . __('CVC (Verification Code)', 'woocommerce-novalnetpayment') . ':<span style="color:red;">*</span></div> 
  1982. <div style="float:left;width:50%;"><input type="text" name="cvv_cvc" id="cvv_cvc" value="" maxlength="4" autocomplete="off" /><br />' . __('* On Visa-, Master- and Eurocard you will find the 3 digit CVC-Code near the signature field at the rearside of the creditcard.', 'woocommerce-novalnetpayment') . '</div> 
  1983. <div style="clear:both;"> </div></div>'; 
  1984.  
  1985. print $payment_field_html; 
  1986. break; 
  1987.  
  1988. case 'novalnet_elv_de': 
  1989.  
  1990. /** Novalnet Direct Debit German Payment form */ 
  1991. print $this->do_print_form_elements_for_novalnet_elv_de_at('de'); 
  1992. break; 
  1993.  
  1994. case 'novalnet_elv_at': 
  1995.  
  1996. /** Novalnet Direct Debit Austria Payment form */ 
  1997. print $this->do_print_form_elements_for_novalnet_elv_de_at('at'); 
  1998. break; 
  1999.  
  2000. } #Endswitchcase 
  2001.  
  2002. } // End payment_fields() 
  2003.  
  2004. /** 
  2005. * Process the payment and return the result 
  2006. */ 
  2007. public function process_payment($order_id) { 
  2008.  
  2009. return($this->do_process_payment_from_novalnet_payments($order_id)); 
  2010. } // End process_payment() 
  2011.  
  2012. /** 
  2013. * Receipt_page 
  2014. */ 
  2015. public function receipt_page($order_id) { 
  2016.  
  2017. $order = new WC_Order($order_id); 
  2018. $this->do_necessary_actions_before_prepare_to_novalnet_payport_or_paygate($order); 
  2019. $this->do_prepare_to_novalnet_payport($order); 
  2020.  
  2021. } // End receipt_page() 
  2022.  
  2023. /** 
  2024. * plugins loaded 
  2025. */ 
  2026. public function plugins_loaded() { 
  2027.  
  2028. } // End plugins_loaded() 
  2029.  
  2030. /** 
  2031. * include template 
  2032. */ 
  2033. public function include_template_functions() { 
  2034.  
  2035. } // End include_template_functions() 
  2036.  
  2037. /** 
  2038. * is valid for use 
  2039. */ 
  2040. function is_valid_for_use() { 
  2041. return(true); 
  2042. } // End is_valid_for_use() 
  2043.  
  2044. /** 
  2045. * Admin Panel Options  
  2046. */ 
  2047. public function admin_options() { 
  2048. ?> 
  2049. <h3><?php echo '<a href="' . (strtolower($this->language) == 'de' ? 'https://' : 'http://') . 'www.' . __('novalnet.com', 'woocommerce-novalnetpayment') . '" alt="' . __('novalnet.com', 'woocommerce-novalnetpayment') . '" target="_new"><img src="' . (is_ssl() ? 'https://' : 'http://') . __('www.novalnet.de/img/NN_Logo_T.png', 'woocommerce-novalnetpayment') . '" alt="' . __('novalnet.com', 'woocommerce-novalnetpayment') . '" /></a> ' . $this->payment_details[$this->novalnet_payment_method]['payment_name'] . ' ' . '<a href="' . (strtolower($this->language) == 'de' ? 'https://www.novalnet.de' : 'http://www.novalnet.com') . '" alt="' . __('novalnet.com', 'woocommerce-novalnetpayment') . '" target="_new"><img height ="30" src="' . $this->icon . '" alt="' . $this->method_title . '" /></a>'; ?></h3> 
  2050. <p><?php echo __('Configure with Novalnet dealer details.If you need more information<br><br>you can visit our website for end-customers visit on <a href="https://www.novalnet.de/" target="_blank"> https://www.novalnet.de</a> or please contact our Sales Team <a href="mailto:sales@novalnet.de">sales@novalnet.de</a>.', 'woocommerce-novalnetpayment'); ?></p> 
  2051. <table class="form-table"> 
  2052. <?php 
  2053. // Generate the HTML For the settings form. 
  2054. $this->generate_settings_html(); 
  2055. ?> 
  2056. </table><!--/.form-table--> 
  2057. <?php 
  2058. } // End admin_options() 
  2059.  
  2060. /** 
  2061. * Initialise Novalnet Gateway Settings Form Fields 
  2062. */ 
  2063. public function init_form_fields() { 
  2064.  
  2065. // Enable module 
  2066. $this->form_fields['enabled'] = array( 
  2067. 'title' => __('Enable module', 'woocommerce-novalnetpayment'),  
  2068. 'type' => 'checkbox',  
  2069. 'label' => '',  
  2070. 'default' => '' 
  2071. ); 
  2072.  
  2073. // Payment title & description fields 
  2074. foreach ($this->language_supported_array as $language) { 
  2075. $this->form_fields['title_' . $language] = array( 
  2076. 'title' => __('Payment Title', 'woocommerce-novalnetpayment') . ' (' . $language . ')<span style="color:red;">*</span>',  
  2077. 'type' => 'text',  
  2078. 'description' => '',  
  2079. 'default' => '' 
  2080. ); 
  2081. $this->form_fields['description_' . $language] = array( 
  2082. 'title' => __('Description', 'woocommerce-novalnetpayment') . ' (' . $language . ')',  
  2083. 'type' => 'textarea',  
  2084. 'description' => '',  
  2085. 'default' => '' 
  2086. ); 
  2087. } #Endforeach 
  2088.  
  2089. // Enable test mode 
  2090. $this->form_fields['test_mode'] = array( 
  2091. 'title' => __('Enable Test Mode', 'woocommerce-novalnetpayment'),  
  2092. 'type' => 'select',  
  2093. 'options' => array('0' => __('No', 'woocommerce-novalnetpayment'), '1' => __('Yes', 'woocommerce-novalnetpayment')),  
  2094. 'description' => '',  
  2095. 'default' => '' 
  2096. ); 
  2097.  
  2098. // Novalnet Merchant ID field 
  2099. $this->form_fields['merchant_id'] = array( 
  2100. 'title' => __('Novalnet Merchant ID', 'woocommerce-novalnetpayment') . '<span style="color:red;">*</span>',  
  2101. 'type' => 'text',  
  2102. 'description' => __('Enter your Novalnet Merchant ID', 'woocommerce-novalnetpayment'),  
  2103. 'default' => '' 
  2104. ); 
  2105.  
  2106. // Novalnet Authorisation code field 
  2107. $this->form_fields['auth_code'] = array( 
  2108. 'title' => __('Novalnet Merchant Authorisation code', 'woocommerce-novalnetpayment') . '<span style="color:red;">*</span>',  
  2109. 'type' => 'text',  
  2110. 'description' => __('Enter your Novalnet Merchant Authorisation code', 'woocommerce-novalnetpayment'),  
  2111. 'default' => '' 
  2112. ); 
  2113.  
  2114. // Novalnet Product ID field 
  2115. $this->form_fields['product_id'] = array( 
  2116. 'title' => __('Novalnet Product ID', 'woocommerce-novalnetpayment') . '<span style="color:red;">*</span>',  
  2117. 'type' => 'text',  
  2118. 'description' => __('Enter your Novalnet Product ID', 'woocommerce-novalnetpayment'),  
  2119. 'default' => '' 
  2120. ); 
  2121.  
  2122. // Novalnet Tariff ID field 
  2123. $this->form_fields['tariff_id'] = array( 
  2124. 'title' => __('Novalnet Tariff ID', 'woocommerce-novalnetpayment') . '<span style="color:red;">*</span>',  
  2125. 'type' => 'text',  
  2126. 'description' => __('Enter your Novalnet Tariff ID', 'woocommerce-novalnetpayment'),  
  2127. 'default' => '' 
  2128. ); 
  2129.  
  2130. // Novalnet Payment Access Key field 
  2131. if (in_array($this->novalnet_payment_method, $this->encode_applicable_for_array)) { 
  2132. $this->form_fields['key_password'] = array( 
  2133. 'title' => __('Novalnet Payment access key', 'woocommerce-novalnetpayment') . '<span style="color:red;">*</span>',  
  2134. 'type' => 'text',  
  2135. 'description' => __('Enter your Novalnet payment access key', 'woocommerce-novalnetpayment'),  
  2136. 'default' => '' 
  2137. ); 
  2138. } #Endif 
  2139.  
  2140. // Enable ACDC 
  2141. if ($this->novalnet_payment_method == 'novalnet_elv_de') { 
  2142. $this->form_fields['acdc'] = array( 
  2143. 'title' => __('Enable credit rating check', 'woocommerce-novalnetpayment'),  
  2144. 'type' => 'checkbox',  
  2145. 'label' => '',  
  2146. 'default' => '' 
  2147. ); 
  2148. } #Endif 
  2149.  
  2150. // Payment duration field 
  2151. if ($this->novalnet_payment_method == 'novalnet_invoice') { 
  2152. $this->form_fields['payment_duration'] = array( 
  2153. 'title' => __('Payment period in days', 'woocommerce-novalnetpayment'),  
  2154. 'type' => 'text',  
  2155. 'label' => '',  
  2156. 'default' => '' 
  2157. ); 
  2158. } #Endif 
  2159.  
  2160. // Manual check limit fields 
  2161. if (!in_array($this->novalnet_payment_method, $this->manual_check_limit_not_available_array)) { 
  2162. $this->form_fields['manual_check_limit'] = array( 
  2163. 'title' => __('Manual checking amount in cents', 'woocommerce-novalnetpayment'),  
  2164. 'type' => 'text',  
  2165. 'description' => __('Please enter the amount in cents', 'woocommerce-novalnetpayment'),  
  2166. 'default' => '' 
  2167. ); 
  2168. $this->form_fields['product_id_2'] = array( 
  2169. 'title' => __('Second Product ID in Novalnet', 'woocommerce-novalnetpayment'),  
  2170. 'type' => 'text',  
  2171. 'description' => __('for the manual checking', 'woocommerce-novalnetpayment'),  
  2172. 'default' => '' 
  2173. ); 
  2174. $this->form_fields['tariff_id_2'] = array( 
  2175. 'title' => __('Second Tariff ID in Novalnet', 'woocommerce-novalnetpayment'),  
  2176. 'type' => 'text',  
  2177. 'description' => __('for the manual checking', 'woocommerce-novalnetpayment'),  
  2178. 'default' => '' 
  2179. ); 
  2180. } #Endif 
  2181.  
  2182. // PayPal configuration fields 
  2183. if ($this->novalnet_payment_method == 'novalnet_paypal') { 
  2184.  
  2185. $this->form_fields['api_username'] = array( 
  2186. 'title' => __('PayPal API User Name', 'woocommerce-novalnetpayment') . '<span style="color:red;">*</span>',  
  2187. 'type' => 'text',  
  2188. 'description' => __('Please enter your PayPal API username', 'woocommerce-novalnetpayment'),  
  2189. 'default' => '' 
  2190. ); 
  2191. $this->form_fields['api_password'] = array( 
  2192. 'title' => __('PayPal API Password', 'woocommerce-novalnetpayment') . '<span style="color:red;">*</span>',  
  2193. 'type' => 'text',  
  2194. 'description' => __('Please enter your PayPal API password', 'woocommerce-novalnetpayment'),  
  2195. 'default' => '' 
  2196. ); 
  2197. $this->form_fields['api_signature'] = array( 
  2198. 'title' => __('PayPal API Signature', 'woocommerce-novalnetpayment') . '<span style="color:red;">*</span>',  
  2199. 'type' => 'text',  
  2200. 'description' => __('Please enter your PayPal API signature', 'woocommerce-novalnetpayment'),  
  2201. 'default' => '' 
  2202. ); 
  2203.  
  2204. } #Endif 
  2205.  
  2206. // Proxy server field (required for cURL protocol, if the client set any proxy port in their server) 
  2207. $this->form_fields['payment_proxy'] = array( 
  2208. 'title' => __('Proxy-Server', 'woocommerce-novalnetpayment'),  
  2209. 'type' => 'text',  
  2210. 'description' => __('If you use a Proxy Server, enter the Proxy Server IP with port here (e.g. www.proxy.de:80)', 'woocommerce-novalnetpayment'),  
  2211. 'default' => '' 
  2212. ); 
  2213.  
  2214. // Enable Payment Logo 
  2215. $this->form_fields['payment_logo'] = array( 
  2216. 'title' => __('Enable Payment Logo', 'woocommerce-novalnetpayment'),  
  2217. 'type' => 'select',  
  2218. 'options' => array('0' => __('No', 'woocommerce-novalnetpayment'), '1' => __('Yes', 'woocommerce-novalnetpayment')),  
  2219. 'description' => __('To display Payment logo in front end', 'woocommerce-novalnetpayment'),  
  2220. 'default' => '' 
  2221. ); 
  2222.  
  2223. } // End init_form_fields() 
  2224.  
  2225. } // End class novalnetpayments 
  2226.  
  2227. } #Endif 
  2228.  
  2229. } #Endif 
  2230.  
  2231. } // End novalnetpayments_Load() 
  2232.  
  2233. /** initiate novlanet payment methods */ 
  2234. if (isset($_REQUEST['novalnet_payment_method']) && in_array($_REQUEST['novalnet_payment_method'], $novalnet_payment_methods)) 
  2235. require_once(dirname(__FILE__) . '/includes/' . $_REQUEST['novalnet_payment_method'] . '.php');  
  2236. else { 
  2237. foreach ($novalnet_payment_methods as $novalnet_payment_method) 
  2238. require_once(dirname(__FILE__) . '/includes/' . $novalnet_payment_method . '.php'); 
  2239. ob_get_clean(); 
  2240. ?> 
.