File: /var/www/dev.captainschairit.com/wp-content/themes/captainschare/template-parts/payment-page.php
<?php
/**
* Template Name: Payment page
*/
global $Countries;
// echo '<pre>'; print_r($Countries);
session_start();
// if(isset($_GET['id'])) {
// $package_id = $_GET['id'];
// $package_type = $_GET['type'];
// // echo '<pre>'; print_r($post_object);
// if($package_id) {
// // $_SESSION['package_info']['id'] = $post_object->ID;
// // $_SESSION['package_info']['name'] = $post_object->post_title;
// // $_SESSION['package_info']['slug'] = $post_object->post_name;
// // $amount = get_field('amount', $post_object->ID);
// // $free_trial = get_field('free_trial', $post_object->ID);
// // $contract_term = get_field('contract_term', $post_object->ID);
// // $client_licenses = get_field('client_licenses', $post_object->ID);
// // $_SESSION['package_info']['amount'] = $amount;
// // $_SESSION['package_info']['free_trial'] = $free_trial;
// // $_SESSION['package_info']['contract_term'] = $contract_term;
// // $_SESSION['package_info']['client_licenses'] = $client_licenses;
// $base_url = get_option( 'api_base' );
// $api = '/api/cc/get-subcription-plans?detail_id='.$package_id;
// $request_body = '';
// $args_plan_details = 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_plan_details);
// // $parsed_ststes = json_decode(wp_remote_retrieve_body($states), true);
// $response_body = json_decode(wp_remote_retrieve_body($reasult), true);
// // echo $api.'<pre>'; print_r($response_body['data'][0]['s_plan_name']); exit;
// if(isset($response_body['data'][0])) {
// $_SESSION['package_info']['id'] = $package_id;
// $_SESSION['package_info']['package_type'] = $package_type;
// $_SESSION['package_info']['name'] = $response_body['data'][0]['s_plan_name'];
// // $_SESSION['package_info']['slug'] = $post_object->post_name;
// // $amount = get_field('amount', $post_object->ID);
// // $free_trial = get_field('free_trial', $post_object->ID);
// // $contract_term = get_field('contract_term', $post_object->ID);
// // $client_licenses = get_field('client_licenses', $post_object->ID);
// if($package_type == 'annual') {
// $_SESSION['package_info']['amount'] = number_format($response_body['data'][0]['d_price'], 2);
// $_SESSION['package_info']['free_trial'] = $response_body['data'][0]['i_trial_periods'];
// } else if($package_type == 'monthly') {
// $_SESSION['package_info']['amount'] = $response_body['data'][0]['d_price_monthly'];
// $_SESSION['package_info']['free_trial'] = $response_body['data'][0]['i_trial_periods_monthly'];
// }
// $_SESSION['package_info']['contract_term'] = $response_body['data'][0]['s_contract_term'];
// $_SESSION['package_info']['client_licenses'] = $response_body['data'][0]['i_client_licenses'];
// } else {
// $err = 'No dara found';
// }
// } else {
// $url = get_site_url().'/choose-plan';
// wp_redirect( $url );
// exit;
// }
// } else {
// $url = get_site_url().'/choose-plan';
// wp_redirect( $url );
// exit;
// }
// Storing payment info
// if(!empty($_POST)) {
// echo '<pre>'; print_r($_POST); exit;
// }
if(empty($_SESSION['msp_chosen'])) {
$url = get_site_url().'/choose-connectors';
wp_redirect( $url );
exit;
}
get_header();
$page_heading = get_field('page_heading');
$content_part = get_field('content_part');
?>
<!-- Services -->
<section class="page-section msp-menu-top" 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 mt-5">
<?php require_once( trailingslashit( get_template_directory() ). 'template-parts/order-tabs.php' ); ?>
<div class="msp-tab-body">
<div class="col-lg-12">
<?php echo $content_part; ?>
<form action="<?php echo get_site_url(); ?>/confirm-order" method="POST" id="payment_form">
<div class="row equal-height-payment mt-5 pt-5 mb-5">
<div class="col-lg-5 col-md-12 equal-height-boder">
<h2 class="mb-5">Billing Info</h2>
<div class="row">
<div class="col-lg-12">
<div class="form-group form-placeholder">
<input type="text" class="form-control " placeholder="Company Name" name="company_name" value="<?php echo (isset($_SESSION['billing_info']['company_name']))?$_SESSION['billing_info']['company_name']:''; ?>" id="company_name">
<label class="placeholder-label">Company Name <span>*</span></label>
</div>
</div>
<div class="col-lg-6 col-md-6">
<div class="form-group form-placeholder">
<input type="text" class="form-control " placeholder="First Name" name="first_name" value="<?php echo (isset($_SESSION['billing_info']['first_name']))?$_SESSION['billing_info']['first_name']:$_SESSION['company_info']['first_name']; ?>" id="first_name">
<label class="placeholder-label">First Name <span>*</span></label>
</div>
</div>
<div class="col-lg-6 col-md-6">
<div class="form-group form-placeholder">
<input type="text" class="form-control " placeholder="Last Name" name="last_name" value="<?php echo (isset($_SESSION['billing_info']['last_name']))?$_SESSION['billing_info']['last_name']:$_SESSION['company_info']['last_name']; ?>" id="last_name">
<label class="placeholder-label">Last Name <span>*</span></label>
</div>
</div>
<div class="col-lg-12">
<div class="form-group form-placeholder">
<input type="text" class="form-control " placeholder="Email" name="email" value="<?php echo (isset($_SESSION['billing_info']['email']))?$_SESSION['billing_info']['email']:$_SESSION['company_info']['email']; ?>" id="email">
<label class="placeholder-label">Email <span>*</span></label>
</div>
</div>
<div class="col-lg-12">
<div class="form-group form-placeholder">
<input type="text" class="form-control " placeholder="phone_no" name="phone_no" value="<?php echo (isset($_SESSION['billing_info']['phone_no']))?$_SESSION['billing_info']['phone_no']:$_SESSION['company_info']['phone_no']; ?>" id="phone_no" maxlength="10">
<label class="placeholder-label">Phone No <span>*</span></label>
</div>
</div>
<div class="col-lg-12">
<div class="form-group form-placeholder">
<input type="text" class="form-control " placeholder="Address" name="bill_address" value="<?php echo (isset($_SESSION['billing_info']['bill_address']))?$_SESSION['billing_info']['bill_address']:''; ?>" id="bill_address" maxlength="60">
<label class="placeholder-label">Address <span>*</span></label>
</div>
</div>
<div class="col-lg-6 col-md-6">
<div class="form-group form-placeholder">
<!-- <input type="text" class="form-control " placeholder="Country Town/City"> -->
<select class="form-control" name="bill_country" id="bill_country">
<option value=""></option>
<?php foreach($Countries as $code=>$country) { ?>
<option value="<?php echo $code; ?>" <?php selected( $_SESSION['billing_info']['bill_country'], $code ); ?>><?php echo $country; ?></option>
<?php
} ?>
</select>
<label class="placeholder-label">Country <span>*</span></label>
</div>
</div>
<div class="col-lg-6 col-md-6">
<div class="form-group form-placeholder">
<input type="text" class="form-control" placeholder="City" name="bill_state" value="<?php echo (isset($_SESSION['billing_info']['bill_state']))?$_SESSION['billing_info']['bill_state']:''; ?>" id="bill_state">
<label class="placeholder-label">State <span>*</span></label>
</div>
</div>
<div class="col-lg-6 col-md-6">
<div class="form-group form-placeholder">
<input type="text" class="form-control" placeholder="City" name="bill_city" value="<?php echo (isset($_SESSION['billing_info']['bill_city']))?$_SESSION['billing_info']['bill_city']:''; ?>" id="bill_city">
<label class="placeholder-label">City <span>*</span></label>
</div>
</div>
<div class="col-lg-6 col-md-6">
<div class="form-group form-placeholder">
<input type="text" class="form-control " placeholder="Country" name="bill_zip" value="<?php echo (isset($_SESSION['billing_info']['bill_zip']))?$_SESSION['billing_info']['bill_zip']:''; ?>" id="bill_zip">
<label class="placeholder-label">ZIP Code <span>*</span></label>
</div>
</div>
</div>
</div>
<div class="col-lg-5 col-md-12 offset-lg-2">
<h2 class="mb-5">Payment Info</h2>
<div class="row">
<div class="col-lg-12">
<div class="form-group form-placeholder">
<input type="text" class="form-control" name="card_no" id="card_no" placeholder="Card Number" value="<?php echo (isset($_SESSION['card_info']['card_no']))?$_SESSION['card_info']['card_no']:''; ?>" maxlength="16" onkeypress="return isNumber(event)">
<label class="placeholder-label">Card Number <span>*</span></label>
</div>
</div>
<div class="col-lg-4 col-md-4">
<div class="form-group form-placeholder">
<select class="form-control" name="exp_month" id="exp_month">
<option value="01" <?php selected($_SESSION['card_info']['exp_month'], '01'); ?>>Jan</option>
<option value="02" <?php selected($_SESSION['card_info']['exp_month'], '02'); ?>>Feb</option>
<option value="03" <?php selected($_SESSION['card_info']['exp_month'], '03'); ?>>Mar</option>
<option value="04" <?php selected($_SESSION['card_info']['exp_month'], '04'); ?>>Apr</option>
<option value="05" <?php selected($_SESSION['card_info']['exp_month'], '05'); ?>>May</option>
<option value="06" <?php selected($_SESSION['card_info']['exp_month'], '06'); ?>>Jun</option>
<option value="07" <?php selected($_SESSION['card_info']['exp_month'], '07'); ?>>Jul</option>
<option value="08" <?php selected($_SESSION['card_info']['exp_month'], '08'); ?>>Aug</option>
<option value="09" <?php selected($_SESSION['card_info']['exp_month'], '09'); ?>>Sep</option>
<option value="10" <?php selected($_SESSION['card_info']['exp_month'], '10'); ?>>oct</option>
<option value="11" <?php selected($_SESSION['card_info']['exp_month'], '11'); ?>>Nov</option>
<option value="12" <?php selected($_SESSION['card_info']['exp_month'], '12'); ?>>Dec</option>
</select>
<span id="month_err" class="error-custom"></span>
<label class="placeholder-label">Expiry Month <span>*</span></label>
</div>
</div>
<div class="col-lg-4 col-md-4">
<div class="form-group form-placeholder">
<?php
echo '<select class="form-control" name="exp_year" id="exp_year">';
$cur_year = date('Y');
for($year = $cur_year; $year <= ($cur_year+10); $year++) {
if ($year == $cur_year) {
// echo '<option value=""></option>';
echo '<option value="'.$year.'" '.selected($_SESSION['card_info']['exp_year'], $year).'>'.$year.'</option>';
} else {
echo '<option value="'.$year.'" '.selected($_SESSION['card_info']['exp_year'], $year).'>'.$year.'</option>';
}
}
echo '<select>'; ?>
<!-- </select> -->
<label class="placeholder-label">Expiry Year <span>*</span></label>
</div>
</div>
<div class="col-lg-4 col-md-4">
<div class="form-group form-placeholder">
<input type="password" class="form-control " name="cvv_no" placeholder="CVV" maxlength="3" value="<?php echo (isset($_SESSION['card_info']['cvv_no']))?$_SESSION['card_info']['cvv_no']:''; ?>" onkeypress="return isNumber(event)" id="cvv_no">
<label class="placeholder-label">CVV <span>*</span></label>
</div>
</div>
<div class="col-lg-12">
<div class="form-group form-placeholder">
<input type="text" class="form-control" name="name_on_card" placeholder="Name on Card" value="<?php echo (isset($_SESSION['card_info']['name_on_card']))?$_SESSION['card_info']['name_on_card']:''; ?>" id="name_on_card">
<label class="placeholder-label">Name on Card <span>*</span></label>
</div>
</div>
</div>
<h2 class="">Plan Info</h2>
<table class="table plan-info">
<thead>
<tr>
<th class="text-left">Plan Name </th>
<th class="text-right">Amount</th>
</tr>
</thead>
<tbody>
<tr>
<td class="text-left"><?php echo $_SESSION['package_info']['name']; ?></td>
<td class="text-right">$<?php echo number_format($_SESSION['package_info']['amount'], 2, '.', ''); ?></td>
</tr>
<tr>
<td class="text-left"><?php echo $_SESSION['package_info']['free_trial']; ?> Days Trial</td>
<td class="text-right">Included</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="text-center">
<!-- <a href="<?php echo get_site_url(); ?>/choose-plan" class="btn btn-gray btn-rounded hvr-shutter-out-horizontal text-transform">Back</a> -->
<a href="<?php echo get_site_url(); ?>/choose-connectors" class="btn btn-gray btn-rounded hvr-shutter-out-horizontal text-transform">Back</a>
<button type="submit" class="btn btn-primary btn-rounded hvr-shutter-out-horizontal text-transform" id="payment_form_sbt">Submit</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<?php
get_footer();
?>
<!-- <script src="dist/jquery-dateformat.js"></script> -->
<script>
$( document ).ready(function() {
var form_contact = $("#payment_form");
var submitbutton_contact = $("#payment_form_sbt");
jQuery.validator.setDefaults({
debug: true,
success: "valid"
});
jQuery.validator.methods.email = function( value, element ) {
return this.optional( element ) || /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test( value );
}
jQuery.validator.methods.lettersonly = function( value, element ) {
return this.optional( element ) || /^[a-zA-Z\s]+$/.test( value );
}
jQuery.validator.methods.validMonth = function(value, element, params) {
var d = new Date(),
curr_month = d.getMonth()+2;
curr_year = d.getFullYear();
var exp_month = $('#exp_month').val();
var exp_year = $('#exp_year').val()
if(exp_year == curr_year) {
return (this.optional(element)) || (exp_month <= month2digits(curr_month) && exp_year == curr_year && exp_month == month2digits(curr_month));
} else {
return (this.optional(element)) || true;
}
};
// jQuery.validator.methods.url = function( value, element ) {
// return this.optional( element ) || /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/.test( value );
// }
var validator = $( "#payment_form" ).validate({
rules: {
company_name: {
required: true
},
first_name: {
required: true
},
last_name: {
required: true
},
bill_address: {
required: true
},
email: {
required: true,
email: true
},
bill_city: {
required: true
},
phone_no: {
required: true,
digits: true,
minlength: 10,
maxlength: 10
},
bill_country: {
required: true
},
bill_state: {
required: true
},
bill_zip: {
digits: true,
required: true
},
card_no: {
required: true,
creditcard: true
},
exp_year: {
required: true
},
exp_month: {
required: true,
validMonth: true
},
name_on_card: {
lettersonly: true,
required: true
},
cvv_no: {
required: true
}
},
messages: {
name_on_card: {
lettersonly: "Only character input is allowed."
},
exp_month: {
validMonth: "Invalid month."
},
},
onfocusout: function(element) {
// "eager" validation
this.element(element);
},
errorElement : 'span',
errorLabelContainer: '.errorTxt',
submitHandler: function (form) {
if ($(form).valid())
form.submit();
return false; // prevent normal form posting
}
});
// $( "#exp_year" ).change(function() {
// var options = [];
// var currentTime = new Date()
// var select_year = $("#exp_year").val();
// var current_year = currentTime.getFullYear()
// console.log(select_year);
// console.log(current_year);
// if(select_year == current_year) {
// var month = currentTime.getMonth()+2;
// for(i=month; i<=12;i++){
// options += '<option value="'+month2digits(i)+'">'+GetMonthName_abbvr(i)+'</option>';
// }
// // console.log($.format.date("2018-05-10T01:10:20+02:00","dd/MM/yyyy"));
// // console.log(current_year);
// $('#exp_month').html(options);
// } else {
// var month = currentTime.getMonth()+2;
// for(i=1; i<=12;i++){
// options += '<option value="'+month2digits(i)+'">'+GetMonthName_abbvr(i)+'</option>';
// }
// // console.log($.format.date("2018-05-10T01:10:20+02:00","dd/MM/yyyy"));
// console.log(current_year);
// $('#exp_month').html(options);
// }
// });
});
function isNumber(evt) {
evt = (evt) ? evt : window.event;
var charCode = (evt.which) ? evt.which : evt.keyCode;
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
return false;
}
return true;
}
function month2digits(month)
{
return (month < 10 ? '0' : '') + month;
}
function GetMonthName_abbvr(monthNumber) {
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec'];
return months[monthNumber - 1];
}
</script>