banklinks_update(); if ( $force ) { $this->methods->load_methods(); return $updated; } if ( $updated ) { wp_send_json( array( 'success' => 1, 'data' => __( 'Update successfully completed!', 'wc_makecommerce_domain' ) ) ); exit; } wp_send_json( array( 'success' => 0, 'data' => __( 'There was an error with your update. Please try again.', 'wc_makecommerce_domain' ) ) ); exit; } die(); } /** * Updates banklinks database and db structure if needed * * @since 3.0.9 */ public function banklinks_update() { global $wp_version; global $wpdb; if ( !$this->MK ) { return false; } try { $shopConfig = $this->MK->getShopConfig( \MakeCommerce::config_request_parameters( $this->id.' '.$this->version ) ); $methods = $shopConfig->paymentMethods; } catch ( \Exception $e ) { error_log( print_r( $e, 1 ) ); return false; } $tableName = $wpdb->prefix . MAKECOMMERCE_TABLENAME; $sql = "SELECT COUNT(*) AS `isLogoUrlSet` FROM `information_schema`.`columns` WHERE `table_name`='".$tableName."' AND `column_name`='logo_url'"; $methodstruct = $wpdb->get_results( $sql ); if ( $methodstruct[0]->isLogoUrlSet == 0 ) { $wpdb->query( 'ALTER TABLE '.$tableName.' ADD COLUMN `logo_url` varchar(250)' ); } $sql = "SELECT COUNT(*) AS `min_amount` FROM `information_schema`.`columns` WHERE `table_name`='".$tableName."' AND `column_name`='min_amount'"; $methodstruct = $wpdb->get_results( $sql ); if ( $methodstruct[0]->min_amount == 0 ) { $wpdb->query( 'ALTER TABLE '.$tableName.' ADD COLUMN `min_amount` mediumint(9) default 0' ); } $sql = "SELECT COUNT(*) AS `max_amount` FROM `information_schema`.`columns` WHERE `table_name`='".$tableName."' AND `column_name`='max_amount'"; $methodstruct = $wpdb->get_results( $sql ); if ( $methodstruct[0]->max_amount == 0 ) { $wpdb->query( 'ALTER TABLE '.$tableName.' ADD COLUMN `max_amount` mediumint(9) default 0' ); } $sql = "SELECT COUNT(*) AS `display_name` FROM `information_schema`.`columns` WHERE `table_name`='".$tableName."' AND `column_name`='display_name'"; $methodstruct = $wpdb->get_results( $sql ); if ( $methodstruct[0]->display_name == 0 ) { $wpdb->query( 'ALTER TABLE '.$tableName.' ADD COLUMN `display_name` varchar(250)' ); } $sql = "SELECT COUNT(*) AS `channel` FROM `information_schema`.`columns` WHERE `table_name`='".$tableName."' AND `column_name`='channel'"; $methodstruct = $wpdb->get_results( $sql ); if ( $methodstruct[0]->channel == 0 ) { $wpdb->query( 'ALTER TABLE '.$tableName.' ADD COLUMN `channel` varchar(250)' ); } $wpdb->query( 'TRUNCATE TABLE `'.$tableName.'`' ); if ( isset( $methods->banklinks ) ) { foreach( $methods->banklinks as $method ) { $wpdb->insert( $tableName, array( 'type' => 'banklink', 'country' => $method->country, 'name' => $method->name, 'url' => $method->url, 'logo_url' => $method->logo_url, 'channel' => $method->channel, 'display_name' => $method->display_name ) ); } $updated = true; } if ( isset( $methods->cards ) ) { foreach( $methods->cards as $method ) { $wpdb->insert( $tableName, array( 'type' => 'card', 'name' => $method->name, 'logo_url' => $method->logo_url, 'channel' => $method->channel, 'display_name' => $method->display_name ) ); } $updated = true; } if ( isset( $methods->other ) ) { foreach( $methods->other as $method ) { $wpdb->insert( $tableName, array( 'type' => 'other', 'country' => $method->country, 'name' => $method->name, 'url' => $method->url, 'logo_url' => $method->logo_url, 'channel' => $method->channel, 'display_name' => $method->display_name ) ); } $updated = true; } if ( isset( $methods->payLater ) ) { foreach( $methods->payLater as $method ) { //not all payLater accounts have a max_amount parameter. Set them to NULL to avoid notice's if ( !isset( $method->max_amount ) ) { $method->max_amount = NULL; } $wpdb->insert( $tableName, array( 'type' => 'payLater', 'country' => $method->country, 'name' => $method->name, 'url' => $method->url, 'logo_url' => $method->logo_url, 'min_amount' => $method->min_amount, 'max_amount' => $method->max_amount, 'channel' => $method->channel, 'display_name' => $method->display_name ) ); } $updated = true; } if ( isset( $shopConfig ) && strlen( $shopConfig->name ) ) { update_option( 'mc_shop_name', $shopConfig->name ); } if ( $updated ) { update_option( 'mc_banklinks_api_type', get_option( 'mk_api_type', false) ); } return $updated; } /** * Creates banklinks reload button * * @since 3.0.0 */ public function generate_mc_banklinks_reload_html( $key, $data ) { $field = $this->get_field_key( $key ); $defaults = array( 'title' => '', 'disabled' => false, 'class' => '', 'css' => '', 'placeholder' => '', 'type' => 'text', 'desc_tip' => false, 'description' => '', 'custom_attributes' => array() ); $data = wp_parse_args( $data, $defaults ); \MakeCommerce::mc_enqueue_script( 'MC_BANKLINKS_RELOAD', dirname( __FILE__ ) . '/js/mc_banklinks_reload.js', [ 'site_url' => get_site_url(), 'error' => __( 'There was an error with your update. Please try again.', 'wc_makecommerce_domain' ) ], [ 'jquery' ] ); ob_start(); ?>