File: /var/www/captainschairit.com/wp-content/themes/captainschare/template-parts/confirmation-page.php
<?php
/**
* Template Name: Confirmation Page
*/
session_start();
// if(isset($_SESSION['package_info']['id'])) {
// $package_id = $_SESSION['package_info']['id'];
// $amount = $_SESSION['package_info']['amount'];
// // echo '<pre>'; print_r($post_object);
// if($package_id) {
// $base_url = get_option( 'api_base' );
// } else {
// $url = get_site_url().'/pricing';
// wp_redirect( $url );
// exit;
// }
// } else {
// $url = get_site_url().'/pricing';
// wp_redirect( $url );
// exit;
// }
// if(!isset($_SESSION['company_info']) || !isset($_SESSION['msp_chosen']) || !isset($_SESSION['billing_info'])) {
// unset($_SESSION['company_info']);
// unset($_SESSION['msp_chosen']);
// unset($_SESSION['billing_info']);
// unset($_SESSION['package_info']);
// $url = get_site_url().'/collect-data-for-msp';
// wp_redirect( $url );
// }
if(!isset($_SESSION['msp_chosen'])) {
// unset($_SESSION['company_info']);
// unset($_SESSION['msp_chosen']);
// unset($_SESSION['billing_info']);
// unset($_SESSION['package_info']);
$url = get_site_url().'/choose-connectors';
wp_redirect( $url );
}
if(!isset($_SESSION['company_info']) || !isset($_SESSION['billing_info'])) {
// unset($_SESSION['company_info']);
// unset($_SESSION['msp_chosen']);
// unset($_SESSION['billing_info']);
// unset($_SESSION['package_info']);
$url = get_site_url().'/collect-data-for-msp';
wp_redirect( $url );
}
// Creating Customer Profile
$success = array();
$error = array();
if(isset($_POST) && isset($_POST['confirm_submit']) && $_POST['confirm_submit'] == 'val_set') {
// require_once( trailingslashit( get_template_directory() ). 'create-customer-profile.php' );
session_start();
$base_url = get_option( 'api_base' );
$domain_name = $_SESSION['company_info']['company_url'];
$first_name = $_SESSION['company_info']['first_name'];
$last_name = $_SESSION['company_info']['last_name'];
$email = $_SESSION['company_info']['email'];
$phone = ($_SESSION['company_info']['phone_no'])?$_SESSION['company_info']['phone_no']:'';
$website = ($_SESSION['company_info']['web_url'])?$_SESSION['company_info']['web_url']:'';
$plan_id = 1;
$plan_type = 'annual';
$connector_id = get_post_meta($_SESSION['msp_chosen']['psa'], 'connector_id', true);
$psa_id = $connector_id;
foreach($_SESSION['msp_chosen'] as $key => $type) {
if($key == 'psa') {
$connectors = '&connectors[]='.get_post_meta($type, 'connector_id', true);
} else {
foreach($type as $ids) {
$connectors .= '&connectors[]='.get_post_meta($ids, 'connector_id', true);
}
}
}
// $pay_customer_name = $_SESSION['billing_info']['first_name'].' '.$_SESSION['billing_info']['last_name'];
$company_name = $_SESSION['billing_info']['company_name'];
// $pay_email = $_SESSION['billing_info']['email'];
// $pay_phone = $_SESSION['billing_info']['phone_no'];
$pay_address = $_SESSION['billing_info']['bill_address'];
$pay_address2 = '';
$pay_country = $_SESSION['billing_info']['bill_country'];
$pay_state = $_SESSION['billing_info']['bill_state'];
$pay_city = $_SESSION['billing_info']['bill_city'];
$pay_zip = $_SESSION['billing_info']['bill_zip'];
$pay_transaction_id = ''; //$tresponse->getTransId();
// $pay_amount = $amount;
// $pay_dt_transaction = '2020-07-28 16:16:16';
// $pay_card_type = $cc_type; //'1';
// $pay_card_number = ''; // $_SESSION['card_info']['card_no'];
// $pay_card_name = ''; // $_SESSION['card_info']['name_on_card'];
// $pay_card_expiry = ''; // $_SESSION['card_info']['exp_month'].'/'.$_SESSION['card_info']['exp_year'];
// $pay_card_cvv = ''; // $_SESSION['card_info']['cvv_no'];
// $authnet_customerProfileId = $customer_profile_id;
// $authnet_subscriptionId = $subscription_id;
// $authnet_customerPaymentProfileId = $payment_profile_id;
// echo '<pre>'; print_r($connectors); exit;
// $api = '/api/cc/setup-master-auto-provision?domain_name='.$domain_name.'&first_name='.$first_name.'&last_name='.$last_name.'&email='.$email.'&phone='.$phone.'&website='.$website.'&psa_id='.$psa_id.$connectors.'&plan_id='.$plan_id.'&send_invite=true&plan_type='.$plan_type.'&pay_customer_name='.$pay_customer_name.'&pay_company_name='.$company_name.'&pay_email='.$pay_email.'&pay_phone='.$pay_phone.'&pay_address='.$pay_address.'&pay_country='.$pay_country.'&pay_state='.$pay_state.'&pay_city='.$pay_city.'&pay_zip='.$pay_zip.'&pay_transaction_id='.$pay_transaction_id.'&pay_amount='.$pay_amount.'&pay_card_number='.$pay_card_number.'&pay_card_name='.$pay_card_name.'&pay_card_expiry='.$pay_card_expiry.'&pay_card_cvv='.$pay_card_cvv.'&pay_card_type='.$pay_card_type.'&authnet_customerProfileId='.$authnet_customerProfileId.'&authnet_subscriptionId='.$authnet_subscriptionId.'&authnet_customerPaymentProfileId='.$authnet_customerPaymentProfileId;
$api = '/api/cc/setup-master-auto-provision?domain_name='.$domain_name.'&first_name='.$first_name.'&last_name='.$last_name.'&email='.$email.'&phone='.$phone.'&website='.$website.'&psa_id='.$psa_id.$connectors.'&send_invite=true&pay_address='.$pay_address.'&pay_country='.$pay_country.'&pay_state='.$pay_state.'&pay_city='.$pay_city.'&pay_zip='.$pay_zip;
$request_body = '';
// echo $api; exit;
$args_business_listings = array(
'timeout' => 120,
'redirection' => 5,
'httpversion' => '1.0',
'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url(),
// 'blocking' => true,
'headers' => array('Accept' => 'application/json', 'Content-Type' => 'application/json'),
// 'cookies' => array(),
'body' => json_encode($request_body),
);
$reasult = wp_remote_post($base_url . $api, $args_business_listings);
// $parsed_ststes = json_decode(wp_remote_retrieve_body($states), true);
$response_body = json_decode(wp_remote_retrieve_body($reasult), true);
// $response_body['status'] = "success";
// echo $api.'<pre>'; print_r($reasult); print_r($response_body); exit;
// $response = createCustomerProfile($_SESSION['company_info']['email'], $_SESSION['billing_info'], $_SESSION['card_info'], $_SESSION['company_info'], $_SESSION['package_info']);
// echo '<pre>'; print_r($response->getMessages()->getMessage());
// echo 'here'; exit;
if (($response_body['status'] == "success")) {
// Salesforce Start
$oid = "00D1N000002J5G7";
//create array of data to be posted
$ch_register_first_name = $first_name;
$ch_register_last_name = $last_name;
// $title = $_GET['answer_1'];
$ch_register_phone = $phone;
$ch_register_email = $email;
$company = $company_name;
// if($_GET['answer_5'] == 'Marketopia' || $_GET['answer_5'] == 'marketopia') {
$lead_source = ($_SESSION['company_info']['lead_source'])?$_SESSION['company_info']['lead_source']:'Website';
// } else {
// $lead_source = 'Website';
// }
// $mobile = $_GET['text_reminder_number'];
// Salesforce Call
$url = 'https://webto.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8';
$fields = array(
'first_name'=>urlencode($ch_register_first_name),
'last_name'=>urlencode($ch_register_last_name),
// 'title'=>urlencode($title),
'company'=>urlencode($company),
'email'=>urlencode($ch_register_email),
'00N1N00000Fa1h9'=>urlencode('Managed Services'),
// 'member_status'=>urlencode('Scheduled_Demo'),
'phone'=>urlencode($ch_register_phone),
// 'mobile'=>urlencode($mobile),
'lead_source'=>urlencode($lead_source),
'rating'=>urlencode('5'),
// 'mycustomefieldid' => urlencode($ch_register_dob), // custom field
'oid' => urlencode($oid) // insert with your id
// 'retURL' => urlencode('https://captainschairit.com/thank-you') // sending this just in case
// 'debug' => '1',
// 'debugEmail' => urlencode("shieldwatch006@gmail.com"), // your debugging email
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION, TRUE);
//execute post
echo $result = curl_exec($ch);
// echo '<pre>'; print_r($result); exit;
// echo curl_errno($url) . '-' . curl_error($url);
//close connection
curl_close($ch);
// HERE YOU CAN ADD ANY BUSINESS REQUIREMENT,
//FOR EXAMPLE:
//1) INSERT THE LEADS DATA TO YOUR MYSQL DATABASE
//2) SEND THE EMAIL, etc
//Salesforce end
confirmation_email_free_trial($first_name, $last_name, $email);
// Unseting Session
unset($_SESSION['pricing_msp']);
unset($_SESSION['company_info']);
unset($_SESSION['msp_chosen']);
unset($_SESSION['billing_info']);
// unset($_SESSION['package_info']);
// unset($_SESSION['card_info']);
$url = get_site_url().'/thank-you-confirmation';
wp_redirect( $url );
exit;
} else {
$error[] = 'Something went wrong, please try again.';
}
}
get_header();
$page_heading = get_field('page_heading');
$content_heading = get_field('content_heading');
$content_part = get_field('content_part');
?>
<!-- Services -->
<section class="page-section msp-menu-top msp-page-section" id="CompanyInfo">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2 class="heading01 mb-5"><?php echo $page_heading; ?></h2>
</div>
<div class="col-sm-12">
<div class="msp-tab">
<?php require_once( trailingslashit( get_template_directory() ). 'template-parts/order-tabs.php' ); ?>
<div class="msp-tab-body">
<div class="col-lg-12">
<?php if(count($error) > 0) { ?>
<div class="alert alert-danger mb-5 mt-5" role="alert">
<?php foreach($error as $msg) {
echo $msg.'<br>';
// echo '<pre>'; print_r($msg);
} ?>
</div>
<?php
} ?>
<div class="confirmation-page mb-5">
<h2 class="mb-3"><?php echo $content_heading; ?></h2>
<?php echo $content_part; ?>
<div class="row equal-height-conf">
<div class="col-sm-6">
<h2>Contact Details</h2>
<p><?php echo $_SESSION['company_info']['company_url']; ?>.captainschair.app</p>
<p><?php echo $_SESSION['company_info']['first_name'].' '.$_SESSION['company_info']['last_name']; ?></p>
<p><?php echo $_SESSION['company_info']['email']; ?></p>
<p><?php echo $_SESSION['company_info']['phone_no']; ?></p>
<p><?php echo $_SESSION['company_info']['web_url']; ?></p>
</div>
<?php
$args = array(
'posts_per_page' => -1,
'orderby' => 'date',
'order' => 'ASC',
'post_type' => 'cc-connectors',
'post_status' => 'publish',
);
$all_connectors = get_posts( $args );
// echo '<pre>'; print_r ($all_connectors); echo '</pre>';
$terms = get_terms( array(
'taxonomy' => 'cc-connector-types',
'hide_empty' => false,
));
// echo '<pre>'; print_r ($_SESSION['msp_chosen']); echo '</pre>';
?>
<div class="col-sm-6">
<h2>Connectors</h2>
<?php
foreach($terms as $term) {
// $term_obj = get_term_by();
if($term->slug != 'psa') {
// echo '<pre>'; print_r ($_SESSION['msp_chosen']['other_'.$term->name]); echo '</pre>';
$slugs_from_session = array_keys( $_SESSION['msp_chosen']);
if(in_array($term->slug, $slugs_from_session)) {
// echo '<pre>'; print_r($term); ?>
<p>
<b> <?php echo $term->name; ?></b>
<?php $names = array();
foreach($all_connectors as $connector) {
// echo '<pre>'; print_r($key);
if(in_array($connector->ID, $_SESSION['msp_chosen'][$term->slug])) {
// echo '<pre>'; print_r($connector);
$names[] = $connector->post_title; ?>
<!-- ConnectWise Automate, Microsoft O365 -->
<?php
}
} ?>
</p>
<?php
echo implode(', ', $names);
}
echo ($_SESSION['msp_chosen']['other_'.$term->name])?'<p><strong>Other '.$term->name.': </strong>'.$_SESSION['msp_chosen']['other_'.$term->name].'<p>':'';
} else if($term->slug == 'psa') { ?>
<p>
<b> <?php echo $term->name; ?></b>
<?php foreach($all_connectors as $connector) {
// echo '<pre>'; print_r($key);
if($connector->ID == $_SESSION['msp_chosen']['psa']) {
// echo '<pre>'; print_r($connector);
echo $connector->post_title.' '; ?>
<!-- ConnectWise Automate, Microsoft O365 -->
<?php
}
} ?>
</p>
<?php } else {
echo ($_SESSION['msp_chosen']['other_'.$term->name])?'<p><strong>Other: </strong>'.$_SESSION['msp_chosen']['other_'.$term->name].'<p>':'';
}
} ?>
</div>
</div>
<div class="row equal-height-conf">
<div class="col-sm-6">
<h2>plan</h2>
</p>30-day Preview</p>
<!-- <p><?php //echo $_SESSION['package_info']['name']; ?> -->
<!-- <span class="float-right">$<?php //echo number_format($_SESSION['package_info']['amount'], 2, '.', ''); ?></span></p> -->
<!-- <p><?php //echo $_SESSION['package_info']['free_trial']; ?> Days Trial</p> -->
</div>
</div>
</div>
<form action="" method="POST">
<div class="text-center">
<a href="<?php echo get_site_url(); ?>/choose-connectors" class="btn btn-gray btn-rounded hvr-shutter-out-horizontal text-transform">Back</a>
<input type="hidden" name="confirm_submit" value="val_set">
<button type="submit" class="btn btn-primary btn-rounded hvr-shutter-out-horizontal text-transform" id="plan_confirmed">Confirm</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<?php
get_footer();
?>