PluginProbe
MakeCommerce for WooCommerce / 2.4.9
MakeCommerce for WooCommerce v2.4.9
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
makecommerce / makecommerce-payment.php

makecommerce-payment.php in MakeCommerce for WooCommerce 2.4.9, at makecommerce-payment.php

1,166 lines 47.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4
5 function woocommerce_payment_makecommerce_init() {
6
7 load_plugin_textdomain('wc_makecommerce_domain', false, dirname(plugin_basename(__FILE__)) . '/');
8
9 class woocommerce_makecommerce extends WC_Payment_Gateway {
10
11 const MC_CANCELLED = 'CANCELLED';
12 const MC_COMPLETED = 'COMPLETED';
13 const MC_DEPOSITED = 'DEPOSITED';
14
15 const MC_PART_REFUNDED = 'PART_REFUNDED';
16 const MC_REFUNDED = 'REFUNDED';
17
18 const module_name = 'MakeCommerce';
19
20 const billing_descriptor_dba = '';
21 const currencies_allowed = 'EUR';
22 const module_homepage_url = 'https://maksekeskus.ee/en/integration-modules/makecommerce-woocommerce-payment-plugin/';
23 const testenv_homepage_url = 'http://maksekeskus.ee/en/for-developers/test-environment/';
24
25 public $id = 'makecommerce';
26 public $version = '2.4.9';
27
28 public $payment_return_url;
29 public $payment_return_url_m2m;
30 public $payment_return_url_cancel;
31
32 //protected $_shop_id;
33 //protected $_api_key_secret;
34 //protected $_api_key_public;
35
36
37 protected $_banklinks = array();
38 protected $_banklinks_grouped;
39 protected $_cards = array();
40
41 protected $MK;
42 protected $_init;
43
44
45 public function __construct($init = false) {
46 $this->_init = $init;
47
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 // Load the form fields.
53 $this->init_form_fields();
54
55 // Load the settings.
56 $this->init_settings();
57
58 $this->initBanklinks();
59
60 if (defined('ICL_LANGUAGE_CODE') && !empty($this->settings['ui_widget_title_'.ICL_LANGUAGE_CODE])) {
61 $this->title = $this->settings['ui_widget_title_'.ICL_LANGUAGE_CODE];
62 } else if (!empty($this->settings['ui_widget_title'])) {
63 $this->title = $this->settings['ui_widget_title'];
64 } else {
65 $this->title = '';
66 }
67
68 $this->method_title = 'MakeCommerce';
69 $this->description = true;
70
71 $this->enabled = $this->settings['active'];
72
73 $this->MK = mk_get_api();
74 if (!$this->MK && $this->_init) {
75 add_action( 'admin_notices', array(&$this, 'makecommerce_api_info_missing') );
76 }
77
78 $this->supports = array(
79 'subscriptions',
80 'subscription_cancellation',
81 'subscription_suspension',
82 'subscription_reactivation',
83 'subscription_amount_changes',
84 'subscription_date_changes',
85 'subscription_payment_method_change',
86 'products',
87 'refunds'
88 );
89
90 add_filter('query_vars', array(&$this, 'makecommerce_return_trigger'));
91 add_action('template_redirect', array(&$this, 'makecommerce_return_trigger_check'));
92 add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'process_subscripion_payment_start'), 10, 2);
93 add_action('scheduled_subscription_payment_' . $this->id, array($this, 'process_subscripion_payment_start'), 10, 2);
94
95 if($this->_init == false) {
96 add_action('woocommerce_update_options_payment_gateways', array(&$this, 'process_admin_options'));
97 add_action('woocommerce_update_options_payment_gateways_' . $this->id, array(&$this, 'process_admin_options'));
98 add_action('woocommerce_receipt_' . $this->id, array($this, 'receipt_page'));
99
100 add_action('woocommerce_admin_order_data_after_order_details', array(&$this, 'admin_order_page'), 10, 1);
101
102 wp_enqueue_script('jquery');
103 wp_enqueue_style('makecommerce', plugins_url('/css/makecommerce.css', __FILE__), array(), $this->version);
104 }
105 if (is_admin()) {
106 add_action( 'wp_ajax_mc_banklinks_reload', array(&$this, 'mc_banklinks_reload') );
107
108 require_once(ABSPATH.'wp-admin/includes/plugin.php');
109 $wc_version = get_plugin_data(__DIR__.'/../woocommerce/woocommerce.php');
110 if ((double)$wc_version['Version'] < 2.6) {
111 function sample_admin_notice__error() {
112 $class = 'notice notice-error';
113 $wc_version = get_plugin_data(__DIR__.'/../woocommerce/woocommerce.php');
114 $message = sprintf(__( 'Makecommerce plugin needs at least <strong>WooCommerce 2.6</strong> to function correctly. Please update yours (currently %s)', 'wc_makecommerce_domain' ), $wc_version['Version']);
115 printf( '<div class="%1$s"><p>%2$s</p></div>', $class, $message );
116 }
117 add_action( 'admin_notices', 'sample_admin_notice__error' );
118 }
119 }
120
121 }
122
123 public function get_title() {
124 // TODO: add multilingual support
125 return $this->title;
126 }
127
128 protected function _getWooCommerce() {
129 global $woocommerce;
130 return $woocommerce;
131 }
132
133 public function is_valid_for_use() {
134 return true;
135 }
136
137 public function is_available() {
138 if (!($this->settings['active'] == "yes" && mk_is_api_set())) {
139 return false;
140 }
141 return parent::is_available();
142 }
143
144 private function initBanklinks() {
145 global $wpdb;
146 global $mkDbTable;
147 $this->_banklinks = array();
148 $has_subscriptions = class_exists('WC_Subscriptions_Cart') && WC_Subscriptions_Cart::cart_contains_subscription();
149
150 $tableName = $wpdb->prefix . $mkDbTable;
151 $methods = $wpdb->get_results('SELECT * FROM '.$tableName);
152
153 if(count($methods)) {
154 if(is_admin() && $this->_init == true && get_option( 'mc_banklinks_api_type' ) != get_option('mk_api_type', false)) {
155 // ??
156 add_action( 'admin_notices', array(&$this, 'makecommerce_banklinks_list_type_notice') );
157 }
158 $banklinks = array();
159 $banklinks_grouped = array();
160 $cards = array();
161 foreach($methods as $method) {
162 if($method->type == 'banklink') {
163 if (!$has_subscriptions) {
164 $banklinks[] = $banklinks_grouped[$method->country][] = $method;
165 }
166 } elseif($method->type == 'card') {
167 $cards[] = $method;
168 }
169 }
170
171 usort($banklinks, array($this, 'orderBanklinks'));
172 foreach($banklinks_grouped as &$country) {
173 usort($country, array($this, 'orderBanklinks'));
174 }
175
176 $this->_banklinks = $banklinks;
177 $this->_banklinks_grouped = $banklinks_grouped;
178 $this->_cards = $cards;
179 remove_action('admin_notices', array(&$this, 'makecommerce_banklinks_list_empty'), 30);
180 } elseif(is_admin() && $this->_init == true) {
181 add_action('admin_notices', array(&$this, 'makecommerce_banklinks_list_empty'), 30);
182 }
183 }
184
185 private function orderBanklinks($a, $b) {
186 $order = array_map('trim', explode(",", $this->settings['ui_chorder']));
187
188 $posA = array_search($a->name, $order);
189 $posB = array_search($b->name, $order);
190
191 if($posA === $posB) return $a->id > $b->id ? 1 : -1;
192 if($posA === FALSE) return 1;
193 if($posB === FALSE) return -1;
194
195 return $posA > $posB ? 1 : -1;
196 }
197
198
199
200 // ===== WC admin related stuff ======
201
202
203 public function makecommerce_api_info_missing() {
204 ?>
205 <div class="notice notice-error is-dismissible">
206 <p>
207 <?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'); ?>
208 <?php if (mk_wc_version("3.4.0")) { ?>
209 <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>
210 <?php } else { ?>
211 <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>
212 <?php } ?>
213 </p>
214 </div>
215 <?php
216 }
217
218 public function makecommerce_banklinks_list_empty() {
219 ?>
220 <div class="notice notice-error is-dismissible">
221 <p>
222 <?php echo __('The payment methods list for MakeCommerce payment module is empty.', 'wc_makecommerce_domain'); ?>
223 <a href="<?php echo admin_url('admin.php?page=wc-settings&tab=checkout&section=makecommerce'); ?>"><?php echo __('Go to the settings to update them', 'wc_makecommerce_domain'); ?></a>
224 </p>
225 </div>
226 <?php
227 }
228
229 public function makecommerce_banklinks_list_type_notice() {
230 ?>
231 <div class="notice notice-error is-dismissible">
232 <p>
233 <?php echo __('You have changed the environment for MakeCommerce payment module. The payment methods list has been loaded for a different environment.', 'wc_makecommerce_domain'); ?>
234 <a href="<?php echo admin_url('admin.php?page=wc-settings&tab=checkout&section=makecommerce'); ?>"><?php echo __('Go to the settings to update them', 'wc_makecommerce_domain'); ?></a>
235 </p>
236 </div>
237 <?php
238 }
239
240
241 public function init_form_fields() {
242
243 if ( function_exists('icl_object_id') && ! defined( 'POLYLANG_VERSION' ) ) {
244 $languages = apply_filters('wpml_active_languages', NULL, 'skip_missing=0');
245 }
246 else if ( defined( 'POLYLANG_VERSION' ) ) {
247 $pl_locales = pll_languages_list( array('fields'=>'locale') );
248 foreach ($pl_locales as $key => $locale_pl ) {
249 $language = array( 'id' => $key,
250 'code' => $locale_pl) ;
251 $languages[$locale_pl] = $language;
252 }
253 }
254
255 $this->form_fields = array();
256 $this->form_fields['logo'] = array('type' => 'title', 'description' => __get_logo_html());
257 $this->form_fields['active'] = array(
258 'title' => __('Enable/Disable', 'wc_makecommerce_domain'),
259 'type' => 'checkbox',
260 'label' => __('Enable MakeCommerce payments', 'wc_makecommerce_domain'),
261 'default' => 'no'
262 );
263 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');
264 $this->form_fields['api_title'] = array(
265 'title' => __('MakeCommerce API', 'wc_makecommerce_domain'),
266 'description' => sprintf(__('Go to <a href="%s">API settings</a> to fill in the credentials', 'wc_makecommerce_domain'), $a),
267 'type' => 'title',
268 );
269 $this->form_fields['ui_title'] = array(
270 'title' => '<br>'.__('User Interface', 'wc_makecommerce_domain'),
271 'type' => 'title',
272 'class' => 'ui-identifier',
273 );
274 $this->form_fields['ui_open_by_default'] = array(
275 'title' => __('Set as default selection', 'wc_makecommerce_domain'),
276 'label' => __('MakeCommerce payments widget will be selected by default', 'wc_makecommerce_domain'),
277 'type' => 'checkbox',
278 'default' => 'yes',
279 'class' => 'ui-identifier',
280 );
281 $this->form_fields['ui_mode'] = array(
282 'title' => __('Display MC payment channels as', 'wc_makecommerce_domain'),
283 'type' => 'mc_hidden',
284 'default' => 'widget',
285 'options' => array(
286 'inline' => __('List', 'wc_makecommerce_domain'),
287 'widget' => __('Grouped to widget', 'wc_makecommerce_domain'),
288 ),
289 'class' => 'ui-identifier',
290 );
291
292
293 if (empty($languages)) {
294 $this->form_fields['ui_widget_title'] = array(
295 'title' => __('Payments widget title', 'wc_makecommerce_domain'),
296 'type' => 'text',
297 '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'),
298 'default' => __('Pay with bank-links or credit card', 'wc_makecommerce_domain'),
299 'class' => 'ui-identifier',
300 );
301 } else {
302 foreach ($languages as $language_code => $language) {
303 $language_name = !empty($language['translated_name']) ? $language['translated_name'] : $language_code;
304 $defaultTitle = __('Pay with bank-links or credit card', 'wc_makecommerce_domain');
305 switch ($language_code) {
306 case 'et':
307 $defaultTitle = 'Maksa pangalingi või krediitkaardiga';
308 break;
309 case 'ru':
310 $defaultTitle = 'оплата в интернет-банке или кредитной картой';
311 break;
312 case 'fi':
313 $defaultTitle = 'Maksaa verkkopankissa tai luottokortilla';
314 break;
315 }
316 $this->form_fields['ui_widget_title_'.$language_code] = array(
317 'title' => __('Payments widget title', 'wc_makecommerce_domain').sprintf(' (%s)', $language_code),
318 'type' => 'text',
319 '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'),
320
321 'default' => $defaultTitle,
322 'class' => 'ui-identifier',
323 );
324 }
325 }
326 $this->form_fields['ui_inline_uselogo'] = array(
327 'title' => __('MC payment channels display style', 'wc_makecommerce_domain'),
328 'type' => 'select',
329 'default' => 'logo',
330 'options' => array(
331 'logo' => __('Logo', 'wc_makecommerce_domain'),
332 'text_logo' => __('Text & logo', 'wc_makecommerce_domain'),
333 'text' => __('Text', 'wc_makecommerce_domain'),
334 ),
335 'class' => 'ui-identifier',
336 );
337 $this->form_fields['ui_widget_logosize'] = array(
338 'title' => __('Size of payment channel logos', 'wc_makecommerce_domain'),
339 'type' => 'select',
340 'default' => 'medium',
341 'options' => array(
342 'small' => __('Small', 'wc_makecommerce_domain'),
343 'medium' => __('Medium', 'wc_makecommerce_domain'),
344 'large' => __('Large', 'wc_makecommerce_domain')
345 ),
346 'class' => 'ui-identifier',
347 );
348 $this->form_fields['ui_widget_groupcountries'] = array(
349 'title' => __('Group bank-links by countries', 'wc_makecommerce_domain'),
350 'type' => 'mc_hidden',
351 'default' => 'no',
352 'class' => 'ui-identifier',
353 );
354 $this->form_fields['ui_widget_countries_hidden'] = array(
355 'title' => __('Hide country selector', 'wc_makecommerce_domain'),
356 'label' => __('Do not display country selector (flags) at payment methods', 'wc_makecommerce_domain'),
357 'type' => 'checkbox',
358 'default' => 'no',
359 );
360 $this->form_fields['ui_widget_countryselector'] = array(
361 'title' => __('Country selector style', 'wc_makecommerce_domain'),
362 'type' => 'mc_hidden',
363 'default' => 'flag',
364 'options' => array(
365 'flag' => __('Flag', 'wc_makecommerce_domain'),
366 'dropdown' => __('Dropdown', 'wc_makecommerce_domain'),
367 ),
368 'class' => 'ui-identifier',
369 );
370 $this->form_fields['ui_widget_groupcc'] = array(
371 'title' => __('Group credit card into separate widget', 'wc_makecommerce_domain'),
372 'type' => 'mc_hidden',
373 'default' => 'no',
374 'class' => 'ui-identifier',
375 );
376 $this->form_fields['ui_chorder'] = array(
377 'title' => __('Define custom order of payment channels', 'wc_makecommerce_domain'),
378 'type' => 'text',
379 'desc_tip' => __('If you want to change default order, put here comma separated list of channels. i,e, - seb,lhv,swedbank. see more on the module home page (link above)', 'wc_makecommerce_domain'),
380 'class' => 'ui-identifier',
381 );
382 $this->form_fields['ui_javascript'] = array(
383 'type' => 'ui_javascript',
384 );
385 $this->form_fields['cc_title'] = array(
386 'title' => '<br>'.__('Credit Card Settings', 'wc_makecommerce_domain'),
387 'type' => 'title',
388 );
389 $this->form_fields['cc_pass_cust_data'] = array(
390 'title' => __('Prefill Credit Card form with customer data', 'wc_makecommerce_domain'),
391 'type' => 'checkbox',
392 'default' => 'yes',
393 'desc_tip' => __('It will pass user Name and e-mail address to the Credit Card dialog to make the form filling easier', 'wc_makecommerce_domain'),
394 );
395 $this->form_fields['adv_title'] = array(
396 'title' => '<hr><br>'.__('Advanced Settings', 'wc_makecommerce_domain'),
397 'type' => 'title',
398 );
399 $this->form_fields['reload_links'] = array(
400 'type' => 'mc_banklinks_reload',
401 'title' => __('Update payment methods', 'wc_makecommerce_domain'),
402 'description' => __('Update', 'wc_makecommerce_domain'),
403 'desc_tip' => __('This will update shop configuration from MakeCommerce servers.', 'wc_makecommerce_domain'),
404 );
405 }
406
407 // Needed to render mc_hidden type fields in admin
408 public function generate_mc_hidden_html( $key, $data ) {
409 $field_key = $this->get_field_key($key);
410 ob_start();
411 ?>
412 <tr style="display: none;">
413 <td colspan="2">
414 <input type="hidden" name="<?php echo $field_key; ?>" value="<?php echo $data['default']; ?>" />
415 </td>
416 </tr>
417 <?php
418 return ob_get_clean();
419 }
420
421
422 public function generate_mc_banklinks_reload_html( $key, $data ) {
423 $field = $this->get_field_key( $key );
424 $defaults = array(
425 'title' => '',
426 'disabled' => false,
427 'class' => '',
428 'css' => '',
429 'placeholder' => '',
430 'type' => 'text',
431 'desc_tip' => false,
432 'description' => '',
433 'custom_attributes' => array()
434 );
435
436 $data = wp_parse_args( $data, $defaults );
437
438 ob_start();
439 ?>
440 <tr valign="top">
441 <th scope="row" class="titledesc">
442 <label for="<?php echo esc_attr( $field ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
443 <?php echo $this->get_tooltip_html( $data ); ?>
444 </th>
445 <td class="forminp">
446 <fieldset>
447 <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
448 <input id="mc_banklinks_reload" class="button <?php echo esc_attr( $data['class'] ); ?>" type="button" name="<?php echo esc_attr( $field ); ?>" id="<?php echo esc_attr( $field ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" value="<?php echo esc_attr( $data['description'] ); ?>" placeholder="<?php echo esc_attr( $data['placeholder'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); ?> />
449 <script type="text/javascript">
450 jQuery('input#mc_banklinks_reload').on('click', function() {
451 init_mc_loading();
452 jQuery.ajax({
453 url: '<?php echo get_site_url(); ?>/wp-admin/admin-ajax.php',
454 type: 'POST',
455 data: 'action=mc_banklinks_reload',
456 success: function (output) {
457 if(output.data) {
458 alert(output.data);
459 } else {
460 alert('<?php echo __('There was an error with your update. Please try again.', 'wc_makecommerce_domain'); ?>');
461 }
462 },
463 complete: function() { stop_mc_loading(); }
464 });
465 });
466
467 function init_mc_loading() {
468 jQuery('input#mc_banklinks_reload').attr('disabled', 'disabled');
469 }
470
471 function stop_mc_loading() {
472 jQuery('input#mc_banklinks_reload').removeAttr('disabled');
473 }
474 </script>
475 </fieldset>
476 </td>
477 </tr>
478 <?php
479
480 return ob_get_clean();
481 }
482
483 public function mc_banklinks_reload($force = false) {
484 if ($force || (defined('DOING_AJAX') && DOING_AJAX)) {
485
486 global $wpdb;
487 global $mkDbTable;
488
489 $request_params = array(
490 'environment' => json_encode(array(
491 'platform' => 'woocommerce '.$this->_getWooCommerce()->version,
492 'module' => $this->id.' '.$this->version,
493 )),
494 );
495
496 if (!$this->MK) {
497 return false;
498 }
499
500 try {
501 $shopConfig = $this->MK->getShopConfig($request_params);
502 $methods = $shopConfig->paymentMethods;
503 } catch (Exception $e) {
504 error_log(print_r($e, 1));
505 return false;
506 }
507
508 $tableName = $wpdb->prefix . $mkDbTable;
509 $sql = "select count(*) as isLogoUrlSet from information_schema.columns where table_name='".$tableName."' and column_name='logo_url'";
510 $methodstruct = $wpdb->get_results( $sql );
511 if ($methodstruct[0]->isLogoUrlSet == 0) {
512 $wpdb->query('ALTER TABLE '.$tableName.' ADD COLUMN logo_url varchar(250)');
513 }
514
515 $wpdb->query('TRUNCATE TABLE '.$tableName);
516
517 if(isset($methods->banklinks)) {
518 foreach($methods->banklinks as $method) {
519 $wpdb->insert($tableName, array('type' => 'banklink', 'country' => $method->country, 'name' => $method->name, 'url' => $method->url, 'logo_url' => $method->logo_url));
520 }
521 $updated = true;
522 }
523
524 if(isset($methods->cards)) {
525 foreach($methods->cards as $method) {
526 $wpdb->insert($tableName, array('type' => 'card', 'name' => $method->name, 'logo_url' => $method->logo_url));
527 }
528 $updated = true;
529 }
530
531 if(isset($shopConfig) && strlen($shopConfig->name)) {
532 update_option( 'mc_shop_name', $shopConfig->name );
533 }
534
535 if ($updated) {
536 update_option( 'mc_banklinks_api_type', get_option('mk_api_type', false) );
537 }
538
539 if ($force) {
540 $this->initBankLinks();
541 return $updated;
542 }
543
544 if($updated) {
545 wp_send_json(array('success' => 1, 'data' => __('Update successfully completed!', 'wc_makecommerce_domain')));
546 exit;
547 }
548
549 wp_send_json(array('success' => 0, 'data' => __('There was an error with your update. Please try again.', 'wc_makecommerce_domain')));
550 exit;
551 }
552 die();
553 }
554
555
556 public function process_subscripion_payment_start($amount_to_charge, $renewal_order, $product_id = '') {
557 $result = $this->process_subscription_payment($renewal_order, $amount_to_charge);
558 if ( is_wp_error( $result ) ) {
559 WC_Subscriptions_Manager::process_subscription_payment_failure_on_order($renewal_order, $product_id);
560 } else {
561 WC_Subscriptions_Manager::process_subscription_payments_on_order($renewal_order);
562 }
563 }
564
565 public function process_subscription_payment($order, $amount = 0) {
566 if (0 === $amount) {
567 $order->payment_complete();
568 return true;
569 }
570 if ('processing' === $order->get_status()) {
571 return true;
572 }
573 $oorder_id = @WC_Subscriptions_Renewal_Order::get_parent_order_id($order);
574 $payment_token = get_post_meta($oorder_id, '_makecommerce_payment_token', true);
575 $payment_token_valid_until = get_post_meta($oorder_id, '_makecommerce_payment_token_valid_until', true);
576 error_log($payment_token.'=>'. $payment_token_valid_until.'=>'. $order->get_status());
577 $body = array(
578 'transaction' => array(
579 'amount' => (string)sprintf("%.2f", $amount),
580 'currency' => method_exists($order, 'get_currency') ? $order->get_currency() : $order->currency,
581 'reference' => $order->get_order_number(),
582 ),
583 'customer' => array(
584 'email' => $order->get_billing_email(),
585 'ip' => $order->get_customer_ip_address(),
586 'country' => strtolower($order->get_billing_country()),
587 'locale' => strtolower(substr(get_locale(), 0, 2)),
588 )
589 );
590 $transaction = $this->MK->createTransaction($body);
591 $paymentRequest = array(
592 'amount' => (string)sprintf("%.2f", $transaction->amount),
593 'currency' => $transaction->currency,
594 'token' => $payment_token
595 );
596 try {
597 $payment = $this->MK->createPayment($transaction->id, $paymentRequest);
598 } catch (Exception $e) {
599 error_log('Payment failed ['.$e->getMessage().']');
600 $order->add_order_note(__('Unable to renew subscription', 'wc_makecommerce_domain')."\r\n".$e->getMessage());
601 return new WP_Error('makecommerce_payment_declined', __( 'Renewal payment was declined', 'wc_makecommerce_domain' ) );
602 }
603 $orderNote = array();
604 $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>';
605 $orderNote[] = __('Payment option', 'wc_makecommerce_domain') . ': ' . get_post_meta($order->get_order_number(), '_makecommerce_preselected_method', true);
606 $order->add_order_note(implode("\r\n", $orderNote));
607 $order->payment_complete($transaction->id);
608 return true;
609 }
610
611 public function admin_order_page($order) {
612 //
613 }
614
615 public function process_refund($order_id, $amount = null, $comment = '') {
616 if ($this->MK) {
617 try {
618 $order = new WC_Order($order_id);
619 $transactionId = $order->get_transaction_id();
620
621 if ( empty($transactionId) ) {
622 $transactionId = get_post_meta( $order_id, '_makecommerce_transaction_id', true);
623 }
624
625 if($response = $this->MK->createRefund($transactionId, array('amount' => sprintf("%.2f", $amount), 'comment' => ($comment ? : 'refund')))) {
626 if($status = (string)$response->transaction->status) {
627 switch($status) {
628 case self::MC_REFUNDED:
629 $order->add_order_note(sprintf(__('Refund completed for amount %s', 'wc_makecommerce_domain'), $amount));
630 return true;
631 break;
632 case self::MC_PART_REFUNDED:
633 $order->add_order_note(sprintf(__('Partial refund completed for amount %s', 'wc_makecommerce_domain'), $amount));
634 return true;
635 break;
636 }
637 }
638 }
639 return false;
640
641 } catch (Exception $e) {
642 return new WP_Error('makecommerce_refund_error', $e->getMessage());
643 }
644
645 return false;
646 }
647 return false;
648 }
649
650
651 // ====== storefront related stuff =========
652
653 public function generate_ui_javascript_html( $key, $data ) {
654 ?>
655 <script type="text/javascript">
656 jQuery(document).ready(function($) {
657
658 var api_type = $('#woocommerce_<?php echo $this->id; ?>_api_type');
659
660 var ui_inline_uselogo_row = $('#woocommerce_<?php echo $this->id; ?>_ui_inline_uselogo').closest('tr');
661 var ui_widget_title_row = $('#woocommerce_<?php echo $this->id; ?>_ui_widget_title').closest('tr');
662 var ui_widget_logosize_row = $('#woocommerce_<?php echo $this->id; ?>_ui_widget_logosize').closest('tr');
663 var ui_widget_countryselector_row = $('#woocommerce_<?php echo $this->id; ?>_ui_widget_countryselector').closest('tr');
664 var ui_widget_groupcountries_row = $('#woocommerce_<?php echo $this->id; ?>_ui_widget_groupcountries').closest('tr');
665 var ui_widget_groupcc_row = $('#woocommerce_<?php echo $this->id; ?>_ui_widget_groupcc').closest('tr');
666 var ui_widget_groupcc_title_row = $('#woocommerce_<?php echo $this->id; ?>_ui_widget_groupcc_title').closest('tr');
667
668 var ui_mode = $('#woocommerce_<?php echo $this->id; ?>_ui_mode');
669 var ui_widget_groupcountries = $('#woocommerce_<?php echo $this->id; ?>_ui_widget_groupcountries');
670 var ui_widget_groupcc = $('#woocommerce_<?php echo $this->id; ?>_ui_widget_groupcc');
671
672 parseVisibility();
673 function parseVisibility() {
674 $('.ui-identifier').closest('tr').show();
675
676 if(api_type.val() == 'live') {
677 $('.mc-test-link').hide();
678 $('.api-test').closest('tr').hide();
679 } else {
680 $('.mc-test-link').show();
681 $('.api-live').closest('tr').hide();
682 }
683
684 if(ui_mode.val() == 'inline') {
685 ui_widget_title_row.hide();
686 ui_widget_logosize_row.hide();
687 ui_widget_countryselector_row.hide();
688 ui_widget_groupcountries_row.hide();
689 ui_widget_groupcc_row.hide();
690 ui_widget_groupcc_title_row.hide();
691 } else {
692 ui_inline_uselogo_row.hide();
693
694 if(ui_widget_groupcountries.prop('checked')) {
695 ui_widget_countryselector_row.hide();
696 }
697 if(!ui_widget_groupcc.prop('checked')) {
698 ui_widget_groupcc_title_row.hide();
699 }
700 }
701 }
702
703 api_type.on('change', parseVisibility);
704 ui_mode.on('change', parseVisibility);
705 ui_widget_groupcountries.on('change', parseVisibility);
706 ui_widget_groupcc.on('change', parseVisibility);
707
708 });
709 </script>
710 <?php
711 }
712
713 public function payment_fields() {
714
715
716 if($this->settings['ui_mode'] == 'inline') {
717
718 ?>
719 <ul class="makecommerce-picker">
720 <?php foreach($this->_banklinks as $method): ?>
721 <li class="makecommerce-picker-method">
722 <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; ?>"/>
723 <label for="makecommerce_method_picker_<?php echo $method->country.'_'.$method->name; ?>">
724 <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>
725 <?php if(in_array($this->settings['ui_inline_uselogo'], array('logo', 'text_logo'))) : ?>
726 <div><img src="<?php echo $method->logo_url; ?>" title="<?php echo ucfirst($method->name); ?>" /></div>
727 <?php endif; ?>
728 </label>
729 </li>
730 <?php endforeach; ?>
731 <?php foreach($this->_cards as $method): ?>
732 <li class="makecommerce-picker-method">
733 <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; ?>"/>
734 <label for="makecommerce_method_picker_<?php echo 'card_'.$method->name; ?>">
735 <span class="makecommerce-method-title"><?php if(in_array($this->settings['ui_inline_uselogo'], array('text', 'text_logo'))) { echo ucfirst($method->name); } ?></span>
736 <?php if(in_array($this->settings['ui_inline_uselogo'], array('logo', 'text_logo'))) : ?>
737 <div><img src="<?php echo $method->logo_url; ?>" title="<?php echo ucfirst($method->name); ?>" /></div>
738 <?php endif; ?>
739 </label>
740 </li>
741 <?php endforeach; ?>
742 </ul>
743 <?php
744
745 } else {
746 ?>
747 <select id="<?php echo $this->id; ?>" name="PRESELECTED_METHOD_<?php echo $this->id; ?>">
748 <option value=""></option>
749 <?php foreach($this->_banklinks as $method): ?>
750 <option value="<?php echo $method->country.'_'.$method->name; ?>"><?php echo strtoupper($method->country).' - '.ucfirst($method->name); ?></option>
751 <?php endforeach; ?>
752 <?php foreach($this->_cards as $method): ?>
753 <option value="card_<?php echo $method->name; ?>"><?php echo ucfirst($method->name); ?></option>
754 <?php endforeach; ?>
755 </select>
756 <ul class="makecommerce-picker">
757 <?php
758
759 if($this->_banklinks || $this->_cards) {
760 $defaultCountry = $this->getDefaultCountry();
761 ?>
762 <?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') ) : ?>
763 <div class="makecommerce_country_picker_countries">
764 <?php foreach(array_keys($this->_banklinks_grouped) as $country): ?>
765 <input style="display: none;" type="radio" id="makecommerce_country_picker_<?php echo $country; ?>" name="makecommerce_country_picker" value="<?php echo $country; ?>" <?php if($defaultCountry == $country) echo 'checked="checked" '; ?>/><?php if($this->settings['ui_widget_countryselector'] == 'flag') { ?><label for="makecommerce_country_picker_<?php echo $country; ?>" class="makecommerce_country_picker_label" style="background-image: url(<?php echo plugins_url('/images/'.$country.'32.png', __FILE__); ?>);"></label><?php } ?>
766 <?php endforeach; ?>
767 <?php if($this->settings['ui_widget_countryselector'] == 'dropdown') : ?>
768 <select name="makecommerce_country_picker_select">
769 <?php foreach(array_keys($this->_banklinks_grouped) as $country): ?>
770 <option value="<?php echo $country; ?>" <?php if($defaultCountry == $country) echo 'selected="selected" '; ?>><?php echo $this->getCountryName($country); ?></option>
771 <?php endforeach; ?>
772 <option value="card" style="display:none;"></option>
773 </select>
774 <?php endif; ?>
775 </div>
776 <?php endif; ?>
777 <?php
778 $banklinks_grouped = $this->_banklinks_grouped;
779 $banklinks_grouped['other'] = array();
780 ?>
781 <?php foreach($banklinks_grouped as $country => $methods): ?>
782 <li class="makecommerce-picker-country">
783 <?php if($this->settings['ui_widget_groupcountries'] == 'yes') : ?>
784 <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>
785 <?php endif; ?>
786 <div class="makecommerce_country_picker_methods" id="makecommerce_country_picker_methods_<?php echo $country; ?>">
787 <?php foreach($methods as $method): ?>
788 <div class="makecommerce-banklink-picker" banklink_id="<?php echo $method->country.'_'.$method->name; ?>">
789 <img src="<?php echo $method->logo_url; ?>" title="<?php echo ucfirst($method->name); ?>" />
790 </div>
791 <?php endforeach; ?>
792 <?php if($this->_cards && $this->settings['ui_widget_groupcc'] == 'no') : ?>
793 <div class="breaker"></div>
794 <?php foreach($this->_cards as $method): ?>
795 <div class="makecommerce-banklink-picker" banklink_id="card_<?php echo $method->name; ?>">
796 <img src="<?php echo $method->logo_url; ?>" title="<?php echo ucfirst($method->name); ?>" />
797 </div>
798 <?php endforeach; ?>
799 <?php elseif($country == 'other') :?>
800 <p class="no-methods"><?php _e('No payment methods for selected country' ,'wc_makecommerce_domain');?></p>
801 <?php endif; ?>
802 </div>
803 </li>
804 <?php endforeach; ?>
805 <?php if($this->_cards && $this->settings['ui_widget_groupcc'] == 'yes') : ?>
806 <li class="makecommerce-picker-country">
807 <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>
808 <div class="makecommerce_country_picker_methods" id="makecommerce_country_picker_methods_card">
809 <?php foreach($this->_cards as $method): ?>
810 <div class="makecommerce-banklink-picker" banklink_id="card_<?php echo $method->name; ?>">
811 <img src="<?php echo $method->logo_url; ?>" title="<?php echo ucfirst($method->name); ?>" />
812 </div>
813 <?php endforeach; ?>
814 </div>
815 </li>
816 <?php endif; ?>
817 <?php
818 }
819 ?>
820 </ul>
821 <div class="mc-clear-both"></div>
822 <script type="text/javascript">
823 var makecommerceId = '<?php echo $this->id; ?>';
824 var selectedCountry = '<?php echo $defaultCountry; ?>';
825
826 var logosize = '<?php echo $this->settings['ui_widget_logosize']; ?>';
827 jQuery('div.makecommerce_country_picker_methods').addClass('logosize-'+logosize);
828
829 <?php if(count($banklinks_grouped) == 1): ?>
830 jQuery('li.makecommerce-picker-country').show();
831 jQuery('div.makecommerce_country_picker_countries').hide();
832 jQuery('li.makecommerce-picker-country > input, li.makecommerce-picker-country > label').hide();
833 <?php else: ?>
834 makecommercePick();
835
836 jQuery('body').on('change', 'select[name=makecommerce_country_picker_select]', function() {
837 selectedCountry = jQuery(this).val();
838 jQuery('input[name=makecommerce_country_picker]').removeAttr('checked');
839 makecommercePick();
840 });
841 jQuery('body').on('change', 'input[name=makecommerce_country_picker]', function() {
842 if(jQuery(this).is(":checked")) {
843 selectedCountry = jQuery(this).val();
844 jQuery('select[name=makecommerce_country_picker_select]').val(selectedCountry);
845 makecommercePick();
846 }
847 });
848
849 function makecommercePick() {
850 jQuery('select#'+makecommerceId).val('');
851 jQuery('div.makecommerce-banklink-picker').removeClass('selected');
852 jQuery('label.makecommerce_country_picker_label').removeClass('selected');
853
854 jQuery('li.makecommerce-picker-country').hide();
855 jQuery('div#makecommerce_country_picker_methods_' + selectedCountry).parent().show();
856 jQuery('label[for=makecommerce_country_picker_' + selectedCountry + ']').addClass('selected');
857 }
858 <?php endif; ?>
859
860 jQuery('div.makecommerce-banklink-picker').on('click', function() {
861 var banklink_id = jQuery(this).attr('banklink_id');
862 jQuery('select#'+makecommerceId).val(banklink_id);
863
864 jQuery('div.makecommerce-banklink-picker').removeClass('selected');
865 jQuery(this).addClass('selected');
866 });
867 </script>
868 <?php
869 }
870
871 if($this->settings['ui_open_by_default'] == 'yes') {
872 ?>
873 <script type="text/javascript">
874 jQuery('input#payment_method_<?php echo $this->id; ?>').trigger('click');
875 </script>
876 <?php
877 }
878 }
879
880
881
882
883
884 protected function getCountryName($slug) {
885 switch($slug) {
886 case 'ee': return __('Estonia', 'wc_makecommerce_domain'); break;
887 case 'lv': return __('Latvia', 'wc_makecommerce_domain'); break;
888 case 'lt': return __('Lithuania', 'wc_makecommerce_domain'); break;
889 case 'fi': return __('Finland', 'wc_makecommerce_domain'); break;
890 }
891 return $slug;
892 }
893
894 private function getDefaultCountry() {
895 if ($this->_getWooCommerce()->customer) {
896 $customerCountry = strtolower($this->_getWooCommerce()->customer->get_shipping_country());
897 if(array_key_exists($customerCountry, $this->_banklinks_grouped)) {
898 return $customerCountry;
899 } else {
900 return 'other';
901 }
902 }
903
904 $localeToCountry = array(
905 'et' => 'ee',
906 'lv' => 'lv',
907 'lt' => 'lt',
908 'fi' => 'fi',
909 );
910 if(array_key_exists(get_locale(), $localeToCountry)) {
911 return $localeToCountry[get_locale()];
912 }
913
914 return key($this->_banklinks_grouped);
915 }
916
917
918 protected function getImageUrl($methodName) { // remove it
919 //$imageUrlPath = 'https://static.maksekeskus.ee/img/channel/lnd/';
920 $imageUrlPath = $this->MK->getEnvUrls()->staticsUrl.'img/channel/lnd/';
921 return $imageUrlPath.$methodName.'.png';
922 }
923
924 public function validate_fields() {
925 $selected = isset($_POST['PRESELECTED_METHOD_' . $this->id]) ? sanitize_text_field($_POST['PRESELECTED_METHOD_' . $this->id]) : false;
926
927 if (!$selected) {
928 wc_add_notice(__('Please select suitable payment option!', 'wc_makecommerce_domain'), 'error');
929 } else {
930 // is this used??
931 $this->_getWooCommerce()->session->makecommerce_preselected_method = $selected;
932 }
933
934 return true;
935 }
936
937
938 public function process_payment($orderId) {
939
940 $order = new WC_Order($orderId);
941
942 $selected = isset($_POST['PRESELECTED_METHOD_' . $this->id]) ? sanitize_text_field($_POST['PRESELECTED_METHOD_' . $this->id]) : false;
943
944 if (!empty($selected)) {
945
946 update_post_meta($order->get_order_number(), '_makecommerce_preselected_method', $selected);
947
948 $request_body = array(
949 'transaction' => array(
950 'amount' => (string)sprintf("%.2f", $order->get_total()),
951 'currency' => method_exists($order, 'get_currency') ? $order->get_currency() : $order->currency,
952 'reference' => $order->get_order_number(),
953 'transaction_url' => array(
954 'return_url' => array(
955 'url' => $this->payment_return_url,
956 'method' => 'POST',
957 ),
958 'cancel_url' => array(
959 'url' => $this->payment_return_url_cancel,
960 'method' => 'POST',
961 ),
962 'notification_url' => array(
963 'url' => $this->payment_return_url_m2m,
964 'method' => 'POST',
965 ),
966 ),
967 ),
968 'customer' => array(
969 'ip' => $_SERVER['REMOTE_ADDR'],
970 'country' => strtolower($order->get_billing_country()),
971 'locale' => strtolower(substr(get_locale(), 0, 2)),
972 ),
973 );
974 $transaction = $this->MK->createTransaction($request_body);
975
976 if(isset($transaction->id)) {
977 update_post_meta($order->get_order_number(), '_makecommerce_transaction_id', $transaction->id);
978 if (substr($selected, 0, 5) == 'card_') {
979 $redirect_url = $order->get_checkout_payment_url( true );
980 } else {
981 $redirect_url = false;
982 foreach ($transaction->payment_methods->banklinks as $banklink) {
983 if ($banklink->country.'_'.$banklink->name === $selected) {
984 $redirect_url = $banklink->url;
985 }
986 }
987 if (!$redirect_url) {
988 $redirect_url = $this->_getRedirectUrl($selected).$transaction->id;
989 }
990 }
991 return array(
992 'result' => 'success',
993 'redirect' => $redirect_url
994 );
995 }
996 }
997
998 wc_add_notice(__('An error occured when trying to process payment!', 'wc_makecommerce_domain'), 'error');
999 return array(
1000 'result' => 'failure',
1001 );
1002 }
1003
1004
1005 protected function _getRedirectUrl($selected) {
1006 foreach($this->_banklinks as $method) {
1007 if($selected == $method->country.'_'.$method->name)
1008 return $method->url;
1009 }
1010
1011 return false;
1012 }
1013
1014 /*
1015 protected function _getOrderConfirmationUrl($order) {
1016
1017 global $sitepress;
1018 if(isset($sitepress)) {
1019 $baseUrl = $sitepress->language_url( ICL_LANGUAGE_CODE );
1020 $lang = ICL_LANGUAGE_CODE;
1021 } else {
1022 $baseUrl = site_url();
1023 $lang = strtolower(substr(get_locale(), 0, 2));
1024 }
1025 $url = add_query_arg( array(
1026 'makecommerce_card_pay' => '1',
1027 'order_id' => $order->get_order_number(),
1028 'lang' => $lang,
1029 ), $baseUrl);
1030
1031 // $url = site_url('?makecommerce_card_pay=1&order_id='.$order->get_order_number().'&lang='.(defined('ICL_LANGUAGE_CODE') ? ICL_LANGUAGE_CODE : strtolower(substr(get_locale(), 0, 2))));
1032 return $url;
1033 }
1034
1035 */
1036
1037 public function receipt_page($orderId) {
1038 $order = new WC_Order($orderId);
1039 if (substr(get_post_meta($orderId, '_makecommerce_preselected_method', true), 0, 5) == 'card_' && $order->get_status() == 'pending') {
1040 echo "<br>".__('The order is still awaiting your payment', 'wc_makecommerce_domain')."<br>";
1041 echo $this->generateCardForm($order);
1042 }
1043 }
1044
1045
1046 public function generateCardForm($orderId) {
1047 $order = new WC_Order($orderId);
1048 $has_subscription = function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order);
1049 $scriptSrc = htmlspecialchars($this->MK->getEnvUrls()->checkoutjsUrl.'checkout.js');
1050 $transactionId = get_post_meta($order->get_order_number(), '_makecommerce_transaction_id', true);
1051 $idReference = $order->get_order_number();
1052 $jsParams = array(
1053 'key' => $this->MK->getPublishableKey(),
1054 'transaction' => $transactionId,
1055 'selector' => '#submit_banklinkmakecommerce_payment_form',
1056 'amount' => sprintf("%.2f", $order->get_total()),
1057 'locale' => !empty($_GET['lang']) ? $_GET['lang'] : (defined('ICL_LANGUAGE_CODE') ? ICL_LANGUAGE_CODE : strtolower(substr(get_locale(), 0, 2))),
1058 'open-on-load' => 'true',
1059 '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)) : ''),
1060 'email' => ($this->settings['cc_pass_cust_data'] == 'yes' ? (string) (method_exists($order, 'get_billing_email') ? $order->get_billing_email() : $order->billing_email) : ''),
1061 'name' => get_option('mc_shop_name', ''),
1062 'description' => __('Order', 'woocommerce') . '&nbsp;' . (string) $idReference,
1063 'completed' => 'makecommerce_cc_complete',
1064 'currency' => 'EUR',
1065 'backdrop-close' => 'false',
1066 );
1067 if ($has_subscription) {
1068 $jsParams['recurring-required'] = 'true';
1069 $jsParams['recurring-title'] = __('Pay for subscription', 'wc_makecommerce_domain');
1070 $jsParams['recurring-description'] = __('This order contains subscriptions', 'wc_makecommerce_domain');
1071 $jsParams['recurring-confirmation'] = __('I agree that my card will be recurringly billed by this store', 'wc_makecommerce_domain');
1072 }
1073 ?>
1074 <script type="text/javascript">
1075 function makecommerce_cc_complete(data) {
1076 if(data.paymentToken) {
1077 jQuery('div.mc-processing-message').show();
1078
1079 var submitform = jQuery('<form action="<?php echo $this->payment_return_url; ?>" method="POST" style="display: none;"><input type="submit"/><input type="hidden" name="transaction" value="<?php echo $transactionId; ?>" /></form>');
1080 for(var key in data) {
1081 submitform.append(jQuery('<input type="hidden" name="'+key+'" />').val(data[key]));
1082 }
1083 jQuery('body').append(submitform);
1084 submitform.submit();
1085 }
1086 }
1087 </script>
1088 <form id="cc_form" >
1089 <input type="submit" class="button-alt" id="submit_banklinkmakecommerce_payment_form" value="<?php echo __('Pay with credit card', 'wc_makecommerce_domain'); ?>" />
1090 <script type="text/javascript" src="<?php echo $scriptSrc; ?>" <?php echo $this->_toHtmlAttributes($jsParams); ?>></script>
1091 </form>
1092 <div class="mc-processing-message"><img src="<?php echo plugins_url('/images/loading.png', __FILE__); ?>"/> <?php echo __('Please wait, processing payment...', 'wc_makecommerce_domain'); ?></div>
1093 <?php
1094 }
1095
1096
1097 protected function _toHtmlAttributes($input) {
1098 $result = array();
1099 foreach ($input as $key => $value) {
1100 $result[] = 'data-' . htmlspecialchars($key) . '=' . '"' . htmlspecialchars($value) . '"';
1101 }
1102 return implode(' ', $result);
1103 }
1104
1105 public function makecommerce_return_trigger($vars) {
1106 $vars[] = 'makecommerce_return';
1107 $vars[] = 'ajax_content';
1108 $vars[] = 'makecommerce_card_pay';
1109 return $vars;
1110 }
1111
1112 public function makecommerce_return_trigger_check() {
1113 if (intval(get_query_var('makecommerce_return')) > 0) {
1114 $return_url = mk_check_payment();
1115 if (intval(get_query_var('ajax_content'))) {
1116 echo json_encode(array('redirect' => $return_url));
1117 } else {
1118 wp_redirect($return_url);
1119 }
1120 exit;
1121 }
1122 }
1123
1124
1125 } // class ends here
1126
1127 New woocommerce_makecommerce(true);
1128
1129 // Woocommerce Multilingual overrides
1130 if (is_plugin_active('woocommerce-multilingual/wpml-woocommerce.php')) {
1131 add_filter( 'get_post_metadata', 'mc_override_payment_method_string', 5, 4 );
1132 }
1133
1134 } // init ends here
1135
1136
1137
1138
1139 function woocommerce_payment_makecommerce_add($methods) {
1140 $methods[] = 'woocommerce_makecommerce';
1141 return $methods;
1142 }
1143
1144 add_action('plugins_loaded', 'woocommerce_payment_makecommerce_init');
1145 add_action('woocommerce_payment_gateways', 'woocommerce_payment_makecommerce_add');
1146
1147 // Banklinks update wrapper for action
1148 function update_mc_banklinks() {
1149 $obj = new woocommerce_makecommerce(true);
1150 $obj->mc_banklinks_reload(true);
1151 }
1152
1153 function mc_override_payment_method_string( $check, $object_id, $meta_key, $single ){
1154 if($meta_key == '_payment_method_title') {
1155 $payment_method = get_post_meta( $object_id, '_payment_method', true );
1156 if( $payment_method == 'makecommerce' ){
1157 $payment_gateways = WC()->payment_gateways->payment_gateways();
1158 if( isset( $payment_gateways[ $payment_method ] ) ){
1159 $title = $payment_gateways[ $payment_method ]->title;
1160 return $title;
1161 }
1162 }
1163 }
1164 return $check;
1165 }
1166