<?php $this->load->view('includes/head') ?>
<?php $this->load->view('includes/topbar') ?>
<?php $this->load->view('includes/header') ?>
<link rel="stylesheet" href="<?=base_url('assets/css/membership-plan.css');?>">
<?php 
$cartList = $this->session->userdata('membership_cart');

$cart_count = isset($cartList['service_id']) && $cartList['service_id'] ? 1 : 0;
$cart_count = $cart_count != '' ? $cart_count : 0;
if(empty($cartList['service_id'])) {
	$cartList = array('totalPrice' => 0.00, 'service_id' => '');
}


$fgh = getFullPaymentSettings();


$dsbj = $fgh['result']['data'][0]['paymentGatewayoffon'];

foreach ($dsbj as $key => $dd) {
	if ($dd['source'] == 'WEBSITE') {
		$paymentSeverOn = $dd['isenable']; 
		$paymentSeverText = $dd['desc']; 
	}
}

$paymentSetting = @getPaymentGatewaySettings();


if ($this->session->userdata('logged_in') == 1) {
	
	$current_user = @getUserDetails()->data[0];

	// print_r($current_user);
}


?>

<main id="main" style="background-image: url(<?=base_url('assets/img/elegant-background-with-mandala.png');?>);background-size: auto;">
	
	<!-- ======= Temple Services Section ======= -->
	<section id="temple-services" class="temple-services" style="background-image: url(<?=base_url('assets/img/elegant-background-with-mandala.png');?>);background-size: auto;">
		<center>

			<h2  class="text-center mb-0" style="font-weight:bold!important;font-size: 2em!important;text-shadow: 1px 1px 5px #FA9D1E;">Membership Plans</h2>
			<img src="<?=base_url('assets/img/border.png');?>" width="20%">
		</center>
		<span hidden class="cart-count"><?=$cart_count?></span>

		<?php

		$color = array('', 'red', 'secondary');
		$color_btn = array('btn-primary', 'btn-danger', 'btn-success');

		?>
		<div class="container-fluid">
			<div class="row gutters">

				<?php $mm = getMasterData('membershipTypes'); foreach ($mm as $key => $value) { ?>
					

					<div class="col-xl-4 col-lg-4 col-md-6 col-sm-6">
						<div class="pricing-plan">
							<div class="pricing-header <?=$color[$key]?>">
								<h4 class="pricing-title"><?=$value['Parent']['refDataName'];?></h4>
								<div class="pricing-cost"><?=getCurrencySymbol().' '.price_format($value['Parent']['price'], 2);?></div>
								<div class="pricing-save"><?=$value['Parent']['desc'];?></div>
							</div>
							<ul class="pricing-features" style="min-height:150px!important">

								<?php foreach ($value['Child Grid'] as $key2 => $item) { ?>

									<li><?=$item['benifits']?></li>

								<?php } ?>
							</ul>
							<div class="pricing-footer">
								<a href="javascript:void(0)" class="btn <?=$color_btn[$key]?> btn-lg" onclick="loginCheck('<?= $value['Parent']['price'] ?>', '<?=str_replace("'", "`", $value['Parent']['refDataName'])?>', '<?= $value['_id'] ?>')">Select Plan</a>
							</div>
						</div>
					</div>

				<?php } ?>


			</div>
		</div>
	</section><!-- End Temple Services Section -->

	<?php
	$header_data = getWebSyncsData('Header Settings', 'headerSettings', '');

	$modalClbtn = 'modalClbtn';
	if ($this->session->userdata('logged_in') == 1 ) { $modalClbtn = ''; }

	?>

	<!-- Payment Modal -->
	<div class="modal fade" id="membershipModal"  tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true" data-keyboard="false" data-backdrop="static">
		<div class="modal-dialog modal-dialog-centered" role="document">
			<div class="modal-content">


				<div class="modal-header text-center">
					<h5 class="modal-title bottomborder modatTitle" >CHECKOUT</h5>
					<button type="button" class="btn-close modalCloseBtn <?= @$modalClbtn; ?>" data-bs-dismiss="modal" aria-label="Close"></button>
				</div>
				<div class="modal-body">
					<div class="container">
						<img src="<?=ApiBaseUrl()['url'].@$header_data[0]['leftImage']?>" class="img-fluid mb-4" height="100px" width="100px" style="display: block;margin-left: auto;margin-right: auto;">
						<div class="row d-flex justify-content-center align-items-center">
							<div class="col-xl-12">
								<div class="row g-0">
									<div class="col-xl-12">
										<div class="row"> 
											<div class="col-md-12 mb-4">
												<table class="table table-responsive table-bordered text-center">
													<thead>
														<tr>
															<th><h5 class="h5-title">Membership Plan</h5></th>
															<th><h5 class="h5-title">Amount to Pay</h5></th>
														</tr>
													</thead>
													<tbody>
														<tr>
															<td><span id="serviceName" class="serviceName"></span></td>

															<td id="edittable">

															</td>
														</tr>
													</tbody>
												</table>
											</div>
										</div>

										<div class="d-flex justify-content-center text-center modal-footer">
											<div class="row">

												<div class="col-md-12">


													<?php	if(isset($paymentSetting) && $paymentSetting == 'PAYPAL' && $paymentSeverOn == 1){ ?>

														<div class="oooooookkakak" id="paypal-button-container"></div>

													<?php }else if( isset($paymentSetting) && $paymentSetting == 'MPI' && $paymentSeverOn == 1 ){ ?> 


														<style>
															#amount {
																width: 75px;
															}
															#card {
																background: #ffffffa3;
																height: 100px;
																padding: 10px 12px;
																border-radius: 5px;
																border: 1px solid #84a6ae;
																box-sizing: border-box;
																line-height: 0;
																margin: 9px 0px;
																width: 500px;
															}

															.input-style {
																color: #32a866;
															}
															.input-hint {
																color: #5e95a1;
																border-color: #9ac0c8;
															}
															/* All fields in form */
															.form-wrapper {
																width: 400px;
															}
															/* Credit Card Number */
															.input-wrapper {
																width: 200px;
															}
															/* Expiry Date */
															.sub-wrapper {
																width: 100px;
															}
															.valid-class {
																color: #217195;
															}
															.invalid-class {
																color: #b05826;
															}

															* {
																box-sizing: border-box;
															}

															.row {
																display: -ms-flexbox; /* IE10 */
																display: flex;
																-ms-flex-wrap: wrap; /* IE10 */
																flex-wrap: wrap;
																margin: 0 -16px;
															}

															.col-25 {
																-ms-flex: 25%; /* IE10 */
																flex: 25%;
															}

															.col-50 {
																-ms-flex: 50%; /* IE10 */
																flex: 50%;
															}
															.col-30 {
																-ms-flex: 30%; /* IE10 */
																flex: 30%;
															}
															.col-75 {
																-ms-flex: 75%; /* IE10 */
																flex: 75%;
															}

															.col-25,
															.col-50,
															.col-75 {
																padding: 0 16px;
															}


															.form-control:focus {
																color: #495057;
																background-color: #fff;
																border-color: #000408;
																outline: 0;
																box-shadow: 0 0 0 0.04rem rgb(0 0 0);
															}


															.icon-container {
																margin-bottom: 20px;
																padding: 7px 0;
																font-size: 24px;
															}




															hr {
																border: 1px solid lightgrey;
															}

															span.price {
																float: right;
																color: grey;
															}
														</style>
														<form id="paymentForm" action="https://www.bridgepaynetsecuretx.com/WebSecurity/echo.aspx" method="post" style=" max-width: 500px;margin: auto;">
															<div class="row px-0">
																<div class="col-md-12 px-0">
																	<h6 class="text-center">Card Details</h6>
																	<div id="card" class="mx-0" style="width: 100%!important;height: 150px;"></div>
																	<div id="errorMessage" style="margin-bottom: 10px; color: #c0392b;"></div>
																</div>
																<div class="col-md-12 px-0">
																	<h6 class="text-center">Billing Address</h6>
																	<input type="text" class="form-control" id="fname" name="firstname" placeholder="Enter Your Full Name*" required style="width: 100%; margin-bottom: 20px; padding: 12px; border: 1px solid #ccc; border-radius: 3px;    padding-top: 12px!important;" value="<?=@$current_user->refDataName; ?>">
																	<input type="email" id="email" class="form-control" name="email" placeholder="Enter Your Email Address*" required style="width: 100%; margin-bottom: 20px; padding: 12px; border: 1px solid #ccc; border-radius: 3px;    padding-top: 12px!important;" value="<?=base64_decode(@$current_user->email);?>">
																	<input type="text" class="form-control" id="address" name="address" placeholder="Enter Your Street Address" style="width: 100%; margin-bottom: 20px; padding: 12px; border: 1px solid #ccc; border-radius: 3px;    padding-top: 12px!important;" value="<?=@$current_user->addressLine1;?>">

																	<input type="number" class="form-control" id="zipcode" name="zipcode" placeholder="Enter Your Zipcode" style="width: 100%; margin-bottom: 20px; padding: 12px; border: 1px solid #ccc; border-radius: 3px;    padding-top: 12px!important;" value="<?=@$current_user->zip;?>">

																	<div class="row m-0 p-0">
																		<div class="col-md-12 px-0">
																			<input type="text" id="state" name="state" placeholder="State" style="width: 100%; margin-bottom: 20px; padding: 12px; border: 1px solid #ccc; border-radius: 3px;    padding-top: 12px!important;" value="<?=@$current_user->stateTypes;?>">
																		</div>
																		<div class="col-md-12 px-0">
																			<input type="text" id="city" name="city" placeholder="City" style="width: 100%; margin-bottom: 20px; padding: 12px; border: 1px solid #ccc; border-radius: 3px;    padding-top: 12px!important;" value="<?=@$current_user->cityTypes;?>">
																		</div>
																	</div>

																	<center>    
																		<button type="submit" class="btn btn-success" style="max-width: 500px;margin: auto;border-radius: 4px!important;font-weight: 800;padding: 8px 24px;background: #e78b00;border: 0;text-shadow: 1px 1px 0px black;">PAY NOW</button>
																	</center>
																</div>
															</div>

														</form>

													</form>



												<?php } ?>


												<button type="button" class="btn PaymentClosebtn btn-danger ms-2" data-dismiss="modal" hidden>CLOSE</button> 
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
			
		</div>
	</div>
</div>



</main><!-- End #main -->

<script type="text/javascript">




	function loginCheck(serviceAmt='', serviceName='', service_Id='') {

		pageName = 'membership-form';

		var amt = (serviceAmt / 1).toFixed(2);
		var serviceName = serviceName;
		var serviceId = service_Id;


		$("#edittable").html('<h4 id="servicePrice">'+amt+'</h4><input type="hidden" name="" value="'+amt+'" id="serviceAmt"><input type="hidden" name="" value="'+serviceName+'" id="membershipType"><input type="hidden" name="" value="'+service_Id+'" id="membershipId">');

    // event.preventDefault();
		$.ajax({
			url: "<?=base_url('check-login-status');?>",
			type: "POST",
			dataType: "json",
			success: function(data) 
			{
				
				if(data == 0){


					$('#servicePrice').text('$'+amt);
					$('#serviceName').text(serviceName);

					$('#serviceId').val(serviceId);
					if (amt != 0.00) {
						$('#serviceAmt').val(amt);
					}
					openLoginModal(pageName);


				}else{

					$("#loginModal").modal("hide");
					$('#servicePrice').text('$'+amt);
					$('#serviceName').text(serviceName);
					$('#serviceId').val(serviceId);

					if (amt != 0.00) {
						$('#serviceAmt').val(amt);
					}

					$("#modaleventCloseBtn").click();
					$("#membershipModal").modal("show");

				}
			}             
		});
	}


</script>



<?php   
// $paymentSetting = 'MPI';

if (isset($paymentSetting) && $paymentSetting == 'MPI' && $paymentSeverOn == 1) { ?>

	<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>



	<script type="text/javascript" src="https://www.bridgepaynetsecureTest.com/Bridgepay.WebSecurity/TokenPay/js/tokenPay.js"></script>
	<?php $mpiTokenPayId  = @getclientInfoById()['data'][0]['MPItokenPay'];

	if (isset($mpiTokenPayId) && $mpiTokenPayId != '') {
		$TokenPay = $mpiTokenPayId;
		
	}else{
		$TokenPay = 'tokenpay10579api20211508121542285';

	}
	?>



	<script>
		var tokenpay = TokenPay('<?=$TokenPay?>');
		tokenpay.initialize({
			dataElement: '#card',
			errorElement: '#errorMessage',
			amountElement: '#amount',
			useStyles: false,
			useACH: false,
			disableZip: true,
			disableCvv: false
		});

		var form = document.getElementById('paymentForm');
		form.addEventListener('submit', function(event) {

			event.preventDefault();
			tokenpay.createToken(function (result) {

				console.log(result);


				var totalPriceText = $("#serviceAmt").val(); 

				var membershipType = $("#membershipType").val();
				var membershipId = $("#membershipId").val();


				var mpi_zipcode = $("#zipcode").val();
				var mpi_fname = $("#fname").val();
				var mpi_address = $("#address").val();

				var numericValue = totalPriceText.replace(/[^0-9.]/g, '');
				var numericAmount = parseFloat(numericValue);

				var totolAmt = numericAmount;


				if (result.status == 'auth_success') {


					$.ajax({
						url: "<?=base_url('MPI_Payments/Paynow')?>",
						type: "POST",
						dataType: "json",
						data : {
							'token': result.token,
							'totolAmt': totolAmt,
							'name': mpi_fname,
							'address': mpi_address,
							'zipcode': mpi_zipcode
						},
						success: function(mpicardpayment_response) 
						{

							console.log(mpicardpayment_response.data);
							var paymentSource = 'MPI';

							var transactionId = 'ABHINAHIMILAHAI';
							

							$.ajax({
								url: "<?=base_url('MembershipForm/CheckoutMembership')?>",
								type: "POST",
								dataType: "json",
								data : {

									'membershipType': membershipType,
									'membershipId': membershipId,
									'transactionId': transactionId,
									'paymentMethod': paymentSource
								},
								success: function(mpicardpayment_response) 
								{
									console.log(mpicardpayment_response.statusCode);


									if (mpicardpayment_response.statusCode == 1) {

										$(".modalCloseBtn").click();
										$("#membershipModal").modal("hide");

										
										swal({
											html: true,
											title: "Membership Activated Sucessful!",
											text: "<span style='font-weight: 600;margin:5px;padding:5px'>Transaction Id:</span> "+transactionId,
											type: "success",
											confirmButtonText: 'OK',
											confirmButtonColor: '#008080',
										},
										function(){
											window.location.reload(); 
										});

									}else{
										alert("Something went wrong!");
									}

								}
							});

						}
					});
				}else{
					alert('Please enter valid details');
				}

			}, function (result) {
				console.log("error@@@: " + result.token);
			});
		});


	</script>



<?php } ?>
<?php $this->load->view('includes/footer') ?>
<?php $this->load->view('includes/script') ?>
