public static function donation_button_constant_contact_handler($posted)
 {
     $cc_list_id = get_option("donation_button_constantcontact_lists");
     $cc_api_key = get_option("constantcontact_api_key");
     $access_token = get_option("constantcontact_access_token");
     $fname = isset($posted['first_name']) ? $posted['first_name'] : '';
     $lname = isset($posted['last_name']) ? $posted['last_name'] : '';
     $email = isset($posted['payer_email']) ? $posted['payer_email'] : $posted['receiver_email'];
     $debug = get_option('log_enable_constant_contact') == 'yes' ? 'yes' : 'no';
     if ('yes' == $debug) {
         $log = new Donation_Button_Logger();
     }
     if (isset($cc_api_key) && !empty($cc_api_key) && (isset($access_token) && !empty($access_token)) && (isset($cc_list_id) && !empty($cc_list_id))) {
         try {
             $ConstantContact = new ConstantContact($cc_api_key);
             $response = $ConstantContact->getContactByEmail($access_token, $email);
             if (empty($response->results)) {
                 $Contact = new Contact();
                 $Contact->addEmail($email);
                 $Contact->addList($cc_list_id);
                 $Contact->first_name = $fname;
                 $Contact->last_name = $lname;
                 $NewContact = $ConstantContact->addContact($access_token, $Contact, false);
                 if (isset($NewContact) && 'yes' == $debug) {
                     $log->add('ConstantContact', ' ConstantContact new contact ' . $email . ' added to selected contact list');
                 }
             } else {
                 $Contact = $response->results[0];
                 $Contact->first_name = $fname;
                 $Contact->last_name = $lname;
                 $Contact->addList($cc_list_id);
                 $new_contact = $ConstantContact->updateContact($access_token, $Contact, false);
                 if (isset($new_contact) && 'yes' == $debug) {
                     $log->add('ConstantContact', ' ConstantContact update contact ' . $email . ' to selected contact list');
                 }
             }
         } catch (CtctException $ex) {
             $error = $ex->getErrors();
             $log->add('ConstantContact', print_r($error, true));
         }
     } else {
         if ('yes' == $debug) {
             $log->add('ConstantContact', 'Constant Contact API Key OR Constant Contact Access Token does not set');
         }
     }
 }
/**
 * Create a schedule for a campaign - this is time the campaign will be sent out
 * @param $campaignId - Id of the campaign to be scheduled
 * @param $time - ISO 8601 formatted timestamp of when the campaign should be sent
 */
function createSchedule($campaignId, $time)
{
    $cc = new ConstantContact(APIKEY);
    $schedule = new Schedule();
    $schedule->scheduled_date = $time;
    return $cc->addEmailCampaignSchedule(ACCESS_TOKEN, $campaignId, $schedule);
}
Пример #3
0
function annadir_newsletter($mail = false)
{
    $handle = new Mensajes();
    $mail = (string) $mail;
    if (!$mail || !is_email($mail)) {
        $handle->add_error('No se ha recibido un mail válido');
    } else {
        require_once '../classes/php-sdk-development/src/Ctct/autoload.php';
        $cc = new ConstantContact(APIKEY_CONSTANT);
        $contacts = $cc->getContacts(ACCESS_TOKEN_CONSTANT);
        $lists = $cc->getLists(ACCESS_TOKEN_CONSTANT);
        $list = '2021474646';
        try {
            $response = $cc->getContactByEmail(ACCESS_TOKEN_CONSTANT, $mail);
            if (empty($response->results)) {
                $contact = new Contact();
                $contact->addEmail($mail);
                $contact->addList($list);
                $returnContact = $cc->addContact(ACCESS_TOKEN_CONSTANT, $contact, true);
            } else {
                $contact = $response->results[0];
                $contact->addList($list);
                $returnContact = $cc->updateContact(ACCESS_TOKEN_CONSTANT, $contact, true);
            }
            $handle->add_mensaje('Tu correo se ha añadido correctamente a la lista de Bunch of Makers');
        } catch (CtctException $ex) {
            $errores = reset($ex->getErrors());
            $handle->add_error($errores['error_message']);
        }
    }
    return $handle->imprimir(false, true) . '<script>finalizar_subscripcion();</script>';
}
properly, you must have a valid Constant Contact API Key as well as an access token. Both of these can be obtained from 
http://constantcontact.mashery.com.
-->

<?php 
// require the autoloader
require_once '../src/Ctct/autoload.php';
use Ctct\ConstantContact;
use Ctct\Components\Contacts\Contact;
use Ctct\Components\Contacts\ContactList;
use Ctct\Components\Contacts\EmailAddress;
use Ctct\Exceptions\CtctException;
// Enter your Constant Contact APIKEY and ACCESS_TOKEN
define("APIKEY", "ENTER YOUR API KEY");
define("ACCESS_TOKEN", "ENTER YOUR ACCESS TOKEN");
$cc = new ConstantContact(APIKEY);
// attempt to fetch lists in the account, catching any exceptions and printing the errors to screen
try {
    $lists = $cc->getLists(ACCESS_TOKEN);
} catch (CtctException $ex) {
    foreach ($ex->getErrors() as $error) {
        print_r($error);
    }
}
// check if the form was submitted
if (isset($_POST['email']) && strlen($_POST['email']) > 1) {
    $action = "Getting Contact By Email Address";
    try {
        // check to see if a contact with the email addess already exists in the account
        $response = $cc->getContactByEmail(ACCESS_TOKEN, $_POST['email']);
        // create a new contact if one does not exist
 public static function donation_button_get_constantcontact_lists()
 {
     $donation_button_constantcontact_lists = array();
     $enable_constant_contact = get_option('enable_constant_contact');
     if (isset($enable_constant_contact) && $enable_constant_contact == 'yes') {
         $concontact_api_key = get_option('constantcontact_api_key');
         $constantcontact_access_token = get_option('constantcontact_access_token');
         $constant_contact_debug = get_option('log_enable_constant_contact') == 'yes' ? 'yes' : 'no';
         $log = new Donation_Button_Logger();
         if (isset($concontact_api_key) && !empty($concontact_api_key) && (isset($constantcontact_access_token) && !empty($constantcontact_access_token))) {
             $donation_button_constantcontact_lists = unserialize(get_transient('constantcontact_lists'));
             if (empty($donation_button_constantcontact_lists) || get_option('donation_button_constantcontact_force_refresh') == 'yes') {
                 try {
                     $cc = new ConstantContact($concontact_api_key);
                     $list_name = $cc->getLists($constantcontact_access_token);
                     if (isset($list_name) && !empty($list_name)) {
                         unset($donation_button_constantcontact_lists);
                         $donation_button_constantcontact_lists = array();
                         foreach ($list_name as $list_namekey => $list_namevalue) {
                             $donation_button_constantcontact_lists[$list_namevalue->id] = $list_namevalue->name;
                         }
                         set_transient('constantcontact_lists', serialize($donation_button_constantcontact_lists), 86400);
                         if ('yes' == $constant_contact_debug) {
                             $log->add('ConstantContact', 'ConstantContact Get List Success..');
                         }
                         update_option('donation_button_constantcontact_force_refresh', 'no');
                     } else {
                         if ('yes' == $constant_contact_debug) {
                             $log->add('ConstantContact', 'No ConstantContact List Available, check your API Key.');
                         }
                         $donation_button_constantcontact_lists['false'] = __("Unable to load Constant Contact lists, check your API Key.", 'paypal-ipn-for-wordpress-constant-contact');
                     }
                 } catch (CtctException $ex) {
                     unset($donation_button_constantcontact_lists);
                     $donation_button_constantcontact_lists = array();
                     $donation_button_constantcontact_lists['false'] = __("Unable to load Constant Contact lists, check your API Key.", 'paypal-ipn-for-wordpress-constant-contact');
                     set_transient('constantcontact_lists', serialize($donation_button_constantcontact_lists), 86400);
                     if ('yes' == $constant_contact_debug) {
                         $log->add('ConstantContact', 'Unable to load Constant Contact lists, check your API Key.');
                     }
                 }
             }
         }
     }
     return $donation_button_constantcontact_lists;
 }
 /**
  * @since    1.2.0
  * @return type
  */
 public function angelleye_get_constantcontact_lists()
 {
     $constantcontact_lists = array();
     $concontact_api_key = get_option('ofw_constantcontact_api_key');
     $constantcontact_access_token = get_option('ofw_constantcontact_access_token');
     if (isset($concontact_api_key) && !empty($concontact_api_key) && (isset($constantcontact_access_token) && !empty($constantcontact_access_token))) {
         $constant_contact_debug_log = get_option('ofw_log_enable_constant_contact') == 'yes' ? 'yes' : 'no';
         if ('yes' == $constant_contact_debug_log) {
             if (!class_exists('Angelleye_Offers_For_Woocommerce_Logger')) {
                 require_once OFFERS_FOR_WOOCOMMERCE_PLUGIN_DIR . '/includes/class-offers-for-woocommerce-logger.php';
             }
             $log = new Angelleye_Offers_For_Woocommerce_Logger();
         }
         $constantcontact_lists = unserialize(get_transient('ofw_constantcontact_mailinglist'));
         if (empty($constantcontact_lists) || get_option('ofw_constantcontact_force_refresh') == 'yes') {
             try {
                 $cc = new ConstantContact($concontact_api_key);
                 $list_name = $cc->getLists($constantcontact_access_token);
                 if (isset($list_name) && !empty($list_name)) {
                     unset($constantcontact_lists);
                     $constantcontact_lists = array();
                     foreach ($list_name as $list_namekey => $list_namevalue) {
                         $constantcontact_lists[$list_namevalue->id] = $list_namevalue->name;
                     }
                     set_transient('ofw_constantcontact_mailinglist', serialize($constantcontact_lists), 86400);
                     update_option('ofw_constantcontact_force_refresh', 'no');
                 } else {
                     $constantcontact_lists['false'] = __("Unable to load Constant Contact lists, check your API Key.", $this->plugin_slug);
                 }
             } catch (CtctException $ex) {
                 unset($constantcontact_lists);
                 $constantcontact_lists = array();
                 $constantcontact_lists['false'] = __("Unable to load Constant Contact lists, check your API Key.", $this->plugin_slug);
                 set_transient('ofw_constantcontact_mailinglist', serialize($constantcontact_lists), 86400);
             }
         }
         return $constantcontact_lists;
     }
 }
<?php

require_once 'Ctct/autoload.php';
define("APIKEY", $options_array['constant_contact']['api_key']);
define("ACCESS_TOKEN", $options_array['constant_contact']['access_token']);
use Ctct\ConstantContact;
use Ctct\Components\Contacts\Contact;
use Ctct\Components\Contacts\ContactList;
use Ctct\Components\Contacts\EmailAddress;
use Ctct\Exceptions\CtctException;
$cc = new ConstantContact(APIKEY);
try {
    $response = $cc->getContactByEmail(ACCESS_TOKEN, $email);
    if (empty($response->results)) {
        $action = "Creating Contact";
        $contact = new Contact();
        $contact->addEmail($email);
        $contact->addList($constant_contact_list);
        $contact->first_name = $fname;
        $contact->last_name = $lname;
        $returnContact = $cc->addContact(ACCESS_TOKEN, $contact, false);
    } else {
        $action = "Updating Contact";
        $contact = $response->results[0];
        $contact->addList($constant_contact_list);
        $contact->first_name = $fname;
        $contact->last_name = $lname;
        $returnContact = $cc->updateContact(ACCESS_TOKEN, $contact, false);
    }
} catch (CtctException $ex) {
}
 /**
  * Añade un mail al newsletter
  *
  * @param bool|string $mail mail que será añadido al newsletter.
  * @return string mensaje de error o de éxito.
  * @throws Exception si el algún setting del Newsletter no ha sido configurado.
  */
 public static function Add($mail = false)
 {
     $handle = new Mensajes();
     $mail = (string) $mail;
     if (!$mail || !is_email($mail)) {
         $handle->add_error('No se ha recibido un mail válido');
     } else {
         require_once '../php-sdk-development/src/Ctct/autoload.php';
         $cc = new ConstantContact(NewsletterHelper::ApiKey());
         $list = NewsletterHelper::ListNumber();
         try {
             $response = $cc->getContactByEmail(NewsletterHelper::AccessToken(), $mail);
             if (empty($response->results)) {
                 $contact = new Contact();
                 $contact->addEmail($mail);
                 $contact->addList($list);
                 $returnContact = $cc->addContact(NewsletterHelper::AccessToken(), $contact, true);
             } else {
                 $contact = $response->results[0];
                 $contact->addList($list);
                 $returnContact = $cc->updateContact(NewsletterHelper::AccessToken(), $contact, true);
             }
             $handle->add_mensaje('Tu correo se ha añadido correctamente a la lista');
         } catch (CtctException $ex) {
             $errores = reset($ex->getErrors());
             $handle->add_error($errores['error_message']);
         }
     }
     return $handle->imprimir(false, true);
     //.'<script>finalizar_subscripcion();</script>';
 }
 /**
  * Añade un mail al newsletter
  *
  * @param bool|string $mail mail que será añadido al newsletter.
  * @return string mensaje de error o de éxito.
  * @throws Exception si el algún setting del Newsletter no ha sido configurado.
  */
 public static function Add($mail = false)
 {
     global $mensaje;
     $mail = (string) $mail;
     if (!$mail || !is_email($mail)) {
         $mensaje->add_error('No se ha recibido un mail válido');
     } else {
         try {
             $cc = new ConstantContact(NewsletterHelper::ApiKey());
             $list = NewsletterHelper::ListNumber();
             $response = $cc->getContactByEmail(NewsletterHelper::AccessToken(), $mail);
             if (empty($response->results)) {
                 $contact = new Contact();
                 $contact->addEmail($mail);
                 $contact->addList($list);
                 $returnContact = $cc->addContact(NewsletterHelper::AccessToken(), $contact, true);
             } else {
                 $contact = $response->results[0];
                 $contact->addList($list);
                 $returnContact = $cc->updateContact(NewsletterHelper::AccessToken(), $contact, true);
             }
             $mensaje->add_mensaje('Tu correo se ha añadido correctamente a la lista');
         } catch (Exception $ex) {
             if ($ex instanceof CtctException) {
                 $errores = reset($ex->getErrors());
                 $mensaje->add_error($errores['error_message']);
             } else {
                 $mensaje->add_error($ex->getMessage());
             }
         }
     }
 }
 public function subscribe()
 {
     if (!$this->getRequest()->isAjax()) {
         //if not ajax, say go and eat your grass.
         exit("Action is not allowed!");
     }
     $return = array('action' => '', 'message' => '');
     $config = SiteConfig::current_site_config();
     $cc = new ConstantContact($config->CcApiKey);
     $list = $this->getRequest()->postVar('list');
     if ($config->CcDisplayZip) {
         $postcode = array('postal_code' => $this->getRequest()->postVar('postcode'));
     } else {
         $postcode = 0;
     }
     $email = $this->getRequest()->postVar('email');
     $first_name = $this->getRequest()->postVar('first_name');
     $last_name = $this->getRequest()->postVar('last_name');
     if (empty($email) || empty($first_name) || empty($last_name) || empty($list)) {
         $return['action'] = 'E';
         $return['message'] = $config->CcRequiredMessage ? $config->CcRequiredMessage : 'Required fields are missing.';
     } else {
         try {
             // check to see if a contact with the email addess already exists in the account
             $response = $cc->getContactByEmail($config->CcAccessToken, $email);
             // create a new contact if one does not exist
             if (empty($response->results)) {
                 $return['action'] = "C";
                 $contact = new Contact();
                 $contact->addEmail($email);
                 if (!is_array($list)) {
                     $contact->addList($list);
                 } else {
                     foreach ($list as $l) {
                         $contact->addList($l);
                     }
                 }
                 $contact->first_name = $first_name;
                 $contact->last_name = $last_name;
                 if ($postcode) {
                     $contact->addAddress($postcode);
                 }
                 $returnContact = $cc->addContact($config->CcAccessToken, $contact);
                 if (!empty($returnContact)) {
                     $return['message'] = $config->CcAddedMessage;
                 }
                 // update the existing contact if address already existed
             } else {
                 $return['action'] = "U";
                 $contact = $response->results[0];
                 if (!is_array($list)) {
                     $contact->addList($list);
                 } else {
                     foreach ($list as $l) {
                         $contact->addList($l);
                     }
                 }
                 $contact->first_name = $first_name;
                 $contact->last_name = $last_name;
                 if ($postcode) {
                     $contact->addAddress($postcode);
                 }
                 $returnContact = $cc->updateContact($config->CcAccessToken, $contact);
                 if (!empty($returnContact)) {
                     $return['message'] = $config->CcUpdatedMessage;
                 }
             }
             // catch any exceptions thrown during the process and print the errors to screen
         } catch (CtctException $ex) {
             $ex = $ex->getErrors();
             print_r($ex);
             $return['action'] = 'E';
             $return['message'] = $config->CcErrorMessage;
         }
     }
     return json_encode($return);
 }
<?php

require_once 'Ctct/autoload.php';
use Ctct\ConstantContact;
use Ctct\Components\Contacts\Contact;
use Ctct\Components\Contacts\ContactList;
use Ctct\Components\Contacts\EmailAddress;
use Ctct\Exceptions\CtctException;
$concontact_api_key = get_option('constantcontact_api_key');
$constantcontact_access_token = get_option('constantcontact_access_token');
define("APIKEY", $concontact_api_key);
define("ACCESS_TOKEN", $constantcontact_access_token);
if (isset($concontact_api_key) && !empty($concontact_api_key) && (isset($constantcontact_access_token) && !empty($constantcontact_access_token))) {
    $cc = new ConstantContact(APIKEY);
    try {
        $lists_tmp = $cc->getLists(ACCESS_TOKEN);
    } catch (CtctException $ex) {
    }
} else {
    $donation_button_constantcontact_lists['false'] = __("API Key is empty.", 'eddms');
}
 /**
  * We override the default so we can pass arrays as well as strings.
  * @param string $param
  * @return array
  */
 private function determineParam($param)
 {
     if (is_array($param)) {
         // If it's an array, we need to convert it to a string because of
         $param = '?' . http_build_query($param, '', '&');
     }
     return parent::determineParam($param);
 }
 function getLists()
 {
     $errors = array();
     $cc = new ConstantContact(ConstantContactV2::$cckey);
     // attempt to fetch lists in the account, catching any exceptions
     try {
         $lists = $cc->getLists(ConstantContactV2::$cctoken);
     } catch (CtctException $ex) {
         foreach ($ex->getErrors() as $error) {
             $errors[] = $error;
         }
         return $errors;
     }
     return $lists;
 }
Пример #14
0
 public function addEmailToNewsLetter()
 {
     if ($this->request->is('POST') || $this->request->is('PUT')) {
         $api_key = Configure::read('constant_contact_key');
         $api_token = Configure::read('constant_contact_token');
         $cc = new ConstantContact($api_key);
         // attempt to fetch lists in the account, catching any exceptions and printing the errors to screen
         try {
             $lists = $cc->getLists($api_token);
         } catch (Exception $ex) {
             throw new Exception();
         }
         // check if the form was submitted
         $action = "Getting Contact By Email Address";
         try {
             // check to see if a contact with the email addess already exists in the account
             $response = $cc->getContactByEmail($api_token, $_POST['data']['email']);
             // create a new contact if one does not exist
             if (empty($response->results)) {
                 $action = "Creating Contact";
                 $contact = new Contact();
                 $contact->addEmail($_POST['data']['email']);
                 $contact->addList('1339315632');
                 $contact->first_name = $_POST['data']['first_name'];
                 $contact->last_name = $_POST['data']['last_name'];
                 /*
                  * The third parameter of addContact defaults to false, but if this were set to true it would tell Constant Contact that this action is being performed by the contact themselves, and gives the ability to opt contacts back in and trigger Welcome/Change-of-interest emails. See: http://developer.constantcontact.com/docs/contacts-api/contacts-index.html#opt_in
                  */
                 $returnContact = $cc->addContact($api_token, $contact, true);
                 // update the existing contact if address already existed
             } else {
                 $action = "Updating Contact";
                 $contact = $response->results[0];
                 $contact->addList('1339315632');
                 $contact->first_name = $_POST['data']['first_name'];
                 $contact->last_name = $_POST['data']['last_name'];
                 $returnContact = $cc->updateContact($api_token, $contact, true);
             }
             // catch any exceptions thrown during the process and print the errors to screen
         } catch (Exception $ex) {
             $this->Session->setFlash('ニュースレターの配信登録に失敗しました。お問い合わせください。', 'default', array('class' => 'message error'));
             $this->redirect('/');
             exit;
         }
         if ($returnContact) {
             $this->Session->setFlash('ニュースレターの配信登録を完了しました。', 'default', array('class' => 'message success'));
             $this->redirect('/');
         }
         exit;
     } else {
         throw new Exception();
     }
 }