Host and post updates / ecom updates

This commit is contained in:
Tony Volpe
2024-10-28 14:23:22 -04:00
parent 6700dc85db
commit 6a0bf4234e
6 changed files with 68 additions and 180 deletions

View File

@@ -2,7 +2,7 @@
/*
Plugin Name: Affiliate Host 'n Post
Description: Handles form submissions and integrates with Salesforce and Five9 APIs.
Version: 1.1
Version: 1.2
Author: Anthony Volpe
*/
@@ -12,18 +12,15 @@ define('LEAD_SOURCE', "Web");
define('MEMBER_STATUS', "Web response");
// Handle the Salesforce form submission
function postsf($data)
{
// Fetch environment configuration
$salesforceEnvironment = get_option('select-environment');
function postsf($data) {
$sfdc_env = get_option('select-environment');
// Set up Salesforce configuration based on the environment
if ($salesforceEnvironment == 'staging') {
$Campaign_ID = '7011I000000dF9n';
if ($sfdc_env == 'full') {
$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';
}
@@ -35,7 +32,7 @@ function postsf($data)
'phone' => sanitize_text_field($data['phone']),
'email' => sanitize_email($data['your-email']),
'zip' => sanitize_text_field($data['zip']),
'Campaign_ID' => $Campaign_ID, // Dynamic Campaign ID
'Campaign_ID' => sanitize_text_field($data['campaign_ID']),
'oid' => $sfdc_oid, // Dynamic OID based on environment
'lead_source' => LEAD_SOURCE,
'Custom_Field_1__c' => sanitize_text_field($data['subid1']),
@@ -124,7 +121,6 @@ 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(
@@ -134,6 +130,7 @@ add_action('rest_api_init', function () {
));
});
// Callback function to handle the form submission
// Handle REST API response formatting
function handle_form_submission($request) {
@@ -143,6 +140,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);
}