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

makecommerce.php in MakeCommerce for WooCommerce 1.1.0, at makecommerce.php

2,131 lines 87.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: MakeCommerce for WooCommerce
4 Description: Adds MakeCommerce payment gateway and Itella/Omniva parcel machine shipping methods to Woocommerce checkout
5 Version: 1.1.0
6 Author: Maksekeskus AS
7 Author URI: https://MakeCommerce.net/
8 Text Domain: wc_makecommerce_domain
9 */
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit; // Exit if accessed directly.
13 }
14
15 if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
16
17 global $mkDbTable;
18 $mkDbTable = 'mc_banklinks';
19
20 function mc_install() {
21 global $wpdb;
22 global $mkDbTable;
23
24 $tableName = $wpdb->prefix . $mkDbTable;
25
26 $charset = $wpdb->get_charset_collate();
27
28 $sql = "CREATE TABLE $tableName (
29 id mediumint(9) NOT NULL AUTO_INCREMENT,
30 type varchar(10) NOT NULL,
31 country char(2) NOT NULL,
32 name varchar(25) NOT NULL,
33 url varchar(250) NOT NULL,
34 UNIQUE KEY id (id)
35 ) $charset;";
36
37 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
38 dbDelta( $sql );
39 }
40
41 register_activation_hook( __FILE__, 'mc_install' );
42
43 if (!class_exists('wc_makecommerce_domain')) {
44 require_once('includes/Api.php');
45 }
46
47 function woocommerce_payment_makecommerce_init() {
48 load_plugin_textdomain('wc_makecommerce_domain', false, dirname(plugin_basename(__FILE__)) . '/');
49
50
51 class woocommerce_makecommerce extends WC_Payment_Gateway {
52
53 const MC_CANCELLED = 'CANCELLED';
54 const MC_COMPLETED = 'COMPLETED';
55 const MC_DEPOSITED = 'DEPOSITED';
56
57 const MC_PART_REFUNDED = 'PART_REFUNDED';
58 const MC_REFUNDED = 'REFUNDED';
59
60 const module_name = 'MakeCommerce';
61 const api_url = 'https://api.maksekeskus.ee/v1/';
62 const gateway_url = 'https://payment.maksekeskus.ee/pay/1/signed.html';
63 const gateway_url_static = 'https://payment.maksekeskus.ee/checkout/dist/';
64 const fo_url = 'https://merchant.maksekeskus.ee/';
65 const test_api_url = 'https://api-test.maksekeskus.ee/v1/';
66 const test_gateway_url = 'https://payment-test.maksekeskus.ee/pay/1/signed.html';
67 const test_gateway_url_static = 'https://payment-test.maksekeskus.ee/checkout/dist/';
68 const test_fo_url = 'https://merchant-test.maksekeskus.ee/';
69 const billing_descriptor_dba = '';
70 const currencies_allowed = 'EUR';
71 const module_homepage_url = 'https://maksekeskus.ee/en/integration-modules/makecommerce-woocommerce-payment-plugin/';
72 const testenv_homepage_url = 'http://maksekeskus.ee/en/for-developers/test-environment/';
73
74 public $id = 'makecommerce';
75 public $version = '1.1';
76
77 public $return_url;
78 public $return_url_cancel;
79
80 public $return_url_cc;
81
82 protected $_shop_id;
83 protected $_api_key_secret;
84 protected $_api_key_public;
85
86 protected $_gateway_url_static;
87
88 protected $_banklinks = array();
89 protected $_banklinks_grouped;
90 protected $_cards = array();
91
92 protected $_api;
93
94 protected $_init;
95
96 public function __construct($init = false) {
97
98 $this->_init = $init;
99
100 $this->return_url = site_url('/?makecommerce_return=1');
101 $this->return_url_cancel = site_url('/?makecommerce_return=1');
102
103 $this->return_url_cc = site_url('/?makecommerce_return=2');
104
105 // Load the form fields.
106 $this->init_form_fields();
107
108 // Load the settings.
109 $this->init_settings();
110
111 $this->initBanklinks();
112
113 $this->title = $this->settings['ui_widget_title'];
114 if (defined('ICL_LANGUAGE_CODE') && !empty($this->settings['ui_widget_title_'.ICL_LANGUAGE_CODE])) {
115 $this->title = $this->settings['ui_widget_title_'.ICL_LANGUAGE_CODE];
116 }
117 $this->method_title = 'MakeCommerce';
118 $this->description = true;
119
120 $this->_api = mk_get_api();
121 if (!$this->_api && $this->_init) {
122 add_action( 'admin_notices', array(&$this, 'makecommerce_api_info_missing') );
123 }
124
125 if(get_option('mk_api_type', false) == 'live') {
126 $this->_gateway_url_static = self::gateway_url_static;
127 } elseif (get_option('mk_api_type', false) == 'test') {
128 $this->_gateway_url_static = self::test_gateway_url_static;
129 }
130
131 $this->supports = array(
132 'products',
133 'refunds',
134 );
135
136 add_filter('query_vars', array(&$this, 'makecommerce_return_trigger'));
137 add_action('template_redirect', array(&$this, 'makecommerce_return_trigger_check'));
138
139 add_action( 'wp_ajax_makecommerce_pay_token', array(&$this, 'makecommerce_pay_token') );
140 add_action( 'wp_ajax_nopriv_makecommerce_pay_token', array(&$this, 'makecommerce_pay_token') );
141
142 if($this->_init == false) {
143 add_action('woocommerce_update_options_payment_gateways', array(&$this, 'process_admin_options'));
144 add_action('woocommerce_update_options_payment_gateways_' . $this->id, array(&$this, 'process_admin_options'));
145
146 add_action('woocommerce_receipt_' . $this->id, array(&$this, 'receipt_page'));
147 add_action('woocommerce_admin_order_data_after_order_details', array(&$this, 'admin_order_page'), 10, 1);
148
149 wp_enqueue_script('jquery');
150 wp_enqueue_style('makecommerce', plugins_url('/css/makecommerce.css', __FILE__), array(), $this->version);
151 }
152
153 if(is_admin()) {
154 add_action( 'wp_ajax_mc_banklinks_reload', array(&$this, 'mc_banklinks_reload') );
155 }
156 }
157
158 function makecommerce_api_info_missing() {
159 ?>
160 <div class="notice notice-error is-dismissible">
161 <p>
162 <?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'); ?>
163 <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>
164 </p>
165 </div>
166 <?php
167 }
168
169 function makecommerce_banklinks_list_empty() {
170 ?>
171 <div class="notice notice-error is-dismissible">
172 <p>
173 <?php echo __('The payment methods list for MakeCommerce payment module is empty.', 'wc_makecommerce_domain'); ?>
174 <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>
175 </p>
176 </div>
177 <?php
178 }
179
180 function makecommerce_banklinks_list_type_notice() {
181 ?>
182 <div class="notice notice-error is-dismissible">
183 <p>
184 <?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'); ?>
185 <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>
186 </p>
187 </div>
188 <?php
189 }
190
191 /**
192 * Initialise Gateway Settings Form Fields
193 */
194 function init_form_fields() {
195
196 $languages = apply_filters('wpml_active_languages', NULL, 'skip_missing=0');
197
198 $this->form_fields = array();
199 $this->form_fields['header'] = array(
200 'type' => 'mc_header',
201 );
202 $this->form_fields['active'] = array(
203 'title' => __('Enable/Disable', 'wc_makecommerce_domain'),
204 'type' => 'checkbox',
205 'label' => __('Enable MakeCommerce payments', 'wc_makecommerce_domain'),
206 'default' => 'no'
207 );
208 $this->form_fields['api_title'] = array(
209 'title' => __('MakeCommerce API', 'wc_makecommerce_domain'),
210 'description' => sprintf(__('Go to <a href="%s">API settings</a> to fill in the credentials', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=api&section=mk_api')),
211 'type' => 'title',
212 );
213 $this->form_fields['ui_title'] = array(
214 'title' => '<br>'.__('User Interface', 'wc_makecommerce_domain'),
215 'type' => 'title',
216 'class' => 'ui-identifier',
217 );
218 $this->form_fields['ui_open_by_default'] = array(
219 'title' => __('Set as default selection', 'wc_makecommerce_domain'),
220 'label' => __('MakeCommerce payments widget will be selected by default', 'wc_makecommerce_domain'),
221 'type' => 'checkbox',
222 'default' => 'yes',
223 'class' => 'ui-identifier',
224 );
225 $this->form_fields['ui_mode'] = array(
226 'title' => __('Display MC payment channels as', 'wc_makecommerce_domain'),
227 'type' => 'mc_hidden',
228 'default' => 'widget',
229 'options' => array(
230 'inline' => __('List', 'wc_makecommerce_domain'),
231 'widget' => __('Grouped to widget', 'wc_makecommerce_domain'),
232 ),
233 'class' => 'ui-identifier',
234 );
235
236
237 if (empty($languages)) {
238 $this->form_fields['ui_widget_title'] = array(
239 'title' => __('Payments widget title', 'wc_makecommerce_domain'),
240 'type' => 'text',
241 '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'),
242 'default' => __('Pay with bank-links or credit card', 'wc_makecommerce_domain'),
243 'class' => 'ui-identifier',
244 );
245 } else {
246 foreach ($languages as $language_code => $language) {
247 $language_name = !empty($language['translated_name']) ? $language['translated_name'] : $language_code;
248 $this->form_fields['ui_widget_title_'.$language_code] = array(
249 'title' => __('Payments widget title', 'wc_makecommerce_domain').sprintf(' (%s)', $language_code),
250 'type' => 'text',
251 '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'),
252 'default' => __('Pay with bank-links or credit card', 'wc_makecommerce_domain'),
253 'class' => 'ui-identifier',
254 );
255 }
256 }
257 $this->form_fields['ui_inline_uselogo'] = array(
258 'title' => __('MC payment channels display style', 'wc_makecommerce_domain'),
259 'type' => 'select',
260 'default' => 'logo',
261 'options' => array(
262 'logo' => __('Logo', 'wc_makecommerce_domain'),
263 'text_logo' => __('Text & logo', 'wc_makecommerce_domain'),
264 'text' => __('Text', 'wc_makecommerce_domain'),
265 ),
266 'class' => 'ui-identifier',
267 );
268 $this->form_fields['ui_widget_logosize'] = array(
269 'title' => __('Size of payment channel logos', 'wc_makecommerce_domain'),
270 'type' => 'select',
271 'default' => 'medium',
272 'options' => array(
273 'small' => __('Small', 'wc_makecommerce_domain'),
274 'medium' => __('Medium', 'wc_makecommerce_domain'),
275 'large' => __('Large', 'wc_makecommerce_domain')
276 ),
277 'class' => 'ui-identifier',
278 );
279 $this->form_fields['ui_widget_groupcountries'] = array(
280 'title' => __('Group bank-links by countries', 'wc_makecommerce_domain'),
281 'type' => 'mc_hidden',
282 'default' => 'no',
283 'class' => 'ui-identifier',
284 );
285 $this->form_fields['ui_widget_countryselector'] = array(
286 'title' => __('Country selector style', 'wc_makecommerce_domain'),
287 'type' => 'mc_hidden',
288 'default' => 'flag',
289 'options' => array(
290 'flag' => __('Flag', 'wc_makecommerce_domain'),
291 'dropdown' => __('Dropdown', 'wc_makecommerce_domain'),
292 ),
293 'class' => 'ui-identifier',
294 );
295 $this->form_fields['ui_widget_groupcc'] = array(
296 'title' => __('Group credit card into separate widget', 'wc_makecommerce_domain'),
297 'type' => 'mc_hidden',
298 'default' => 'no',
299 'class' => 'ui-identifier',
300 );
301 $this->form_fields['ui_chorder'] = array(
302 'title' => __('Define custom order of payment channels', 'wc_makecommerce_domain'),
303 'type' => 'text',
304 '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'),
305 'class' => 'ui-identifier',
306 );
307 $this->form_fields['ui_javascript'] = array(
308 'type' => 'ui_javascript',
309 );
310 $this->form_fields['cc_title'] = array(
311 'title' => '<br>'.__('Credit Card Settings', 'wc_makecommerce_domain'),
312 'type' => 'title',
313 );
314 $this->form_fields['cc_pass_cust_data'] = array(
315 'title' => __('Prefill Credit Card form with customer data', 'wc_makecommerce_domain'),
316 'type' => 'checkbox',
317 'default' => 'yes',
318 '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'),
319 );
320 $this->form_fields['cc_shop_name'] = array(
321 'title' => __('Shop name on credit card payment', 'wc_makecommerce_domain'),
322 'type' => 'text',
323 'desc_tip' => __('This will appear on buyer\'s credit card transaction', 'wc_makecommerce_domain'),
324 );
325 $this->form_fields['cc_cart_reference_string'] = array(
326 'title' => __('Order reference on credit card payment', 'wc_makecommerce_domain'),
327 'type' => 'text',
328 'default' => 'Order %s',
329 'desc_tip' => __('This will appear on buyer\'s credit card transaction where "%s" is the order number', 'wc_makecommerce_domain'),
330 );
331 $this->form_fields['adv_title'] = array(
332 'title' => '<br>'.__('Advanced Settings', 'wc_makecommerce_domain'),
333 'type' => 'title',
334 );
335 $this->form_fields['reload_links'] = array(
336 'type' => 'mc_banklinks_reload',
337 'title' => __('Update payment methods', 'wc_makecommerce_domain'),
338 'description' => __('Update', 'wc_makecommerce_domain'),
339 'desc_tip' => __('This will update shop configuration from MakeCommerce servers.', 'wc_makecommerce_domain'),
340 );
341 }
342
343 public function generate_mc_hidden_html( $key, $data ) {
344 $field_key = $this->get_field_key($key);
345 ob_start();
346 ?>
347 <tr style="display: none;">
348 <td colspan="2">
349 <input type="hidden" name="<?php echo $field_key; ?>" value="<?php echo $data['default']; ?>" />
350 </td>
351 </tr>
352 <?php
353 return ob_get_clean();
354 }
355
356 public function generate_mc_banklinks_reload_html( $key, $data ) {
357
358 $field = $this->get_field_key( $key );
359 $defaults = array(
360 'title' => '',
361 'disabled' => false,
362 'class' => '',
363 'css' => '',
364 'placeholder' => '',
365 'type' => 'text',
366 'desc_tip' => false,
367 'description' => '',
368 'custom_attributes' => array()
369 );
370
371 $data = wp_parse_args( $data, $defaults );
372
373 ob_start();
374 ?>
375 <tr valign="top">
376 <th scope="row" class="titledesc">
377 <label for="<?php echo esc_attr( $field ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
378 <?php echo $this->get_tooltip_html( $data ); ?>
379 </th>
380 <td class="forminp">
381 <fieldset>
382 <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
383 <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 ); ?> />
384 <script type="text/javascript">
385 jQuery('input#mc_banklinks_reload').on('click', function() {
386 init_mc_loading();
387 jQuery.ajax({
388 url: '<?php echo get_site_url(); ?>/wp-admin/admin-ajax.php',
389 type: 'POST',
390 data: 'action=mc_banklinks_reload',
391 success: function (output) {
392 if(output.data) {
393 alert(output.data);
394 } else {
395 alert('<?php echo __('There was an error with your update. Please try again.', 'wc_makecommerce_domain'); ?>');
396 }
397 },
398 complete: function() { stop_mc_loading(); }
399 });
400 });
401
402 function init_mc_loading() {
403 jQuery('input#mc_banklinks_reload').attr('disabled', 'disabled');
404 }
405
406 function stop_mc_loading() {
407 jQuery('input#mc_banklinks_reload').removeAttr('disabled');
408 }
409 </script>
410 </fieldset>
411 </td>
412 </tr>
413 <?php
414
415 return ob_get_clean();
416 }
417
418 public function generate_ui_javascript_html( $key, $data ) {
419 ?>
420 <script type="text/javascript">
421 jQuery(document).ready(function($) {
422
423 var api_type = $('#woocommerce_<?php echo $this->id; ?>_api_type');
424
425 var ui_inline_uselogo_row = $('#woocommerce_<?php echo $this->id; ?>_ui_inline_uselogo').closest('tr');
426 var ui_widget_title_row = $('#woocommerce_<?php echo $this->id; ?>_ui_widget_title').closest('tr');
427 var ui_widget_logosize_row = $('#woocommerce_<?php echo $this->id; ?>_ui_widget_logosize').closest('tr');
428 var ui_widget_countryselector_row = $('#woocommerce_<?php echo $this->id; ?>_ui_widget_countryselector').closest('tr');
429 var ui_widget_groupcountries_row = $('#woocommerce_<?php echo $this->id; ?>_ui_widget_groupcountries').closest('tr');
430 var ui_widget_groupcc_row = $('#woocommerce_<?php echo $this->id; ?>_ui_widget_groupcc').closest('tr');
431 var ui_widget_groupcc_title_row = $('#woocommerce_<?php echo $this->id; ?>_ui_widget_groupcc_title').closest('tr');
432
433 var ui_mode = $('#woocommerce_<?php echo $this->id; ?>_ui_mode');
434 var ui_widget_groupcountries = $('#woocommerce_<?php echo $this->id; ?>_ui_widget_groupcountries');
435 var ui_widget_groupcc = $('#woocommerce_<?php echo $this->id; ?>_ui_widget_groupcc');
436
437 parseVisibility();
438 function parseVisibility() {
439 $('.ui-identifier').closest('tr').show();
440
441 if(api_type.val() == 'live') {
442 $('.mc-test-link').hide();
443 $('.api-test').closest('tr').hide();
444 } else {
445 $('.mc-test-link').show();
446 $('.api-live').closest('tr').hide();
447 }
448
449 if(ui_mode.val() == 'inline') {
450 ui_widget_title_row.hide();
451 ui_widget_logosize_row.hide();
452 ui_widget_countryselector_row.hide();
453 ui_widget_groupcountries_row.hide();
454 ui_widget_groupcc_row.hide();
455 ui_widget_groupcc_title_row.hide();
456 } else {
457 ui_inline_uselogo_row.hide();
458
459 if(ui_widget_groupcountries.prop('checked')) {
460 ui_widget_countryselector_row.hide();
461 }
462 if(!ui_widget_groupcc.prop('checked')) {
463 ui_widget_groupcc_title_row.hide();
464 }
465 }
466 }
467
468 api_type.on('change', parseVisibility);
469 ui_mode.on('change', parseVisibility);
470 ui_widget_groupcountries.on('change', parseVisibility);
471 ui_widget_groupcc.on('change', parseVisibility);
472
473 });
474 </script>
475 <?php
476 }
477
478 public function generate_mc_header_html( $key, $data ) {
479 ?>
480 <div class="makecommerce-info">
481 <div class="makecommerce-logo">
482 <a target="_blank" href="http://makecommerce.net"><img src="<?php echo plugins_url('/images/makecommerce_logo_en.svg', __FILE__); ?>" class="makecommerce-logo"></a>
483 </div>
484 <div class="makecommerce-links">
485 <div class="makecommerce-link"><a target="_blank" href="https://merchant.maksekeskus.ee">Merchant Portal</a></div>
486 <div class="makecommerce-link"><a target="_blank" href="https://makecommerce.net/">makecommerce.net</a></div>
487 <div class="makecommerce-link"><a target="_blank" href="http://maksekeskus.ee">maksekeskus.ee</a></div>
488 </div>
489 </div>
490 <?php
491 }
492
493 public function mc_banklinks_reload($force = false) {
494 if ($force || (defined('DOING_AJAX') && DOING_AJAX)) {
495
496 global $wpdb;
497 global $mkDbTable;
498 global $wp_version;
499
500 $tableName = $wpdb->prefix . $mkDbTable;
501 $wpdb->query('TRUNCATE TABLE '.$tableName);
502
503 $request_params = array(
504 'environment' => json_encode(array(
505 'platform' => 'wordpress '.$wp_version,
506 'module' => $this->id.' '.$this->version,
507 )),
508 );
509
510 if (!$this->_api) {
511 return false;
512 }
513
514 try {
515 $methods = $this->_api->getShopConfig($request_params)->payment_methods;
516 } catch (Exception $e) {
517 error_log(print_r($e, 1));
518 return false;
519 }
520 if(isset($methods->banklinks)) {
521 foreach($methods->banklinks as $method) {
522 $wpdb->insert($tableName, array('type' => 'banklink', 'country' => $method->country, 'name' => $method->name, 'url' => $method->url));
523 }
524 $updated = true;
525 }
526
527 if(isset($methods->cards)) {
528 foreach($methods->cards as $method) {
529 $wpdb->insert($tableName, array('type' => 'card', 'name' => $method->name));
530 }
531 $updated = true;
532 }
533 if ($updated) {
534 update_option( 'mc_banklinks_api_type', get_option('mk_api_type', false) );
535 }
536 if ($force) {
537 $this->initBankLinks();
538 return $updated;
539 }
540
541 if($updated) {
542 wp_send_json(array('success' => 1, 'data' => __('Update successfully completed!', 'wc_makecommerce_domain')));
543 exit;
544 }
545
546 wp_send_json(array('success' => 0, 'data' => __('There was an error with your update. Please try again.', 'wc_makecommerce_domain')));
547 exit;
548 }
549 die();
550 }
551
552 protected function _getWooCommerce() {
553 global $woocommerce;
554 return $woocommerce;
555 }
556
557 function is_valid_for_use() {
558 return true;
559 }
560
561 public function is_available() {
562 if ($this->settings['active'] == "yes") {
563 return true;
564 }
565 }
566
567 function payment_fields() {
568
569 if($this->settings['ui_mode'] == 'inline') {
570
571 ?>
572 <ul class="makecommerce-picker">
573 <?php foreach($this->_banklinks as $method): ?>
574 <li class="makecommerce-picker-method">
575 <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; ?>"/>
576 <label for="makecommerce_method_picker_<?php echo $method->country.'_'.$method->name; ?>">
577 <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>
578 <?php if(in_array($this->settings['ui_inline_uselogo'], array('logo', 'text_logo'))) : ?>
579 <div><img src="<?php echo $this->getImageUrl($method->name); ?>" title="<?php echo ucfirst($method->name); ?>" /></div>
580 <?php endif; ?>
581 </label>
582 </li>
583 <?php endforeach; ?>
584 <?php foreach($this->_cards as $method): ?>
585 <li class="makecommerce-picker-method">
586 <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; ?>"/>
587 <label for="makecommerce_method_picker_<?php echo 'card_'.$method->name; ?>">
588 <span class="makecommerce-method-title"><?php if(in_array($this->settings['ui_inline_uselogo'], array('text', 'text_logo'))) { echo ucfirst($method->name); } ?></span>
589 <?php if(in_array($this->settings['ui_inline_uselogo'], array('logo', 'text_logo'))) : ?>
590 <div><img src="<?php echo $this->getImageUrl($method->name); ?>" title="<?php echo ucfirst($method->name); ?>" /></div>
591 <?php endif; ?>
592 </label>
593 </li>
594 <?php endforeach; ?>
595 </ul>
596 <?php
597
598 } else {
599 ?>
600 <select id="<?php echo $this->id; ?>" name="PRESELECTED_METHOD_<?php echo $this->id; ?>">
601 <option value=""></option>
602 <?php foreach($this->_banklinks as $method): ?>
603 <option value="<?php echo $method->country.'_'.$method->name; ?>"><?php echo strtoupper($method->country).' - '.ucfirst($method->name); ?></option>
604 <?php endforeach; ?>
605 <?php foreach($this->_cards as $method): ?>
606 <option value="card_<?php echo $method->name; ?>"><?php echo ucfirst($method->name); ?></option>
607 <?php endforeach; ?>
608 </select>
609 <ul class="makecommerce-picker">
610 <?php
611
612 if($this->_banklinks) {
613 $defaultCountry = $this->getDefaultCountry();
614 ?>
615 <?php if(empty($this->settings['ui_widget_groupcountries']) || $this->settings['ui_widget_groupcountries'] == 'no') : ?>
616 <div class="makecommerce_country_picker_countries">
617 <?php foreach(array_keys($this->_banklinks_grouped) as $country): ?>
618 <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 } ?>
619 <?php endforeach; ?>
620 <?php if($this->settings['ui_widget_countryselector'] == 'dropdown') : ?>
621 <select name="makecommerce_country_picker_select">
622 <?php foreach(array_keys($this->_banklinks_grouped) as $country): ?>
623 <option value="<?php echo $country; ?>" <?php if($defaultCountry == $country) echo 'selected="selected" '; ?>><?php echo $this->getCountryName($country); ?></option>
624 <?php endforeach; ?>
625 <option value="card" style="display:none;"></option>
626 </select>
627 <?php endif; ?>
628 </div>
629 <?php endif; ?>
630 <?php foreach($this->_banklinks_grouped as $country => $methods): ?>
631 <li class="makecommerce-picker-country">
632 <?php if($this->settings['ui_widget_groupcountries'] == 'yes') : ?>
633 <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>
634 <?php endif; ?>
635 <div class="makecommerce_country_picker_methods" id="makecommerce_country_picker_methods_<?php echo $country; ?>">
636 <?php foreach($methods as $method): ?>
637 <div class="makecommerce-banklink-picker" banklink_id="<?php echo $method->country.'_'.$method->name; ?>">
638 <img src="<?php echo $this->getImageUrl($method->name); ?>" title="<?php echo ucfirst($method->name); ?>" />
639 </div>
640 <?php endforeach; ?>
641 <?php if($this->_cards && $this->settings['ui_widget_groupcc'] == 'no') : ?>
642 <div class="breaker"></div>
643 <?php foreach($this->_cards as $method): ?>
644 <div class="makecommerce-banklink-picker" banklink_id="card_<?php echo $method->name; ?>">
645 <img src="<?php echo $this->getImageUrl($method->name); ?>" title="<?php echo ucfirst($method->name); ?>" />
646 </div>
647 <?php endforeach; ?>
648 <?php endif; ?>
649 </div>
650 </li>
651 <?php endforeach; ?>
652 <?php if($this->_cards && $this->settings['ui_widget_groupcc'] == 'yes') : ?>
653 <li class="makecommerce-picker-country">
654 <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>
655 <div class="makecommerce_country_picker_methods" id="makecommerce_country_picker_methods_card">
656 <?php foreach($this->_cards as $method): ?>
657 <div class="makecommerce-banklink-picker" banklink_id="card_<?php echo $method->name; ?>">
658 <img src="<?php echo $this->getImageUrl($method->name); ?>" title="<?php echo ucfirst($method->name); ?>" />
659 </div>
660 <?php endforeach; ?>
661 </div>
662 </li>
663 <?php endif; ?>
664 <?php
665 }
666 ?>
667 </ul>
668 <script type="text/javascript">
669 var makecommerceId = '<?php echo $this->id; ?>';
670 var selectedCountry = jQuery('input[name=makecommerce_country_picker]:checked').val();
671
672 var logosize = '<?php echo $this->settings['ui_widget_logosize']; ?>';
673 jQuery('div.makecommerce_country_picker_methods').addClass('logosize-'+logosize);
674
675 <?php if(count($this->_banklinks_grouped) == 1): ?>
676 jQuery('div.makecommerce_country_picker_methods').show();
677 jQuery('div.makecommerce_country_picker_countries').hide();
678 jQuery('li.makecommerce-picker-country > input, li.makecommerce-picker-country > label').hide();
679 <?php else: ?>
680 makecommercePick();
681
682 jQuery('body').on('change', 'select[name=makecommerce_country_picker_select]', function() {
683 selectedCountry = jQuery(this).val();
684 jQuery('input[name=makecommerce_country_picker]').removeAttr('checked');
685 makecommercePick();
686 });
687 jQuery('body').on('change', 'input[name=makecommerce_country_picker]', function() {
688 selectedCountry = jQuery(this).val();
689 jQuery('select[name=makecommerce_country_picker_select]').val(selectedCountry);
690 makecommercePick();
691 });
692
693 function makecommercePick() {
694 jQuery('select#'+makecommerceId).val('');
695 jQuery('div.makecommerce-banklink-picker').removeClass('selected');
696 jQuery('label.makecommerce_country_picker_label').removeClass('selected');
697
698 jQuery('div.makecommerce_country_picker_methods').hide();
699 jQuery('div#makecommerce_country_picker_methods_' + selectedCountry).show();
700 jQuery('label[for=makecommerce_country_picker_' + selectedCountry + ']').addClass('selected');
701 }
702 <?php endif; ?>
703
704 jQuery('div.makecommerce-banklink-picker').on('click', function() {
705 var banklink_id = jQuery(this).attr('banklink_id');
706 jQuery('select#'+makecommerceId).val(banklink_id);
707
708 jQuery('div.makecommerce-banklink-picker').removeClass('selected');
709 jQuery(this).addClass('selected');
710 });
711 </script>
712 <?php
713 }
714
715 if($this->settings['ui_open_by_default'] == 'yes') {
716 ?>
717 <script type="text/javascript">
718 jQuery('input#payment_method_<?php echo $this->id; ?>').trigger('click');
719 </script>
720 <?php
721 }
722 }
723
724 private function getDefaultCountry() {
725 if ($this->_getWooCommerce()->customer) {
726 $customerCountry = strtolower($this->_getWooCommerce()->customer->get_shipping_country());
727 if(array_key_exists($customerCountry, $this->_banklinks_grouped)) {
728 return $customerCountry;
729 }
730 }
731
732 $localeToCountry = array(
733 'et' => 'ee',
734 'lv' => 'lv',
735 'lt' => 'lt',
736 'fi' => 'fi',
737 );
738 if(array_key_exists(get_locale(), $localeToCountry)) {
739 return $localeToCountry[get_locale()];
740 }
741
742 return key($this->_banklinks_grouped);
743 }
744
745 private function initBanklinks() {
746 global $wpdb;
747 global $mkDbTable;
748 $this->_banklinks = array();
749
750 $tableName = $wpdb->prefix . $mkDbTable;
751 $methods = $wpdb->get_results('SELECT * FROM '.$tableName);
752
753 if(count($methods)) {
754 if(is_admin() && $this->_init == true && get_option( 'mc_banklinks_api_type' ) != get_option('mk_api_type', false)) {
755 //add_action( 'admin_notices', array(&$this, 'makecommerce_banklinks_list_type_notice') );
756 }
757 $banklinks = array();
758 $banklinks_grouped = array();
759 $cards = array();
760 foreach($methods as $method) {
761 if($method->type == 'banklink') {
762 $banklinks[] = $banklinks_grouped[$method->country][] = $method;
763 } elseif($method->type == 'card') {
764 $cards[] = $method;
765 }
766 }
767
768 usort($banklinks, array($this, 'orderBanklinks'));
769 foreach($banklinks_grouped as &$country) {
770 usort($country, array($this, 'orderBanklinks'));
771 }
772
773 $this->_banklinks = $banklinks;
774 $this->_banklinks_grouped = $banklinks_grouped;
775 $this->_cards = $cards;
776 remove_action('admin_notices', array(&$this, 'makecommerce_banklinks_list_empty'), 30);
777 } elseif(is_admin() && $this->_init == true) {
778 add_action('admin_notices', array(&$this, 'makecommerce_banklinks_list_empty'), 30);
779 }
780 }
781
782 private function orderBanklinks($a, $b) {
783 $order = array_map('trim', explode(",", $this->settings['ui_chorder']));
784
785 $posA = array_search($a->name, $order);
786 $posB = array_search($b->name, $order);
787
788 if($posA === $posB) return $a->id > $b->id ? 1 : -1;
789 if($posA === FALSE) return 1;
790 if($posB === FALSE) return -1;
791
792 return $posA > $posB ? 1 : -1;
793 }
794
795 protected function getImageUrl($methodName) {
796 $imageUrlPath = 'https://static.maksekeskus.ee/img/channel/lnd/';
797
798 return $imageUrlPath.$methodName.'.png';
799 }
800
801 public function validate_fields() {
802 $selected = isset($_POST['PRESELECTED_METHOD_' . $this->id]) ? sanitize_text_field($_POST['PRESELECTED_METHOD_' . $this->id]) : false;
803
804 if (!$selected) {
805 wc_add_notice(__('Please select suitable payment option!', 'wc_makecommerce_domain'), 'error');
806 } else {
807 $this->_getWooCommerce()->session->makecommerce_preselected_method = $selected;
808 }
809
810 return true;
811 }
812
813 function process_payment($orderId) {
814
815 $order = new WC_Order($orderId);
816
817 $selected = isset($_POST['PRESELECTED_METHOD_' . $this->id]) ? sanitize_text_field($_POST['PRESELECTED_METHOD_' . $this->id]) : false;
818
819 if(!empty($selected)) {
820
821 update_post_meta($order->id, '_makecommerce_preselected_method', $selected);
822
823 if(substr($selected, 0, 5) == 'card_') {
824
825 $request_body = array(
826 'transaction' => array(
827 'amount' => round($order->order_total, 2),
828 'currency' => $order->get_order_currency(),
829 'reference' => $order->id,
830 'transaction_url' => array(
831 'return_url' => array(
832 'url' => $this->return_url_cc,
833 'method' => 'POST',
834 ),
835 'cancel_url' => array(
836 'url' => $this->return_url_cc,
837 'method' => 'POST',
838 ),
839 'notification_url' => array(
840 'url' => $this->return_url_cc,
841 'method' => 'POST',
842 ),
843 ),
844 ),
845 'customer' => array(
846 'ip' => $_SERVER['REMOTE_ADDR'],
847 'country' => strtolower($order->billing_country),
848 'locale' => strtolower(substr(get_locale(), 0, 2)),
849 ),
850 );
851 $transaction = $this->_api->createTransaction($request_body);
852
853 if(isset($transaction->id)) {
854 update_post_meta($order->id, '_makecommerce_cc_transaction_id', $transaction->id);
855 return array(
856 'result' => 'success',
857 'redirect' => $this->_getOrderConfirmationUrl($order),
858 );
859 }
860
861 wc_add_notice(__('An error occured when trying to process payment!', 'wc_makecommerce_domain'), 'error');
862 return array(
863 'result' => 'failure',
864 );
865
866 } else {
867
868 $redirectUrl = $this->_getRedirectUrl($selected);
869
870 if($redirectUrl) {
871 $request_body = array(
872 'transaction' => array(
873 'amount' => round($order->order_total, 2),
874 'currency' => $order->get_order_currency(),
875 'reference' => $order->id,
876 'transaction_url' => array(
877 'return_url' => array(
878 'url' => $this->return_url,
879 'method' => 'POST',
880 ),
881 'cancel_url' => array(
882 'url' => $this->return_url,
883 'method' => 'POST',
884 ),
885 'notification_url' => array(
886 'url' => $this->return_url,
887 'method' => 'POST',
888 ),
889 ),
890 ),
891 'customer' => array(
892 'ip' => $_SERVER['REMOTE_ADDR'],
893 'country' => strtolower($order->billing_country),
894 'locale' => strtolower(substr(get_locale(), 0, 2)),
895 )
896 );
897 $transaction = $this->_api->createTransaction($request_body);
898
899 if(isset($transaction->id)) {
900 return array(
901 'result' => 'success',
902 'redirect' => $redirectUrl.$transaction->id,
903 );
904 }
905 }
906
907 wc_add_notice(__('An error occured when trying to process payment!', 'wc_makecommerce_domain'), 'error');
908 return array(
909 'result' => 'failure',
910 );
911
912 }
913
914 }
915
916 wc_add_notice(__('An error occured when trying to process payment!', 'wc_makecommerce_domain'), 'error');
917 return array(
918 'result' => 'failure',
919 );
920 }
921
922 protected function _getRedirectUrl($selected) {
923 foreach($this->_banklinks as $method) {
924 if($selected == $method->country.'_'.$method->name)
925 return $method->url;
926 }
927
928 return false;
929 }
930
931 protected function _getOrderConfirmationUrl($order) {
932 //$url = add_query_arg('order', $order->id, add_query_arg('key', $order->order_key, get_permalink(get_option('woocommerce_pay_page_id'))));
933 $url = site_url('?makecommerce_card_pay=1&order_id='.$order->id.'&lang='.(defined('ICL_LANGUAGE_CODE') ? ICL_LANGUAGE_CODE : strtolower(substr(get_locale(), 0, 2))));
934 return $url;
935 }
936
937 function receipt_page($orderId) {
938 echo '<p>' . __('Thank you for the order, please click on the button to start the payment.', 'wc_makecommerce_domain') . '</p>';
939
940 $order = new WC_Order($orderId);
941 if(substr(get_post_meta($orderId, '_makecommerce_preselected_method', true), 0, 5) == 'card_' && $order->get_status() == 'pending') {
942 echo $this->generateCardForm($order);
943 }
944 }
945
946 function generateCardForm($order) {
947 $scriptSrc = htmlspecialchars($this->_gateway_url_static.'checkout.js');
948 $transactionId = get_post_meta($order->id, '_makecommerce_cc_transaction_id', true);
949 $idReference = $order->id;
950 $jsParams = array(
951 'key' => $this->_api->getPublishableKey(),
952 'transaction' => $transactionId,
953 'selector' => '#submit_banklinkmakecommerce_payment_form',
954 'amount' => round($order->order_total, 2),
955 'locale' => !empty($_GET['lang']) ? $_GET['lang'] : (defined('ICL_LANGUAGE_CODE') ? ICL_LANGUAGE_CODE : strtolower(substr(get_locale(), 0, 2))),
956 'open-on-load' => 'true',
957 'client-name' => ($this->settings['cc_pass_cust_data'] == 'yes' ? (string) ($order->billing_first_name . ' ' . $order->billing_last_name) : ''),
958 'email' => ($this->settings['cc_pass_cust_data'] == 'yes' ? (string) $order->billing_email : ''),
959 'name' => $this->settings['cc_shop_name'],
960 'description' => (string)sprintf($this->settings['cc_cart_reference_string'], (string) $idReference),
961 'completed' => 'makecommerce_cc_complete',
962 'currency' => 'EUR',
963 );
964 ?>
965 <script type="text/javascript">
966 function makecommerce_cc_complete(data) {
967 if(data.paymentToken) {
968 jQuery('div.mc-processing-message').show();
969
970 var submitform = jQuery('<form action="<?php echo $this->return_url_cc; ?>" method="POST" style="display: none;"><input type="submit"/><input type="hidden" name="transaction" value="<?php echo $transactionId; ?>" /></form>');
971 for(var key in data) {
972 submitform.append('<input type="hidden" name="'+key+'" value="'+data[key]+'" />');
973 }
974 jQuery('body').append(submitform);
975 submitform.submit();
976 }
977 }
978 </script>
979 <form id="cc_form">
980 <input type="submit" class="button-alt" id="submit_banklinkmakecommerce_payment_form" value="<?php echo __('Pay', 'wc_makecommerce_domain'); ?>" />
981 <a class="button cancel" href="<?php echo esc_url($order->get_cancel_order_url()); ?>"><?php echo __('Cancel order &amp; restore cart', 'wc_makecommerce_domain'); ?></a>
982 <script type="text/javascript" src="<?php echo $scriptSrc; ?>" <?php echo $this->_toHtmlAttributes($jsParams); ?>></script>
983 </form>
984 <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>
985 <?php
986 }
987
988 protected function _toHtmlAttributes($input) {
989 $result = array();
990 foreach ($input as $key => $value) {
991 $result[] = 'data-' . htmlspecialchars($key) . '=' . '"' . htmlspecialchars($value) . '"';
992 }
993 return implode(' ', $result);
994 }
995
996 function makecommerce_return_trigger($vars) {
997 $vars[] = 'makecommerce_return';
998 $vars[] = 'makecommerce_card_pay';
999 return $vars;
1000 }
1001
1002 function makecommerce_return_trigger_check() {
1003 if(intval(get_query_var('makecommerce_return')) == 1) {
1004
1005 $returnUrl = home_url();
1006
1007 $request = stripslashes_deep($_POST);
1008 if($this->_api->verifySignature($request)) {
1009 $data = $this->_api->extractRequestData($request);
1010 $order = new WC_Order($data['reference']);
1011
1012 switch($data['status']) {
1013 case self::MC_CANCELLED:
1014 $order->update_status( 'cancelled' );
1015 wc_add_notice(__('Payment transaction cancelled', 'wc_makecommerce_domain'), 'error');
1016 $returnUrl = $this->_getWooCommerce()->cart->get_cart_url();
1017 break;
1018 case self::MC_COMPLETED:
1019 if($this->validate_completed_payment($order, $data)) {
1020 $orderNote = array();
1021 $orderNote[] = __('Transaction ID', 'wc_makecommerce_domain') . ': ' . $data['transaction'];
1022 $orderNote[] = __('Payment option', 'wc_makecommerce_domain') . ': ' . get_post_meta($order->id, '_makecommerce_preselected_method', true);
1023
1024 $order->add_order_note(implode("\r\n", $orderNote));
1025
1026 $order->payment_complete($data['transaction']);
1027 $order->update_status( 'processing' );
1028
1029 try {
1030 @ob_start();
1031 $this->receipt_page($order->id);
1032 @ob_end_clean();
1033
1034 $returnUrl = $this->get_return_url($order);
1035 } catch (Exception $ex) {
1036 @ob_end_clean();
1037 }
1038 } else {
1039 $returnUrl = $this->_getWooCommerce()->cart->get_cart_url();
1040 }
1041 break;
1042 }
1043
1044 //exit;
1045 }
1046 wp_redirect($returnUrl);
1047 exit;
1048
1049 } elseif(intval(get_query_var('makecommerce_return')) == 2) {
1050
1051 $returnUrl = home_url();
1052
1053 if(isset($_POST['paymentToken']) && isset($_POST['transaction'])) {
1054 $token = $_POST['paymentToken'];
1055 $transaction = $_POST['transaction'];
1056 }
1057
1058 if(isset($_POST['json'])) {
1059 $data = json_decode(stripslashes($_POST['json']), true);
1060 $token = $data['token']['id'];
1061 $transaction = $data['transaction']['id'];
1062 }
1063
1064 if(!empty($token) && !empty($transaction)) {
1065 global $wpdb;
1066 if($order = New WC_Order($wpdb->get_var('SELECT post_id from '.$wpdb->postmeta.' where meta_key = "_makecommerce_cc_transaction_id" AND meta_value = "'.$transaction.'"'))) {
1067 $request_body = array(
1068 'token' => $token,
1069 );
1070 $data = $this->_api->createPayment(get_post_meta($order->id, '_makecommerce_cc_transaction_id', true), $request_body);
1071 switch($data->status) {
1072 case self::MC_CANCELLED:
1073 $order->update_status( 'cancelled' );
1074 wc_add_notice(__('Payment transaction cancelled', 'wc_makecommerce_domain'), 'error');
1075 $returnUrl = $this->_getWooCommerce()->cart->get_cart_url();
1076 break;
1077 case self::MC_DEPOSITED:
1078 if($this->validate_completed_payment($order, $data)) {
1079 $orderNote = array();
1080 $orderNote[] = __('Transaction ID', 'wc_makecommerce_domain') . ': ' . $data->transaction->id;
1081 $orderNote[] = __('Payment option', 'wc_makecommerce_domain') . ': ' . get_post_meta($order->id, '_makecommerce_preselected_method', true);
1082
1083 $order->add_order_note(implode("\r\n", $orderNote));
1084
1085 $order->payment_complete($data->transaction->id);
1086 $order->update_status( 'processing' );
1087
1088 try {
1089 @ob_start();
1090 $this->receipt_page($order->id);
1091 @ob_end_clean();
1092
1093 $returnUrl = $this->get_return_url($order);
1094 } catch (Exception $ex) {
1095 @ob_end_clean();
1096 }
1097 } else {
1098 $returnUrl = $this->_getWooCommerce()->cart->get_cart_url();
1099 }
1100 break;
1101 }
1102 }
1103 }
1104
1105 wp_redirect($returnUrl);
1106 exit;
1107 }
1108
1109 if(intval(get_query_var('makecommerce_card_pay')) == 1) {
1110 if(isset($_GET['order_id'])) {
1111 if($order = New WC_Order($_GET['order_id'])) {
1112 New woocommerce_makecommerce(false);
1113 get_header();
1114 ?>
1115 <div id="primary" class="content-area">
1116 <?php $this->receipt_page($order->id); ?>
1117 </div>
1118 <?php
1119 get_sidebar();
1120 get_footer();
1121
1122 exit;
1123 }
1124 }
1125 }
1126 }
1127
1128 private function validate_completed_payment($order, $data) {
1129
1130 if(is_object($data)) {
1131 $data = json_decode(json_encode($data), true);
1132 }
1133
1134 if(empty($data['transaction'])) {
1135 $order->add_order_note(__('Payment error, missing transaction id', 'wc_makecommerce_domain'));
1136 wc_add_notice(__('Error verifying transaction', 'wc_makecommerce_domain'), 'error');
1137 return false;
1138 }
1139 if($data['amount'] != round($order->order_total, 2)) {
1140 $order->add_order_note(sprintf(__('Payment error, incorrect amount captured: %s', 'wc_makecommerce_domain'), $data['amount'].' '.$data['currency']));
1141 wc_add_notice(__('Error verifying transaction', 'wc_makecommerce_domain').', '.__('Incorrect amount captured', 'wc_makecommerce_domain'), 'error');
1142 return false;
1143 }
1144 if($data['currency'] != $order->get_order_currency()) {
1145 $order->add_order_note(sprintf(__('Payment error, incorrect currency captured: %s', 'wc_makecommerce_domain'), $data['currency']));
1146 wc_add_notice(__('Error verifying transaction', 'wc_makecommerce_domain').', '.__('Incorrect currency captured', 'wc_makecommerce_domain'), 'error');
1147 return false;
1148 }
1149
1150 return true;
1151 }
1152
1153 function admin_order_page($order) {
1154 //
1155 }
1156
1157 public function process_refund($order_id, $amount = null, $comment = '') {
1158 if ($this->_api) {
1159 try {
1160 $order = new WC_Order($order_id);
1161 $transactionId = $order->get_transaction_id();
1162
1163 if($response = $this->_api->createRefund($transactionId, array('amount' => $amount, 'comment' => ($comment ? : 'refund')))) {
1164 if($status = (string)$response->transaction->status) {
1165 switch($status) {
1166 case self::MC_REFUNDED:
1167 $order->add_order_note(sprintf(__('Refund completed for amount %s', 'wc_makecommerce_domain'), $amount));
1168 return true;
1169 break;
1170 case self::MC_PART_REFUNDED:
1171 $order->add_order_note(sprintf(__('Partial refund completed for amount %s', 'wc_makecommerce_domain'), $amount));
1172 return true;
1173 break;
1174 }
1175 }
1176 }
1177 return false;
1178
1179 } catch (Exception $e) {
1180 return new WP_Error('makecommerce_refund_error', $e->getMessage());
1181 }
1182
1183 return false;
1184 }
1185 return false;
1186 }
1187
1188 protected function getCountryName($slug) {
1189 switch($slug) {
1190 case 'ee': return __('Estonia', 'wc_makecommerce_domain'); break;
1191 case 'lv': return __('Latvia', 'wc_makecommerce_domain'); break;
1192 case 'lt': return __('Lithuania', 'wc_makecommerce_domain'); break;
1193 case 'fi': return __('Finland', 'wc_makecommerce_domain'); break;
1194 }
1195 return $slug;
1196 }
1197
1198 }
1199
1200 New woocommerce_makecommerce(true);
1201
1202 }
1203
1204 function woocommerce_payment_makecommerce_add($methods) {
1205 $methods[] = 'woocommerce_makecommerce';
1206 return $methods;
1207 }
1208
1209 add_action('plugins_loaded', 'woocommerce_payment_makecommerce_init');
1210 add_action('woocommerce_payment_gateways', 'woocommerce_payment_makecommerce_add');
1211
1212 function clear_wc_shipping_rates_cache(){
1213 $packages = WC()->cart->get_shipping_packages();
1214 foreach ($packages as $key => $value) {
1215 $shipping_session = "shipping_for_package_$key";
1216 unset(WC()->session->$shipping_session);
1217 }
1218 }
1219 add_filter('woocommerce_checkout_update_order_review', 'clear_wc_shipping_rates_cache');
1220
1221 // Parcel machine specific stuff
1222 function parcelmachine_add_method() {
1223
1224 // Delete all the wc_ship transient scum, you aren’t wanted around here, move along.
1225 // Same as being in shipping debug mode
1226 global $wpdb;
1227 $transients = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '_transient_wc_ship%'");
1228 if (count($transients)) {
1229 foreach ($transients as $tr) {
1230 $hash = substr($tr, 11);
1231 delete_transient($hash);
1232 }
1233 }
1234 $transient_value = get_transient('shipping-transient-version');
1235 WC_Cache_Helper::delete_version_transients( $transient_value );
1236 if (WC()->session) {
1237 WC()->session->set('shipping_for_package', '');
1238 }
1239
1240 if ( ! class_exists( 'WC_ParcelMachine_Shipping_Method' ) ) {
1241
1242 class WC_ParcelMachine_Shipping_Method extends WC_Shipping_Method {
1243
1244
1245 function __construct($instance_id = 0) {
1246 if (!$this->ext) {
1247 throw new Exception('Do not call this class directly!');
1248 }
1249 $this->id = 'parcelmachine_' . mb_strtolower($this->ext);
1250 $this->instance_id = $instance_id;
1251 $this->method_title = $this->name_ext . __(' Parcel Machine by MC', 'wc_makecommerce_domain');
1252 $this->init();
1253 }
1254
1255 function init() {
1256 $this->init_form_fields();
1257 $this->init_settings();
1258
1259 $this->enable = $this->settings['active'];
1260 $this->title = $this->settings['method_name'];
1261 if (defined('ICL_LANGUAGE_CODE') && !empty($this->settings['method_name_'.ICL_LANGUAGE_CODE])) {
1262 $this->title = $this->settings['method_name_'.ICL_LANGUAGE_CODE];
1263 }
1264 $this->availability = 'specific';
1265 $this->countries = $this->settings['countries'];
1266 $this->prioritization = $this->settings['prioritization'];
1267 $this->free_shipping_min_amount = $this->settings['free_shipping_min_amount'];
1268 $this->maximum_weight = (double)$this->settings['maximum_weight'];
1269 $this->short_office_names = $this->settings['short_office_names'];
1270 $this->order_country = 'unknown';
1271 add_action('woocommerce_update_options_shipping_' . $this->id, array(&$this, 'process_admin_options'));
1272 add_filter('woocommerce_review_order_after_shipping' , array(&$this, 'add_parcelmachine_checkout_fields'));
1273 add_action('woocommerce_checkout_process', array(&$this, 'check_parcelmachine_checkout_fields'));
1274 add_action('woocommerce_checkout_update_order_meta', array(&$this, 'add_parcelmachine_order_meta'));
1275 add_filter('woocommerce_order_shipping_to_display_shipped_via', array(&$his, 'add_admin_parcelmachine_via_field'));
1276 }
1277
1278 function calculate_shipping($package = array()) {
1279
1280 $price = $this->settings['price_'.strtolower($package['destination']['country'])];
1281 if ($this->free_shipping_min_amount && $package['contents_cost'] >= $this->free_shipping_min_amount) {
1282 $price = 0;
1283 }
1284 $rate = array(
1285 'id' => $this->id,
1286 'label' => $this->title,
1287 'cost' => $price,
1288 'calc_tax' => 'per_order',
1289 );
1290 $this->add_rate( $rate );
1291 }
1292
1293 function calculate_weight($package) {
1294 $weight = 0;
1295 foreach ($package['contents'] as $line) {
1296 $weight += $line['data']->get_weight();
1297 }
1298 return $weight;
1299 }
1300 function fits_parcel_machine($package) {
1301 foreach ($package['contents'] as $line) {
1302 if (get_post_meta($line['product_id'], '_no_parcel_machine', true) === 'yes') {
1303 return false;
1304 }
1305 }
1306 return true;
1307 }
1308
1309
1310 function is_available($package) {
1311 if (!$this->fits_parcel_machine($package)) {
1312 return false;
1313 }
1314 $package_weight = $this->calculate_weight($package);
1315 if ($package_weight >= $this->maximum_weight) {
1316 return false;
1317 }
1318 $is_available = $this->enable === 'yes';
1319 if (!$is_available) {
1320 return false;
1321 }
1322 if (is_array($this->countries) && !in_array($package['destination']['country'], $this->countries)) {
1323 $is_available = false;
1324 }
1325 $this->order_country = $package['destination']['country'];
1326 return apply_filters('woocommerce_shipping_' . $this->id . '_is_available', $is_available, $package);
1327 }
1328
1329 function mk_get_machines() {
1330 $machines = mk_get_machines($this->ext, $this->order_country);
1331 if ($this->prioritization === 'yes') {
1332 usort($machines, function($a, $b) {
1333 $sortorder = array(
1334 'tallinn', 'tartu', 'narva', 'pärnu', 'viljandi', 'kohtla-järve', 'rakvere', 'maardu', 'sillamäe', 'kuressaare',
1335 'helsinki', 'espoo', 'tampere', 'vantaa', 'oulu', 'turku', 'jüväskülä', 'lahti', 'kuopio', 'kouvola',
1336 'riga', 'daugavpils', 'liepaja', 'jelgava', 'jurmala', 'ventspils', 'rezekne', 'valmiera', 'jekabpils',
1337 'vilnius', 'kaunas', 'klaipeda', 'siauliai', 'panevezys', 'alytus', 'mariampole', 'mazeikiai', 'jonava', 'utena'
1338 );
1339 $acity = mb_strtolower($a['city']);
1340 $bcity = mb_strtolower($b['city']);
1341 if (!$acity) { $acity = 'xxxxxxx'; }
1342 if (!$bcity) { $bcity = 'xxxxxxx'; }
1343 $aidx = array_search($acity, $sortorder);
1344 $bidx = array_search($bcity, $sortorder);
1345 if ($aidx !== false) {
1346 $acity = str_pad($aidx, 4, "0", STR_PAD_LEFT) . '-' . $acity;
1347 }
1348 if ($bidx !== false) {
1349 $bcity = str_pad($bidx, 4, "0", STR_PAD_LEFT) . '-' . $bcity;
1350 }
1351 $acity .= '-' . mb_strtolower($a['name']);
1352 $bcity .= '-' . mb_strtolower($b['name']);
1353 return $acity < $bcity ? -1 : 1;
1354 });
1355 }
1356 return $machines;
1357 }
1358
1359 function add_parcelmachine_checkout_fields($checkout) {
1360 $this->order_country = WC()->customer->get_shipping_country();
1361 echo '<tr style="display: none;" class="parcel_machine_checkout" id="parcel_machine_checkout_parcelmachine_'.mb_strtolower($this->ext).'"><th>' . $this->title . '</th>';
1362 echo '<td>';
1363 $options = array();
1364 $machines = $this->mk_get_machines();
1365 echo '<p class="form-row" id="'.esc_attr($this->id).'_field">';
1366 echo '<select class="select" name="'.esc_attr($this->id).'" id="'.esc_attr($this->id).'">';
1367 $pcity = false;
1368 foreach ($machines as $machine) {
1369 $city = strtolower($machine['city']);
1370 if ($city !== $pcity) {
1371 if ($pcity) echo '</optgroup>';
1372 echo '<optgroup label="'.$machine['city'].'">';
1373 }
1374 $mname = $machine['name'];
1375 if ($this->short_office_names !== 'yes') $mname .= ' - ' . $machine['city'] . ', ' . $machine['address'];
1376 echo '<option value="'.esc_attr($machine['provider'].'||'.$machine['id']).'">'.$mname.'</option>';
1377 $pcity = $city;
1378 }
1379 if ($pcity) echo '</optgroup>';
1380 echo '</select>';
1381 echo '</p>';
1382 echo '</td></tr>';
1383 }
1384
1385 function check_parcelmachine_checkout_fields() {
1386 $shipping_method = !empty($_POST['shipping_method']) ? $_POST['shipping_method'] : false;
1387 if (!empty($shipping_method[0])) { $shipping_method = $shipping_method[0]; }
1388 if ($shipping_method === $this->id && empty($_POST[$shipping_method])) {
1389 wc_add_notice(__('<strong>Parcel machine</strong> is a required field.'), 'error');
1390 }
1391 }
1392 function add_parcelmachine_order_meta($order_id) {
1393 $shipping_method = !empty($_POST['shipping_method']) ? $_POST['shipping_method'] : false;
1394 if (!empty($shipping_method[0])) { $shipping_method = $shipping_method[0]; }
1395 if ($shipping_method === $this->id && !empty($_POST[$this->id])) {
1396 update_post_meta($order_id, '_parcel_machine', sanitize_text_field($_POST[$this->id]));
1397 }
1398 }
1399 function add_admin_parcelmachine_via_field($order) {
1400 error_log('Via');
1401 error_log(print_r($order, 1));
1402 }
1403 }
1404 class WC_ParcelMachine_Shipping_Method_Omniva extends WC_ParcelMachine_Shipping_Method {
1405 function __construct($instance_id = 0) {
1406 $this->ext = 'Omniva';
1407 $this->name_ext = 'Omniva';
1408 parent::__construct();
1409 }
1410 function init_form_fields() {
1411
1412 $this->form_fields = array();
1413 $this->form_fields['logo'] = array('type' => 'title', 'title' => __get_logo_html());
1414 $this->form_fields['generic'] = array('type' => 'title', 'title' => __('Generic and pricing options', 'wc_makecommerce_domain'));
1415 $this->form_fields['active'] = array(
1416 'title' => __('Enable', 'wc_makecommerce_domain'),
1417 'type' => 'checkbox',
1418 'label' => __('enabled', 'wc_makecommerce_domain'),
1419 'default' => 'no',
1420 'description' => __('You can always exclude a product from being available for the Parcel Machine delivery by clicking "Does not fit parcel machine" in the product\'s shipping options', 'wc_makecommerce_domain'),
1421 );
1422 $this->form_fields['price_ee'] = array(
1423 'title' => __('Price EE', 'wc_makecommerce_domain'),
1424 'type' => 'text',
1425 'default' => '2.99'
1426 );
1427 $this->form_fields['price_lv'] = array(
1428 'title' => __('Price LV', 'wc_makecommerce_domain'),
1429 'type' => 'text',
1430 'default' => '7.99'
1431 );
1432 $this->form_fields['price_lt'] = array(
1433 'title' => __('Price LT', 'wc_makecommerce_domain'),
1434 'type' => 'text',
1435 'default' => '8.99'
1436 );
1437 $this->form_fields['free_shipping_min_amount'] = array(
1438 'title' => __('Minimum amount for free shipping', 'wc_makecommerce_domain'),
1439 'type' => 'number',
1440 'default' => '0',
1441 'description' => '(0 means no free shipping)'
1442 );
1443 $this->form_fields['maximum_weight'] = array(
1444 'title' => __('Maximum weight allowed for shipping', 'wc_makecommerce_domain'),
1445 'type' => 'text',
1446 'default' => '15'
1447 );
1448 $this->form_fields['countries'] = array(
1449 'title' => __('Specific Countries', 'wc_makecommerce_domain'),
1450 'type' => 'multiselect',
1451 'class' => 'wp-enhanced-select',
1452 'css' => 'width: 450px;',
1453 'default' => array('EE','LV','LT'),
1454 'options' => array('EE' => __('Estonia'), 'LV' => __('Latvia'), 'LT' => __('Lithuania')),
1455 );
1456 $this->form_fields['look_and_feel'] = array( 'type' => 'title', 'title' => __('Look and feel options', 'wc_makecommerce_domain'), 'description' => __('Options for presentation on check-out page', 'wc_makecommerce_domain'));
1457 $languages = apply_filters('wpml_active_languages', NULL, 'skip_missing=0');
1458 if (empty($languages)) {
1459 $this->form_fields['method_name'] = array(
1460 'title' => __('Shipping Method Title', 'wc_makecommerce_domain'),
1461 'type' => 'text',
1462 'default' => __('Omniva Parcel Machine', 'wc_makecommerce_domain')
1463 );
1464 } else {
1465 foreach ($languages as $language_code => $language) {
1466 $language_name = !empty($language['translated_name']) ? $language['translated_name'] : $language_code;
1467 $this->form_fields['method_name_'.$language_code] = array(
1468 'title' => __('Shipping Method Title', 'wc_makecommerce_domain').sprintf(' (%s)', $language_code),
1469 'type' => 'text',
1470 'default' => __('Omniva Parcel Machine', 'wc_makecommerce_domain')
1471 );
1472 }
1473 }
1474 $this->form_fields['prioritization'] = array(
1475 'title' => __('Prioritize', 'wc_makecommerce_domain'),
1476 'type' => 'checkbox',
1477 'label' => __('Bigger cities will be on top of list, others sorted alphabetically', 'wc_makecommerce_domain'),
1478 'default' => 'yes'
1479 );
1480 $this->form_fields['short_office_names'] = array(
1481 'title' => __('Short names', 'wc_makecommerce_domain'),
1482 'type' => 'checkbox',
1483 'label' => __('Display only parcel machine names, without addresses', 'wc_makecommerce_domain'),
1484 'default' => 'no'
1485 );
1486 $this->form_fields['api_access'] = array( 'type' => 'title', 'title' => '<br>'.__('API access for', 'wc_makecommerce_domain').' '.$this->ext, 'description' => sprintf(__('You can automatically create shipments into Omniva system and print the out the package labels right here, at the shop orders view. <br> Please set your Omniva web servises account credentials below here. <br>(see more on <a href="https://makecommerce.net/en/integration-modules/makecommerce-woocommerce-payment-plugin/#carriers-integration">MakeCommerce plugin page</a>. Don\'t forget to enable also <a href="%s">MC API keys</a>!)', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=api&section=mk_api')));
1487 $this->form_fields['service_user'] = array(
1488 'title' => __('Omniva web services username', 'wc_makecommerce_domain'),
1489 'type' => 'text',
1490 'default' => ''
1491 );
1492 $this->form_fields['service_password'] = array(
1493 'title' => __('Omniva web services password', 'wc_makecommerce_domain'),
1494 'type' => 'text',
1495 'default' => ''
1496 );
1497 $this->form_fields['return_address'] = array( 'type' => 'title', 'title' => __('Return address', 'wc_makecommerce_domain'), 'description' => __('Please define return address for Omniva shipments', 'wc_makecommerce_domain'));
1498 $this->form_fields['shop_name'] = array(
1499 'type' => 'text',
1500 'title' => __('Shop name', 'wc_makecommerce_domain'),
1501 'class' => 'input-text regular-input',
1502 );
1503 $this->form_fields['shop_phone'] = array(
1504 'type' => 'text',
1505 'title' => __('Shop phone', 'wc_makecommerce_domain'),
1506 'class' => 'input-text regular-input',
1507 );
1508 $this->form_fields['shop_email'] = array(
1509 'type' => 'text',
1510 'title' => __('Shop email', 'wc_makecommerce_domain'),
1511 'class' => 'input-text regular-input',
1512 );
1513 $this->form_fields['shop_postal_code'] = array(
1514 'type' => 'text',
1515 'title' => __('Shop postal code', 'wc_makecommerce_domain'),
1516 'class' => 'input-text regular-input',
1517 'description' => __('Put here zip-code of the Parcel Terminal you use for returns, see: <a href="https://www.omniva.ee/era/kaart/asukohad">List of Omniva Terminals</a>', 'wc_makecommerce_domain')
1518 );
1519 }
1520
1521 }
1522 class WC_ParcelMachine_Shipping_Method_Smartpost extends WC_ParcelMachine_Shipping_Method {
1523 function __construct() {
1524 $this->ext = 'SmartPost';
1525 $this->name_ext = 'SmartPOST';
1526 parent::__construct();
1527 }
1528 function init_form_fields() {
1529 global $woocommerce;
1530
1531 $this->form_fields = array();
1532 $this->form_fields['logo'] = array('type' => 'title', 'title' => __get_logo_html());
1533 $this->form_fields['generic'] = array( 'type' => 'title', 'title' => __('Generic and pricing options', 'wc_makecommerce_domain'));
1534 $this->form_fields['active'] = array(
1535 'title' => __('Enable', 'wc_makecommerce_domain'),
1536 'type' => 'checkbox',
1537 'label' => __('enabled', 'wc_makecommerce_domain'),
1538 'default' => 'no',
1539 'description' => __('You can always exclude a product from being available for the Parcel Machine delivery by clicking "Does not fit parcel machine" in the product\'s shipping options', 'wc_makecommerce_domain'),
1540 );
1541 $this->form_fields['price_ee'] = array(
1542 'title' => __('Price EE', 'wc_makecommerce_domain'),
1543 'type' => 'text',
1544 'default' => '2.99'
1545 );
1546 $this->form_fields['price_fi'] = array(
1547 'title' => __('Price FI', 'wc_makecommerce_domain'),
1548 'type' => 'text',
1549 'default' => '10.99'
1550 );
1551 $this->form_fields['free_shipping_min_amount'] = array(
1552 'title' => __('Minimum amount for free shipping', 'wc_makecommerce_domain'),
1553 'type' => 'number',
1554 'default' => '0',
1555 'description' => __('(0 means no free shipping)', 'wc_makecommerce_domain'),
1556 );
1557 $this->form_fields['maximum_weight'] = array(
1558 'title' => __('Maximum weight allowed for shipping', 'wc_makecommerce_domain'),
1559 'type' => 'text',
1560 'default' => '15'
1561 );
1562 $this->form_fields['countries'] = array(
1563 'title' => __('Specific Countries', 'wc_makecommerce_domain'),
1564 'type' => 'multiselect',
1565 'class' => 'wp-enhanced-select',
1566 'css' => 'width: 450px;',
1567 'default' => array('EE','FI'),
1568 'options' => array('EE' => __('Estonia'), 'FI' => __('Finland')),
1569 );
1570 $this->form_fields['look_and_feel'] = array( 'type' => 'title', 'title' => __('Look and feel options', 'wc_makecommerce_domain'), 'description' => __('Options for presentation on checkout page', 'wc_makecommerce_domain'));
1571 $languages = apply_filters('wpml_active_languages', NULL, 'skip_missing=0');
1572 if (empty($languages)) {
1573 $this->form_fields['method_name'] = array(
1574 'title' => __('Shipping Method Title', 'wc_makecommerce_domain'),
1575 'type' => 'text',
1576 'default' => __('SmartPOST Parcel Machine', 'wc_makecommerce_domain')
1577 );
1578 } else {
1579 foreach ($languages as $language_code => $language) {
1580 $language_name = !empty($language['translated_name']) ? $language['translated_name'] : $language_code;
1581 $this->form_fields['method_name_'.$language_code] = array(
1582 'title' => __('Shipping Method Title', 'wc_makecommerce_domain').sprintf(' (%s)', $language_code),
1583 'type' => 'text',
1584 'default' => __('SmartPOST Parcel Machine', 'wc_makecommerce_domain')
1585 );
1586 }
1587 }
1588 $this->form_fields['prioritization'] = array(
1589 'title' => __('Prioritize', 'wc_makecommerce_domain'),
1590 'type' => 'checkbox',
1591 'label' => __('Bigger cities will be on top of list, others sorted alphabetically', 'wc_makecommerce_domain'),
1592 'default' => 'yes'
1593 );
1594 $this->form_fields['short_office_names'] = array(
1595 'title' => __('Short names', 'wc_makecommerce_domain'),
1596 'type' => 'checkbox',
1597 'label' => __('Display only parcel machine names, without addresses', 'wc_makecommerce_domain'),
1598 'default' => 'no'
1599 );
1600 $this->form_fields['api_access'] = array( 'type' => 'title', 'title' => '<br>'.__('API access for', 'wc_makecommerce_domain').' '.$this->ext, 'description' => sprintf(__('You can automatically create shipments into smartpost.ee system and print the out the package labels right here, at the shop orders view. <br> Please set your smartpost.ee account credentials below here. <br>(See more on <a href="https://makecommerce.net/en/integration-modules/makecommerce-woocommerce-payment-plugin/#carriers-integration">MakeCommerce plugin page</a>. Don\'t forget to enable also <a href="%s">MC API keys</a>!)', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=api&section=mk_api')));
1601 $this->form_fields['service_user'] = array(
1602 'title' => __('eteenindus.smartpost.ee username', 'wc_makecommerce_domain'),
1603 'type' => 'text',
1604 'default' => ''
1605 );
1606 $this->form_fields['service_password'] = array(
1607 'title' => __('eteenindus.smartpost.ee password', 'wc_makecommerce_domain'),
1608 'type' => 'text',
1609 'default' => ''
1610 );
1611 $this->form_fields['return_address'] = array( 'type' => 'title', 'title' => __('Return address', 'wc_makecommerce_domain'), 'description' => __('Please define return address for SmartPOST shipments (used on parcel labels)', 'wc_makecommerce_domain'));
1612 $this->form_fields['shop_name'] = array(
1613 'type' => 'text',
1614 'title' => __('Shop name', 'wc_makecommerce_domain'),
1615 'class' => 'input-text regular-input',
1616 );
1617 $this->form_fields['shop_phone'] = array(
1618 'type' => 'text',
1619 'title' => __('Shop phone', 'wc_makecommerce_domain'),
1620 'class' => 'input-text regular-input',
1621 );
1622 $this->form_fields['shop_email'] = array(
1623 'type' => 'text',
1624 'title' => __('Shop email', 'wc_makecommerce_domain'),
1625 'class' => 'input-text regular-input',
1626 );
1627 }
1628
1629 }
1630 }
1631 }
1632 add_action('woocommerce_shipping_init', 'parcelmachine_add_method');
1633
1634 function add_parcelmachine_shipping_method($methods) {
1635 $methods[] = 'WC_ParcelMachine_Shipping_Method_Omniva';
1636 $methods[] = 'WC_ParcelMachine_Shipping_Method_Smartpost';
1637 return $methods;
1638 }
1639 add_filter('woocommerce_shipping_methods', 'add_parcelmachine_shipping_method');
1640
1641 function mk_parcelmachine_add_assets() {
1642 wp_enqueue_style('parcelmachine-css', plugin_dir_url(__FILE__).'/css/parcelmachine.css');
1643 wp_enqueue_script('parcelmachine-js', plugin_dir_url(__FILE__).'/scripts/parcelmachine.js', array('jquery'));
1644 }
1645 add_action('wp_enqueue_scripts', 'mk_parcelmachine_add_assets');
1646
1647 function mk_admin_plugin_settings_link($links) {
1648 $settings_link = '<a href="admin.php?page=wc-settings&tab=api&section=mk_api">API '.__('Settings').'</a>';
1649 array_unshift($links, $settings_link);
1650 return $links;
1651 }
1652 $plugin = plugin_basename(__FILE__);
1653 add_filter("plugin_action_links_$plugin", 'mk_admin_plugin_settings_link' );
1654
1655 function mk_admin_add_settings($sections) {
1656 $sections['mk_api'] = __('MakeCommerce API access', 'wc_makecommerce_domain');
1657 return $sections;
1658 }
1659
1660 function mk_admin_all_settings($settings) {
1661 global $current_section;
1662 if ($current_section !== 'mk_api') {
1663 return $settings;
1664 }
1665 return array(
1666 array('type' => 'title', 'desc' => __get_logo_html()),
1667 array(
1668 'type' => 'title',
1669 'title' => __('MakeCommerce API access credentials', 'wc_makecommerce_domain'),
1670 'desc' => sprintf(__('To use MakeCommerce/Maksekeskus services you need to enter API credentials below here <br/> <br/>'.
1671 'To further configure the Payment methods please go to <a href="%s">MakeCommerce Checkout Options</a><br>'.
1672 'To use also Ominva or Itella SmartPOST integration please configure these API accesses: <a href="%s">Omniva API access</a> | '.
1673 '<a href="%s">SmartPOST API access</a><br/>','wc_makecommerce_domain'),
1674 'admin.php?page=wc-settings&tab=checkout&section=makecommerce',
1675 'admin.php?page=wc-settings&tab=-shipping&section=parcelmachine_omniva',
1676 'admin.php?page=wc-settings&tab=shipping&section=parcelmachine_smartpost'
1677 ),
1678 'id' => 'mk_api_settings'
1679 ),
1680 array(
1681 'type' => 'select',
1682 'title' => __('Current environment', 'wc_makecommerce_domain'),
1683 'desc' => __('See more about <a href="https://maksekeskus.ee/en/for-developers/test-environment/">MakeCommerce Test environment</a>', 'wc_makecommerce_domain'),
1684 'default' => 'live',
1685 'options' => array(
1686 'live' => __('Live', 'wc_makecommerce_domain'),
1687 'test' => __('Test', 'wc_makecommerce_domain'),
1688 ),
1689 'id' => 'mk_api_type'
1690 ),
1691 array(
1692 'id' => 'mk_shop_id',
1693 'type' => 'text',
1694 'title' => __('Shop ID (live)', 'wc_makecommerce_domain'),
1695 'desc' => __('Get it from <a href="https://merchant.maksekeskus.ee/api.html" target="_blank">Merchant Portal</a>','wc_makecommerce_domain'),
1696 'class' => 'input-text regular-input',
1697 ),
1698 array(
1699 'id' => 'mk_private_key',
1700 'type' => 'text',
1701 'title' => __('Secret key (live)', 'wc_makecommerce_domain'),
1702 'class' => 'input-text regular-input',
1703 ),
1704 array(
1705 'id' => 'mk_public_key',
1706 'type' => 'text',
1707 'title' => __('Publishable key (live)', 'wc_makecommerce_domain'),
1708 'class' => 'input-text regular-input',
1709 ),
1710 array(
1711 'id' => 'mk_test_shop_id',
1712 'type' => 'text',
1713 'title' => __('Shop ID (test)', 'wc_makecommerce_domain'),
1714 'class' => 'input-text regular-input',
1715 'desc' => __('Get it from <a href="https://merchant-test.maksekeskus.ee/api.html" target="_blank">Merchant Portal Test</a>','wc_makecommerce_domain'),
1716 ),
1717 array(
1718 'id' => 'mk_test_private_key',
1719 'type' => 'text',
1720 'title' => __('Secret key (test)', 'wc_makecommerce_domain'),
1721 'class' => 'input-text regular-input',
1722 ),
1723 array(
1724 'id' => 'mk_test_public_key',
1725 'type' => 'text',
1726 'title' => __('Publishable key (test)', 'wc_makecommerce_domain'),
1727 'class' => 'input-text regular-input',
1728 ),
1729 array('type' => 'sectionend', 'id' => 'mk_api_settings')
1730 );
1731 }
1732
1733 function mk_admin_save_settings() {
1734 // reload banklinks
1735 global $current_section;
1736 if ($current_section !== 'mk_api') {
1737 return;
1738 }
1739 $wcmc = New woocommerce_makecommerce(true);
1740 $wcmc->mc_banklinks_reload(true);
1741 }
1742
1743 function __get_logo_html() {
1744 return '<div class="makecommerce-info">'.
1745 '<div class="makecommerce-logo">'.
1746 '<a target="_blank" href="http://maksekeskus.ee"><img src="'. plugins_url('/images/makecommerce_logo_en.svg', __FILE__) .'" class="makecommerce-logo"></a>'.
1747 '</div>'.
1748 '<div class="makecommerce-links">'.
1749 '<div class="makecommerce-link"><a target="_blank" href="https://merchant.maksekeskus.ee">Merchant Portal</a></div>'.
1750 '<div class="makecommerce-link"><a target="_blank" href="https://makecommerce.net/">makecommerce.net</a></div>'.
1751 '<div class="makecommerce-link"><a target="_blank" href="http://maksekeskus.ee">maksekeskus.ee</a></div>'.
1752 '</div>'.
1753 '</div>';
1754 }
1755
1756 add_action('woocommerce_get_sections_api', 'mk_admin_add_settings');
1757 add_filter('woocommerce_get_settings_api', 'mk_admin_all_settings', 10, 2);
1758 add_action('woocommerce_settings_saved', 'mk_admin_save_settings', 30, 0);
1759
1760 function mk_admin_restrict_manage_posts() {
1761 global $typenow;
1762 if ( in_array( $typenow, wc_get_order_types( 'order-meta-boxes' ) ) ) {
1763 $selected_method = !empty($_REQUEST['_shipping_method']) ? $_REQUEST['_shipping_method'] : false;
1764 $methods = WC()->shipping->load_shipping_methods();
1765 echo '<select name="_shipping_method" id="shipping_type" class="enhanced">';
1766 echo '<option value="">'.__('-- filter by shipping method', 'wc_makecommerce_domain') . '</option>';
1767 foreach ($methods as $method) {
1768 echo '<option value="'.$method->id.'"'.($selected_method === $method->id ? ' selected="selected"' : '').'>'.$method->title.'</option>';
1769 }
1770 echo '</select>';
1771 }
1772 }
1773 function mk_admin_shipping_filter($where, &$wp_query) {
1774 global $pagenow, $wpdb;
1775 $method = !empty($_REQUEST['_shipping_method']) ? $_REQUEST['_shipping_method'] : false;
1776 if (is_admin() && $pagenow=='edit.php' && $wp_query->query_vars['post_type'] == 'shop_order' && !empty($method) ) {
1777 $where .= $GLOBALS['wpdb']->prepare( ' AND ID
1778 IN (
1779 SELECT items.order_id
1780 FROM '.$wpdb->prefix.'woocommerce_order_itemmeta meta, '.$wpdb->prefix.'woocommerce_order_items items
1781 WHERE meta.order_item_id = items.order_item_id
1782 AND meta.meta_key = "method_id"
1783 AND meta.meta_value = %s
1784 ) ', $method );
1785 }
1786 return $where;
1787 }
1788 add_filter('restrict_manage_posts', 'mk_admin_restrict_manage_posts');
1789 add_filter('posts_where', 'mk_admin_shipping_filter', 10, 2);
1790
1791 function mk_admin_bulk_actions() {
1792 global $post_type;
1793 if ('shop_order' === $post_type) {
1794 ?>
1795 <script type="text/javascript">
1796 jQuery(function() {
1797 jQuery('<option>').val('parcel_machine_labels').text('<?php _e( 'Register parcel machine shipments', 'wc_makecommerce_domain' )?>').appendTo('select[name="action"]');
1798 jQuery('<option>').val('parcel_machine_labels').text('<?php _e( 'Register parcel machine shipments', 'wc_makecommerce_domain' )?>').appendTo('select[name="action2"]');
1799 jQuery('<option>').val('parcel_machine_print_labels').text('<?php _e( 'Print parcel machine labels', 'wc_makecommerce_domain' )?>').appendTo('select[name="action"]');
1800 jQuery('<option>').val('parcel_machine_print_labels').text('<?php _e( 'Print parcel machine labels', 'wc_makecommerce_domain' )?>').appendTo('select[name="action2"]');
1801 });
1802 </script>
1803 <?php
1804 if (!empty($_REQUEST['mk_pdf'])) {
1805 ?>
1806 <script type="text/javascript">
1807 jQuery(function(){
1808 window.open('<?php echo $_REQUEST['mk_pdf'] ?>', 'pdf');
1809 });
1810 </script>
1811 <?php
1812 }
1813 }
1814 }
1815 function mk_admin_bulk_action_labels() {
1816 $wp_list_table = _get_list_table('WP_Posts_List_Table');
1817 $shipping_request = array('credentials' => array(), 'orders' => array());
1818 $post_ids = array_map('absint', (array)$_REQUEST['post']);
1819 mk_get_shipment_ids($post_ids);
1820 }
1821 function mk_admin_bulk_action_print() {
1822 $wp_list_table = _get_list_table('WP_Posts_List_Table');
1823 $shipping_request = array('credentials' => array(), 'orders' => array());
1824 $post_ids = array_map('absint', (array)$_REQUEST['post']);
1825 mk_get_labels($post_ids);
1826 }
1827 add_action('admin_footer', 'mk_admin_bulk_actions', 11);
1828 add_action('admin_action_parcel_machine_labels', 'mk_admin_bulk_action_labels');
1829 add_action('admin_action_parcel_machine_print_labels', 'mk_admin_bulk_action_print');
1830
1831
1832
1833 function mk_admin_parcelmachine_order_meta($order) {
1834 $machine_id = get_post_meta($order->id, '_parcel_machine', true);
1835 if (empty($machine_id)) return;
1836 list($provider, $machine) = explode('||', $machine_id);
1837 if (empty($machine)) return;
1838 $machine = mk_get_machine($provider, (int)$machine);
1839 if (!$machine) return;
1840 echo '<p><strong>'.__('Parcel machine').':</strong><br/>' . $machine['name'] . '<br/><small>' . $machine['address'] . '</small></p>';
1841 $shipment_id = get_post_meta($order->id, '_parcel_machine_shipment_id', true);
1842 $shipment_id_error = get_post_meta($order->id, '_parcel_machine_error', true);
1843 if ($shipment_id) {
1844 echo '<p><strong>'.__('Parcel machine shipment ID').':</strong><br/>' . $shipment_id . '</small></p>';
1845 }
1846 if ($shipment_id_error) {
1847 echo '<p><strong style="color: red;">'.__('Parcel machine shipment generation error').':</strong><br/>' . $shipment_id_error . '</small></p>';
1848 }
1849 }
1850
1851 function mk_admin_render_shop_order_columns( $column ) {
1852 global $post, $woocommerce, $the_order;
1853 if (empty($the_order) || $the_order->id != $post->ID) {
1854 $the_order = wc_get_order($post->ID);
1855 }
1856 if ($column === 'shipping_address') {
1857 $machine = get_post_meta($the_order->id, '_parcel_machine', true);
1858 $shipment_id = get_post_meta($the_order->id, '_parcel_machine_shipment_id', true);
1859 $shipment_id_error = get_post_meta($the_order->id, '_parcel_machine_error', true);
1860 if ($machine) {
1861 if ($shipment_id) echo __('Package shipment_id:', 'wc_makecommerce_domain') . ' ' . $shipment_id;
1862 else if ($shipment_id_error) echo '<span style="color: red;">'.__('Package shipment generation error:', 'wc_makecommerce_domain') . '</span><br/>' .$shipment_id_error;
1863 else echo __('Shipment ID not generated for delivery', 'wc_makecommerce_domain');
1864 }
1865 }
1866 }
1867 function mk_add_email_customer_details_fields($fields, $sent_to_admin, $order) {
1868 $machine_id = get_post_meta($order->id, '_parcel_machine', true);
1869 if (empty($machine_id)) return $fields;
1870 list($provider, $machine) = explode('||', $machine_id);
1871 if (empty($machine)) return $fields;
1872 $machine = mk_get_machine($provider, (int)$machine);
1873 if (!$machine) return $fields;
1874 $fields[] = array('label' => __('Parcel machine'), 'value' => $machine['name'].' - '.$machine['address']);
1875 return $fields;
1876 }
1877 function mk_add_order_customer_details_fields($order) {
1878 $machine_id = get_post_meta($order->id, '_parcel_machine', true);
1879 if (empty($machine_id)) return;
1880 list($provider, $machine) = explode('||', $machine_id);
1881 if (empty($machine)) return;
1882 $machine = mk_get_machine($provider, (int)$machine);
1883 if (!$machine) return;
1884 echo '<tr>';
1885 echo '<th>'.__('Parcel machine').'</th>';
1886 echo '<td>'.$machine['name'].'<br/>'.$machine['address'].'</td>';
1887 echo '</tr>';
1888 }
1889 function mk_admin_product_option_fields($fields) {
1890 echo '<div class="options_group">';
1891 woocommerce_wp_checkbox(
1892 array(
1893 'id' => '_no_parcel_machine',
1894 'wrapper_class' => 'show_if_simple',
1895 'label' => __('Does not fit parcel machine', 'wc_makecommerce_domain'),
1896 'description' => __('When this is checked, parcel machine shipping option is not available for a cart with this product', 'wc_makecommerce_domain')
1897 )
1898 );
1899 echo '</div>';
1900 }
1901 function mk_admin_product_fields_save($post_id) {
1902 $no_parcel_machine = isset($_POST['_no_parcel_machine']) ? 'yes' : 'no';
1903 update_post_meta($post_id, '_no_parcel_machine', $no_parcel_machine);
1904 }
1905
1906 add_action('woocommerce_product_options_shipping', 'mk_admin_product_option_fields');
1907 add_action('woocommerce_process_product_meta', 'mk_admin_product_fields_save');
1908 add_action('woocommerce_admin_order_data_after_shipping_address', 'mk_admin_parcelmachine_order_meta', 10, 1);
1909 add_action('manage_shop_order_posts_custom_column', 'mk_admin_render_shop_order_columns', 3);
1910 add_filter('woocommerce_email_customer_details_fields', 'mk_add_email_customer_details_fields', 10, 3 );
1911 add_action('woocommerce_order_details_after_customer_details', 'mk_add_order_customer_details_fields');
1912 add_action('woocommerce_order_status_processing', 'mk_get_shipment_ids');
1913
1914
1915
1916 function mk_get_shipment_ids($post_ids) {
1917 if (!is_array($post_ids)) {
1918 $post_ids = array($post_ids);
1919 }
1920 parcelmachine_add_method();
1921 $shipping_request = array('credentials' => array(), 'orders' => array());
1922 foreach ($post_ids as $post_id) {
1923 $parcel_machine = get_post_meta($post_id, '_parcel_machine', true);
1924 if (!$parcel_machine) { continue; }
1925 list($provider, $machine_id) = explode('||', $parcel_machine);
1926 if (!$provider || !$machine_id) { continue; }
1927 $provider_uc = mb_strtoupper($provider);
1928 switch ($provider_uc) {
1929 case "OMNIVA":
1930 $transport_class = new WC_ParcelMachine_Shipping_Method_Omniva();
1931 break;
1932 case "SMARTPOST":
1933 $transport_class = new WC_ParcelMachine_Shipping_Method_Smartpost();
1934 break;
1935 default:
1936 break 2;
1937 }
1938 if (empty($shipping_request['credentials'][$provider_uc])) {
1939 $api_user = $transport_class->settings['service_user'];
1940 $api_password = $transport_class->settings['service_password'];
1941 if (!$api_user || !$api_password) {
1942 add_action('admin_notices', 'mk_admin_error');
1943 continue;
1944 }
1945 $shipping_request['credentials'][$provider_uc] = array('carrier' => $provider_uc, 'username' => $api_user, 'password' => $api_password);
1946 }
1947 $order = wc_get_order($post_id);
1948 $sender = array(
1949 'name' => $transport_class->settings['shop_name'],
1950 'phone' => $transport_class->settings['shop_phone'],
1951 'email' => $transport_class->settings['shop_email'],
1952 'postalCode' => $transport_class->settings['shop_postal_code']
1953 );
1954 $shipping_request['orders'][] = array(
1955 'carrier' => $provider_uc,
1956 'orderId' => $order->id,
1957 'destination' => array('destinationId' => $machine_id),
1958 'recipient' => array('name' => $order->shipping_first_name . ' ' . $order->shipping_last_name, 'phone' => $order->billing_phone, 'email' => $order->billing_email),
1959 'sender' => $sender
1960 );
1961 }
1962 $shipping_request['credentials'] = array_values($shipping_request['credentials']);
1963 if (empty($shipping_request['orders'])) {
1964 return;
1965 }
1966 $MK = mk_get_api();
1967 if (!$MK) {
1968 return;
1969 }
1970 try {
1971 $response = $MK->createShipments($shipping_request);
1972 } catch (Exception $e) {
1973 echo $e->getMessage();
1974 exit();
1975 }
1976 foreach ($response as $order) {
1977 if (!empty($order->orderId) && !empty($order->shipmentId)) {
1978 update_post_meta((int)$order->orderId, '_parcel_machine_shipment_id', sanitize_text_field($order->shipmentId));
1979 } else if (!empty($order->orderId) && !empty($order->barCode)) {
1980 update_post_meta((int)$order->orderId, '_parcel_machine_shipment_id', sanitize_text_field($order->barCode));
1981 } else if (!empty($order->orderId) && !empty($order->errorMessage)) {
1982 update_post_meta((int)$order->orderId, '_parcel_machine_error', sanitize_text_field($order->errorMessage));
1983 }
1984 }
1985 }
1986
1987 function mk_get_labels($post_ids) {
1988 if (!is_array($post_ids)) {
1989 $post_ids = array($post_ids);
1990 }
1991 $sender = array(
1992 'name' => get_option('mk_shop_name', ''),
1993 'phone' => get_option('mk_shop_phone', ''),
1994 'email' => get_option('mk_shop_email', ''),
1995 'postalCode' => get_option('mk_shop_postal_code', '')
1996 );
1997 parcelmachine_add_method();
1998 $shipping_request = array('credentials' => array(), 'orders' => array(), 'printFormat' => 'A4');
1999 foreach ($post_ids as $post_id) {
2000 $parcel_machine = get_post_meta($post_id, '_parcel_machine', true);
2001 if (!$parcel_machine) { continue; }
2002 list($provider, $machine_id) = explode('||', $parcel_machine);
2003 if (!$provider || !$machine_id) { continue; }
2004 $provider_uc = mb_strtoupper($provider);
2005 if (empty($shipping_request['credentials'][$provider_uc])) {
2006 switch ($provider_uc) {
2007 case "OMNIVA":
2008 $transport_class = new WC_ParcelMachine_Shipping_Method_Omniva();
2009 break;
2010 case "SMARTPOST":
2011 $transport_class = new WC_ParcelMachine_Shipping_Method_Smartpost();
2012 break;
2013 default:
2014 break 2;
2015 }
2016 $api_user = $transport_class->settings['service_user'];
2017 $api_password = $transport_class->settings['service_password'];
2018 if (!$api_user || !$api_password) {
2019 add_action('admin_notices', 'mk_admin_error');
2020 continue;
2021 }
2022 $shipping_request['credentials'][$provider_uc] = array('carrier' => $provider_uc, 'username' => $api_user, 'password' => $api_password);
2023 }
2024 $order = wc_get_order($post_id);
2025 $shipment_id = get_post_meta($post_id, '_parcel_machine_shipment_id', true);
2026 if (!$shipment_id) { continue; }
2027 $shipping_request['orders'][] = array(
2028 'carrier' => $provider_uc,
2029 'orderId' => $order->id,
2030 'destination' => array('destinationId' => $machine_id),
2031 'recipient' => array('name' => $order->shipping_first_name . ' ' . $order->shipping_last_name, 'phone' => $order->billing_phone, 'email' => $order->billing_email),
2032 'sender' => $sender,
2033 'shipmentId' => $shipment_id
2034 );
2035 }
2036 $shipping_request['credentials'] = array_values($shipping_request['credentials']);
2037 if (empty($shipping_request['orders'])) {
2038 return;
2039 }
2040 $MK = mk_get_api();
2041 if (!$MK) {
2042 return;
2043 }
2044 try {
2045 $response = $MK->createLabels($shipping_request);
2046 } catch (Exception $e) {
2047 echo $e->getMessage();
2048 exit();
2049 }
2050 if (empty($response->labelUrl)) {
2051 return;
2052 }
2053 $sendback = add_query_arg(array('post_type' => 'shop_order', 'mk_pdf' => urlencode($response->labelUrl)), '');
2054 wp_redirect(esc_url_raw($sendback));
2055 exit();
2056 }
2057
2058
2059
2060 $MKAPI = false;
2061 function mk_get_api() {
2062 global $MKAPI;
2063 if ($MKAPI) {
2064 //return $MKAPI;
2065 }
2066 $mk_api_type = get_option('mk_api_type', false);
2067 if (!$mk_api_type) {
2068 return false;
2069 }
2070 if ($mk_api_type !== 'live') {
2071 $key_prefix = $mk_api_type.'_';
2072 } else {
2073 $key_prefix = '';
2074 }
2075 $mk_shop_id = get_option('mk_'.$key_prefix.'shop_id', '');
2076 $mk_public_key = get_option('mk_'.$key_prefix.'public_key', '');
2077 $mk_private_key = get_option('mk_'.$key_prefix.'private_key', '');
2078 if (!$mk_shop_id || !$mk_public_key || !$mk_shop_id) {
2079 return false;
2080 }
2081 $MKAPI = new Maksekeskus($mk_shop_id, $mk_public_key, $mk_private_key, $mk_api_type === 'live' ? false : true);
2082 return $MKAPI;
2083 }
2084 function mk_get_machines($provider, $country = 'EE') {
2085 $data = get_option('mk_machines_cache', false);
2086 $data_expires = get_option('mk_machines_expires', false);
2087 if (!$data || $data_expires < time()) {
2088 $MK = mk_get_api();
2089 $data = $MK->getDestinations(array('type' => 'APT'));
2090 update_option('mk_machines_cache', $data);
2091 update_option('mk_machines_expires', time()+3*60*60);
2092 }
2093
2094 $machines = array();
2095 if (!$data || empty($data)) {
2096 return array();
2097 }
2098 foreach ($data as $machine) {
2099 if ($machine->country === $country && $machine->type === 'APT' && ($provider === '*' || strtolower($provider) === strtolower($machine->provider))) {
2100 $machines[] = array(
2101 'provider' => strtolower($machine->provider),
2102 'id' => $machine->id,
2103 'name' => $machine->name,
2104 'city' => $machine->city,
2105 'address' => !empty($machine->address) ? $machine->address : '',
2106 );
2107 }
2108 }
2109 usort($machines, function($a, $b){
2110 if ($a['city'] === $b['city']) {
2111 return $a['name'] > $b['name'];
2112 }
2113 return $a['city'] > $b['city'];
2114 });
2115 return $machines;
2116 }
2117
2118 function mk_get_machine($provider, $id) {
2119 $machines = mk_get_machines($provider);
2120 foreach ($machines as $machine) {
2121 if ($machine['provider'] === $provider && $machine['id'] === $id) {
2122 return $machine;
2123 }
2124 }
2125 return false;
2126 }
2127 function mk_admin_error() {
2128 printf( '<div class="%1$s"><p>%2$s</p></div>', 'notice notice-error', __('Please check that you have configured correctly MakeCommerce API accesses', 'wc_makecommerce_domain'));
2129 }
2130 }
2131