PluginProbe
MakeCommerce for WooCommerce / 2.6.0
MakeCommerce for WooCommerce v2.6.0
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 +242 -72 2.1.42.6.0 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.1.3';
26 + public $version = '2.6.0';
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,21 @@
56 71 $this->init_settings();
57 72
58 73 $this->initBanklinks();
59 74
60 - $this->title = $this->settings['ui_widget_title'];
61 75 if (defined('ICL_LANGUAGE_CODE') && !empty($this->settings['ui_widget_title_'.ICL_LANGUAGE_CODE])) {
62 76 $this->title = $this->settings['ui_widget_title_'.ICL_LANGUAGE_CODE];
77 + } else if (!empty($this->settings['ui_widget_title'])) {
78 + $this->title = $this->settings['ui_widget_title'];
79 + } else {
80 + $this->title = '';
63 81 }
82 +
64 83 $this->method_title = 'MakeCommerce';
65 84 $this->description = true;
66 85
86 + $this->enabled = $this->settings['active'];
87 +
67 88 $this->MK = mk_get_api();
68 89 if (!$this->MK && $this->_init) {
69 90 add_action( 'admin_notices', array(&$this, 'makecommerce_api_info_missing') );
70 91 }
@@ -69,14 +90,23 @@
69 90 add_action( 'admin_notices', array(&$this, 'makecommerce_api_info_missing') );
70 91 }
71 92
72 93 $this->supports = array(
94 + 'subscriptions',
95 + 'subscription_cancellation',
96 + 'subscription_suspension',
97 + 'subscription_reactivation',
98 + 'subscription_amount_changes',
99 + 'subscription_date_changes',
100 + 'subscription_payment_method_change',
73 101 'products',
74 - 'refunds',
102 + 'refunds'
75 103 );
76 104
77 105 add_filter('query_vars', array(&$this, 'makecommerce_return_trigger'));
78 106 add_action('template_redirect', array(&$this, 'makecommerce_return_trigger_check'));
107 + add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'process_subscripion_payment_start'), 10, 2);
108 + add_action('scheduled_subscription_payment_' . $this->id, array($this, 'process_subscripion_payment_start'), 10, 2);
79 109
80 110 if($this->_init == false) {
81 111 add_action('woocommerce_update_options_payment_gateways', array(&$this, 'process_admin_options'));
82 112 add_action('woocommerce_update_options_payment_gateways_' . $this->id, array(&$this, 'process_admin_options'));
@@ -88,8 +118,9 @@
88 118 wp_enqueue_style('makecommerce', plugins_url('/css/makecommerce.css', __FILE__), array(), $this->version);
89 119 }
90 120 if (is_admin()) {
91 121 add_action( 'wp_ajax_mc_banklinks_reload', array(&$this, 'mc_banklinks_reload') );
122 +
92 123 require_once(ABSPATH.'wp-admin/includes/plugin.php');
93 124 $wc_version = get_plugin_data(__DIR__.'/../woocommerce/woocommerce.php');
94 125 if ((double)$wc_version['Version'] < 2.6) {
95 126 function sample_admin_notice__error() {
@@ -118,11 +149,12 @@
118 149 return true;
119 150 }
120 151
121 152 public function is_available() {
122 - if ($this->settings['active'] == "yes" && mk_is_api_set()) {
123 - return true;
153 + if (!($this->settings['active'] == "yes" && mk_is_api_set())) {
154 + return false;
124 155 }
156 + return parent::is_available();
125 157 }
126 158
127 159 private function initBanklinks() {
128 160 global $wpdb;
@@ -127,8 +159,9 @@
127 159 private function initBanklinks() {
128 160 global $wpdb;
129 161 global $mkDbTable;
130 162 $this->_banklinks = array();
163 + $has_subscriptions = class_exists('WC_Subscriptions_Cart') && WC_Subscriptions_Cart::cart_contains_subscription();
131 164
132 165 $tableName = $wpdb->prefix . $mkDbTable;
133 166 $methods = $wpdb->get_results('SELECT * FROM '.$tableName);
134 167
@@ -139,13 +172,21 @@
139 172 }
140 173 $banklinks = array();
141 174 $banklinks_grouped = array();
142 175 $cards = array();
176 + $paylater = array();
177 + $paylater_grouped = array();
143 178 foreach($methods as $method) {
144 - if($method->type == 'banklink') {
145 - $banklinks[] = $banklinks_grouped[$method->country][] = $method;
179 + if($method->type == 'banklink'|| $method->type == 'other') {
180 + if (!$has_subscriptions) {
181 + $banklinks[] = $banklinks_grouped[$method->country][] = $method;
182 + }
146 183 } elseif($method->type == 'card') {
147 184 $cards[] = $method;
185 + } elseif($method->type == 'payLater') {
186 + if (!$has_subscriptions) {
187 + $paylater[] = $paylater_grouped[$method->country][] = $method;
188 + }
148 189 }
149 190 }
150 191
151 192 usort($banklinks, array($this, 'orderBanklinks'));
@@ -155,8 +196,10 @@
155 196
156 197 $this->_banklinks = $banklinks;
157 198 $this->_banklinks_grouped = $banklinks_grouped;
158 199 $this->_cards = $cards;
200 + $this->_paylater = $paylater;
201 + $this->_paylater_grouped = $paylater_grouped;
159 202 remove_action('admin_notices', array(&$this, 'makecommerce_banklinks_list_empty'), 30);
160 203 } elseif(is_admin() && $this->_init == true) {
161 204 add_action('admin_notices', array(&$this, 'makecommerce_banklinks_list_empty'), 30);
162 205 }
@@ -184,9 +227,13 @@
184 227 ?>
185 228 <div class="notice notice-error is-dismissible">
186 229 <p>
187 230 <?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'); ?>
231 + <?php if (mk_wc_version("3.4.0")) { ?>
232 + <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>
233 + <?php } else { ?>
188 234 <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>
235 + <?php } ?>
189 236 </p>
190 237 </div>
191 238 <?php
192 239 }
@@ -235,11 +282,12 @@
235 282 'type' => 'checkbox',
236 283 'label' => __('Enable MakeCommerce payments', 'wc_makecommerce_domain'),
237 284 'default' => 'no'
238 285 );
286 + 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 287 $this->form_fields['api_title'] = array(
240 288 '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')),
289 + 'description' => sprintf(__('Go to <a href="%s">API settings</a> to fill in the credentials', 'wc_makecommerce_domain'), $a),
242 290 'type' => 'title',
243 291 );
244 292 $this->form_fields['ui_title'] = array(
245 293 'title' => '<br>'.__('User Interface', 'wc_makecommerce_domain'),
@@ -286,14 +334,13 @@
286 334 break;
287 335 case 'fi':
288 336 $defaultTitle = 'Maksaa verkkopankissa tai luottokortilla';
289 337 break;
290 - }
291 - $this->form_fields['ui_widget_title_'.$language_code] = array(
338 + }
339 + $this->form_fields['ui_widget_title'] = array(
292 340 'title' => __('Payments widget title', 'wc_makecommerce_domain').sprintf(' (%s)', $language_code),
293 341 'type' => 'text',
294 342 '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 343 'default' => $defaultTitle,
297 344 'class' => 'ui-identifier',
298 345 );
299 346 }
@@ -480,13 +527,29 @@
480 527 return false;
481 528 }
482 529
483 530 $tableName = $wpdb->prefix . $mkDbTable;
531 + $sql = "select count(*) as isLogoUrlSet from information_schema.columns where table_name='".$tableName."' and column_name='logo_url'";
532 + $methodstruct = $wpdb->get_results( $sql );
533 + if ($methodstruct[0]->isLogoUrlSet == 0) {
534 + $wpdb->query('ALTER TABLE '.$tableName.' ADD COLUMN logo_url varchar(250)');
535 + }
536 +
537 + $sql = "select count(*) as min_amount from information_schema.columns where table_name='".$tableName."' and column_name='min_amount'";
538 + $methodstruct = $wpdb->get_results( $sql );
539 + if ($methodstruct[0]->min_amount == 0) {
540 + $wpdb->query('ALTER TABLE '.$tableName.' ADD COLUMN min_amount mediumint(9) default 0');
541 + }
542 + $sql = "select count(*) as max_amount from information_schema.columns where table_name='".$tableName."' and column_name='max_amount'";
543 + $methodstruct = $wpdb->get_results( $sql );
544 + if ($methodstruct[0]->max_amount == 0) {
545 + $wpdb->query('ALTER TABLE '.$tableName.' ADD COLUMN max_amount mediumint(9) default 0');
546 + }
484 547 $wpdb->query('TRUNCATE TABLE '.$tableName);
485 548
486 549 if(isset($methods->banklinks)) {
487 550 foreach($methods->banklinks as $method) {
488 - $wpdb->insert($tableName, array('type' => 'banklink', 'country' => $method->country, 'name' => $method->name, 'url' => $method->url));
551 + $wpdb->insert($tableName, array('type' => 'banklink', 'country' => $method->country, 'name' => $method->name, 'url' => $method->url, 'logo_url' => $method->logo_url));
489 552 }
490 553 $updated = true;
491 554 }
492 555
@@ -491,13 +554,31 @@
491 554 }
492 555
493 556 if(isset($methods->cards)) {
494 557 foreach($methods->cards as $method) {
495 - $wpdb->insert($tableName, array('type' => 'card', 'name' => $method->name));
558 + $wpdb->insert($tableName, array('type' => 'card', 'name' => $method->name, 'logo_url' => $method->logo_url));
496 559 }
497 560 $updated = true;
498 561 }
499 562
563 + if(isset($methods->other)) {
564 + foreach($methods->other as $method) {
565 + $wpdb->insert($tableName, array('type' => 'other', 'country' => $method->country, 'name' => $method->name, 'url' => $method->url, 'logo_url' => $method->logo_url));
566 + }
567 + $updated = true;
568 + }
569 +
570 + if(isset($methods->payLater)) {
571 + foreach($methods->payLater as $method) {
572 + //not all payLater accounts have a max_amount parameter. Set them to NULL to avoid notice's
573 + if (!isset($method->max_amount)) {
574 + $method->max_amount = NULL;
575 + }
576 +
577 + $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));
578 + }
579 + $updated = true;
580 + }
500 581 if(isset($shopConfig) && strlen($shopConfig->name)) {
501 582 update_option( 'mc_shop_name', $shopConfig->name );
502 583 }
503 584
@@ -520,8 +601,64 @@
520 601 }
521 602 die();
522 603 }
523 604
605 +
606 + public function process_subscripion_payment_start($amount_to_charge, $renewal_order, $product_id = '') {
607 + $result = $this->process_subscription_payment($renewal_order, $amount_to_charge);
608 + if ( is_wp_error( $result ) ) {
609 + WC_Subscriptions_Manager::process_subscription_payment_failure_on_order($renewal_order, $product_id);
610 + } else {
611 + WC_Subscriptions_Manager::process_subscription_payments_on_order($renewal_order);
612 + }
613 + }
614 +
615 + public function process_subscription_payment($order, $amount = 0) {
616 + if (0 === $amount) {
617 + $order->payment_complete();
618 + return true;
619 + } // if ('processing' === $order->get_status() || 'completed' === $order->get_status()){ // ('processing' === $order->get_status())
620 + if ('processing' === $order->get_status() || 'completed' === $order->get_status()){
621 + return true;
622 + }
623 + $oorder_id = @WC_Subscriptions_Renewal_Order::get_parent_order_id($order);
624 + $payment_token = get_post_meta($oorder_id, '_makecommerce_payment_token', true);
625 + $payment_token_valid_until = get_post_meta($oorder_id, '_makecommerce_payment_token_valid_until', true);
626 + error_log($payment_token.'=>'. $payment_token_valid_until.'=>'. $order->get_status());
627 + $body = array(
628 + 'transaction' => array(
629 + 'amount' => (string)sprintf("%.2f", $amount),
630 + 'currency' => method_exists($order, 'get_currency') ? $order->get_currency() : $order->currency,
631 + 'reference' => $order->get_id(),
632 + ),
633 + 'customer' => array(
634 + 'email' => $order->get_billing_email(),
635 + 'ip' => $order->get_customer_ip_address(),
636 + 'country' => strtolower($order->get_billing_country()),
637 + 'locale' => strtolower(substr(get_locale(), 0, 2)),
638 + )
639 + );
640 + $transaction = $this->MK->createTransaction($body);
641 + $paymentRequest = array(
642 + 'amount' => (string)sprintf("%.2f", $transaction->amount),
643 + 'currency' => $transaction->currency,
644 + 'token' => $payment_token
645 + );
646 + try {
647 + $payment = $this->MK->createPayment($transaction->id, $paymentRequest);
648 + } catch (Exception $e) {
649 + error_log('Payment failed ['.$e->getMessage().']');
650 + $order->add_order_note(__('Unable to renew subscription', 'wc_makecommerce_domain')."\r\n".$e->getMessage());
651 + return new WP_Error('makecommerce_payment_declined', __( 'Renewal payment was declined', 'wc_makecommerce_domain' ) );
652 + }
653 + $orderNote = array();
654 + $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>';
655 + $orderNote[] = __('Payment option', 'wc_makecommerce_domain') . ': ' . get_post_meta($order->get_id(), '_makecommerce_preselected_method', true);
656 + $order->add_order_note(implode("\r\n", $orderNote));
657 + $order->payment_complete($transaction->id);
658 + return true;
659 + }
660 +
524 661 public function admin_order_page($order) {
525 662 //
526 663 }
527 664
@@ -529,10 +666,14 @@
529 666 if ($this->MK) {
530 667 try {
531 668 $order = new WC_Order($order_id);
532 669 $transactionId = $order->get_transaction_id();
670 +
671 + if ( empty($transactionId) ) {
672 + $transactionId = get_post_meta( $order_id, '_makecommerce_transaction_id', true);
673 + }
533 674
534 - if($response = $this->MK->createRefund($transactionId, array('amount' => $amount, 'comment' => ($comment ? : 'refund')))) {
675 + if($response = $this->MK->createRefund($transactionId, array('amount' => sprintf("%.2f", $amount), 'comment' => ($comment ? : 'refund')))) {
535 676 if($status = (string)$response->transaction->status) {
536 677 switch($status) {
537 678 case self::MC_REFUNDED:
538 679 $order->add_order_note(sprintf(__('Refund completed for amount %s', 'wc_makecommerce_domain'), $amount));
@@ -619,8 +760,9 @@
619 760 <?php
620 761 }
621 762
622 763 public function payment_fields() {
764 +
623 765
624 766 if($this->settings['ui_mode'] == 'inline') {
625 767
626 768 ?>
@@ -630,9 +772,9 @@
630 772 <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 773 <label for="makecommerce_method_picker_<?php echo $method->country.'_'.$method->name; ?>">
632 774 <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 775 <?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>
776 + <div><img src="<?php echo $method->logo_url; ?>" title="<?php echo ucfirst($method->name); ?>" /></div>
635 777 <?php endif; ?>
636 778 </label>
637 779 </li>
638 780 <?php endforeach; ?>
@@ -641,13 +783,24 @@
641 783 <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 784 <label for="makecommerce_method_picker_<?php echo 'card_'.$method->name; ?>">
643 785 <span class="makecommerce-method-title"><?php if(in_array($this->settings['ui_inline_uselogo'], array('text', 'text_logo'))) { echo ucfirst($method->name); } ?></span>
644 786 <?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>
787 + <div><img src="<?php echo $method->logo_url; ?>" title="<?php echo ucfirst($method->name); ?>" /></div>
646 788 <?php endif; ?>
647 789 </label>
648 790 </li>
649 791 <?php endforeach; ?>
792 + <?php foreach($this->_paylater as $method): ?>
793 + <li class="makecommerce-picker-method">
794 + <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; ?>"/>
795 + <label for="makecommerce_method_picker_<?php echo $method->country.'_'.$method->name; ?>">
796 + <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>
797 + <?php if(in_array($this->settings['ui_inline_uselogo'], array('logo', 'text_logo'))) : ?>
798 + <div><img src="<?php echo $method->logo_url; ?>" title="<?php echo ucfirst($method->name); ?>" /></div>
799 + <?php endif; ?>
800 + </label>
801 + </li>
802 + <?php endforeach; ?>
650 803 </ul>
651 804 <?php
652 805
653 806 } else {
@@ -659,12 +812,16 @@
659 812 <?php endforeach; ?>
660 813 <?php foreach($this->_cards as $method): ?>
661 814 <option value="card_<?php echo $method->name; ?>"><?php echo ucfirst($method->name); ?></option>
662 815 <?php endforeach; ?>
816 + <?php foreach($this->_paylater as $method): ?>
817 + <option value="<?php echo $method->country.'_'.$method->name; ?>"><?php echo strtoupper($method->country).' - '.ucfirst($method->name); ?></option>
818 + <?php endforeach; ?>
663 819 </select>
664 820 <ul class="makecommerce-picker">
665 821 <?php
666 -
822 + global $woocommerce;
823 + $cartTotal = $woocommerce->cart->total;
667 824 if($this->_banklinks || $this->_cards) {
668 825 $defaultCountry = $this->getDefaultCountry();
669 826 ?>
670 827 <?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 +850,9 @@
693 850 <?php endif; ?>
694 851 <div class="makecommerce_country_picker_methods" id="makecommerce_country_picker_methods_<?php echo $country; ?>">
695 852 <?php foreach($methods as $method): ?>
696 853 <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); ?>" />
854 + <img src="<?php echo $method->logo_url; ?>" title="<?php echo ucfirst($method->name); ?>" />
698 855 </div>
699 856 <?php endforeach; ?>
700 857 <?php if($this->_cards && $this->settings['ui_widget_groupcc'] == 'no') : ?>
701 858 <div class="breaker"></div>
@@ -700,9 +857,9 @@
700 857 <?php if($this->_cards && $this->settings['ui_widget_groupcc'] == 'no') : ?>
701 858 <div class="breaker"></div>
702 859 <?php foreach($this->_cards as $method): ?>
703 860 <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); ?>" />
861 + <img src="<?php echo $method->logo_url; ?>" title="<?php echo ucfirst($method->name); ?>" />
705 862 </div>
706 863 <?php endforeach; ?>
707 864 <?php elseif($country == 'other') :?>
708 865 <p class="no-methods"><?php _e('No payment methods for selected country' ,'wc_makecommerce_domain');?></p>
@@ -715,14 +872,39 @@
715 872 <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 873 <div class="makecommerce_country_picker_methods" id="makecommerce_country_picker_methods_card">
717 874 <?php foreach($this->_cards as $method): ?>
718 875 <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); ?>" />
876 + <img src="<?php echo $method->logo_url; ?>" title="<?php echo ucfirst($method->name); ?>" />
720 877 </div>
721 878 <?php endforeach; ?>
722 879 </div>
723 880 </li>
724 881 <?php endif; ?>
882 + <?php
883 + $paylater_grouped = $this->_paylater_grouped;
884 + $paylater_grouped['other'] = array();
885 + ?>
886 + <?php foreach($paylater_grouped as $country => $methods): ?>
887 + <li class="makecommerce-picker-country">
888 + <?php if($this->settings['ui_widget_groupcountries'] == 'yes') : ?>
889 + <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>
890 + <?php endif; ?>
891 + <div class="makecommerce_country_picker_methods" id="makecommerce_country_picker_methods_<?php echo $country; ?>">
892 + <?php foreach($methods as $method): ?>
893 + <?php if (($method->min_amount < $cartTotal && $method->max_amount == 0) || ($method->min_amount < $cartTotal && $method->max_amount > $cartTotal)): ?>
894 + <div class="makecommerce-banklink-picker" banklink_id="<?php echo $method->country.'_'.$method->name; ?>" <?php /* // Slice Promo 3
895 + if ((get_option('mk_checkout_slice', 'yes') == 'yes') && ($method->name == 'slice')) echo 'style="position: relative; display: inline-block;"'; */ ?>>
896 + <img src="<?php echo $method->logo_url; ?>" title="<?php echo ucfirst($method->name); ?> "/>
897 + </div>
898 + <?php endif; ?>
899 + <?php endforeach; ?>
900 + <?php if($this->_cards && $this->settings['ui_widget_groupcc'] == 'no') : ?>
901 + <?php elseif($country == 'other') :?>
902 + <p class="no-methods"><?php _e('No payment methods for selected country' ,'wc_makecommerce_domain');?></p>
903 + <?php endif; ?>
904 + </div>
905 + </li>
906 + <?php endforeach; ?>
725 907 <?php
726 908 }
727 909 ?>
728 910 </ul>
@@ -741,16 +923,18 @@
741 923 <?php else: ?>
742 924 makecommercePick();
743 925
744 926 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();
927 + selectedCountry = jQuery(this).val();
928 + jQuery('input[name=makecommerce_country_picker]').removeAttr('checked');
929 + makecommercePick();
748 930 });
749 931 jQuery('body').on('change', 'input[name=makecommerce_country_picker]', function() {
932 + if(jQuery(this).is(":checked")) {
750 933 selectedCountry = jQuery(this).val();
751 934 jQuery('select[name=makecommerce_country_picker_select]').val(selectedCountry);
752 935 makecommercePick();
936 + }
753 937 });
754 938
755 939 function makecommercePick() {
756 940 jQuery('select#'+makecommerceId).val('');
@@ -820,10 +1004,9 @@
820 1004 return key($this->_banklinks_grouped);
821 1005 }
822 1006
823 1007
824 - protected function getImageUrl($methodName) {
825 - //$imageUrlPath = 'https://static.maksekeskus.ee/img/channel/lnd/';
1008 + protected function getImageUrl($methodName) { // remove it
826 1009 $imageUrlPath = $this->MK->getEnvUrls()->staticsUrl.'img/channel/lnd/';
827 1010 return $imageUrlPath.$methodName.'.png';
828 1011 }
829 1012
@@ -848,15 +1031,15 @@
848 1031 $selected = isset($_POST['PRESELECTED_METHOD_' . $this->id]) ? sanitize_text_field($_POST['PRESELECTED_METHOD_' . $this->id]) : false;
849 1032
850 1033 if (!empty($selected)) {
851 1034
852 - update_post_meta($order->id, '_makecommerce_preselected_method', $selected);
1035 + update_post_meta($order->get_id(), '_makecommerce_preselected_method', $selected);
853 1036
854 1037 $request_body = array(
855 1038 'transaction' => array(
856 - 'amount' => round($order->order_total, 2),
857 - 'currency' => $order->get_order_currency(),
858 - 'reference' => $order->id,
1039 + 'amount' => (string)sprintf("%.2f", $order->get_total()),
1040 + 'currency' => method_exists($order, 'get_currency') ? $order->get_currency() : $order->currency,
1041 + 'reference' => $order->get_id(),
859 1042 'transaction_url' => array(
860 1043 'return_url' => array(
861 1044 'url' => $this->payment_return_url,
862 1045 'method' => 'POST',
@@ -872,9 +1055,9 @@
872 1055 ),
873 1056 ),
874 1057 'customer' => array(
875 1058 'ip' => $_SERVER['REMOTE_ADDR'],
876 - 'country' => strtolower($order->billing_country),
1059 + 'country' => strtolower($order->get_billing_country()),
877 1060 'locale' => strtolower(substr(get_locale(), 0, 2)),
878 1061 ),
879 1062 );
880 1063 $transaction = $this->MK->createTransaction($request_body);
@@ -879,9 +1062,9 @@
879 1062 );
880 1063 $transaction = $this->MK->createTransaction($request_body);
881 1064
882 1065 if(isset($transaction->id)) {
883 - update_post_meta($order->id, '_makecommerce_transaction_id', $transaction->id);
1066 + update_post_meta($order->get_id(), '_makecommerce_transaction_id', $transaction->id);
884 1067 if (substr($selected, 0, 5) == 'card_') {
885 1068 $redirect_url = $order->get_checkout_payment_url( true );
886 1069 } else {
887 1070 $redirect_url = false;
@@ -912,35 +1095,16 @@
912 1095 foreach($this->_banklinks as $method) {
913 1096 if($selected == $method->country.'_'.$method->name)
914 1097 return $method->url;
915 1098 }
1099 + foreach($this->_paylater as $method) {
1100 + if($selected == $method->country.'_'.$method->name)
1101 + return $method->url;
1102 + }
916 1103
917 1104 return false;
918 1105 }
919 1106
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 1107 public function receipt_page($orderId) {
944 1108 $order = new WC_Order($orderId);
945 1109 if (substr(get_post_meta($orderId, '_makecommerce_preselected_method', true), 0, 5) == 'card_' && $order->get_status() == 'pending') {
946 1110 echo "<br>".__('The order is still awaiting your payment', 'wc_makecommerce_domain')."<br>";
@@ -950,26 +1114,33 @@
950 1114
951 1115
952 1116 public function generateCardForm($orderId) {
953 1117 $order = new WC_Order($orderId);
1118 + $has_subscription = function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order);
954 1119 $scriptSrc = htmlspecialchars($this->MK->getEnvUrls()->checkoutjsUrl.'checkout.js');
955 - $transactionId = get_post_meta($order->id, '_makecommerce_transaction_id', true);
956 - $idReference = $order->id;
1120 + $transactionId = get_post_meta($order->get_id(), '_makecommerce_transaction_id', true);
1121 + $idReference = $order->get_id();
957 1122 $jsParams = array(
958 1123 'key' => $this->MK->getPublishableKey(),
959 1124 'transaction' => $transactionId,
960 1125 'selector' => '#submit_banklinkmakecommerce_payment_form',
961 - 'amount' => round($order->order_total, 2),
1126 + 'amount' => sprintf("%.2F", $order->get_total()),
962 1127 'locale' => !empty($_GET['lang']) ? $_GET['lang'] : (defined('ICL_LANGUAGE_CODE') ? ICL_LANGUAGE_CODE : strtolower(substr(get_locale(), 0, 2))),
963 1128 '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 : ''),
1129 + '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)) : ''),
1130 + 'email' => ($this->settings['cc_pass_cust_data'] == 'yes' ? (string) (method_exists($order, 'get_billing_email') ? $order->get_billing_email() : $order->billing_email) : ''),
966 1131 'name' => get_option('mc_shop_name', ''),
967 1132 'description' => __('Order', 'woocommerce') . '&nbsp;' . (string) $idReference,
968 1133 'completed' => 'makecommerce_cc_complete',
969 - 'currency' => 'EUR',
1134 + 'currency' => method_exists($order, 'get_currency') ? $order->get_currency() : $order->currency, // $transaction->currency, // 'EUR',
970 1135 'backdrop-close' => 'false',
971 1136 );
1137 + if ($has_subscription) {
1138 + $jsParams['recurring-required'] = 'true';
1139 + $jsParams['recurring-title'] = __('Pay for subscription', 'wc_makecommerce_domain');
1140 + $jsParams['recurring-description'] = __('This order contains subscriptions', 'wc_makecommerce_domain');
1141 + $jsParams['recurring-confirmation'] = __('I agree that my card will be recurringly billed by this store', 'wc_makecommerce_domain');
1142 + }
972 1143 ?>
973 1144 <script type="text/javascript">
974 1145 function makecommerce_cc_complete(data) {
975 1146 if(data.paymentToken) {
@@ -1004,8 +1175,9 @@
1004 1175 public function makecommerce_return_trigger($vars) {
1005 1176 $vars[] = 'makecommerce_return';
1006 1177 $vars[] = 'ajax_content';
1007 1178 $vars[] = 'makecommerce_card_pay';
1179 + $vars[] = 'lang1';
1008 1180 return $vars;
1009 1181 }
1010 1182
1011 1183 public function makecommerce_return_trigger_check() {
@@ -1025,9 +1197,9 @@
1025 1197
1026 1198 New woocommerce_makecommerce(true);
1027 1199
1028 1200 // Woocommerce Multilingual overrides
1029 - if ( in_array( 'woocommerce-multilingual/wpml-woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
1201 + if (is_plugin_active('woocommerce-multilingual/wpml-woocommerce.php')) {
1030 1202 add_filter( 'get_post_metadata', 'mc_override_payment_method_string', 5, 4 );
1031 1203 }
1032 1204
1033 1205 } // init ends here
@@ -1042,15 +1214,13 @@
1042 1214
1043 1215 add_action('plugins_loaded', 'woocommerce_payment_makecommerce_init');
1044 1216 add_action('woocommerce_payment_gateways', 'woocommerce_payment_makecommerce_add');
1045 1217
1046 -
1047 1218 // Banklinks update wrapper for action
1048 1219 function update_mc_banklinks() {
1049 1220 $obj = new woocommerce_makecommerce(true);
1050 1221 $obj->mc_banklinks_reload(true);
1051 1222 }
1052 -
1053 1223
1054 1224 function mc_override_payment_method_string( $check, $object_id, $meta_key, $single ){
1055 1225 if($meta_key == '_payment_method_title') {
1056 1226 $payment_method = get_post_meta( $object_id, '_payment_method', true );