register_routes();
}
add_action( 'plugins_loaded', 'woocommerce_revolut_init', 0 );
/**
* Set up Revolut plugin links
*
* @param array $links Revolut plugin link.
*
* @return array
*/
function woocommerce_revolut_plugin_links( $links ) {
$settings_url = add_query_arg(
array(
'page' => 'wc-settings',
'tab' => 'checkout',
'section' => 'revolut',
),
admin_url( 'admin.php' )
);
$plugin_links = array(
'' . __( 'Settings', 'revolut-gateway-for-woocommerce' ) . '',
'' . __( 'Support', 'revolut-gateway-for-woocommerce' ) . '',
'' . __( 'Docs', 'revolut-gateway-for-woocommerce' ) . '',
);
return array_merge( $plugin_links, $links );
}
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'woocommerce_revolut_plugin_links' );
/**
* Add Revolut payment gateways
*
* @param String $gateways Revolut Payment Gateways.
*
* @return mixed
*/
function woocommerce_revolut_add_gateways( $gateways ) {
return array_merge( $gateways, woocommerce_revolut_payment_gateways() );
}
/**
* Get Revolut payment gateway list.
*/
function woocommerce_revolut_payment_gateways() {
return array(
'WC_Gateway_Revolut_CC',
'WC_Gateway_Revolut_Pay',
'WC_Gateway_Revolut_Payment_Request',
);
}
/**
* Create table to save Revolut Order
*/
register_activation_hook( __FILE__, 'woocommerce_revolut_install' );
/**
* Install plugin tables.
*
* @param bool $network_wide if the plugin is being network-activated.
*/
function woocommerce_revolut_install( $network_wide ) {
global $wpdb;
// Check if the plugin is being network-activated or not.
if ( $network_wide ) {
// Retrieve all site IDs from this network (WordPress >= 4.6 provides easy to use functions for that).
if ( function_exists( 'get_sites' ) && function_exists( 'get_current_network_id' ) ) {
$site_ids = get_sites(
array(
'fields' => 'ids',
'network_id' => get_current_network_id(),
)
);
} else {
$site_ids = $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE site_id = %s;", array( $wpdb->siteid ) ) ); // db call ok; no-cache ok.
}
// Install the plugin for all these sites.
foreach ( $site_ids as $site_id ) {
switch_to_blog( $site_id );
woocommerce_revolut_install_single_site();
restore_current_blog();
}
} else {
woocommerce_revolut_install_single_site();
}
}
/**
* Install plugin tables for single site.
*/
function woocommerce_revolut_install_single_site() {
global $wpdb;
$charset_collate = $wpdb->get_charset_collate();
$orders_table_name = $wpdb->prefix . 'wc_revolut_orders';
$temp_session_name = $wpdb->prefix . 'wc_revolut_temp_session';
$customer_table_name = $wpdb->prefix . 'wc_revolut_customer';
try {
$orders_table_sql = "CREATE TABLE IF NOT EXISTS $orders_table_name (
order_id BINARY(16) NOT NULL,
public_id BINARY(16) NOT NULL UNIQUE,
wc_order_id INTEGER NULL UNIQUE,
PRIMARY KEY (order_id)
) $charset_collate;";
$temp_session_table_sql = "CREATE TABLE IF NOT EXISTS $temp_session_name (
order_id VARCHAR (150) NOT NULL UNIQUE,
temp_session TEXT,
INDEX (order_id)
) $charset_collate;";
$customers_table_sql = "CREATE TABLE IF NOT EXISTS $customer_table_name (
wc_customer_id INTEGER NOT NULL UNIQUE,
revolut_customer_id VARCHAR (50) NOT NULL UNIQUE,
PRIMARY KEY (wc_customer_id)
) $charset_collate;";
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
dbDelta( $orders_table_sql );
dbDelta( $temp_session_table_sql );
dbDelta( $customers_table_sql );
// update plugin version on DB.
update_option( 'WC_GATEWAY_REVOLUT_VERSION', WC_GATEWAY_REVOLUT_VERSION );
} catch ( Exception $exception ) {
if ( defined( 'WP_DEBUG' ) && WP_DEBUG === true ) {
// phpcs:disable WordPress.PHP.DevelopmentFunctions
error_log( $exception->getMessage() );
// phpcs:enable
}
}
}
/**
* Add script to setup Webhook using ajax
*/
function woocommerce_revolut_load_admin_scripts() {
wp_register_script( 'revolut-settings', plugins_url( 'assets/js/revolut-setting.js', WC_REVOLUT_MAIN_FILE ), array(), WC_GATEWAY_REVOLUT_VERSION, false );
wp_localize_script(
'revolut-settings',
'default_options',
array(
'default_bg_color' => WC_REVOLUT_CARD_WIDGET_BG_COLOR,
'default_text_color' => WC_REVOLUT_CARD_WIDGET_TEXT_COLOR,
)
);
wp_enqueue_script( 'revolut-settings' );
}