/**
  * Saves the Marketing Campaigns parameters sent from the settings page
  *
  * @param  mixed   $params    array of parameters from $_POST
  *
  * @return mixed              response array with message and status
  */
 private static function save_mc_settings($params)
 {
     // Use Transactional Option
     $use_transactional_key = false;
     if (!defined('SENDGRID_MC_OPT_USE_TRANSACTIONAL')) {
         if (isset($params['sendgrid_mc_use_transactional'])) {
             $use_transactional_key = true;
             Sendgrid_Tools::set_mc_opt_use_transactional('true');
         } else {
             Sendgrid_Tools::set_mc_opt_use_transactional('false');
         }
     } else {
         $use_transactional_key = 'true' == SENDGRID_MC_OPT_USE_TRANSACTIONAL ? true : false;
     }
     // If Use Transactional Is Set and auth is not through credentials, check the API key for MC scopes.
     if ($use_transactional_key and 'apikey' == Sendgrid_Tools::get_auth_method()) {
         $apikey = Sendgrid_Tools::get_api_key();
         if (false == $apikey or empty($apikey)) {
             $response = array('message' => 'API Key is empty.', 'status' => 'error');
             return $response;
         }
         if (!Sendgrid_Tools::check_api_key_mc($apikey)) {
             $response = array('message' => 'API Key is invalid or without permissions.', 'status' => 'error');
             return $response;
         }
     }
     if (false == $use_transactional_key and !defined('SENDGRID_MC_API_KEY')) {
         // MC API Key was set empty on purpose
         if (!isset($params['sendgrid_mc_apikey']) or empty($params['sendgrid_mc_apikey'])) {
             $response = array('message' => 'API Key is empty.', 'status' => 'error');
             Sendgrid_Tools::set_mc_api_key('');
         } else {
             // MC API Key was set, check scopes and save if correct
             $apikey = $params['sendgrid_mc_apikey'];
             if (!Sendgrid_Tools::check_api_key_mc($apikey)) {
                 $response = array('message' => 'API Key is invalid or without permissions.', 'status' => 'error');
             } else {
                 Sendgrid_Tools::set_mc_api_key($apikey);
             }
         }
     }
     if (!defined('SENDGRID_MC_OPT_INCL_FNAME_LNAME')) {
         if (isset($params['sendgrid_mc_incl_fname_lname'])) {
             Sendgrid_Tools::set_mc_opt_incl_fname_lname('true');
         } else {
             Sendgrid_Tools::set_mc_opt_incl_fname_lname('false');
         }
     }
     if (!defined('SENDGRID_MC_OPT_REQ_FNAME_LNAME')) {
         if (isset($params['sendgrid_mc_req_fname_lname'])) {
             Sendgrid_Tools::set_mc_opt_req_fname_lname('true');
         } else {
             Sendgrid_Tools::set_mc_opt_req_fname_lname('false');
         }
     }
     if (isset($params['sendgrid_mc_contact_list']) and !defined('SENDGRID_MC_LIST_ID')) {
         Sendgrid_Tools::set_mc_list_id($params['sendgrid_mc_contact_list']);
     }
     if (!defined('SENDGRID_MC_SIGNUP_EMAIL_SUBJECT')) {
         if (!isset($params['sendgrid_mc_email_subject']) or empty($params['sendgrid_mc_email_subject'])) {
             $response = array('message' => 'Signup email subject cannot be empty.', 'status' => 'error');
         } else {
             Sendgrid_Tools::set_mc_signup_email_subject($params['sendgrid_mc_email_subject']);
         }
     }
     if (!defined('SENDGRID_MC_SIGNUP_EMAIL_CONTENT')) {
         if (!isset($params['sendgrid_mc_email_content']) or empty($params['sendgrid_mc_email_content'])) {
             $response = array('message' => 'Signup email content cannot be empty.', 'status' => 'error');
         } else {
             Sendgrid_Tools::set_mc_signup_email_content($params['sendgrid_mc_email_content']);
         }
     }
     if (!defined('SENDGRID_MC_SIGNUP_EMAIL_CONTENT_TEXT')) {
         if (!isset($params['sendgrid_mc_email_content_text']) or empty($params['sendgrid_mc_email_content_text'])) {
             $response = array('message' => 'Signup email content plain/text cannot be empty.', 'status' => 'error');
         } else {
             Sendgrid_Tools::set_mc_signup_email_content_text($params['sendgrid_mc_email_content_text']);
         }
     }
     if (isset($params['sendgrid_mc_signup_page']) and !defined('SENDGRID_MC_SIGNUP_CONFIRMATION_PAGE')) {
         Sendgrid_Tools::set_mc_signup_confirmation_page($params['sendgrid_mc_signup_page']);
     }
     if (isset($response) and $response['status'] == 'error') {
         return $response;
     }
     return array('message' => 'Options are saved.', 'status' => 'updated');
 }