| @@ -3,9 +3,9 @@ | ||
| 3 | 3 | |
| 4 | 4 | |
| 5 | 5 | function woocommerce_payment_makecommerce_init() { |
| 6 | 6 | |
| 7 | - load_plugin_textdomain('wc_makecommerce_domain', false, dirname(plugin_basename(__FILE__)) . '/'); | |
| 7 | + load_plugin_textdomain('wc_makecommerce_domain', false, dirname(plugin_basename(__FILE__)) . '/languages/'); | |
| 8 | 8 | |
| 9 | 9 | class woocommerce_makecommerce extends WC_Payment_Gateway { |
| 10 | 10 | |
| 11 | 11 | const MC_CANCELLED = 'CANCELLED'; |
| @@ -16,15 +16,15 @@ | ||
| 16 | 16 | const MC_REFUNDED = 'REFUNDED'; |
| 17 | 17 | |
| 18 | 18 | const module_name = 'MakeCommerce'; |
| 19 | 19 | |
| 20 | - const billing_descriptor_dba = ''; | |
| 20 | + const billing_descriptor_dba = ''; | |
| 21 | 21 | const currencies_allowed = 'EUR'; |
| 22 | 22 | const module_homepage_url = 'https://maksekeskus.ee/en/integration-modules/makecommerce-woocommerce-payment-plugin/'; |
| 23 | 23 | const testenv_homepage_url = 'http://maksekeskus.ee/en/for-developers/test-environment/'; |
| 24 | 24 | |
| 25 | 25 | public $id = 'makecommerce'; |
| 26 | - public $version = '2.1.3'; | |
| 26 | + public $version = '2.6.2'; | |
| 27 | 27 | |
| 28 | 28 | public $payment_return_url; |
| 29 | 29 | public $payment_return_url_m2m; |
| 30 | 30 | public $payment_return_url_cancel; |
| @@ -36,20 +36,35 @@ | ||
| 36 | 36 | |
| 37 | 37 | protected $_banklinks = array(); |
| 38 | 38 | protected $_banklinks_grouped; |
| 39 | 39 | protected $_cards = array(); |
| 40 | + protected $_paylater = array(); | |
| 41 | + protected $_paylater_grouped; | |
| 40 | 42 | |
| 41 | - protected $MK; | |
| 43 | + protected $MK; | |
| 42 | 44 | protected $_init; |
| 43 | 45 | |
| 44 | - | |
| 45 | - public function __construct($init = false) { | |
| 46 | + public function __construct($init = false) { | |
| 46 | 47 | $this->_init = $init; |
| 48 | + $langGet = ""; | |
| 49 | + | |
| 50 | + //set language | |
| 51 | + //wpml | |
| 52 | + if (function_exists('icl_object_id') && defined('ICL_LANGUAGE_CODE')) { | |
| 53 | + $langGet = "&lang1=".ICL_LANGUAGE_CODE; | |
| 54 | + } else { | |
| 55 | + //if wpml wasnt set, try polylang | |
| 56 | + if (function_exists('pll_current_language')) { | |
| 57 | + //language param will be set but is not implemented in further steps. | |
| 58 | + $langGet = "&lang1=".pll_current_language(); | |
| 59 | + } | |
| 60 | + } | |
| 61 | + | |
| 62 | + //set return url's | |
| 63 | + $this->payment_return_url = site_url('/?makecommerce_return=1'.$langGet); | |
| 64 | + $this->payment_return_url_m2m = site_url('/?makecommerce_return=1&ajax_content=1'.$langGet); | |
| 65 | + $this->payment_return_url_cancel = site_url('/?makecommerce_return=1'.$langGet); | |
| 47 | 66 | |
| 48 | - $this->payment_return_url = site_url('/?makecommerce_return=1'); | |
| 49 | - $this->payment_return_url_m2m = site_url('/?makecommerce_return=1&ajax_content=1'); | |
| 50 | - $this->payment_return_url_cancel = site_url('/?makecommerce_return=1'); | |
| 51 | - | |
| 52 | 67 | // Load the form fields. |
| 53 | 68 | $this->init_form_fields(); |
| 54 | 69 | |
| 55 | 70 | // Load the settings. |
| @@ -56,15 +71,68 @@ | ||
| 56 | 71 | $this->init_settings(); |
| 57 | 72 | |
| 58 | 73 | $this->initBanklinks(); |
| 59 | 74 | |
| 60 | - $this->title = $this->settings['ui_widget_title']; | |
| 61 | - if (defined('ICL_LANGUAGE_CODE') && !empty($this->settings['ui_widget_title_'.ICL_LANGUAGE_CODE])) { | |
| 62 | - $this->title = $this->settings['ui_widget_title_'.ICL_LANGUAGE_CODE]; | |
| 75 | + $this->title = ''; | |
| 76 | + if (!empty($this->settings['ui_widget_title'])) { | |
| 77 | + $this->title = $this->settings['ui_widget_title']; | |
| 63 | 78 | } |
| 79 | + | |
| 80 | + //set the correct language | |
| 81 | + if (isset($_GET["lang1"])) { | |
| 82 | + do_action('wpml_switch_language', $_GET["lang1"]); | |
| 83 | + | |
| 84 | + if (!empty($this->settings['ui_widget_title_'.get_locale()]) || !empty($this->settings['ui_widget_title_'.substr(get_locale(), 0, 2)])) { | |
| 85 | + if (!empty($this->settings['ui_widget_title_'.substr(get_locale(), 0, 2)])) { | |
| 86 | + $this->title = $this->settings['ui_widget_title_'.substr(get_locale(), 0, 2)]; | |
| 87 | + } else { | |
| 88 | + $this->title = $this->settings['ui_widget_title_'.get_locale()]; | |
| 89 | + } | |
| 90 | + } else if (!empty($this->settings['ui_widget_title'])) { | |
| 91 | + $this->title = $this->settings['ui_widget_title']; | |
| 92 | + } else { | |
| 93 | + $this->title = ''; | |
| 94 | + } | |
| 95 | + } else { | |
| 96 | + //coming from admin, set language according to order wpml_language. This meta is set for both polylang wpml | |
| 97 | + if (isset($_POST["meta"])) { | |
| 98 | + foreach ($_POST["meta"] as $key=>$value) { | |
| 99 | + if (is_array($value)) { | |
| 100 | + if ($value["key"] == "wpml_language") { | |
| 101 | + do_action('wpml_switch_language', $value["value"]); | |
| 102 | + } | |
| 103 | + } | |
| 104 | + } | |
| 105 | + } | |
| 106 | + | |
| 107 | + $glocale = get_locale(); | |
| 108 | + if ($glocale == "en_US") { | |
| 109 | + $glocale = "en_GB"; | |
| 110 | + } | |
| 111 | + | |
| 112 | + if (function_exists('pll_languages_list') && (!empty($this->settings['ui_widget_title_'.pll_current_language('locale')]) || !empty($this->settings['ui_widget_title_'.get_locale()]))) { | |
| 113 | + if (!empty($this->settings['ui_widget_title_'.pll_current_language('locale')])) { | |
| 114 | + $this->title = $this->settings['ui_widget_title_'.pll_current_language('locale')]; | |
| 115 | + } else { | |
| 116 | + $this->title = $this->settings['ui_widget_title_'.get_locale()]; | |
| 117 | + } | |
| 118 | + } else { | |
| 119 | + if (defined('ICL_LANGUAGE_CODE') && (!empty($this->settings['ui_widget_title_'.ICL_LANGUAGE_CODE]) || !empty($this->settings['ui_widget_title_'.$glocale]))) { | |
| 120 | + //ICL_LANGUAGE_CODE seems to be in different format in different places. Perhaps its a mistake somewhere but we cant ignore or change it as it is already set previously | |
| 121 | + if (!empty($this->settings['ui_widget_title_'.ICL_LANGUAGE_CODE])) { | |
| 122 | + $this->title = $this->settings['ui_widget_title_'.ICL_LANGUAGE_CODE]; | |
| 123 | + } else { | |
| 124 | + $this->title = $this->settings['ui_widget_title_'.$glocale]; | |
| 125 | + } | |
| 126 | + } | |
| 127 | + } | |
| 128 | + } | |
| 129 | + | |
| 64 | 130 | $this->method_title = 'MakeCommerce'; |
| 65 | 131 | $this->description = true; |
| 66 | 132 | |
| 133 | + $this->enabled = $this->settings['active']; | |
| 134 | + | |
| 67 | 135 | $this->MK = mk_get_api(); |
| 68 | 136 | if (!$this->MK && $this->_init) { |
| 69 | 137 | add_action( 'admin_notices', array(&$this, 'makecommerce_api_info_missing') ); |
| 70 | 138 | } |
| @@ -69,14 +137,23 @@ | ||
| 69 | 137 | add_action( 'admin_notices', array(&$this, 'makecommerce_api_info_missing') ); |
| 70 | 138 | } |
| 71 | 139 | |
| 72 | 140 | $this->supports = array( |
| 141 | + 'subscriptions', | |
| 142 | + 'subscription_cancellation', | |
| 143 | + 'subscription_suspension', | |
| 144 | + 'subscription_reactivation', | |
| 145 | + 'subscription_amount_changes', | |
| 146 | + 'subscription_date_changes', | |
| 147 | + 'subscription_payment_method_change', | |
| 73 | 148 | 'products', |
| 74 | - 'refunds', | |
| 149 | + 'refunds' | |
| 75 | 150 | ); |
| 76 | 151 | |
| 77 | 152 | add_filter('query_vars', array(&$this, 'makecommerce_return_trigger')); |
| 78 | 153 | add_action('template_redirect', array(&$this, 'makecommerce_return_trigger_check')); |
| 154 | + add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'process_subscripion_payment_start'), 10, 2); | |
| 155 | + add_action('scheduled_subscription_payment_' . $this->id, array($this, 'process_subscripion_payment_start'), 10, 2); | |
| 79 | 156 | |
| 80 | 157 | if($this->_init == false) { |
| 81 | 158 | add_action('woocommerce_update_options_payment_gateways', array(&$this, 'process_admin_options')); |
| 82 | 159 | add_action('woocommerce_update_options_payment_gateways_' . $this->id, array(&$this, 'process_admin_options')); |
| @@ -88,8 +165,9 @@ | ||
| 88 | 165 | wp_enqueue_style('makecommerce', plugins_url('/css/makecommerce.css', __FILE__), array(), $this->version); |
| 89 | 166 | } |
| 90 | 167 | if (is_admin()) { |
| 91 | 168 | add_action( 'wp_ajax_mc_banklinks_reload', array(&$this, 'mc_banklinks_reload') ); |
| 169 | + | |
| 92 | 170 | require_once(ABSPATH.'wp-admin/includes/plugin.php'); |
| 93 | 171 | $wc_version = get_plugin_data(__DIR__.'/../woocommerce/woocommerce.php'); |
| 94 | 172 | if ((double)$wc_version['Version'] < 2.6) { |
| 95 | 173 | function sample_admin_notice__error() { |
| @@ -118,11 +196,12 @@ | ||
| 118 | 196 | return true; |
| 119 | 197 | } |
| 120 | 198 | |
| 121 | 199 | public function is_available() { |
| 122 | - if ($this->settings['active'] == "yes" && mk_is_api_set()) { | |
| 123 | - return true; | |
| 200 | + if (!($this->settings['active'] == "yes" && mk_is_api_set())) { | |
| 201 | + return false; | |
| 124 | 202 | } |
| 203 | + return parent::is_available(); | |
| 125 | 204 | } |
| 126 | 205 | |
| 127 | 206 | private function initBanklinks() { |
| 128 | 207 | global $wpdb; |
| @@ -127,8 +206,9 @@ | ||
| 127 | 206 | private function initBanklinks() { |
| 128 | 207 | global $wpdb; |
| 129 | 208 | global $mkDbTable; |
| 130 | 209 | $this->_banklinks = array(); |
| 210 | + $has_subscriptions = class_exists('WC_Subscriptions_Cart') && WC_Subscriptions_Cart::cart_contains_subscription(); | |
| 131 | 211 | |
| 132 | 212 | $tableName = $wpdb->prefix . $mkDbTable; |
| 133 | 213 | $methods = $wpdb->get_results('SELECT * FROM '.$tableName); |
| 134 | 214 | |
| @@ -139,13 +219,21 @@ | ||
| 139 | 219 | } |
| 140 | 220 | $banklinks = array(); |
| 141 | 221 | $banklinks_grouped = array(); |
| 142 | 222 | $cards = array(); |
| 223 | + $paylater = array(); | |
| 224 | + $paylater_grouped = array(); | |
| 143 | 225 | foreach($methods as $method) { |
| 144 | - if($method->type == 'banklink') { | |
| 145 | - $banklinks[] = $banklinks_grouped[$method->country][] = $method; | |
| 226 | + if($method->type == 'banklink'|| $method->type == 'other') { | |
| 227 | + if (!$has_subscriptions) { | |
| 228 | + $banklinks[] = $banklinks_grouped[$method->country][] = $method; | |
| 229 | + } | |
| 146 | 230 | } elseif($method->type == 'card') { |
| 147 | 231 | $cards[] = $method; |
| 232 | + } elseif($method->type == 'payLater') { | |
| 233 | + if (!$has_subscriptions) { | |
| 234 | + $paylater[] = $paylater_grouped[$method->country][] = $method; | |
| 235 | + } | |
| 148 | 236 | } |
| 149 | 237 | } |
| 150 | 238 | |
| 151 | 239 | usort($banklinks, array($this, 'orderBanklinks')); |
| @@ -155,8 +243,10 @@ | ||
| 155 | 243 | |
| 156 | 244 | $this->_banklinks = $banklinks; |
| 157 | 245 | $this->_banklinks_grouped = $banklinks_grouped; |
| 158 | 246 | $this->_cards = $cards; |
| 247 | + $this->_paylater = $paylater; | |
| 248 | + $this->_paylater_grouped = $paylater_grouped; | |
| 159 | 249 | remove_action('admin_notices', array(&$this, 'makecommerce_banklinks_list_empty'), 30); |
| 160 | 250 | } elseif(is_admin() && $this->_init == true) { |
| 161 | 251 | add_action('admin_notices', array(&$this, 'makecommerce_banklinks_list_empty'), 30); |
| 162 | 252 | } |
| @@ -184,9 +274,13 @@ | ||
| 184 | 274 | ?> |
| 185 | 275 | <div class="notice notice-error is-dismissible"> |
| 186 | 276 | <p> |
| 187 | 277 | <?php echo __('You have not entered the Shop ID and keys for the MakeCommerce payment module. The module will not work without them.', 'wc_makecommerce_domain'); ?> |
| 278 | + <?php if (mk_wc_version("3.4.0")) { ?> | |
| 279 | + <a href="<?php echo admin_url('admin.php?page=wc-settings&tab=advanced§ion=mk_api'); ?>"><?php echo __('Click here to enter them', 'wc_makecommerce_domain'); ?></a> | |
| 280 | + <?php } else { ?> | |
| 188 | 281 | <a href="<?php echo admin_url('admin.php?page=wc-settings&tab=api§ion=mk_api'); ?>"><?php echo __('Click here to enter them', 'wc_makecommerce_domain'); ?></a> |
| 282 | + <?php } ?> | |
| 189 | 283 | </p> |
| 190 | 284 | </div> |
| 191 | 285 | <?php |
| 192 | 286 | } |
| @@ -215,12 +309,12 @@ | ||
| 215 | 309 | |
| 216 | 310 | |
| 217 | 311 | public function init_form_fields() { |
| 218 | 312 | |
| 219 | - if ( function_exists('icl_object_id') && ! defined( 'POLYLANG_VERSION' ) ) { | |
| 313 | + if ( function_exists('icl_object_id') && !function_exists('pll_languages_list')) { | |
| 220 | 314 | $languages = apply_filters('wpml_active_languages', NULL, 'skip_missing=0'); |
| 221 | 315 | } |
| 222 | - else if ( defined( 'POLYLANG_VERSION' ) ) { | |
| 316 | + else if (function_exists('pll_languages_list')) { | |
| 223 | 317 | $pl_locales = pll_languages_list( array('fields'=>'locale') ); |
| 224 | 318 | foreach ($pl_locales as $key => $locale_pl ) { |
| 225 | 319 | $language = array( 'id' => $key, |
| 226 | 320 | 'code' => $locale_pl) ; |
| @@ -235,11 +329,12 @@ | ||
| 235 | 329 | 'type' => 'checkbox', |
| 236 | 330 | 'label' => __('Enable MakeCommerce payments', 'wc_makecommerce_domain'), |
| 237 | 331 | 'default' => 'no' |
| 238 | 332 | ); |
| 333 | + if (mk_wc_version("3.4.0")) $a = admin_url('admin.php?page=wc-settings&tab=advanced§ion=mk_api'); else $a = admin_url('admin.php?page=wc-settings&tab=api§ion=mk_api'); | |
| 239 | 334 | $this->form_fields['api_title'] = array( |
| 240 | 335 | 'title' => __('MakeCommerce API', 'wc_makecommerce_domain'), |
| 241 | - 'description' => sprintf(__('Go to <a href="%s">API settings</a> to fill in the credentials', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=api§ion=mk_api')), | |
| 336 | + 'description' => sprintf(__('Go to <a href="%s">API settings</a> to fill in the credentials', 'wc_makecommerce_domain'), $a), | |
| 242 | 337 | 'type' => 'title', |
| 243 | 338 | ); |
| 244 | 339 | $this->form_fields['ui_title'] = array( |
| 245 | 340 | 'title' => '<br>'.__('User Interface', 'wc_makecommerce_domain'), |
| @@ -274,27 +369,13 @@ | ||
| 274 | 369 | 'class' => 'ui-identifier', |
| 275 | 370 | ); |
| 276 | 371 | } else { |
| 277 | 372 | foreach ($languages as $language_code => $language) { |
| 278 | - $language_name = !empty($language['translated_name']) ? $language['translated_name'] : $language_code; | |
| 279 | - $defaultTitle = __('Pay with bank-links or credit card', 'wc_makecommerce_domain'); | |
| 280 | - switch ($language_code) { | |
| 281 | - case 'et': | |
| 282 | - $defaultTitle = 'Maksa pangalingi või krediitkaardiga'; | |
| 283 | - break; | |
| 284 | - case 'ru': | |
| 285 | - $defaultTitle = 'оплата в интернет-банке или кредитной картой'; | |
| 286 | - break; | |
| 287 | - case 'fi': | |
| 288 | - $defaultTitle = 'Maksaa verkkopankissa tai luottokortilla'; | |
| 289 | - break; | |
| 290 | - } | |
| 291 | 373 | $this->form_fields['ui_widget_title_'.$language_code] = array( |
| 292 | 374 | 'title' => __('Payments widget title', 'wc_makecommerce_domain').sprintf(' (%s)', $language_code), |
| 293 | 375 | 'type' => 'text', |
| 294 | 376 | 'desc_tip' => __("Appropriate title may depend on the configuration you have made, i.e. 'pay with bank-link or credit card', 'pay with bank-links' or 'payment methods'", 'wc_makecommerce_domain'), |
| 295 | - | |
| 296 | - 'default' => $defaultTitle, | |
| 377 | + 'default' => $this->getLanguageVersion('Pay with bank-links or credit card', 'wc_makecommerce_domain', $language_code), | |
| 297 | 378 | 'class' => 'ui-identifier', |
| 298 | 379 | ); |
| 299 | 380 | } |
| 300 | 381 | } |
| @@ -376,10 +457,35 @@ | ||
| 376 | 457 | 'title' => __('Update payment methods', 'wc_makecommerce_domain'), |
| 377 | 458 | 'description' => __('Update', 'wc_makecommerce_domain'), |
| 378 | 459 | 'desc_tip' => __('This will update shop configuration from MakeCommerce servers.', 'wc_makecommerce_domain'), |
| 379 | 460 | ); |
| 461 | + | |
| 462 | + | |
| 380 | 463 | } |
| 381 | 464 | |
| 465 | + //returns the translation for the given string from the specified locale. | |
| 466 | + public function getLanguageVersion($string, $textdomain, $locale) | |
| 467 | + { | |
| 468 | + $file = plugin_dir_path(__FILE__) . 'languages/'.$textdomain . '-' . $locale . '.mo'; | |
| 469 | + | |
| 470 | + if (file_exists($file)) { | |
| 471 | + $mo = new MO(); | |
| 472 | + $mo->import_from_file($file); | |
| 473 | + | |
| 474 | + if (isset($mo->entries)) { | |
| 475 | + if (isset($mo->entries[$string])) { | |
| 476 | + if (isset($mo->entries[$string]->translations)) { | |
| 477 | + if (isset($mo->entries[$string]->translations[0])) { | |
| 478 | + $string = $mo->entries[$string]->translations[0]; | |
| 479 | + } | |
| 480 | + } | |
| 481 | + } | |
| 482 | + } | |
| 483 | + } | |
| 484 | + | |
| 485 | + return $string; | |
| 486 | + } | |
| 487 | + | |
| 382 | 488 | // Needed to render mc_hidden type fields in admin |
| 383 | 489 | public function generate_mc_hidden_html( $key, $data ) { |
| 384 | 490 | $field_key = $this->get_field_key($key); |
| 385 | 491 | ob_start(); |
| @@ -457,13 +563,15 @@ | ||
| 457 | 563 | |
| 458 | 564 | public function mc_banklinks_reload($force = false) { |
| 459 | 565 | if ($force || (defined('DOING_AJAX') && DOING_AJAX)) { |
| 460 | 566 | |
| 567 | + global $wp_version; | |
| 461 | 568 | global $wpdb; |
| 462 | 569 | global $mkDbTable; |
| 463 | 570 | |
| 464 | 571 | $request_params = array( |
| 465 | 572 | 'environment' => json_encode(array( |
| 573 | + 'system' => array('wordpress' => $wp_version, "php" => phpversion()), | |
| 466 | 574 | 'platform' => 'woocommerce '.$this->_getWooCommerce()->version, |
| 467 | 575 | 'module' => $this->id.' '.$this->version, |
| 468 | 576 | )), |
| 469 | 577 | ); |
| @@ -480,13 +588,29 @@ | ||
| 480 | 588 | return false; |
| 481 | 589 | } |
| 482 | 590 | |
| 483 | 591 | $tableName = $wpdb->prefix . $mkDbTable; |
| 592 | + $sql = "select count(*) as isLogoUrlSet from information_schema.columns where table_name='".$tableName."' and column_name='logo_url'"; | |
| 593 | + $methodstruct = $wpdb->get_results( $sql ); | |
| 594 | + if ($methodstruct[0]->isLogoUrlSet == 0) { | |
| 595 | + $wpdb->query('ALTER TABLE '.$tableName.' ADD COLUMN logo_url varchar(250)'); | |
| 596 | + } | |
| 597 | + | |
| 598 | + $sql = "select count(*) as min_amount from information_schema.columns where table_name='".$tableName."' and column_name='min_amount'"; | |
| 599 | + $methodstruct = $wpdb->get_results( $sql ); | |
| 600 | + if ($methodstruct[0]->min_amount == 0) { | |
| 601 | + $wpdb->query('ALTER TABLE '.$tableName.' ADD COLUMN min_amount mediumint(9) default 0'); | |
| 602 | + } | |
| 603 | + $sql = "select count(*) as max_amount from information_schema.columns where table_name='".$tableName."' and column_name='max_amount'"; | |
| 604 | + $methodstruct = $wpdb->get_results( $sql ); | |
| 605 | + if ($methodstruct[0]->max_amount == 0) { | |
| 606 | + $wpdb->query('ALTER TABLE '.$tableName.' ADD COLUMN max_amount mediumint(9) default 0'); | |
| 607 | + } | |
| 484 | 608 | $wpdb->query('TRUNCATE TABLE '.$tableName); |
| 485 | 609 | |
| 486 | 610 | if(isset($methods->banklinks)) { |
| 487 | 611 | foreach($methods->banklinks as $method) { |
| 488 | - $wpdb->insert($tableName, array('type' => 'banklink', 'country' => $method->country, 'name' => $method->name, 'url' => $method->url)); | |
| 612 | + $wpdb->insert($tableName, array('type' => 'banklink', 'country' => $method->country, 'name' => $method->name, 'url' => $method->url, 'logo_url' => $method->logo_url)); | |
| 489 | 613 | } |
| 490 | 614 | $updated = true; |
| 491 | 615 | } |
| 492 | 616 | |
| @@ -491,13 +615,31 @@ | ||
| 491 | 615 | } |
| 492 | 616 | |
| 493 | 617 | if(isset($methods->cards)) { |
| 494 | 618 | foreach($methods->cards as $method) { |
| 495 | - $wpdb->insert($tableName, array('type' => 'card', 'name' => $method->name)); | |
| 619 | + $wpdb->insert($tableName, array('type' => 'card', 'name' => $method->name, 'logo_url' => $method->logo_url)); | |
| 496 | 620 | } |
| 497 | 621 | $updated = true; |
| 498 | 622 | } |
| 499 | 623 | |
| 624 | + if(isset($methods->other)) { | |
| 625 | + foreach($methods->other as $method) { | |
| 626 | + $wpdb->insert($tableName, array('type' => 'other', 'country' => $method->country, 'name' => $method->name, 'url' => $method->url, 'logo_url' => $method->logo_url)); | |
| 627 | + } | |
| 628 | + $updated = true; | |
| 629 | + } | |
| 630 | + | |
| 631 | + if(isset($methods->payLater)) { | |
| 632 | + foreach($methods->payLater as $method) { | |
| 633 | + //not all payLater accounts have a max_amount parameter. Set them to NULL to avoid notice's | |
| 634 | + if (!isset($method->max_amount)) { | |
| 635 | + $method->max_amount = NULL; | |
| 636 | + } | |
| 637 | + | |
| 638 | + $wpdb->insert($tableName, array('type' => 'payLater', 'country' => $method->country, 'name' => $method->name, 'url' => $method->url, 'logo_url' => $method->logo_url, 'min_amount' => $method->min_amount, 'max_amount' => $method->max_amount)); | |
| 639 | + } | |
| 640 | + $updated = true; | |
| 641 | + } | |
| 500 | 642 | if(isset($shopConfig) && strlen($shopConfig->name)) { |
| 501 | 643 | update_option( 'mc_shop_name', $shopConfig->name ); |
| 502 | 644 | } |
| 503 | 645 | |
| @@ -520,8 +662,64 @@ | ||
| 520 | 662 | } |
| 521 | 663 | die(); |
| 522 | 664 | } |
| 523 | 665 | |
| 666 | + | |
| 667 | + public function process_subscripion_payment_start($amount_to_charge, $renewal_order, $product_id = '') { | |
| 668 | + $result = $this->process_subscription_payment($renewal_order, $amount_to_charge); | |
| 669 | + if ( is_wp_error( $result ) ) { | |
| 670 | + WC_Subscriptions_Manager::process_subscription_payment_failure_on_order($renewal_order, $product_id); | |
| 671 | + } else { | |
| 672 | + WC_Subscriptions_Manager::process_subscription_payments_on_order($renewal_order); | |
| 673 | + } | |
| 674 | + } | |
| 675 | + | |
| 676 | + public function process_subscription_payment($order, $amount = 0) { | |
| 677 | + if (0 === $amount) { | |
| 678 | + $order->payment_complete(); | |
| 679 | + return true; | |
| 680 | + } // if ('processing' === $order->get_status() || 'completed' === $order->get_status()){ // ('processing' === $order->get_status()) | |
| 681 | + if ('processing' === $order->get_status() || 'completed' === $order->get_status()){ | |
| 682 | + return true; | |
| 683 | + } | |
| 684 | + $oorder_id = @WC_Subscriptions_Renewal_Order::get_parent_order_id($order); | |
| 685 | + $payment_token = get_post_meta($oorder_id, '_makecommerce_payment_token', true); | |
| 686 | + $payment_token_valid_until = get_post_meta($oorder_id, '_makecommerce_payment_token_valid_until', true); | |
| 687 | + error_log($payment_token.'=>'. $payment_token_valid_until.'=>'. $order->get_status()); | |
| 688 | + $body = array( | |
| 689 | + 'transaction' => array( | |
| 690 | + 'amount' => (string)sprintf("%.2f", $amount), | |
| 691 | + 'currency' => method_exists($order, 'get_currency') ? $order->get_currency() : $order->currency, | |
| 692 | + 'reference' => $order->get_id(), | |
| 693 | + ), | |
| 694 | + 'customer' => array( | |
| 695 | + 'email' => $order->get_billing_email(), | |
| 696 | + 'ip' => $order->get_customer_ip_address(), | |
| 697 | + 'country' => strtolower($order->get_billing_country()), | |
| 698 | + 'locale' => strtolower(substr(get_locale(), 0, 2)), | |
| 699 | + ) | |
| 700 | + ); | |
| 701 | + $transaction = $this->MK->createTransaction($body); | |
| 702 | + $paymentRequest = array( | |
| 703 | + 'amount' => (string)sprintf("%.2f", $transaction->amount), | |
| 704 | + 'currency' => $transaction->currency, | |
| 705 | + 'token' => $payment_token | |
| 706 | + ); | |
| 707 | + try { | |
| 708 | + $payment = $this->MK->createPayment($transaction->id, $paymentRequest); | |
| 709 | + } catch (Exception $e) { | |
| 710 | + error_log('Payment failed ['.$e->getMessage().']'); | |
| 711 | + $order->add_order_note(__('Unable to renew subscription', 'wc_makecommerce_domain')."\r\n".$e->getMessage()); | |
| 712 | + return new WP_Error('makecommerce_payment_declined', __( 'Renewal payment was declined', 'wc_makecommerce_domain' ) ); | |
| 713 | + } | |
| 714 | + $orderNote = array(); | |
| 715 | + $orderNote[] = __('Transaction ID', 'wc_makecommerce_domain') . ': <a target=_blank href="'.$this->MK->getEnvUrls()->merchantUrl.'/merchant/shop/deals/detail.html?id='. $transaction->id .'">'.$transaction->id.'</a>'; | |
| 716 | + $orderNote[] = __('Payment option', 'wc_makecommerce_domain') . ': ' . get_post_meta($order->get_id(), '_makecommerce_preselected_method', true); | |
| 717 | + $order->add_order_note(implode("\r\n", $orderNote)); | |
| 718 | + $order->payment_complete($transaction->id); | |
| 719 | + return true; | |
| 720 | + } | |
| 721 | + | |
| 524 | 722 | public function admin_order_page($order) { |
| 525 | 723 | // |
| 526 | 724 | } |
| 527 | 725 | |
| @@ -529,10 +727,14 @@ | ||
| 529 | 727 | if ($this->MK) { |
| 530 | 728 | try { |
| 531 | 729 | $order = new WC_Order($order_id); |
| 532 | 730 | $transactionId = $order->get_transaction_id(); |
| 731 | + | |
| 732 | + if ( empty($transactionId) ) { | |
| 733 | + $transactionId = get_post_meta( $order_id, '_makecommerce_transaction_id', true); | |
| 734 | + } | |
| 533 | 735 | |
| 534 | - if($response = $this->MK->createRefund($transactionId, array('amount' => $amount, 'comment' => ($comment ? : 'refund')))) { | |
| 736 | + if($response = $this->MK->createRefund($transactionId, array('amount' => sprintf("%.2f", $amount), 'comment' => ($comment ? : 'refund')))) { | |
| 535 | 737 | if($status = (string)$response->transaction->status) { |
| 536 | 738 | switch($status) { |
| 537 | 739 | case self::MC_REFUNDED: |
| 538 | 740 | $order->add_order_note(sprintf(__('Refund completed for amount %s', 'wc_makecommerce_domain'), $amount)); |
| @@ -619,8 +821,9 @@ | ||
| 619 | 821 | <?php |
| 620 | 822 | } |
| 621 | 823 | |
| 622 | 824 | public function payment_fields() { |
| 825 | + | |
| 623 | 826 | |
| 624 | 827 | if($this->settings['ui_mode'] == 'inline') { |
| 625 | 828 | |
| 626 | 829 | ?> |
| @@ -630,9 +833,9 @@ | ||
| 630 | 833 | <input type="radio" id="makecommerce_method_picker_<?php echo $method->country.'_'.$method->name; ?>" name="PRESELECTED_METHOD_<?php echo $this->id; ?>" value="<?php echo $method->country.'_'.$method->name; ?>"/> |
| 631 | 834 | <label for="makecommerce_method_picker_<?php echo $method->country.'_'.$method->name; ?>"> |
| 632 | 835 | <span class="makecommerce-method-title"><?php if(in_array($this->settings['ui_inline_uselogo'], array('text', 'text_logo'))) { echo ucfirst($method->name); if(count($this->_banklinks_grouped) > 1) { echo ' ('.$this->getCountryName($method->country).')'; } } ?></span> |
| 633 | 836 | <?php if(in_array($this->settings['ui_inline_uselogo'], array('logo', 'text_logo'))) : ?> |
| 634 | - <div><img src="<?php echo $this->getImageUrl($method->name); ?>" title="<?php echo ucfirst($method->name); ?>" /></div> | |
| 837 | + <div><img src="<?php echo $method->logo_url; ?>" title="<?php echo ucfirst($method->name); ?>" /></div> | |
| 635 | 838 | <?php endif; ?> |
| 636 | 839 | </label> |
| 637 | 840 | </li> |
| 638 | 841 | <?php endforeach; ?> |
| @@ -641,13 +844,24 @@ | ||
| 641 | 844 | <input type="radio" id="makecommerce_method_picker_<?php echo 'card_'.$method->name; ?>" name="PRESELECTED_METHOD_<?php echo $this->id; ?>" value="<?php echo 'card_'.$method->name; ?>"/> |
| 642 | 845 | <label for="makecommerce_method_picker_<?php echo 'card_'.$method->name; ?>"> |
| 643 | 846 | <span class="makecommerce-method-title"><?php if(in_array($this->settings['ui_inline_uselogo'], array('text', 'text_logo'))) { echo ucfirst($method->name); } ?></span> |
| 644 | 847 | <?php if(in_array($this->settings['ui_inline_uselogo'], array('logo', 'text_logo'))) : ?> |
| 645 | - <div><img src="<?php echo $this->getImageUrl($method->name); ?>" title="<?php echo ucfirst($method->name); ?>" /></div> | |
| 848 | + <div><img src="<?php echo $method->logo_url; ?>" title="<?php echo ucfirst($method->name); ?>" /></div> | |
| 646 | 849 | <?php endif; ?> |
| 647 | 850 | </label> |
| 648 | 851 | </li> |
| 649 | 852 | <?php endforeach; ?> |
| 853 | + <?php foreach($this->_paylater as $method): ?> | |
| 854 | + <li class="makecommerce-picker-method"> | |
| 855 | + <input type="radio" id="makecommerce_method_picker_<?php echo $method->country.'_'.$method->name; ?>" name="PRESELECTED_METHOD_<?php echo $this->id; ?>" value="<?php echo $method->country.'_'.$method->name; ?>"/> | |
| 856 | + <label for="makecommerce_method_picker_<?php echo $method->country.'_'.$method->name; ?>"> | |
| 857 | + <span class="makecommerce-method-title"><?php if(in_array($this->settings['ui_inline_uselogo'], array('text', 'text_logo'))) { echo ucfirst($method->name); if(count($this->_banklinks_grouped) > 1) { echo ' ('.$this->getCountryName($method->country).')'; } } ?></span> | |
| 858 | + <?php if(in_array($this->settings['ui_inline_uselogo'], array('logo', 'text_logo'))) : ?> | |
| 859 | + <div><img src="<?php echo $method->logo_url; ?>" title="<?php echo ucfirst($method->name); ?>" /></div> | |
| 860 | + <?php endif; ?> | |
| 861 | + </label> | |
| 862 | + </li> | |
| 863 | + <?php endforeach; ?> | |
| 650 | 864 | </ul> |
| 651 | 865 | <?php |
| 652 | 866 | |
| 653 | 867 | } else { |
| @@ -659,12 +873,16 @@ | ||
| 659 | 873 | <?php endforeach; ?> |
| 660 | 874 | <?php foreach($this->_cards as $method): ?> |
| 661 | 875 | <option value="card_<?php echo $method->name; ?>"><?php echo ucfirst($method->name); ?></option> |
| 662 | 876 | <?php endforeach; ?> |
| 877 | + <?php foreach($this->_paylater as $method): ?> | |
| 878 | + <option value="<?php echo $method->country.'_'.$method->name; ?>"><?php echo strtoupper($method->country).' - '.ucfirst($method->name); ?></option> | |
| 879 | + <?php endforeach; ?> | |
| 663 | 880 | </select> |
| 664 | 881 | <ul class="makecommerce-picker"> |
| 665 | 882 | <?php |
| 666 | - | |
| 883 | + global $woocommerce; | |
| 884 | + $cartTotal = $woocommerce->cart->total; | |
| 667 | 885 | if($this->_banklinks || $this->_cards) { |
| 668 | 886 | $defaultCountry = $this->getDefaultCountry(); |
| 669 | 887 | ?> |
| 670 | 888 | <?php if( ( empty($this->settings['ui_widget_groupcountries']) || $this->settings['ui_widget_groupcountries'] == 'no' ) && (!isset($this->settings['ui_widget_countries_hidden']) || $this->settings['ui_widget_countries_hidden'] == 'no') ) : ?> |
| @@ -693,9 +911,9 @@ | ||
| 693 | 911 | <?php endif; ?> |
| 694 | 912 | <div class="makecommerce_country_picker_methods" id="makecommerce_country_picker_methods_<?php echo $country; ?>"> |
| 695 | 913 | <?php foreach($methods as $method): ?> |
| 696 | 914 | <div class="makecommerce-banklink-picker" banklink_id="<?php echo $method->country.'_'.$method->name; ?>"> |
| 697 | - <img src="<?php echo $this->getImageUrl($method->name); ?>" title="<?php echo ucfirst($method->name); ?>" /> | |
| 915 | + <img src="<?php echo $method->logo_url; ?>" title="<?php echo ucfirst($method->name); ?>" /> | |
| 698 | 916 | </div> |
| 699 | 917 | <?php endforeach; ?> |
| 700 | 918 | <?php if($this->_cards && $this->settings['ui_widget_groupcc'] == 'no') : ?> |
| 701 | 919 | <div class="breaker"></div> |
| @@ -700,9 +918,9 @@ | ||
| 700 | 918 | <?php if($this->_cards && $this->settings['ui_widget_groupcc'] == 'no') : ?> |
| 701 | 919 | <div class="breaker"></div> |
| 702 | 920 | <?php foreach($this->_cards as $method): ?> |
| 703 | 921 | <div class="makecommerce-banklink-picker" banklink_id="card_<?php echo $method->name; ?>"> |
| 704 | - <img src="<?php echo $this->getImageUrl($method->name); ?>" title="<?php echo ucfirst($method->name); ?>" /> | |
| 922 | + <img src="<?php echo $method->logo_url; ?>" title="<?php echo ucfirst($method->name); ?>" /> | |
| 705 | 923 | </div> |
| 706 | 924 | <?php endforeach; ?> |
| 707 | 925 | <?php elseif($country == 'other') :?> |
| 708 | 926 | <p class="no-methods"><?php _e('No payment methods for selected country' ,'wc_makecommerce_domain');?></p> |
| @@ -715,14 +933,39 @@ | ||
| 715 | 933 | <input type="radio" id="makecommerce_country_picker_card" name="makecommerce_country_picker" value="card"/><label for="makecommerce_country_picker_card"><?php echo $this->settings['ui_widget_groupcc_title']; ?></label> |
| 716 | 934 | <div class="makecommerce_country_picker_methods" id="makecommerce_country_picker_methods_card"> |
| 717 | 935 | <?php foreach($this->_cards as $method): ?> |
| 718 | 936 | <div class="makecommerce-banklink-picker" banklink_id="card_<?php echo $method->name; ?>"> |
| 719 | - <img src="<?php echo $this->getImageUrl($method->name); ?>" title="<?php echo ucfirst($method->name); ?>" /> | |
| 937 | + <img src="<?php echo $method->logo_url; ?>" title="<?php echo ucfirst($method->name); ?>" /> | |
| 720 | 938 | </div> |
| 721 | 939 | <?php endforeach; ?> |
| 722 | 940 | </div> |
| 723 | 941 | </li> |
| 724 | 942 | <?php endif; ?> |
| 943 | + <?php | |
| 944 | + $paylater_grouped = $this->_paylater_grouped; | |
| 945 | + $paylater_grouped['other'] = array(); | |
| 946 | + ?> | |
| 947 | + <?php foreach($paylater_grouped as $country => $methods): ?> | |
| 948 | + <li class="makecommerce-picker-country"> | |
| 949 | + <?php if($this->settings['ui_widget_groupcountries'] == 'yes') : ?> | |
| 950 | + <input type="radio" id="makecommerce_country_picker_<?php echo $country; ?>" name="makecommerce_country_picker" value="<?php echo $country; ?>" <?php if($defaultCountry == $country) echo 'checked="checked" '; ?>/><label for="makecommerce_country_picker_<?php echo $country; ?>"><img src="<?php echo plugins_url('/images/'.$country.'32.png', __FILE__); ?>" /></label> | |
| 951 | + <?php endif; ?> | |
| 952 | + <div class="makecommerce_country_picker_methods" id="makecommerce_country_picker_methods_<?php echo $country; ?>"> | |
| 953 | + <?php foreach($methods as $method): ?> | |
| 954 | + <?php if (($method->min_amount < $cartTotal && $method->max_amount == 0) || ($method->min_amount < $cartTotal && $method->max_amount > $cartTotal)): ?> | |
| 955 | + <div class="makecommerce-banklink-picker" banklink_id="<?php echo $method->country.'_'.$method->name; ?>" <?php /* // Slice Promo 3 | |
| 956 | + if ((get_option('mk_checkout_slice', 'yes') == 'yes') && ($method->name == 'slice')) echo 'style="position: relative; display: inline-block;"'; */ ?>> | |
| 957 | + <img src="<?php echo $method->logo_url; ?>" title="<?php echo ucfirst($method->name); ?> "/> | |
| 958 | + </div> | |
| 959 | + <?php endif; ?> | |
| 960 | + <?php endforeach; ?> | |
| 961 | + <?php if($this->_cards && $this->settings['ui_widget_groupcc'] == 'no') : ?> | |
| 962 | + <?php elseif($country == 'other') :?> | |
| 963 | + <p class="no-methods"><?php _e('No payment methods for selected country' ,'wc_makecommerce_domain');?></p> | |
| 964 | + <?php endif; ?> | |
| 965 | + </div> | |
| 966 | + </li> | |
| 967 | + <?php endforeach; ?> | |
| 725 | 968 | <?php |
| 726 | 969 | } |
| 727 | 970 | ?> |
| 728 | 971 | </ul> |
| @@ -741,16 +984,18 @@ | ||
| 741 | 984 | <?php else: ?> |
| 742 | 985 | makecommercePick(); |
| 743 | 986 | |
| 744 | 987 | jQuery('body').on('change', 'select[name=makecommerce_country_picker_select]', function() { |
| 745 | - selectedCountry = jQuery(this).val(); | |
| 746 | - jQuery('input[name=makecommerce_country_picker]').removeAttr('checked'); | |
| 747 | - makecommercePick(); | |
| 988 | + selectedCountry = jQuery(this).val(); | |
| 989 | + jQuery('input[name=makecommerce_country_picker]').removeAttr('checked'); | |
| 990 | + makecommercePick(); | |
| 748 | 991 | }); |
| 749 | 992 | jQuery('body').on('change', 'input[name=makecommerce_country_picker]', function() { |
| 993 | + if(jQuery(this).is(":checked")) { | |
| 750 | 994 | selectedCountry = jQuery(this).val(); |
| 751 | 995 | jQuery('select[name=makecommerce_country_picker_select]').val(selectedCountry); |
| 752 | 996 | makecommercePick(); |
| 997 | + } | |
| 753 | 998 | }); |
| 754 | 999 | |
| 755 | 1000 | function makecommercePick() { |
| 756 | 1001 | jQuery('select#'+makecommerceId).val(''); |
| @@ -820,10 +1065,9 @@ | ||
| 820 | 1065 | return key($this->_banklinks_grouped); |
| 821 | 1066 | } |
| 822 | 1067 | |
| 823 | 1068 | |
| 824 | - protected function getImageUrl($methodName) { | |
| 825 | - //$imageUrlPath = 'https://static.maksekeskus.ee/img/channel/lnd/'; | |
| 1069 | + protected function getImageUrl($methodName) { // remove it | |
| 826 | 1070 | $imageUrlPath = $this->MK->getEnvUrls()->staticsUrl.'img/channel/lnd/'; |
| 827 | 1071 | return $imageUrlPath.$methodName.'.png'; |
| 828 | 1072 | } |
| 829 | 1073 | |
| @@ -848,15 +1092,15 @@ | ||
| 848 | 1092 | $selected = isset($_POST['PRESELECTED_METHOD_' . $this->id]) ? sanitize_text_field($_POST['PRESELECTED_METHOD_' . $this->id]) : false; |
| 849 | 1093 | |
| 850 | 1094 | if (!empty($selected)) { |
| 851 | 1095 | |
| 852 | - update_post_meta($order->id, '_makecommerce_preselected_method', $selected); | |
| 1096 | + update_post_meta($order->get_id(), '_makecommerce_preselected_method', $selected); | |
| 853 | 1097 | |
| 854 | 1098 | $request_body = array( |
| 855 | 1099 | 'transaction' => array( |
| 856 | - 'amount' => round($order->order_total, 2), | |
| 857 | - 'currency' => $order->get_order_currency(), | |
| 858 | - 'reference' => $order->id, | |
| 1100 | + 'amount' => (string)sprintf("%.2f", $order->get_total()), | |
| 1101 | + 'currency' => method_exists($order, 'get_currency') ? $order->get_currency() : $order->currency, | |
| 1102 | + 'reference' => $order->get_id(), | |
| 859 | 1103 | 'transaction_url' => array( |
| 860 | 1104 | 'return_url' => array( |
| 861 | 1105 | 'url' => $this->payment_return_url, |
| 862 | 1106 | 'method' => 'POST', |
| @@ -872,9 +1116,9 @@ | ||
| 872 | 1116 | ), |
| 873 | 1117 | ), |
| 874 | 1118 | 'customer' => array( |
| 875 | 1119 | 'ip' => $_SERVER['REMOTE_ADDR'], |
| 876 | - 'country' => strtolower($order->billing_country), | |
| 1120 | + 'country' => strtolower($order->get_billing_country()), | |
| 877 | 1121 | 'locale' => strtolower(substr(get_locale(), 0, 2)), |
| 878 | 1122 | ), |
| 879 | 1123 | ); |
| 880 | 1124 | $transaction = $this->MK->createTransaction($request_body); |
| @@ -879,9 +1123,9 @@ | ||
| 879 | 1123 | ); |
| 880 | 1124 | $transaction = $this->MK->createTransaction($request_body); |
| 881 | 1125 | |
| 882 | 1126 | if(isset($transaction->id)) { |
| 883 | - update_post_meta($order->id, '_makecommerce_transaction_id', $transaction->id); | |
| 1127 | + update_post_meta($order->get_id(), '_makecommerce_transaction_id', $transaction->id); | |
| 884 | 1128 | if (substr($selected, 0, 5) == 'card_') { |
| 885 | 1129 | $redirect_url = $order->get_checkout_payment_url( true ); |
| 886 | 1130 | } else { |
| 887 | 1131 | $redirect_url = false; |
| @@ -912,35 +1156,16 @@ | ||
| 912 | 1156 | foreach($this->_banklinks as $method) { |
| 913 | 1157 | if($selected == $method->country.'_'.$method->name) |
| 914 | 1158 | return $method->url; |
| 915 | 1159 | } |
| 1160 | + foreach($this->_paylater as $method) { | |
| 1161 | + if($selected == $method->country.'_'.$method->name) | |
| 1162 | + return $method->url; | |
| 1163 | + } | |
| 916 | 1164 | |
| 917 | 1165 | return false; |
| 918 | 1166 | } |
| 919 | 1167 | |
| 920 | - /* | |
| 921 | - protected function _getOrderConfirmationUrl($order) { | |
| 922 | - | |
| 923 | - global $sitepress; | |
| 924 | - if(isset($sitepress)) { | |
| 925 | - $baseUrl = $sitepress->language_url( ICL_LANGUAGE_CODE ); | |
| 926 | - $lang = ICL_LANGUAGE_CODE; | |
| 927 | - } else { | |
| 928 | - $baseUrl = site_url(); | |
| 929 | - $lang = strtolower(substr(get_locale(), 0, 2)); | |
| 930 | - } | |
| 931 | - $url = add_query_arg( array( | |
| 932 | - 'makecommerce_card_pay' => '1', | |
| 933 | - 'order_id' => $order->id, | |
| 934 | - 'lang' => $lang, | |
| 935 | - ), $baseUrl); | |
| 936 | - | |
| 937 | - // $url = site_url('?makecommerce_card_pay=1&order_id='.$order->id.'&lang='.(defined('ICL_LANGUAGE_CODE') ? ICL_LANGUAGE_CODE : strtolower(substr(get_locale(), 0, 2)))); | |
| 938 | - return $url; | |
| 939 | - } | |
| 940 | - | |
| 941 | - */ | |
| 942 | - | |
| 943 | 1168 | public function receipt_page($orderId) { |
| 944 | 1169 | $order = new WC_Order($orderId); |
| 945 | 1170 | if (substr(get_post_meta($orderId, '_makecommerce_preselected_method', true), 0, 5) == 'card_' && $order->get_status() == 'pending') { |
| 946 | 1171 | echo "<br>".__('The order is still awaiting your payment', 'wc_makecommerce_domain')."<br>"; |
| @@ -950,26 +1175,33 @@ | ||
| 950 | 1175 | |
| 951 | 1176 | |
| 952 | 1177 | public function generateCardForm($orderId) { |
| 953 | 1178 | $order = new WC_Order($orderId); |
| 1179 | + $has_subscription = function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order); | |
| 954 | 1180 | $scriptSrc = htmlspecialchars($this->MK->getEnvUrls()->checkoutjsUrl.'checkout.js'); |
| 955 | - $transactionId = get_post_meta($order->id, '_makecommerce_transaction_id', true); | |
| 956 | - $idReference = $order->id; | |
| 1181 | + $transactionId = get_post_meta($order->get_id(), '_makecommerce_transaction_id', true); | |
| 1182 | + $idReference = $order->get_id(); | |
| 957 | 1183 | $jsParams = array( |
| 958 | 1184 | 'key' => $this->MK->getPublishableKey(), |
| 959 | 1185 | 'transaction' => $transactionId, |
| 960 | 1186 | 'selector' => '#submit_banklinkmakecommerce_payment_form', |
| 961 | - 'amount' => round($order->order_total, 2), | |
| 1187 | + 'amount' => sprintf("%.2F", $order->get_total()), | |
| 962 | 1188 | 'locale' => !empty($_GET['lang']) ? $_GET['lang'] : (defined('ICL_LANGUAGE_CODE') ? ICL_LANGUAGE_CODE : strtolower(substr(get_locale(), 0, 2))), |
| 963 | 1189 | 'open-on-load' => 'true', |
| 964 | - 'client-name' => ($this->settings['cc_pass_cust_data'] == 'yes' ? (string) ($order->billing_first_name . ' ' . $order->billing_last_name) : ''), | |
| 965 | - 'email' => ($this->settings['cc_pass_cust_data'] == 'yes' ? (string) $order->billing_email : ''), | |
| 1190 | + 'client-name' => ($this->settings['cc_pass_cust_data'] == 'yes' ? (string) ((method_exists($order, 'get_billing_first_name') ? $order->get_billing_first_name() : $order->billing_first_name) . ' ' . (method_exists($order, 'get_billing_last_name') ? $order->get_billing_last_name() : $order->billing_last_name)) : ''), | |
| 1191 | + 'email' => ($this->settings['cc_pass_cust_data'] == 'yes' ? (string) (method_exists($order, 'get_billing_email') ? $order->get_billing_email() : $order->billing_email) : ''), | |
| 966 | 1192 | 'name' => get_option('mc_shop_name', ''), |
| 967 | 1193 | 'description' => __('Order', 'woocommerce') . ' ' . (string) $idReference, |
| 968 | 1194 | 'completed' => 'makecommerce_cc_complete', |
| 969 | - 'currency' => 'EUR', | |
| 1195 | + 'currency' => method_exists($order, 'get_currency') ? $order->get_currency() : $order->currency, // $transaction->currency, // 'EUR', | |
| 970 | 1196 | 'backdrop-close' => 'false', |
| 971 | 1197 | ); |
| 1198 | + if ($has_subscription) { | |
| 1199 | + $jsParams['recurring-required'] = 'true'; | |
| 1200 | + $jsParams['recurring-title'] = __('Pay for subscription', 'wc_makecommerce_domain'); | |
| 1201 | + $jsParams['recurring-description'] = __('This order contains subscriptions', 'wc_makecommerce_domain'); | |
| 1202 | + $jsParams['recurring-confirmation'] = __('I agree that my card will be recurringly billed by this store', 'wc_makecommerce_domain'); | |
| 1203 | + } | |
| 972 | 1204 | ?> |
| 973 | 1205 | <script type="text/javascript"> |
| 974 | 1206 | function makecommerce_cc_complete(data) { |
| 975 | 1207 | if(data.paymentToken) { |
| @@ -1004,8 +1236,9 @@ | ||
| 1004 | 1236 | public function makecommerce_return_trigger($vars) { |
| 1005 | 1237 | $vars[] = 'makecommerce_return'; |
| 1006 | 1238 | $vars[] = 'ajax_content'; |
| 1007 | 1239 | $vars[] = 'makecommerce_card_pay'; |
| 1240 | + $vars[] = 'lang1'; | |
| 1008 | 1241 | return $vars; |
| 1009 | 1242 | } |
| 1010 | 1243 | |
| 1011 | 1244 | public function makecommerce_return_trigger_check() { |
| @@ -1025,9 +1258,9 @@ | ||
| 1025 | 1258 | |
| 1026 | 1259 | New woocommerce_makecommerce(true); |
| 1027 | 1260 | |
| 1028 | 1261 | // Woocommerce Multilingual overrides |
| 1029 | - if ( in_array( 'woocommerce-multilingual/wpml-woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { | |
| 1262 | + if (is_plugin_active('woocommerce-multilingual/wpml-woocommerce.php') || function_exists('pll_languages_list')) { | |
| 1030 | 1263 | add_filter( 'get_post_metadata', 'mc_override_payment_method_string', 5, 4 ); |
| 1031 | 1264 | } |
| 1032 | 1265 | |
| 1033 | 1266 | } // init ends here |
| @@ -1042,9 +1275,8 @@ | ||
| 1042 | 1275 | |
| 1043 | 1276 | add_action('plugins_loaded', 'woocommerce_payment_makecommerce_init'); |
| 1044 | 1277 | add_action('woocommerce_payment_gateways', 'woocommerce_payment_makecommerce_add'); |
| 1045 | 1278 | |
| 1046 | - | |
| 1047 | 1279 | // Banklinks update wrapper for action |
| 1048 | 1280 | function update_mc_banklinks() { |
| 1049 | 1281 | $obj = new woocommerce_makecommerce(true); |
| 1050 | 1282 | $obj->mc_banklinks_reload(true); |
| @@ -1049,18 +1281,21 @@ | ||
| 1049 | 1281 | $obj = new woocommerce_makecommerce(true); |
| 1050 | 1282 | $obj->mc_banklinks_reload(true); |
| 1051 | 1283 | } |
| 1052 | 1284 | |
| 1285 | + function mc_override_payment_method_string($check, $object_id, $meta_key, $single) | |
| 1286 | + { | |
| 1287 | + if ($meta_key == '_payment_method_title') { | |
| 1288 | + $payment_method = get_post_meta($object_id, '_payment_method', true); | |
| 1289 | + | |
| 1290 | + if ($payment_method == 'makecommerce') { | |
| 1291 | + $payment_gateways = WC()->payment_gateways->payment_gateways(); | |
| 1053 | 1292 | |
| 1054 | - function mc_override_payment_method_string( $check, $object_id, $meta_key, $single ){ | |
| 1055 | - if($meta_key == '_payment_method_title') { | |
| 1056 | - $payment_method = get_post_meta( $object_id, '_payment_method', true ); | |
| 1057 | - if( $payment_method == 'makecommerce' ){ | |
| 1058 | - $payment_gateways = WC()->payment_gateways->payment_gateways(); | |
| 1059 | - if( isset( $payment_gateways[ $payment_method ] ) ){ | |
| 1060 | - $title = $payment_gateways[ $payment_method ]->title; | |
| 1061 | - return $title; | |
| 1062 | - } | |
| 1063 | - } | |
| 1064 | - } | |
| 1065 | - return $check; | |
| 1066 | - } | |
| 1293 | + if (isset($payment_gateways[$payment_method])) { | |
| 1294 | + $title = $payment_gateways[$payment_method]->title; | |
| 1295 | + | |
| 1296 | + return $title; | |
| 1297 | + } | |
| 1298 | + } | |
| 1299 | + } | |
| 1300 | + return $check; | |
| 1301 | + } | |