TWEB-20: Host and Post
This commit is contained in:
@@ -14,14 +14,29 @@ define('MEMBER_STATUS', "Web response");
|
||||
// Handle the Salesforce form submission
|
||||
function postsf($data)
|
||||
{
|
||||
// Fetch environment configuration
|
||||
$salesforceEnvironment = get_option('select-environment');
|
||||
|
||||
// Set up Salesforce configuration based on the environment
|
||||
if ($salesforceEnvironment == 'staging') {
|
||||
$Campaign_ID = '7011I000000dF9n';
|
||||
$sfdc_oid = '00DDh0000009Umu';
|
||||
$webtolead_url = 'https://test.salesforce.com/servlet/servlet.WebToLead';
|
||||
} else {
|
||||
$Campaign_ID = '7011I000000dDwA';
|
||||
$sfdc_oid = '00D1I000000mJ0Q';
|
||||
$webtolead_url = 'https://webto.salesforce.com/servlet/servlet.WebToLead';
|
||||
}
|
||||
|
||||
// Prepare POST data with the selected environment's `Campaign_ID` and `sfdc_oid`
|
||||
$cleanPOST = array(
|
||||
'first_name' => sanitize_text_field($data['first-name']),
|
||||
'last_name' => sanitize_text_field($data['last-name']),
|
||||
'phone' => sanitize_text_field($data['phone']),
|
||||
'email' => sanitize_email($data['your-email']),
|
||||
'zip' => sanitize_text_field($data['zip']),
|
||||
'Campaign_ID' => sanitize_text_field($data['campaign_ID']),
|
||||
'oid' => SALESFORCE_OID,
|
||||
'Campaign_ID' => $Campaign_ID, // Dynamic Campaign ID
|
||||
'oid' => $sfdc_oid, // Dynamic OID based on environment
|
||||
'lead_source' => LEAD_SOURCE,
|
||||
'Custom_Field_1__c' => sanitize_text_field($data['subid1']),
|
||||
'Custom_Field_2__c' => sanitize_text_field($data['subid2']),
|
||||
@@ -30,19 +45,18 @@ function postsf($data)
|
||||
);
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, "https://webto.salesforce.com/servlet/servlet.WebToLead");
|
||||
curl_setopt($ch, CURLOPT_URL, $webtolead_url); // Dynamic URL based on environment
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($cleanPOST));
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return the response for handling
|
||||
curl_setopt($ch, CURLOPT_HEADER, true); // Include headers in output for detailed debugging
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HEADER, true);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); // Get HTTP response code
|
||||
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$error = curl_error($ch);
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
// Check if CURL encountered an error
|
||||
if ($error) {
|
||||
return "CURL Error: $error";
|
||||
}
|
||||
@@ -56,8 +70,7 @@ function postsf($data)
|
||||
return $response ? $response : "Failed to submit lead to Salesforce.";
|
||||
}
|
||||
|
||||
|
||||
// Handle the Five9 form submission
|
||||
// Function to handle the Five9 form submission
|
||||
function post59($data) {
|
||||
$Campaign_ID = '701130000026vNy';
|
||||
date_default_timezone_set('America/New_York');
|
||||
@@ -66,6 +79,7 @@ function post59($data) {
|
||||
$newphone = preg_replace('/^1|\D/', '', sanitize_text_field($data['phone']));
|
||||
$webDialerKey = "YOUR_WEB_DIALER_KEY"; // Replace with actual WebDialer key
|
||||
|
||||
// Prepare POST data
|
||||
$cleanPOST = array(
|
||||
'first_name' => sanitize_text_field($data['first-name']),
|
||||
'last_name' => sanitize_text_field($data['last-name']),
|
||||
@@ -110,12 +124,13 @@ function post59($data) {
|
||||
return json_encode($parsed_response);
|
||||
}
|
||||
|
||||
|
||||
// Register REST API route for form submission
|
||||
add_action('rest_api_init', function () {
|
||||
register_rest_route('affiliates/v1', '/form', array(
|
||||
'methods' => 'POST',
|
||||
'callback' => 'handle_form_submission',
|
||||
'permission_callback' => '__return_true'
|
||||
'permission_callback' => '__return_true' // Allows public access; adjust for security as needed
|
||||
));
|
||||
});
|
||||
|
||||
@@ -128,6 +143,6 @@ function handle_form_submission($request) {
|
||||
|
||||
return new WP_REST_Response(array(
|
||||
'salesforce_response' => $response1 ? "Success" : "Failed",
|
||||
'five9_response' => strip_tags($response2)
|
||||
'five9_response' => strip_tags($response2)
|
||||
), 200);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user