<?php
/**
 * Template Name: Make a donation
 *
 * @package WordPress
 * @subpackage Charity
 * @since Charity 1.0
 */
?>
<?php
	$wplook_pid = get_the_ID();
	$wplook_page_meta = get_post_meta($wplook_pid);
	$wplook_sidebar_position 	= isset($wplook_page_meta['wpl_cpt_sidebar_position'][0]) ? $wplook_page_meta['wpl_cpt_sidebar_position'][0] : "right";
	$wplook_page_sidebar = (isset($wplook_page_meta['wpl_cpt_sidebar_select'][0]) && $wplook_page_meta['wpl_cpt_sidebar_select'][0] != '') ? $wplook_page_meta['wpl_cpt_sidebar_select'][0] : "page-1";
	$wplook_page_header  = (isset($wplook_page_meta['wpl_page_header'][0]) && $wplook_page_meta['wpl_page_header'][0] != '') ? $wplook_page_meta['wpl_page_header'][0] : false;
	$wplook_default_custom_amount = isset($wplook_page_meta['wpl_default_custom_amount'][0]) ? $wplook_page_meta['wpl_default_custom_amount'][0] : 300;
	$wplook_default_first_amount  = isset($wplook_page_meta['wpl_default_first_amount'][0]) ? $wplook_page_meta['wpl_default_first_amount'][0] : 25;
	$wplook_default_second_amount = isset($wplook_page_meta['wpl_default_second_amount'][0]) ? $wplook_page_meta['wpl_default_second_amount'][0] : 50;
	$wplook_default_third_amount  = isset($wplook_page_meta['wpl_default_third_amount'][0]) ? $wplook_page_meta['wpl_default_third_amount'][0] : 75;
	$wplook_default_fourth_amount = isset($wplook_page_meta['wpl_default_fourth_amount'][0]) ? $wplook_page_meta['wpl_default_fourth_amount'][0] : 100;
	$wplook_default_fifth_amount  = isset($wplook_page_meta['wpl_default_fifth_amount'][0]) ? $wplook_page_meta['wpl_default_fifth_amount'][0] : 150;
	$wplook_default_sixth_amount  = isset($wplook_page_meta['wpl_default_sixth_amount'][0]) ? $wplook_page_meta['wpl_default_sixth_amount'][0] : 200;
	$wplook_default_percent_fee   = ot_get_option('wpl_stripe_percent_fee') ? ot_get_option('wpl_stripe_percent_fee') / 100 : 0;
	$wplook_default_fixed_fee     = ot_get_option('wpl_stripe_fixed_fee') ? : 0;
?>
<?php get_header(); ?>

	<div class="main">
		<div class="main-head">
			<div class="main-head-image fullscreener">
				<?php
					if ( $wplook_page_header ) {
						echo '<img class="hide" src="'. esc_url( $wplook_page_header ).'">';
					}?>
			</div><!-- /.main-head-image fullscreener -->

			<div class="main-head-content">
				<div class="grid-container">
					<div class="grid-x grid-margin-x">
						<div class="cell small-12">
							<h1 class="main-title main-title-alt"><?php the_title(); ?></h1><!-- /.main-title main-title-alt -->
							<?php if (ot_get_option('wpl_breadcrumbs_status') == 'on') : ?>
								<ul class="breadcrumbs">
									<?php wplook_breadcrumbs(); ?>
								</ul><!-- /.breadcrumbs -->
							<?php endif; ?>
						</div><!-- /.cell small-12 -->
					</div><!-- /.grid-x grid-margin-x -->
				</div><!-- /.grid-container -->
			</div><!-- /.main-head-content -->
		</div><!-- /.main-head -->
		<div class="main-body">
			<div class="grid-container">
				<div class="grid-x grid-margin-x">
					<div class="cell small-12 <?php if ( $wplook_sidebar_position == 'right') { echo "large-8";} elseif ( $wplook_sidebar_position == 'disable' ) {echo "large-12"; } else { echo " large-8 ";} ?>">
						<div class="content">


								<?php
									if ($_SERVER['REQUEST_METHOD'] == 'POST') :
										$error = false;

										try {

											if (!(isset($_POST['fname']) && $_POST['fname'] != '')) throw new Exception("Add Frist Name");
											if (!(isset($_POST['lname']) && $_POST['lname'] != '')) throw new Exception("Add Last Name");
											if (!(isset($_POST['email']) && $_POST['email'] != '')) throw new Exception("Add Email");


											if (!isset($_POST['stripeToken'])) throw new Exception("The Stripe Token was not generated correctly");

											$wplook_amount_cc = ( isset( $_POST["amount_cc"] ) && !empty( $_POST["amount_cc"] ) ) ? $_POST["amount_cc"] : false;
											$wplook_ccfees    = ( isset( $_POST["ccfees"] ) && $_POST["ccfees"] == 'on' ) ? true : false;
											$wplook_cause_id  = ( isset( $_POST["causeid"] ) && !empty( $_POST["causeid"] ) ) ? $_POST["causeid"] : 0;
											$wplook_email     = ( isset( $_POST["email"] ) && !empty( $_POST["email"] ) ) ? sanitize_email( $_POST["email"] ) : false;
											$wplook_pass      = ( isset( $_POST["password"] ) && !empty( $_POST["password"] ) ) ? $_POST["password"] : false;
											$wplook_fname     = ( isset( $_POST["fname"] ) && !empty( $_POST["fname"] ) ) ? $_POST["fname"] : false;
											$wplook_lname     = ( isset( $_POST["lname"] ) && !empty( $_POST["lname"] ) ) ? $_POST["lname"] : false;
											$wplook_uname     = sanitize_user( preg_replace( '/\s+/', '', $wplook_fname .'wpl' .$wplook_lname ), true );
											$wplook_comments  = ( isset( $_POST["comments"] ) && !empty( $_POST["comments"] ) ) ? $_POST["comments"] : false;

											if ( $wplook_amount_cc && $wplook_ccfees && $wplook_default_percent_fee && $wplook_default_fixed_fee ) {
												$wplook_amount_cc = round( ( $wplook_amount_cc + $wplook_default_fixed_fee ) / ( 1 - $wplook_default_percent_fee ), 2 );
											}
											// stripe api love cents
											$wplook_amount_cc = $wplook_amount_cc * 100;
											// wp_die($wplook_amount_cc);

											$wplook_donation_frequency = ( isset( $_POST["donation_frequency"] ) && !empty( $_POST["donation_frequency"] ) ) ? $_POST["donation_frequency"] : false;
											if ($wplook_donation_frequency == 'onetime') {
												$wplook_donation_frequency_meta = 'onetime';
												$wplook_donation_frequency      = 'day';
											} else {
												$wplook_donation_frequency_meta = $wplook_donation_frequency;
											}
											$wplook_plan_meta_key     = 'wpl_stripe_'.$wplook_donation_frequency.'_plan_'.$wplook_cause_id.'_'.$wplook_amount_cc;
											$wplook_product_name      = sanitize_title_with_dashes( get_the_title( $wplook_cause_id ) );

											// Test if user exist (by email)
											$wplook_mail_exists = email_exists( $wplook_email );

											if ( $wplook_mail_exists ) {
												$wplook_user_id = $wplook_mail_exists;
											} else {
												if (!(isset($_POST['password']) && $_POST['password'] != '')) throw new Exception("Add Password");
												$wplook_userdata = array(
													'user_email'	=> $wplook_email,
													'user_login' 	=> $wplook_uname,
													'user_pass'		=> $wplook_pass,
													'first_name'	=> $wplook_fname,
													'last_name'		=> $wplook_lname,
													'display_name'	=> $wplook_fname .' ' .$wplook_lname,
												);

												$wplook_user_id = wp_insert_user( $wplook_userdata ) ;

												//On error
												if ( is_wp_error( $wplook_user_id ) ) {
													throw new Exception("User wasn't created");
												}
											}

											//get current user info
											$cu              = get_userdata( $wplook_user_id );
											$wplook_customer = get_user_meta( $cu->ID, '_swp_stripe_customer', true);
											if ( $cu ) {
												$wplook_curr_uname = $cu->user_login;
											} else {
												throw new Exception( "User ID: ".$wplook_user_id." does not exist" );
											}

											// Stripe Plan
											try {
												if ( $first_plan = \Stripe\Plan::retrieve( $wplook_plan_meta_key ) ) { }
											} catch (Exception $e) {
												$first_plan = \Stripe\Plan::create( array(
													"amount"   => $wplook_amount_cc,
													"interval" => $wplook_donation_frequency,
													"product"  => [ "name" => $wplook_product_name, "type" => "service" ],
													"currency" => ot_get_option( 'wpl_curency_code' ),
													"id"       => $wplook_plan_meta_key
													)
												);
											}
											update_post_meta( $wplook_cause_id, $first_plan->id, true );
											try {
												if( $customer_obj = \Stripe\Customer::retrieve( $wplook_customer ) ) {  }
											} catch (Exception $e ) {
												$customer_obj = \Stripe\Customer::create(array(
													"description" => "Customer for " . get_bloginfo('name'),
													"email"       => $cu->user_email,
													'card'        => $_POST['stripeToken'],
													"metadata"    => array (
														"wpl_username"   => $cu->user_login,
														"wpl_first_name" => get_user_meta( $cu->ID, 'first_name', true ),
														"wpl_last_name"  => get_user_meta( $cu->ID, 'last_name', true ),
													),
												));
												//add customer ID to user meta
											}
											update_user_meta( $cu->ID, '_swp_stripe_customer', $customer_obj->id );

											//create subscriptions for customer object
											$subscription_obj = \Stripe\Subscription::create(
												array(
														'customer' => $customer_obj->id,
														'items'    => [['plan' => $first_plan->id]],
														'metadata' => array (
															'wpl_sub_frequency' => $wplook_donation_frequency_meta,
															'wpl_user_id' 		=> $wplook_user_id,
															'wpl_user_name' 	=> $wplook_curr_uname,
															'wpl_user_email' 	=> $wplook_email,
															"wpl_first_name" 	=> $wplook_fname,
															"wpl_last_name" 	=> $wplook_lname,
															'wpl_cause_id' 		=> $wplook_cause_id,
															"wpl_comments" 		=> $wplook_comments,
													),
												)
											);

										} catch (Exception $e) {
											$error = $e->getMessage();
										} catch (\Stripe\Error\ApiConnection $e) {
											$error = $e->getMessage();
											// Network problem, perhaps try again.
										} catch (\Stripe\Error\InvalidRequest $e) {
											$error = $e->getMessage();
											// You screwed up in your programming. Shouldn't happen!
										} catch (\Stripe\Error\Api $e) {
											$error = $e->getMessage();
											// Stripe's servers are down!
										} catch (\Stripe\Error\Card $e) {
											$error = $e->getMessage();
											// Card was declined.
										}
										if (!$error) {
											printf( '<h1>%s<h1>', __( 'Thank you! Your donation was received.', 'charity-wpl' ) );
											the_content();
										}
										else {
											printf( '<h1>%s<h1>', __( 'Sorry, the transaction not occurred', 'charity-wpl' ) );
											echo '<span class="payment-errors">'.esc_html($error).'</span>';
										}
									else :
								 ?>

									<?php if ( have_posts() ) : ?>
										<?php while ( have_posts() ) : the_post(); ?>
											<?php get_template_part( 'content', 'page' ); ?>
										<?php endwhile; ?>
									<?php endif; ?>

								<div class="tabs-wrapper">
									<ul class="tabs" data-tabs id="payment-tabs">
										<?php if (ot_get_option('wpl_activate_paypal') == 'on') :  ?>
											<li class="tabs-title is-active">
												<a href="#panel1" aria-selected="true">
													<i class="fab fa-paypal"></i> <?php _e('PayPal', 'charity-wpl'); ?>
												</a>
											</li>
										<?php endif; ?>

										<?php if (ot_get_option('wpl_activate_cc_payment') == 'on') : ?>
											<li class="tabs-title">
												<a data-tabs-target="panel2" href="#panel2">
													<i class="far fa-credit-card"></i> <?php _e('Credit Card', 'charity-wpl'); ?>
												</a>
											</li>
										<?php endif; ?>

										<?php if (ot_get_option('wpl_activate_bank_transfer') == 'on') :  ?>
											<li class="tabs-title">
												<a data-tabs-target="panel3" href="#panel3">
													<i class="fas fa-university"></i> <?php _e('Bank Transfer', 'charity-wpl'); ?>
												</a>
											</li>
										<?php endif; ?>

										<?php if (ot_get_option('wpl_activate_check_payment') == 'on') :  ?>
											<li class="tabs-title">
												<a data-tabs-target="panel4" href="#panel4">
													<i class="fas fa-money-check-alt"></i> <?php _e('Check Payment', 'charity-wpl'); ?>
												</a>
											</li>
										<?php endif; ?>

									</ul>

									<div class="tabs-content" data-tabs-content="payment-tabs">

										<?php if (ot_get_option('wpl_activate_paypal') == 'on') :  ?>
											<div class="tabs-panel is-active" id="panel1">
												<div class="form-donation form-donation-pp-general">
													<form action="<?php echo get_permalink( ot_get_option('wpl_pp_pay_page') ); ?>" method="post">
														<div class="form-body-pp">
															<div class="form-row">
																<div class="form-controls">
																	<fieldset class="fieldset">
																		<legend><?php _e('Donation Amount', 'charity-wpl'); ?></legend>
																		<div class="grid-x grid-margin-x">
																			<?php if ( $wplook_default_custom_amount > 0 ) { ?>
																				<div class="cell small-12 medium-3">
																					<input step="5" type="number" class="field" name="amount" id="field-amount-pp" value="<?php echo esc_attr( $wplook_default_custom_amount ); ?>">
																				</div>
																			<?php } ?>

																			<div class="cell small-12 medium-9">
																				<ul class="list-radios">
																					<?php if ( $wplook_default_first_amount > 0 ) { ?>
																						<li>
																							<div class="radio">
																								<input type="radio" name="amount" id="field-25-usd-pp" value="<?php echo esc_attr( $wplook_default_first_amount ); ?>">

																								<label for="field-25-usd-pp"><?php echo esc_attr( $wplook_default_first_amount ); ?> <?php echo ot_get_option('wpl_curency_code'); ?></label>
																							</div><!-- /.radio -->
																						</li>
																					<?php } ?>

																					<?php if ( $wplook_default_second_amount > 0 ) { ?>
																						<li>
																							<div class="radio">
																								<input type="radio" name="amount" id="field-50-usd-pp" value="<?php echo esc_attr( $wplook_default_second_amount ); ?>">

																								<label for="field-50-usd-pp"><?php echo esc_attr( $wplook_default_second_amount ); ?> <?php echo ot_get_option('wpl_curency_code'); ?></label>
																							</div><!-- /.radio -->
																						</li>
																					<?php } ?>

																					<?php if ( $wplook_default_third_amount > 0) { ?>
																						<li>
																							<div class="radio">
																								<input type="radio" name="amount" id="field-100-usd-pp" value="<?php echo esc_attr( $wplook_default_third_amount ); ?>">

																								<label for="field-100-usd-pp"><?php echo esc_attr( $wplook_default_third_amount ); ?> <?php echo ot_get_option('wpl_curency_code'); ?></label>
																							</div><!-- /.radio -->
																						</li>
																					<?php } ?>

																					<?php if ( $wplook_default_fourth_amount > 0) { ?>
																						<li>
																							<div class="radio">
																								<input type="radio" name="amount" id="field-150-usd-pp" value="<?php echo esc_attr( $wplook_default_fourth_amount ); ?>">

																								<label for="field-150-usd-pp"><?php echo esc_attr( $wplook_default_fourth_amount ); ?> <?php echo ot_get_option('wpl_curency_code'); ?></label>
																							</div><!-- /.radio -->
																						</li>
																					<?php } ?>

																					<?php if ( $wplook_default_fifth_amount > 0) { ?>
																						<li>
																							<div class="radio">
																								<input type="radio" name="amount" id="field-200-usd-pp" value="<?php echo esc_attr( $wplook_default_fifth_amount ); ?>">

																								<label for="field-200-usd-pp"><?php echo esc_attr( $wplook_default_fifth_amount ); ?> <?php echo ot_get_option('wpl_curency_code'); ?></label>
																							</div><!-- /.radio -->
																						</li>
																					<?php } ?>
																					<?php if ( $wplook_default_sixth_amount > 0) { ?>
																						<li>
																							<div class="radio">
																								<input type="radio" name="amount" id="field-250-usd-pp" value="<?php echo esc_attr( $wplook_default_sixth_amount ); ?>">

																								<label for="field-250-usd-pp"><?php echo esc_attr( $wplook_default_sixth_amount ); ?> <?php echo ot_get_option('wpl_curency_code'); ?></label>
																							</div><!-- /.radio -->
																						</li>
																					<?php } ?>
																				</ul><!-- /.list-radios -->
																			</div>
																		</div><!-- /.grid-x grid-margin-x -->
																	</fieldset>
																	<fieldset class="fieldset">
																		<legend><?php _e('I give a donation for:', 'charity-wpl'); ?></legend>
																		<div class="grid-x grid-margin-x">
																			<div class="cell small-12">
																				<label class="label-donation-for">
																					<select name="cause">
																						<option value="<?php echo esc_attr( $wplook_pid ); ?>|#| <?php _e('General Donation', 'charity-wpl'); ?>" <?php selected( '<?php echo esc_attr( $wplook_pid ); ?>' ); ?>><?php _e('General Donation', 'charity-wpl'); ?></option>
																							<?php $args = array( 'post_type' => 'post_causes', 'post_status' => 'publish', 'posts_per_page' => 1000, 'paged'=> $paged); ?>
																							<?php $wp_query = null; ?>
																							<?php $wp_query = new WP_Query( $args ); ?>
																							<?php if ( $wp_query->have_posts() ) :
																							$id = get_the_ID();
																							while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
																								<option value="<?php echo $id; ?>|#| <?php the_title(); ?>" <?php selected( '<?php the_title(); ?>' ); ?>><?php the_title(); ?></option>
																							<?php endwhile; wp_reset_postdata(); ?>
																							<?php endif; ?>
																					</select>
																				</label>
																			</div>
																		</div><!-- /.grid-x grid-margin-x -->
																	</fieldset>
																</div><!-- /.form-controls -->
															</div><!-- /.form-row -->
														</div><!-- /.form-body -->

														<div class="form-actions">
															<input type="submit" value="<?php _e('Donate Now!', 'charity-wpl'); ?>" class="button">
														</div><!-- /.form-actions -->
													</form>
												</div><!-- /.form-donation -->
											</div>
										<?php endif; ?>

									<?php if (ot_get_option('wpl_activate_cc_payment') == 'on') :  ?>
									<div class="tabs-panel" id="panel2">
										<span class="payment-errors hide"></span>
										<form action="<?php echo get_permalink( $wplook_pid ); ?>" method="POST" id="payment-form">
											<!-- User info -->
											<?php if( is_user_logged_in() ) : ?>
												<?php $wpl_cu_user = wp_get_current_user(); ?>
												<fieldset class="fieldset">
													<legend><?php _e('Donor Information', 'charity-wpl'); ?></legend>
													<div class="grid-x grid-margin-x">
														<div class="cell small-6">
															<label><?php _e('First Name *', 'charity-wpl'); ?>
																<input value="<?php echo ( $wpl_cu_user->user_firstname ) ?>" name="fname" type="text" placeholder="<?php _e('First Name', 'charity-wpl'); ?>">
															</label>
														</div>

														<div class="cell small-6">
															<label><?php _e('Last Name *', 'charity-wpl'); ?>
																<input value="<?php echo ( $wpl_cu_user->user_lastname ) ?>" name="lname"  type="text" placeholder="<?php _e('Last Name', 'charity-wpl'); ?>">
															</label>
														</div>
													</div>

													<div class="grid-x grid-margin-x">
														<div class="cell small-12 large-12">
															<label><?php _e('Email *', 'charity-wpl'); ?>
																<input value="<?php echo ( $wpl_cu_user->user_email ) ?>" name="email" type="text" placeholder="<?php _e('Email', 'charity-wpl'); ?>">
															</label>
														</div>
													</div>
												</fieldset>
											<?php else : ?>
												<fieldset class="fieldset">
													<legend><?php _e('Donor Information', 'charity-wpl'); ?></legend>
													<div class="grid-x grid-margin-x">
														<div class="cell small-6">
															<label><?php _e('First Name *', 'charity-wpl'); ?>
																<input value="<?php echo (isset($_POST['fname']) ? $_POST['fname'] : '') ?>" name="fname" type="text" placeholder="<?php _e('First Name', 'charity-wpl'); ?>">
															</label>
														</div>

														<div class="cell small-6">
															<label><?php _e('Last Name *', 'charity-wpl'); ?>
																<input value="<?php echo (isset($_POST['lname']) ? $_POST['lname'] : '') ?>" name="lname"  type="text" placeholder="<?php _e('Last Name', 'charity-wpl'); ?>">
															</label>
														</div>
													</div>
													<div class="grid-x grid-margin-x">
														<div class="cell small-12 medium-6">
															<label><?php _e('Email *', 'charity-wpl'); ?>
																<input value="<?php echo (isset($_POST['email']) ? $_POST['email'] : '') ?>" name="email" type="text" placeholder="<?php _e('Email', 'charity-wpl'); ?>">
															</label>
														</div>
														<div class="cell small-12 medium-6">
															<label><?php _e('Password *', 'charity-wpl'); ?>
																<input value="<?php echo (isset($_POST['password']) ? $_POST['password'] : '') ?>" name="password" type="password" placeholder="<?php _e('Password', 'charity-wpl'); ?>">
															</label>
														</div>
														<div class="cell small-12">
															<p><?php printf( __( '%1$s Login if you have an account %2$s', 'charity-wpl' ),
																'<a href="'. esc_url( get_permalink( ot_get_option('wpl_login_link' ) ) ).'">',
																'</a>' ); ?>
															</p>
														</div>
													</div>
												</fieldset>
											<?php endif; ?>
											<!-- User Info-->
												<div class="grid-x grid-margin-x">
													<div class="cell small-12">
														<div class="form-controls">
															<fieldset class="fieldset">
																<legend><?php _e('Donation Amount', 'charity-wpl'); ?></legend>
																<div class="grid-x grid-margin-x">
																	<?php if ( $wplook_default_custom_amount > 0 ) { ?>
																	<div class="cell small-12 medium-2">
																		<input step="5" type="number" class="field" name="amount_cc" id="field-amount" value="<?php echo esc_attr( $wplook_default_custom_amount ); ?>">
																	</div>
																	<?php } ?>
																	<div class="cell small-12 medium-10">
																		<ul class="list-radios">
																			<?php if ( $wplook_default_first_amount > 0 ) { ?>
																			<li>
																				<div class="radio">
																					<input type="radio" name="amount_cc" id="field-25-usd" value="<?php echo esc_attr( $wplook_default_first_amount ); ?>">

																					<label for="field-25-usd"><?php echo esc_attr( $wplook_default_first_amount ); ?> <?php echo ot_get_option('wpl_curency_code'); ?></label>
																				</div><!-- /.radio -->
																			</li>
																			<?php } ?>
																			<?php if ( $wplook_default_second_amount > 0 ) { ?>
																			<li>
																				<div class="radio">
																					<input type="radio" name="amount_cc" id="field-50-usd" value="<?php echo esc_attr( $wplook_default_second_amount ); ?>">

																					<label for="field-50-usd"><?php echo esc_attr( $wplook_default_second_amount ); ?> <?php echo ot_get_option('wpl_curency_code'); ?></label>
																				</div><!-- /.radio -->
																			</li>
																			<?php } ?>
																			<?php if ( $wplook_default_third_amount > 0 ) { ?>
																			<li>
																				<div class="radio">
																					<input type="radio" name="amount_cc" id="field-75-usd" value="<?php echo esc_attr( $wplook_default_third_amount ); ?>">

																					<label for="field-75-usd"><?php echo esc_attr( $wplook_default_third_amount ); ?> <?php echo ot_get_option('wpl_curency_code'); ?></label>
																				</div><!-- /.radio -->
																			</li>
																			<?php } ?>
																			<?php if ( $wplook_default_fourth_amount > 0 ) { ?>
																			<li>
																				<div class="radio">
																					<input type="radio" name="amount_cc" id="field-100-usd" value="<?php echo esc_attr( $wplook_default_fourth_amount ); ?>">

																					<label for="field-100-usd"><?php echo esc_attr( $wplook_default_fourth_amount ); ?> <?php echo ot_get_option('wpl_curency_code'); ?></label>
																				</div><!-- /.radio -->
																			</li>
																			<?php } ?>
																			<?php if ( $wplook_default_fifth_amount > 0 ) { ?>
																			<li>
																				<div class="radio">
																					<input type="radio" name="amount_cc" id="field-150-usd" value="<?php echo esc_attr( $wplook_default_fifth_amount ); ?>">

																					<label for="field-150-usd"><?php echo esc_attr( $wplook_default_fifth_amount ); ?> <?php echo ot_get_option('wpl_curency_code'); ?></label>
																				</div><!-- /.radio -->
																			</li>
																			<?php } ?>
																			<?php if ( $wplook_default_sixth_amount > 0 ) { ?>
																			<li>
																				<div class="radio">
																					<input type="radio" name="amount_cc" id="field-200-usd" value="<?php echo esc_attr( $wplook_default_sixth_amount ); ?>">

																					<label for="field-200-usd"><?php echo esc_attr( $wplook_default_sixth_amount ); ?> <?php echo ot_get_option('wpl_curency_code'); ?></label>
																				</div><!-- /.radio -->
																			</li>
																			<?php } ?>
																		</ul><!-- /.list-radios -->
																	</div>
																</div>
															</fieldset>
															<p></p>
														</div><!-- /.form-controls -->
													</div>
													<div class="cell small-12 medium-6">
														<fieldset class="fieldset">
															<legend><?php _e('Include Credit Card Fees', 'charity-wpl'); ?></legend>
																<input name="ccfees" id="ccfees" type="checkbox">
																<label for="ccfees">
																	<span data-curency-code="<?php echo ot_get_option('wpl_curency_code'); ?>" data-fixed-fee="<?php  echo esc_attr( $wplook_default_fixed_fee  ); ?>" data-percent-fee="<?php  echo esc_attr( $wplook_default_percent_fee ); ?>" class="js_cc_fees"></span> <?php _e( 'Credit Card Fees', 'charity-wpl' ); ?>
																</label>
														</fieldset>
													</div>
													<div class="cell small-12 medium-6">
														<fieldset class="fieldset">
															<legend><?php _e('Donation Frequency', 'charity-wpl'); ?></legend>
																<input type="radio" name="donation_frequency" value="onetime" id="onetime" checked="checked"><label for="onetime"><?php _e('One Time', 'charity-wpl'); ?></label>
																<input type="radio" name="donation_frequency" value="week" id="week"><label for="week"><?php _e('Weekly', 'charity-wpl'); ?></label>
																<input type="radio" name="donation_frequency" value="month" id="month"><label for="month"><?php _e('Monthly', 'charity-wpl'); ?></label>
														</fieldset>
													</div>
												</div> <!-- /.grid-x grid-margin-x -->

												<fieldset class="fieldset">
													<legend><?php _e('Credit Card Information', 'charity-wpl'); ?></legend>
													<div class="grid-x grid-margin-x">
														<div class="cell small-12 medium-6">
															<label><?php _e('Card Number', 'charity-wpl'); ?>
																<input type="text" placeholder="<?php _e('Card Number', 'charity-wpl'); ?>" size="20" data-stripe="number" class="card-number" />
															</label>
														</div>
														<div class="cell small-12 medium-6">
															<img class="stripe-cards" src="<?php echo get_template_directory_uri(); ?>/assets/images/stripe-cards.svg">
														</div>
													</div>
													<div class="grid-x grid-margin-x">
														<div class="cell small-12 medium-4">
															<label><?php _e('Expiration Month  (MM)', 'charity-wpl'); ?>
																<input type="text" placeholder="MM" size="2" data-stripe="exp-month" class="card-expiry-month" />
															</label>
														</div>
														<div class="cell small-12 medium-4">
															<label><?php _e('Expiration Year  (YYYY)', 'charity-wpl'); ?>
																<input  type="text" placeholder="YYYY" size="4" data-stripe="exp-year" class="card-expiry-year" />
															</label>
														</div>
														<div class="cell small-12 medium-4">
															<label><?php _e('CVC', 'charity-wpl'); ?>
																<input type="text" placeholder="<?php _e('CVC', 'charity-wpl'); ?>" size="4" data-stripe="cvc"  class="card-cvc" />
															</label>
														</div>
													</div>
												</fieldset>
												<div class="grid-x grid-margin-x">
													<div class="cell small-12">
														<fieldset class="fieldset">
															<legend><?php _e('I give a donation for:', 'charity-wpl'); ?></legend>
															<select name="causeid">
																<option value="<?php echo esc_attr( $wplook_pid ); ?>" <?php selected( '<?php echo esc_attr( $wplook_pid ); ?>' ); ?>><?php _e('General Donation', 'charity-wpl'); ?></option>
																	<?php $args = array( 'post_type' => 'post_causes', 'post_status' => 'publish', 'posts_per_page' => 1000, 'paged'=> $paged); ?>
																	<?php $wp_query = null; ?>
																	<?php $wp_query = new WP_Query( $args ); ?>
																	<?php if ( $wp_query->have_posts() ) :
																	$id = get_the_ID();
																	while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
																		<option value="<?php echo $id; ?>" <?php selected( '<?php the_title(); ?>' ); ?>><?php the_title(); ?></option>
																	<?php endwhile; wp_reset_postdata(); ?>
																	<?php endif; ?>
															</select>
														</fieldset>
													</div>
												</div>

												<div class="grid-x grid-margin-x">
													<div class="cell small-12">
														<fieldset class="fieldset">
															<legend><?php _e('Comments', 'charity-wpl'); ?></legend>
																<textarea name="comments" placeholder="<?php _e('Comments', 'charity-wpl'); ?>"></textarea>
														</fieldset>
													</div>
												</div>

												<div class="grid-x grid-margin-x">
													<div class="cell small-12 form-actions">
														<input type="submit" value="<?php _e('Donate Now', 'charity-wpl'); ?>" class="button">
													</div>
												</div>
										</form>
									</div>


											<script type="text/javascript">
												// this identifies your website in the createToken call below
												jQuery(document).ready(function() {
													Stripe.setPublishableKey('<?php echo ot_get_option('wpl_cc_publishable_key'); ?>');
												});
												function stripeResponseHandler(status, response) {
													if (response.error) {
														// re-enable the submit button
														jQuery('.button').removeAttr("disabled");
														// show the errors on the form
														jQuery(".payment-errors").removeClass("hide").html(response.error.message);
													} else {
														var form$ = jQuery("#payment-form");
														// token contains id, last4, and card type
														var token = response['id'];
														// insert the token into the form so it gets submitted to the server
														form$.append("<input type='hidden' name='stripeToken' value='" + token + "' />");
														// and submit
														form$.get(0).submit();
													}
												}
												jQuery(document).ready(function() {
													jQuery("#payment-form").submit(function(event) {
														// disable the submit button to prevent repeated clicks
														jQuery('.button').attr("disabled", "disabled");
														// createToken returns immediately - the supplied callback submits the form if there are no errors
														Stripe.createToken({
															number: jQuery('.card-number').val(),
															cvc: jQuery('.card-cvc').val(),
															exp_month: jQuery('.card-expiry-month').val(),
															exp_year: jQuery('.card-expiry-year').val(),
															metadata: { _wpl_cause_id: jQuery('.causeid').val()}
														}, stripeResponseHandler);
														return false; // submit from callback
													});
												});
											</script>
										<?php endif; ?>

										<!-- Bank transfer -->
										<?php if (ot_get_option('wpl_activate_bank_transfer') == 'on') :  ?>
											<div class="tabs-panel" id="panel3">
												<?php echo wp_kses_post( ot_get_option('wpl_direct_bank_transfer') ); ?>
											</div>
										<?php endif; ?>
										<?php if (ot_get_option('wpl_activate_check_payment') == 'on') :  ?>
											<div class="tabs-panel" id="panel4">
												<?php echo wp_kses_post( ot_get_option('wpl_cheque_payment') ); ?>
											</div>
										<?php endif; ?>
									</div>
								</div>

								<?php endif; ?>
							</div><!-- /.content -->
						</div><!-- /.cell large-8 -->
					<?php if ( $wplook_sidebar_position != 'disable') { ?>
						<div id="sidebar" class="cell large-3 large-offset-1">
							<div class="sidebar">
								<?php dynamic_sidebar( $wplook_page_sidebar ); ?>
							</div><!-- /.sidebar -->
						</div><!-- /.cell large-3 large-offset-1 -->
					<?php } ?>
				</div><!-- /.grid-x grid-margin-x -->
			</div><!-- /.grid-container -->
		</div><!-- /.main-body -->
	</div><!-- /.main -->

<?php get_footer(); ?>
