From 31eacf670ae45eb762e1bd9056b63839f0e0fa3b Mon Sep 17 00:00:00 2001 From: Tony Volpe Date: Wed, 16 Oct 2024 23:56:36 +0000 Subject: [PATCH] Feature/TWEB-143 woo order data to sf --- .../affiliate-host-n-post/host-n-post.php | 108 ++++ wp/wp-content/themes/medicalalert/footer.php | 79 +-- .../themes/medicalalert/functions.php | 544 ++++++++++++++++-- wp/wp-content/themes/medicalalert/header.php | 102 +--- .../medicalalert/helpers/SecuredContent.php | 135 +++++ .../themes/medicalalert/tpl-cart.php | 38 +- 6 files changed, 758 insertions(+), 248 deletions(-) create mode 100644 wp/wp-content/plugins/affiliate-host-n-post/host-n-post.php create mode 100644 wp/wp-content/themes/medicalalert/helpers/SecuredContent.php diff --git a/wp/wp-content/plugins/affiliate-host-n-post/host-n-post.php b/wp/wp-content/plugins/affiliate-host-n-post/host-n-post.php new file mode 100644 index 00000000..c4e22679 --- /dev/null +++ b/wp/wp-content/plugins/affiliate-host-n-post/host-n-post.php @@ -0,0 +1,108 @@ + stripslashes($data['first-name']), + 'last_name' => stripslashes($data['last-name']), + 'phone' => stripslashes($data['phone']), + 'email' => stripslashes($data['your-email']), + 'zip' => stripslashes($data['zip']), + 'Campaign_ID' => $campaign_ID, + 'oid' => $oid, + 'lead_source' => $lead_source, + 'Custom_Field_1__c' => stripslashes($data['subid1']), + 'Custom_Field_2__c' => stripslashes($data['subid2']), + 'Custom_Field_3__c' => stripslashes($data['subid3']), + 'Custom_Field_4__c' => stripslashes($data['subid4']), + ); + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, "https://webto.salesforce.com/servlet/servlet.WebToLead"); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($cleanPOST)); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Added to ensure the response is captured + + $response = curl_exec($ch); + $error = curl_error($ch); + curl_close($ch); + + if ($error) { + return "Salesforce Error: $error"; + } else { + return json_decode($response, true); + } +} + +// Function to handle the Five9 form submission +function post59($data) { + $Campaign_ID = '701130000026vNy'; + date_default_timezone_set('America/New_York'); + $F9Date = date("Y-m-d")."-". date("H:i"); + $F9domain = "connect america"; + $F9list = isset($data['callback']) ? $data['callback'] : ''; + $newphone = preg_replace('/^1|\D/', '', $data['phone']); + + $cleanPOST = array( + 'first_name' => stripslashes($data['first-name']), + 'last_name' => stripslashes($data['last-name']), + 'number1' => $newphone, + 'F9domain' => $F9domain, + 'F9list' => $F9list, + 'salesforce_id' => $Campaign_ID, + 'Device_6' => '', + 'WebDialer_Key' => $F9Date, + 'F9key' => $F9Date, + 'F9CallASAP' => true + ); + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, "https://api.five9.com/web2campaign/AddToList"); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($cleanPOST)); + + $response = curl_exec($ch); + + if ($response === false) { + $error = curl_error($ch); + curl_close($ch); + return "Five9 Error: $error"; + } else { + curl_close($ch); + return json_decode($response, true); + } +} + +// REST API endpoint registration +add_action('rest_api_init', function () { + register_rest_route('affiliates/v1', '/form', array( + 'methods' => 'POST', + 'callback' => 'handle_form_submission', + )); +}); + +// Function to handle the form submission and trigger both postsf() and post59() +function handle_form_submission($request) +{ + $params = $request->get_params(); + $response1 = postsf($params); + $response2 = post59($params); + + return array( + 'salesforce_response' => $response1, + 'five9_response' => $response2 + ); +} diff --git a/wp/wp-content/themes/medicalalert/footer.php b/wp/wp-content/themes/medicalalert/footer.php index 897d7604..842fe548 100644 --- a/wp/wp-content/themes/medicalalert/footer.php +++ b/wp/wp-content/themes/medicalalert/footer.php @@ -38,7 +38,6 @@ $linkedin_url = get_field('linkedin_url', 'option'); $youtube_url = get_field('youtube_url', 'option'); $consumer_phone_number = get_field('consumer_phone_number', 'option'); $business_phone_number = get_field('business_phone_number', 'option'); -$address = get_field('address', 'option'); $copyright_info = get_field('copyright_info', 'option'); $privacy_policy_link = get_field('privacy_policy_link', 'option'); $terms_of_use_link = get_field('terms_of_use_link', 'option'); @@ -47,86 +46,18 @@ $incident_report_link = get_field('incident_report_link', 'option'); $consumer_disclaimer = get_field('consumer_disclaimer', 'option'); $business_disclaimer = get_field('business_disclaimer', 'option'); $caution_info = get_field('caution_info', 'option'); -$referral_paragraph = get_field('referral_paragraph', 'option'); $banner_bottom = get_field('banner_bottom', 'option'); $banner_link = get_field('banner_link', 'option'); $col_1_consumer_menu_title = get_field('col_1_consumer_menu_title', 'option'); $col_2_consumer_menu_title = get_field('col_2_consumer_menu_title', 'option'); $col_3_consumer_menu_title = get_field('col_3_consumer_menu_title', 'option'); $col_4_consumer_menu_title = get_field('col_4_consumer_menu_title', 'option'); -$col_1_business_menu_title = get_field('col_1_business_menu_title', 'option'); -$col_2_business_menu_title = get_field('col_2_business_menu_title', 'option'); -$col_3_business_menu_title = get_field('col_3_business_menu_title', 'option'); -$col_4_business_menu_title = get_field('col_4_business_menu_title', 'option'); -$google_link = get_field('google_link', 'option'); + ?>