/**
  * Method that processes the subscription params
  *
  * @param   mixed   $params   array of parameters from $_POST
  *
  * @return  void
  */
 private function process_subscription($params)
 {
     $email_split = explode("@", $_POST['sendgrid_mc_email']);
     if (isset($email_split[1])) {
         $email_domain = $email_split[1];
         try {
             $Punycode = new Punycode();
             $email_domain = $Punycode->decode($email_split[1]);
         } catch (Exception $e) {
         }
         $email = $email_split[0] . '@' . $email_domain;
     } else {
         $email = $_POST['sendgrid_mc_email'];
     }
     // Bad call
     if (!isset($email) or !Sendgrid_Tools::is_valid_email($email)) {
         return self::INVALID_EMAIL_ERROR;
     }
     if ('true' == Sendgrid_Tools::get_mc_opt_req_fname_lname() and 'true' == Sendgrid_Tools::get_mc_opt_incl_fname_lname()) {
         if (!isset($_POST['sendgrid_mc_first_name']) or empty($_POST['sendgrid_mc_first_name'])) {
             return self::ERROR_EMAIL_SEND;
         }
         if (!isset($_POST['sendgrid_mc_last_name']) or empty($_POST['sendgrid_mc_last_name'])) {
             return self::ERROR_EMAIL_SEND;
         }
     }
     if (isset($_POST['sendgrid_mc_first_name']) and isset($_POST['sendgrid_mc_last_name'])) {
         Sendgrid_OptIn_API_Endpoint::send_confirmation_email($email, $_POST['sendgrid_mc_first_name'], $_POST['sendgrid_mc_last_name']);
     } else {
         Sendgrid_OptIn_API_Endpoint::send_confirmation_email($email);
     }
     return self::SUCCESS_EMAIL_SEND;
 }
 /**
  * Uploads a contact using the parameters specified in the settings page
  *
  * @param  mixed   $params    array of parameters from $_POST
  *
  * @return mixed              response array with message and status
  */
 private static function send_contact_upload_test($params)
 {
     $email = $params['sendgrid_test_email'];
     if (!Sendgrid_Tools::is_valid_email($email)) {
         return array('message' => 'Email address provided is invalid.', 'status' => 'error', 'error_type' => 'upload');
     }
     switch (Sendgrid_Tools::get_auth_method()) {
         case 'apikey':
             $apikey = Sendgrid_Tools::get_api_key();
             if (!Sendgrid_Tools::check_api_key($apikey, true)) {
                 return array('message' => 'API Key used for mail send is invalid or without permissions.', 'status' => 'error', 'error_type' => 'upload');
             }
             break;
         case 'credentials':
             $username = Sendgrid_Tools::get_username();
             $password = Sendgrid_Tools::get_password();
             if (!Sendgrid_Tools::check_username_password($params['sendgrid_username'], $params['sendgrid_password'], true)) {
                 return array('message' => 'Credentials used for mail send are invalid.', 'status' => 'error', 'error_type' => 'upload');
             }
             break;
         default:
             return array('message' => 'An error occured when trying to check your transactional credentials. Please check that they are correct on the General Settings tab.', 'status' => 'error', 'error_type' => 'upload');
     }
     if (false == Sendgrid_OptIn_API_Endpoint::send_confirmation_email($email, '', '', true)) {
         return array('message' => 'An error occured when trying send the subscription email. Please make sure you have configured all settings properly.', 'status' => 'error', 'error_type' => 'upload');
     }
     return array('message' => 'Subscription confirmation email was sent.', 'status' => 'updated');
 }