示例#1
0
    /**
     * Output the Stripe's payment dialog.
     * Step 2 in the payment process.
     */
    public function pay_page()
    {
        $payment_id = absint(get_query_var('edu-pay'));
        if (!$payment_id) {
            return;
        }
        $user = wp_get_current_user();
        if (0 == $user->ID) {
            return;
        }
        $payment = edr_get_payment($payment_id);
        if (!$payment->ID || $user->ID != $payment->user_id) {
            // The payment must exist and it must be associated with the current user.
            return;
        }
        if ('course' == $payment->payment_type) {
            $post = get_post($payment->course_id);
        } elseif ('membership' == $payment->payment_type) {
            $post = get_post($payment->object_id);
        }
        if (!$post) {
            return;
        }
        ?>
		<p id="ib-edu-payment-processing-msg">
			<?php 
        _e('The payment is getting processed...', 'ibeducator');
        ?>
		</p>
		<script src="https://checkout.stripe.com/checkout.js"></script>
		<script>
		(function($) {
			var handler = StripeCheckout.configure({
				key: <?php 
        echo json_encode($this->get_option('publishable_key'));
        ?>
,
				image: '',
				email: <?php 
        echo json_encode($user->user_email);
        ?>
,
				token: function(token) {
					$.ajax({
						type: 'POST',
						cache: false,
						url: <?php 
        echo json_encode(ib_edu_request_url('stripe_token'));
        ?>
,
						data: {
							payment_id: <?php 
        echo intval($payment->ID);
        ?>
,
							token: token.id,
							_wpnonce: <?php 
        echo json_encode(wp_create_nonce('ib_educator_stripe_token'));
        ?>
						},
						success: function(response) {
							if (response === '1') {
								$('#ib-edu-payment-processing-msg').text(<?php 
        echo json_encode(__('Redirecting to the payment summary page...', 'ibeducator'));
        ?>
);
								var redirectTo = <?php 
        echo json_encode(ib_edu_get_endpoint_url('edu-thankyou', $payment->ID, get_permalink(ib_edu_page_id('payment'))));
        ?>
;
								document.location = redirectTo;
							}
						}
					});
				}
			});

			handler.open({
				name: <?php 
        echo json_encode(esc_html($post->post_title));
        ?>
,
				description: <?php 
        echo json_encode(ib_edu_format_price($payment->amount, false, false));
        ?>
,
				currency: <?php 
        echo json_encode(ib_edu_get_currency());
        ?>
,
				amount: <?php 
        echo absint($payment->amount * 100);
        ?>
			});

			$(window).on('popstate', function() {
				handler.close();
			});
		})(jQuery);
		</script>
		<?php 
    }
示例#2
0
</a></h2>
	</header>

	<section class="price">
		<?php 
echo $ms->format_price($membership_meta['price'], $membership_meta['duration'], $membership_meta['period']);
?>
	</section>

	<section class="membership-summary">
		<?php 
$continue_reading = get_theme_mod('continue_reading') ? sprintf(__('Continue reading %s', 'ib-educator'), the_title('<span class="screen-reader-text">', '</span>', false)) : '';
the_content($continue_reading);
?>
	</section>

	<footer class="membership-options post-meta">
		<?php 
if (function_exists('ib_edu_purchase_link')) {
    echo ib_edu_purchase_link(array('object_id' => $membership_id, 'type' => 'membership'));
} else {
    $purchase_url = ib_edu_get_endpoint_url('edu-membership', $membership_id, get_permalink(ib_edu_page_id('payment')));
    echo '<a href="' . esc_url($purchase_url) . '">' . __('Purchase', 'ibeducator') . '</a>';
}
?>

		<?php 
echo educator_share('menu');
?>
	</footer>
</article>
        ?>
</td>
			<td>
				<?php 
        if (array_key_exists($payment->payment_status, $statuses)) {
            echo esc_html($statuses[$payment->payment_status]);
        }
        ?>
			</td>
			<td><?php 
        echo ib_edu_format_price($payment->amount, false);
        ?>
</td>
			<td class="actions-group">
				<?php 
        $invoice_url = ib_edu_get_endpoint_url('edu-thankyou', $payment->ID, get_permalink(ib_edu_page_id('payment')));
        ?>
				<a href="<?php 
        echo esc_url($invoice_url);
        ?>
"><?php 
        _e('Details', 'ibeducator');
        ?>
</a>

				<?php 
        if ('pending' == $payment->payment_status) {
            ?>
				<form action="<?php 
            echo esc_url(ib_edu_get_endpoint_url('edu-action', 'cancel-payment', get_permalink()));
            ?>
示例#4
0
</a></li>
							</ul>
						</div>

						<?php 
    if ('registered' == get_query_var('action')) {
        echo '<div class="ib-edu-message success">' . __('Registration complete.', 'ib-educator') . '</div>';
    }
    ?>

						<div class="login-form clearfix">
							<?php 
    $redirect_to = get_query_var('redirect_to');
    if (empty($redirect_to)) {
        // Determine default redirect URL.
        $student_courses_page_id = ib_edu_page_id('student_courses');
        if ($student_courses_page_id) {
            $redirect_to = get_permalink($student_courses_page_id);
        } else {
            $user_page_id = get_theme_mod('user_page');
            if ($user_page_id) {
                $redirect_to = ib_edu_get_endpoint_url('action', 'courses', get_permalink($user_page_id));
            }
        }
    }
    remove_filter('login_url', 'educator_login_url_filter', 10, 2);
    wp_login_form(array('id_submit' => 'submit-login-form', 'redirect' => $redirect_to));
    add_filter('login_url', 'educator_login_url_filter', 10, 2);
    ?>

							<p class="lost-password-link">
		<dt class="payment-total"><?php 
    esc_html_e('Total', 'training');
    ?>
</dt>
		<dd><?php 
    echo ib_edu_format_price($payment->amount, false);
    ?>
</dd>
	</dl>
	<?php 
    if ($payment->ID && $payment->user_id == $user_id) {
        do_action('ib_educator_thankyou_' . $payment->payment_gateway);
    }
    // Show link to the payments page.
    $payments_page = get_post(ib_edu_page_id('user_payments'));
    if ($payments_page) {
        echo '<p>' . sprintf(esc_html__('Go to %s page', 'training'), '<a href="' . esc_url(get_permalink($payments_page->ID)) . '">' . esc_html($payments_page->post_title) . '</a>') . '</p>';
    }
} else {
    if ($pay = get_query_var('edu-pay')) {
        // Can be used for step 2 of the payment process.
        // PayPal gateway uses it.
        if (!is_numeric($pay)) {
            return;
        }
        $payment = IB_Educator_Payment::get_instance($pay);
        // The payment must exist and it must belong to the current user.
        if ($payment->ID && $payment->user_id == $user_id) {
            do_action('ib_educator_pay_' . $payment->payment_gateway);
        }
示例#6
0
 /**
  * Get the membership price widget.
  *
  * @param int $membership_id
  * @return string
  */
 public function get_price_widget($membership_id = null)
 {
     if (is_null($membership_id)) {
         $membership_id = get_the_ID();
     }
     $output = apply_filters('ib_educator_membership_price_widget', null, $membership_id);
     if (!is_null($output)) {
         return $output;
     }
     $price = $this->get_price($membership_id);
     $payment_url = ib_edu_get_endpoint_url('edu-membership', $membership_id, get_permalink(ib_edu_page_id('payment')));
     $output = '<div class="ib-edu-price-widget">';
     $output .= '<span class="price">' . ib_edu_format_price($price) . '</span>';
     $output .= '<a href="' . esc_url($payment_url) . '" class="ib-edu-button">' . __('Purchase', 'ibeducator') . '</a>';
     $output .= '</div>';
     return $output;
 }
示例#7
0
function ib_edu_purchase_link($atts)
{
    $atts = wp_parse_args($atts, array('object_id' => null, 'type' => null, 'text' => __('Purchase', 'ib-educator'), 'class' => array()));
    // Add default class.
    array_push($atts['class'], 'edu-purchase-link');
    $html = apply_filters('ib_edu_pre_purchase_link', null, $atts);
    if (!is_null($html)) {
        return $html;
    }
    if ('membership' == $atts['type']) {
        $html = sprintf('<a href="%s" class="%s">%s</a>', esc_url(ib_edu_get_endpoint_url('edu-membership', $atts['object_id'], get_permalink(ib_edu_page_id('payment')))), esc_attr(implode(' ', $atts['class'])), $atts['text']);
    }
    return $html;
}
    /**
     * Send the membership expiration emails to users.
     */
    public static function send_expiration_notifications()
    {
        global $wpdb;
        $days_notify = ib_edu_get_option('days_notify', 'memberships');
        if (null === $days_notify) {
            $days_notify = 5;
        } else {
            $days_notify = absint($days_notify);
        }
        $expires_date = date('Y-m-d', strtotime('+ ' . $days_notify . ' days'));
        $tables = ib_edu_table_names();
        $users = $wpdb->get_results($wpdb->prepare('SELECT u.ID, u.user_email, u.display_name, m.expiration, m.membership_id
			FROM ' . $tables['members'] . ' m
			INNER JOIN ' . $wpdb->users . ' u ON u.ID = m.user_id
			WHERE m.`expiration` LIKE %s AND m.`status` = %s', $expires_date . '%', 'active'));
        if (empty($users)) {
            return;
        }
        // Get memberships.
        $membership_ids = array();
        foreach ($users as $user) {
            if (!in_array($user->membership_id, $membership_ids)) {
                $membership_ids[] = $user->membership_id;
            }
        }
        $memberships = get_posts(array('post_type' => 'ib_edu_membership', 'include' => $membership_ids, 'post_status' => 'publish', 'posts_per_page' => -1));
        if ($memberships) {
            foreach ($memberships as $key => $membership) {
                $memberships[$membership->ID] = $membership;
                unset($memberships[$key]);
            }
            foreach ($users as $user) {
                ib_edu_send_notification($user->user_email, 'membership_renew', array(), array('student_name' => $user->display_name, 'membership' => isset($memberships[$user->membership_id]) ? $memberships[$user->membership_id]->post_title : '', 'expiration' => date_i18n(get_option('date_format'), strtotime($user->expiration)), 'membership_payment_url' => ib_edu_get_endpoint_url('edu-membership', $user->membership_id, get_permalink(ib_edu_page_id('payment')))));
            }
        }
    }
示例#9
0
    /**
     * Output the form to the step 2 (pay page) of the payment page.
     */
    public function pay_page()
    {
        $action_url = $this->get_option('test') ? $this->test_url : $this->live_url;
        $payment_id = absint(get_query_var('edu-pay'));
        if (!$payment_id) {
            return;
        }
        $user_id = get_current_user_id();
        if (!$user_id) {
            return;
        }
        $payment = edr_get_payment($payment_id);
        // The payment must exist in the database
        // and it must belong to the current user.
        if (!$payment->ID || $user_id != $payment->user_id) {
            return;
        }
        if ('course' == $payment->payment_type) {
            $post = get_post($payment->course_id);
        } elseif ('membership' == $payment->payment_type) {
            $post = get_post($payment->object_id);
        }
        if (!$post) {
            return;
        }
        $amount = $payment->amount - $payment->tax;
        $return_url = '';
        $payment_page_id = ib_edu_page_id('payment');
        if ($payment_page_id) {
            $return_url = ib_edu_get_endpoint_url('edu-thankyou', $payment->ID ? $payment->ID : '', get_permalink($payment_page_id));
        }
        echo '<form id="ib-edu-paypal-form" action="' . esc_url($action_url) . '" method="post">';
        echo '<input type="hidden" name="cmd" value="_xclick">';
        echo '<input type="hidden" name="charset" value="utf-8">';
        echo '<input type="hidden" name="business" value="' . esc_attr($this->get_option('business_email')) . '">';
        echo '<input type="hidden" name="return" value="' . esc_url($return_url) . '">';
        echo '<input type="hidden" name="notify_url" value="' . esc_url(ib_edu_request_url('paypalipn')) . '">';
        echo '<input type="hidden" name="currency_code" value="' . esc_attr(ib_edu_get_currency()) . '">';
        echo '<input type="hidden" name="item_name" value="' . esc_attr($post->post_title) . '">';
        echo '<input type="hidden" name="item_number" value="' . absint($payment->ID) . '">';
        if ($payment->tax) {
            echo '<input type="hidden" name="tax" value="' . (double) $payment->tax . '">';
        }
        echo '<input type="hidden" name="amount" value="' . (double) $amount . '">';
        echo '<div id="paypal-form-buttons"><button type="submit">' . __('Continue', 'ibeducator') . '</button></div>';
        echo '</form>';
        echo '<div id="paypal-redirect-notice" style="display: none;">' . __('Redirecting to PayPal...', 'ibeducator') . '</div>';
        echo '<script>(function() {
			function goToPayPal() {
				document.getElementById("paypal-form-buttons").style.display = "none";
				document.getElementById("paypal-redirect-notice").style.display = "block";
				document.getElementById("ib-edu-paypal-form").submit();
			}

			if ( typeof jQuery === "undefined" ) {
				setTimeout(goToPayPal, 500);
			} else {
				jQuery(document).on("ready", function() {
					goToPayPal();
				});
			}
		})();</script>';
    }
 /**
  * Get the url to the "thank you" page.
  *
  * @param array $args
  * @return string
  */
 public function get_redirect_url($args)
 {
     $redirect = '';
     if (isset($args['value'])) {
         $redirect = ib_edu_get_endpoint_url('edu-thankyou', $args['value'], get_permalink(ib_edu_page_id('payment')));
     } else {
         $redirect = ib_edu_get_endpoint_url('edu-thankyou', '', get_permalink(ib_edu_page_id('payment')));
     }
     return $redirect;
 }
</h1>
						<?php 
do_action('ib_educator_after_course_title');
?>
						<div class="course-rating">
							<?php 
if (function_exists('the_ratings')) {
    the_ratings();
}
?>
						</div>
						<?php 
$output = '<ul class="list">';
$price = ib_edu_get_course_price($course_id);
$price = 0 == $price ? esc_html__('Free', 'training') : ib_edu_format_course_price($price);
$register_url = ib_edu_get_endpoint_url('edu-course', $course_id, get_permalink(ib_edu_page_id('payment')));
$output .= '<li class="price"><i class="uicon icon-price"></i><span class="lab">' . esc_html__('Price: ', 'training') . '</span> <span class="val">' . $price . '</span></li>';
if (isset($options['duration']) && $options['duration']) {
    $output .= '<li class="price"><i class="uicon icon-duration"></i><span class="lab">' . esc_html__('Duration: ', 'training') . '</span> <span class="val">' . $options['duration'] . '</span></li>';
}
if (isset($options['is_certificates'])) {
    $output .= '<li class="price hidden"><i class="uicon icon-certificates"></i><span class="lab">' . esc_html__('Certificates: ', 'training') . '</span> <span class="val">' . ($options['is_certificates'] ? esc_html__('Yes', 'training') : esc_html__('No', 'training')) . '</span></li>';
}
$output .= '<li class="lesson"><i class="uicon icon-students"></i><span class="lab">' . esc_html__('Students: ', 'training') . '</span> <span class="val">' . count($students) . '</span></li>';
$output .= '<li class="lesson"><i class="uicon icon-lesson"></i><span class="lab">' . esc_html__('Lesson: ', 'training') . '</span> <span class="val">' . $api->get_num_lessons(get_the_id()) . '</span></li>';
$output .= '</ul>';
echo trim($output);
?>

						<div class="action">
								<?php 
示例#12
0
 /**
  * Protect private pages.
  */
 public static function protect_private_pages()
 {
     // User must be logged in to view a private pages (e.g. payment, my courses).
     $private_pages = array();
     // Student courses page.
     $student_courses_page = ib_edu_page_id('student_courses_page');
     if ($student_courses_page > 0) {
         $private_pages[] = $student_courses_page;
     }
     if (!empty($private_pages) && is_page($private_pages) && !is_user_logged_in()) {
         wp_redirect(wp_login_url(get_permalink($GLOBALS['wp_query']->post->ID)));
         exit;
     }
 }