| @@ -1,30 +1,39 @@ | ||
| 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.3 | |
| 5 | + Version: 2.5.3 | |
| 6 | 6 | Author: Maksekeskus AS |
| 7 | 7 | Author URI: https://MakeCommerce.net/ |
| 8 | 8 | Text Domain: wc_makecommerce_domain |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 11 | +if (!defined('ABSPATH')) { | |
| 12 | 12 | exit; // Exit if accessed directly. |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | -if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { | |
| 15 | +include_once(ABSPATH.'wp-admin/includes/plugin.php'); | |
| 16 | +if (is_plugin_active('woocommerce/woocommerce.php')) { | |
| 16 | 17 | |
| 17 | - | |
| 18 | 18 | define('WC_MC_VERSION', 2.0); |
| 19 | 19 | |
| 20 | - $enable_experimental = get_option('mk_experimental_features', false); | |
| 21 | - if ($enable_experimental && $enable_experimental !== 'no') { | |
| 20 | + $enable_experimental = get_option('mk_checkout_sco', 'no'); | |
| 21 | + if ($enable_experimental === 'yes') { | |
| 22 | 22 | require_once(__DIR__.'/makecommerce-simplecheckout.php'); |
| 23 | 23 | } |
| 24 | 24 | require_once(__DIR__.'/makecommerce-transport.php'); |
| 25 | 25 | require_once(__DIR__.'/makecommerce-payment.php'); |
| 26 | 26 | |
| 27 | + if (is_admin() && !extension_loaded('curl')) { | |
| 28 | + add_action('admin_notices', function(){ | |
| 29 | + $class = 'notice notice-error'; | |
| 30 | + $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'); | |
| 31 | + printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) ); | |
| 32 | + }); | |
| 33 | + } | |
| 34 | + | |
| 35 | + | |
| 27 | 36 | global $mkDbTable; |
| 28 | 37 | $mkDbTable = 'mc_banklinks'; |
| 29 | 38 | |
| 30 | 39 | function mc_install() { |
| @@ -40,8 +49,9 @@ | ||
| 40 | 49 | type varchar(10) NOT NULL, |
| 41 | 50 | country char(2) NOT NULL, |
| 42 | 51 | name varchar(25) NOT NULL, |
| 43 | 52 | url varchar(250) NOT NULL, |
| 53 | + logo_url varchar(250), | |
| 44 | 54 | UNIQUE KEY id (id) |
| 45 | 55 | ) $charset;"; |
| 46 | 56 | |
| 47 | 57 | require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
| @@ -119,9 +129,9 @@ | ||
| 119 | 129 | $paymentStatus = $transaction->status; |
| 120 | 130 | |
| 121 | 131 | if ($paymentStatus == 'PENDING') { |
| 122 | 132 | $paymentRequest = array( |
| 123 | - 'amount' => $transaction->amount, | |
| 133 | + 'amount' => (string)sprintf("%.2f", $transaction->amount), | |
| 124 | 134 | 'currency' => $transaction->currency, |
| 125 | 135 | 'token' => $data['token']['id'] |
| 126 | 136 | ); |
| 127 | 137 | $payment = $api->createPayment($transactionId, $paymentRequest); |
| @@ -141,9 +151,9 @@ | ||
| 141 | 151 | if (!$reference) { return $returnUrl; } |
| 142 | 152 | |
| 143 | 153 | $order = new WC_Order($reference); |
| 144 | 154 | // if we din't find the Order, we send user to shop landing-page. TODO: could be improved |
| 145 | - if (!$order->id) { return $returnUrl; } | |
| 155 | + if (!$order->get_order_number()) { return $returnUrl; } | |
| 146 | 156 | |
| 147 | 157 | $returnUrl = $order->get_checkout_order_received_url(); |
| 148 | 158 | |
| 149 | 159 | switch($paymentStatus) { |
| @@ -156,13 +166,17 @@ | ||
| 156 | 166 | |
| 157 | 167 | case 'COMPLETED': |
| 158 | 168 | $orderNote = array(); |
| 159 | 169 | $orderNote[] = __('Transaction ID', 'wc_makecommerce_domain') . ': <a target=_blank href="'.$api->getEnvUrls()->merchantUrl.'/merchant/shop/deals/detail.html?id='. $transactionId .'">'.$transactionId.'</a>'; |
| 160 | - $orderNote[] = __('Payment option', 'wc_makecommerce_domain') . ': ' . get_post_meta($order->id, '_makecommerce_preselected_method', true); | |
| 170 | + $orderNote[] = __('Payment option', 'wc_makecommerce_domain') . ': ' . get_post_meta($order->get_order_number(), '_makecommerce_preselected_method', true); | |
| 161 | 171 | $order->add_order_note(implode("\r\n", $orderNote)); |
| 172 | + if (!empty($data['token']) && !empty($data['token']['multiuse'])) { | |
| 173 | + update_post_meta($order->get_order_number(), '_makecommerce_payment_token', $data['token']['id']); | |
| 174 | + update_post_meta($order->get_order_number(), '_makecommerce_payment_token_valid_until', $data['token']['valid_until']); | |
| 175 | + } | |
| 162 | 176 | |
| 163 | - $order->payment_complete(); | |
| 164 | - $order->update_status( 'processing' ); | |
| 177 | + $order->payment_complete( $transactionId ); | |
| 178 | + // $order->update_status( 'processing' ); | |
| 165 | 179 | $woocommerce->cart->empty_cart(); |
| 166 | 180 | break; |
| 167 | 181 | |
| 168 | 182 | } |
| @@ -253,9 +267,9 @@ | ||
| 253 | 267 | add_action('wp_login', 'mk_admin_login_update', 10, 2); |
| 254 | 268 | |
| 255 | 269 | |
| 256 | 270 | |
| 257 | - function mk_admin_add_api_settings($sections) { | |
| 271 | + function mk_admin_add_api_settings($sections) { | |
| 258 | 272 | $sections['mk_api'] = __('MakeCommerce API access', 'wc_makecommerce_domain'); |
| 259 | 273 | return $sections; |
| 260 | 274 | } |
| 261 | 275 | |
| @@ -269,15 +283,9 @@ | ||
| 269 | 283 | array( |
| 270 | 284 | 'type' => 'title', |
| 271 | 285 | 'title' => __('MakeCommerce API access credentials', 'wc_makecommerce_domain'), |
| 272 | 286 | 'desc' => __('To use MakeCommerce/Maksekeskus services you need to enter API credentials below here <br/> <br/>', 'wc_makecommerce_domain'). |
| 273 | - 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§ion=makecommerce'). | |
| 274 | - sprintf( __('To use also Ominva or Itella SmartPOST integration please configure these API accesses: <a href="%s">Omniva Parcel Machine API access</a> | '. | |
| 275 | - '<a href="%s">SmartPOST API access</a> | <a href="%s">Omniva Courier API access</a><br/>','wc_makecommerce_domain'), | |
| 276 | - 'admin.php?page=wc-settings&tab=-shipping§ion=parcelmachine_omniva', | |
| 277 | - 'admin.php?page=wc-settings&tab=shipping§ion=parcelmachine_smartpost', | |
| 278 | - 'admin.php?page=wc-settings&tab=shipping§ion=courier_omniva' | |
| 279 | - ), | |
| 287 | + 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§ion=makecommerce'), | |
| 280 | 288 | 'id' => 'mk_api_settings' |
| 281 | 289 | ), |
| 282 | 290 | array( |
| 283 | 291 | 'type' => 'select', |
| @@ -330,15 +338,68 @@ | ||
| 330 | 338 | 'title' => __('Publishable key (test)', 'wc_makecommerce_domain'), |
| 331 | 339 | 'default' => '7Hog41ci2mKkmtviMycWxpNx14pNP70m', |
| 332 | 340 | 'class' => 'input-text regular-input', |
| 333 | 341 | ), |
| 342 | + array('type' => 'sectionend', 'id' => 'mk_api_settings'), | |
| 343 | + array( | |
| 344 | + 'type' => 'title', | |
| 345 | + 'desc' => '<br><hr><br>', | |
| 346 | + ), | |
| 347 | + array( | |
| 348 | + 'id' => 'mk_module_title', | |
| 349 | + 'type' => 'title', | |
| 350 | + 'title' => __('Makecommerce modules', 'wc_makecommerce_domain'), | |
| 351 | + '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'), | |
| 352 | + 'class' => '', | |
| 353 | + ), | |
| 334 | 354 | array( |
| 335 | - 'id' => 'mk_experimental_features', | |
| 355 | + 'id' => 'mk_transport_apt_omniva', | |
| 336 | 356 | 'type' => 'checkbox', |
| 337 | - 'title' => __('Enable experimental features', 'wc_makecommerce_domain'), | |
| 357 | + 'default' => 'yes', | |
| 358 | + 'title' => __('Omniva Parcel Machine', 'wc_makecommerce_domain'), | |
| 359 | + '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§ion=parcelmachine_omniva')).')', | |
| 338 | 360 | 'class' => '', |
| 339 | 361 | ), |
| 340 | 362 | array( |
| 363 | + 'id' => 'mk_transport_apt_smartpost', | |
| 364 | + 'type' => 'checkbox', | |
| 365 | + 'default' => 'yes', | |
| 366 | + 'title' => __('SmartPOST Parcel Machine', 'wc_makecommerce_domain'), | |
| 367 | + '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§ion=parcelmachine_smartpost')).')', | |
| 368 | + 'class' => '', | |
| 369 | + ), | |
| 370 | + array( | |
| 371 | + 'id' => 'mk_transport_apt_dpd', | |
| 372 | + 'type' => 'checkbox', | |
| 373 | + 'default' => 'no', | |
| 374 | + 'title' => __('DPD Pickup Network', 'wc_makecommerce_domain'), | |
| 375 | + '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§ion=parcelmachine_dpd')).')', | |
| 376 | + 'class' => '', | |
| 377 | + ), | |
| 378 | + array( | |
| 379 | + 'id' => 'mk_transport_courier_omniva', | |
| 380 | + 'type' => 'checkbox', | |
| 381 | + 'default' => 'yes', | |
| 382 | + 'title' => __('Omniva Courier', 'wc_makecommerce_domain'), | |
| 383 | + '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§ion=courier_omniva')).')', | |
| 384 | + 'class' => '', | |
| 385 | + ), | |
| 386 | + array( | |
| 387 | + 'id' => 'mk_transport_courier_smartpost', | |
| 388 | + 'type' => 'checkbox', | |
| 389 | + 'default' => 'yes', | |
| 390 | + 'title' => __('SmartPOST Courier', 'wc_makecommerce_domain'), | |
| 391 | + '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§ion=courier_smartpost')).')', | |
| 392 | + 'class' => '', | |
| 393 | + ), | |
| 394 | + array( | |
| 395 | + 'id' => 'mk_checkout_sco', | |
| 396 | + 'type' => 'checkbox', | |
| 397 | + 'title' => __('SimpleCheckout', 'wc_makecommerce_domain'), | |
| 398 | + 'desc' => __('enable SimpleCheckout™ Checkout method', 'wc_makecommerce_domain').' ('. sprintf(__('<a href="%s">module settings</a>', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=makecommerce_sc')).')', | |
| 399 | + 'class' => '', | |
| 400 | + ), | |
| 401 | + array( | |
| 341 | 402 | 'id' => 'mk_javascript_ui', |
| 342 | 403 | 'type' => 'api_javascript_ui', |
| 343 | 404 | ), |
| 344 | 405 | array('type' => 'sectionend', 'id' => 'mk_api_settings') |
| @@ -344,8 +405,17 @@ | ||
| 344 | 405 | array('type' => 'sectionend', 'id' => 'mk_api_settings') |
| 345 | 406 | ); |
| 346 | 407 | } |
| 347 | 408 | |
| 409 | + function mk_wc_version($version) { | |
| 410 | + global $woocommerce; | |
| 411 | + if ( version_compare( $woocommerce->version, "3.4.0", ">=" ) ) { | |
| 412 | + return true; | |
| 413 | + } else { | |
| 414 | + return false; | |
| 415 | + } | |
| 416 | + } | |
| 417 | + | |
| 348 | 418 | function mk_admin_save_api_settings() { |
| 349 | 419 | // reload banklinks |
| 350 | 420 | global $current_section; |
| 351 | 421 | if ($current_section !== 'mk_api') { |
| @@ -353,17 +423,25 @@ | ||
| 353 | 423 | } |
| 354 | 424 | update_mc_banklinks(); |
| 355 | 425 | } |
| 356 | 426 | |
| 357 | - function mk_admin_plugin_settings_link($links) { | |
| 358 | - $settings_link = '<a href="admin.php?page=wc-settings&tab=api§ion=mk_api">API '.__('Settings').'</a>'; | |
| 359 | - array_unshift($links, $settings_link); | |
| 360 | - return $links; | |
| 427 | + function mk_admin_plugin_settings_link($links) { | |
| 428 | + if (mk_wc_version("3.4.0")) | |
| 429 | + $settings_link = '<a href="admin.php?page=wc-settings&tab=advanced§ion=mk_api">API '.__('Settings').'</a>'; | |
| 430 | + else | |
| 431 | + $settings_link = '<a href="admin.php?page=wc-settings&tab=api§ion=mk_api">API '.__('Settings').'</a>'; | |
| 432 | + array_unshift($links, $settings_link); | |
| 433 | + return $links; | |
| 361 | 434 | } |
| 435 | + // if (mk_wc_version("3.4.0")) { | |
| 436 | + add_filter('woocommerce_get_settings_advanced', 'mk_admin_api_settings', 10, 2); | |
| 437 | + add_action('woocommerce_get_sections_advanced', 'mk_admin_add_api_settings'); | |
| 362 | 438 | add_filter('woocommerce_get_settings_api', 'mk_admin_api_settings', 10, 2); |
| 439 | + // } else { | |
| 363 | 440 | add_action('woocommerce_get_sections_api', 'mk_admin_add_api_settings'); |
| 364 | 441 | add_action('woocommerce_settings_saved', 'mk_admin_save_api_settings', 30, 0); |
| 365 | 442 | add_filter("plugin_action_links_".plugin_basename(__FILE__), 'mk_admin_plugin_settings_link' ); |
| 443 | + // } | |
| 366 | 444 | |
| 367 | 445 | function __get_logo_html() { |
| 368 | 446 | return '<div class="makecommerce-info">'. |
| 369 | 447 | '<div class="makecommerce-logo">'. |
| @@ -375,5 +453,12 @@ | ||
| 375 | 453 | '<div class="makecommerce-link"><a target="_blank" href="http://maksekeskus.ee">maksekeskus.ee</a></div>'. |
| 376 | 454 | '</div>'. |
| 377 | 455 | '</div>'; |
| 378 | 456 | } |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 379 | 464 | } |