/**
  * @since   1.2.0
  * @param type $posted
  * @return type
  */
 public static function ofw_constantcontact_handler($posted)
 {
     if (!isset($posted) || empty($posted)) {
         return;
     }
     $debug = get_option('ofw_log_enable_constant_contact') == 'yes' ? 'yes' : 'no';
     if ('yes' == $debug) {
         require_once 'class-offers-for-woocommerce-logger.php';
         $log = new Angelleye_Offers_For_Woocommerce_Logger();
     }
     $concontact_api_key = get_option('ofw_constantcontact_api_key');
     $constantcontact_access_token = get_option('ofw_constantcontact_access_token');
     $cclistsid = get_option('ofw_constantcontact_lists');
     $first_name = isset($posted['offer_name']) ? $posted['offer_name'] : '';
     $last_name = '';
     $offer_email = isset($posted['offer_email']) ? $posted['offer_email'] : '';
     if (isset($concontact_api_key) && !empty($concontact_api_key) && (isset($constantcontact_access_token) && !empty($constantcontact_access_token))) {
         $ConstantContact = new ConstantContact($concontact_api_key);
         $response = $ConstantContact->getContactByEmail($constantcontact_access_token, $offer_email);
         if (empty($response->results)) {
             $Contact = new Contact();
             $Contact->addEmail($offer_email);
             $Contact->first_name = $first_name;
             $Contact->last_name = $last_name;
             $Contact->addList($cclistsid);
             $NewContact = $ConstantContact->addContact($constantcontact_access_token, $Contact, false);
             if ('yes' == $debug) {
                 $log->add('ConstantContact', 'ConstantContact new contact ' . $offer_email . ' added to selected contact list');
             }
         } else {
             $Contact = $response->results[0];
             $Contact->first_name = $first_name;
             $Contact->last_name = $last_name;
             $Contact->addList($cclistsid);
             $new_contact = $ConstantContact->updateContact($constantcontact_access_token, $Contact, false);
             $log->add('ConstantContact', 'ConstantContact update contact ' . $offer_email . ' to selected contact list');
         }
     } else {
         if ('yes' == $debug) {
             $log->add('ConstantContact', 'Constant Contact API Key OR Constant Contact Access Token does not set');
         }
     }
 }
 /**
  *  @since    1.2.0
  *  Get List from MailChimp
  */
 public function angelleye_get_ofw_mailchimp_lists($apikey)
 {
     $mailchimp_lists = array();
     $enable_mailchimp = get_option('ofw_enable_mailchimp');
     if (isset($enable_mailchimp) && $enable_mailchimp == 'yes') {
         $mailchimp_lists = unserialize(get_transient('ofw_mailchimp_mailinglist'));
         $mailchimp_debug_log = get_option('ofw_log_enable_mailchimp') == 'yes' ? 'yes' : 'no';
         if ('yes' == $mailchimp_debug_log) {
             if (!class_exists('Angelleye_Offers_For_Woocommerce_Logger')) {
                 include_once OFFERS_FOR_WOOCOMMERCE_PLUGIN_DIR . '/includes/class-offers-for-woocommerce-logger.php';
             }
             $log = new Angelleye_Offers_For_Woocommerce_Logger();
         }
         if (empty($mailchimp_lists) || get_option('ofw_mailchimp_force_refresh') == 'yes') {
             include_once 'class-offers-for-woocommerce-mailchimp-mcapi.php';
             $mailchimp_api_key = get_option('ofw_mailchimp_api_key');
             $apikey = isset($mailchimp_api_key) ? $mailchimp_api_key : '';
             $api = new AngellEYE_Offers_for_Woocommerce_MailChimp_MCAPI($apikey);
             $retval = $api->lists();
             if ($api->errorCode) {
                 unset($mailchimp_lists);
                 $mailchimp_lists['false'] = __("Unable to load MailChimp lists, check your API Key.", 'doation-button');
                 if ('yes' == $mailchimp_debug_log) {
                     $log->add('MailChimp', 'Unable to load MailChimp lists, check your API Key.');
                 }
             } else {
                 unset($mailchimp_lists);
                 if ($retval['total'] == 0) {
                     if ('yes' == $mailchimp_debug_log) {
                         $log->add('MailChimp', 'You have not created any lists at MailChimp.');
                     }
                     $mailchimp_lists['false'] = __("You have not created any lists at MailChimp", 'doation-button');
                     return $mailchimp_lists;
                 }
                 foreach ($retval['data'] as $list) {
                     $mailchimp_lists[$list['id']] = $list['name'];
                 }
                 if ('yes' == $mailchimp_debug_log) {
                     $log->add('MailChimp', 'MailChimp Get List Success..');
                 }
                 set_transient('ofw_mailchimp_mailinglist', serialize($mailchimp_lists), 86400);
                 update_option('ofw_mailchimp_force_refresh', 'no');
             }
         }
     }
     return $mailchimp_lists;
 }
 /**
  * @since    1.2.0
  *  Get List from MailPoet
  */
 public function angelleye_get_ofw_mailpoet_lists()
 {
     $mailpoet_lists_array = array();
     $enable_mailpoet = get_option('ofw_enable_mailpoet');
     $mailpoet_lists_array = unserialize(get_transient('ofw_mailpoet_mailinglist'));
     if (empty($mailpoet_lists_array) || get_option('ofw_mailpoet_force_refresh') == 'yes') {
         if (!class_exists('WYSIJA')) {
             return;
         }
         unset($mailpoet_lists_array);
         $mailpoet_debug_log = get_option('ofw_log_enable_mailpoet') == 'yes' ? 'yes' : 'no';
         if ('yes' == $mailpoet_debug_log) {
             if (!class_exists('Angelleye_Offers_For_Woocommerce_Logger')) {
                 include_once OFFERS_FOR_WOOCOMMERCE_PLUGIN_DIR . '/includes/class-offers-for-woocommerce-logger.php';
             }
             $log = new Angelleye_Offers_For_Woocommerce_Logger();
         }
         // get MailPoet / Wysija lists
         $model_list = WYSIJA::get('list', 'model');
         $mailpoet_lists = $model_list->get(array('name', 'list_id'), array('is_enabled' => 1));
         foreach ($mailpoet_lists as $list) {
             $mailpoet_lists_array[$list['list_id']] = $list['name'];
         }
         if ('yes' == $mailpoet_debug_log) {
             $log->add('MailPoet', 'MailPoet Get List Success..');
         }
         set_transient('ofw_mailpoet_mailinglist', serialize($mailpoet_lists_array), 86400);
         update_option('ofw_mailpoet_force_refresh', 'no');
     }
     return $mailpoet_lists_array;
 }