Host and post updates / ecom updates
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
/*
|
/*
|
||||||
Plugin Name: Affiliate Host 'n Post
|
Plugin Name: Affiliate Host 'n Post
|
||||||
Description: Handles form submissions and integrates with Salesforce and Five9 APIs.
|
Description: Handles form submissions and integrates with Salesforce and Five9 APIs.
|
||||||
Version: 1.1
|
Version: 1.2
|
||||||
Author: Anthony Volpe
|
Author: Anthony Volpe
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -12,18 +12,15 @@ define('LEAD_SOURCE', "Web");
|
|||||||
define('MEMBER_STATUS', "Web response");
|
define('MEMBER_STATUS', "Web response");
|
||||||
|
|
||||||
// Handle the Salesforce form submission
|
// Handle the Salesforce form submission
|
||||||
function postsf($data)
|
function postsf($data) {
|
||||||
{
|
|
||||||
// Fetch environment configuration
|
$sfdc_env = get_option('select-environment');
|
||||||
$salesforceEnvironment = get_option('select-environment');
|
|
||||||
|
|
||||||
// Set up Salesforce configuration based on the environment
|
// Set up Salesforce configuration based on the environment
|
||||||
if ($salesforceEnvironment == 'staging') {
|
if ($sfdc_env == 'full') {
|
||||||
$Campaign_ID = '7011I000000dF9n';
|
|
||||||
$sfdc_oid = '00DDh0000009Umu';
|
$sfdc_oid = '00DDh0000009Umu';
|
||||||
$webtolead_url = 'https://test.salesforce.com/servlet/servlet.WebToLead';
|
$webtolead_url = 'https://test.salesforce.com/servlet/servlet.WebToLead';
|
||||||
} else {
|
} else {
|
||||||
$Campaign_ID = '7011I000000dDwA';
|
|
||||||
$sfdc_oid = '00D1I000000mJ0Q';
|
$sfdc_oid = '00D1I000000mJ0Q';
|
||||||
$webtolead_url = 'https://webto.salesforce.com/servlet/servlet.WebToLead';
|
$webtolead_url = 'https://webto.salesforce.com/servlet/servlet.WebToLead';
|
||||||
}
|
}
|
||||||
@@ -35,7 +32,7 @@ function postsf($data)
|
|||||||
'phone' => sanitize_text_field($data['phone']),
|
'phone' => sanitize_text_field($data['phone']),
|
||||||
'email' => sanitize_email($data['your-email']),
|
'email' => sanitize_email($data['your-email']),
|
||||||
'zip' => sanitize_text_field($data['zip']),
|
'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
|
'oid' => $sfdc_oid, // Dynamic OID based on environment
|
||||||
'lead_source' => LEAD_SOURCE,
|
'lead_source' => LEAD_SOURCE,
|
||||||
'Custom_Field_1__c' => sanitize_text_field($data['subid1']),
|
'Custom_Field_1__c' => sanitize_text_field($data['subid1']),
|
||||||
@@ -124,7 +121,6 @@ function post59($data) {
|
|||||||
return json_encode($parsed_response);
|
return json_encode($parsed_response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Register REST API route for form submission
|
// Register REST API route for form submission
|
||||||
add_action('rest_api_init', function () {
|
add_action('rest_api_init', function () {
|
||||||
register_rest_route('affiliates/v1', '/form', array(
|
register_rest_route('affiliates/v1', '/form', array(
|
||||||
@@ -134,6 +130,7 @@ add_action('rest_api_init', function () {
|
|||||||
));
|
));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// Callback function to handle the form submission
|
// Callback function to handle the form submission
|
||||||
// Handle REST API response formatting
|
// Handle REST API response formatting
|
||||||
function handle_form_submission($request) {
|
function handle_form_submission($request) {
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
include_once(get_template_directory() . '/helpers/secured-content.php');
|
|
||||||
|
|
||||||
add_action( 'gform_after_submission_1', 'post_to_salesforce_and_five9', 10, 2 );
|
add_action( 'gform_after_submission_1', 'post_to_salesforce_and_five9', 10, 2 );
|
||||||
function post_to_salesforce_and_five9( $entry, $form ) {
|
function post_to_salesforce_and_five9( $entry, $form ) {
|
||||||
post_to_salesforce( $entry, $form );
|
post_to_salesforce( $entry, $form );
|
||||||
|
|||||||
@@ -1,30 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
/** Salesforce Api Url */
|
$sf_env = get_option('select-environment');
|
||||||
define("IPER_SALESFORCE_API_URL","https://connectamerica--full.sandbox.my.salesforce-sites.com/RestServices/services/apexrest");
|
if ($sf_env == 'Full') {
|
||||||
|
include_once(get_template_directory() . '/helpers/sfconfig-test.php');
|
||||||
/** Salesforce Brand ID */
|
} else {
|
||||||
define("IPER_SALESFORCE_BRAND","MedicalAlert");
|
include_once(get_template_directory() . '/helpers/sfconfig-prod.php');
|
||||||
|
}
|
||||||
/** Encryption key */
|
|
||||||
define("IPER_ENCRYPTION_KEY","potEgc8+5f32y+jpXSz/NqFEPuVWoT95V7aYiyRNjpQ=");
|
|
||||||
|
|
||||||
/** Signature */
|
|
||||||
define("IPER_SIGNATURE_KEY","-----BEGIN PRIVATE KEY-----
|
|
||||||
MIICcgIBADANBgkqhkiG9w0BAQEFAASCAlwwggJYAgEAAoGAwCSPvGdoZsC1Q4btJETb9fnkM/ne
|
|
||||||
zBA4F4f0bX3JymVZ83H9F1CTykhQWjZ8WiAuPFGHNaUESGtfr0pWF113KrY5ei910WcvcBKd1w6w
|
|
||||||
JrpUdhWC5bAgoXfLoS0itbX7TvIKrvoXcHbtAPMEDyMNv/Dy/RstNTqUBzF2fLKTwTkCAwEAAQKB
|
|
||||||
gAZuct0554sLnPBOCOFePgVFaw0OVRXRiSnIeYxcry92Ja+ku3WsqHXB5pFOd5UbX1DSOHYO4vjQ
|
|
||||||
QfCqdVKXj1CGF+5snE8elE8uuN4Y7OgZ9PBdTJ/V2gevtkYQsjtjteZn3ay3Eic1ItVWSXL4NjZh
|
|
||||||
4eso3QN+yQsfUhFAOD59AkD1W58VDN8vHWymyJebIGPwKFf6bQpUCeEJVCR5gBvz0wGEQWaLoiyJ
|
|
||||||
HGSenfpDTo9eiKWvGOnlB11wLvvatqATAkDIeg5jQvj2M6aQRr1k+UETGtjz9BN5vwwpJt+qnVbR
|
|
||||||
hypoSsBtqBMxTSbWizNzMen1JaOw/Vck8Iei4FoatrsDAkAnSZp5hmweYTnKowgToOYfyHX99YPX
|
|
||||||
3RUZp02H3wmay0jM4qQG69rxwYgjFezC5ktyubK+DOE2+SzvD7boWKHdAkBup+B1LaxZyRyxGjrE
|
|
||||||
F0iyEOmbjieJ1cgSluByPjKDqMXhlxEr9c/SMLG1TlRxyyVGKSZ3NP765sEXSBq0EBSdAkCX8h79
|
|
||||||
z9mezZxyRcdod2Sk4t1hWUf0AnLhkzfAgdQoNwY692uBYXsyKXGufLNkb+RznASmn5Lr6NanIL4c
|
|
||||||
6S9P
|
|
||||||
-----END PRIVATE KEY-----");
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(!class_exists("EncryptedContent")){
|
if(!class_exists("EncryptedContent")){
|
||||||
class EncryptedContent{
|
class EncryptedContent{
|
||||||
@@ -59,8 +39,8 @@ if(!class_exists("SecuredContent")){
|
|||||||
public function __construct() {
|
public function __construct() {
|
||||||
/*$this->encrption_key = get_option("encrption_key");
|
/*$this->encrption_key = get_option("encrption_key");
|
||||||
$this->signature_key = get_option("signature_key");*/
|
$this->signature_key = get_option("signature_key");*/
|
||||||
$this->encrption_key = IPER_ENCRYPTION_KEY;
|
$this->encrption_key = ENCRYPTION_KEY;
|
||||||
$this->signature_key = IPER_SIGNATURE_KEY;
|
$this->signature_key = SIGNATURE_KEY;
|
||||||
$this->cipher = 'AES-256-CBC';
|
$this->cipher = 'AES-256-CBC';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,139 +0,0 @@
|
|||||||
<?php
|
|
||||||
/** Salesforce Api Url */
|
|
||||||
define("IPER_SALESFORCE_API_URL","https://connectamerica--full.sandbox.my.salesforce-sites.com/RestServices/services/apexrest");
|
|
||||||
|
|
||||||
/** Salesforce Brand ID */
|
|
||||||
define("IPER_SALESFORCE_BRAND","MedicalAlert");
|
|
||||||
|
|
||||||
/** Encryption key */
|
|
||||||
define("IPER_ENCRYPTION_KEY","potEgc8+5f32y+jpXSz/NqFEPuVWoT95V7aYiyRNjpQ=");
|
|
||||||
|
|
||||||
/** Signature */
|
|
||||||
define("IPER_SIGNATURE_KEY","-----BEGIN PRIVATE KEY-----
|
|
||||||
MIICcgIBADANBgkqhkiG9w0BAQEFAASCAlwwggJYAgEAAoGAwCSPvGdoZsC1Q4btJETb9fnkM/ne
|
|
||||||
zBA4F4f0bX3JymVZ83H9F1CTykhQWjZ8WiAuPFGHNaUESGtfr0pWF113KrY5ei910WcvcBKd1w6w
|
|
||||||
JrpUdhWC5bAgoXfLoS0itbX7TvIKrvoXcHbtAPMEDyMNv/Dy/RstNTqUBzF2fLKTwTkCAwEAAQKB
|
|
||||||
gAZuct0554sLnPBOCOFePgVFaw0OVRXRiSnIeYxcry92Ja+ku3WsqHXB5pFOd5UbX1DSOHYO4vjQ
|
|
||||||
QfCqdVKXj1CGF+5snE8elE8uuN4Y7OgZ9PBdTJ/V2gevtkYQsjtjteZn3ay3Eic1ItVWSXL4NjZh
|
|
||||||
4eso3QN+yQsfUhFAOD59AkD1W58VDN8vHWymyJebIGPwKFf6bQpUCeEJVCR5gBvz0wGEQWaLoiyJ
|
|
||||||
HGSenfpDTo9eiKWvGOnlB11wLvvatqATAkDIeg5jQvj2M6aQRr1k+UETGtjz9BN5vwwpJt+qnVbR
|
|
||||||
hypoSsBtqBMxTSbWizNzMen1JaOw/Vck8Iei4FoatrsDAkAnSZp5hmweYTnKowgToOYfyHX99YPX
|
|
||||||
3RUZp02H3wmay0jM4qQG69rxwYgjFezC5ktyubK+DOE2+SzvD7boWKHdAkBup+B1LaxZyRyxGjrE
|
|
||||||
F0iyEOmbjieJ1cgSluByPjKDqMXhlxEr9c/SMLG1TlRxyyVGKSZ3NP765sEXSBq0EBSdAkCX8h79
|
|
||||||
z9mezZxyRcdod2Sk4t1hWUf0AnLhkzfAgdQoNwY692uBYXsyKXGufLNkb+RznASmn5Lr6NanIL4c
|
|
||||||
6S9P
|
|
||||||
-----END PRIVATE KEY-----");
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(!class_exists("EncryptedContent")){
|
|
||||||
class EncryptedContent{
|
|
||||||
public $IV;
|
|
||||||
public $Data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!class_exists("MessageContentSigned")){
|
|
||||||
class MessageContentSigned{
|
|
||||||
public $Content;
|
|
||||||
public $Signature;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!class_exists("MessageContent")){
|
|
||||||
class MessageContent{
|
|
||||||
public $Body;
|
|
||||||
public $Timestamp;
|
|
||||||
public $Uid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
include_once ('message-content.php');
|
|
||||||
include_once ('message-content-signed.php');
|
|
||||||
include_once ('encrypted-content.php');
|
|
||||||
|
|
||||||
if(!class_exists("SecuredContent")){
|
|
||||||
date_default_timezone_set('UTC');
|
|
||||||
|
|
||||||
class SecuredContent {
|
|
||||||
protected $encrption_key;
|
|
||||||
protected $signature_key;
|
|
||||||
protected $cipher;
|
|
||||||
|
|
||||||
public function __construct() {
|
|
||||||
/*$this->encrption_key = get_option("encrption_key");
|
|
||||||
$this->signature_key = get_option("signature_key");*/
|
|
||||||
$this->encrption_key = IPER_ENCRYPTION_KEY;
|
|
||||||
$this->signature_key = IPER_SIGNATURE_KEY;
|
|
||||||
$this->cipher = 'AES-256-CBC';
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function encode_content($raw_content)
|
|
||||||
{
|
|
||||||
$message_content = new MessageContent();
|
|
||||||
$message_content->Body = $raw_content;
|
|
||||||
$message_content->Timestamp = date('Y-m-d H:i:s', time());
|
|
||||||
$message_content->Uid = self::guid();
|
|
||||||
|
|
||||||
// create signature & pack message
|
|
||||||
$signed_message = new MessageContentSigned();
|
|
||||||
$signed_message->Content = json_encode($message_content);
|
|
||||||
$signed_message->Signature = $this->generate_signature($signed_message->Content);
|
|
||||||
|
|
||||||
// create initialization vector & encode data
|
|
||||||
$iv_size = 16;
|
|
||||||
$iv = openssl_random_pseudo_bytes($iv_size);
|
|
||||||
$key = base64_decode($this->encrption_key);
|
|
||||||
$data = json_encode($signed_message);
|
|
||||||
$padding = 16 - (strlen($data) % 16);
|
|
||||||
$data .= str_repeat(chr($padding), $padding);
|
|
||||||
$cipher_text = openssl_encrypt($data, $this->cipher, $key, OPENSSL_RAW_DATA, $iv);
|
|
||||||
|
|
||||||
// store content inside an encrypted container
|
|
||||||
$encrypted_content = new EncryptedContent();
|
|
||||||
$encrypted_content->IV = base64_encode($iv);
|
|
||||||
$encrypted_content->Data = base64_encode($cipher_text);
|
|
||||||
|
|
||||||
return $encrypted_content;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function decode_content($encrypted_string)
|
|
||||||
{
|
|
||||||
$encrypted_content = json_decode($encrypted_string);
|
|
||||||
|
|
||||||
// decode data
|
|
||||||
|
|
||||||
$key = base64_decode($this->encrption_key);
|
|
||||||
$iv = base64_decode($encrypted_content->IV);
|
|
||||||
$message = openssl_decrypt(base64_decode($encrypted_content->Data), $this->cipher, $key, OPENSSL_RAW_DATA, $iv);
|
|
||||||
$message = json_decode(substr($message, 0));
|
|
||||||
$signature = $this->generate_signature($message->Content);
|
|
||||||
|
|
||||||
return json_decode($message->Content)->Body;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function generate_signature($message_content)
|
|
||||||
{
|
|
||||||
$private_key = openssl_get_privatekey($this->signature_key);
|
|
||||||
|
|
||||||
openssl_sign($message_content, $signature, $this->signature_key, 'SHA256');
|
|
||||||
|
|
||||||
openssl_free_key($private_key);
|
|
||||||
|
|
||||||
return base64_encode($signature);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function guid()
|
|
||||||
{
|
|
||||||
if (function_exists('com_create_guid') === true)
|
|
||||||
{
|
|
||||||
return trim(com_create_guid(), '{}');
|
|
||||||
}
|
|
||||||
|
|
||||||
return sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
26
wp/wp-content/themes/medicalalert/helpers/sfconfig-prod.php
Executable file
26
wp/wp-content/themes/medicalalert/helpers/sfconfig-prod.php
Executable file
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/** Salesforce Api Url */
|
||||||
|
define("SALESFORCE_API_URL","https://connectamerica.my.salesforce-sites.com/RestServices/services/apexrest/");
|
||||||
|
|
||||||
|
/** Salesforce Brand ID */
|
||||||
|
define("SALESFORCE_BRAND","MedicalAlert");
|
||||||
|
|
||||||
|
/** Encryption key */
|
||||||
|
define("ENCRYPTION_KEY","SDaT8NmuVsEGmqlR813gmk366z9QMe6vCVqVBadqht8=");
|
||||||
|
|
||||||
|
/** Signature */
|
||||||
|
define("SIGNATURE_KEY","-----BEGIN PRIVATE KEY-----
|
||||||
|
MIICcgIBADANBgkqhkiG9w0BAQEFAASCAlwwggJYAgEAAoGAnXhO2+NRVYLOZM430aUTBSz6soc4
|
||||||
|
tJfXGaggwn8u55//K2mVkSW+jD3ofHH3YRpyPIzIs9oX1Umyz7TJQJORSBKK/qcHO2trA8yy+v7h
|
||||||
|
913Y0VPuLfLxnxvaHc1fWSAMj0zKpmR2COZ9BdfxgpIAZOUy7NfAA0Guv8r7cKEMsnkCAwEAAQKB
|
||||||
|
gAHvrJnj5H2hLfQrsaBYdRs/WivKIYaIRsL61Wr0JmRUYXkBWNn1NVptw8c38ts/oypJxDQAmVds
|
||||||
|
NbsmasJqWMMdpxia2OaPOvWDmfVp2v7pQC8d1EiqkTjlGPNQ/dJD4ngNemfTg4NL20URJ70s9Nbq
|
||||||
|
sFaaUUWgvtJKMOs7YilJAkDZsZL2Ecb9vxGpeCXKjVOZf2luavqK8SjNTNXYy52oBhg66WkfgUGU
|
||||||
|
a4OOaKy0ibx5dPfLFAaFjemLs8O8it11AkC5Lde4vYToBuJyLs8fIKqtf60Km3O7RTMfAFzjU1Hh
|
||||||
|
KDZilbFa+vsXb02FzBRH4fgmgwpI6aKc9VskDT775Ax1AkBXkCa11ba98DHxgcNpsukSj/5fjKZU
|
||||||
|
ZuZrleFaf6Rdpn3ujF5dbsdrJMfY61+0isaF8DePtvFcnRV4vQkZeJ3VAkCVp/PwrNHNx0qZJzVj
|
||||||
|
Hb5yi33o1atZjNp80ok/eyXwRtR1Ji94rN/il6RaXo2BbqFjVoIoXRF7slsfLslZP3vFAkB8FrpQ
|
||||||
|
XEvLYwhQ7OEwOinMvXK8vb37PAKXMp3pa3uPAK3pQmapmrfWC5LRweHdjeAqArbZmgGWtovRTHVo
|
||||||
|
s5qc
|
||||||
|
-----END PRIVATE KEY-----");
|
||||||
26
wp/wp-content/themes/medicalalert/helpers/sfconfig-test.php
Executable file
26
wp/wp-content/themes/medicalalert/helpers/sfconfig-test.php
Executable file
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/** Salesforce Api Url */
|
||||||
|
define("SALESFORCE_API_URL","https://connectamerica--full.sandbox.my.salesforce-sites.com/RestServices/services/apexrest");
|
||||||
|
|
||||||
|
/** Salesforce Brand ID */
|
||||||
|
define("SALESFORCE_BRAND","MedicalAlert");
|
||||||
|
|
||||||
|
/** Encryption key */
|
||||||
|
define("ENCRYPTION_KEY","potEgc8+5f32y+jpXSz/NqFEPuVWoT95V7aYiyRNjpQ=");
|
||||||
|
|
||||||
|
/** Signature */
|
||||||
|
define("SIGNATURE_KEY","-----BEGIN PRIVATE KEY-----
|
||||||
|
MIICcgIBADANBgkqhkiG9w0BAQEFAASCAlwwggJYAgEAAoGAwCSPvGdoZsC1Q4btJETb9fnkM/ne
|
||||||
|
zBA4F4f0bX3JymVZ83H9F1CTykhQWjZ8WiAuPFGHNaUESGtfr0pWF113KrY5ei910WcvcBKd1w6w
|
||||||
|
JrpUdhWC5bAgoXfLoS0itbX7TvIKrvoXcHbtAPMEDyMNv/Dy/RstNTqUBzF2fLKTwTkCAwEAAQKB
|
||||||
|
gAZuct0554sLnPBOCOFePgVFaw0OVRXRiSnIeYxcry92Ja+ku3WsqHXB5pFOd5UbX1DSOHYO4vjQ
|
||||||
|
QfCqdVKXj1CGF+5snE8elE8uuN4Y7OgZ9PBdTJ/V2gevtkYQsjtjteZn3ay3Eic1ItVWSXL4NjZh
|
||||||
|
4eso3QN+yQsfUhFAOD59AkD1W58VDN8vHWymyJebIGPwKFf6bQpUCeEJVCR5gBvz0wGEQWaLoiyJ
|
||||||
|
HGSenfpDTo9eiKWvGOnlB11wLvvatqATAkDIeg5jQvj2M6aQRr1k+UETGtjz9BN5vwwpJt+qnVbR
|
||||||
|
hypoSsBtqBMxTSbWizNzMen1JaOw/Vck8Iei4FoatrsDAkAnSZp5hmweYTnKowgToOYfyHX99YPX
|
||||||
|
3RUZp02H3wmay0jM4qQG69rxwYgjFezC5ktyubK+DOE2+SzvD7boWKHdAkBup+B1LaxZyRyxGjrE
|
||||||
|
F0iyEOmbjieJ1cgSluByPjKDqMXhlxEr9c/SMLG1TlRxyyVGKSZ3NP765sEXSBq0EBSdAkCX8h79
|
||||||
|
z9mezZxyRcdod2Sk4t1hWUf0AnLhkzfAgdQoNwY692uBYXsyKXGufLNkb+RznASmn5Lr6NanIL4c
|
||||||
|
6S9P
|
||||||
|
-----END PRIVATE KEY-----");
|
||||||
Reference in New Issue
Block a user