PluginProbe
MakeCommerce for WooCommerce / 3.0.4
MakeCommerce for WooCommerce v3.0.4
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
makecommerce / api / api.php

api.php in MakeCommerce for WooCommerce 3.0.4, at api/api.php

402 lines 13.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The api functionality of the plugin.
5 *
6 * @link https://makecommerce.net/
7 * @since 3.0.0
8 *
9 * @package Makecommerce
10 * @subpackage Makecommerce/api
11 */
12
13 namespace MakeCommerce;
14
15 /**
16 * The payment functionality of the plugin.
17 *
18 * Defines the plugin name, version, and two examples hooks for how to
19 * enqueue the admin-specific stylesheet and JavaScript.
20 *
21 * @package Makecommerce
22 * @subpackage Makecommerce/api
23 * @author Maksekeskus AS <support@maksekeskus.ee>
24 */
25 class API {
26
27 /**
28 * The ID of this plugin.
29 *
30 * @since 3.0.0
31 * @access private
32 * @var string $plugin_name The ID of this plugin.
33 */
34 private $plugin_name;
35
36 /**
37 * The version of this plugin.
38 *
39 * @since 3.0.0
40 * @access private
41 * @var string $version The current version of this plugin.
42 */
43 private $version;
44
45 private Loader $loader;
46
47 /**
48 * Initialize the class and set its properties.
49 *
50 * @since 3.0.0
51 * @param string $plugin_name The name of this plugin.
52 * @param string $version The version of this plugin.
53 */
54 public function __construct( $plugin_name, $version, Loader $loader ) {
55
56 $this->plugin_name = $plugin_name;
57 $this->version = $version;
58 $this->loader = $loader;
59 }
60
61 public function label_formats() {
62
63 $MK = \MakeCommerce::get_api();
64
65 if ( !$MK ) {
66 return array( 'A4' => 'A4' );
67 }
68
69 $formats = $MK->getLabelFormats();
70 $optionsArray = array();
71 foreach ( $formats as $format ) {
72 $optionsArray[$format] = $format;
73 }
74
75 return $optionsArray;
76 }
77
78 /**
79 * Gives error in admin if curl is not loaded
80 */
81 public function check_if_curl_is_loaded() {
82
83 if ( !extension_loaded('curl') ) {
84
85 $class = 'notice notice-error';
86 $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' );
87
88 printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) );
89 }
90 }
91
92 /**
93 * Add menu item to WooCommerce advanced section
94 *
95 * @since 3.0.0
96 */
97 public function add_woo_menu( $sections ) {
98
99 $sections['mk_api'] = __('MakeCommerce API access', 'wc_makecommerce_domain');
100
101 return $sections;
102 }
103
104 /**
105 * Adds new column (payment method) in order view
106 *
107 * @since 3.0.0
108 */
109 public function add_ordersview_paymentmethod_column( $columns ) {
110
111 $columns['makecommerce_payment_method'] = __('Payment method (MC)');
112
113 return $columns;
114 }
115
116 /**
117 * Makes payment method column in order view sortable
118 *
119 * @since 3.0.0
120 */
121 public function make_ordersview_paymentmethod_column_sortable( $columns ) {
122
123 return wp_parse_args (array( 'makecommerce_payment_method' => 'makecommerce_payment_method' ), $columns );
124 }
125
126 /**
127 * Inserts content for payment method column in order view
128 *
129 * @since 3.0.0
130 */
131 public function fill_ordersview_paymentmethod_column( $column, $post_id ) {
132
133 if ( 'makecommerce_payment_method' === $column ) {
134 echo get_post_meta( $post_id, '_makecommerce_preselected_method', true );
135 }
136 }
137
138 /**
139 * Update banklinks when an admin logs in
140 *
141 * @since 3.0.0
142 */
143 public function admin_login( $user_login, $user ) {
144
145 if ( user_can( $user, 'administrator' ) ) {
146 Payment::update_banklinks();
147 }
148 }
149
150 /**
151 * Adds settings link to plugins page
152 *
153 * @since 3.0.0
154 */
155 public function add_plugin_settings_link( $links ) {
156
157 $settings_link = '<a href="admin.php?page=wc-settings&tab=api&section=mk_api">API '.__('Settings').'</a>';
158
159 if ( \MakeCommerce::new_woo_version() ) {
160 $settings_link = '<a href="admin.php?page=wc-settings&tab=advanced&section=mk_api">API '.__('Settings').'</a>';
161 }
162
163 array_unshift( $links, $settings_link );
164
165 return $links;
166 }
167
168 /**
169 * Updates banklinks if current section is not in mk_api
170 *
171 * @since 3.0.0
172 */
173 public function save_settings() {
174
175 global $current_section;
176
177 if ( $current_section !== 'mk_api' ) {
178 return;
179 }
180
181 Payment::update_banklinks();
182 }
183
184 /**
185 * Test and live switching in API settings (jQuery)
186 *
187 * @since 3.0.0
188 */
189 public function api_javascript_ui( $data ) {
190
191 ?>
192 <script type="text/javascript">
193 jQuery(document).ready(function($) {
194
195 var env_select = $('#mk_api_type');
196 var test_fields = ['mk_test_shop_id', 'mk_test_private_key', 'mk_test_public_key'];
197 var live_fields = ['mk_shop_id', 'mk_private_key', 'mk_public_key'];
198
199 env_select.on('change', function(){
200 hideFields($(this).val());
201 });
202
203 hideFields(env_select.val());
204
205 function hideFields(type) {
206 var hide = type == 'live' ? test_fields : live_fields;
207 var show = type == 'live' ? live_fields : test_fields;
208 $.each(hide, function(i, elem) {
209 $('#'+elem).closest('tr').hide();
210 });
211 $.each(show, function(i, elem) {
212 $('#'+elem).closest('tr').show();
213 });
214 }
215 });
216 </script>
217 <?php
218 }
219
220 /**
221 * Add admin settings for api in woocommerce->settings->advanced->Makcommerce API
222 *
223 * @since 3.0.0
224 */
225 public function add_woo_admin_settings( $settings ) {
226
227 /**
228 * Prevent the settings from being loaded if we are not at actually the page
229 */
230 global $current_section;
231
232 if ( $current_section !== 'mk_api' ) {
233 return $settings;
234 }
235
236 /**
237 * Return array with fields for settings
238 */
239 return array(
240 array( 'type' => 'title', 'desc' => \MakeCommerce::get_logo_html() ),
241 array(
242 'type' => 'title',
243 'title' => __('MakeCommerce API access credentials', 'wc_makecommerce_domain'),
244 'desc' => __('To use MakeCommerce/Maksekeskus services you need to enter API credentials below here <br/> <br/>', 'wc_makecommerce_domain').
245 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'),
246 'id' => 'mk_api_settings'
247 ),
248 array(
249 'type' => 'select',
250 'title' => __('Current environment', 'wc_makecommerce_domain'),
251 'desc' => __('See more about <a href="https://maksekeskus.ee/en/for-developers/test-environment/">MakeCommerce Test environment</a>', 'wc_makecommerce_domain'),
252 'default' => 'live',
253 'options' => array(
254 'live' => __('Live', 'wc_makecommerce_domain'),
255 'test' => __('Test', 'wc_makecommerce_domain'),
256 ),
257 'id' => 'mk_api_type'
258 ),
259 array(
260 'id' => 'mk_shop_id',
261 'type' => 'text',
262 'title' => __('Shop ID (live)', 'wc_makecommerce_domain'),
263 'desc' => __('Get it from <a href="https://merchant.maksekeskus.ee/api.html" target="_blank">Merchant Portal</a>','wc_makecommerce_domain'),
264 'class' => 'input-text regular-input',
265 ),
266 array(
267 'id' => 'mk_private_key',
268 'type' => 'text',
269 'title' => __('Secret key (live)', 'wc_makecommerce_domain'),
270 'class' => 'input-text regular-input',
271 ),
272 array(
273 'id' => 'mk_public_key',
274 'type' => 'text',
275 'title' => __('Publishable key (live)', 'wc_makecommerce_domain'),
276 'class' => 'input-text regular-input',
277 ),
278 array(
279 'id' => 'mk_test_shop_id',
280 'type' => 'text',
281 'title' => __('Shop ID (test)', 'wc_makecommerce_domain'),
282 'class' => 'input-text regular-input',
283 'default' => 'f64b4f20-5ef9-4b7b-a6fa-d623d87f0b9c',
284 'desc' => __('Get it from <a href="https://merchant.test.maksekeskus.ee/api.html" target="_blank">Merchant Portal Test</a>','wc_makecommerce_domain'),
285 ),
286 array(
287 'id' => 'mk_test_private_key',
288 'type' => 'text',
289 'title' => __('Secret key (test)', 'wc_makecommerce_domain'),
290 'default' => 'MPjcVMoRZPAucsTuGK5ZukOlV7BlzgSvXOowJUkk9IFSQPVooRwcVOxzz3mhEpgM',
291 'class' => 'input-text regular-input',
292 ),
293 array(
294 'id' => 'mk_test_public_key',
295 'type' => 'text',
296 'title' => __('Publishable key (test)', 'wc_makecommerce_domain'),
297 'default' => '7Hog41ci2mKkmtviMycWxpNx14pNP70m',
298 'class' => 'input-text regular-input',
299 ),
300 array(
301 'type' => 'select',
302 'title' => __('Label print format', 'wc_makecommerce_domain'),
303 'desc' => __('In which format should shipping labels be printed. (*make sure you have API access to see more options)', 'wc_makecommerce_domain'),
304 'default' => 'A4',
305 'options' => $this->label_formats(),
306 'id' => 'mk_label_format'
307 ),
308 array('type' => 'sectionend', 'id' => 'mk_api_settings'),
309 array(
310 'type' => 'title',
311 'desc' => '<br><hr><br>',
312 ),
313 array(
314 'id' => 'mk_module_title',
315 'type' => 'title',
316 'title' => __('Makecommerce modules', 'wc_makecommerce_domain'),
317 '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'),
318 'class' => '',
319 ),
320 array(
321 'id' => 'mk_transport_apt_omniva',
322 'type' => 'checkbox',
323 'default' => 'yes',
324 'title' => __('Omniva Parcel Machine', 'wc_makecommerce_domain'),
325 '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')).')',
326 'class' => '',
327 ),
328 array(
329 'id' => 'mk_transport_apt_smartpost',
330 'type' => 'checkbox',
331 'default' => 'yes',
332 'title' => __('Smartpost Parcel Machine', 'wc_makecommerce_domain'),
333 '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')).')',
334 'class' => '',
335 ),
336 array(
337 'id' => 'mk_transport_apt_dpd',
338 'type' => 'checkbox',
339 'default' => 'no',
340 'title' => __('DPD', 'wc_makecommerce_domain') . ' ' . __('parcel machine', 'wc_makecommerce_domain'),
341 'desc' => __('enable DPD parcel machine 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')).')',
342 'class' => '',
343 ),
344 array(
345 'id' => 'mk_transport_courier_omniva',
346 'type' => 'checkbox',
347 'default' => 'yes',
348 'title' => __('Omniva Courier', 'wc_makecommerce_domain'),
349 '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')).')',
350 'class' => '',
351 ),
352 array(
353 'id' => 'mk_transport_courier_smartpost',
354 'type' => 'checkbox',
355 'default' => 'yes',
356 'title' => __('Smartpost Courier', 'wc_makecommerce_domain'),
357 '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')).')',
358 'class' => '',
359 ),
360 array(
361 'id' => 'mk_checkout_sco',
362 'type' => 'checkbox',
363 'title' => __('SimpleCheckout', 'wc_makecommerce_domain'),
364 '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')).')',
365 'class' => '',
366 ),
367 array(
368 'id' => 'mk_product_slice',
369 'type' => 'checkbox',
370 'title' => __('Indivy Slice 3 information in product view', 'wc_makecommerce_domain'),
371 'desc' => __('enable Indivy Slice 3 in product view', 'wc_makecommerce_domain'),
372 'class' => '',
373 ),
374 array(
375 'id' => 'mk_javascript_ui',
376 'type' => 'api_javascript_ui',
377 ),
378 array('type' => 'sectionend', 'id' => 'mk_api_settings')
379 );
380 }
381
382 /**
383 * Notice for missing API information
384 *
385 * @since 3.0.0
386 */
387 public function api_info_missing() {
388
389 ?>
390 <div class="notice notice-error is-dismissible">
391 <p>
392 <?php echo __( 'You have not entered the Shop ID and keys for the MakeCommerce payment module. The module will not work without them.', 'wc_makecommerce_domain' ); ?>
393 <?php if ( \MakeCommerce::new_woo_version() ) { ?>
394 <a href="<?php echo admin_url( 'admin.php?page=wc-settings&tab=advanced&section=mk_api' ); ?>"><?php echo __( 'Click here to enter them', 'wc_makecommerce_domain' ); ?></a>
395 <?php } else { ?>
396 <a href="<?php echo admin_url( 'admin.php?page=wc-settings&tab=api&section=mk_api' ); ?>"><?php echo __( 'Click here to enter them', 'wc_makecommerce_domain' ); ?></a>
397 <?php } ?>
398 </p>
399 </div>
400 <?php
401 }
402 }