Files
medicalalert-web-reloaded/wp/wp-content/plugins/iper-medical/templates/template-order.php
Rachit Bhargava 5d0f0734d8 first commit
2023-07-21 17:12:10 -04:00

694 lines
24 KiB
PHP

<?php
session_start();
foreach($_POST as $k=>$v) {
$_SESSION[$k]=$v;
}
$creditcard_type = $_POST['creditcard_type'];
if ($creditcard_type == 'visa') {
$creditcard_type = 'Visa';
}
iper_hook_css();
get_header('product');
global $wpdb;
$_POST["firstName_shipping"] = strip_tags($_POST["firstName_shipping"]);
$_POST["lastName_shipping"] =strip_tags($_POST["lastName_shipping"]);
$_POST["address1_shipping"] =strip_tags($_POST["address1_shipping"]);
$_POST["address2_shipping"] =strip_tags($_POST["address2_shipping"]);
$_POST["city_shipping"] =strip_tags($_POST["city_shipping"]);
$_POST["state_shipping"] =strip_tags($_POST["state_shipping"]);
$_POST["zip_shipping"] =strip_tags($_POST["zip_shipping"]);
$_POST["zip_shipping"] =strip_tags($_POST["zip_shipping"]);
$_POST["country_shipping"] =strip_tags($_POST["country_shipping"]);
$_POST["phone_shipping"] =strip_tags($_POST["phone_shipping"]);
$_POST["lastName_billing"] =strip_tags($_POST["lastName_billing"]);
$_POST["firstName_billing"] =strip_tags($_POST["firstName_billing"]);
$_POST["phone_billing"] =strip_tags($_POST["phone_billing"]);
$_POST["address1_billing"] =strip_tags($_POST["address1_billing"]);
$_POST["address2_billing"] =strip_tags($_POST["address2_billing"]);
$_POST["email_shipping"] =strip_tags($_POST["email_shipping"]);
$_POST["city_billing"] =strip_tags($_POST["city_billing"]);
$_POST["state_billing"] =strip_tags($_POST["state_billing"]);
$_POST["zip_billing"] =strip_tags($_POST["zip_billing"]);
$_POST["country_billing"] =strip_tags($_POST["country_billing"]);
$_POST["creditcard_name"] =strip_tags($_POST["creditcard_name"]);
$_POST["creditcard_type"] =strip_tags($_POST["creditcard_type"]);
$_POST["creditcard_number"] =strip_tags($_POST["creditcard_number"]);
$_POST["creditcard_month"] =strip_tags($_POST["creditcard_month"]);
$_POST["creditcard_year"] =strip_tags($_POST["creditcard_year"]);
$_POST["gclid_field"] =strip_tags($_POST["gclid_field"]);
$_POST["gCard"] =strip_tags($_POST["gCard"]);
$_POST["subid1"] =strip_tags($_POST["subid1"]);
$_POST["subid2"] =strip_tags($_POST["subid2"]);
$_POST["subid3"] =strip_tags($_POST["subid3"]);
$_POST["subid4"] =strip_tags($_POST["subid4"]);
$post_medical_shipping = array(
$_POST["firstName_shipping"],
$_POST["lastName_shipping"],
$_POST["address1_shipping"],
$_POST["city_shipping"],
$_POST["state_shipping"],
$_POST["zip_shipping"],
$_POST["email_shipping"],
$_POST["country_shipping"],
$_POST["phone_shipping"],
$_POST["lastName_billing"],
$_POST["firstName_billing"],
$_POST["phone_billing"],
$_POST["address1_billing"],
$_POST["email_shipping"],
$_POST["city_billing"],
$_POST["state_billing"],
$_POST["zip_billing"],
$_POST["country_billing"],
$_POST["creditcard_name"],
$_POST["creditcard_type"],
$_POST["creditcard_number"],
$_POST["creditcard_year"],
$_POST["creditcard_month"],
$_POST["gclid_field"],
$_POST["gCard"],
$_POST["subid1"],
$_POST["subid2"],
$_POST["subid3"],
$_POST["subid4"],
$_POST["subid4"]
);
$expiration_credit_card_date = $_POST["cc_date"];
foreach($post_medical_shipping as $post_medical){
if(!$post_medical && $post_medical!=''){ header('Location: '.get_permalink($config['id_medical_shipping'])); }
}
$orderID=md5("iperdesign|".microtime());
$_SESSION["md_profile"]=array(
"first_name"=>$_POST["firstName_billing"],
"last_name"=>$_POST["lastName_billing"],
);
/**
* @param $AccessoryID
* @param $Quantity
* @return array
*/
function createAccessory($AccessoryID,$Quantity, $ProgrammingFee){
$Accessory= array(
"AccessoryID" => $AccessoryID,
"Price" => $ProgrammingFee,
"Quantity" => $Quantity
);
return $Accessory;
}
/**
* @param $PaymentType
* @param $CardholderName
* @param $CardType
* @param $CardNumber
* @param $CVV
* @param $AccountHolderName
* @param $AccountType
* @param $AccountNumber
* @param $RoutingNumber
* @return array
*/
function createPaymentInformation($PaymentType,$CardholderName,$CardType,$CardNumber,$ExpDate, $CVV=NULL,$AccountHolderName=NULL,$AccountType=NULL,$AccountNumber=NULL,$RoutingNumber=NULL){
if($CardType=="American" ){
$CardType = "American Express";
}
if($CardType=="Master" ){
$CardType = "MasterCard";
}
$PaymentInformation = array(
"PaymentType" => $PaymentType
,"CardholderName" => $CardholderName
,"CardType" => $CardType
,"CardNumber" => $CardNumber
,"ExpirationDate" => $ExpDate
);
return $PaymentInformation;
}
$objPaymentInformation=createPaymentInformation("Credit Card",$_POST["creditcard_name"], $_POST["creditcard_type"], $_POST["creditcard_number"], $expiration_credit_card_date);
/**
* @param $ProductID
* @param $Quantity
* @param $RatePlanID
* @param $PromotionID
* @param $Accessories
* @return array
*/
function createOrderProduct($ProductID,$Quantity,$RatePlanID, $PromotionID=null ,$Accessories=null){
$OrderProduct= array(
"ProductID" => $ProductID
, "Quantity" => $Quantity
, "RatePlanID" => $RatePlanID
, "PromotionID" => $PromotionID
, "Accessories" => $Accessories
);
if(!$PromotionID){
unset($OrderProduct["PromotionID"]);
}
if(is_null($Accessories)){
unset($OrderProduct["Accessories"]);
}
return $OrderProduct;
}
$aProductPromotion=$_SESSION['PromotionID'];
$aProductAccessories=array($_SESSION['Accessories']);
$aProductUpsells=$_SESSION['Upsells'];
foreach($_SESSION["iper_cart"]["products"] as $single){
$aProduct=$single;
}
$accessories=NULL;
$arrAccessories=array();
if(!empty($aProductAccessories)){
$accessories=array();
$i = 0;
foreach($aProductAccessories[0] as $key => $value){
$AccessoryID = $value[0];
$ProgrammingFee = $value[2];
$accessories[]=createAccessory($AccessoryID,1,$ProgrammingFee);
$arrAccessories[]=$single;
}
}
$aRatePlan=$_SESSION['RatePlanID'];
$dbProduct=$_SESSION['ProductName'];
$orderProducts=array(
createOrderProduct($_SESSION['ProductID'], 1, $aRatePlan, $aProductPromotion, $accessories)
);
$arrUpsells=array();
if(!empty($aProductUpsells)){
foreach($aProductUpsells as $single){
$aUpsell=$single[0];
$arrUpsells[]=$aUpsell;
$orderProducts[]=createOrderProduct($aUpsell, 1, $aRatePlan, $single[4]);
}
}
/**
* @param $Name
* @param $Phone
* @param $Street1
* @param $Street2
* @param $City
* @param $State
* @param $PostalCode
* @param $Country
* @return array
*/
function createAddress($FirstName, $LastName, $Phone, $Street1, $Street2, $City, $State,$PostalCode,$Country){
$Address = array(
"FirstName" => $FirstName
, "LastName" => $LastName
, "Phone" => $Phone
, "Street1" => $Street1
, "Street2" => $Street2
, "City" => $City
, "State" => $State
, "PostalCode" => $PostalCode
, "Country" => $Country
);
return $Address;
}
function fix_dash($num){
$number = $num;
$number = str_replace("-","",$number);
$number = str_split($number);
$number1 = array_slice($number, 0, 3);
array_push($number1, '-');
$number2 = array_slice($number, 3, 3);
array_push($number2, '-');
$number3 = array_slice($number, 6, 4);
$number = array_merge($number1, $number2, $number3);
$number = implode('', $number);
return $number;
}
$phone_shipping = $_POST["phone_shipping"];
$phone_billing = $_POST["phone_billing"];
$phone_shipping = fix_dash($phone_shipping);
$phone_billing = fix_dash($phone_billing);
$objAddressShipping=createAddress(rtrim($_POST["firstName_shipping"]), rtrim($_POST["lastName_shipping"]),$phone_shipping, $_POST["address1_shipping"],
$_POST["address2_shipping"],$_POST["city_shipping"],$_POST["state_shipping"],$_POST["zip_shipping"],$_POST["country_shipping"]);
$objAddressBilling=createAddress(rtrim($_POST["firstName_billing"]), rtrim($_POST["lastName_billing"]),$phone_billing,$_POST["address1_billing"],
$_POST["address2_billing"],$_POST["city_billing"],$_POST["state_billing"],$_POST["zip_billing"],$_POST["country_billing"]);
/**
* @param $CustomerFirstName
* @param $CustomerLastName
* @param $CustomerEmail
* @param $CustomerPhoneNumber
* @param $DiscountCode
* @param $MarketingCampaign
* @param $ShippingID
* @param $PaymentInformation
* @param $ShippingInformation
* @param $BillingInformation
* @param $OrderProducts
* @return array
*/
function createOrder($CustomerFirstName,$CustomerLastName,$CustomerEmail,$CustomerPhoneNumber,$gclid_field,$control,$subid1,$subid2,$subid3,$subid4,$DiscountCode,$MarketingCampaign,$ShippingID,$PaymentInformation,$ShippingInformation,$BillingInformation,$OrderProducts){
if(isset($_COOKIE['SESSabtest']) && $_COOKIE['SESSabtest']== "1" ) {
$control = "Control";
}
$Order = array(
"CustomerFirstName" => $CustomerFirstName
, "CustomerLastName" => $CustomerLastName
, "CustomerEmail" => $CustomerEmail
, "CustomerPhoneNumber" => $CustomerPhoneNumber
, "GCLID" => $gclid_field
, "UserExperience" => $control
, "CustomField1" => $subid1
, "CustomField2" => $subid2
, "CustomField3" => $subid3
, "CustomField4" => $subid4
, "MarketingCampaign" => IperCampaignController::getCampaignID()!=null?IperCampaignController::getCampaignID():"ecom campaign"
, "ShippingID" => $ShippingID
, "PaymentInformation" => $PaymentInformation
, "ShippingInformation" => $ShippingInformation
, "BillingInformation" => $BillingInformation
, "OrderProducts" => $OrderProducts
);
return $Order;
}
$shippingPackage = explode(',',$_POST["shippingType"]);
$idShipping=$shippingPackage[1];
$shippingPrice=$shippingPackage[0];
$objOrder=createOrder($_POST["firstName_shipping"], $_POST["lastName_shipping"] , $_POST["email_shipping"], $phone_shipping, $_POST["gclid_field"], $_POST["control"],$_POST["subid1"] , $_POST["subid2"] , $_POST["subid3"] , $_POST["subid4"] , NULL, NULL, $idShipping, $objPaymentInformation, $objAddressShipping,$objAddressBilling,$orderProducts);
/**
* @param $RequestHeader
* @param $RequestBody
* @param $ResumeID
* @return array
*/
/**
* @return array
*/
function orderLogs($result) {
$ups1 = $_SESSION['Upsells'][0][2];
$ups2 = $_SESSION['Upsells'][1][2];
$op_id = $_SESSION['Opportunity_ID_Profile_Page'];
$firstname = $_POST['firstName_shipping'];
$lastname = $_POST['lastName_shipping'];
$phone = $_POST["phone_shipping"];
$email = $_POST['email_shipping'];
$productsel = $_SESSION['Package']['productName'];
$rateplansel = $_SESSION['Package']['ratePlan'];
global $wpdb;
$table_name = $wpdb->prefix . "ecom_log";
$wpdb->insert($table_name, array(
'id' => insert_id,
'sfdc_id' => $op_id,
'first_name' => $firstname,
'last_name' => $lastname,
'phone' => $phone,
'email' => $email,
'product' => $productsel,
'rateplan' => $rateplansel,
'upsell1' => $ups1,
'upsell2' => $ups2,
'order_date' => date("Y-m-d H:i:s"),
'res_text' => $result
));
return $orderlogs;
}
function createRequestHeader(){
$RequestHeader = array(
"RequestID" =>"Request_".microtime()
);
return $RequestHeader;
}
function createOrderRequest($order,$request, $resume_id){
$order_request = array(
"RequestHeader"=>$request,
"RequestBody"=>$order,
"ResumeID" => $resume_id
);
if(is_null($resume_id) || empty($resume_id) || $resume_id==''){
unset($order_request["ResumeID"]);
}
return $order_request;
}
function createProfile($FirstName, $LastName, $Country_shipping, $Street1, $Street2, $City, $State, $PostalCode, $Mail, $Phone){
$Profile = array(
"Name" => $FirstName
, "LastName" => $LastName
, "Country" => $Country_shipping
, "Street1" => $Street1
, "Street2" => $Street2
, "City" => $City
, "State" => $State
, "PostalCode" => $PostalCode
, "Mail" => $Mail
, "Phone" => $Phone
);
return $Profile;
}
$objProfile=createProfile($_POST["firstName_shipping"], $_POST["lastName_shipping"], $_POST["country_shipping"], $_POST["address1_shipping"],$_POST["address2_shipping"], $_POST["city_shipping"],$_POST["state_shipping"],$_POST["zip_shipping"], $_POST['email_shipping'], $phone_shipping );
$_SESSION['shipping_info']=$objProfile;
$req=createOrderRequest($objOrder,createRequestHeader(), $_SESSION['Opportunity_ID_Profile_Page']);
$sf=new IperSalseforceSync(IperSalseforceSync::kACTION_ORDER_CREATE,$req, "POST");
$res=json_decode(json_decode($sf->sendRequest()));
$error_response = serialize($res->ErrorList);
foreach($res->ErrorList as $errorinlist){
if(strpos($errorinlist, 'OpportunityID') !== false){
$errorinlist1 = str_replace('OpportunityID=', '', $errorinlist);
$_SESSION['Opportunity_ID_Profile_Page'] = $errorinlist1;
}
}
if($res->ResponseBody){
$_SESSION['Opportunity_ID_Profile_Page'] = $res->ResponseBody;
}
function check_card_error_presence($x){
$e_1 = array(
'Customer account is in the “known bad” account list (EFT only)',
'Void/capture and original transaction types do not agree (CC/EFT)',
'Transaction was previously voided or captured',
'Void or Capture failed',
'Credit card number is invalid',
'Date is malformed',
'Swipe data is malformed',
'Malformed expiration date',
'Negative amount',
'Invalid data present in transaction',
'Transaction was declined due to preauthorization (ATM Verify) result',
'Preauthorizer not responding (Verify Only transactions only)',
'Preauthorizer error (Verify Only transactions only)',
'Transaction was declined due to authorizer declination',
'Authorizer not responding',
'Authorizer error',
'Authorizer AVS check failed',
'Authorizing Vendor busy, may be resubmitted (CC only)');
$result_presence = 0;
foreach($e_1 as $error){
if(strpos($x, $error) !== false){
$result_presence += 1;}
}
return $result_presence;
}
function check_general_error_presence($x){
$e_1 = array(
"CustomerFirstName was null",
"CustomerLastName was null",
"CustomerEmail was null",
"Street1 was null",
"City was null",
"State was null",
"PostalCode was null",
"Country was null",
"Street1 was null",
"City was null",
"State was null",
"PostalCode was null",
"Country was null",
"CardholderName was null",
"CardType provided is invalid",
"CardNumber was null");
$result_presence = 0;
foreach($e_1 as $error){
if(strpos($x, $error) !== false){
$result_presence += 1;}
}
return $result_presence;
}
$result_card_presence_error = check_card_error_presence($error_response);
$result_general_error_presence = check_general_error_presence($error_response);
global $response;
if(isset($res->ResponseBody) && $res->ResponseBody !=''){
$res_text = 'Success';
$response = 'Success';
}
if(!isset($res->ResponseBody) || $res->ResponseBody ==''){
slack();
$res_text = 'Failed';
$response = 'Failed';
}
function slack() {
global $error_response;
$pantheon_env = $_ENV['PANTHEON_ENVIRONMENT'];
$sf_status = $error_response;
$slack_message = $sf_status;
if ($pantheon_env == 'live') {
$slack_webhook_url = 'https://hooks.slack.com/services/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'; // #medicalalert-order
} else {
$slack_webhook_url = 'https://hooks.slack.com/services/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'; // #medicalalert-order-qa
}
$slack_data = array(
'text' => $slack_message
);
$slack_data_string = json_encode( $slack_data );
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $slack_webhook_url );
curl_setopt( $ch, CURLOPT_POST, 1 );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $slack_data_string );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen( $slack_data_string )
) );
$result = curl_exec( $ch );
curl_close( $ch );
}
orderLogs($response);
if($_SERVER["REMOTE_ADDR"]=='79.3.196.80'):
?>
<?php endif; ?>
<div class="container">
<?php if(is_user_logged_in()){ ?>
<br>
<span class="_result"><?php echo $res_text; ?></span>
<button class="tmp_btn" data-target="#responses" data-toggle="collapse" data-responses = "<?php echo $res_text; ?>">See the Response</button>
<div id="responses" class="collapse">
<div class="req">
<h2>Request</h2>
<?php echo json_encode($req); ?>
</div>
<div class="res">
<h2>Response</h2>
<?php echo json_encode($res); ?>
</div>
</div>
<?php } else { ?>
<script>
jQuery(".tmp_btn, ._result").hide();
</script>
<?php } ?>
<div class="row">
<div class="col-md-12">
<br>
<div class="header-thank">
<?php if(!isset($response) || $response =='Failed'){ ?>
<h1 class="error-title-page">We're sorry, there was an error processing your request.</h1>
<h2 class="error-title-page">To complete you order, please call <?php echo do_shortcode('[op]') ?> and provide the Order ID below.</h2>
<div> </div>
<?php } else { ?>
<h2 class="title-page cblue">Thanks for your order!</h2>
<h1 class="big-title-page cblue">Now, set up your profile:</h1>
<a href="<?php echo get_permalink($config['id_medical_profile']); ?>" title="Create Profile" class="et_pb_button et_pb_button_1 btn-red-learnmore btn_to_continue">Create Profile</a>
<p>Setting up your profile now will save you time when your receive and set up your system.</p>
<br>
<?php } ?>
</div>
<hr>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="header-thank">
<h2 class="big-title-page cblue">Order Details:</h2>
<p>Ordered On: <?php echo date("F jS, Y") ;?> <a href="#" title="Print page" class="print_icon" onclick="window.print();"><i class="fa fa-print"></i></a></p>
</div>
</div>
</div>
<div id="iperOderDetailFinalSummary" class="row detail-order-row">
<div class="shipping-address col-sm-12 col-md-6">
<h2 class="title-page cblue">Shipping Address</h2>
<p><strong>Name: </strong><span class="price_o pull-right"><?php echo $_POST["firstName_shipping"].' '.$_POST["lastName_shipping"]; ?></span></p>
<p><strong>Address 1: </strong><span class="price_o pull-right"><?php echo $objAddressShipping['Street1']; ?></span></p>
<p><strong>Address 2: </strong><span class="price_o pull-right"><?php echo $objAddressShipping['Street2']; ?></span></p>
<p><strong>City: </strong><span class="price_o pull-right"><?php echo $objAddressShipping["City"]; ?></span></p>
<p><strong>State: </strong><span class="price_o pull-right"><?php echo $objAddressShipping["State"];?></span></p>
<p><strong>Postal Code: </strong><span class="price_o pull-right"><?php echo $objAddressShipping['PostalCode']; ?></span></p>
<p><strong>Phone: </strong><span class="price_o pull-right"><?php echo $objAddressShipping['Phone']; ?></span></p>
<p><strong>Email: </strong><span class="price_o pull-right"><?php echo $objOrder['CustomerEmail']; ?></span></p>
</div>
<div class="order-summary col-sm-12 col-md-6">
<h2 class="title-page cblue">Order Summary</h2>
<div>
<p><strong>Payment Details</strong>
<span class="price priceme pull-right"><?php echo $objPaymentInformation["CardType"]; ?> ***<?php echo substr($objPaymentInformation["CardNumber"],strlen($objPaymentInformation["CardNumber"])-4,4);?></span></p>
<p><strong>Order ID</strong><span class="price priceme pull-right"><?php echo $_SESSION['Opportunity_ID_Profile_Page']; ?></span></p>
<p><strong><?php echo $_SESSION['Package']['productName']; ?></strong></p>
<p><?php echo $_SESSION['Package']['ratePlan']; ?><span class="price priceme pull-right">$<?php echo $_SESSION['Package']['product_rate_price']; ?></span></p>
</div>
<?php if(!empty($_SESSION['Upsells'])){ ?>
<div>
<?php foreach($_SESSION['Upsells'] as $single): ?>
<p><?php echo $single[2]; ?>
<span class="price_o pull-right">$<?php echo $single[3];?></span></p>
<?php endforeach; ?>
</div>
<?php } ?>
<p>Programming Fee<span class="price_o pull-right">$79.00</span></p>
<?php
$total = floatval($_SESSION['Package']['totalPrice']);
$final_price = $total+$shippingPrice;
$final_priceAsString = number_format($final_price, 2);
?>
<p>Item(s) Subtotal<span class="price_o pull-right">$<?php echo $_SESSION['Package']['totalPrice'];?></span></p>
<p>Shipping & Handling<span class="price_o pull-right">$<?php echo $shippingPrice;?></span></p>
<p><strong>Grand Total</strong><span class="price_o pull-right">$<?php echo $final_priceAsString;?></span></p>
</div>
</div>
<br>
</div>
<?php $opportunity_id = $_SESSION['Opportunity_ID_Profile_Page'];?>
<script>
(function($) {
$res = $('.tmp_btn');
$( document ).ready(function(){
if($res.attr('data-responses')=='Failed'){
console.log('ciao');
$btn_next = $('.btn_to_continue');
$btn_next.removeAttr('href');
}
});
})(jQuery);
</script>
<?php include($ABS_path . "/footer.php");
get_footer();