*/
class API {
/**
* The ID of this plugin.
*
* @since 3.0.0
* @access private
* @var string $plugin_name The ID of this plugin.
*/
private $plugin_name;
/**
* The version of this plugin.
*
* @since 3.0.0
* @access private
* @var string $version The current version of this plugin.
*/
private $version;
private Loader $loader;
/**
* Initialize the class and set its properties.
*
* @since 3.0.0
* @param string $plugin_name The name of this plugin.
* @param string $version The version of this plugin.
*/
public function __construct( $plugin_name, $version, Loader $loader ) {
$this->plugin_name = $plugin_name;
$this->version = $version;
$this->loader = $loader;
}
public function label_formats() {
$MK = \MakeCommerce::get_api();
if ( !$MK ) {
return array( 'A4' => 'A4' );
}
$optionsArray = array();
try {
$formats = $MK->getLabelFormats();
foreach ( $formats as $format ) {
$optionsArray[$format] = $format;
}
} catch ( \Exception $e ) {
//do nothing, something is wrong with the credentials or the shop is disabled
}
return $optionsArray;
}
/**
* Gives error in admin if curl is not loaded
*/
public function check_if_curl_is_loaded() {
if ( !extension_loaded('curl') ) {
$class = 'notice notice-error';
$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' );
printf( '
', esc_attr( $class ), esc_html( $message ) );
}
}
/**
* Add menu item to WooCommerce advanced section
*
* @since 3.0.0
*/
public function add_woo_menu( $sections ) {
$sections['mk_api'] = __('MakeCommerce API access', 'wc_makecommerce_domain');
return $sections;
}
/**
* Adds new column (payment method) in order view
*
* @since 3.0.0
*/
public function add_ordersview_paymentmethod_column( $columns ) {
$columns['makecommerce_payment_method'] = __('Payment method (MC)');
return $columns;
}
/**
* Makes payment method column in order view sortable
*
* @since 3.0.0
*/
public function make_ordersview_paymentmethod_column_sortable( $columns ) {
return wp_parse_args (array( 'makecommerce_payment_method' => 'makecommerce_payment_method' ), $columns );
}
/**
* Inserts content for payment method column in order view
*
* @since 3.0.0
*/
public function fill_ordersview_paymentmethod_column( $column, $post_id ) {
if ( 'makecommerce_payment_method' === $column ) {
echo get_post_meta( $post_id, '_makecommerce_preselected_method', true );
}
}
/**
* Update banklinks when an admin logs in
*
* @since 3.0.0
*/
public function admin_login( $user_login, $user ) {
if ( user_can( $user, 'administrator' ) ) {
Payment::update_banklinks();
}
}
/**
* Adds settings link to plugins page
*
* @since 3.0.0
*/
public function add_plugin_settings_link( $links ) {
$settings_link = 'API '.__('Settings').'';
if ( \MakeCommerce::new_woo_version() ) {
$settings_link = 'API '.__('Settings').'';
}
array_unshift( $links, $settings_link );
return $links;
}
/**
* Updates banklinks if current section is not in mk_api
*
* @since 3.0.0
*/
public function save_settings() {
global $current_section;
if ( $current_section !== 'mk_api' ) {
return;
}
Payment::update_banklinks();
}
/**
* Test and live switching in API settings (jQuery)
*
* @since 3.0.0
*/
public function api_javascript_ui( $data ) {
?>
settings->advanced->Makcommerce API
*
* @since 3.0.0
*/
public function add_woo_admin_settings( $settings ) {
/**
* Prevent the settings from being loaded if we are not at actually the page
*/
global $current_section;
if ( $current_section !== 'mk_api' ) {
return $settings;
}
/**
* Return array with fields for settings
*/
return array(
array( 'type' => 'title', 'desc' => \MakeCommerce::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' => 'select',
'title' => __('Label print format', 'wc_makecommerce_domain'),
'desc' => __('In which format should shipping labels be printed. (*make sure you have API access to see more options)', 'wc_makecommerce_domain'),
'default' => 'A4',
'options' => $this->label_formats(),
'id' => 'mk_label_format'
),
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')
);
}
/**
* Notice for missing API information
*
* @since 3.0.0
*/
public function api_info_missing() {
?>