/** * Setup the registration details * * @since 2.5 */ function rcp_calc_total_ajax() { $return = array('valid' => false, 'total' => __('No available subscription levels for your account.', 'rcp')); if (!rcp_is_registration()) { wp_send_json($return); } ob_start(); rcp_get_template_part('register-total-details'); $return['total'] = ob_get_clean(); wp_send_json($return); }
function rcp_change_password_form($args = array()) { global $rcp_password_form_args; // parse the arguments passed $defaults = array('redirect' => rcp_get_current_url()); $rcp_password_form_args = wp_parse_args($args, $defaults); ob_start(); do_action('rcp_before_password_form'); rcp_get_template_part('change-password'); do_action('rcp_after_password_form'); return ob_get_clean(); }
/** * Generate Invoice * * @since 2.6 */ function rcp_generate_invoice($payment_id = 0) { global $rcp_options, $rcp_payment, $rcp_member; if (empty($payment_id)) { return; } $payments_db = new RCP_Payments(); $payment = $payments_db->get_payment($payment_id); if (!$payment) { wp_die(__('This payment record does not exist', 'rcp')); } if ($payment->user_id != get_current_user_id() && !current_user_can('rcp_manage_payments')) { wp_die(__('You do not have permission to download this invoice', 'rcp')); } $rcp_payment = $payment; $rcp_member = new RCP_Member($payment->user_id); rcp_get_template_part('invoice'); die; // Stop the rest of the page from processsing and being sent to the browser }
/** * Process registration * * @since 2.3 */ public function fields() { ob_start(); ?> <script type="text/javascript"> // Called when token created successfully. var successCallback = function(data) { // re-enable the submit button jQuery('#rcp_registration_form #rcp_submit').attr("disabled", false); // Remove loding overlay jQuery('#rcp_ajax_loading').hide(); var form$ = jQuery('#rcp_registration_form'); // token contains id, last4, and card type var token = data.response.token.token; // insert the token into the form so it gets submitted to the server form$.append("<input type='hidden' name='twoCheckoutToken' value='" + token + "' />"); form$.get(0).submit(); }; // Called when token creation fails. var errorCallback = function(data) { if (data.errorCode === 200) { tokenRequest(); } else { jQuery('#rcp_registration_form').unblock(); jQuery('#rcp_submit').before( '<div class="rcp_message error"><p class="rcp_error"><span>' + data.errorMsg + '</span></p></div>' ); jQuery('#rcp_submit').val( rcp_script_options.register ); } }; var tokenRequest = function() { // Setup token request arguments var args = { sellerId: '<?php echo $this->seller_id; ?> ', publishableKey: '<?php echo $this->publishable_key; ?> ', ccNo: jQuery('.rcp_card_number').val(), cvv: jQuery('.rcp_card_cvc').val(), expMonth: jQuery('.rcp_card_exp_month').val(), expYear: jQuery('.rcp_card_exp_year').val() }; // Make the token request TCO.requestToken(successCallback, errorCallback, args); }; jQuery(document).ready(function($) { // Pull in the public encryption key for our environment TCO.loadPubKey('<?php echo $this->environment; ?> '); jQuery("#rcp_registration_form").submit(function(e) { if( jQuery('.rcp_level:checked').length ) { var price = jQuery('.rcp_level:checked').closest('.rcp_subscription_level').find('span.rcp_price').attr('rel'); } else { var price = jQuery('.rcp_level').attr('rel'); } if( price > 0 && ! jQuery('.rcp_gateway_fields').hasClass('rcp_discounted_100') ) { // Call our token request function tokenRequest(); // Prevent form from submitting return false; } }); }); </script> <?php rcp_get_template_part('card-form', 'full'); return ob_get_clean(); }
/** * Add credit card fields * * @since 2.1 * @return string */ public function fields() { ob_start(); ?> <script type="text/javascript"> var rcp_script_options; var rcp_processing; var rcp_stripe_processing = false; // this identifies your website in the createToken call below Stripe.setPublishableKey('<?php echo $this->publishable_key; ?> '); function stripeResponseHandler(status, response) { if (response.error) { // re-enable the submit button jQuery('#rcp_registration_form #rcp_submit').attr("disabled", false); jQuery('#rcp_ajax_loading').hide(); // show the errors on the form jQuery('#rcp_registration_form').unblock(); jQuery('#rcp_submit').before( '<div class="rcp_message error"><p class="rcp_error"><span>' + response.error.message + '</span></p></div>' ); jQuery('#rcp_submit').val( rcp_script_options.register ); rcp_stripe_processing = false; rcp_processing = false; } else { var form$ = jQuery('#rcp_registration_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($) { $("#rcp_registration_form").on('submit', function(event) { if( ! rcp_stripe_processing ) { rcp_stripe_processing = true; // get the subscription price if( $('.rcp_level:checked').length ) { var price = $('.rcp_level:checked').closest('.rcp_subscription_level').find('span.rcp_price').attr('rel') * <?php echo rcp_stripe_get_currency_multiplier(); ?> ; } else { var price = $('.rcp_level').attr('rel') * <?php echo rcp_stripe_get_currency_multiplier(); ?> ; } if( ( $('select#rcp_gateway option:selected').val() == 'stripe' || $('input[name=rcp_gateway]').val() == 'stripe') && price > 0 && ! $('.rcp_gateway_fields').hasClass('rcp_discounted_100')) { event.preventDefault(); // disable the submit button to prevent repeated clicks $('#rcp_registration_form #rcp_submit').attr("disabled", "disabled"); $('#rcp_ajax_loading').show(); // createToken returns immediately - the supplied callback submits the form if there are no errors Stripe.createToken({ number: $('.card-number').val(), name: $('.card-name').val(), cvc: $('.card-cvc').val(), exp_month: $('.card-expiry-month').val(), exp_year: $('.card-expiry-year').val(), address_zip: $('.card-zip').val() }, stripeResponseHandler); return false; } } }); }); </script> <?php rcp_get_template_part('card-form'); return ob_get_clean(); }
/** * Update card form short code * * Displays a form to update the billing credit / debit card * * @access public * @since 2.1 */ function rcp_update_billing_card_shortcode( $atts, $content = null ) { global $rcp_load_css, $rcp_load_scripts; $rcp_load_css = true; $rcp_load_scripts = true; ob_start(); if( rcp_member_can_update_billing_card() ) { do_action( 'rcp_before_update_billing_card_form' ); rcp_get_template_part( 'card-update', 'form' ); do_action( 'rcp_after_update_billing_card_form' ); } return ob_get_clean(); }
/** * Add credit card form * * @since 2.1 * @return string */ public function fields() { ob_start(); rcp_get_template_part('card-form'); return ob_get_clean(); }
/** * Update card form short code * * Displays a form to update the billing credit / debit card. * * @since 2.1 * @access public * * @param $atts * @param $content */ function rcp_update_billing_card_shortcode($atts, $content = null) { global $rcp_load_css, $rcp_load_scripts; $rcp_load_css = true; $rcp_load_scripts = true; ob_start(); if (rcp_member_can_update_billing_card()) { do_action('rcp_before_update_billing_card_form'); if (isset($_GET['card'])) { switch ($_GET['card']) { case 'updated': echo '<p class="rcp_success"><span>' . __('Billing card updated successfully', 'rcp') . '</span></p>'; break; case 'not-updated': if (isset($_GET['msg'])) { $message = urldecode($_GET['msg']); } else { $message = __('Billing card could not be updated, please try again.', 'rcp'); } echo '<p class="rcp_error"><span>' . $message . '</span></p>'; break; } } rcp_get_template_part('card-update', 'form'); do_action('rcp_after_update_billing_card_form'); } return ob_get_clean(); }
/** * Remove comments from posts/pages if user does not have access * * @since 2.6 * @param $template Path to template file to load * * @return string Path to template file to load */ function rcp_hide_comments($template) { $post_id = get_the_ID(); if (!empty($post_id)) { if (!rcp_user_can_access(get_current_user_id(), $post_id)) { $template = rcp_get_template_part('comments', 'no-access', false); } } return $template; }
/** * Display the confirmation form * * @since 2.1 * @return string */ public function confirmation_form() { global $rcp_checkout_details; $token = sanitize_text_field($_GET['token']); $rcp_checkout_details = $this->get_checkout_details($token); ob_start(); rcp_get_template_part('paypal-express-confirm'); return ob_get_clean(); }
/** * Profile Editor Shortcode * * Outputs the EDD Profile Editor to allow users to amend their details from the * front-end * * @access public * @since 1.5 */ function rcp_profile_editor_shortcode($atts, $content = null) { global $rcp_load_css; $rcp_load_css = true; ob_start(); rcp_get_template_part('profile', 'editor'); return ob_get_clean(); }
/** * Loads the restricted content template if required. * * @access public * @since 2.5 */ public function hide_template($template, $slug, $name) { $product_id = get_the_ID(); if (!is_singular('product')) { return $template; } if ('content-single-product' !== $slug . '-' . $name) { return $template; } if (current_user_can('edit_post', $product_id)) { return $template; } $active_only = get_post_meta($product_id, '_rcp_woo_active_to_view', true); $levels = (array) get_post_meta($product_id, '_rcp_woo_subscription_levels_to_view', true); $access_level = get_post_meta($product_id, '_rcp_woo_access_level_to_view', true); $product_cat = rcp_is_post_taxonomy_restricted($product_id, 'product_cat'); $product_tag = rcp_is_post_taxonomy_restricted($product_id, 'product_tag'); /** * rcp_is_post_taxonomy_restricted() returns: * - true when restrictions are found for the current user * - false when restrictions are not found for the current user * - -1 when no terms are assigned, for which we don't care. * We're normalizing the value here. If the value is false, * the user has already passed the restriction checks. */ $cat_restricted = true === $product_cat ? true : false; $tag_restricted = true === $product_tag ? true : false; // Return early if no restrictions if (!$active_only && empty($levels[0]) && !$access_level && !$cat_restricted && !$tag_restricted) { return $template; } $visible = true; // Active subscription setting if ($active_only && !rcp_is_active()) { $visible = false; } // Subscription level setting if (!in_array(rcp_get_subscription_id(), $levels)) { $visible = false; } // User level setting if ($access_level && rcp_user_has_access(get_current_user_id(), $access_level)) { $visible = false; } if ($visible) { return $template; } return rcp_get_template_part('woocommerce', 'single-no-access', false); }