PluginProbe
MakeCommerce for WooCommerce / 2.6.2
MakeCommerce for WooCommerce v2.6.2
4.1.0 4.0.8 trunk 1.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 2.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2.0 2.2.1 2.2.2 All 96 releases
← All changes | makecommerce-payment.php +326 -97 2.2.22.6.2 View file →
@@ -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.2.0';
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&section=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&section=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&section=mk_api'); else $a = admin_url('admin.php?page=wc-settings&tab=api&section=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&section=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
@@ -534,9 +732,9 @@
534 732 if ( empty($transactionId) ) {
535 733 $transactionId = get_post_meta( $order_id, '_makecommerce_transaction_id', true);
536 734 }
537 735
538 - 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')))) {
539 737 if($status = (string)$response->transaction->status) {
540 738 switch($status) {
541 739 case self::MC_REFUNDED:
542 740 $order->add_order_note(sprintf(__('Refund completed for amount %s', 'wc_makecommerce_domain'), $amount));
@@ -623,8 +821,9 @@
623 821 <?php
624 822 }
625 823
626 824 public function payment_fields() {
825 +
627 826
628 827 if($this->settings['ui_mode'] == 'inline') {
629 828
630 829 ?>
@@ -634,9 +833,9 @@
634 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; ?>"/>
635 834 <label for="makecommerce_method_picker_<?php echo $method->country.'_'.$method->name; ?>">
636 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>
637 836 <?php if(in_array($this->settings['ui_inline_uselogo'], array('logo', 'text_logo'))) : ?>
638 - <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>
639 838 <?php endif; ?>
640 839 </label>
641 840 </li>
642 841 <?php endforeach; ?>
@@ -645,13 +844,24 @@
645 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; ?>"/>
646 845 <label for="makecommerce_method_picker_<?php echo 'card_'.$method->name; ?>">
647 846 <span class="makecommerce-method-title"><?php if(in_array($this->settings['ui_inline_uselogo'], array('text', 'text_logo'))) { echo ucfirst($method->name); } ?></span>
648 847 <?php if(in_array($this->settings['ui_inline_uselogo'], array('logo', 'text_logo'))) : ?>
649 - <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>
650 849 <?php endif; ?>
651 850 </label>
652 851 </li>
653 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; ?>
654 864 </ul>
655 865 <?php
656 866
657 867 } else {
@@ -663,12 +873,16 @@
663 873 <?php endforeach; ?>
664 874 <?php foreach($this->_cards as $method): ?>
665 875 <option value="card_<?php echo $method->name; ?>"><?php echo ucfirst($method->name); ?></option>
666 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; ?>
667 880 </select>
668 881 <ul class="makecommerce-picker">
669 882 <?php
670 -
883 + global $woocommerce;
884 + $cartTotal = $woocommerce->cart->total;
671 885 if($this->_banklinks || $this->_cards) {
672 886 $defaultCountry = $this->getDefaultCountry();
673 887 ?>
674 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') ) : ?>
@@ -697,9 +911,9 @@
697 911 <?php endif; ?>
698 912 <div class="makecommerce_country_picker_methods" id="makecommerce_country_picker_methods_<?php echo $country; ?>">
699 913 <?php foreach($methods as $method): ?>
700 914 <div class="makecommerce-banklink-picker" banklink_id="<?php echo $method->country.'_'.$method->name; ?>">
701 - <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); ?>" />
702 916 </div>
703 917 <?php endforeach; ?>
704 918 <?php if($this->_cards && $this->settings['ui_widget_groupcc'] == 'no') : ?>
705 919 <div class="breaker"></div>
@@ -704,9 +918,9 @@
704 918 <?php if($this->_cards && $this->settings['ui_widget_groupcc'] == 'no') : ?>
705 919 <div class="breaker"></div>
706 920 <?php foreach($this->_cards as $method): ?>
707 921 <div class="makecommerce-banklink-picker" banklink_id="card_<?php echo $method->name; ?>">
708 - <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); ?>" />
709 923 </div>
710 924 <?php endforeach; ?>
711 925 <?php elseif($country == 'other') :?>
712 926 <p class="no-methods"><?php _e('No payment methods for selected country' ,'wc_makecommerce_domain');?></p>
@@ -719,14 +933,39 @@
719 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>
720 934 <div class="makecommerce_country_picker_methods" id="makecommerce_country_picker_methods_card">
721 935 <?php foreach($this->_cards as $method): ?>
722 936 <div class="makecommerce-banklink-picker" banklink_id="card_<?php echo $method->name; ?>">
723 - <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); ?>" />
724 938 </div>
725 939 <?php endforeach; ?>
726 940 </div>
727 941 </li>
728 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; ?>
729 968 <?php
730 969 }
731 970 ?>
732 971 </ul>
@@ -826,10 +1065,9 @@
826 1065 return key($this->_banklinks_grouped);
827 1066 }
828 1067
829 1068
830 - protected function getImageUrl($methodName) {
831 - //$imageUrlPath = 'https://static.maksekeskus.ee/img/channel/lnd/';
1069 + protected function getImageUrl($methodName) { // remove it
832 1070 $imageUrlPath = $this->MK->getEnvUrls()->staticsUrl.'img/channel/lnd/';
833 1071 return $imageUrlPath.$methodName.'.png';
834 1072 }
835 1073
@@ -854,15 +1092,15 @@
854 1092 $selected = isset($_POST['PRESELECTED_METHOD_' . $this->id]) ? sanitize_text_field($_POST['PRESELECTED_METHOD_' . $this->id]) : false;
855 1093
856 1094 if (!empty($selected)) {
857 1095
858 - update_post_meta($order->id, '_makecommerce_preselected_method', $selected);
1096 + update_post_meta($order->get_id(), '_makecommerce_preselected_method', $selected);
859 1097
860 1098 $request_body = array(
861 1099 'transaction' => array(
862 - 'amount' => round($order->order_total, 2),
863 - 'currency' => $order->get_order_currency(),
864 - '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(),
865 1103 'transaction_url' => array(
866 1104 'return_url' => array(
867 1105 'url' => $this->payment_return_url,
868 1106 'method' => 'POST',
@@ -878,9 +1116,9 @@
878 1116 ),
879 1117 ),
880 1118 'customer' => array(
881 1119 'ip' => $_SERVER['REMOTE_ADDR'],
882 - 'country' => strtolower($order->billing_country),
1120 + 'country' => strtolower($order->get_billing_country()),
883 1121 'locale' => strtolower(substr(get_locale(), 0, 2)),
884 1122 ),
885 1123 );
886 1124 $transaction = $this->MK->createTransaction($request_body);
@@ -885,9 +1123,9 @@
885 1123 );
886 1124 $transaction = $this->MK->createTransaction($request_body);
887 1125
888 1126 if(isset($transaction->id)) {
889 - update_post_meta($order->id, '_makecommerce_transaction_id', $transaction->id);
1127 + update_post_meta($order->get_id(), '_makecommerce_transaction_id', $transaction->id);
890 1128 if (substr($selected, 0, 5) == 'card_') {
891 1129 $redirect_url = $order->get_checkout_payment_url( true );
892 1130 } else {
893 1131 $redirect_url = false;
@@ -918,35 +1156,16 @@
918 1156 foreach($this->_banklinks as $method) {
919 1157 if($selected == $method->country.'_'.$method->name)
920 1158 return $method->url;
921 1159 }
1160 + foreach($this->_paylater as $method) {
1161 + if($selected == $method->country.'_'.$method->name)
1162 + return $method->url;
1163 + }
922 1164
923 1165 return false;
924 1166 }
925 1167
926 - /*
927 - protected function _getOrderConfirmationUrl($order) {
928 -
929 - global $sitepress;
930 - if(isset($sitepress)) {
931 - $baseUrl = $sitepress->language_url( ICL_LANGUAGE_CODE );
932 - $lang = ICL_LANGUAGE_CODE;
933 - } else {
934 - $baseUrl = site_url();
935 - $lang = strtolower(substr(get_locale(), 0, 2));
936 - }
937 - $url = add_query_arg( array(
938 - 'makecommerce_card_pay' => '1',
939 - 'order_id' => $order->id,
940 - 'lang' => $lang,
941 - ), $baseUrl);
942 -
943 - // $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))));
944 - return $url;
945 - }
946 -
947 - */
948 -
949 1168 public function receipt_page($orderId) {
950 1169 $order = new WC_Order($orderId);
951 1170 if (substr(get_post_meta($orderId, '_makecommerce_preselected_method', true), 0, 5) == 'card_' && $order->get_status() == 'pending') {
952 1171 echo "<br>".__('The order is still awaiting your payment', 'wc_makecommerce_domain')."<br>";
@@ -956,26 +1175,33 @@
956 1175
957 1176
958 1177 public function generateCardForm($orderId) {
959 1178 $order = new WC_Order($orderId);
1179 + $has_subscription = function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order);
960 1180 $scriptSrc = htmlspecialchars($this->MK->getEnvUrls()->checkoutjsUrl.'checkout.js');
961 - $transactionId = get_post_meta($order->id, '_makecommerce_transaction_id', true);
962 - $idReference = $order->id;
1181 + $transactionId = get_post_meta($order->get_id(), '_makecommerce_transaction_id', true);
1182 + $idReference = $order->get_id();
963 1183 $jsParams = array(
964 1184 'key' => $this->MK->getPublishableKey(),
965 1185 'transaction' => $transactionId,
966 1186 'selector' => '#submit_banklinkmakecommerce_payment_form',
967 - 'amount' => round($order->order_total, 2),
1187 + 'amount' => sprintf("%.2F", $order->get_total()),
968 1188 'locale' => !empty($_GET['lang']) ? $_GET['lang'] : (defined('ICL_LANGUAGE_CODE') ? ICL_LANGUAGE_CODE : strtolower(substr(get_locale(), 0, 2))),
969 1189 'open-on-load' => 'true',
970 - 'client-name' => ($this->settings['cc_pass_cust_data'] == 'yes' ? (string) ($order->billing_first_name . ' ' . $order->billing_last_name) : ''),
971 - '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) : ''),
972 1192 'name' => get_option('mc_shop_name', ''),
973 1193 'description' => __('Order', 'woocommerce') . '&nbsp;' . (string) $idReference,
974 1194 'completed' => 'makecommerce_cc_complete',
975 - 'currency' => 'EUR',
1195 + 'currency' => method_exists($order, 'get_currency') ? $order->get_currency() : $order->currency, // $transaction->currency, // 'EUR',
976 1196 'backdrop-close' => 'false',
977 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 + }
978 1204 ?>
979 1205 <script type="text/javascript">
980 1206 function makecommerce_cc_complete(data) {
981 1207 if(data.paymentToken) {
@@ -1010,8 +1236,9 @@
1010 1236 public function makecommerce_return_trigger($vars) {
1011 1237 $vars[] = 'makecommerce_return';
1012 1238 $vars[] = 'ajax_content';
1013 1239 $vars[] = 'makecommerce_card_pay';
1240 + $vars[] = 'lang1';
1014 1241 return $vars;
1015 1242 }
1016 1243
1017 1244 public function makecommerce_return_trigger_check() {
@@ -1031,9 +1258,9 @@
1031 1258
1032 1259 New woocommerce_makecommerce(true);
1033 1260
1034 1261 // Woocommerce Multilingual overrides
1035 - if (is_plugin_active('woocommerce-multilingual/wpml-woocommerce.php')) {
1262 + if (is_plugin_active('woocommerce-multilingual/wpml-woocommerce.php') || function_exists('pll_languages_list')) {
1036 1263 add_filter( 'get_post_metadata', 'mc_override_payment_method_string', 5, 4 );
1037 1264 }
1038 1265
1039 1266 } // init ends here
@@ -1048,9 +1275,8 @@
1048 1275
1049 1276 add_action('plugins_loaded', 'woocommerce_payment_makecommerce_init');
1050 1277 add_action('woocommerce_payment_gateways', 'woocommerce_payment_makecommerce_add');
1051 1278
1052 -
1053 1279 // Banklinks update wrapper for action
1054 1280 function update_mc_banklinks() {
1055 1281 $obj = new woocommerce_makecommerce(true);
1056 1282 $obj->mc_banklinks_reload(true);
@@ -1055,18 +1281,21 @@
1055 1281 $obj = new woocommerce_makecommerce(true);
1056 1282 $obj->mc_banklinks_reload(true);
1057 1283 }
1058 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();
1059 1292
1060 - function mc_override_payment_method_string( $check, $object_id, $meta_key, $single ){
1061 - if($meta_key == '_payment_method_title') {
1062 - $payment_method = get_post_meta( $object_id, '_payment_method', true );
1063 - if( $payment_method == 'makecommerce' ){
1064 - $payment_gateways = WC()->payment_gateways->payment_gateways();
1065 - if( isset( $payment_gateways[ $payment_method ] ) ){
1066 - $title = $payment_gateways[ $payment_method ]->title;
1067 - return $title;
1068 - }
1069 - }
1070 - }
1071 - return $check;
1072 - }
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 + }