PluginProbe
MakeCommerce for WooCommerce / 3.0.12
MakeCommerce for WooCommerce v3.0.12
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 +160 -328 2.1.13.0.12 View file →
@@ -1,371 +1,203 @@
1 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: 2.1.1
6 - Author: Maksekeskus AS
7 - Author URI: https://MakeCommerce.net/
8 - Text Domain: wc_makecommerce_domain
9 -*/
10 2
11 -if ( ! defined( 'ABSPATH' ) ) {
12 - exit; // Exit if accessed directly.
3 +/**
4 + * @link https://makecommerce.net/
5 + * @since 3.0.0
6 + * @package Makecommerce
7 + *
8 + * @wordpress-plugin
9 + * Plugin Name: MakeCommerce
10 + * Plugin URI: https://makecommerce.net/
11 + * Description: Adds MakeCommerce/Simplecheckout payment gateway and Itella/Omniva/DPD parcel machine shipping methods to WooCommerce checkout
12 + * Version: 3.0.12
13 + * Author: Maksekeskus AS
14 + * Author URI: https://makecommerce.net/
15 + * License: GPL-2.0+
16 + * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
17 + * Text Domain: makecommerce
18 + * Domain Path: /languages
19 + * Requires at least: 5.6.1
20 + * Requires PHP: 7.4
21 + * WC requires at least: 5.0.0
22 + * WC tested up to: 6.1.1
23 + */
24 +
25 +// If this file is called directly, abort.
26 +if ( ! defined( 'WPINC' ) ) {
27 + die;
13 28 }
14 29
15 -if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
30 +/**
31 + * Currently plugin version.
32 + * Start at version 3.0.0 and use SemVer - https://semver.org
33 + */
34 +define( 'MAKECOMMERCE_VERSION', '3.0.12' );
35 +define( 'MAKECOMMERCE_PLUGIN_ID', 'makecommerce' );
16 36
37 +//table name for banklinks
38 +define( 'MAKECOMMERCE_TABLENAME', 'mc_banklinks' );
39 +define( 'MAKECOMMERCE_SCO_TABLENAME', 'woocommerce_makecommerce_sc' );
17 40
18 - define('WC_MC_VERSION', 2.0);
41 +//WC makecommerce version
42 +define( 'WC_MC_VERSION', 2.0 );
19 43
20 - $enable_experimental = get_option('mk_experimental_features', false);
21 - if ($enable_experimental && $enable_experimental !== 'no') {
22 - require_once(__DIR__.'/makecommerce-simplecheckout.php');
23 - }
24 - require_once(__DIR__.'/makecommerce-transport.php');
25 - require_once(__DIR__.'/makecommerce-payment.php');
44 +register_activation_hook( __FILE__, 'activate_makecommerce' );
45 +register_deactivation_hook( __FILE__, 'deactivate_makecommerce' );
26 46
27 - global $mkDbTable;
28 - $mkDbTable = 'mc_banklinks';
47 +/**
48 + * Check if we are ok to continue (if namesoace and class doesn't already exist)
49 + */
50 +if ( class_exists( 'MakeCommerce' ) || namespaceExists( 'MakeCommerce' ) ) {
29 51
30 - function mc_install() {
31 - global $wpdb;
32 - global $mkDbTable;
33 -
34 - $tableName = $wpdb->prefix . $mkDbTable;
35 -
36 - $charset = $wpdb->get_charset_collate();
37 -
38 - $sql = "CREATE TABLE $tableName (
39 - id mediumint(9) NOT NULL AUTO_INCREMENT,
40 - type varchar(10) NOT NULL,
41 - country char(2) NOT NULL,
42 - name varchar(25) NOT NULL,
43 - url varchar(250) NOT NULL,
44 - UNIQUE KEY id (id)
45 - ) $charset;";
46 -
47 - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
48 - dbDelta( $sql );
49 - }
52 + add_action( 'admin_notices', 'namespace_or_class_already_in_use' );
50 53
51 - register_activation_hook( __FILE__, 'mc_install' );
54 + deactivate_plugins( plugin_dir_path( __FILE__ ) . '/makecommerce.php' );
52 55
53 - // On uninstall remove scheduled hook
54 - function mc_uninstall() {
55 - if (wp_next_scheduled ( 'mc_banklinks_update_cron' )) {
56 - wp_clear_scheduled_hook('mc_banklinks_update_cron');
57 - }
58 - }
56 + return false;
57 +}
59 58
60 - register_deactivation_hook(__FILE__, 'mc_uninstall');
59 +/**
60 + * Check if a namespace already exists
61 + *
62 + * @since 3.0.0
63 + */
64 +function namespaceExists( $namespace ) {
61 65
62 - // WP schedule callable action
63 - add_action('mc_banklinks_update_cron', 'update_mc_banklinks');
64 - // Assign schedule if not set, update compatible no need to reactivate, format('U') php 5.2 compatible
65 - // Assigns task at 23.59.59 by local time, task runs if time has passed and somebody navigates the site
66 - if (! wp_next_scheduled ( 'mc_banklinks_update_cron' )) {
67 - $date = new DateTime();
68 - $date->setTime(04,10,00);
69 - $timestamp = intval($date->format('U'));
70 - //$local = 3600 * intval(get_option('gmt_offset'));
71 - //wp_schedule_event($timestamp - $local, 'twicedaily', 'mc_banklinks_update_cron');
72 - wp_schedule_event($timestamp, 'hourly', 'mc_banklinks_update_cron');
73 - }
74 -
75 - if (!class_exists('wc_makecommerce_domain')) {
76 - require_once('includes/vendor/autoload.php');
77 - require_once('includes/Maksekeskus.php');
78 - }
79 -
80 - function mk_check_payment() {
81 -
82 - global $woocommerce;
83 - $api = mk_get_api();
84 -
85 - $returnUrl = home_url();
66 + $namespace .= "\\";
67 +
68 + foreach ( get_declared_classes() as $name ) {
86 69
87 - $request = stripslashes_deep($_POST);
88 - if ($api->verifyMac($request)) {
89 - $data = $api->extractRequestData($request);
90 - $reference = false;
91 -
92 - if (!empty($data['message_type']) ) {
93 - if ($data['message_type'] == 'payment_return') {
94 - $transactionId = $data['transaction'];
95 - $reference = $data['reference'];
96 - $paymentStatus = $data['status'];
97 - }
98 - if ($data['message_type'] == 'token_return') {
99 - if (!empty($data['transaction']['reference'])) {
100 - $reference = $data['transaction']['reference'];
101 - }
102 - $paymentStatus = $data['transaction']['status'];
103 - $transactionId = $data['transaction']['id'];
104 -
105 - // for API backward compatibility - if we didn't find reference in the mesage, or the transaction state vas still PENDING
106 - // we'll fetch the transaction data from API, and make a payment request if needed
107 - // this all can be removed avter 2017-jan
108 - if (!$reference or $paymentStatus == 'PENDING') {
109 - $transaction = $api->getTransaction($transactionId);
110 - if (!empty($transaction->reference)) {
111 - $reference = $transaction->reference;
112 - }
113 -
114 - $paymentStatus = $transaction->status;
115 -
116 - if ($paymentStatus == 'PENDING') {
117 - $paymentRequest = array(
118 - 'amount' => $transaction->amount,
119 - 'currency' => $transaction->currency,
120 - 'token' => $data['token']['id']
121 - );
122 - $payment = $api->createPayment($transactionId, $paymentRequest);
123 - // TODO: validate
124 - $paymentStatus = $payment->transaction->status;
125 - }
126 -
127 - }
128 -
129 -
130 - }
131 -
132 - }
70 + if ( strpos( $name, $namespace ) === 0 ) {
71 + return true;
133 72 }
73 + }
134 74
135 - // if we didn't find reference to an Order, we send user to shop landing-page. TODO: could be improved
136 - if (!$reference) { return $returnUrl; }
75 + return false;
76 +}
137 77
138 - $order = new WC_Order($reference);
139 - // if we din't find the Order, we send user to shop landing-page. TODO: could be improved
140 - if (!$order->id) { return $returnUrl; }
78 +/**
79 + * Shows error in admin that we cannot continue
80 + *
81 + * @since 3.0.0
82 + */
83 +function namespace_or_class_already_in_use() {
84 +
85 + ?>
86 + <div class="error notice">
87 + <p><?php _e( 'Cannot initiate MakeCommerce, a class and/or namespace called "MakeCommerce" is already in use somewhere else...', 'wc_makecommerce_domain' ); ?></p>
88 + </div>
89 + <?php
90 +}
141 91
142 - switch($paymentStatus) {
92 +/**
93 + * Check if WooCommerce exists and is active. Can't do much without it
94 + */
95 +if ( !in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
143 96
144 - case 'CANCELLED':
145 - $order->update_status( 'cancelled' );
146 - wc_add_notice(__('Payment transaction cancelled', 'wc_makecommerce_domain'), 'error');
147 - break;
97 + if ( is_multisite() ) {
148 98
149 - case 'COMPLETED':
150 - $orderNote = array();
151 - $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);
153 - $order->add_order_note(implode("\r\n", $orderNote));
154 -
155 - $order->payment_complete();
156 - $order->update_status( 'processing' );
157 - break;
99 + include_once( ABSPATH . "wp-admin/includes/plugin.php" );
100 + if ( !is_plugin_active_for_network( "woocommerce/woocommerce.php" ) ) {
101 + woocommerce_not_found_or_active();
158 102
159 - }
103 + deactivate_plugins( plugin_dir_path( __FILE__ ) . '/makecommerce.php' );
160 104
161 - $returnUrl = $order->get_checkout_order_received_url();
162 - return $returnUrl;
163 - }
164 -
165 -
166 -
167 -
168 - $MKAPI = false;
169 - function mk_get_api() {
170 - global $MKAPI;
171 - if ($MKAPI) {
172 - //return $MKAPI;
173 - }
174 - $mk_api_type = get_option('mk_api_type', false);
175 - if (!$mk_api_type) {
176 105 return false;
177 106 }
178 - if ($mk_api_type !== 'live') {
179 - $key_prefix = $mk_api_type.'_';
180 - } else {
181 - $key_prefix = '';
182 - }
183 - $mk_shop_id = get_option('mk_'.$key_prefix.'shop_id', '');
184 - $mk_public_key = get_option('mk_'.$key_prefix.'public_key', '');
185 - $mk_private_key = get_option('mk_'.$key_prefix.'private_key', '');
186 - if (!$mk_shop_id || !$mk_public_key || !$mk_shop_id) {
187 - return false;
188 - }
189 - $MKAPI = new \Maksekeskus\Maksekeskus($mk_shop_id, $mk_public_key, $mk_private_key, $mk_api_type === 'live' ? false : true);
190 - return $MKAPI;
191 - }
107 + } else {
108 + woocommerce_not_found_or_active();
192 109
193 - function mk_is_api_set() {
194 - $mk_api_type = get_option('mk_api_type', false);
195 - if (!$mk_api_type) {
196 - return false;
197 - }
198 - if ($mk_api_type !== 'live') {
199 - $key_prefix = $mk_api_type.'_';
200 - } else {
201 - $key_prefix = '';
202 - }
203 - $mk_shop_id = get_option('mk_'.$key_prefix.'shop_id', '');
204 - $mk_public_key = get_option('mk_'.$key_prefix.'public_key', '');
205 - $mk_private_key = get_option('mk_'.$key_prefix.'private_key', '');
206 - if (!$mk_shop_id || !$mk_public_key || !$mk_shop_id) {
207 - return false;
208 - }
209 - return true;
110 + deactivate_plugins( plugin_dir_path( __FILE__ ) . '/makecommerce.php' );
111 +
112 + return false;
210 113 }
114 +}
211 115
116 +/**
117 + * If no WooCommerce is found
118 + *
119 + * @since 3.0.3
120 + */
121 +function woocommerce_not_found_or_active() {
212 122
213 - function mk_admin_error() {
214 - 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'));
215 - }
123 + add_action( 'admin_notices', 'no_woocommerce_found' );
216 124
125 + deactivate_makecommerce();
126 +}
217 127
128 +/**
129 + * Shows error in admin that we cannot continue
130 + *
131 + * @since 3.0.0
132 + */
133 +function no_woocommerce_found() {
134 +
135 + ?>
136 + <div class="error notice">
137 + <p><?php _e( 'Cannot initiate MakeCommerce, there seems to be no WooCommerce present or active...', 'wc_makecommerce_domain' ); ?></p>
138 + </div>
139 + <?php
140 +}
218 141
219 - add_filter('query_vars', 'mk_cron_query_vars');
220 - add_action('parse_request', 'mk_parse_cron_update_vars');
142 +/**
143 + * Disable automatic updates for MakeCommerce plugin
144 + *
145 + * @since 3.0.1
146 + */
147 +function disable_makecommerce_automatic_updates( $should_update, $plugin ) {
221 148
222 - function mk_cron_query_vars($vars) {
223 - $vars[] = 'mk-action';
224 - $vars[] = 'mk-shop-id';
225 - $vars[] = 'mk-test-shop-id';
226 - return $vars;
149 + if ( ! isset( $plugin->plugin, $plugin->new_version ) ) {
150 + return $should_update;
227 151 }
228 152
229 - function mk_parse_cron_update_vars($wp) {
230 - if (array_key_exists('mk-action', $wp->query_vars) && $wp->query_vars['mk-action'] == 'mk-update'
231 - && (array_key_exists('mk-shop-id', $wp->query_vars) || array_key_exists('mk-test-shop-id', $wp->query_vars) ) ) {
232 - if( (strlen($wp->query_vars['mk-shop-id']) && $wp->query_vars['mk-shop-id'] == get_option('mk_shop_id', false) )
233 - || (strlen($wp->query_vars['mk-test-shop-id']) && $wp->query_vars['mk-test-shop-id'] == get_option('mk_test_shop_id', false) ) ) {
234 - update_mc_banklinks();
235 - exit();
236 - }
237 - }
153 + if ( 'makecommerce/makecommerce.php' !== $plugin->plugin ) {
154 + return $should_update;
238 155 }
239 156
240 - function mk_admin_login_update($user_login, $user) {
241 - if(user_can( $user, 'administrator' )) {
242 - update_mc_banklinks();
243 - }
244 - }
245 - add_action('wp_login', 'mk_admin_login_update', 10, 2);
157 + return false;
158 +}
246 159
160 +add_filter( 'auto_update_plugin', 'disable_makecommerce_automatic_updates', 99, 2 );
247 161
162 +/**
163 + * The code that runs during plugin activation.
164 + * This action is documented in includes/class-makecommerce-activator.php
165 + *
166 + * @since 3.0.1
167 + */
168 +function activate_makecommerce() {
248 169
249 - function mk_admin_add_api_settings($sections) {
250 - $sections['mk_api'] = __('MakeCommerce API access', 'wc_makecommerce_domain');
251 - return $sections;
252 - }
170 + require_once plugin_dir_path( __FILE__ ) . 'includes/activator.php';
171 + MakeCommerce\Activator::activate();
172 +}
253 173
254 - function mk_admin_api_settings($settings) {
255 - global $current_section;
256 - if ($current_section !== 'mk_api') {
257 - return $settings;
258 - }
259 - return array(
260 - array('type' => 'title', 'desc' => __get_logo_html()),
261 - array(
262 - 'type' => 'title',
263 - 'title' => __('MakeCommerce API access credentials', 'wc_makecommerce_domain'),
264 - '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 - ),
272 - 'id' => 'mk_api_settings'
273 - ),
274 - array(
275 - 'type' => 'select',
276 - 'title' => __('Current environment', 'wc_makecommerce_domain'),
277 - 'desc' => __('See more about <a href="https://maksekeskus.ee/en/for-developers/test-environment/">MakeCommerce Test environment</a>', 'wc_makecommerce_domain'),
278 - 'default' => 'live',
279 - 'options' => array(
280 - 'live' => __('Live', 'wc_makecommerce_domain'),
281 - 'test' => __('Test', 'wc_makecommerce_domain'),
282 - ),
283 - 'id' => 'mk_api_type'
284 - ),
285 - array(
286 - 'id' => 'mk_shop_id',
287 - 'type' => 'text',
288 - 'title' => __('Shop ID (live)', 'wc_makecommerce_domain'),
289 - 'desc' => __('Get it from <a href="https://merchant.maksekeskus.ee/api.html" target="_blank">Merchant Portal</a>','wc_makecommerce_domain'),
290 - 'class' => 'input-text regular-input',
291 - ),
292 - array(
293 - 'id' => 'mk_private_key',
294 - 'type' => 'text',
295 - 'title' => __('Secret key (live)', 'wc_makecommerce_domain'),
296 - 'class' => 'input-text regular-input',
297 - ),
298 - array(
299 - 'id' => 'mk_public_key',
300 - 'type' => 'text',
301 - 'title' => __('Publishable key (live)', 'wc_makecommerce_domain'),
302 - 'class' => 'input-text regular-input',
303 - ),
304 - array(
305 - 'id' => 'mk_test_shop_id',
306 - 'type' => 'text',
307 - 'title' => __('Shop ID (test)', 'wc_makecommerce_domain'),
308 - 'class' => 'input-text regular-input',
309 - 'default' => 'f64b4f20-5ef9-4b7b-a6fa-d623d87f0b9c',
310 - 'desc' => __('Get it from <a href="https://merchant-test.maksekeskus.ee/api.html" target="_blank">Merchant Portal Test</a>','wc_makecommerce_domain'),
311 - ),
312 - array(
313 - 'id' => 'mk_test_private_key',
314 - 'type' => 'text',
315 - 'title' => __('Secret key (test)', 'wc_makecommerce_domain'),
316 - 'default' => 'MPjcVMoRZPAucsTuGK5ZukOlV7BlzgSvXOowJUkk9IFSQPVooRwcVOxzz3mhEpgM',
317 - 'class' => 'input-text regular-input',
318 - ),
319 - array(
320 - 'id' => 'mk_test_public_key',
321 - 'type' => 'text',
322 - 'title' => __('Publishable key (test)', 'wc_makecommerce_domain'),
323 - 'default' => '7Hog41ci2mKkmtviMycWxpNx14pNP70m',
324 - 'class' => 'input-text regular-input',
325 - ),
326 - array(
327 - 'id' => 'mk_experimental_features',
328 - 'type' => 'checkbox',
329 - 'title' => __('Enable experimental features', 'wc_makecommerce_domain'),
330 - 'class' => '',
331 - ),
332 - array(
333 - 'id' => 'mk_javascript_ui',
334 - 'type' => 'api_javascript_ui',
335 - ),
336 - array('type' => 'sectionend', 'id' => 'mk_api_settings')
337 - );
338 - }
339 -
340 - function mk_admin_save_api_settings() {
341 - // reload banklinks
342 - global $current_section;
343 - if ($current_section !== 'mk_api') {
344 - return;
345 - }
346 - update_mc_banklinks();
347 - }
174 +/**
175 + * The code that runs during plugin deactivation.
176 + * This action is documented in includes/class-makecommerce-deactivator.php
177 + *
178 + * @since 3.0.1
179 + */
180 +function deactivate_makecommerce() {
348 181
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;
353 - }
354 - add_filter('woocommerce_get_settings_api', 'mk_admin_api_settings', 10, 2);
355 - add_action('woocommerce_get_sections_api', 'mk_admin_add_api_settings');
356 - add_action('woocommerce_settings_saved', 'mk_admin_save_api_settings', 30, 0);
357 - add_filter("plugin_action_links_".plugin_basename(__FILE__), 'mk_admin_plugin_settings_link' );
182 + require_once plugin_dir_path( __FILE__ ) . 'includes/deactivator.php';
183 + MakeCommerce\Deactivator::deactivate();
184 +}
358 185
359 - function __get_logo_html() {
360 - return '<div class="makecommerce-info">'.
361 - '<div class="makecommerce-logo">'.
362 - '<a target="_blank" href="http://maksekeskus.ee"><img src="'. plugins_url('/images/makecommerce_logo_en.svg', __FILE__) .'" class="makecommerce-logo"></a>'.
363 - '</div>'.
364 - '<div class="makecommerce-links">'.
365 - '<div class="makecommerce-link"><a target="_blank" href="https://merchant.maksekeskus.ee">Merchant Portal</a></div>'.
366 - '<div class="makecommerce-link"><a target="_blank" href="https://makecommerce.net/">makecommerce.net</a></div>'.
367 - '<div class="makecommerce-link"><a target="_blank" href="http://maksekeskus.ee">maksekeskus.ee</a></div>'.
368 - '</div>'.
369 - '</div>';
370 - }
186 +/**
187 + * The core plugin class that is used to define internationalization,
188 + * payment-specific hooks, and shipping-specific site hooks.
189 + */
190 +require plugin_dir_path( __FILE__ ) . 'includes/makecommerce.php';
191 +
192 +/**
193 + * Begins execution of the plugin.
194 + *
195 + * @since 3.0.0
196 + */
197 +function run_makecommerce() {
198 +
199 + $makeCommerce = new MakeCommerce();
200 + $makeCommerce->run();
371 201 }
202 +
203 +run_makecommerce();