<?php $setting = get_setting(); ?>
<?php $settings = get_setting(); ?>
<?php if(isset($settings['is_coupon']) && $settings['is_coupon']==1): ?>
	<?php if(d_auth('is_discount')==TRUE): ?>
		<?php $total_price = d_auth('total_price'); ?>
	<?php else: ?>
		<?php $total_price = $package['price']; ?>
	<?php endif;?>
<?php else: ?>
	<?php $total_price = $package['price']; ?>
<?php endif;?>
<a href="<?php echo base_url() ?>" id="base_url"></a>
<a href="<?= $this->security->get_csrf_hash(); ?>" id="csrf_value"></a>
<a href="<?= $this->security->csrf_token();?>" id="csrf_data"></a>
<a href="<?= isset($setting['key_id'])?$setting['key_id']:'';?>" id="razorpay_key"></a>
<div class="payment_warper">
	<div class="container">
		<div class="row">
			<div class="col-md-12">
		        <a href="<?php echo base_url('dashboard'); ?>" class="back payment_back"><i class="fa fa-arrow-left"></i> <?= !empty(lang('back'))?lang('back'):"Back"?></a>
		    </div>
			<div class="col-md-8 col-lg-7 <?= direction()=='rtl'?"mr-25":"offset-md-3"?>">
				<div class="card mt-50 payment_card">

					<?php if(isset($setting) && $setting['is_stripe']==0 && $setting['is_paypal']==0 && $setting['is_razorpay']==0 && $setting['is_offline']==0): ?>
						<div class="alert alert-warning alert-dismissible verify_alert_msg" id="successMessage">
					        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
					        <h4>
					            <i class="icon fa fa-close"></i>
					           <?= !empty(lang('sorry'))?lang('sorry'):"Sorry!" ;?>
					        </h4>
					        <p><?= !empty(lang('payment_not_available'))?lang('payment_not_available'):"Payment is not available!" ;?></p>
					    </div>
					<?php else: ?>


					 <?php if ($this->session->flashdata('verify')) { ?>
						    <div class="alert alert-success alert-dismissible verify_alert_msg" id="successMessage">
						        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
						        <h4>
						            <i class="icon fa fa-check"></i>
						            success!
						        </h4>
						        <p><?= $this->session->flashdata('verify'); ?></p>
						        <p>Please Payment now</p>
						    </div>
						    <?php } ?>
					<div class="card-header">
						<ul class="nav nav-tabs payment_nav">

							<?php foreach (payment_methods() as $key => $pay): ?>
								<?php if($settings[$pay['active_slug']]==1 && $settings[$pay['status_slug']]==1): ?>
									<li class="<?=  isset($_GET['method']) && $_GET['method']==$pay['slug']?"active":"";?>"><a href="<?= base_url("payment-method/{$slug}/{$account_type}?method={$pay['slug']}") ;?>"><?= lang($pay['slug']) ;?></a></li>
								<?php endif;?>
							<?php endforeach; ?>
							<li class="<?=  isset($_GET['method']) && $_GET['method']=="offline"?"active":"";?>"><a href="<?= base_url("payment-method/{$slug}/{$account_type}?method=offline") ;?>"><?= !empty(lang('offline'))?lang('offline'):"Offline"?> </a></li>

						</ul>
					</div>

					<div class="card-body">
						<div class="tab-content" id="myTabContent">
							<?php  if(isset($_GET['method'])):?>
								<?php 
								$method = $_GET['method'];
								?>
								<?php foreach (payment_methods() as $key => $pay): ?>
									<?php if($method==$pay['slug']): ?>
										<?php include "inc/{$pay['slug']}.php"; ?>
									<?php endif;?>
								<?php endforeach; ?>
								<?php if($method=='offline'): ?>
									<?php include 'inc/offline.php'; ?>
								<?php endif;?>
							<?php else: ?>
								<div class="tab-pane active" id="activity" role="tabpanel" aria-labelledby="home-tab">
									<div class="text-center emptyPayment">
										<i class="icofont-hand-drag1 fa-3x mb-10"></i>
										<h4><?= lang('select_payment_gateway'); ?></h4>
									</div>
								</div>
							<?php endif;?>


							
		  				</div><!-- tab-content -->
					</div>
					<?php endif;?>
				</div><!-- card -->
			</div>
		</div>
	</div>
</div>


<script>
	
	$(function(){
		$(document).on('submit', '#couponForm', function(e) {
			var url = $(this).attr('action');
			$.post(url, $(this).serialize(), function(json){
				if (json.st == 1) {
					$('.buy_now').prop('disabled',true);
					$('#couponForm').slideUp();
					$('.discount_price').html(json.total_price).slideDown();
					$(".reg_msg").slideDown().html(json.msg); 
					$("#couponForm")[0].reset(); 
					location.reload();
				}else{
					$("#couponForm")[0].reset(); 
					$('.discount_price').slideUp();
					$(".reg_msg").slideDown().html(json.msg);
				}
				setTimeout(function(){ $('.reg_msg').fadeOut();}, 2000);
			},'json');
			return false;
		});
	});

</script>