PluginProbe
MakeCommerce for WooCommerce / 2.5.2
MakeCommerce for WooCommerce v2.5.2
4.1.0 4.0.8 trunk 1.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 2.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2.0 2.2.1 2.2.2 All 96 releases
makecommerce / makecommerce-payment.php

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

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