template-payment.php

mail@pastecode.io avatar
unknown
php
2 months ago
12 kB
0
Indexable
Never
<?php
/**
* Template Name: Payment Template
*/
session_start();
global $woocommerce;
if(count(WC()->cart->get_cart())>0){
if(isset($_SESSION['date']) && !empty($_SESSION['date']) && isset($_SESSION["location"]) && !empty($_SESSION["location"])){
get_header();
global $woocommerce;
?> 
<div class="loading" style="display:none">Loading…</div>
<section class="payments-section">
  <div class="container">
    <div class="row justify-content-center">
      <div class="col-md-12">
        <div class="order-list">
          <div class="payment-nav">
            <div class="payment-item">
              <span>1</span>
              <p>Order details</p>
            </div>
            <div class="payment-item">
              <span class="">2</span>
              <p>Personal details</p>
            </div>
            <div class="payment-item">
              <span class="active">3</span>
              <p class="active">Payment</p>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="row justify-content-center">
      <div class="col-md-7">
        <div class="book-form">
          <h2>Payment details</h2>
          <form id="frmContact" method="post">
            <div class="form-group">
			<label>Card Number*</label>
              <input type="text" class="form-control req_num" name="sf_card" id="sf_card" placeholder="Card Number">
              <span class="valid_error" id="sf_card_mess"></span>
            </div>
            <div class="row">

              <div class="col-4">
                <div class="form-group">
				<label>Select Month*</label>
                  <select name="sf_exmonth" id="sf_exmonth" class="form-control"> 
			<?php $curnmpnth = date('m');
			for($i=1; $i<=12; $i++) { ?>
				<option <?php if($curnmpnth==$i) { echo "selected"; } ?> value="<?php if($i<=9) { echo '0'; } echo $i; ?>"><?php if($i<=9) { echo '0'; } echo $i; ?></option>
			<?php } ?> 
                  </select>
                  <span class="valid_error" id="sf_exmonth_mess"></span>
                </div>
              </div>
              <div class="col-4">
                <div class="form-group">
				<label>Select Year*</label>
                  <select name="sf_exyear" id="sf_exyear" class="form-control demoSelectBox"> 
					<?php $currentYear = date('Y'); 
					for($i=$currentYear; $i<=2050; $i++) { ?>
					<option <?php if($currentYear==$i) { echo "selected"; } ?>  value="<?php echo $i; ?>"><?php echo $i; ?></option> 
					<?php } ?> 
					 
                  </select>
                  <span class="valid_error" id="sf_exyear_mess"></span>
                </div>
              </div>
              <div class="col-4">
                <div class="form-group">
				<label>CVV*</label>
                  <input type="tel" class="form-control req_num" name="cvv" id="sf_cvc" placeholder="CVV">
                  <span class="valid_error" id="sf_cvc_mess"></span>
                </div>
              </div>
            </div>
            <div class="form-group">
              <div class="summry-totel">
                <h4>Amount</h4>
                <h4><?php echo get_woocommerce_currency_symbol().$_SESSION["total_charge"]; ?></h4>
              </div>
            </div>
			<input type="hidden" name="card_type" id="sf_creditCardType" >
            <button type="submit" onclick="return frmContact()" class="btn btn-primary btnAction">Continue Booking</button> 
          </form>
		  <div class="valid_error" id="p_mess"></div>
        </div>
      </div>
    </div>
  </div>
</section>
<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/assets/js/jquery.maskedinput.js"></script>
<script>

jQuery(document).ready(function(){
    jQuery("#msg_valid_exp").hide();
    var selectedyear = jQuery('#sf_exyear option:selected').val();
    var currentyear = '<?php echo date('Y'); ?>';
    var currentmonth = '<?php echo date('m'); ?>';
    var currentmonthlength = parseInt(currentmonth)-1;
    if(selectedyear==currentyear) {
        // Get all options within <select id='foo'>...</select>
        var op = document.getElementById("sf_exmonth").getElementsByTagName("option");
        for (var i = 0; i < currentmonthlength; i++) {
            // lowercase comparison for case-insensitivity
            op[i].disabled = true;
        }
        jQuery('#sf_exmonth option[value="'+currentmonth+'"]').attr("selected", "selected").change();
    } else {
        jQuery('#sf_exmonth option').removeAttr("disabled");
    }
})
jQuery('#sf_exyear').on('change', function(){
    jQuery("#msg_valid_exp").hide();
    var selectedyear = jQuery('#sf_exyear option:selected').val();
    var currentyear = '<?php echo date('Y'); ?>';
    var currentmonth = '<?php echo date('m'); ?>';
    var currentmonthlength = parseInt(currentmonth)-1;
    if(selectedyear==currentyear) {
        // Get all options within <select id='foo'>...</select>
        var op = document.getElementById("sf_exmonth").getElementsByTagName("option");
        for (var i = 0; i < currentmonthlength; i++) {
            // lowercase comparison for case-insensitivity
            op[i].disabled = true;
        }
        jQuery('#sf_exmonth option[value="'+currentmonth+'"]').attr("selected", "selected").change();
    } else {
        jQuery('#sf_exmonth option').removeAttr("disabled");
    }
})



jQuery(function($){
  jQuery("#sf_card").keyup(function(){
    if (/^(3)/.test(jQuery("#sf_card").val())) {
      jQuery("#sf_card").attr('maxlength','15');
      jQuery("#sf_cvc").attr('maxlength','4');
      jQuery("#sf_creditCardType").val('Amex');
    }
    else if (/^(5)/.test(jQuery("#sf_card").val())) {
      jQuery("#sf_card").attr('maxlength','16');
      jQuery("#sf_cvc").attr('maxlength','3');
      jQuery("#sf_creditCardType").val('MasterCard');
    }
    else if (/^(6)/.test(jQuery("#sf_card").val())) {
      jQuery("#sf_card").attr('maxlength','16');
      jQuery("#sf_cvc").attr('maxlength','3');
      jQuery("#sf_creditCardType").val('Discover');
    }
    else if (/^(4)/.test(jQuery("#sf_card").val())) {
      jQuery("#sf_card").attr('maxlength','16');
      jQuery("#sf_cvc").attr('maxlength','3');
      jQuery("#sf_creditCardType").val('Visa');
    }
  });
});
var specialKeys = new Array();
specialKeys.push(8, 9); //Backspace
jQuery(function() {
  jQuery(".req_num").bind("keypress", function(e) {
    var keyCode = e.which ? e.which : e.keyCode
    var ret = ((keyCode >= 48 && keyCode <= 57) || specialKeys.indexOf(keyCode) != -1);
    jQuery(".error").css("display", ret ? "none" : "inline");
    return ret;
  });
  jQuery(".req_num").bind("paste", function(e) {
    return false;
  });
  jQuery(".req_num").bind("drop", function(e) {
    return false;
  });
  jQuery(".req_char2").bind("keypress", function(e) {
    var keyCode = e.which ? e.which : e.keyCode
    // Checking value weather the key between the 0-9 or not! If not we are restricting
    var result = ((keyCode >= 65 && keyCode <= 90) ||
    (keyCode >= 97 && keyCode <= 122) || specialKeys.indexOf(keyCode) != -1) ||
    (keyCode == 32)|| (keyCode == 39)||(keyCode == 45)|| (keyCode == 95)|| (keyCode == 46);
    jQuery(".error").css("display",
    result ? "none" : "inline");
    return result;
  });
});
jQuery('input[type="text"]').keyup(function(evt){
  var txt = jQuery(this).val();
  jQuery(this).val(txt.replace(/^(.)|\s(.)/g, function($1){ return $1.toUpperCase( ); }));
});
</script>
<script>
function frmContact(){
  var sf_card_value 		= jQuery.trim(jQuery("#sf_card").val());
  var sf_exmonth_value 		= jQuery.trim(jQuery("#sf_exmonth").val());
  var sf_exyear_value 		=  jQuery.trim(jQuery("#sf_exyear").val());
  var sf_cvc_value 		= jQuery.trim(jQuery("#sf_cvc").val());
  var card_type 		= jQuery.trim(jQuery("#sf_creditCardType").val());
  var flagcheck = 0;

  if(sf_card_value == ''){
    var sf_contctemams = "Please enter your card number.";
    jQuery('#sf_card_mess').html(sf_contctemams);
    jQuery('#sf_card_mess').fadeIn();
    jQuery('#sf_card_mess').delay(3000).fadeOut();
    jQuery("#sf_card").focus(); 
    flagcheck = 1;
    return false;
  }
  var sf_t=jQuery("#sf_card").val(),
  sf_s=jQuery("#sf_card").val().length,
  sf_u=String(sf_t).charAt(0);
  if(sf_s<15 ){
    var sf_contctemams = "Invalid card number. Please try again.";
    jQuery('#sf_card_mess').html(sf_contctemams);
    jQuery('#sf_card_mess').fadeIn();
    jQuery('#sf_card_mess').delay(3000).fadeOut();
    jQuery("#sf_card").focus(); 
    flagcheck = 1;
    return false;
  }

  if(4!=sf_u&&5!=sf_u&&6!=sf_u&&3!=sf_u){
    var sf_contctemams = "Invalid card number. Please try again.";
    jQuery('#sf_card_mess').html(sf_contctemams);
    jQuery('#sf_card_mess').fadeIn();
    jQuery('#sf_card_mess').delay(3000).fadeOut();
    jQuery("#sf_card").focus(); 
    flagcheck = 1;
    return false;
  }
  if((4==sf_u||5==sf_u||6==sf_u)&&16!=sf_s){
    var sf_contctemams = "Invalid card number. Please try again.";
    jQuery('#sf_card_mess').html(sf_contctemams);
    jQuery('#sf_card_mess').fadeIn();
    jQuery('#sf_card_mess').delay(3000).fadeOut();
    jQuery("#sf_card").focus(); 
    flagcheck = 1;
    return false;
  }
  if(3==sf_u&&15!=sf_s){
    var sf_contctemams = "Invalid card number. Please try again.";
    jQuery('#sf_card_mess').html(sf_contctemams);
    jQuery('#sf_card_mess').fadeIn();
    jQuery('#sf_card_mess').delay(3000).fadeOut();
    jQuery("#sf_card").focus(); 
    flagcheck = 1;
    return false;
  }
  if((4==sf_u||5==sf_u||6==sf_u)&&16 ==sf_s){
    jQuery("#sf_cvc").attr('maxlength','3');
    var sf_incvc = '3';
  }else {
    jQuery("#sf_cvc").attr('maxlength','4');
    var sf_incvc = '4';
  }
  if(sf_exmonth_value == ''){
    var sf_contctemams = "Please select your expire month.";
    jQuery('#sf_exmonth_mess').html(sf_contctemams);
    jQuery('#sf_exmonth_mess').fadeIn();
    jQuery('#sf_exmonth_mess').delay(3000).fadeOut();
    jQuery("#sf_exmonth").focus();
    //scrollTOfield('sf_exmonth');
    flagcheck = 1;
    return false;
  }
  if(sf_exyear_value == ''){
    var sf_contctemams = "Please select your expire year.";
    jQuery('#sf_exyear_mess').html(sf_contctemams);
    jQuery('#sf_exyear_mess').fadeIn();
    jQuery('#sf_exyear_mess').delay(3000).fadeOut();
    jQuery("#sf_exyear").focus(); 
    flagcheck = 1;
    return false;
  }
  if(sf_cvc_value == ''){
    var sf_contctemams = "Please enter your cvc.";
    jQuery('#sf_cvc_mess').html(sf_contctemams);
    jQuery('#sf_cvc_mess').fadeIn();
    jQuery('#sf_cvc_mess').delay(3000).fadeOut();
    jQuery("#sf_cvc").focus(); 
    flagcheck = 1;
    return false;
  }
  
  if(flagcheck == 0)
  {
	jQuery.ajax({
           type: 'post',
           url: "<?php bloginfo('template_url'); ?>/booking-payment.php",
           data:{card_no:sf_card_value,
			   card_month:sf_exmonth_value,
			   card_year:sf_exyear_value,
			   card_cvv:sf_cvc_value,
			   card_type:card_type
			   },
			    beforeSend: function() { 
			    jQuery('.loading').css("display","block");
		        },
			   success: function(data){
				   jQuery('.loading').css("display","none"); 
			   if(data == 1)
			   {
				   window.location='<?php echo the_permalink(485); ?>?IT=<?php echo $_SESSION["string"]; ?>';
			   }else if(data == 0){
				   window.location='<?php echo the_permalink(323); ?>';
			   }else{
					jQuery('#p_mess').html(data);
					jQuery('#p_mess').fadeIn();
					jQuery('#p_mess').delay(4000).fadeOut();
			   }
			   
           }
       });
	  return false;
  }

}

</script>

<?php 
}else{
	echo "<script type='text/javascript'>window.location='".site_url()."'</script>"; exit;
}
}else{
	echo "<script type='text/javascript'>window.location='".site_url()."'</script>";exit;
}
get_footer();
?>
Leave a Comment