<?php $this->load->view('includes/head') ?>
<?php $this->load->view('includes/topbar') ?>
<?php $this->load->view('includes/header') ?>
<style>
	.description {
		display: none;
		font-size: 19px !important;
		text-align: justify;
		padding: 0 10px;
	}
</style>
<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);
}

$getclientInfoById = @getclientInfoById()['data'][0];

$CAW_MerchantId = @$getclientInfoById['ChargeAnywhereMerchantId'];
$CAW_TerminalId = @$getclientInfoById['ChargeAnywhereTerminalId'];


?>

<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('#40CBB4', '#1D95D2', '#FFC20B', 'warning');
		$icon = array('fa fa-paper-plane', 'fa fa-diamond', 'fa fa-rocket', 'warning');

		?>



		<section class="pricing-section">
			<div class="container">

				<div class="outer-box">
					<div class="row">
						<!-- Pricing Block -->
						<?php $mm = SettingsApi()['result']['data'][0]['membershipSettings']['membershipTypes'];
						// var_dump($this->session->userdata());
						// echo "<pre>";
						// print_r($mm);

						foreach ($mm as $key => $value) {
						?>

							<div class="pricing-block col-lg-4 col-md-6 col-sm-12 wow fadeInUp" data-wow-delay="800ms">
								<div class="inner-box">
									<!-- style="box-shadow: 1px 1px 38px <?= @$color[$key] ?>;" -->
									<div class="icon-box <?= @$color[$key] ?>">
										<div class="icon-outer"><i class="<?= $icon[$key]; ?>"></i></div>
									</div>
									<div class="price-box">
										<div class="title"><?= @camelCase($value['membershipType']); ?></div>
										<h4 class="price <?= @$color[$key] ?>"><?= getCurrencySymbol() . ' ' . price_format(@$value['membershipPrice'], 2); ?></h4>
									</div>
									<div class="px-2">
										<?php
										if(isset($value['membershipDesc']) && !empty($value['membershipDesc'])){
											?>
										<p class="description" id="moreDesc<?= $key ?>" style="display:none;">
											<?php echo @$value['membershipDesc']; ?>
											<br>
										</p>
										
										<center>
										<a href="javaScript:void(0);" onclick="ReadMore(<?= $key ?>)" id="myBtn<?= $key ?>" style="color: <?= @$color[$key] ?>;text-decoration: underline;">View Membership Benefits <i class="fa fa-eye"></i> </a>
										<br>
										<br>
										</center>
										
										<?php
										}else{
											echo "<br><br>";
										}
										?>
									</div>
									<?php
							
									if(isset($value['Child Grid'][0]['benefit']) && !empty($value['Child Grid'][0]['benefit'])){
										?>
									<ul class="fa-ul mb-3">

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

											if ($val['benefit']) { ?>

												<li><i class="fa fa-check-square"></i> </span><?= $val['benefit']; ?></li>

										<?php	}
										} ?>
									</ul>
									<?php
									}
									?>
									<div class="btn-box">
										<a href="javaScript:void(0)" onclick="loginCheck('<?= @$value['membershipPrice'] ?>', '<?= str_replace("'", "`", @$value['membershipType']) ?>', '<?= str_replace("'", "`", @$value['membershipDesc']) ?>','<?= @$value['_id'] ?>', '<?= @$value['inDays'] ?>', '<?= @$value['membershipName'] ?>')" class="theme-btn <?= @$color[$key] ?>">Select Plan</a>
									</div>
								</div>
							</div>


						<?php } ?>
					</div>
				</div>
			</div>
		</section>


	</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" style="font-size: 20px !important;"></span></td>

															<td id="edittable">

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

										<div class="">
											<div class="row">

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


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

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

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


														<link rel="stylesheet" href="<?= base_url('assets/css/mpi-form.css'); ?>">

														<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); ?>" oninput="this.value = this.value.toLowerCase();"> -->
																	<!-- <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 } else if (isset($paymentSetting) && $paymentSetting == 'CHARGEANYWHERE' && $paymentSeverOn == 1) { ?>


														<iframe id="paymentIframe" title="Payment Page" width="100%" height="600px"></iframe>

													<?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 = '', membershipDetail = '', service_Id = '', in_Days = '', membership_Name = '') {

		pageName = 'membership-form';

		var amt = (serviceAmt / 1).toFixed(2);
		var serviceName = serviceName;
		var membershipDetail = membershipDetail;
		var serviceId = service_Id;
		var inDays = in_Days;
		var membershipName = membership_Name;


		$("#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="' + membershipDetail + '" id="membershipDetail"><input type="hidden" name="" value="' + service_Id + '" id="membershipId"><input type="hidden" name="" value="' + inDays + '" id="inDays"><input type="hidden" name="" value="' + membershipName + '" id="membershipName">');

		// 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);
					}


					var memberShipExpiryDate = '<?= $this->session->userdata('memberShipExpiryDate'); ?>';
					var membershipStatus = '<?= $this->session->userdata('membershipStatus'); ?>';
					if (memberShipExpiryDate) {
						const today = new Date();
						const targetDate = new Date(memberShipExpiryDate);

						if (membershipStatus && today.getTime() <= targetDate.getTime() && membershipStatus == 'ACTIVE') {
							// alert('Ypur are already member');
							swal({
									html: true,
									title: "Your are already a member!",
									text: "Your are already a member! ",
									type: "warning",
									confirmButtonText: 'OK',
									confirmButtonColor: 'var(--main-color-new-theme)',
									// timer:5000,
								},

								function() {

									window.location.href = "<?= base_url('admin/membership'); ?>"


								});
						} else {
							$("#modaleventCloseBtn").click();
							$("#membershipModal").modal("show");
						}
					} else {
						if (membershipStatus && membershipStatus == 'ACTIVE') {
							// alert('Ypur are already member');
							swal({
									html: true,
									title: "Your are already a member!",
									text: "Your are already a member! ",
									type: "warning",
									confirmButtonText: 'OK',
									confirmButtonColor: 'var(--main-color-new-theme)',
									// timer:5000,
								},

								function() {

									window.location.href = "<?= base_url('admin/membership'); ?>"


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



				}
			}
		});



		<?php if (isset($paymentSetting) && $paymentSetting == 'CHARGEANYWHERE') { ?>
			var finalAmt = amt;
			var iframe = document.getElementById('paymentIframe');
			var url = "https://www.chargeanywhere.com/APIs/PayOnline.aspx?Version=2.0&MerchantId=<?= $CAW_MerchantId ?>&TerminalId=<?= $CAW_TerminalId ?>&Amount=" + finalAmt + "&Mode=0";
			iframe.src = url;
		<?php } ?>



	}
</script>

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

	<script type="text/javascript">
		const paypalButtonsComponent = paypal.Buttons({
			style: {
				shape: 'rect',
				color: 'gold',
				layout: 'vertical',
				label: 'paypal',
			},
			createOrder: (data, actions) => {
				var currency = "USD";

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

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


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



				const createOrderPayload = {
					purchase_units: [{
						amount: {
							currency_code: currency,
							value: amt
						}
					}]
				};
				return actions.order.create(createOrderPayload);
			},
			onApprove: (data, actions) => {
				const captureOrderHandler = (details) => {

					loader.on();
					var status = 'COMPLETED';

					// var orderid = details.id;
					var status = details.status;

					var transactionId = details.purchase_units[0].payments.captures[0].id;
					var paymentSource = 'PAYPAL';


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

							'membershipType': membershipType,
							'membershipName': membershipName,
							'inDays': inDays,
							'membershipId': membershipId,
							'transactionId': transactionId,
							'membershipDetail': membershipDetail,
							'membershipAmount': amt
						},
						success: function(response) {
							loader.off();
							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: 'var(--main-color-new-theme)',
									},
									function() {
										// window.location.reload();
										$.ajax({
											url: "<?= base_url('Home/updateLoginSessionData'); ?>",
											type: "POST",
											dataType: "json",
											success: function(data) {
												loader.off();
												console.log(data);
												// window.location.reload();
												window.location.href = "<?= base_url('admin/membership'); ?>"
											}
										});
									});

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

						}
					});
				};

				return actions.order.capture().then(captureOrderHandler);
			},

			onError: (err) => {

				console.log(err);
				alert('Transaction Failed');

			}
		});

		paypalButtonsComponent
			.render("#paypal-button-container-membership")
			.catch((err) => {
				console.log('PayPal Buttons failed to render');
			});
	</script>

<?php } ?>



<?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>



	<?php $TokenPay  = @getclientInfoById()['data'][0]['MPItokenPay'];
	$MpiPayUrl = base_url('MPI_Payments/Paynow');
	if (isset($TokenPay) && $TokenPay != '') {
		$TokenPay = $TokenPay;
	?>
		<script type="text/javascript" src="https://www.bridgepaynetsecuretx.com/Bridgepay.WebSecurity/TokenPay/js/tokenPay.js"></script>
	<?php
	} else {
		$TokenPay = 'tokenpay10579api20211508121542285';
		$MpiPayUrl = base_url('MPI_Payments/PaynowTest');
	?>
		<script type="text/javascript" src="https://www.bridgepaynetsecuretest.com/WebSecurity/TokenPay/js/tokenPay.js"></script>
	<?php
	}

	?>



	<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) {
			loader.on();
			event.preventDefault();
			tokenpay.createToken(function(result) {

				console.log(result);


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


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

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


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


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


							if (mpicardpayment_response.data.responseCode == 00000) {

								var paymentSource = 'MPI_CARD_NOT_PRESENT';
								var paymentStatus = 'COMPLETED';

								var transactionId = "Payment completed~" + mpicardpayment_response.data.TransactionID + "~" + mpicardpayment_response.data.cardType + "~" + mpicardpayment_response.data.maskedAccountNumber;


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

										'membershipDetail': membershipDetail,
										'membershipAmount': totolAmt,
										'paymentSource': paymentSource,
										'paymentStatus': paymentStatus

									},
									success: function(checkoutmembership_response) {
										console.log(checkoutmembership_response.statusCode);


										if (checkoutmembership_response.statusCode == 1) {

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


											swal({
													html: true,
													title: "Membership Activated Sucessful!",
													type: "success",
													confirmButtonText: 'OK',
													confirmButtonColor: 'var(--main-color-new-theme)',
												},
												function() {
													$.ajax({
														url: "<?= base_url('Home/updateLoginSessionData'); ?>",
														type: "POST",
														dataType: "json",
														success: function(data) {
															loader.off();
															console.log(data);
															// window.location.reload();
															window.location.href = "<?= base_url('admin/membership'); ?>"
														}
													});

												});


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

									}
								});
							} else {

								var paymentSource = 'MPI_CARD_NOT_PRESENT';
								var paymentStatus = 'FAILED';

								var transactionId = "Payment failed~0~" + mpicardpayment_response.message;

								var paymentStatus = 'FAILED';
								$.ajax({
									url: "<?= base_url('MembershipForm/CheckoutMembership') ?>",
									type: "POST",
									dataType: "json",
									data: {
										'membershipType': membershipType,
										'membershipId': membershipId,
										'transactionId': transactionId,

										'membershipName': membershipName,
										'inDays': inDays,
										'membershipDetail': membershipDetail,
										'membershipAmount': totolAmt,
										'paymentSource': paymentSource,
										'paymentStatus': paymentStatus


									},
									success: function(checkoutmembership_response) {
										loader.off();
										console.log(checkoutmembership_response.statusCode);


										if (checkoutmembership_response.statusCode == 1) {

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


											swal({
													html: true,
													title: checkoutmembership_response.message,
													type: "success",
													confirmButtonText: 'OK',
													confirmButtonColor: 'var(--main-color-new-theme)',
												},
												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
// $paymentSetting = 'MPI';

if (isset($paymentSetting) && $paymentSetting == 'MPITEST' && $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
	$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) {
			loader.on();
			event.preventDefault();
			tokenpay.createToken(function(result) {

				console.log(result);


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

				var membershipName = $("#membershipName").val();
				var inDays = $("#inDays").val();

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

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


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


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

							if (mpicardpayment_response.data.responseCode == 00000) {

								var paymentSource = 'MPI_CARD_NOT_PRESENT';
								var paymentStatus = 'COMPLETED';

								var transactionId = "Payment completed~" + mpicardpayment_response.data.TransactionID + "~" + mpicardpayment_response.data.cardType + "~" + mpicardpayment_response.data.maskedAccountNumber;


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

										'membershipName': membershipName,
										'inDays': inDays,
										'membershipDetail': membershipDetail,
										'membershipAmount': totolAmt,
										'paymentSource': paymentSource,
										'paymentStatus': paymentStatus

									},
									success: function(checkoutmembership_response) {
										console.log(checkoutmembership_response.statusCode);


										if (checkoutmembership_response.statusCode == 1) {

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


											swal({
													html: true,
													title: "Membership Activated Sucessful!",
													type: "success",
													confirmButtonText: 'OK',
													confirmButtonColor: 'var(--main-color-new-theme)',
												},
												function() {
													// window.location.reload();
													$.ajax({
														url: "<?= base_url('Home/updateLoginSessionData'); ?>",
														type: "POST",
														dataType: "json",
														success: function(data) {
															loader.off();
															console.log(data);
															// window.location.reload();
															window.location.href = "<?= base_url('admin/membership'); ?>"
														}
													});
												});

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

									}
								});
							} else {
								loader.off();
								var paymentSource = 'MPI_CARD_NOT_PRESENT';
								var paymentStatus = 'FAILED';

								var transactionId = "Payment failed~0~" + mpicardpayment_response.message;

								var paymentStatus = 'FAILED';
								$.ajax({
									url: "<?= base_url('MembershipForm/CheckoutMembership') ?>",
									type: "POST",
									dataType: "json",
									data: {
										'membershipType': membershipType,
										'membershipId': membershipId,
										'transactionId': transactionId,

										'membershipName': membershipName,
										'inDays': inDays,
										'membershipDetail': membershipDetail,
										'membershipAmount': totolAmt,
										'paymentSource': paymentSource,
										'paymentStatus': paymentStatus


									},
									success: function(checkoutmembership_response) {
										console.log(checkoutmembership_response.statusCode);


										if (checkoutmembership_response.statusCode == 1) {

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


											swal({
													html: true,
													title: checkoutmembership_response.message,
													type: "success",
													confirmButtonText: 'OK',
													confirmButtonColor: 'var(--main-color-new-theme)',
												},
												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

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

	<script type="text/javascript">
		window.addEventListener('message', handleMessage, false);
		window.addEventListener('message', chargeanywher, false);

		function handleMessage(event) {

			if (event.origin != "https://www.chargeanywhere.com") {
				return;
			}

			var customData = event.data;


		}



		function chargeanywher(event) {

			loader.on();

			if (event.origin != "https://www.chargeanywhere.com") {
				return;
			}

			// console.log(event);

			var customData = event.data;


			console.log(customData);



			if (customData.ResponseCode === "000") {



				var cardTypeCode = customData.CardType;
				var cardTypeName = getCardTypeName(cardTypeCode);

				var transactionId = "Payment completed~" + customData.ReferenceNumber + "~" + cardTypeName + "~" + customData.CardNumber;

				// var transactionId = "Payment completed~" + customData.ReferenceNumber + "~" + "TEST CARD" + "~" + customData.CardNumber;



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


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

				var paymentStatus = 'COMPLETED';

				var paymentSource = 'CAW_CARD_NOT_PRESENT';


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

						'membershipType': membershipType,
						'membershipId': membershipId,
						'transactionId': transactionId,

						'membershipName': membershipName,
						'inDays': inDays,
						'membershipDetail': membershipDetail,
						'membershipAmount': totolAmt,
						'paymentSource': paymentSource,
						'paymentStatus': paymentStatus
					},
					success: function(caw_response) {
						console.log(caw_response.statusCode);

						loader.off();
						if (caw_response.statusCode == 1) {

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


							swal({
									html: true,
									title: "Membership Activated Sucessful!",
									type: "success",
									confirmButtonText: 'OK',
									confirmButtonColor: 'var(--main-color-new-theme)',
								},
								function() {
									// window.location.reload();
									$.ajax({
										url: "<?= base_url('Home/updateLoginSessionData'); ?>",
										type: "POST",
										dataType: "json",
										success: function(data) {
											loader.off();
											console.log(data);
											// window.location.reload();
											window.location.href = "<?= base_url('admin/membership'); ?>"
										}
									});
								});

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

					}
				});





			} else {

				var cardTypeCode = customData.CardType;
				var cardTypeName = getCardTypeName(cardTypeCode);


				var transactionId = "Payment failed~0~" + customData.ResponseText + "~" + cardTypeName + "~" + customData.CardNumber;



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

				var membershipName = $("#membershipName").val();
				var inDays = $("#inDays").val();

				var mpi_zipcode = $("#zipcode").val();
				var mpi_fname = $("#fname").val();
				var mpi_address = $("#address").val();
				var paymentStatus = 'FAILED';
				var paymentSource = 'CAW_CARD_NOT_PRESENT';


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

						'membershipType': membershipType,
						'membershipId': membershipId,
						'transactionId': transactionId,

						'membershipName': membershipName,
						'inDays': inDays,
						'membershipDetail': membershipDetail,
						'membershipAmount': totolAmt,
						'paymentSource': paymentSource,
						'paymentStatus': paymentStatus
					},
					success: function(caw_response) {
						console.log(caw_response.statusCode);
						loader.off();

						if (caw_response.statusCode == 1) {

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


							swal({
									html: true,
									title: checkoutmembership_response.message,
									type: "success",
									confirmButtonText: 'OK',
									confirmButtonColor: 'var(--main-color-new-theme)',
								},
								function() {
									window.location.reload();
								});

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

					}
				});

			}
		}
	</script>

<?php } ?>
<script>
	function ReadMore(id) {
		var moreText = document.getElementById("moreDesc" + id);
		var btnText = document.getElementById("myBtn" + id);

		if (moreText.style.display === "none") {
			btnText.innerHTML = "Hide Membership Benefits<i class='fa fa-eye'></i> ";
			moreText.style.display = "inline";
		} else {
			btnText.innerHTML = "View Membership Benefits<i class='fa fa-eye'></i> ";
			moreText.style.display = "none";

		}
	}
</script>

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