PluginProbe
MakeCommerce for WooCommerce / 2.6.0
MakeCommerce for WooCommerce v2.6.0
4.1.0 4.0.8 trunk 1.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 2.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2.0 2.2.1 2.2.2 All 96 releases
← All changes | makecommerce.php +170 -31 2.1.12.6.0 View file →
@@ -1,30 +1,41 @@
1 1 <?php
2 2 /*
3 3 Plugin Name: MakeCommerce for WooCommerce
4 4 Description: Adds MakeCommerce payment gateway and Itella/Omniva parcel machine shipping methods to Woocommerce checkout
5 - Version: 2.1.1
5 + Version: 2.6.0
6 6 Author: Maksekeskus AS
7 7 Author URI: https://MakeCommerce.net/
8 8 Text Domain: wc_makecommerce_domain
9 + WC requires at least: 3.0
10 + WC tested up to: 4.3.1
9 11 */
10 12
11 -if ( ! defined( 'ABSPATH' ) ) {
13 +if (!defined('ABSPATH')) {
12 14 exit; // Exit if accessed directly.
13 15 }
14 16
15 -if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
17 +include_once(ABSPATH.'wp-admin/includes/plugin.php');
18 +if (is_plugin_active('woocommerce/woocommerce.php')) {
16 19
17 -
18 20 define('WC_MC_VERSION', 2.0);
19 21
20 - $enable_experimental = get_option('mk_experimental_features', false);
21 - if ($enable_experimental && $enable_experimental !== 'no') {
22 + $enable_experimental = get_option('mk_checkout_sco', 'no');
23 + if ($enable_experimental === 'yes') {
22 24 require_once(__DIR__.'/makecommerce-simplecheckout.php');
23 25 }
24 26 require_once(__DIR__.'/makecommerce-transport.php');
25 27 require_once(__DIR__.'/makecommerce-payment.php');
26 28
29 + if (is_admin() && !extension_loaded('curl')) {
30 + add_action('admin_notices', function(){
31 + $class = 'notice notice-error';
32 + $message = __( 'You have enabled MakeCommerce module but it seems that you don\'t have CURL enabled. This way MakeCommerce unfortunately does not work!', 'wc_makecommerce_domain');
33 + printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) );
34 + });
35 + }
36 +
37 +
27 38 global $mkDbTable;
28 39 $mkDbTable = 'mc_banklinks';
29 40
30 41 function mc_install() {
@@ -40,8 +51,11 @@
40 51 type varchar(10) NOT NULL,
41 52 country char(2) NOT NULL,
42 53 name varchar(25) NOT NULL,
43 54 url varchar(250) NOT NULL,
55 + logo_url varchar(250),
56 + min_amount mediumint(9),
57 + max_amount mediumint(9),
44 58 UNIQUE KEY id (id)
45 59 ) $charset;";
46 60
47 61 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
@@ -64,13 +78,13 @@
64 78 // Assign schedule if not set, update compatible no need to reactivate, format('U') php 5.2 compatible
65 79 // Assigns task at 23.59.59 by local time, task runs if time has passed and somebody navigates the site
66 80 if (! wp_next_scheduled ( 'mc_banklinks_update_cron' )) {
67 81 $date = new DateTime();
68 - $date->setTime(04,10,00);
82 + $date->setTime(rand(0,23),rand(0,59),00);
69 83 $timestamp = intval($date->format('U'));
70 84 //$local = 3600 * intval(get_option('gmt_offset'));
71 85 //wp_schedule_event($timestamp - $local, 'twicedaily', 'mc_banklinks_update_cron');
72 - wp_schedule_event($timestamp, 'hourly', 'mc_banklinks_update_cron');
86 + wp_schedule_event($timestamp, 'twicedaily', 'mc_banklinks_update_cron');
73 87 }
74 88
75 89 if (!class_exists('wc_makecommerce_domain')) {
76 90 require_once('includes/vendor/autoload.php');
@@ -76,13 +90,26 @@
76 90 require_once('includes/vendor/autoload.php');
77 91 require_once('includes/Maksekeskus.php');
78 92 }
79 93
80 - function mk_check_payment() {
94 + function mk_check_payment() {
81 95
82 96 global $woocommerce;
83 97 $api = mk_get_api();
84 98
99 + //set the correct language
100 + if (isset($_GET["lang1"])) {
101 + //set wpml language
102 + if (function_exists('icl_object_id')) {
103 + do_action('wpml_switch_language', $_GET["lang1"]);
104 + } else {
105 + //set polylang language
106 + if (function_exists('pll_current_language')) {
107 + //not implemented yet
108 + }
109 + }
110 + }
111 +
85 112 $returnUrl = home_url();
86 113
87 114 $request = stripslashes_deep($_POST);
88 115 if ($api->verifyMac($request)) {
@@ -88,8 +115,13 @@
88 115 if ($api->verifyMac($request)) {
89 116 $data = $api->extractRequestData($request);
90 117 $reference = false;
91 118
119 + if (!empty($data['error']) ) {
120 + wc_add_notice(__('Payment failed', 'wc_makecommerce_domain'), 'error');
121 + return $returnUrl;
122 + }
123 +
92 124 if (!empty($data['message_type']) ) {
93 125 if ($data['message_type'] == 'payment_return') {
94 126 $transactionId = $data['transaction'];
95 127 $reference = $data['reference'];
@@ -103,9 +135,9 @@
103 135 $transactionId = $data['transaction']['id'];
104 136
105 137 // for API backward compatibility - if we didn't find reference in the mesage, or the transaction state vas still PENDING
106 138 // we'll fetch the transaction data from API, and make a payment request if needed
107 - // this all can be removed avter 2017-jan
139 + // this all can be removed after 2017-jan
108 140 if (!$reference or $paymentStatus == 'PENDING') {
109 141 $transaction = $api->getTransaction($transactionId);
110 142 if (!empty($transaction->reference)) {
111 143 $reference = $transaction->reference;
@@ -114,9 +146,9 @@
114 146 $paymentStatus = $transaction->status;
115 147
116 148 if ($paymentStatus == 'PENDING') {
117 149 $paymentRequest = array(
118 - 'amount' => $transaction->amount,
150 + 'amount' => (string)sprintf("%.2f", $transaction->amount),
119 151 'currency' => $transaction->currency,
120 152 'token' => $data['token']['id']
121 153 );
122 154 $payment = $api->createPayment($transactionId, $paymentRequest);
@@ -136,30 +168,36 @@
136 168 if (!$reference) { return $returnUrl; }
137 169
138 170 $order = new WC_Order($reference);
139 171 // if we din't find the Order, we send user to shop landing-page. TODO: could be improved
140 - if (!$order->id) { return $returnUrl; }
172 + if (!$order->get_id()) { return $returnUrl; }
141 173
174 + $returnUrl = $order->get_checkout_order_received_url();
175 +
142 176 switch($paymentStatus) {
143 177
144 178 case 'CANCELLED':
145 179 $order->update_status( 'cancelled' );
146 180 wc_add_notice(__('Payment transaction cancelled', 'wc_makecommerce_domain'), 'error');
181 + $returnUrl = wc_get_cart_url();
147 182 break;
148 183
149 184 case 'COMPLETED':
150 185 $orderNote = array();
151 186 $orderNote[] = __('Transaction ID', 'wc_makecommerce_domain') . ': <a target=_blank href="'.$api->getEnvUrls()->merchantUrl.'/merchant/shop/deals/detail.html?id='. $transactionId .'">'.$transactionId.'</a>';
152 - $orderNote[] = __('Payment option', 'wc_makecommerce_domain') . ': ' . get_post_meta($order->id, '_makecommerce_preselected_method', true);
187 + $orderNote[] = __('Payment option', 'wc_makecommerce_domain') . ': ' . get_post_meta($order->get_id(), '_makecommerce_preselected_method', true);
153 188 $order->add_order_note(implode("\r\n", $orderNote));
189 + if (!empty($data['token']) && !empty($data['token']['multiuse'])) {
190 + update_post_meta($order->get_id(), '_makecommerce_payment_token', $data['token']['id']);
191 + update_post_meta($order->get_id(), '_makecommerce_payment_token_valid_until', $data['token']['valid_until']);
192 + }
154 193
155 - $order->payment_complete();
156 - $order->update_status( 'processing' );
194 + if( isset($_GET['lang1']) ) $order->update_meta_data('wpml_language', $_GET["lang1"]);
195 + $order->payment_complete( $transactionId );
196 + $woocommerce->cart->empty_cart();
157 197 break;
158 -
159 198 }
160 199
161 - $returnUrl = $order->get_checkout_order_received_url();
162 200 return $returnUrl;
163 201 }
164 202
165 203
@@ -245,9 +283,9 @@
245 283 add_action('wp_login', 'mk_admin_login_update', 10, 2);
246 284
247 285
248 286
249 - function mk_admin_add_api_settings($sections) {
287 + function mk_admin_add_api_settings($sections) {
250 288 $sections['mk_api'] = __('MakeCommerce API access', 'wc_makecommerce_domain');
251 289 return $sections;
252 290 }
253 291
@@ -261,15 +299,9 @@
261 299 array(
262 300 'type' => 'title',
263 301 'title' => __('MakeCommerce API access credentials', 'wc_makecommerce_domain'),
264 302 'desc' => __('To use MakeCommerce/Maksekeskus services you need to enter API credentials below here <br/> <br/>', 'wc_makecommerce_domain').
265 - sprintf( __('To further configure the Payment methods please go to <a href="%s">MakeCommerce Checkout Options</a><br>', 'wc_makecommerce_domain'), 'admin.php?page=wc-settings&tab=checkout&section=makecommerce').
266 - sprintf( __('To use also Ominva or Itella SmartPOST integration please configure these API accesses: <a href="%s">Omniva Parcel Machine API access</a> | '.
267 - '<a href="%s">SmartPOST API access</a> | <a href="%s">Omniva Courier API access</a><br/>','wc_makecommerce_domain'),
268 - 'admin.php?page=wc-settings&tab=-shipping&section=parcelmachine_omniva',
269 - 'admin.php?page=wc-settings&tab=shipping&section=parcelmachine_smartpost',
270 - 'admin.php?page=wc-settings&tab=shipping&section=courier_omniva'
271 - ),
303 + sprintf( __('To further configure the Payment methods please go to <a href=."%s">MakeCommerce Checkout Options</a>, links to settings of our Shipment methods are listed below', 'wc_makecommerce_domain'), 'admin.php?page=wc-settings&tab=checkout&section=makecommerce'),
272 304 'id' => 'mk_api_settings'
273 305 ),
274 306 array(
275 307 'type' => 'select',
@@ -322,15 +354,75 @@
322 354 'title' => __('Publishable key (test)', 'wc_makecommerce_domain'),
323 355 'default' => '7Hog41ci2mKkmtviMycWxpNx14pNP70m',
324 356 'class' => 'input-text regular-input',
325 357 ),
358 + array('type' => 'sectionend', 'id' => 'mk_api_settings'),
359 + array(
360 + 'type' => 'title',
361 + 'desc' => '<br><hr><br>',
362 + ),
363 + array(
364 + 'id' => 'mk_module_title',
365 + 'type' => 'title',
366 + 'title' => __('Makecommerce modules', 'wc_makecommerce_domain'),
367 + 'desc' => __('Our plugin adds several modules to your shop. Here you can switch off modules that are not important for you, they will disappear from Woocommerce settings menus.<br> Each active module have their own settings dialog, where they must also be Enabled before use.', 'wc_makecommerce_domain'),
368 + 'class' => '',
369 + ),
326 370 array(
327 - 'id' => 'mk_experimental_features',
371 + 'id' => 'mk_transport_apt_omniva',
328 372 'type' => 'checkbox',
329 - 'title' => __('Enable experimental features', 'wc_makecommerce_domain'),
373 + 'default' => 'yes',
374 + 'title' => __('Omniva Parcel Machine', 'wc_makecommerce_domain'),
375 + 'desc' => __('enable Omniva parcel machines shipping method', 'wc_makecommerce_domain').' ('. sprintf(__('<a href="%s">module settings</a>', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=shipping&section=parcelmachine_omniva')).')',
330 376 'class' => '',
331 377 ),
332 378 array(
379 + 'id' => 'mk_transport_apt_smartpost',
380 + 'type' => 'checkbox',
381 + 'default' => 'yes',
382 + 'title' => __('SmartPOST Parcel Machine', 'wc_makecommerce_domain'),
383 + 'desc' => __('enable SmartPOST parcel machines shipping method', 'wc_makecommerce_domain').' ('. sprintf(__('<a href="%s">module settings</a>', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=shipping&section=parcelmachine_smartpost')).')',
384 + 'class' => '',
385 + ),
386 + array(
387 + 'id' => 'mk_transport_apt_dpd',
388 + 'type' => 'checkbox',
389 + 'default' => 'no',
390 + 'title' => __('DPD Pickup Network', 'wc_makecommerce_domain'),
391 + 'desc' => __('enable DPD Pickup network shipping method', 'wc_makecommerce_domain').' ('. sprintf(__('<a href="%s">module settings</a>', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=shipping&section=parcelmachine_dpd')).')',
392 + 'class' => '',
393 + ),
394 + array(
395 + 'id' => 'mk_transport_courier_omniva',
396 + 'type' => 'checkbox',
397 + 'default' => 'yes',
398 + 'title' => __('Omniva Courier', 'wc_makecommerce_domain'),
399 + 'desc' => __('enable Omniva courier shipping method', 'wc_makecommerce_domain').' ('. sprintf(__('<a href="%s">module settings</a>', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=shipping&section=courier_omniva')).')',
400 + 'class' => '',
401 + ),
402 + array(
403 + 'id' => 'mk_transport_courier_smartpost',
404 + 'type' => 'checkbox',
405 + 'default' => 'yes',
406 + 'title' => __('SmartPOST Courier', 'wc_makecommerce_domain'),
407 + 'desc' => __('enable SmartPOST courier shipping method', 'wc_makecommerce_domain').' ('. sprintf(__('<a href="%s">module settings</a>', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=shipping&section=courier_smartpost')).')',
408 + 'class' => '',
409 + ),
410 + array(
411 + 'id' => 'mk_checkout_sco',
412 + 'type' => 'checkbox',
413 + 'title' => __('SimpleCheckout', 'wc_makecommerce_domain'),
414 + 'desc' => __('enable SimpleCheckout&trade; Checkout method', 'wc_makecommerce_domain').' ('. sprintf(__('<a href="%s">module settings</a>', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=checkout&section=makecommerce_sc')).')',
415 + 'class' => '',
416 + ),
417 + array(
418 + 'id' => 'mk_product_slice',
419 + 'type' => 'checkbox',
420 + 'title' => __('Slice in 3 information in product view', 'wc_makecommerce_domain'),
421 + 'desc' => __('enable Slice in product view', 'wc_makecommerce_domain').' ('. sprintf(__('<a href="%s">module settings</a>', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=checkout&section=makecommerce_sc')).')',
422 + 'class' => '',
423 + ),
424 + array(
333 425 'id' => 'mk_javascript_ui',
334 426 'type' => 'api_javascript_ui',
335 427 ),
336 428 array('type' => 'sectionend', 'id' => 'mk_api_settings')
@@ -336,8 +428,17 @@
336 428 array('type' => 'sectionend', 'id' => 'mk_api_settings')
337 429 );
338 430 }
339 431
432 + function mk_wc_version($version) {
433 + global $woocommerce;
434 + if ( version_compare( $woocommerce->version, "3.4.0", ">=" ) ) {
435 + return true;
436 + } else {
437 + return false;
438 + }
439 + }
440 +
340 441 function mk_admin_save_api_settings() {
341 442 // reload banklinks
342 443 global $current_section;
343 444 if ($current_section !== 'mk_api') {
@@ -345,17 +446,55 @@
345 446 }
346 447 update_mc_banklinks();
347 448 }
348 449
349 - function mk_admin_plugin_settings_link($links) {
350 - $settings_link = '<a href="admin.php?page=wc-settings&tab=api&section=mk_api">API '.__('Settings').'</a>';
351 - array_unshift($links, $settings_link);
352 - return $links;
450 + function mk_admin_plugin_settings_link($links) {
451 + if (mk_wc_version("3.4.0"))
452 + $settings_link = '<a href="admin.php?page=wc-settings&tab=advanced&section=mk_api">API '.__('Settings').'</a>';
453 + else
454 + $settings_link = '<a href="admin.php?page=wc-settings&tab=api&section=mk_api">API '.__('Settings').'</a>';
455 + array_unshift($links, $settings_link);
456 + return $links;
353 457 }
458 +
459 + function wc_mc_shop_slice_button() {
460 + if (get_option('mk_product_slice', 'no') == 'yes') {
461 + global $product;
462 + // $price_excl_tax = wc_get_price_excluding_tax( $product ); // price without VAT
463 + $price_incl_tax = wc_get_price_including_tax( $product ); // price with VAT
464 + global $wpdb;
465 + global $mkDbTable;
466 + $tableName = $wpdb->prefix . $mkDbTable;
467 + $methods = $wpdb->get_results('SELECT * FROM '.$tableName);
468 + $slice = false;
469 + if(count($methods)) {
470 + foreach ($methods as $method) {
471 + if ($method->name =="slice") {
472 + if ( $price_incl_tax >= $method->min_amount ) {
473 + if ( $price_incl_tax <= $method->max_amount ) {
474 + $slice = true;
475 + }
476 + }
477 + }
478 + }
479 + }
480 + if ($slice == true) {
481 + echo '<div style="width:100%; margin-top: 20px; margin-bottom: auto;"><img src="'.plugins_url('/images/slice_logo_dark_176x62.svg', __FILE__).'" width="88" weight="31"/>&nbsp;&nbsp;Osta kohe, maksa hiljem. Kolmes võrdses osas 3 x '.sprintf("%.2f",$price_incl_tax/3).' €</div>'; // sprintf("%.2f",$price_incl_tax/3).' in month
482 + }
483 + }
484 + }
485 + // Slice Promo 1
486 + add_action( 'woocommerce_after_add_to_cart_button', 'wc_mc_shop_slice_button', 20 );
487 +
488 + // if (mk_wc_version("3.4.0")) {
489 + add_filter('woocommerce_get_settings_advanced', 'mk_admin_api_settings', 10, 2);
490 + add_action('woocommerce_get_sections_advanced', 'mk_admin_add_api_settings');
354 491 add_filter('woocommerce_get_settings_api', 'mk_admin_api_settings', 10, 2);
492 + // } else {
355 493 add_action('woocommerce_get_sections_api', 'mk_admin_add_api_settings');
356 494 add_action('woocommerce_settings_saved', 'mk_admin_save_api_settings', 30, 0);
357 495 add_filter("plugin_action_links_".plugin_basename(__FILE__), 'mk_admin_plugin_settings_link' );
496 + // }
358 497
359 498 function __get_logo_html() {
360 499 return '<div class="makecommerce-info">'.
361 500 '<div class="makecommerce-logo">'.