/**
 * initialise plugin once other plugins are loaded
 */
function em_gateway_stripe_token_register()
{
    //check that EM Pro is installed
    if (!defined('EMP_VERSION')) {
        add_action('admin_notices', 'em_pro_prereq');
        return false;
        //don't load plugin further
    }
    if (class_exists('EM_Gateways')) {
        require_once plugin_dir_path(__FILE__) . 'em-gateway-stripe-token.php';
        EM_Gateways::register_gateway('em_pro_stripe_token', 'EM_Gateway_Stripe_Token');
    }
}
	/**
	* handle init action
	*/
	public function init() {
		// register with Events Manager
		if (class_exists('EM_Gateways')) {
			require EWAY_PAYMENTS_PLUGIN_ROOT . 'includes/integrations/class.EwayPaymentsEventsManager.php';
			EM_Gateways::register_gateway('eway', 'EwayPaymentsEventsManager');
		}

		// register with Another WordPress Classifieds Plugin
		if (isset($GLOBALS['awpcp'])) {
			require EWAY_PAYMENTS_PLUGIN_ROOT . 'includes/integrations/class.EwayPaymentsAWPCP.php';
			new EwayPaymentsAWPCP();
		}
	}
function mycred_load_events_manager()
{
    if (!defined('EM_VERSION')) {
        return;
    }
    // Pro
    if (class_exists('EM_Pro') && class_exists('EM_Gateways')) {
        require_once myCRED_GATE_EVENT_DIR . 'mycred-eventsmanager-pro.php';
        EM_Gateways::register_gateway('mycred', 'EM_Gateway_myCRED');
    } else {
        require_once myCRED_GATE_EVENT_DIR . 'mycred-eventsmanager.php';
        $events = new myCRED_Events_Manager_Gateway();
        $events->load();
    }
}
 function emp_register_gateway($gateway, $class)
 {
     EM_Gateways::register_gateway($gateway, $class);
 }
            update_option('em_' . $key, stripslashes($option));
        }
        //default action is to return true
        return true;
    }
    /**
     * Load Custom js for gateway admin
     */
    function gateway_admin_js($hook)
    {
        if ($hook == 'event_page_events-manager-gateways') {
            wp_enqueue_script('netbanx_gateway_admin', plugin_dir_url(__FILE__) . '/gateway.paypal-chained-payments-admin.js');
        }
    }
}
EM_Gateways::register_gateway('paypal_chained', 'EM_Gateway_Paypal_Chained');
/**
 * Deletes bookings pending payment that are more than x minutes old, defined by paypal options.
 */
function em_gateway_paypal_chained_booking_timeout()
{
    global $wpdb;
    //Get a time from when to delete
    $minutes_to_subtract = absint(get_option('em_paypal_booking_timeout'));
    if ($minutes_to_subtract > 0) {
        //get booking IDs without pending transactions
        $cut_off_time = date('Y-m-d H:i:s', current_time('timestamp') - $minutes_to_subtract * 60);
        $booking_ids = $wpdb->get_col('SELECT b.booking_id FROM ' . EM_BOOKINGS_TABLE . ' b LEFT JOIN ' . EM_TRANSACTIONS_TABLE . " t ON t.booking_id=b.booking_id  WHERE booking_date < '{$cut_off_time}' AND booking_status=4 AND transaction_id IS NULL");
        if (count($booking_ids) > 0) {
            //first delete ticket_bookings with expired bookings
            $sql = "DELETE FROM " . EM_TICKETS_BOOKINGS_TABLE . " WHERE booking_id IN (" . implode(',', $booking_ids) . ");";
    }
    /* 
     * Run when saving PayPal settings, saves the settings available in EM_Gateway_Paypal::mysettings()
     */
    function update()
    {
        parent::update();
        $gateway_options = array($this->gateway . "_email" => $_REQUEST[$this->gateway . '_email'], $this->gateway . "_site" => $_REQUEST[$this->gateway . '_site'], $this->gateway . "_currency" => $_REQUEST['currency'], $this->gateway . "_inc_tax" => $_REQUEST['em_' . $this->gateway . '_inc_tax'], $this->gateway . "_lc" => $_REQUEST[$this->gateway . '_lc'], $this->gateway . "_status" => $_REQUEST[$this->gateway . '_status'], $this->gateway . "_format_logo" => $_REQUEST[$this->gateway . '_format_logo'], $this->gateway . "_format_border" => $_REQUEST[$this->gateway . '_format_border'], $this->gateway . "_manual_approval" => $_REQUEST[$this->gateway . '_manual_approval'], $this->gateway . "_booking_feedback" => wp_kses_data($_REQUEST[$this->gateway . '_booking_feedback']), $this->gateway . "_booking_feedback_free" => wp_kses_data($_REQUEST[$this->gateway . '_booking_feedback_free']), $this->gateway . "_booking_feedback_thanks" => wp_kses_data($_REQUEST[$this->gateway . '_booking_feedback_thanks']), $this->gateway . "_booking_timeout" => $_REQUEST[$this->gateway . '_booking_timeout'], $this->gateway . "_return" => $_REQUEST[$this->gateway . '_return'], $this->gateway . "_cancel_return" => $_REQUEST[$this->gateway . '_cancel_return']);
        foreach ($gateway_options as $key => $option) {
            update_option('em_' . $key, stripslashes($option));
        }
        //default action is to return true
        return true;
    }
}
EM_Gateways::register_gateway('paypal', 'EM_Gateway_Paypal');
/**
 * Deletes bookings pending payment that are more than x minutes old, defined by paypal options. 
 */
function em_gateway_paypal_booking_timeout()
{
    global $wpdb;
    //Get a time from when to delete
    $minutes_to_subtract = absint(get_option('em_paypal_booking_timeout'));
    if ($minutes_to_subtract > 0) {
        //get booking IDs without pending transactions
        $cut_off_time = date('Y-m-d H:i:s', current_time('timestamp') - $minutes_to_subtract * 60);
        $booking_ids = $wpdb->get_col('SELECT b.booking_id FROM ' . EM_BOOKINGS_TABLE . ' b LEFT JOIN ' . EM_TRANSACTIONS_TABLE . " t ON t.booking_id=b.booking_id  WHERE booking_date < '{$cut_off_time}' AND booking_status=4 AND transaction_id IS NULL AND booking_meta LIKE '%s:7:\"gateway\";s:6:\"paypal\";%'");
        if (count($booking_ids) > 0) {
            //first delete ticket_bookings with expired bookings
            foreach ($booking_ids as $booking_id) {
 /><br />
			  	<em><?php 
        _e('By default, when someone pays for a booking, it gets automatically approved once the payment is confirmed. If you would like to manually verify and approve bookings, tick this box.', 'em-pro');
        ?>
</em><br />
			  	<em><?php 
        echo sprintf(__('Approvals must also be required for all bookings in your <a href="%s">settings</a> for this to work properly.', 'em-pro'), EM_ADMIN_URL . '&amp;page=events-manager-options');
        ?>
</em>
			  </td>
		  </tr>
		</tbody>
		</table>
		<?php 
    }
    /* 
     * Run when saving settings, saves the settings available in EM_Gateway_Authorize_AIM::mysettings()
     */
    function update()
    {
        parent::update();
        $gateway_options = array($this->gateway . "_mode" => $_REQUEST['mode'], $this->gateway . "_api_user" => $_REQUEST['api_user'], $this->gateway . "_api_key" => $_REQUEST['api_key'], $this->gateway . "_user_login" => $_REQUEST['user_login'], $this->gateway . "_email_customer" => $_REQUEST['email_customer'], $this->gateway . "_header_email_receipt" => $_REQUEST['header_email_receipt'], $this->gateway . "_footer_email_receipt" => $_REQUEST['footer_email_receipt'], $this->gateway . "_md5_hash" => $_REQUEST['md5_hash'], $this->gateway . "_manual_approval" => $_REQUEST['manual_approval'], $this->gateway . "_booking_feedback" => wp_kses_data($_REQUEST['booking_feedback']), $this->gateway . "_booking_feedback_free" => wp_kses_data($_REQUEST['booking_feedback_free']));
        foreach ($gateway_options as $key => $option) {
            update_option('em_' . $key, stripslashes($option));
        }
        //default action is to return true
        return true;
    }
}
EM_Gateways::register_gateway('authorize_aim', 'EM_Gateway_Authorize_AIM');
         $gateway_options[] = 'em_' . $this->gateway . '_booking_timeout';
         $gateway_options[] = 'em_' . $this->gateway . '_return';
         $gateway_options[] = 'em_' . $this->gateway . '_cancel_return';
         //add wp_kses filters for relevant options and merge in
         $options_wpkses[] = 'em_' . $this->gateway . '_booking_feedback';
         $options_wpkses[] = 'em_' . $this->gateway . '_booking_feedback_free';
         $options_wpkses[] = 'em_' . $this->gateway . '_booking_feedback_completed';
         foreach ($options_wpkses as $option_wpkses) {
             add_filter('gateway_update_' . $option_wpkses, 'wp_kses_post');
         }
         $gateway_options = array_merge($gateway_options, $options_wpkses);
         //pass options to parent which handles saving
         return parent::update($gateway_options);
     }
 }
 EM_Gateways::register_gateway('migs', 'EM_Gateway_Migs');
 /**
  * Deletes bookings pending payment that are more than x minutes old, defined by migs options. 
  */
 function em_gateway_migs_booking_timeout()
 {
     global $wpdb;
     //Get a time from when to delete
     $minutes_to_subtract = absint(get_option('em_migs_booking_timeout'));
     if ($minutes_to_subtract > 0) {
         //get booking IDs without pending transactions
         $cut_off_time = date('Y-m-d H:i:s', current_time('timestamp') - $minutes_to_subtract * 60);
         $booking_ids = $wpdb->get_col('SELECT b.booking_id FROM ' . EM_BOOKINGS_TABLE . ' b LEFT JOIN ' . EM_TRANSACTIONS_TABLE . " t ON t.booking_id=b.booking_id  WHERE booking_date < '{$cut_off_time}' AND booking_status=4 AND transaction_id IS NULL AND booking_meta LIKE '%s:7:\"gateway\";s:6:\"migs\";%'");
         if (count($booking_ids) > 0) {
             //first delete ticket_bookings with expired bookings
             foreach ($booking_ids as $booking_id) {
			  <td>
			  	<input type="text" name="offline_booking_feedback" value="<?php 
        esc_attr_e(get_option('em_' . $this->gateway . "_booking_feedback"));
        ?>
" style='width: 40em;' /><br />
			  	<em><?php 
        _e('The message that is shown to a user when a booking with offline payments is successful.', 'em-pro');
        ?>
</em>
			  </td>
		  </tr>
		</tbody>
		</table>
		<?php 
    }
    /* 
     * Run when saving PayPal settings, saves the settings available in EM_Gateway_Paypal::mysettings()
     */
    function update()
    {
        parent::update();
        $gateway_options = array($this->gateway . "_button" => $_REQUEST['offline_button'], $this->gateway . "_form" => $_REQUEST['offline_form'], $this->gateway . "_booking_feedback" => $_REQUEST['offline_booking_feedback']);
        foreach ($gateway_options as $key => $option) {
            update_option('em_' . $key, stripslashes($option));
        }
        //default action is to return true
        return true;
    }
}
EM_Gateways::register_gateway('offline', 'EM_Gateway_Offline');