| @@ -1,21 +1,21 @@ | ||
| 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.2.0 | |
| 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 | 20 | $enable_experimental = get_option('mk_checkout_sco', 'no'); |
| 21 | 21 | if ($enable_experimental === 'yes') { |
| @@ -49,8 +49,9 @@ | ||
| 49 | 49 | type varchar(10) NOT NULL, |
| 50 | 50 | country char(2) NOT NULL, |
| 51 | 51 | name varchar(25) NOT NULL, |
| 52 | 52 | url varchar(250) NOT NULL, |
| 53 | + logo_url varchar(250), | |
| 53 | 54 | UNIQUE KEY id (id) |
| 54 | 55 | ) $charset;"; |
| 55 | 56 | |
| 56 | 57 | require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
| @@ -128,9 +129,9 @@ | ||
| 128 | 129 | $paymentStatus = $transaction->status; |
| 129 | 130 | |
| 130 | 131 | if ($paymentStatus == 'PENDING') { |
| 131 | 132 | $paymentRequest = array( |
| 132 | - 'amount' => $transaction->amount, | |
| 133 | + 'amount' => (string)sprintf("%.2f", $transaction->amount), | |
| 133 | 134 | 'currency' => $transaction->currency, |
| 134 | 135 | 'token' => $data['token']['id'] |
| 135 | 136 | ); |
| 136 | 137 | $payment = $api->createPayment($transactionId, $paymentRequest); |
| @@ -150,9 +151,9 @@ | ||
| 150 | 151 | if (!$reference) { return $returnUrl; } |
| 151 | 152 | |
| 152 | 153 | $order = new WC_Order($reference); |
| 153 | 154 | // if we din't find the Order, we send user to shop landing-page. TODO: could be improved |
| 154 | - if (!$order->id) { return $returnUrl; } | |
| 155 | + if (!$order->get_order_number()) { return $returnUrl; } | |
| 155 | 156 | |
| 156 | 157 | $returnUrl = $order->get_checkout_order_received_url(); |
| 157 | 158 | |
| 158 | 159 | switch($paymentStatus) { |
| @@ -165,13 +166,17 @@ | ||
| 165 | 166 | |
| 166 | 167 | case 'COMPLETED': |
| 167 | 168 | $orderNote = array(); |
| 168 | 169 | $orderNote[] = __('Transaction ID', 'wc_makecommerce_domain') . ': <a target=_blank href="'.$api->getEnvUrls()->merchantUrl.'/merchant/shop/deals/detail.html?id='. $transactionId .'">'.$transactionId.'</a>'; |
| 169 | - $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); | |
| 170 | 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 | + } | |
| 171 | 176 | |
| 172 | 177 | $order->payment_complete( $transactionId ); |
| 173 | - $order->update_status( 'processing' ); | |
| 178 | + // $order->update_status( 'processing' ); | |
| 174 | 179 | $woocommerce->cart->empty_cart(); |
| 175 | 180 | break; |
| 176 | 181 | |
| 177 | 182 | } |
| @@ -361,17 +366,17 @@ | ||
| 361 | 366 | 'title' => __('SmartPOST Parcel Machine', 'wc_makecommerce_domain'), |
| 362 | 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')).')', |
| 363 | 368 | 'class' => '', |
| 364 | 369 | ), |
| 365 | -// array( | |
| 366 | -// 'id' => 'mk_transport_apt_dpd', | |
| 367 | -// 'type' => 'checkbox', | |
| 368 | -// 'default' => 'no', | |
| 369 | -// 'title' => __('DPD Pickup Network', 'wc_makecommerce_domain'), | |
| 370 | -// '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')).')', | |
| 371 | -// 'class' => '', | |
| 372 | -// ), | |
| 373 | 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( | |
| 374 | 379 | 'id' => 'mk_transport_courier_omniva', |
| 375 | 380 | 'type' => 'checkbox', |
| 376 | 381 | 'default' => 'yes', |
| 377 | 382 | 'title' => __('Omniva Courier', 'wc_makecommerce_domain'), |
| @@ -400,8 +405,17 @@ | ||
| 400 | 405 | array('type' => 'sectionend', 'id' => 'mk_api_settings') |
| 401 | 406 | ); |
| 402 | 407 | } |
| 403 | 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 | + | |
| 404 | 418 | function mk_admin_save_api_settings() { |
| 405 | 419 | // reload banklinks |
| 406 | 420 | global $current_section; |
| 407 | 421 | if ($current_section !== 'mk_api') { |
| @@ -409,17 +423,25 @@ | ||
| 409 | 423 | } |
| 410 | 424 | update_mc_banklinks(); |
| 411 | 425 | } |
| 412 | 426 | |
| 413 | - function mk_admin_plugin_settings_link($links) { | |
| 414 | - $settings_link = '<a href="admin.php?page=wc-settings&tab=api§ion=mk_api">API '.__('Settings').'</a>'; | |
| 415 | - array_unshift($links, $settings_link); | |
| 416 | - 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; | |
| 417 | 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'); | |
| 418 | 438 | add_filter('woocommerce_get_settings_api', 'mk_admin_api_settings', 10, 2); |
| 439 | + // } else { | |
| 419 | 440 | add_action('woocommerce_get_sections_api', 'mk_admin_add_api_settings'); |
| 420 | 441 | add_action('woocommerce_settings_saved', 'mk_admin_save_api_settings', 30, 0); |
| 421 | 442 | add_filter("plugin_action_links_".plugin_basename(__FILE__), 'mk_admin_plugin_settings_link' ); |
| 443 | + // } | |
| 422 | 444 | |
| 423 | 445 | function __get_logo_html() { |
| 424 | 446 | return '<div class="makecommerce-info">'. |
| 425 | 447 | '<div class="makecommerce-logo">'. |
| @@ -431,5 +453,12 @@ | ||
| 431 | 453 | '<div class="makecommerce-link"><a target="_blank" href="http://maksekeskus.ee">maksekeskus.ee</a></div>'. |
| 432 | 454 | '</div>'. |
| 433 | 455 | '</div>'; |
| 434 | 456 | } |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 435 | 464 | } |