/**
 * Customize the PayPal Cancel Redirect URL.
 *
 * Be default when using PayPal standard when a donor clicks to PayPal and then clicks cancel return to the website it takes you to a Transaction Failed page instead of the donation page. This will redirect back to donation page when the donor cancels.
 *
 * Please note: when using this redirect payments won't be marked as "Failed" when a donor clicks the cancel option in PayPal. They will be left in a "pending" status until being marked as "abandoned" at the 7 day mark. Not a big deal for most, but it's worth mentioning.
 *
 * @see: https://wordpress.org/support/topic/paypal-back-to-website-url/
 *
 * @param array $paypal_args   Params used to build redirect query to PayPal.
 * @param array $donation_data Information about the donation.
 *
 * @return mixed
 */
function give_customize_paypal_failed_redirect($paypal_args, $donation_data)
{
    $cancel_url = add_query_arg(array('payment-mode' => 'paypal'), give_get_current_page_url());
    if (isset($paypal_args['cancel_return'])) {
        $paypal_args['cancel_return'] = $cancel_url;
    }
    return $paypal_args;
}
Beispiel #2
0
/**
 * Get AJAX URL
 *
 * @since 1.0
 * @return string
 */
function give_get_ajax_url()
{
    $scheme = defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN ? 'https' : 'admin';
    $current_url = give_get_current_page_url();
    $ajax_url = admin_url('admin-ajax.php', $scheme);
    if (preg_match('/^https/', $current_url) && !preg_match('/^https/', $ajax_url)) {
        $ajax_url = preg_replace('/^http/', 'https', $ajax_url);
    }
    return apply_filters('give_ajax_url', $ajax_url);
}
/**
 * Registration Form
 *
 * @since 2.0
 * @global       $give_options
 * @global       $post
 *
 * @param string $redirect Redirect page URL
 *
 * @return string Register form
 */
function give_register_form($redirect = '')
{
    global $give_options, $give_register_redirect;
    if (empty($redirect)) {
        $redirect = give_get_current_page_url();
    }
    $give_register_redirect = $redirect;
    ob_start();
    if (!is_user_logged_in()) {
        give_get_template_part('shortcode', 'register');
    }
    return apply_filters('give_register_form', ob_get_clean());
}
Beispiel #4
0
 public function test_get_donation_form()
 {
     $this->go_to('/');
     $args = array('id' => $this->_post->ID);
     ob_start();
     $form = give_get_donation_form($args);
     $form = ob_get_clean();
     $this->assertInternalType('string', $form);
     $this->assertContains('<form id="give-form-', $form);
     $this->assertContains('class="give-form', $form);
     $this->assertContains('method="post">', $form);
     $this->assertContains('<input type="hidden" name="give-form-id" value="' . $this->_post->ID . '"/>', $form);
     $this->assertContains('<input type="hidden" name="give-form-title" value="' . get_the_title($this->_post->ID) . '"/>', $form);
     $this->assertContains('<input type="hidden" name="give-form-url" value="' . give_get_current_page_url() . '"/>', $form);
     // The donation form we created has variable pricing, so ensure the price options render
     $this->assertContains('class="give-donation-levels-wrap', $form);
     $this->assertContains('<input type="hidden" name="give-price-id"', $form);
     // Test a single price point as well
 }
Beispiel #5
0
/**
 * Receipt Shortcode.
 *
 * Shows a donation receipt.
 *
 * @since 1.0
 *
 * @param array  $atts    Shortcode attributes.
 * @param string $content
 *
 * @return string
 */
function give_receipt_shortcode($atts, $content = null)
{
    global $give_receipt_args, $payment;
    $give_receipt_args = shortcode_atts(array('error' => esc_html__('Sorry, you are missing the payment key to view this donation receipt.', 'give'), 'price' => true, 'donor' => true, 'date' => true, 'payment_key' => false, 'payment_method' => true, 'payment_id' => true), $atts, 'give_receipt');
    //set $session var
    $session = give_get_purchase_session();
    //set payment key var
    if (isset($_GET['payment_key'])) {
        $payment_key = urldecode($_GET['payment_key']);
    } elseif ($session) {
        $payment_key = $session['purchase_key'];
    } elseif ($give_receipt_args['payment_key']) {
        $payment_key = $give_receipt_args['payment_key'];
    }
    $email_access = give_get_option('email_access');
    // No payment_key found & Email Access is Turned on:
    if (!isset($payment_key) && $email_access == 'on' && !Give()->email_access->token_exists) {
        ob_start();
        give_get_template_part('email-login-form');
        return ob_get_clean();
    } elseif (!isset($payment_key)) {
        return give_output_error($give_receipt_args['error'], false, 'error');
    }
    $payment_id = give_get_purchase_id_by_key($payment_key);
    $user_can_view = give_can_view_receipt($payment_key);
    // Key was provided, but user is logged out. Offer them the ability to login and view the receipt.
    if (!$user_can_view && $email_access == 'on' && !Give()->email_access->token_exists) {
        ob_start();
        give_get_template_part('email-login-form');
        return ob_get_clean();
    } elseif (!$user_can_view) {
        global $give_login_redirect;
        $give_login_redirect = give_get_current_page_url();
        ob_start();
        give_output_error(apply_filters('give_must_be_logged_in_error_message', esc_html__('You must be logged in to view this donation payment receipt.', 'give')));
        give_get_template_part('shortcode', 'login');
        $login_form = ob_get_clean();
        return $login_form;
    }
    /*
     * Check if the user has permission to view the receipt.
     *
     * If user is logged in, user ID is compared to user ID of ID stored in payment meta
     * or if user is logged out and purchase was made as a guest, the purchase session is checked for
     * or if user is logged in and the user can view sensitive shop data.
     *
     */
    if (!apply_filters('give_user_can_view_receipt', $user_can_view, $give_receipt_args)) {
        return give_output_error($give_receipt_args['error'], false, 'error');
    }
    ob_start();
    give_get_template_part('shortcode', 'receipt');
    $display = ob_get_clean();
    return $display;
}
    _e('Please note after changing your password, you must log back in.', 'give');
    ?>
</p>

			<?php 
    do_action('give_profile_editor_after_password');
    ?>

			<p id="give_profile_submit_wrap">
				<input type="hidden" name="give_profile_editor_nonce" value="<?php 
    echo wp_create_nonce('give-profile-editor-nonce');
    ?>
" />
				<input type="hidden" name="give_action" value="edit_user_profile" />
				<input type="hidden" name="give_redirect" value="<?php 
    echo esc_url(give_get_current_page_url());
    ?>
" />
				<input name="give_profile_editor_submit" id="give_profile_editor_submit" type="submit" class="give_submit" value="<?php 
    _e('Save Changes', 'give');
    ?>
" />
			</p>
		</fieldset>
	</form><!-- #give_profile_editor_form -->

	<?php 
    do_action('give_profile_editor_after');
    ?>

<?php 
Beispiel #7
0
/**
 * Receipt Shortcode
 *
 * Shows an order receipt.
 *
 * @since 1.0
 *
 * @param array  $atts Shortcode attributes
 * @param string $content
 *
 * @return string
 */
function give_receipt_shortcode($atts, $content = null)
{
    global $give_receipt_args, $payment;
    $give_receipt_args = shortcode_atts(array('error' => __('Sorry, it appears the viewing window for this donation receipt has expired or you do not have the permission to view this donation receipt.', 'give'), 'price' => true, 'date' => true, 'payment_key' => false, 'payment_method' => true, 'payment_id' => true), $atts, 'give_receipt');
    //set $session var
    $session = give_get_purchase_session();
    //set payment key var
    if (isset($_GET['payment_key'])) {
        $payment_key = urldecode($_GET['payment_key']);
    } elseif ($session) {
        $payment_key = $session['purchase_key'];
    } elseif ($give_receipt_args['payment_key']) {
        $payment_key = $give_receipt_args['payment_key'];
    }
    // No key found
    if (!isset($payment_key)) {
        return '<div class="give_errors"><p class="give_error">' . $give_receipt_args['error'] . '</p></div>';
    }
    $payment_id = give_get_purchase_id_by_key($payment_key);
    $user_can_view = give_can_view_receipt($payment_key);
    // Key was provided, but user is logged out. Offer them the ability to login and view the receipt
    if (!$user_can_view && !empty($payment_key) && !is_user_logged_in() && !give_is_guest_payment($payment_id)) {
        global $give_login_redirect;
        $give_login_redirect = give_get_current_page_url();
        ob_start();
        echo '<div class="give_errors"><p class="give_error">' . __('You must be logged in to view this payment receipt.', 'give') . '</p></div>';
        give_get_template_part('shortcode', 'login');
        $login_form = ob_get_clean();
        return $login_form;
    }
    /*
     * Check if the user has permission to view the receipt
     *
     * If user is logged in, user ID is compared to user ID of ID stored in payment meta
     *
     * Or if user is logged out and purchase was made as a guest, the purchase session is checked for
     *
     * Or if user is logged in and the user can view sensitive shop data
     *
     */
    if (!apply_filters('give_user_can_view_receipt', $user_can_view, $give_receipt_args)) {
        return '<p class="edd-alert edd-alert-error">' . $give_receipt_args['error'] . '</p>';
    }
    ob_start();
    give_get_template_part('shortcode', 'receipt');
    $display = ob_get_clean();
    return $display;
}
Beispiel #8
0
 public function test_current_page_url()
 {
     $_SERVER['SERVER_PORT'] = 80;
     $_SERVER["SERVER_NAME"] = 'example.org';
     $this->assertEquals('http://example.org/', give_get_current_page_url());
 }
Beispiel #9
0
/**
 * Get Donation Form
 *
 * @since 1.0
 *
 * @param array $args Arguments for display
 *
 * @return string $purchase_form
 */
function give_get_donation_form($args = array())
{
    global $post;
    $form_id = is_object($post) ? $post->ID : 0;
    if (isset($args['id'])) {
        $form_id = $args['id'];
    }
    $defaults = apply_filters('give_form_args_defaults', array('form_id' => $form_id));
    $args = wp_parse_args($args, $defaults);
    $form = new Give_Donate_Form($args['form_id']);
    //bail if no form ID
    if (empty($form->ID)) {
        return false;
    }
    $payment_mode = give_get_chosen_gateway($form->ID);
    $form_action = add_query_arg(apply_filters('give_form_action_args', array('payment-mode' => $payment_mode)), give_get_current_page_url());
    //Sanity Check: Donation form not published or user doesn't have permission to view drafts
    if ('publish' !== $form->post_status && !current_user_can('edit_give_forms', $form->ID)) {
        return false;
    }
    //Get the form wrap CSS classes.
    $form_wrap_classes = $form->get_form_wrap_classes($args);
    //Get the <form> tag wrap CSS classes.
    $form_classes = $form->get_form_classes($args);
    ob_start();
    /**
     * Fires before the post form outputs.
     *
     * @since 1.0
     *
     * @param int $form ->ID The current form ID
     * @param array $args An array of form args
     */
    do_action('give_pre_form_output', $form->ID, $args);
    ?>

	<div id="give-form-<?php 
    echo $form->ID;
    ?>
-wrap" class="<?php 
    echo $form_wrap_classes;
    ?>
">

		<?php 
    if ($form->is_close_donation_form()) {
        //Get Goal thank you message.
        $display_thankyou_message = get_post_meta($form->ID, '_give_form_goal_achieved_message', true);
        $display_thankyou_message = !empty($display_thankyou_message) ? $display_thankyou_message : esc_html__('Thank you to all our donors, we have met our fundraising goal.', 'give');
        //Print thank you message.
        apply_filters('give_goal_closed_output', give_output_error($display_thankyou_message, true, 'success'));
    } else {
        if (isset($args['show_title']) && $args['show_title'] == true) {
            echo apply_filters('give_form_title', '<h2 class="give-form-title">' . get_the_title($form_id) . '</h2>');
        }
        do_action('give_pre_form', $form->ID, $args);
        ?>

			<form id="give-form-<?php 
        echo $form_id;
        ?>
" class="<?php 
        echo $form_classes;
        ?>
" action="<?php 
        echo esc_url_raw($form_action);
        ?>
" method="post">
				<input type="hidden" name="give-form-id" value="<?php 
        echo $form->ID;
        ?>
"/>
				<input type="hidden" name="give-form-title" value="<?php 
        echo htmlentities($form->post_title);
        ?>
"/>
				<input type="hidden" name="give-current-url" value="<?php 
        echo htmlspecialchars(give_get_current_page_url());
        ?>
"/>
				<input type="hidden" name="give-form-url" value="<?php 
        echo htmlspecialchars(give_get_current_page_url());
        ?>
"/>
				<input type="hidden" name="give-form-minimum" value="<?php 
        echo give_format_amount(give_get_form_minimum_price($form->ID));
        ?>
"/>

				<!-- The following field is for robots only, invisible to humans: -->
				<span class="give-hidden" style="display: none !important;">
					<label for="give-form-honeypot-<?php 
        echo $form_id;
        ?>
"></label>
					<input id="give-form-honeypot-<?php 
        echo $form_id;
        ?>
" type="text" name="give-honeypot" class="give-honeypot give-hidden"/>
				</span>

				<?php 
        //Price ID hidden field for variable (mult-level) donation forms
        if (give_has_variable_prices($form_id)) {
            //get default selected price ID
            $prices = apply_filters('give_form_variable_prices', give_get_variable_prices($form_id), $form_id);
            $price_id = 0;
            //loop through prices
            foreach ($prices as $price) {
                if (isset($price['_give_default']) && $price['_give_default'] === 'default') {
                    $price_id = $price['_give_id']['level_id'];
                }
            }
            ?>
					<input type="hidden" name="give-price-id" value="<?php 
            echo $price_id;
            ?>
"/>
				<?php 
        }
        do_action('give_checkout_form_top', $form->ID, $args);
        do_action('give_payment_mode_select', $form->ID, $args);
        do_action('give_checkout_form_bottom', $form->ID, $args);
        ?>
			</form>

			<?php 
        do_action('give_post_form', $form->ID, $args);
        ?>

		<?php 
    }
    ?>

		<!--end #give-form-<?php 
    echo absint($form->ID);
    ?>
--></div>
	<?php 
    /**
     * Fires after the post form outputs.
     *
     * @since 1.0
     *
     * @param int $form ->ID The current form ID
     * @param array $args An array of form args
     */
    do_action('give_post_form_output', $form->ID, $args);
    $final_output = ob_get_clean();
    echo apply_filters('give_donate_form', $final_output, $args);
}
Beispiel #10
0
/**
 * Get Donation Form
 *
 * @since 1.0
 *
 * @param array $args Arguments for display
 *
 * @return string $purchase_form
 */
function give_get_donation_form($args = array())
{
    global $post;
    $post_id = is_object($post) ? $post->ID : 0;
    if (isset($args['id'])) {
        $post_id = $args['id'];
    }
    $defaults = apply_filters('give_form_args_defaults', array('form_id' => $post_id));
    $args = wp_parse_args($args, $defaults);
    $form = new Give_Donate_Form($args['form_id']);
    //bail if no form ID
    if (empty($form->ID)) {
        return false;
    }
    $payment_mode = give_get_chosen_gateway($form->ID);
    $form_action = esc_url(add_query_arg(apply_filters('give_form_action_args', array('payment-mode' => $payment_mode)), give_get_current_page_url()));
    if ('publish' !== $form->post_status && !current_user_can('edit_product', $form->ID)) {
        return false;
        // Product not published or user doesn't have permission to view drafts
    }
    $display_option = isset($args['display_style']) && !empty($args['display_style']) ? $args['display_style'] : get_post_meta($form->ID, '_give_payment_display', true);
    $float_labels_option = give_is_float_labels_enabled($args) ? ' float-labels-enabled' : '';
    $form_classes_array = apply_filters('give_form_classes', array('give-form-wrap', 'give-display-' . $display_option), $form->ID, $args);
    $form_classes = implode(' ', $form_classes_array);
    ob_start();
    /**
     * Fires before the post form outputs.
     *
     * @since 1.0
     *
     * @param int $form ->ID The current form ID
     * @param array $args An array of form args
     */
    do_action('give_pre_form_output', $form->ID, $args);
    ?>

	<div id="give-form-<?php 
    echo $form->ID;
    ?>
-wrap" class="<?php 
    echo $form_classes;
    ?>
">

		<?php 
    if (isset($args['show_title']) && $args['show_title'] == true) {
        echo apply_filters('give_form_title', '<h2  class="give-form-title">' . get_the_title($post_id) . '</h2>');
    }
    ?>

		<?php 
    do_action('give_pre_form', $form->ID, $args);
    ?>

		<form id="give-form-<?php 
    echo $post_id;
    ?>
" class="give-form give-form-<?php 
    echo absint($form->ID);
    echo $float_labels_option;
    ?>
" action="<?php 
    echo $form_action;
    ?>
" method="post">
			<input type="hidden" name="give-form-id" value="<?php 
    echo $form->ID;
    ?>
"/>
			<input type="hidden" name="give-form-title" value="<?php 
    echo htmlentities($form->post_title);
    ?>
"/>
			<input type="hidden" name="give-current-url" value="<?php 
    echo htmlspecialchars(give_get_current_page_url());
    ?>
"/>
			<input type="hidden" name="give-form-url" value="<?php 
    echo htmlspecialchars(give_get_current_page_url());
    ?>
"/>
			<input type="hidden" name="give-form-minimum" value="<?php 
    echo give_get_form_minimum_price($form->ID);
    ?>
"/>
			<?php 
    //Price ID hidden field for variable (mult-level) donation forms
    if (give_has_variable_prices($post_id)) {
        //get default selected price ID
        $prices = apply_filters('give_form_variable_prices', give_get_variable_prices($post_id), $post_id);
        $price_id = 0;
        //loop through prices
        foreach ($prices as $price) {
            if (isset($price['_give_default']) && $price['_give_default'] === 'default') {
                $price_id = $price['_give_id']['level_id'];
            }
        }
        ?>
				<input type="hidden" name="give-price-id" value="<?php 
        echo $price_id;
        ?>
"/>
			<?php 
    }
    do_action('give_checkout_form_top', $form->ID, $args);
    do_action('give_payment_mode_select', $form->ID, $args);
    do_action('give_checkout_form_bottom', $form->ID, $args);
    ?>

		</form>

		<?php 
    do_action('give_post_form', $form->ID, $args);
    ?>

		<!--end #give-form-<?php 
    echo absint($form->ID);
    ?>
--></div>
	<?php 
    /**
     * Fires after the post form outputs.
     *
     * @since 1.0
     *
     * @param int $form ->ID The current form ID
     * @param array $args An array of form args
     */
    do_action('give_post_form_output', $form->ID, $args);
    $final_output = ob_get_clean();
    echo apply_filters('give_donate_form', $final_output, $args);
}