Your IP : 216.73.216.95


Current Path : /var/test/www/ljmti/wp-content/plugins/goodlayers-lms/
Upload File :
Current File : /var/test/www/ljmti/wp-content/plugins/goodlayers-lms/single-stripe.php

<?php get_header(); ?>
<div id="primary" class="content-area gdlr-lms-primary-wrapper">
<div id="content" class="site-content" role="main">
	<?php
		global $wpdb, $gdlr_lms_option;

		// get price
		$invoice = empty($_GET['invoice'])? 0: $_GET['invoice'];

		$temp_sql  = "SELECT * FROM " . $wpdb->prefix . "gdlrpayment ";
		$temp_sql .= "WHERE id = " . $invoice;	
		$result = $wpdb->get_row($temp_sql);
		$payment_info = unserialize($result->payment_info);

		$price = (floatval($result->price) * 100);

		\Stripe\Stripe::setAppInfo(
		  "WordPress GoodLms Plugin",
		  "2.1.3",
		  "https://codecanyon.net/item/good-lms-learning-management-system-wp-plugin/9033850"
		);
		\Stripe\Stripe::setApiKey(trim($gdlr_lms_option['stripe-secret-key']));
		$intent = \Stripe\PaymentIntent::create([
		    'amount' => $price,
		    'currency' => trim($gdlr_lms_option['stripe-currency-code']),
		    'receipt_email' => $payment_info['email'],
		    'description' => get_the_title($result->course_id),
		    'metadata' => array(
		    	'invoice' => $invoice,
		    	'email' => $payment_info['email']
		    )
		]);

		if( function_exists('gdlr_lms_get_header') && !empty($gdlr_lms_option['show-header']) && $gdlr_lms_option['show-header'] == 'enable' ){
			gdlr_lms_get_header();
		}
	?>
	<div class="gdlr-lms-content">
		<div class="gdlr-lms-container gdlr-lms-container">
			<div class="gdlr-lms-item">	
				<form action="" method="POST" id="payment-form" class="gdlr-lms-form" data-ajax="<?php echo admin_url('admin-ajax.php'); ?>" data-invoice="<?php echo esc_attr($invoice); ?>" >
					<div class="gdlr-lms-error payment-errors" style="display: none;"></div>
				
					<p class="gdlr-lms-half-left">
						<label><span><?php _e('Card Holder Name', 'gdlr-lms'); ?></span></label>
						<input id="cardholder-name" type="text">
					</p>
					<div class="clear" ></div>
					
					<div class="gdlr-lms-half-left">
						<label><span><?php _e('Card Information', 'gdlr-lms'); ?></span></label>
						<div id="card-element"></div>
					</div>
					<div class="clear" ></div>

					<div class="gdlr-lms-loading gdlr-lms-instant-payment-loading"><?php _e('loading', 'gdlr-lms'); ?></div>
					<div class="gdlr-lms-notice gdlr-lms-instant-payment-notice"></div>
					<input id="card-button" type="submit" class="gdlr-lms-button cyan" data-secret="<?= $intent->client_secret ?>" value="<?php _e('Submit Payment', 'gdlr-lms'); ?>" >
				</form>
			</div>
		</div>
	</div>
</div>
</div>

<script type="text/javascript">
jQuery(function($){
	var form = $('#payment-form');

	var stripe = Stripe('<?php echo esc_js(trim($gdlr_lms_option['stripe-publishable-key'])); ?>');
	var elements = stripe.elements();
	var cardElement = elements.create('card');
	cardElement.mount('#card-element');

	var cardholderName = document.getElementById('cardholder-name');
	var cardButton = document.getElementById('card-button');
	var clientSecret = cardButton.dataset.secret;
	cardButton.addEventListener('click', function(ev){

		// validate empty input field
		if( !form.find('#cardholder-name').val() ){
			var req = true;
		}else{
			var req = false;
		}
		
		// make the payment
		if( req ){
			form.find('.payment-errors').text('<?php _e('Please fill the card holder name', 'gdlr-lms'); ?>').slideDown();
		}else{

			// Disable the submit button to prevent repeated clicks
			$(cardButton).prop('disabled', true);
			form.find('.payment-errors, .gdlr-lms-notice').slideUp();
			form.find('.gdlr-lms-loading').slideDown();
			
			// make the payment
			stripe.handleCardPayment(
				clientSecret, cardElement, {
					payment_method_data: {
						billing_details: {name: cardholderName.value}
					}
				}
			).then(function(result){
				if( result.error ){

					form.find('.payment-errors').text(result.error.message).slideDown();
					form.find('.gdlr-lms-loading').slideUp(); 
					$(cardButton).prop('disabled', false);
	
				}else{

					$.ajax({
						type: 'POST',
						url: form.attr('data-ajax'),
						data: {'action':'gdlr_lms_stripe_payment', 'paymentIntent': result.paymentIntent.id, 'invoice': form.attr('data-invoice')},
						dataType: 'json',
						error: function(a, b, c){ 
							console.log(a, b, c); 
							form.find('.gdlr-form-loading').slideUp(); 
							$(cardButton).prop('disabled', false);
						},
						success: function(data){

							form.find('.gdlr-lms-loading').slideUp();
							form.find('.gdlr-lms-notice').removeClass('success failed')
								.addClass(data.status).html(data.message).slideDown();
							
							if( data.status == 'failed' ){
								form.find('input[type="submit"]').prop('disabled', false);
							}
								
							if( data.redirect ){
								window.location.replace(data.redirect);
							}

						}
					});	

				}
			});

		}
	});

	$(cardButton).on('click', function(){
		return false;
	});

});
</script>
<?php
if( !empty($gdlr_lms_option['show-sidebar']) && $gdlr_lms_option['show-sidebar'] == 'enable' ){ 
	get_sidebar( 'content' );
	get_sidebar();
}

get_footer(); ?>