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');
         }
     }
 }
 public static function donation_button_twilio_sms_handler($posted)
 {
     $debug = get_option('donation_button_twilio_sms_log_errors') == 'yes' ? 'yes' : 'no';
     if ('yes' == $debug) {
         $log = new Donation_Button_Logger();
     }
     $account_sid = get_option("donation_button_twilio_sms_account_sid");
     $auth_token = get_option("donation_button_twilio_sms_auth_token");
     $from_number = get_option("donation_button_twilio_sms_from_number");
     $template = get_option("donation_button_twilio_sms_admin_sms_template");
     $recipients = get_option("donation_button_twilio_sms_admin_sms_recipients");
     //$log->add('Twilio SMS before', $template);
     $message = self::replace_message_body($template, $posted);
     //$log->add('Twilio SMS after', $message);
     if (isset($account_sid) && !empty($account_sid) && (isset($auth_token) && !empty($auth_token)) && (isset($from_number) && !empty($from_number)) && (isset($recipients) && !empty($recipients))) {
         include_once DBP_PLUGIN_DIR_PATH . '/admin/partials/lib/Twilio.php';
         $http = new Services_Twilio_TinyHttp('https://api.twilio.com', array('curlopts' => array(CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => 2)));
         $client = new Services_Twilio($account_sid, $auth_token, "2010-04-01", $http);
         try {
             $message = $client->account->messages->create(array("From" => $from_number, "To" => $recipients, "Body" => $message));
             if ('yes' == get_option('donation_button_twilio_sms_log_errors')) {
                 $log->add('Twilio SMS', 'SMS Sent message ' . $message->sid);
             }
         } catch (Exception $e) {
             if ('yes' == get_option('donation_button_twilio_sms_log_errors')) {
                 $log->add('Twilio SMS', 'SMS Error message ' . $e->getMessage());
             }
         }
     }
 }
 public static function donation_button_infusionsoft_handler($posted)
 {
     $is_api_key = get_option("infusionsoft_api_key");
     $app_name = get_option("infusionsoft_api_app_name");
     $is_list_id = get_option("infusionsoft_lists");
     $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_infusionsoft') == 'yes' ? 'yes' : 'no';
     if ('yes' == $debug) {
         $log = new Donation_Button_Logger();
     }
     if (isset($is_api_key) && !empty($is_api_key) && (isset($app_name) && !empty($app_name)) && (isset($is_list_id) && !empty($is_list_id))) {
         include_once DBP_PLUGIN_DIR_PATH . '/admin/partials/lib/infusionsoft/isdk.php';
         $app = new iSDK();
         try {
             if ($app->cfgCon($app_name, $is_api_key)) {
                 $contactid = $app->addCon(array('FirstName' => $fname, 'LastName' => $lname, 'Email' => $email));
                 $infusionsoft_result = $app->campAssign($contactid, $is_list_id);
                 if ('yes' == $debug) {
                     $log->add('Infusionsoft', print_r($infusionsoft_result, true));
                 }
             }
         } catch (Exception $e) {
             if ('yes' == $debug) {
                 $log->add('Infusionsoft', print_r($e, true));
             }
         }
     }
 }
 public function ipn_response_data_handler($posted = null)
 {
     global $wp;
     $debug = get_option('log_enable_general_settings') == 'yes' ? 'yes' : 'no';
     if ('yes' == $debug) {
         $log = new Donation_Button_Logger();
         $log->add('Paypal Donation Button Post Callback', print_r($posted, true));
     }
     if (isset($posted) && !empty($posted)) {
         if (isset($posted['txn_id'])) {
             $paypal_txn_id = $posted['txn_id'];
         } else {
             return false;
         }
         if ($this->donation_button_exist_post_by_title($paypal_txn_id) == false) {
             $insert_ipn_array = array('ID' => '', 'post_type' => 'donation_list', 'post_status' => 'publish', 'post_title' => $paypal_txn_id);
             $post_id = wp_insert_post($insert_ipn_array);
             if ('yes' == get_option('enable_mailchimp')) {
                 do_action('donation_button_mailchimp_handler', $posted);
             }
             if ('yes' == get_option('enable_getresponse')) {
                 do_action('donation_button_getresponse_handler', $posted);
             }
             if ('yes' == get_option('enable_icontact')) {
                 do_action('donation_button_icontact_handler', $posted);
             }
             if ('yes' == get_option('enable_infusionsoft')) {
                 do_action('donation_button_infusionsoft_handler', $posted);
             }
             if ('yes' == get_option('enable_constant_contact')) {
                 do_action('donation_button_constant_contact_handler', $posted);
             }
             if ('yes' == get_option('enable_campaignmonitor')) {
                 do_action('donation_button_campaign_monitor_handler', $posted);
             }
             if ('yes' == get_option('donation_button_twilio_sms_enable_admin_sms')) {
                 do_action('donation_button_twilio_sms_handler', $posted);
             }
             $this->ipn_response_postmeta_handler($post_id, $posted);
         } else {
             $post_id = $this->donation_button_exist_post_by_title($paypal_txn_id);
             wp_update_post(array('ID' => $post_id, 'post_status' => 'publish'));
             $this->ipn_response_postmeta_handler($post_id, $posted);
         }
     }
 }
 public static function donation_button_icontact_handler($posted)
 {
     if (!isset($posted) || empty($posted)) {
         return;
     }
     $ic_api_key = get_option("icontact_api_id");
     $app_password = get_option("icontact_api_password");
     $app_username = get_option("icontact_api_username");
     $icontact_list = get_option("icontact_lists");
     $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_icontact') == 'yes' ? 'yes' : 'no';
     if ('yes' == $debug) {
         $log = new Donation_Button_Logger();
     }
     if (isset($ic_api_key) && !empty($ic_api_key) && (isset($app_username) && !empty($app_username)) && (isset($app_password) && !empty($app_password))) {
         if (isset($icontact_list) && !empty($icontact_list)) {
             include_once DBP_PLUGIN_DIR_PATH . '/admin/partials/lib/icontact/icontact.php';
             iContactApi::getInstance()->setConfig(array('appId' => $ic_api_key, 'apiUsername' => $app_username, 'apiPassword' => $app_password));
             $iContact = iContactApi::getInstance();
             try {
                 $contactid = $iContact->addContact($email, 'normal', null, $fname, $lname, null, null, null, null, null, null, null, null, null);
                 $subscribed = $iContact->subscribeContactToList($contactid->contactId, $icontact_list, 'normal');
                 if ('yes' == $debug) {
                     if ($subscribed) {
                         $log->add('Icontact', $email . ' Successfully Add Contact in iContact');
                     } else {
                         $log->add('Icontact', $email . ' Contact already added to target campaign in iContact');
                     }
                 }
             } catch (Exception $e) {
                 if ('yes' == $debug) {
                     $log->add('Icontact', prin_r($e, true));
                 }
             }
         }
     }
 }
 public static function donation_button_getresponse_handler($posted)
 {
     if (!isset($posted) || empty($posted)) {
         return;
     }
     $debug = get_option('log_enable_Getrsponse') == 'yes' ? 'yes' : 'no';
     if ('yes' == $debug) {
         $log = new Donation_Button_Logger();
     }
     $apikey = get_option('getresponse_api_key');
     $campaigns = get_option('getresponse_lists');
     $first_name = isset($posted['first_name']) ? $posted['first_name'] : '';
     $last_name = isset($posted['last_name']) ? $posted['last_name'] : '';
     $payer_email = isset($posted['payer_email']) ? $posted['payer_email'] : $posted['receiver_email'];
     $merge_vars = array('FNAME' => $first_name, 'LNAME' => $last_name);
     $name = $first_name . ' ' . $last_name;
     if (isset($apikey) && !empty($apikey) && (isset($campaigns) && !empty($campaigns))) {
         include_once DBP_PLUGIN_DIR_PATH . 'admin/partials/lib/getresponse/getresponse.php';
         try {
             $api = new Donation_Button_Getesponse_API($apikey);
             $retval = $api->addContact($campaigns, $name, $payer_email);
             if ('yes' == $debug) {
                 if ($retval) {
                     $log->add('Getresponse', $payer_email . ' Successfully Add Contact in Getresponse');
                 } else {
                     $log->add('Getresponse', $payer_email . ' Contact already added to target campaign in Getresponse');
                 }
             }
         } catch (Exception $e) {
             if ('yes' == $debug) {
                 $log->add('Getresponse', print_r($e, true));
             }
         }
     } else {
         $log->add('Getresponse', 'Getresponse Api Key is Empty.');
     }
 }
 public static function donation_button_mailchimp_handler($posted)
 {
     if (!isset($posted) || empty($posted)) {
         return;
     }
     $debug = get_option('log_enable_mailchimp') == 'yes' ? 'yes' : 'no';
     if ('yes' == $debug) {
         $log = new Donation_Button_Logger();
     }
     $apikey = get_option('mailchimp_api_key');
     $listId = get_option('mailchimp_lists');
     $first_name = isset($posted['first_name']) ? $posted['first_name'] : '';
     $last_name = isset($posted['last_name']) ? $posted['last_name'] : '';
     $payer_email = isset($posted['payer_email']) ? $posted['payer_email'] : $posted['receiver_email'];
     $merge_vars = array('FNAME' => $first_name, 'LNAME' => $last_name);
     if (isset($apikey) && !empty($apikey)) {
         if (isset($listId) && !empty($listId)) {
             include_once 'class-donation-button-mcapi.php';
             $api = new Donation_Button_MailChimp_MCAPI($apikey);
             try {
                 $retval = $api->listSubscribe($listId, $payer_email, $merge_vars, $email_type = 'html');
                 if ('yes' == $debug) {
                     if ("true" == $retval) {
                         $log->add('MailChimp', $payer_email . ' Successfully Add Contact in Mailchimp');
                     } else {
                         $log->add('MailChimp', $payer_email . ' in Mailchimp');
                     }
                 }
             } catch (Mailchimp_Error $e) {
                 if ('yes' == $debug) {
                     $log->add('MailChimp', print_r($e, true));
                 }
             }
         } else {
             if ('yes' == $debug) {
                 $log->add('MailChimp', 'MailChimp List Id is Empty.');
             }
         }
     } else {
         if ('yes' == $debug) {
             $log->add('MailChimp', 'MailChimp Api Key is Empty.');
         }
     }
 }
 public static function donation_button_campaign_monitor_handler($posted)
 {
     $cm_api_key = get_option("campaignmonitor_api_key");
     $client_id = get_option("campaignmonitor_client_id");
     $cm_list_id = get_option("campaignmonitor_lists");
     $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_campaignmonitor') == 'yes' ? 'yes' : 'no';
     if ('yes' == $debug) {
         $log = new Donation_Button_Logger();
     }
     if (isset($cm_api_key) && !empty($cm_api_key) && (isset($client_id) && !empty($client_id)) && (isset($cm_list_id) && !empty($cm_list_id))) {
         include_once DBP_PLUGIN_DIR_PATH . '/admin/partials/lib/campaign_monitor/csrest_subscribers.php';
         $wrap = new CS_REST_Subscribers($cm_list_id, $cm_api_key);
         try {
             $response = $wrap->get($email);
             if ($response->http_status_code == "200") {
                 $result = $wrap->update($email, array('EmailAddress' => $email, 'Name' => $fname . ' ' . $lname, 'CustomFields' => array(), 'Resubscribe' => true));
                 if ("yes" == $debug) {
                     if ($response->response->State == "Unsubscribed") {
                         $log->add('CampaignMonitor', ' CampaignMonitor new contact ' . $email . ' added to selected contact list');
                     } else {
                         $log->add('CampaignMonitor', ' CampaignMonitor update contact ' . $email . ' to selected contact list');
                     }
                 }
             } else {
                 $result = $wrap->add(array('EmailAddress' => $email, 'Name' => $fname . ' ' . $lname, 'CustomFields' => array(), 'Resubscribe' => true));
                 if (isset($result) && 'yes' == $debug) {
                     $log->add('CampaignMonitor', ' CampaignMonitor new contact ' . $email . ' added to selected contact list');
                 }
             }
         } catch (Exception $e) {
             if ('yes' == $debug) {
                 $log->add('CampaignMonitor', prin_r($e, true));
             }
         }
     } else {
         if ('yes' == $debug) {
             $log->add('CampaignMonitor', 'Campaign Monitor API Key OR Campaign Monitor Client ID does not set');
         }
     }
 }
 public static function donation_button_twilio_send_test_sms()
 {
     //check_ajax_referer('donation_button_twilio_test_sms_button', 'security');
     $donation_button_twilio_sms_log_errors = get_option('donation_button_twilio_sms_log_errors');
     if (isset($donation_button_twilio_sms_log_errors) && $donation_button_twilio_sms_log_errors == 'yes') {
         $log = new Donation_Button_Logger();
     }
     include_once DBP_PLUGIN_DIR_PATH . '/admin/partials/lib/Twilio.php';
     $AccountSid = get_option("donation_button_twilio_sms_account_sid");
     $AuthToken = get_option("donation_button_twilio_sms_auth_token");
     $from_number = get_option("donation_button_twilio_sms_from_number");
     $test_mobile_number = $_POST['donation_button_twilio_sms_test_mobile_number'];
     $test_message = sanitize_text_field($_POST['donation_button_twilio_sms_test_message']);
     $http = new Services_Twilio_TinyHttp('https://api.twilio.com', array('curlopts' => array(CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => 2)));
     try {
         $client = new Services_Twilio($AccountSid, $AuthToken, "2010-04-01", $http);
         $message = $client->account->messages->create(array("From" => $from_number, "To" => $test_mobile_number, "Body" => $test_message));
         $response['success'] = "Successfully Sent message {$message->sid}";
         if ('yes' == get_option('twilio_sms_woo_log_errors')) {
             $log->add('Twilio SMS', 'TEST SMS Sent message ' . $message->sid);
         }
     } catch (Exception $e) {
         $response['error'] = $e->getMessage();
         if ('yes' == get_option('twilio_sms_woo_log_errors')) {
             $log->add('Twilio SMS', 'TEST SMS Error message ' . $e->getMessage());
         }
     }
     echo json_encode($response);
     die;
 }