%2$s

', esc_attr( $class ), esc_html( $message ) ); }); } global $mkDbTable; $mkDbTable = 'mc_banklinks'; function mc_install() { global $wpdb; global $mkDbTable; $tableName = $wpdb->prefix . $mkDbTable; $charset = $wpdb->get_charset_collate(); $sql = "CREATE TABLE $tableName ( id mediumint(9) NOT NULL AUTO_INCREMENT, type varchar(10) NOT NULL, country char(2) NOT NULL, name varchar(25) NOT NULL, url varchar(250) NOT NULL, logo_url varchar(250), min_amount mediumint(9), max_amount mediumint(9), UNIQUE KEY id (id) ) $charset;"; require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); dbDelta( $sql ); } register_activation_hook( __FILE__, 'mc_install' ); // On uninstall remove scheduled hook function mc_uninstall() { if (wp_next_scheduled ( 'mc_banklinks_update_cron' )) { wp_clear_scheduled_hook('mc_banklinks_update_cron'); } } register_deactivation_hook(__FILE__, 'mc_uninstall'); // WP schedule callable action add_action('mc_banklinks_update_cron', 'update_mc_banklinks'); // Assign schedule if not set, update compatible no need to reactivate, format('U') php 5.2 compatible // Assigns task at 23.59.59 by local time, task runs if time has passed and somebody navigates the site if (! wp_next_scheduled ( 'mc_banklinks_update_cron' )) { $date = new DateTime(); $date->setTime(rand(0,23),rand(0,59),00); $timestamp = intval($date->format('U')); //$local = 3600 * intval(get_option('gmt_offset')); //wp_schedule_event($timestamp - $local, 'twicedaily', 'mc_banklinks_update_cron'); wp_schedule_event($timestamp, 'twicedaily', 'mc_banklinks_update_cron'); } if (!class_exists('wc_makecommerce_domain')) { require_once('includes/vendor/autoload.php'); require_once('includes/Maksekeskus.php'); } function mk_check_payment() { global $woocommerce; $api = mk_get_api(); //set the correct language if (isset($_GET["lang1"])) { //set polylang language if (function_exists('pll_current_language')) { //get the correct locale name from polylang $polylangLangs = pll_the_languages(array('raw' => 1)); if (isset($polylangLangs[$_GET["lang1"]])) { $locale = str_replace("-", "_", $polylangLangs[$_GET["lang1"]]["locale"]); } //first change WP language, this triggers some polylang hooks switch_to_locale($locale); //second, change WPML language?!?! this ensures the correct landingpage (works with polylang) do_action('wpml_switch_language', $_GET["lang1"]); } else { if (function_exists('icl_object_id')) { //weirdly enough icl_object ID exists in this point of the request. It doesn't in other locations... //set wpml language do_action('wpml_switch_language', $_GET["lang1"]); } } } $returnUrl = home_url(); $request = stripslashes_deep($_POST); if ($api->verifyMac($request)) { $data = $api->extractRequestData($request); $reference = false; if (!empty($data['error']) ) { wc_add_notice(__('Payment failed', 'wc_makecommerce_domain'), 'error'); return $returnUrl; } if (!empty($data['message_type']) ) { if ($data['message_type'] == 'payment_return') { $transactionId = $data['transaction']; $reference = $data['reference']; $paymentStatus = $data['status']; } if ($data['message_type'] == 'token_return') { if (!empty($data['transaction']['reference'])) { $reference = $data['transaction']['reference']; } $paymentStatus = $data['transaction']['status']; $transactionId = $data['transaction']['id']; // for API backward compatibility - if we didn't find reference in the mesage, or the transaction state vas still PENDING // we'll fetch the transaction data from API, and make a payment request if needed // this all can be removed after 2017-jan if (!$reference or $paymentStatus == 'PENDING') { $transaction = $api->getTransaction($transactionId); if (!empty($transaction->reference)) { $reference = $transaction->reference; } $paymentStatus = $transaction->status; if ($paymentStatus == 'PENDING') { $paymentRequest = array( 'amount' => (string)sprintf("%.2f", $transaction->amount), 'currency' => $transaction->currency, 'token' => $data['token']['id'] ); $payment = $api->createPayment($transactionId, $paymentRequest); // TODO: validate $paymentStatus = $payment->transaction->status; } } } } } // if we didn't find reference to an Order, we send user to shop landing-page. TODO: could be improved if (!$reference) { return $returnUrl; } $order = new WC_Order($reference); // if we din't find the Order, we send user to shop landing-page. TODO: could be improved if (!$order->get_id()) { return $returnUrl; } $returnUrl = $order->get_checkout_order_received_url(); if ($paymentStatus == 'CANCELLED' || $paymentStatus == 'COMPLETED') { //get transaction to update the payment method. $transaction = $api->getTransaction($transactionId); //make sure the payment method is the same for simplecheckout and normal version. $paymentMethod = ""; if (isset($transaction->type) && isset($transaction->method)) { if ($transaction->type == "card") { $paymentMethod = "card_".$transaction->method; } else { if (isset($transaction->country)) { $paymentMethod = $transaction->country."_".$transaction->method; } } } //update _makecommerce_preselected_method update_post_meta($order->get_id(), '_makecommerce_preselected_method', $paymentMethod); } switch($paymentStatus) { case 'CANCELLED': $order->update_status( 'cancelled' ); wc_add_notice(__('Payment transaction cancelled', 'wc_makecommerce_domain'), 'error'); $returnUrl = wc_get_cart_url(); break; case 'COMPLETED': $orderNote = array(); $orderNote[] = __('Transaction ID', 'wc_makecommerce_domain') . ': '.$transactionId.''; $orderNote[] = __('Payment option', 'wc_makecommerce_domain') . ': ' . get_post_meta($order->get_id(), '_makecommerce_preselected_method', true); $order->add_order_note(implode("\r\n", $orderNote)); if (!empty($data['token']) && !empty($data['token']['multiuse'])) { update_post_meta($order->get_id(), '_makecommerce_payment_token', $data['token']['id']); update_post_meta($order->get_id(), '_makecommerce_payment_token_valid_until', $data['token']['valid_until']); } if (isset($_GET['lang1'])) { $order->update_meta_data('wpml_language', $_GET["lang1"]); } $order->payment_complete( $transactionId ); $woocommerce->cart->empty_cart(); break; } return $returnUrl; } $MKAPI = false; function mk_get_api() { global $MKAPI; if ($MKAPI) { //return $MKAPI; } $mk_api_type = get_option('mk_api_type', false); if (!$mk_api_type) { return false; } if ($mk_api_type !== 'live') { $key_prefix = $mk_api_type.'_'; } else { $key_prefix = ''; } $mk_shop_id = get_option('mk_'.$key_prefix.'shop_id', ''); $mk_public_key = get_option('mk_'.$key_prefix.'public_key', ''); $mk_private_key = get_option('mk_'.$key_prefix.'private_key', ''); if (!$mk_shop_id || !$mk_public_key || !$mk_shop_id) { return false; } $MKAPI = new \Maksekeskus\Maksekeskus($mk_shop_id, $mk_public_key, $mk_private_key, $mk_api_type === 'live' ? false : true); return $MKAPI; } function mk_is_api_set() { $mk_api_type = get_option('mk_api_type', false); if (!$mk_api_type) { return false; } if ($mk_api_type !== 'live') { $key_prefix = $mk_api_type.'_'; } else { $key_prefix = ''; } $mk_shop_id = get_option('mk_'.$key_prefix.'shop_id', ''); $mk_public_key = get_option('mk_'.$key_prefix.'public_key', ''); $mk_private_key = get_option('mk_'.$key_prefix.'private_key', ''); if (!$mk_shop_id || !$mk_public_key || !$mk_shop_id) { return false; } return true; } function mk_admin_error() { printf( '

%2$s

', 'notice notice-error', __('Please check that you have configured correctly MakeCommerce API accesses', 'wc_makecommerce_domain')); } add_filter('query_vars', 'mk_cron_query_vars'); add_action('parse_request', 'mk_parse_cron_update_vars'); function mk_cron_query_vars($vars) { $vars[] = 'mk-action'; $vars[] = 'mk-shop-id'; $vars[] = 'mk-test-shop-id'; return $vars; } function mk_parse_cron_update_vars($wp) { if (array_key_exists('mk-action', $wp->query_vars) && $wp->query_vars['mk-action'] == 'mk-update' && (array_key_exists('mk-shop-id', $wp->query_vars) || array_key_exists('mk-test-shop-id', $wp->query_vars) ) ) { if( (strlen($wp->query_vars['mk-shop-id']) && $wp->query_vars['mk-shop-id'] == get_option('mk_shop_id', false) ) || (strlen($wp->query_vars['mk-test-shop-id']) && $wp->query_vars['mk-test-shop-id'] == get_option('mk_test_shop_id', false) ) ) { update_mc_banklinks(); exit(); } } } function mk_admin_login_update($user_login, $user) { if(user_can( $user, 'administrator' )) { update_mc_banklinks(); } } add_action('wp_login', 'mk_admin_login_update', 10, 2); function mk_admin_add_api_settings($sections) { $sections['mk_api'] = __('MakeCommerce API access', 'wc_makecommerce_domain'); return $sections; } function mk_admin_api_settings($settings) { global $current_section; if ($current_section !== 'mk_api') { return $settings; } return array( array('type' => 'title', 'desc' => __get_logo_html()), array( 'type' => 'title', 'title' => __('MakeCommerce API access credentials', 'wc_makecommerce_domain'), 'desc' => __('To use MakeCommerce/Maksekeskus services you need to enter API credentials below here

', 'wc_makecommerce_domain'). sprintf( __('To further configure the Payment methods please go to MakeCommerce Checkout Options, links to settings of our Shipment methods are listed below', 'wc_makecommerce_domain'), 'admin.php?page=wc-settings&tab=checkout§ion=makecommerce'), 'id' => 'mk_api_settings' ), array( 'type' => 'select', 'title' => __('Current environment', 'wc_makecommerce_domain'), 'desc' => __('See more about MakeCommerce Test environment', 'wc_makecommerce_domain'), 'default' => 'live', 'options' => array( 'live' => __('Live', 'wc_makecommerce_domain'), 'test' => __('Test', 'wc_makecommerce_domain'), ), 'id' => 'mk_api_type' ), array( 'id' => 'mk_shop_id', 'type' => 'text', 'title' => __('Shop ID (live)', 'wc_makecommerce_domain'), 'desc' => __('Get it from Merchant Portal','wc_makecommerce_domain'), 'class' => 'input-text regular-input', ), array( 'id' => 'mk_private_key', 'type' => 'text', 'title' => __('Secret key (live)', 'wc_makecommerce_domain'), 'class' => 'input-text regular-input', ), array( 'id' => 'mk_public_key', 'type' => 'text', 'title' => __('Publishable key (live)', 'wc_makecommerce_domain'), 'class' => 'input-text regular-input', ), array( 'id' => 'mk_test_shop_id', 'type' => 'text', 'title' => __('Shop ID (test)', 'wc_makecommerce_domain'), 'class' => 'input-text regular-input', 'default' => 'f64b4f20-5ef9-4b7b-a6fa-d623d87f0b9c', 'desc' => __('Get it from Merchant Portal Test','wc_makecommerce_domain'), ), array( 'id' => 'mk_test_private_key', 'type' => 'text', 'title' => __('Secret key (test)', 'wc_makecommerce_domain'), 'default' => 'MPjcVMoRZPAucsTuGK5ZukOlV7BlzgSvXOowJUkk9IFSQPVooRwcVOxzz3mhEpgM', 'class' => 'input-text regular-input', ), array( 'id' => 'mk_test_public_key', 'type' => 'text', 'title' => __('Publishable key (test)', 'wc_makecommerce_domain'), 'default' => '7Hog41ci2mKkmtviMycWxpNx14pNP70m', 'class' => 'input-text regular-input', ), array('type' => 'sectionend', 'id' => 'mk_api_settings'), array( 'type' => 'title', 'desc' => '


', ), array( 'id' => 'mk_module_title', 'type' => 'title', 'title' => __('Makecommerce modules', 'wc_makecommerce_domain'), '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.
Each active module have their own settings dialog, where they must also be Enabled before use.', 'wc_makecommerce_domain'), 'class' => '', ), array( 'id' => 'mk_transport_apt_omniva', 'type' => 'checkbox', 'default' => 'yes', 'title' => __('Omniva Parcel Machine', 'wc_makecommerce_domain'), 'desc' => __('enable Omniva parcel machines shipping method', 'wc_makecommerce_domain').' ('. sprintf(__('module settings', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=shipping§ion=parcelmachine_omniva')).')', 'class' => '', ), array( 'id' => 'mk_transport_apt_smartpost', 'type' => 'checkbox', 'default' => 'yes', 'title' => __('SmartPOST Parcel Machine', 'wc_makecommerce_domain'), 'desc' => __('enable SmartPOST parcel machines shipping method', 'wc_makecommerce_domain').' ('. sprintf(__('module settings', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=shipping§ion=parcelmachine_smartpost')).')', 'class' => '', ), array( 'id' => 'mk_transport_apt_dpd', 'type' => 'checkbox', 'default' => 'no', 'title' => __('DPD', 'wc_makecommerce_domain') . ' ' . __('parcel machine', 'wc_makecommerce_domain'), 'desc' => __('enable DPD parcel machine shipping method', 'wc_makecommerce_domain').' ('. sprintf(__('module settings', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=shipping§ion=parcelmachine_dpd')).')', 'class' => '', ), array( 'id' => 'mk_transport_courier_omniva', 'type' => 'checkbox', 'default' => 'yes', 'title' => __('Omniva Courier', 'wc_makecommerce_domain'), 'desc' => __('enable Omniva courier shipping method', 'wc_makecommerce_domain').' ('. sprintf(__('module settings', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=shipping§ion=courier_omniva')).')', 'class' => '', ), array( 'id' => 'mk_transport_courier_smartpost', 'type' => 'checkbox', 'default' => 'yes', 'title' => __('SmartPOST Courier', 'wc_makecommerce_domain'), 'desc' => __('enable SmartPOST courier shipping method', 'wc_makecommerce_domain').' ('. sprintf(__('module settings', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=shipping§ion=courier_smartpost')).')', 'class' => '', ), array( 'id' => 'mk_checkout_sco', 'type' => 'checkbox', 'title' => __('SimpleCheckout', 'wc_makecommerce_domain'), 'desc' => __('enable SimpleCheckout™ Checkout method', 'wc_makecommerce_domain').' ('. sprintf(__('module settings', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=makecommerce_sc')).')', 'class' => '', ), array( 'id' => 'mk_product_slice', 'type' => 'checkbox', 'title' => __('Indivy Slice 3 information in product view', 'wc_makecommerce_domain'), 'desc' => __('enable Indivy Slice 3 in product view', 'wc_makecommerce_domain'), 'class' => '', ), array( 'id' => 'mk_javascript_ui', 'type' => 'api_javascript_ui', ), array('type' => 'sectionend', 'id' => 'mk_api_settings') ); } function mk_wc_version($version) { global $woocommerce; if ( version_compare( $woocommerce->version, "3.4.0", ">=" ) ) { return true; } else { return false; } } function mk_admin_save_api_settings() { // reload banklinks global $current_section; if ($current_section !== 'mk_api') { return; } update_mc_banklinks(); } function mk_admin_plugin_settings_link($links) { if (mk_wc_version("3.4.0")) $settings_link = 'API '.__('Settings').''; else $settings_link = 'API '.__('Settings').''; array_unshift($links, $settings_link); return $links; } function wc_mc_shop_slice_button() { if (get_option('mk_product_slice', 'no') == 'yes') { global $product; // $price_excl_tax = wc_get_price_excluding_tax( $product ); // price without VAT $price_incl_tax = wc_get_price_including_tax( $product ); // price with VAT global $wpdb; global $mkDbTable; $tableName = $wpdb->prefix . $mkDbTable; $methods = $wpdb->get_results('SELECT * FROM '.$tableName); $slice = false; if(count($methods)) { foreach ($methods as $method) { if ($method->name =="slice") { if ( $price_incl_tax >= $method->min_amount ) { if ( $price_incl_tax <= $method->max_amount ) { $slice = true; } } } } } if ($slice == true) { echo '
  Osta kohe, maksa hiljem. Kolmes võrdses osas 3 x '.sprintf("%.2f",$price_incl_tax/3).' €
'; // sprintf("%.2f",$price_incl_tax/3).' in month } } } // Slice Promo 1 add_action( 'woocommerce_after_add_to_cart_button', 'wc_mc_shop_slice_button', 20 ); // if (mk_wc_version("3.4.0")) { add_filter('woocommerce_get_settings_advanced', 'mk_admin_api_settings', 10, 2); add_action('woocommerce_get_sections_advanced', 'mk_admin_add_api_settings'); add_filter('woocommerce_get_settings_api', 'mk_admin_api_settings', 10, 2); // } else { add_action('woocommerce_get_sections_api', 'mk_admin_add_api_settings'); add_action('woocommerce_settings_saved', 'mk_admin_save_api_settings', 30, 0); add_filter("plugin_action_links_".plugin_basename(__FILE__), 'mk_admin_plugin_settings_link' ); // } function __get_logo_html() { return '
'. ''. ''. '
'; } /* add new column (makecommerce_payment_method) to orders list */ function wc_makecommerce_payment_method_order_column($columns) { $columns['makecommerce_payment_method'] = __('Payment method (MC)'); return $columns; } add_filter('manage_edit-shop_order_columns', 'wc_makecommerce_payment_method_order_column'); // Make custom column sortable add_filter( "manage_edit-shop_order_sortable_columns", 'makecommerce_payment_method_sortable' ); function makecommerce_payment_method_sortable($columns) { $meta_key = 'makecommerce_payment_method'; return wp_parse_args(array('makecommerce_payment_method' => $meta_key), $columns); } /* fill content for makecommerce_payment_method */ function wc_makecommerce_payment_method_order_column_content($column) { global $post; if ('makecommerce_payment_method' === $column) { echo get_post_meta($post->ID, '_makecommerce_preselected_method', true); } } add_action('manage_shop_order_posts_custom_column', 'wc_makecommerce_payment_method_order_column_content'); }