PluginProbe
MakeCommerce for WooCommerce / 2.2.6
MakeCommerce for WooCommerce v2.2.6
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 +429 -40 trunk2.2.6 View file →
@@ -1,46 +1,435 @@
1 1 <?php
2 -/**
3 - * @link https://makecommerce.net/
4 - * @since 4.0.0
5 - * @package Makecommerce
6 - *
7 - * @wordpress-plugin
8 - * Plugin Name: MakeCommerce
9 - * Plugin URI: https://makecommerce.net/
10 - * Description: Adds MakeCommerce payment gateway and shipping methods to WooCommerce checkout
11 - * Version: 4.1.0
12 - * Author: Maksekeskus AS
13 - * Author URI: https://makecommerce.net/
14 - * License: GPL-2.0+
15 - * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
16 - * Text Domain: makecommerce
17 - * Domain Path: /languages
18 - * Requires Plugins: woocommerce
19 - * Requires at least: 6.8.1
20 - * Requires PHP: 8.1
21 - * WC requires at least: 9.9.3
22 - * WC tested up to: 11.0.1
23 - * WC HPOS compatibility: yes
24 - * WC Legacy Order Table Compatibility: yes
25 - */
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.2.6
6 + Author: Maksekeskus AS
7 + Author URI: https://MakeCommerce.net/
8 + Text Domain: wc_makecommerce_domain
9 +*/
26 10
27 -function mc_table_exists(string $table): bool {
28 - global $wpdb;
29 - $table_name = $wpdb->prefix . $table;
30 - return $wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $table_name)) === $table_name;
11 +if (!defined('ABSPATH')) {
12 + exit; // Exit if accessed directly.
31 13 }
32 14
15 +include_once(ABSPATH.'wp-admin/includes/plugin.php');
16 +if (is_plugin_active('woocommerce/woocommerce.php')) {
33 17
34 -if (
35 - (
36 - get_option('mc_version') !== false ||
37 - get_option('wc_mc_version') !== false ||
38 - mc_table_exists('mc_banklinks')
39 - ) &&
40 - !filter_var(get_option('mc_shipping_plus'), FILTER_VALIDATE_BOOLEAN)
41 -) {
42 - require_once plugin_dir_path(__FILE__) . 'config.php';
43 -} else {
44 - require_once plugin_dir_path(__FILE__) . 'makecommerce/makecommerce.php';
18 + define('WC_MC_VERSION', 2.0);
19 +
20 + $enable_experimental = get_option('mk_checkout_sco', 'no');
21 + if ($enable_experimental === 'yes') {
22 + require_once(__DIR__.'/makecommerce-simplecheckout.php');
23 + }
24 + require_once(__DIR__.'/makecommerce-transport.php');
25 + require_once(__DIR__.'/makecommerce-payment.php');
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 +
36 + global $mkDbTable;
37 + $mkDbTable = 'mc_banklinks';
38 +
39 + function mc_install() {
40 + global $wpdb;
41 + global $mkDbTable;
42 +
43 + $tableName = $wpdb->prefix . $mkDbTable;
44 +
45 + $charset = $wpdb->get_charset_collate();
46 +
47 + $sql = "CREATE TABLE $tableName (
48 + id mediumint(9) NOT NULL AUTO_INCREMENT,
49 + type varchar(10) NOT NULL,
50 + country char(2) NOT NULL,
51 + name varchar(25) NOT NULL,
52 + url varchar(250) NOT NULL,
53 + UNIQUE KEY id (id)
54 + ) $charset;";
55 +
56 + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
57 + dbDelta( $sql );
58 + }
59 +
60 + register_activation_hook( __FILE__, 'mc_install' );
61 +
62 + // On uninstall remove scheduled hook
63 + function mc_uninstall() {
64 + if (wp_next_scheduled ( 'mc_banklinks_update_cron' )) {
65 + wp_clear_scheduled_hook('mc_banklinks_update_cron');
66 + }
67 + }
68 +
69 + register_deactivation_hook(__FILE__, 'mc_uninstall');
70 +
71 + // WP schedule callable action
72 + add_action('mc_banklinks_update_cron', 'update_mc_banklinks');
73 + // Assign schedule if not set, update compatible no need to reactivate, format('U') php 5.2 compatible
74 + // Assigns task at 23.59.59 by local time, task runs if time has passed and somebody navigates the site
75 + if (! wp_next_scheduled ( 'mc_banklinks_update_cron' )) {
76 + $date = new DateTime();
77 + $date->setTime(04,10,00);
78 + $timestamp = intval($date->format('U'));
79 + //$local = 3600 * intval(get_option('gmt_offset'));
80 + //wp_schedule_event($timestamp - $local, 'twicedaily', 'mc_banklinks_update_cron');
81 + wp_schedule_event($timestamp, 'twicedaily', 'mc_banklinks_update_cron');
82 + }
83 +
84 + if (!class_exists('wc_makecommerce_domain')) {
85 + require_once('includes/vendor/autoload.php');
86 + require_once('includes/Maksekeskus.php');
87 + }
88 +
89 + function mk_check_payment() {
90 +
91 + global $woocommerce;
92 + $api = mk_get_api();
93 +
94 + $returnUrl = home_url();
95 +
96 + $request = stripslashes_deep($_POST);
97 + if ($api->verifyMac($request)) {
98 + $data = $api->extractRequestData($request);
99 + $reference = false;
100 +
101 + if (!empty($data['error']) ) {
102 + wc_add_notice(__('Payment failed', 'wc_makecommerce_domain'), 'error');
103 + return $returnUrl;
104 + }
105 +
106 + if (!empty($data['message_type']) ) {
107 + if ($data['message_type'] == 'payment_return') {
108 + $transactionId = $data['transaction'];
109 + $reference = $data['reference'];
110 + $paymentStatus = $data['status'];
111 + }
112 + if ($data['message_type'] == 'token_return') {
113 + if (!empty($data['transaction']['reference'])) {
114 + $reference = $data['transaction']['reference'];
115 + }
116 + $paymentStatus = $data['transaction']['status'];
117 + $transactionId = $data['transaction']['id'];
118 +
119 + // for API backward compatibility - if we didn't find reference in the mesage, or the transaction state vas still PENDING
120 + // we'll fetch the transaction data from API, and make a payment request if needed
121 + // this all can be removed after 2017-jan
122 + if (!$reference or $paymentStatus == 'PENDING') {
123 + $transaction = $api->getTransaction($transactionId);
124 + if (!empty($transaction->reference)) {
125 + $reference = $transaction->reference;
126 + }
127 +
128 + $paymentStatus = $transaction->status;
129 +
130 + if ($paymentStatus == 'PENDING') {
131 + $paymentRequest = array(
132 + 'amount' => $transaction->amount,
133 + 'currency' => $transaction->currency,
134 + 'token' => $data['token']['id']
135 + );
136 + $payment = $api->createPayment($transactionId, $paymentRequest);
137 + // TODO: validate
138 + $paymentStatus = $payment->transaction->status;
139 + }
140 +
141 + }
142 +
143 +
144 + }
145 +
146 + }
147 + }
148 +
149 + // if we didn't find reference to an Order, we send user to shop landing-page. TODO: could be improved
150 + if (!$reference) { return $returnUrl; }
151 +
152 + $order = new WC_Order($reference);
153 + // if we din't find the Order, we send user to shop landing-page. TODO: could be improved
154 + if (!$order->get_order_number()) { return $returnUrl; }
155 +
156 + $returnUrl = $order->get_checkout_order_received_url();
157 +
158 + switch($paymentStatus) {
159 +
160 + case 'CANCELLED':
161 + $order->update_status( 'cancelled' );
162 + wc_add_notice(__('Payment transaction cancelled', 'wc_makecommerce_domain'), 'error');
163 + $returnUrl = $woocommerce->cart->get_cart_url();
164 + break;
165 +
166 + case 'COMPLETED':
167 + $orderNote = array();
168 + $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->get_order_number(), '_makecommerce_preselected_method', true);
170 + $order->add_order_note(implode("\r\n", $orderNote));
171 +
172 + $order->payment_complete( $transactionId );
173 + $order->update_status( 'processing' );
174 + $woocommerce->cart->empty_cart();
175 + break;
176 +
177 + }
178 +
179 + return $returnUrl;
180 + }
181 +
182 +
183 +
184 +
185 + $MKAPI = false;
186 + function mk_get_api() {
187 + global $MKAPI;
188 + if ($MKAPI) {
189 + //return $MKAPI;
190 + }
191 + $mk_api_type = get_option('mk_api_type', false);
192 + if (!$mk_api_type) {
193 + return false;
194 + }
195 + if ($mk_api_type !== 'live') {
196 + $key_prefix = $mk_api_type.'_';
197 + } else {
198 + $key_prefix = '';
199 + }
200 + $mk_shop_id = get_option('mk_'.$key_prefix.'shop_id', '');
201 + $mk_public_key = get_option('mk_'.$key_prefix.'public_key', '');
202 + $mk_private_key = get_option('mk_'.$key_prefix.'private_key', '');
203 + if (!$mk_shop_id || !$mk_public_key || !$mk_shop_id) {
204 + return false;
205 + }
206 + $MKAPI = new \Maksekeskus\Maksekeskus($mk_shop_id, $mk_public_key, $mk_private_key, $mk_api_type === 'live' ? false : true);
207 + return $MKAPI;
208 + }
209 +
210 + function mk_is_api_set() {
211 + $mk_api_type = get_option('mk_api_type', false);
212 + if (!$mk_api_type) {
213 + return false;
214 + }
215 + if ($mk_api_type !== 'live') {
216 + $key_prefix = $mk_api_type.'_';
217 + } else {
218 + $key_prefix = '';
219 + }
220 + $mk_shop_id = get_option('mk_'.$key_prefix.'shop_id', '');
221 + $mk_public_key = get_option('mk_'.$key_prefix.'public_key', '');
222 + $mk_private_key = get_option('mk_'.$key_prefix.'private_key', '');
223 + if (!$mk_shop_id || !$mk_public_key || !$mk_shop_id) {
224 + return false;
225 + }
226 + return true;
227 + }
228 +
229 +
230 + function mk_admin_error() {
231 + 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'));
232 + }
233 +
234 +
235 +
236 + add_filter('query_vars', 'mk_cron_query_vars');
237 + add_action('parse_request', 'mk_parse_cron_update_vars');
238 +
239 + function mk_cron_query_vars($vars) {
240 + $vars[] = 'mk-action';
241 + $vars[] = 'mk-shop-id';
242 + $vars[] = 'mk-test-shop-id';
243 + return $vars;
244 + }
245 +
246 + function mk_parse_cron_update_vars($wp) {
247 + if (array_key_exists('mk-action', $wp->query_vars) && $wp->query_vars['mk-action'] == 'mk-update'
248 + && (array_key_exists('mk-shop-id', $wp->query_vars) || array_key_exists('mk-test-shop-id', $wp->query_vars) ) ) {
249 + if( (strlen($wp->query_vars['mk-shop-id']) && $wp->query_vars['mk-shop-id'] == get_option('mk_shop_id', false) )
250 + || (strlen($wp->query_vars['mk-test-shop-id']) && $wp->query_vars['mk-test-shop-id'] == get_option('mk_test_shop_id', false) ) ) {
251 + update_mc_banklinks();
252 + exit();
253 + }
254 + }
255 + }
256 +
257 + function mk_admin_login_update($user_login, $user) {
258 + if(user_can( $user, 'administrator' )) {
259 + update_mc_banklinks();
260 + }
261 + }
262 + add_action('wp_login', 'mk_admin_login_update', 10, 2);
263 +
264 +
265 +
266 + function mk_admin_add_api_settings($sections) {
267 + $sections['mk_api'] = __('MakeCommerce API access', 'wc_makecommerce_domain');
268 + return $sections;
269 + }
270 +
271 + function mk_admin_api_settings($settings) {
272 + global $current_section;
273 + if ($current_section !== 'mk_api') {
274 + return $settings;
275 + }
276 + return array(
277 + array('type' => 'title', 'desc' => __get_logo_html()),
278 + array(
279 + 'type' => 'title',
280 + 'title' => __('MakeCommerce API access credentials', 'wc_makecommerce_domain'),
281 + 'desc' => __('To use MakeCommerce/Maksekeskus services you need to enter API credentials below here <br/> <br/>', 'wc_makecommerce_domain').
282 + 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'),
283 + 'id' => 'mk_api_settings'
284 + ),
285 + array(
286 + 'type' => 'select',
287 + 'title' => __('Current environment', 'wc_makecommerce_domain'),
288 + 'desc' => __('See more about <a href="https://maksekeskus.ee/en/for-developers/test-environment/">MakeCommerce Test environment</a>', 'wc_makecommerce_domain'),
289 + 'default' => 'live',
290 + 'options' => array(
291 + 'live' => __('Live', 'wc_makecommerce_domain'),
292 + 'test' => __('Test', 'wc_makecommerce_domain'),
293 + ),
294 + 'id' => 'mk_api_type'
295 + ),
296 + array(
297 + 'id' => 'mk_shop_id',
298 + 'type' => 'text',
299 + 'title' => __('Shop ID (live)', 'wc_makecommerce_domain'),
300 + 'desc' => __('Get it from <a href="https://merchant.maksekeskus.ee/api.html" target="_blank">Merchant Portal</a>','wc_makecommerce_domain'),
301 + 'class' => 'input-text regular-input',
302 + ),
303 + array(
304 + 'id' => 'mk_private_key',
305 + 'type' => 'text',
306 + 'title' => __('Secret key (live)', 'wc_makecommerce_domain'),
307 + 'class' => 'input-text regular-input',
308 + ),
309 + array(
310 + 'id' => 'mk_public_key',
311 + 'type' => 'text',
312 + 'title' => __('Publishable key (live)', 'wc_makecommerce_domain'),
313 + 'class' => 'input-text regular-input',
314 + ),
315 + array(
316 + 'id' => 'mk_test_shop_id',
317 + 'type' => 'text',
318 + 'title' => __('Shop ID (test)', 'wc_makecommerce_domain'),
319 + 'class' => 'input-text regular-input',
320 + 'default' => 'f64b4f20-5ef9-4b7b-a6fa-d623d87f0b9c',
321 + 'desc' => __('Get it from <a href="https://merchant-test.maksekeskus.ee/api.html" target="_blank">Merchant Portal Test</a>','wc_makecommerce_domain'),
322 + ),
323 + array(
324 + 'id' => 'mk_test_private_key',
325 + 'type' => 'text',
326 + 'title' => __('Secret key (test)', 'wc_makecommerce_domain'),
327 + 'default' => 'MPjcVMoRZPAucsTuGK5ZukOlV7BlzgSvXOowJUkk9IFSQPVooRwcVOxzz3mhEpgM',
328 + 'class' => 'input-text regular-input',
329 + ),
330 + array(
331 + 'id' => 'mk_test_public_key',
332 + 'type' => 'text',
333 + 'title' => __('Publishable key (test)', 'wc_makecommerce_domain'),
334 + 'default' => '7Hog41ci2mKkmtviMycWxpNx14pNP70m',
335 + 'class' => 'input-text regular-input',
336 + ),
337 + array('type' => 'sectionend', 'id' => 'mk_api_settings'),
338 + array(
339 + 'type' => 'title',
340 + 'desc' => '<br><hr><br>',
341 + ),
342 + array(
343 + 'id' => 'mk_module_title',
344 + 'type' => 'title',
345 + 'title' => __('Makecommerce modules', 'wc_makecommerce_domain'),
346 + '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'),
347 + 'class' => '',
348 + ),
349 + array(
350 + 'id' => 'mk_transport_apt_omniva',
351 + 'type' => 'checkbox',
352 + 'default' => 'yes',
353 + 'title' => __('Omniva Parcel Machine', 'wc_makecommerce_domain'),
354 + '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')).')',
355 + 'class' => '',
356 + ),
357 + array(
358 + 'id' => 'mk_transport_apt_smartpost',
359 + 'type' => 'checkbox',
360 + 'default' => 'yes',
361 + 'title' => __('SmartPOST Parcel Machine', 'wc_makecommerce_domain'),
362 + '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')).')',
363 + 'class' => '',
364 + ),
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&section=parcelmachine_dpd')).')',
371 + // 'class' => '',
372 + // ),
373 + array(
374 + 'id' => 'mk_transport_courier_omniva',
375 + 'type' => 'checkbox',
376 + 'default' => 'yes',
377 + 'title' => __('Omniva Courier', 'wc_makecommerce_domain'),
378 + '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')).')',
379 + 'class' => '',
380 + ),
381 + array(
382 + 'id' => 'mk_transport_courier_smartpost',
383 + 'type' => 'checkbox',
384 + 'default' => 'yes',
385 + 'title' => __('SmartPOST Courier', 'wc_makecommerce_domain'),
386 + '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')).')',
387 + 'class' => '',
388 + ),
389 + array(
390 + 'id' => 'mk_checkout_sco',
391 + 'type' => 'checkbox',
392 + 'title' => __('SimpleCheckout', 'wc_makecommerce_domain'),
393 + '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')).')',
394 + 'class' => '',
395 + ),
396 + array(
397 + 'id' => 'mk_javascript_ui',
398 + 'type' => 'api_javascript_ui',
399 + ),
400 + array('type' => 'sectionend', 'id' => 'mk_api_settings')
401 + );
402 + }
403 +
404 + function mk_admin_save_api_settings() {
405 + // reload banklinks
406 + global $current_section;
407 + if ($current_section !== 'mk_api') {
408 + return;
409 + }
410 + update_mc_banklinks();
411 + }
412 +
413 + function mk_admin_plugin_settings_link($links) {
414 + $settings_link = '<a href="admin.php?page=wc-settings&tab=api&section=mk_api">API '.__('Settings').'</a>';
415 + array_unshift($links, $settings_link);
416 + return $links;
417 + }
418 + add_filter('woocommerce_get_settings_api', 'mk_admin_api_settings', 10, 2);
419 + add_action('woocommerce_get_sections_api', 'mk_admin_add_api_settings');
420 + add_action('woocommerce_settings_saved', 'mk_admin_save_api_settings', 30, 0);
421 + add_filter("plugin_action_links_".plugin_basename(__FILE__), 'mk_admin_plugin_settings_link' );
422 +
423 + function __get_logo_html() {
424 + return '<div class="makecommerce-info">'.
425 + '<div class="makecommerce-logo">'.
426 + '<a target="_blank" href="http://maksekeskus.ee"><img src="'. plugins_url('/images/makecommerce_logo_en.svg', __FILE__) .'" class="makecommerce-logo"></a>'.
427 + '</div>'.
428 + '<div class="makecommerce-links">'.
429 + '<div class="makecommerce-link"><a target="_blank" href="https://merchant.maksekeskus.ee">Merchant Portal</a></div>'.
430 + '<div class="makecommerce-link"><a target="_blank" href="https://makecommerce.net/">makecommerce.net</a></div>'.
431 + '<div class="makecommerce-link"><a target="_blank" href="http://maksekeskus.ee">maksekeskus.ee</a></div>'.
432 + '</div>'.
433 + '</div>';
434 + }
45 435 }
46 -