示例#1
0
 public function __construct()
 {
     global $woocommerce;
     $this->id = 'infusionsoft';
     $this->icon == apply_filters('woocommerce_infusionsoft_icon', plugins_url('infusionsoft.png', __FILE__));
     $this->has_fields = true;
     $this->method_title = __('Infusionsoft', 'woocommerce');
     $this->api_connected = true;
     // Load the form fields.
     $this->init_form_fields();
     // Load the settings.
     $this->init_settings();
     //print_r($this->settings);
     // Define user set variables
     $this->title = $this->settings['title'];
     $this->cards = $this->settings['cards'] ? $this->settings['cards'] : "VISA\nMASTERCARD";
     $this->description = $this->settings['description'];
     $this->debug = $this->settings['debug'];
     $this->debug_email = $this->settings['debug_email'];
     $this->thanks_message = $this->settings['thanks_message'];
     $this->is_application_name = $this->settings['is_application_name'];
     //defaults to empty
     $this->is_api_key = $this->settings['is_api_key'];
     //defaults to empty
     $this->is_merchant_id = $this->settings['is_merchant_id'];
     //defaults to empty
     $this->test_mode = $this->settings['test_mode'];
     //defaults to empty
     $this->api_info = '';
     //defaults to empty
     $this->api_connected = 0;
     if ($this->is_application_name && $this->is_api_key) {
         //api connection check
         include_once plugin_dir_path(__FILE__) . 'isdk.php';
         $infusionApp = new iSDK();
         $response = $infusionApp->cfgCon($this->is_application_name, $this->is_api_key);
         $response2 = $infusionApp->getInventory(1);
         //a random request. We want to catch the error not the result so the query itself doesn't matter
         if (!is_array($response2) && in_array(substr($response2, 0, 8), array('ERROR: 2', 'ERROR: 8'))) {
             $this->api_connected = 0;
         } else {
             $this->api_connected = 1;
         }
         //end api connection check
     }
     if ($this->is_application_name && $this->is_api_key) {
         $api_info = 'InfusionsoftApp:' . $this->is_application_name . ':i:' . $this->is_api_key . ':This is the API key for ' . $this->is_application_name . '.infusionsoft.com.';
         $this->api_info = $api_info;
     }
     $this->feedback_message = '';
     // Actions
     if (version_compare(WOOCOMMERCE_VERSION, '2.0', '<')) {
         // Pre 2.0
         add_action('woocommerce_update_options_payment_gateways', array(&$this, 'process_admin_options'));
     } else {
         // 2.0
         add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
     }
     add_action('woocommerce_thankyou_' . $this->id, array(&$this, 'thankyou_page'));
     // Logs
     if ($this->debug == 'yes') {
         $this->log = $woocommerce->logger();
     }
     if (!$this->is_valid_for_use()) {
         $this->enabled = false;
     }
 }