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 +237 -71 2.2.12.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.2.0';
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
@@ -534,9 +671,9 @@
534 671 if ( empty($transactionId) ) {
535 672 $transactionId = get_post_meta( $order_id, '_makecommerce_transaction_id', true);
536 673 }
537 674
538 - 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')))) {
539 676 if($status = (string)$response->transaction->status) {
540 677 switch($status) {
541 678 case self::MC_REFUNDED:
542 679 $order->add_order_note(sprintf(__('Refund completed for amount %s', 'wc_makecommerce_domain'), $amount));
@@ -623,8 +760,9 @@
623 760 <?php
624 761 }
625 762
626 763 public function payment_fields() {
764 +
627 765
628 766 if($this->settings['ui_mode'] == 'inline') {
629 767
630 768 ?>
@@ -634,9 +772,9 @@
634 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; ?>"/>
635 773 <label for="makecommerce_method_picker_<?php echo $method->country.'_'.$method->name; ?>">
636 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>
637 775 <?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>
776 + <div><img src="<?php echo $method->logo_url; ?>" title="<?php echo ucfirst($method->name); ?>" /></div>
639 777 <?php endif; ?>
640 778 </label>
641 779 </li>
642 780 <?php endforeach; ?>
@@ -645,13 +783,24 @@
645 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; ?>"/>
646 784 <label for="makecommerce_method_picker_<?php echo 'card_'.$method->name; ?>">
647 785 <span class="makecommerce-method-title"><?php if(in_array($this->settings['ui_inline_uselogo'], array('text', 'text_logo'))) { echo ucfirst($method->name); } ?></span>
648 786 <?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>
787 + <div><img src="<?php echo $method->logo_url; ?>" title="<?php echo ucfirst($method->name); ?>" /></div>
650 788 <?php endif; ?>
651 789 </label>
652 790 </li>
653 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; ?>
654 803 </ul>
655 804 <?php
656 805
657 806 } else {
@@ -663,12 +812,16 @@
663 812 <?php endforeach; ?>
664 813 <?php foreach($this->_cards as $method): ?>
665 814 <option value="card_<?php echo $method->name; ?>"><?php echo ucfirst($method->name); ?></option>
666 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; ?>
667 819 </select>
668 820 <ul class="makecommerce-picker">
669 821 <?php
670 -
822 + global $woocommerce;
823 + $cartTotal = $woocommerce->cart->total;
671 824 if($this->_banklinks || $this->_cards) {
672 825 $defaultCountry = $this->getDefaultCountry();
673 826 ?>
674 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') ) : ?>
@@ -697,9 +850,9 @@
697 850 <?php endif; ?>
698 851 <div class="makecommerce_country_picker_methods" id="makecommerce_country_picker_methods_<?php echo $country; ?>">
699 852 <?php foreach($methods as $method): ?>
700 853 <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); ?>" />
854 + <img src="<?php echo $method->logo_url; ?>" title="<?php echo ucfirst($method->name); ?>" />
702 855 </div>
703 856 <?php endforeach; ?>
704 857 <?php if($this->_cards && $this->settings['ui_widget_groupcc'] == 'no') : ?>
705 858 <div class="breaker"></div>
@@ -704,9 +857,9 @@
704 857 <?php if($this->_cards && $this->settings['ui_widget_groupcc'] == 'no') : ?>
705 858 <div class="breaker"></div>
706 859 <?php foreach($this->_cards as $method): ?>
707 860 <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); ?>" />
861 + <img src="<?php echo $method->logo_url; ?>" title="<?php echo ucfirst($method->name); ?>" />
709 862 </div>
710 863 <?php endforeach; ?>
711 864 <?php elseif($country == 'other') :?>
712 865 <p class="no-methods"><?php _e('No payment methods for selected country' ,'wc_makecommerce_domain');?></p>
@@ -719,14 +872,39 @@
719 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>
720 873 <div class="makecommerce_country_picker_methods" id="makecommerce_country_picker_methods_card">
721 874 <?php foreach($this->_cards as $method): ?>
722 875 <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); ?>" />
876 + <img src="<?php echo $method->logo_url; ?>" title="<?php echo ucfirst($method->name); ?>" />
724 877 </div>
725 878 <?php endforeach; ?>
726 879 </div>
727 880 </li>
728 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; ?>
729 907 <?php
730 908 }
731 909 ?>
732 910 </ul>
@@ -745,16 +923,18 @@
745 923 <?php else: ?>
746 924 makecommercePick();
747 925
748 926 jQuery('body').on('change', 'select[name=makecommerce_country_picker_select]', function() {
749 - selectedCountry = jQuery(this).val();
750 - jQuery('input[name=makecommerce_country_picker]').removeAttr('checked');
751 - makecommercePick();
927 + selectedCountry = jQuery(this).val();
928 + jQuery('input[name=makecommerce_country_picker]').removeAttr('checked');
929 + makecommercePick();
752 930 });
753 931 jQuery('body').on('change', 'input[name=makecommerce_country_picker]', function() {
932 + if(jQuery(this).is(":checked")) {
754 933 selectedCountry = jQuery(this).val();
755 934 jQuery('select[name=makecommerce_country_picker_select]').val(selectedCountry);
756 935 makecommercePick();
936 + }
757 937 });
758 938
759 939 function makecommercePick() {
760 940 jQuery('select#'+makecommerceId).val('');
@@ -824,10 +1004,9 @@
824 1004 return key($this->_banklinks_grouped);
825 1005 }
826 1006
827 1007
828 - protected function getImageUrl($methodName) {
829 - //$imageUrlPath = 'https://static.maksekeskus.ee/img/channel/lnd/';
1008 + protected function getImageUrl($methodName) { // remove it
830 1009 $imageUrlPath = $this->MK->getEnvUrls()->staticsUrl.'img/channel/lnd/';
831 1010 return $imageUrlPath.$methodName.'.png';
832 1011 }
833 1012
@@ -852,15 +1031,15 @@
852 1031 $selected = isset($_POST['PRESELECTED_METHOD_' . $this->id]) ? sanitize_text_field($_POST['PRESELECTED_METHOD_' . $this->id]) : false;
853 1032
854 1033 if (!empty($selected)) {
855 1034
856 - update_post_meta($order->id, '_makecommerce_preselected_method', $selected);
1035 + update_post_meta($order->get_id(), '_makecommerce_preselected_method', $selected);
857 1036
858 1037 $request_body = array(
859 1038 'transaction' => array(
860 - 'amount' => round($order->order_total, 2),
861 - 'currency' => $order->get_order_currency(),
862 - '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(),
863 1042 'transaction_url' => array(
864 1043 'return_url' => array(
865 1044 'url' => $this->payment_return_url,
866 1045 'method' => 'POST',
@@ -876,9 +1055,9 @@
876 1055 ),
877 1056 ),
878 1057 'customer' => array(
879 1058 'ip' => $_SERVER['REMOTE_ADDR'],
880 - 'country' => strtolower($order->billing_country),
1059 + 'country' => strtolower($order->get_billing_country()),
881 1060 'locale' => strtolower(substr(get_locale(), 0, 2)),
882 1061 ),
883 1062 );
884 1063 $transaction = $this->MK->createTransaction($request_body);
@@ -883,9 +1062,9 @@
883 1062 );
884 1063 $transaction = $this->MK->createTransaction($request_body);
885 1064
886 1065 if(isset($transaction->id)) {
887 - update_post_meta($order->id, '_makecommerce_transaction_id', $transaction->id);
1066 + update_post_meta($order->get_id(), '_makecommerce_transaction_id', $transaction->id);
888 1067 if (substr($selected, 0, 5) == 'card_') {
889 1068 $redirect_url = $order->get_checkout_payment_url( true );
890 1069 } else {
891 1070 $redirect_url = false;
@@ -916,35 +1095,16 @@
916 1095 foreach($this->_banklinks as $method) {
917 1096 if($selected == $method->country.'_'.$method->name)
918 1097 return $method->url;
919 1098 }
1099 + foreach($this->_paylater as $method) {
1100 + if($selected == $method->country.'_'.$method->name)
1101 + return $method->url;
1102 + }
920 1103
921 1104 return false;
922 1105 }
923 1106
924 - /*
925 - protected function _getOrderConfirmationUrl($order) {
926 -
927 - global $sitepress;
928 - if(isset($sitepress)) {
929 - $baseUrl = $sitepress->language_url( ICL_LANGUAGE_CODE );
930 - $lang = ICL_LANGUAGE_CODE;
931 - } else {
932 - $baseUrl = site_url();
933 - $lang = strtolower(substr(get_locale(), 0, 2));
934 - }
935 - $url = add_query_arg( array(
936 - 'makecommerce_card_pay' => '1',
937 - 'order_id' => $order->id,
938 - 'lang' => $lang,
939 - ), $baseUrl);
940 -
941 - // $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))));
942 - return $url;
943 - }
944 -
945 - */
946 -
947 1107 public function receipt_page($orderId) {
948 1108 $order = new WC_Order($orderId);
949 1109 if (substr(get_post_meta($orderId, '_makecommerce_preselected_method', true), 0, 5) == 'card_' && $order->get_status() == 'pending') {
950 1110 echo "<br>".__('The order is still awaiting your payment', 'wc_makecommerce_domain')."<br>";
@@ -954,26 +1114,33 @@
954 1114
955 1115
956 1116 public function generateCardForm($orderId) {
957 1117 $order = new WC_Order($orderId);
1118 + $has_subscription = function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order);
958 1119 $scriptSrc = htmlspecialchars($this->MK->getEnvUrls()->checkoutjsUrl.'checkout.js');
959 - $transactionId = get_post_meta($order->id, '_makecommerce_transaction_id', true);
960 - $idReference = $order->id;
1120 + $transactionId = get_post_meta($order->get_id(), '_makecommerce_transaction_id', true);
1121 + $idReference = $order->get_id();
961 1122 $jsParams = array(
962 1123 'key' => $this->MK->getPublishableKey(),
963 1124 'transaction' => $transactionId,
964 1125 'selector' => '#submit_banklinkmakecommerce_payment_form',
965 - 'amount' => round($order->order_total, 2),
1126 + 'amount' => sprintf("%.2F", $order->get_total()),
966 1127 'locale' => !empty($_GET['lang']) ? $_GET['lang'] : (defined('ICL_LANGUAGE_CODE') ? ICL_LANGUAGE_CODE : strtolower(substr(get_locale(), 0, 2))),
967 1128 'open-on-load' => 'true',
968 - 'client-name' => ($this->settings['cc_pass_cust_data'] == 'yes' ? (string) ($order->billing_first_name . ' ' . $order->billing_last_name) : ''),
969 - '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) : ''),
970 1131 'name' => get_option('mc_shop_name', ''),
971 1132 'description' => __('Order', 'woocommerce') . '&nbsp;' . (string) $idReference,
972 1133 'completed' => 'makecommerce_cc_complete',
973 - 'currency' => 'EUR',
1134 + 'currency' => method_exists($order, 'get_currency') ? $order->get_currency() : $order->currency, // $transaction->currency, // 'EUR',
974 1135 'backdrop-close' => 'false',
975 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 + }
976 1143 ?>
977 1144 <script type="text/javascript">
978 1145 function makecommerce_cc_complete(data) {
979 1146 if(data.paymentToken) {
@@ -1008,8 +1175,9 @@
1008 1175 public function makecommerce_return_trigger($vars) {
1009 1176 $vars[] = 'makecommerce_return';
1010 1177 $vars[] = 'ajax_content';
1011 1178 $vars[] = 'makecommerce_card_pay';
1179 + $vars[] = 'lang1';
1012 1180 return $vars;
1013 1181 }
1014 1182
1015 1183 public function makecommerce_return_trigger_check() {
@@ -1046,15 +1214,13 @@
1046 1214
1047 1215 add_action('plugins_loaded', 'woocommerce_payment_makecommerce_init');
1048 1216 add_action('woocommerce_payment_gateways', 'woocommerce_payment_makecommerce_add');
1049 1217
1050 -
1051 1218 // Banklinks update wrapper for action
1052 1219 function update_mc_banklinks() {
1053 1220 $obj = new woocommerce_makecommerce(true);
1054 1221 $obj->mc_banklinks_reload(true);
1055 1222 }
1056 -
1057 1223
1058 1224 function mc_override_payment_method_string( $check, $object_id, $meta_key, $single ){
1059 1225 if($meta_key == '_payment_method_title') {
1060 1226 $payment_method = get_post_meta( $object_id, '_payment_method', true );