PluginProbe
MakeCommerce for WooCommerce / 3.0.2
MakeCommerce for WooCommerce v3.0.2
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.2, at api/api.php

377 lines 12.9 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 /**
62 * Gives error in admin if curl is not loaded
63 */
64 public function check_if_curl_is_loaded() {
65
66 if ( !extension_loaded('curl') ) {
67
68 $class = 'notice notice-error';
69 $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' );
70
71 printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) );
72 }
73 }
74
75 /**
76 * Add menu item to WooCommerce advanced section
77 *
78 * @since 3.0.0
79 */
80 public function add_woo_menu( $sections ) {
81
82 $sections['mk_api'] = __('MakeCommerce API access', 'wc_makecommerce_domain');
83
84 return $sections;
85 }
86
87 /**
88 * Adds new column (payment method) in order view
89 *
90 * @since 3.0.0
91 */
92 public function add_ordersview_paymentmethod_column( $columns ) {
93
94 $columns['makecommerce_payment_method'] = __('Payment method (MC)');
95
96 return $columns;
97 }
98
99 /**
100 * Makes payment method column in order view sortable
101 *
102 * @since 3.0.0
103 */
104 public function make_ordersview_paymentmethod_column_sortable( $columns ) {
105
106 return wp_parse_args (array( 'makecommerce_payment_method' => 'makecommerce_payment_method' ), $columns );
107 }
108
109 /**
110 * Inserts content for payment method column in order view
111 *
112 * @since 3.0.0
113 */
114 public function fill_ordersview_paymentmethod_column( $column, $post_id ) {
115
116 if ( 'makecommerce_payment_method' === $column ) {
117 echo get_post_meta( $post_id, '_makecommerce_preselected_method', true );
118 }
119 }
120
121 /**
122 * Update banklinks when an admin logs in
123 *
124 * @since 3.0.0
125 */
126 public function admin_login( $user_login, $user ) {
127
128 if ( user_can( $user, 'administrator' ) ) {
129 Payment::update_banklinks();
130 }
131 }
132
133 /**
134 * Adds settings link to plugins page
135 *
136 * @since 3.0.0
137 */
138 public function add_plugin_settings_link( $links ) {
139
140 $settings_link = '<a href="admin.php?page=wc-settings&tab=api&section=mk_api">API '.__('Settings').'</a>';
141
142 if ( \MakeCommerce::new_woo_version() ) {
143 $settings_link = '<a href="admin.php?page=wc-settings&tab=advanced&section=mk_api">API '.__('Settings').'</a>';
144 }
145
146 array_unshift( $links, $settings_link );
147
148 return $links;
149 }
150
151 /**
152 * Updates banklinks if current section is not in mk_api
153 *
154 * @since 3.0.0
155 */
156 public function save_settings() {
157
158 global $current_section;
159
160 if ( $current_section !== 'mk_api' ) {
161 return;
162 }
163
164 Payment::update_banklinks();
165 }
166
167 /**
168 * Test and live switching in API settings (jQuery)
169 *
170 * @since 3.0.0
171 */
172 public function api_javascript_ui( $data ) {
173
174 ?>
175 <script type="text/javascript">
176 jQuery(document).ready(function($) {
177
178 var env_select = $('#mk_api_type');
179 var test_fields = ['mk_test_shop_id', 'mk_test_private_key', 'mk_test_public_key'];
180 var live_fields = ['mk_shop_id', 'mk_private_key', 'mk_public_key'];
181
182 env_select.on('change', function(){
183 hideFields($(this).val());
184 });
185
186 hideFields(env_select.val());
187
188 function hideFields(type) {
189 var hide = type == 'live' ? test_fields : live_fields;
190 var show = type == 'live' ? live_fields : test_fields;
191 $.each(hide, function(i, elem) {
192 $('#'+elem).closest('tr').hide();
193 });
194 $.each(show, function(i, elem) {
195 $('#'+elem).closest('tr').show();
196 });
197 }
198 });
199 </script>
200 <?php
201 }
202
203 /**
204 * Add admin settings for api in woocommerce->settings->advanced->Makcommerce API
205 *
206 * @since 3.0.0
207 */
208 public function add_woo_admin_settings( $settings ) {
209
210 /**
211 * Prevent the settings from being loaded if we are not at actually the page
212 */
213 global $current_section;
214
215 if ( $current_section !== 'mk_api' ) {
216 return $settings;
217 }
218
219 /**
220 * Return array with fields for settings
221 */
222 return array(
223 array( 'type' => 'title', 'desc' => \MakeCommerce::get_logo_html() ),
224 array(
225 'type' => 'title',
226 'title' => __('MakeCommerce API access credentials', 'wc_makecommerce_domain'),
227 'desc' => __('To use MakeCommerce/Maksekeskus services you need to enter API credentials below here <br/> <br/>', 'wc_makecommerce_domain').
228 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'),
229 'id' => 'mk_api_settings'
230 ),
231 array(
232 'type' => 'select',
233 'title' => __('Current environment', 'wc_makecommerce_domain'),
234 'desc' => __('See more about <a href="https://maksekeskus.ee/en/for-developers/test-environment/">MakeCommerce Test environment</a>', 'wc_makecommerce_domain'),
235 'default' => 'live',
236 'options' => array(
237 'live' => __('Live', 'wc_makecommerce_domain'),
238 'test' => __('Test', 'wc_makecommerce_domain'),
239 ),
240 'id' => 'mk_api_type'
241 ),
242 array(
243 'id' => 'mk_shop_id',
244 'type' => 'text',
245 'title' => __('Shop ID (live)', 'wc_makecommerce_domain'),
246 'desc' => __('Get it from <a href="https://merchant.maksekeskus.ee/api.html" target="_blank">Merchant Portal</a>','wc_makecommerce_domain'),
247 'class' => 'input-text regular-input',
248 ),
249 array(
250 'id' => 'mk_private_key',
251 'type' => 'text',
252 'title' => __('Secret key (live)', 'wc_makecommerce_domain'),
253 'class' => 'input-text regular-input',
254 ),
255 array(
256 'id' => 'mk_public_key',
257 'type' => 'text',
258 'title' => __('Publishable key (live)', 'wc_makecommerce_domain'),
259 'class' => 'input-text regular-input',
260 ),
261 array(
262 'id' => 'mk_test_shop_id',
263 'type' => 'text',
264 'title' => __('Shop ID (test)', 'wc_makecommerce_domain'),
265 'class' => 'input-text regular-input',
266 'default' => 'f64b4f20-5ef9-4b7b-a6fa-d623d87f0b9c',
267 'desc' => __('Get it from <a href="https://merchant.test.maksekeskus.ee/api.html" target="_blank">Merchant Portal Test</a>','wc_makecommerce_domain'),
268 ),
269 array(
270 'id' => 'mk_test_private_key',
271 'type' => 'text',
272 'title' => __('Secret key (test)', 'wc_makecommerce_domain'),
273 'default' => 'MPjcVMoRZPAucsTuGK5ZukOlV7BlzgSvXOowJUkk9IFSQPVooRwcVOxzz3mhEpgM',
274 'class' => 'input-text regular-input',
275 ),
276 array(
277 'id' => 'mk_test_public_key',
278 'type' => 'text',
279 'title' => __('Publishable key (test)', 'wc_makecommerce_domain'),
280 'default' => '7Hog41ci2mKkmtviMycWxpNx14pNP70m',
281 'class' => 'input-text regular-input',
282 ),
283 array('type' => 'sectionend', 'id' => 'mk_api_settings'),
284 array(
285 'type' => 'title',
286 'desc' => '<br><hr><br>',
287 ),
288 array(
289 'id' => 'mk_module_title',
290 'type' => 'title',
291 'title' => __('Makecommerce modules', 'wc_makecommerce_domain'),
292 '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'),
293 'class' => '',
294 ),
295 array(
296 'id' => 'mk_transport_apt_omniva',
297 'type' => 'checkbox',
298 'default' => 'yes',
299 'title' => __('Omniva Parcel Machine', 'wc_makecommerce_domain'),
300 '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')).')',
301 'class' => '',
302 ),
303 array(
304 'id' => 'mk_transport_apt_smartpost',
305 'type' => 'checkbox',
306 'default' => 'yes',
307 'title' => __('Smartpost Parcel Machine', 'wc_makecommerce_domain'),
308 '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')).')',
309 'class' => '',
310 ),
311 array(
312 'id' => 'mk_transport_apt_dpd',
313 'type' => 'checkbox',
314 'default' => 'no',
315 'title' => __('DPD', 'wc_makecommerce_domain') . ' ' . __('parcel machine', 'wc_makecommerce_domain'),
316 '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')).')',
317 'class' => '',
318 ),
319 array(
320 'id' => 'mk_transport_courier_omniva',
321 'type' => 'checkbox',
322 'default' => 'yes',
323 'title' => __('Omniva Courier', 'wc_makecommerce_domain'),
324 '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')).')',
325 'class' => '',
326 ),
327 array(
328 'id' => 'mk_transport_courier_smartpost',
329 'type' => 'checkbox',
330 'default' => 'yes',
331 'title' => __('Smartpost Courier', 'wc_makecommerce_domain'),
332 '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')).')',
333 'class' => '',
334 ),
335 array(
336 'id' => 'mk_checkout_sco',
337 'type' => 'checkbox',
338 'title' => __('SimpleCheckout', 'wc_makecommerce_domain'),
339 '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')).')',
340 'class' => '',
341 ),
342 array(
343 'id' => 'mk_product_slice',
344 'type' => 'checkbox',
345 'title' => __('Indivy Slice 3 information in product view', 'wc_makecommerce_domain'),
346 'desc' => __('enable Indivy Slice 3 in product view', 'wc_makecommerce_domain'),
347 'class' => '',
348 ),
349 array(
350 'id' => 'mk_javascript_ui',
351 'type' => 'api_javascript_ui',
352 ),
353 array('type' => 'sectionend', 'id' => 'mk_api_settings')
354 );
355 }
356
357 /**
358 * Notice for missing API information
359 *
360 * @since 3.0.0
361 */
362 public function api_info_missing() {
363
364 ?>
365 <div class="notice notice-error is-dismissible">
366 <p>
367 <?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' ); ?>
368 <?php if ( \MakeCommerce::new_woo_version() ) { ?>
369 <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>
370 <?php } else { ?>
371 <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>
372 <?php } ?>
373 </p>
374 </div>
375 <?php
376 }
377 }