Exemple #1
0
/**
 * Define the metabox and field configurations.
 *
 * @param  array $meta_boxes
 *
 * @return array
 */
function give_single_forms_cmb2_metaboxes(array $meta_boxes)
{
    $post_id = give_get_admin_post_id();
    $price = give_get_form_price($post_id);
    $goal = give_get_form_goal($post_id);
    $variable_pricing = give_has_variable_prices($post_id);
    $prices = give_get_variable_prices($post_id);
    //No empty prices - min. 1.00 for new forms
    if (empty($price)) {
        $price = esc_attr(give_format_amount('1.00'));
    }
    // Start with an underscore to hide fields from custom fields list
    $prefix = '_give_';
    /**
     * Repeatable Field Groups
     */
    $meta_boxes['form_field_options'] = apply_filters('give_forms_field_options', array('id' => 'form_field_options', 'title' => __('Donation Options', 'give'), 'object_types' => array('give_forms'), 'context' => 'normal', 'priority' => 'high', 'fields' => apply_filters('give_forms_donation_form_metabox_fields', array(array('name' => __('Donation Option', 'give'), 'description' => __('Would you like this form to have one set donation price or multiple levels (for example, $10 silver, $20 gold, $50 platinum)?', 'give'), 'id' => $prefix . 'price_option', 'type' => 'radio_inline', 'default' => 'set', 'options' => apply_filters('give_forms_price_options', array('set' => __('Set Donation', 'give'), 'multi' => __('Multi-level Donation', 'give')))), array('name' => __('Set Donation', 'give'), 'description' => __('This is the set donation amount for this form.', 'give'), 'id' => $prefix . 'set_price', 'type' => 'text_small', 'row_classes' => 'give-subfield', 'before_field' => give_get_option('currency_position') == 'before' ? '<span class="give-money-symbol give-money-symbol-before">' . give_currency_symbol() . '</span>' : '', 'after_field' => give_get_option('currency_position') == 'after' ? '<span class="give-money-symbol give-money-symbol-after">' . give_currency_symbol() . '</span>' : '', 'attributes' => array('placeholder' => give_format_amount('1.00'), 'value' => $price, 'class' => 'cmb-type-text-small give-money-field')), array('id' => $prefix . 'levels_header', 'type' => 'levels_repeater_header'), array('id' => $prefix . 'donation_levels', 'type' => 'group', 'row_classes' => 'give-subfield', 'options' => array('add_button' => __('Add Level', 'give'), 'remove_button' => __('<span class="dashicons dashicons-no"></span>', 'give'), 'sortable' => true), 'fields' => apply_filters('give_donation_levels_table_row', array(array('name' => __('ID', 'give'), 'id' => $prefix . 'id', 'type' => 'levels_id'), array('name' => __('Amount', 'give'), 'id' => $prefix . 'amount', 'type' => 'text_small', 'before_field' => give_get_option('currency_position') == 'before' ? '<span class="give-money-symbol  give-money-symbol-before">' . give_currency_symbol() . '</span>' : '', 'after_field' => give_get_option('currency_position') == 'after' ? '<span class="give-money-symbol  give-money-symbol-after">' . give_currency_symbol() . '</span>' : '', 'attributes' => array('placeholder' => give_format_amount('1.00'), 'class' => 'cmb-type-text-small give-money-field'), 'before' => 'give_format_admin_multilevel_amount'), array('name' => __('Text', 'give'), 'id' => $prefix . 'text', 'type' => 'text', 'attributes' => array('placeholder' => __('Donation Level', 'give'), 'rows' => 3)), array('name' => __('Default', 'give'), 'id' => $prefix . 'default', 'type' => 'give_default_radio_inline')))), array('name' => __('Display Style', 'give'), 'description' => __('Set how the donations levels will display on the form.', 'give'), 'id' => $prefix . 'display_style', 'type' => 'radio_inline', 'default' => 'buttons', 'options' => array('buttons' => __('Buttons', 'give'), 'radios' => __('Radios', 'give'), 'dropdown' => __('Dropdown', 'give'))), array('name' => __('Custom Amount', 'give'), 'description' => __('Do you want the user to be able to input their own donation amount?', 'give'), 'id' => $prefix . 'custom_amount', 'type' => 'radio_inline', 'default' => 'no', 'options' => array('yes' => __('Yes', 'give'), 'no' => __('No', 'give'))), array('name' => __('Custom Amount Text', 'give'), 'description' => __('This text appears as a label next to the custom amount field for single level forms. For multi-level forms the text will appear as it\'s own level (ie button, radio, or select option). Add your own message or leave this field blank to prevent it from displaying within your form.', 'give'), 'id' => $prefix . 'custom_amount_text', 'type' => 'text', 'row_classes' => 'give-subfield', 'attributes' => array('rows' => 3, 'placeholder' => __('Give a Custom Amount', 'give'))), array('name' => __('Set Goal?', 'give'), 'description' => __('Do you want to set a donation goal for this form?', 'give'), 'id' => $prefix . 'goal_option', 'type' => 'radio_inline', 'default' => 'no', 'options' => array('yes' => __('Yes', 'give'), 'no' => __('No', 'give'))), array('name' => __('Set Goal', 'give'), 'description' => __('This is the goal you want to achieve for this form.', 'give'), 'id' => $prefix . 'set_goal', 'type' => 'text_small', 'row_classes' => 'give-subfield', 'before_field' => give_get_option('currency_position') == 'before' ? '<span class="give-money-symbol give-money-symbol-before">' . give_currency_symbol() . '</span>' : '', 'after_field' => give_get_option('currency_position') == 'after' ? '<span class="give-money-symbol give-money-symbol-after">' . give_currency_symbol() . '</span>' : '', 'attributes' => array('placeholder' => give_format_amount('0.00'), 'value' => isset($goal) ? esc_attr(give_format_amount($goal)) : '', 'class' => 'cmb-type-text-small give-money-field')), array('name' => __('Goal Progress Bar Color', 'give'), 'id' => $prefix . 'goal_color', 'type' => 'colorpicker', 'row_classes' => 'give-subfield', 'default' => '#2bc253')))));
    /**
     * Content Field
     */
    $meta_boxes['form_content_options'] = apply_filters('give_forms_content_options', array('id' => 'form_content_options', 'title' => __('Form Content', 'give'), 'object_types' => array('give_forms'), 'context' => 'normal', 'priority' => 'high', 'fields' => apply_filters('give_forms_content_options_metabox_fields', array(array('name' => __('Display Content', 'give'), 'description' => __('Do you want to display content? If you select "Yes" a WYSIWYG editor will appear which you will be able to enter content to display above or below the form.', 'give'), 'id' => $prefix . 'content_option', 'type' => 'select', 'options' => apply_filters('give_forms_content_options_select', array('none' => __('No content', 'give'), 'give_pre_form' => __('Yes, display content ABOVE the form fields', 'give'), 'give_post_form' => __('Yes, display content BELOW the form fields', 'give'))), 'default' => 'none'), array('name' => __('Content', 'give'), 'description' => __('This content will display on the single give form page.', 'give'), 'id' => $prefix . 'form_content', 'row_classes' => 'give-subfield', 'type' => 'wysiwyg')))));
    /**
     * Display Options
     */
    $meta_boxes['form_display_options'] = apply_filters('give_form_display_options', array('id' => 'form_display_options', 'title' => __('Form Display Options', 'give'), 'object_types' => array('give_forms'), 'context' => 'normal', 'priority' => 'high', 'show_names' => true, 'fields' => apply_filters('give_forms_display_options_metabox_fields', array(array('name' => __('Payment Fields', 'give'), 'desc' => __('How would you like to display payment information for this form? The "Show on Page" option will display the entire form when the page loads. "Reveal Upon Click" places a button below the donation fields and upon clicks slides into view the rest of the fields. "Modal Window Upon Click" is a similar option, rather than sliding into view the fields they will open in a shadow box or "modal" window.', 'give'), 'id' => $prefix . 'payment_display', 'type' => 'select', 'options' => array('onpage' => __('Show on Page', 'give'), 'reveal' => __('Reveal Upon Click', 'give'), 'modal' => __('Modal Window Upon Click', 'give')), 'default' => 'onpage'), array('id' => $prefix . 'reveal_label', 'name' => __('Reveal / Modal Open Text', 'give'), 'desc' => __('The button label for completing the donation.', 'give'), 'type' => 'text_small', 'row_classes' => 'give-subfield', 'attributes' => array('placeholder' => __('Donate Now', 'give'))), array('id' => $prefix . 'checkout_label', 'name' => __('Complete Donation Text', 'give'), 'desc' => __('The button label for completing a donation.', 'give'), 'type' => 'text_small', 'attributes' => array('placeholder' => __('Donate Now', 'give'))), array('name' => __('Default Gateway', 'give'), 'desc' => __('By default, the gateway for this form will inherit the global default gateway (set under Give > Settings > Payment Gateways). This option allows you to customize the default gateway for this form only.', 'give'), 'id' => $prefix . 'default_gateway', 'type' => 'default_gateway'), array('name' => __('Disable Guest Donations', 'give'), 'desc' => __('Do you want to require users be logged-in to make donations?', 'give'), 'id' => $prefix . 'logged_in_only', 'type' => 'checkbox'), array('name' => __('Register / Login Form', 'give'), 'desc' => __('Display the registration and login forms in the checkout section for non-logged-in users. Note: this option will not require users to register or log in prior to completing a donation. It simply determines whether the login and/or registration form are displayed on the checkout page.', 'give'), 'id' => $prefix . 'show_register_form', 'type' => 'select', 'options' => array('both' => __('Registration and Login Forms', 'give'), 'registration' => __('Registration Form Only', 'give'), 'login' => __('Login Form Only', 'give'), 'none' => __('None', 'give')), 'default' => 'none'), array('name' => __('Floating Labels', 'give'), 'desc' => sprintf(__('Select the <a href="%s" target="_blank">floating labels</a> setting for this Give form.<br>Be aware that if you have the "Disable CSS" option enabled, you will need to style the floating labels yourself.', 'give'), esc_url("http://bradfrost.com/blog/post/float-label-pattern/")), 'id' => $prefix . 'form_floating_labels', 'type' => 'select', 'options' => array('' => __('Use the global setting', 'give'), 'enabled' => __('Enabled', 'give'), 'disabled' => __('Disabled', 'give')), 'default' => 'none')))));
    /**
     * Terms & Conditions
     */
    $meta_boxes['form_terms_options'] = apply_filters('give_forms_terms_options', array('id' => 'form_terms_options', 'title' => __('Terms and Conditions', 'give'), 'object_types' => array('give_forms'), 'context' => 'normal', 'priority' => 'high', 'fields' => apply_filters('give_forms_terms_options_metabox_fields', array(array('name' => __('Terms and Conditions', 'give'), 'description' => __('Do you want to require the user to agree to terms and conditions prior to being able to complete their donation?', 'give'), 'id' => $prefix . 'terms_option', 'type' => 'select', 'options' => apply_filters('give_forms_content_options_select', array('none' => __('No', 'give'), 'yes' => __('Yes', 'give'))), 'default' => 'none'), array('id' => $prefix . 'agree_label', 'name' => __('Agree to Terms Label', 'give'), 'desc' => __('The label shown next to the agree to terms check box. Add your own to customize or leave blank to use the default text placeholder.', 'give'), 'type' => 'text', 'row_classes' => 'give-subfield', 'size' => 'regular', 'attributes' => array('placeholder' => __('Agree to Terms?', 'give'))), array('id' => $prefix . 'agree_text', 'row_classes' => 'give-subfield', 'name' => __('Agreement Text', 'give'), 'desc' => __('This is the actual text which the user will have to agree to in order to make a donation.', 'give'), 'type' => 'wysiwyg')))));
    return $meta_boxes;
}
/**
 * Get Default Form Amount
 *
 * @description: Grabs the default amount for set and level forms
 *
 * @param int $form_id
 *
 * @return string $default_price
 * @since      1.0
 */
function give_get_default_form_amount($form_id)
{
    if (give_has_variable_prices($form_id)) {
        $default_amount = give_get_default_multilevel_amount($form_id);
    } else {
        $default_amount = get_post_meta($form_id, '_give_set_price', true);
    }
    return $default_amount;
}
Exemple #3
0
/**
 * Render Give Form Columns
 *
 * @since 1.0
 *
 * @param string $column_name Column name
 * @param int    $post_id     Give Form (Post) ID
 *
 * @return void
 */
function give_render_form_columns($column_name, $post_id)
{
    if (get_post_type($post_id) == 'give_forms') {
        global $give_options;
        $style = isset($give_options['button_style']) ? $give_options['button_style'] : 'button';
        $color = isset($give_options['checkout_color']) ? $give_options['checkout_color'] : 'blue';
        $color = $color == 'inherit' ? '' : $color;
        $purchase_text = !empty($give_options['add_to_cart_text']) ? $give_options['add_to_cart_text'] : __('Purchase', 'give');
        switch ($column_name) {
            case 'form_category':
                echo get_the_term_list($post_id, 'give_forms_category', '', ', ', '');
                break;
            case 'form_tag':
                echo get_the_term_list($post_id, 'give_forms_tag', '', ', ', '');
                break;
            case 'price':
                if (give_has_variable_prices($post_id)) {
                    echo give_price_range($post_id);
                } else {
                    echo give_price($post_id, false);
                    echo '<input type="hidden" class="formprice-' . $post_id . '" value="' . give_get_form_price($post_id) . '" />';
                }
                break;
            case 'goal':
                $goal_option = get_post_meta($post_id, '_give_goal_option', true);
                if (!empty($goal_option) && $goal_option === 'yes') {
                    echo give_goal($post_id, false);
                } else {
                    echo __('No Goal Set', 'give');
                }
                echo '<input type="hidden" class="formgoal-' . $post_id . '" value="' . give_get_form_goal($post_id) . '" />';
                break;
            case 'donations':
                if (current_user_can('view_give_forms_stats', $post_id)) {
                    echo '<a href="' . esc_url(admin_url('edit.php?post_type=give_forms&page=give-reports&tab=logs&view=sales&form=' . $post_id)) . '">';
                    echo give_get_form_sales_stats($post_id);
                    echo '</a>';
                } else {
                    echo '-';
                }
                break;
            case 'earnings':
                if (current_user_can('view_give_forms_stats', $post_id)) {
                    echo '<a href="' . esc_url(admin_url('edit.php?post_type=give_forms&page=give-reports&view=forms&form-id=' . $post_id)) . '">';
                    echo give_currency_filter(give_format_amount(give_get_form_earnings_stats($post_id)));
                    echo '</a>';
                } else {
                    echo '-';
                }
                break;
            case 'shortcode':
                echo '<input onclick="this.setSelectionRange(0, this.value.length)" type="text" class="shortcode-input" readonly="" value="[give_form id=&#34;' . absint($post_id) . '&#34;]">';
                break;
        }
    }
}
/**
 * Process PayPal Purchase
 *
 * @since 1.0
 *
 * @param array $purchase_data Purchase Data
 *
 * @return void
 */
function give_process_paypal_purchase($purchase_data)
{
    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'give-gateway')) {
        wp_die(__('Nonce verification has failed', 'give'), __('Error', 'give'), array('response' => 403));
    }
    // Collect payment data
    $payment_data = array('price' => $purchase_data['price'], 'give_form_title' => $purchase_data['post_data']['give-form-title'], 'give_form_id' => intval($purchase_data['post_data']['give-form-id']), 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => give_get_currency(), 'user_info' => $purchase_data['user_info'], 'status' => 'pending', 'gateway' => 'paypal');
    // Record the pending payment
    $payment = give_insert_payment($payment_data);
    // Check payment
    if (!$payment) {
        // Record the error
        give_record_gateway_error(__('Payment Error', 'give'), sprintf(__('Payment creation failed before sending buyer to PayPal. Payment data: %s', 'give'), json_encode($payment_data)), $payment);
        // Problems? send back
        give_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['give-gateway']);
    } else {
        // Only send to PayPal if the pending payment is created successfully
        $listener_url = add_query_arg('give-listener', 'IPN', home_url('index.php'));
        // Get the success url
        $return_url = add_query_arg(array('payment-confirmation' => 'paypal', 'payment-id' => $payment), get_permalink(give_get_option('success_page')));
        // Get the PayPal redirect uri
        $paypal_redirect = trailingslashit(give_get_paypal_redirect()) . '?';
        //Item name - pass level name if variable priced
        $item_name = $purchase_data['post_data']['give-form-title'];
        if (give_has_variable_prices($purchase_data['post_data']['give-form-id']) && isset($purchase_data['post_data']['give-price-id'])) {
            $item_price_level_text = give_get_price_option_name($purchase_data['post_data']['give-form-id'], $purchase_data['post_data']['give-price-id']);
            //Is there any donation level text?
            if (!empty($item_price_level_text)) {
                $item_name .= ' - ' . $item_price_level_text;
            }
        }
        // Setup PayPal arguments
        $paypal_args = array('business' => give_get_option('paypal_email', false), 'email' => $purchase_data['user_email'], 'invoice' => $purchase_data['purchase_key'], 'amount' => $purchase_data['price'], 'item_name' => $item_name, 'no_shipping' => '1', 'shipping' => '0', 'no_note' => '1', 'currency_code' => give_get_currency(), 'charset' => get_bloginfo('charset'), 'custom' => $payment, 'rm' => '2', 'return' => $return_url, 'cancel_return' => give_get_failed_transaction_uri('?payment-id=' . $payment), 'notify_url' => $listener_url, 'page_style' => give_get_paypal_page_style(), 'cbt' => get_bloginfo('name'), 'bn' => 'WordImpress_Donate_Give_US');
        if (!empty($purchase_data['user_info']['address'])) {
            $paypal_args['address1'] = $purchase_data['user_info']['address']['line1'];
            $paypal_args['address2'] = $purchase_data['user_info']['address']['line2'];
            $paypal_args['city'] = $purchase_data['user_info']['address']['city'];
            $paypal_args['country'] = $purchase_data['user_info']['address']['country'];
        }
        if (give_get_option('paypal_button_type') === 'standard') {
            $paypal_extra_args = array('cmd' => '_xclick');
        } else {
            $paypal_extra_args = array('cmd' => '_donations');
        }
        $paypal_args = array_merge($paypal_extra_args, $paypal_args);
        $paypal_args = apply_filters('give_paypal_redirect_args', $paypal_args, $purchase_data);
        // Build query
        $paypal_redirect .= http_build_query($paypal_args);
        // Fix for some sites that encode the entities
        $paypal_redirect = str_replace('&amp;', '&', $paypal_redirect);
        // Redirect to PayPal
        wp_redirect($paypal_redirect);
        exit;
    }
}
/**
 * Donation Form Validate Minimum Donation Amount
 *
 * @access      private
 * @since       1.3.6
 * @return      bool
 */
function give_verify_minimum_price()
{
    $amount = give_sanitize_amount($_REQUEST['give-amount']);
    $form_id = isset($_REQUEST['give-form-id']) ? $_REQUEST['give-form-id'] : 0;
    $price_id = isset($_REQUEST['give-price-id']) ? $_REQUEST['give-price-id'] : 0;
    $variable_prices = give_has_variable_prices($form_id);
    if ($variable_prices && !empty($price_id)) {
        $price_level_amount = give_get_price_option_amount($form_id, $price_id);
        if ($price_level_amount == $amount) {
            return true;
        }
    }
    $minimum = give_get_form_minimum_price($form_id);
    if ($minimum > $amount) {
        return false;
    }
    return true;
}
Exemple #6
0
/**
 * Check for Variation Prices HTML  (Multi-level donation forms)
 *
 * @since  1.6
 *
 * @return void
 */
function give_check_for_form_price_variations_html()
{
    if (!current_user_can('edit_give_payments', get_current_user_id())) {
        wp_die();
    }
    $form_id = intval($_POST['form_id']);
    $payment_id = intval($_POST['payment_id']);
    $form = get_post($form_id);
    if ('give_forms' != $form->post_type) {
        wp_die();
    }
    if (!give_has_variable_prices($form_id)) {
        esc_html_e('n/a', 'give');
    } else {
        // Payment object.
        $payment = new Give_Payment($payment_id);
        // Payment meta.
        $payment_meta = $payment->get_meta();
        // Variable price dropdown options.
        $variable_price_dropdown_option = array('id' => $form_id, 'name' => 'give-variable-price', 'chosen' => true, 'show_option_all' => '', 'selected' => $payment_meta['price_id']);
        // Render variable prices select tag html.
        give_get_form_variable_price_dropdown($variable_price_dropdown_option, true);
    }
    give_die();
}
Exemple #7
0
/**
 * Get/Print give form variable price dropdown html
 *
 * @since 1.6
 *
 * @param array $args Arguments for form dropdown
 * @param bool  $echo This parameter decide if print form dropdown html output or not
 *
 * @return string/void
 */
function give_get_form_variable_price_dropdown($args = array(), $echo = false)
{
    // Check for give form id.
    if (empty($args['id'])) {
        return false;
    }
    // Check if form has variable prices or not.
    if (!($variable_prices = give_has_variable_prices($args['id']))) {
        return false;
    }
    $variable_prices = give_get_variable_prices(absint($args['id']));
    $variable_price_options = array();
    // Check if multi donation form support custom donation or not.
    if (give_is_custom_price_mode(absint($args['id']))) {
        $variable_price_options['custom'] = _x('Custom', 'custom donation dropdown item', 'give');
    }
    // Get variable price and ID from variable price array.
    foreach ($variable_prices as $variable_price) {
        $variable_price_options[$variable_price['_give_id']['level_id']] = $variable_price['_give_text'];
    }
    // Update options.
    $args = array_merge($args, array('options' => $variable_price_options));
    // Generate select html.
    $form_dropdown_html = Give()->html->select($args);
    if (!$echo) {
        return $form_dropdown_html;
    }
    echo $form_dropdown_html;
}
Exemple #8
0
/**
 *
 * Process the payment details edit
 *
 * @access      private
 *
 * @param array $data
 *
 * @since       1.0
 * @return      void
 *
 */
function give_update_payment_details($data)
{
    if (!current_user_can('edit_give_payments', $data['give_payment_id'])) {
        wp_die(esc_html__('You do not have permission to edit payment records.', 'give'), esc_html__('Error', 'give'), array('response' => 403));
    }
    check_admin_referer('give_update_payment_details_nonce');
    // Retrieve the payment ID
    $payment_id = absint($data['give_payment_id']);
    /* @var Give_Payment $payment */
    $payment = new Give_Payment($payment_id);
    // Retrieve existing payment meta
    $meta = $payment->get_meta();
    $user_info = $payment->user_info;
    $status = $data['give-payment-status'];
    $date = sanitize_text_field($data['give-payment-date']);
    $hour = sanitize_text_field($data['give-payment-time-hour']);
    // Restrict to our high and low
    if ($hour > 23) {
        $hour = 23;
    } elseif ($hour < 0) {
        $hour = 00;
    }
    $minute = sanitize_text_field($data['give-payment-time-min']);
    // Restrict to our high and low
    if ($minute > 59) {
        $minute = 59;
    } elseif ($minute < 0) {
        $minute = 00;
    }
    $address = array_map('trim', $data['give-payment-address'][0]);
    $curr_total = give_sanitize_amount($payment->total);
    $new_total = give_sanitize_amount($data['give-payment-total']);
    $date = date('Y-m-d', strtotime($date)) . ' ' . $hour . ':' . $minute . ':00';
    $curr_customer_id = sanitize_text_field($data['give-current-customer']);
    $new_customer_id = sanitize_text_field($data['customer-id']);
    /**
     * Fires before updating edited purchase.
     *
     * @since 1.0
     *
     * @param int $payment_id The ID of the payment.
     */
    do_action('give_update_edited_purchase', $payment_id);
    $payment->date = $date;
    $updated = $payment->save();
    if (0 === $updated) {
        wp_die(esc_html__('Error Updating Payment.', 'give'), esc_html__('Error', 'give'), array('response' => 400));
    }
    $customer_changed = false;
    if (isset($data['give-new-customer']) && $data['give-new-customer'] == '1') {
        $email = isset($data['give-new-customer-email']) ? sanitize_text_field($data['give-new-customer-email']) : '';
        $names = isset($data['give-new-customer-name']) ? sanitize_text_field($data['give-new-customer-name']) : '';
        if (empty($email) || empty($names)) {
            wp_die(esc_html__('New Customers require a name and email address.', 'give'), esc_html__('Error', 'give'), array('response' => 400));
        }
        $customer = new Give_Customer($email);
        if (empty($customer->id)) {
            $customer_data = array('name' => $names, 'email' => $email);
            $user_id = email_exists($email);
            if (false !== $user_id) {
                $customer_data['user_id'] = $user_id;
            }
            if (!$customer->create($customer_data)) {
                // Failed to crete the new donor, assume the previous donor
                $customer_changed = false;
                $customer = new Give_Customer($curr_customer_id);
                give_set_error('give-payment-new-customer-fail', esc_html__('Error creating new donor.', 'give'));
            }
        }
        $new_customer_id = $customer->id;
        $previous_customer = new Give_Customer($curr_customer_id);
        $customer_changed = true;
    } elseif ($curr_customer_id !== $new_customer_id) {
        $customer = new Give_Customer($new_customer_id);
        $email = $customer->email;
        $names = $customer->name;
        $previous_customer = new Give_Customer($curr_customer_id);
        $customer_changed = true;
    } else {
        $customer = new Give_Customer($curr_customer_id);
        $email = $customer->email;
        $names = $customer->name;
    }
    // Setup first and last name from input values
    $names = explode(' ', $names);
    $first_name = !empty($names[0]) ? $names[0] : '';
    $last_name = '';
    if (!empty($names[1])) {
        unset($names[0]);
        $last_name = implode(' ', $names);
    }
    if ($customer_changed) {
        // Remove the stats and payment from the previous customer and attach it to the new customer
        $previous_customer->remove_payment($payment_id, false);
        $customer->attach_payment($payment_id, false);
        if ('publish' == $status) {
            // Reduce previous user donation count and amount.
            $previous_customer->decrease_purchase_count();
            $previous_customer->decrease_value($curr_total);
            // If purchase was completed adjust stats of new customers.
            $customer->increase_purchase_count();
            $customer->increase_value($new_total);
        }
        $payment->customer_id = $customer->id;
    } else {
        if ('publish' === $status) {
            // Update user donation stat.
            $customer->update_donation_value($curr_total, $new_total);
        }
    }
    // Set new meta values
    $payment->user_id = $customer->user_id;
    $payment->email = $customer->email;
    $payment->first_name = $first_name;
    $payment->last_name = $last_name;
    $payment->address = $address;
    $payment->total = $new_total;
    // Check for payment notes
    if (!empty($data['give-payment-note'])) {
        $note = wp_kses($data['give-payment-note'], array());
        give_insert_payment_note($payment_id, $note);
    }
    // Set new status
    $payment->status = $status;
    // Adjust total store earnings if the payment total has been changed
    if ($new_total !== $curr_total && 'publish' == $status) {
        if ($new_total > $curr_total) {
            // Increase if our new total is higher
            $difference = $new_total - $curr_total;
            give_increase_total_earnings($difference);
        } elseif ($curr_total > $new_total) {
            // Decrease if our new total is lower
            $difference = $curr_total - $new_total;
            give_decrease_total_earnings($difference);
        }
    }
    $payment->save();
    // Get new give form ID.
    $new_form_id = absint($data['forms']);
    $current_form_id = absint($payment->get_meta('_give_payment_form_id'));
    // We are adding payment transfer code in last to remove any conflict with above functionality.
    // For example: above code will automatically handle form stat (increase/decrease) when payment status changes.
    /* Check if user want to transfer current payment to new give form id. */
    if ($new_form_id != $current_form_id) {
        // Get new give form title.
        $new_form_title = get_the_title($new_form_id);
        // Update new give form data in payment data.
        $payment_meta = $payment->get_meta();
        $payment_meta['form_title'] = $new_form_title;
        $payment_meta['form_id'] = $new_form_id;
        // Update price id post meta data for set donation form.
        if (!give_has_variable_prices($new_form_id)) {
            $payment_meta['price_id'] = '';
        }
        // Update payment give form meta data.
        $payment->update_meta('_give_payment_form_id', $new_form_id);
        $payment->update_meta('_give_payment_form_title', $new_form_title);
        $payment->update_meta('_give_payment_meta', $payment_meta);
        // Update price id payment metadata.
        if (!give_has_variable_prices($new_form_id)) {
            $payment->update_meta('_give_payment_price_id', '');
        }
        // If purchase was completed, adjust stats of forms
        if ('publish' == $status) {
            // Decrease sale of old give form. For other payment status
            $current_form = new Give_Donate_Form($current_form_id);
            $current_form->decrease_sales();
            $current_form->decrease_earnings($curr_total);
            // Increase sale of new give form.
            $new_form = new Give_Donate_Form($new_form_id);
            $new_form->increase_sales();
            $new_form->increase_earnings($new_total);
        }
        // Re setup payment to update new meta value in object.
        $payment->update_payment_setup($payment->ID);
    }
    // Update price id if current form is variable form.
    if (!empty($data['give-variable-price']) && give_has_variable_prices($payment->form_id)) {
        // Get payment meta data.
        $payment_meta = $payment->get_meta();
        // Set payment id to empty string if variable price id is negative ( i.e. custom amount feature enabled ).
        $data['give-variable-price'] = 'custom' === $data['give-variable-price'] ? 'custom' : 0 < $data['give-variable-price'] ? $data['give-variable-price'] : '';
        // Update payment meta data.
        $payment_meta['price_id'] = $data['give-variable-price'];
        // Update payment give form meta data.
        $payment->update_meta('_give_payment_price_id', $data['give-variable-price']);
        $payment->update_meta('_give_payment_meta', $payment_meta);
        // Re setup payment to update new meta value in object.
        $payment->update_payment_setup($payment->ID);
    }
    /**
     * Fires after updating edited purchase.
     *
     * @since 1.0
     *
     * @param int $payment_id The ID of the payment.
     */
    do_action('give_updated_edited_purchase', $payment_id);
    wp_safe_redirect(admin_url('edit.php?post_type=give_forms&page=give-payment-history&view=view-order-details&give-message=payment-updated&id=' . $payment_id));
    exit;
}
 /**
  * Retrieves Recent Sales
  *
  * @access public
  * @since  1.1
  * @return array
  */
 public function get_recent_donations()
 {
     global $wp_query;
     $sales = array();
     if (!user_can($this->user_id, 'view_give_reports') && !$this->override) {
         return $sales;
     }
     if (isset($wp_query->query_vars['id'])) {
         $query = array();
         $query[] = give_get_payment_by('id', $wp_query->query_vars['id']);
     } elseif (isset($wp_query->query_vars['purchasekey'])) {
         $query = array();
         $query[] = give_get_payment_by('key', $wp_query->query_vars['purchasekey']);
     } elseif (isset($wp_query->query_vars['email'])) {
         $query = give_get_payments(array('meta_key' => '_give_payment_user_email', 'meta_value' => $wp_query->query_vars['email'], 'number' => $this->per_page(), 'page' => $this->get_paged(), 'status' => 'publish'));
     } else {
         $query = give_get_payments(array('number' => $this->per_page(), 'page' => $this->get_paged(), 'status' => 'publish'));
     }
     if ($query) {
         $i = 0;
         foreach ($query as $payment) {
             $payment_meta = give_get_payment_meta($payment->ID);
             $user_info = give_get_payment_meta_user_info($payment->ID);
             $first_name = isset($user_info['first_name']) ? $user_info['first_name'] : '';
             $last_name = isset($user_info['last_name']) ? $user_info['last_name'] : '';
             $sales['donations'][$i]['ID'] = give_get_payment_number($payment->ID);
             $sales['donations'][$i]['transaction_id'] = give_get_payment_transaction_id($payment->ID);
             $sales['donations'][$i]['key'] = give_get_payment_key($payment->ID);
             $sales['donations'][$i]['total'] = give_get_payment_amount($payment->ID);
             $sales['donations'][$i]['gateway'] = give_get_payment_gateway($payment->ID);
             $sales['donations'][$i]['name'] = $first_name . ' ' . $last_name;
             $sales['donations'][$i]['fname'] = $first_name;
             $sales['donations'][$i]['lname'] = $last_name;
             $sales['donations'][$i]['email'] = give_get_payment_user_email($payment->ID);
             $sales['donations'][$i]['date'] = $payment->post_date;
             $form_id = isset($payment_meta['form_id']) ? $payment_meta['form_id'] : $payment_meta;
             $price = isset($payment_meta['form_id']) ? give_get_form_price($payment_meta['form_id']) : false;
             $price_id = isset($payment_meta['price_id']) ? $payment_meta['price_id'] : null;
             $sales['donations'][$i]['form']['id'] = $form_id;
             $sales['donations'][$i]['form']['name'] = get_the_title($payment_meta['form_id']);
             $sales['donations'][$i]['form']['price'] = $price;
             if (give_has_variable_prices($form_id)) {
                 if (isset($payment_meta['price_id'])) {
                     $price_name = give_get_price_option_name($form_id, $payment_meta['price_id'], $payment->ID);
                     $sales['donations'][$i]['form']['price_name'] = $price_name;
                     $sales['donations'][$i]['form']['price_id'] = $price_id;
                     $sales['donations'][$i]['form']['price'] = give_get_price_option_amount($form_id, $price_id);
                 }
             }
             //Add custom meta to API
             foreach ($payment_meta as $meta_key => $meta_value) {
                 $exceptions = array('form_title', 'form_id', 'price_id', 'user_info', 'key', 'email', 'date');
                 //Don't clutter up results with dupes
                 if (in_array($meta_key, $exceptions)) {
                     continue;
                 }
                 $sales['donations'][$i]['payment_meta'][$meta_key] = $meta_value;
             }
             $i++;
         }
     }
     return apply_filters('give_api_donations_endpoint', $sales);
 }
Exemple #10
0
/**
 * Displays a formatted price for a donation form
 *
 * @since 1.0
 *
 * @param int  $form_id  ID of the form price to show
 * @param bool $echo     Whether to echo or return the results
 * @param int  $price_id Optional price id for variable pricing
 *
 * @return void
 */
function give_price($form_id = 0, $echo = true, $price_id = false)
{
    if (empty($form_id)) {
        $form_id = get_the_ID();
    }
    if (give_has_variable_prices($form_id)) {
        $prices = give_get_variable_prices($form_id);
        if (false !== $price_id) {
            //loop through multi-prices to see which is default
            foreach ($prices as $price) {
                //this is the default price
                if (isset($price['_give_default']) && $price['_give_default'] === 'default') {
                    $price = (double) $price['_give_amount'];
                }
            }
        } else {
            $price = give_get_lowest_price_option($form_id);
        }
        $price = give_sanitize_amount($price);
    } else {
        $price = give_get_form_price($form_id);
    }
    $price = apply_filters('give_form_price', give_sanitize_amount($price), $form_id);
    $formatted_price = '<span class="give_price" id="give_price_' . $form_id . '">' . $price . '</span>';
    $formatted_price = apply_filters('give_form_price_after_html', $formatted_price, $form_id, $price);
    if ($echo) {
        echo $formatted_price;
    } else {
        return $formatted_price;
    }
}
 /**
  * Get the Export Data
  *
  * @access public
  * @since 1.5
  * @return array $data The data for the CSV file
  */
 public function get_data()
 {
     $data = array();
     $meta = array('give_price', '_thumbnail_id', 'give_sku', 'give_product_notes', '_give_form_sales', '_give_download_earnings');
     $args = array('post_type' => 'download', 'posts_per_page' => 30, 'paged' => $this->step);
     $downloads = new WP_Query($args);
     if ($downloads->posts) {
         foreach ($downloads->posts as $download) {
             $row = array();
             foreach ($this->csv_cols() as $key => $value) {
                 // Setup default value
                 $row[$key] = '';
                 if (in_array($key, $meta)) {
                     switch ($key) {
                         case '_thumbnail_id':
                             $image_id = get_post_thumbnail_id($download->ID);
                             $row[$key] = wp_get_attachment_url($image_id);
                             break;
                         case 'give_price':
                             if (give_has_variable_prices($download->ID)) {
                                 $prices = array();
                                 foreach (give_get_variable_prices($download->ID) as $price) {
                                     $prices[] = $price['name'] . ': ' . $price['amount'];
                                 }
                                 $row[$key] = implode(' | ', $prices);
                             } else {
                                 $row[$key] = give_get_download_price($download->ID);
                             }
                             break;
                         case '_give_files':
                             $files = array();
                             foreach (give_get_download_files($download->ID) as $file) {
                                 $files[] = $file['file'];
                             }
                             $row[$key] = implode(' | ', $files);
                             break;
                         default:
                             $row[$key] = get_post_meta($download->ID, $key, true);
                             break;
                     }
                 } elseif (isset($download->{$key})) {
                     switch ($key) {
                         case 'post_author':
                             $row[$key] = get_the_author_meta('user_login', $download->post_author);
                             break;
                         default:
                             $row[$key] = $download->{$key};
                             break;
                     }
                 } elseif ('tags' == $key) {
                     $terms = get_the_terms($download->ID, 'download_tag');
                     if ($terms) {
                         $terms = wp_list_pluck($terms, 'name');
                         $row[$key] = implode(' | ', $terms);
                     }
                 } elseif ('categories' == $key) {
                     $terms = get_the_terms($download->ID, 'download_category');
                     if ($terms) {
                         $terms = wp_list_pluck($terms, 'name');
                         $row[$key] = implode(' | ', $terms);
                     }
                 }
             }
             $data[] = $row;
         }
         $data = apply_filters('give_export_get_data', $data);
         $data = apply_filters('give_export_get_data_' . $this->export_type, $data);
         return $data;
     }
     return false;
 }
Exemple #12
0
/**
 * Donation Amount Field
 *
 * Outputs the donation amount field that appears at the top of the donation forms. If the user has custom amount enabled the field will output as a customizable input
 *
 * @since  1.0
 *
 * @param  int   $form_id Give Form ID
 * @param  array $args
 *
 * @return void
 */
function give_output_donation_amount_top($form_id = 0, $args = array())
{
    global $give_options;
    $variable_pricing = give_has_variable_prices($form_id);
    $allow_custom_amount = get_post_meta($form_id, '_give_custom_amount', true);
    $currency_position = isset($give_options['currency_position']) ? $give_options['currency_position'] : 'before';
    $symbol = give_currency_symbol(give_get_currency());
    $currency_output = '<span class="give-currency-symbol give-currency-position-' . $currency_position . '">' . $symbol . '</span>';
    $default_amount = give_format_amount(give_get_default_form_amount($form_id));
    $custom_amount_text = get_post_meta($form_id, '_give_custom_amount_text', true);
    do_action('give_before_donation_levels', $form_id, $args);
    //Set Price, No Custom Amount Allowed means hidden price field
    if ($allow_custom_amount == 'no') {
        ?>

		<label class="give-hidden" for="give-amount-hidden"><?php 
        echo esc_html__('Donation Amount:', 'give');
        ?>
</label>
		<input id="give-amount" class="give-amount-hidden" type="hidden" name="give-amount"
		       value="<?php 
        echo $default_amount;
        ?>
" required>
		<div class="set-price give-donation-amount form-row-wide">
			<?php 
        if ($currency_position == 'before') {
            echo $currency_output;
        }
        ?>
			<span id="give-amount-text" class="give-text-input give-amount-top"><?php 
        echo $default_amount;
        ?>
</span>
			<?php 
        if ($currency_position == 'after') {
            echo $currency_output;
        }
        ?>
		</div>
		<?php 
    } else {
        //Custom Amount Allowed
        ?>
		<div class="give-total-wrap">
			<div class="give-donation-amount form-row-wide">
				<?php 
        if ($currency_position == 'before') {
            echo $currency_output;
        }
        ?>
				<label class="give-hidden" for="give-amount"><?php 
        echo esc_html__('Donation Amount:', 'give');
        ?>
</label>
				<input class="give-text-input give-amount-top" id="give-amount" name="give-amount" type="tel" placeholder="" value="<?php 
        echo $default_amount;
        ?>
" autocomplete="off">
				<?php 
        if ($currency_position == 'after') {
            echo $currency_output;
        }
        ?>
			</div>
		</div>
	<?php 
    }
    do_action('give_after_donation_amount', $form_id, $args);
    //Custom Amount Text
    if (!$variable_pricing && $allow_custom_amount == 'yes' && !empty($custom_amount_text)) {
        ?>
		<p class="give-custom-amount-text"><?php 
        echo $custom_amount_text;
        ?>
</p>
	<?php 
    }
    //Output Variable Pricing Levels
    if ($variable_pricing) {
        give_output_levels($form_id);
    }
    do_action('give_after_donation_levels', $form_id, $args);
}
 /**
  * Determine if the donation is free or if the given price ID is free
  *
  * @since  1.0
  * @access public
  *
  * @param  int    $price_id Price ID. Default is false.
  *
  * @return bool
  */
 public function is_free($price_id = false)
 {
     $is_free = false;
     $variable_pricing = give_has_variable_prices($this->ID);
     if ($variable_pricing && !is_null($price_id) && $price_id !== false) {
         $price = give_get_price_option_amount($this->ID, $price_id);
     } elseif (!$variable_pricing) {
         $price = get_post_meta($this->ID, '_give_set_price', true);
     }
     if (isset($price) && (double) $price == 0) {
         $is_free = true;
     }
     return (bool) apply_filters('give_is_free_donation', $is_free, $this->ID, $price_id);
 }
Exemple #14
0
/**
 * Process PayPal Purchase.
 *
 * @since 1.0
 *
 * @param array $purchase_data Purchase Data
 *
 * @return void
 */
function give_process_paypal_purchase($purchase_data)
{
    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'give-gateway')) {
        wp_die(esc_html__('Nonce verification has failed.', 'give'), esc_html__('Error', 'give'), array('response' => 403));
    }
    $form_id = intval($purchase_data['post_data']['give-form-id']);
    $price_id = isset($purchase_data['post_data']['give-price-id']) ? $purchase_data['post_data']['give-price-id'] : '';
    // Collect payment data.
    $payment_data = array('price' => $purchase_data['price'], 'give_form_title' => $purchase_data['post_data']['give-form-title'], 'give_form_id' => $form_id, 'give_price_id' => $price_id, 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => give_get_currency(), 'user_info' => $purchase_data['user_info'], 'status' => 'pending', 'gateway' => 'paypal');
    // Record the pending payment.
    $payment_id = give_insert_payment($payment_data);
    // Check payment.
    if (!$payment_id) {
        // Record the error.
        give_record_gateway_error(esc_html__('Payment Error', 'give'), sprintf(esc_html__('Payment creation failed before sending donor to PayPal. Payment data: %s', 'give'), json_encode($payment_data)), $payment_id);
        // Problems? Send back.
        give_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['give-gateway']);
    } else {
        // Only send to PayPal if the pending payment is created successfully.
        $listener_url = add_query_arg('give-listener', 'IPN', home_url('index.php'));
        // Get the success url.
        $return_url = add_query_arg(array('payment-confirmation' => 'paypal', 'payment-id' => $payment_id), get_permalink(give_get_option('success_page')));
        // Get the PayPal redirect uri.
        $paypal_redirect = trailingslashit(give_get_paypal_redirect()) . '?';
        //Item name - pass level name if variable priced.
        $item_name = $purchase_data['post_data']['give-form-title'];
        //Verify has variable prices.
        if (give_has_variable_prices($form_id) && isset($purchase_data['post_data']['give-price-id'])) {
            $item_price_level_text = give_get_price_option_name($form_id, $purchase_data['post_data']['give-price-id']);
            $price_level_amount = give_get_price_option_amount($form_id, $purchase_data['post_data']['give-price-id']);
            //Donation given doesn't match selected level (must be a custom amount).
            if ($price_level_amount != give_sanitize_amount($purchase_data['price'])) {
                $custom_amount_text = get_post_meta($form_id, '_give_custom_amount_text', true);
                //user custom amount text if any, fallback to default if not.
                $item_name .= ' - ' . (!empty($custom_amount_text) ? $custom_amount_text : esc_html__('Custom Amount', 'give'));
            } elseif (!empty($item_price_level_text)) {
                $item_name .= ' - ' . $item_price_level_text;
            }
        } elseif (give_get_form_price($form_id) !== give_sanitize_amount($purchase_data['price'])) {
            $custom_amount_text = get_post_meta($form_id, '_give_custom_amount_text', true);
            //user custom amount text if any, fallback to default if not.
            $item_name .= ' - ' . (!empty($custom_amount_text) ? $custom_amount_text : esc_html__('Custom Amount', 'give'));
        }
        // Setup PayPal API params.
        $paypal_args = array('business' => give_get_option('paypal_email', false), 'first_name' => $purchase_data['user_info']['first_name'], 'last_name' => $purchase_data['user_info']['last_name'], 'email' => $purchase_data['user_email'], 'invoice' => $purchase_data['purchase_key'], 'amount' => $purchase_data['price'], 'item_name' => stripslashes($item_name), 'no_shipping' => '1', 'shipping' => '0', 'no_note' => '1', 'currency_code' => give_get_currency(), 'charset' => get_bloginfo('charset'), 'custom' => $payment_id, 'rm' => '2', 'return' => $return_url, 'cancel_return' => give_get_failed_transaction_uri('?payment-id=' . $payment_id), 'notify_url' => $listener_url, 'page_style' => give_get_paypal_page_style(), 'cbt' => get_bloginfo('name'), 'bn' => 'givewp_SP');
        //Add user address if present.
        if (!empty($purchase_data['user_info']['address'])) {
            $paypal_args['address1'] = isset($purchase_data['user_info']['address']['line1']) ? $purchase_data['user_info']['address']['line1'] : '';
            $paypal_args['address2'] = isset($purchase_data['user_info']['address']['line2']) ? $purchase_data['user_info']['address']['line2'] : '';
            $paypal_args['city'] = isset($purchase_data['user_info']['address']['city']) ? $purchase_data['user_info']['address']['city'] : '';
            $paypal_args['state'] = isset($purchase_data['user_info']['address']['state']) ? $purchase_data['user_info']['address']['state'] : '';
            $paypal_args['country'] = isset($purchase_data['user_info']['address']['country']) ? $purchase_data['user_info']['address']['country'] : '';
        }
        //Donations or regular transactions?
        if (give_get_option('paypal_button_type') === 'standard') {
            $paypal_extra_args = array('cmd' => '_xclick');
        } else {
            $paypal_extra_args = array('cmd' => '_donations');
        }
        $paypal_args = array_merge($paypal_extra_args, $paypal_args);
        $paypal_args = apply_filters('give_paypal_redirect_args', $paypal_args, $purchase_data);
        // Build query.
        $paypal_redirect .= http_build_query($paypal_args);
        // Fix for some sites that encode the entities.
        $paypal_redirect = str_replace('&amp;', '&', $paypal_redirect);
        // Redirect to PayPal.
        wp_redirect($paypal_redirect);
        exit;
    }
}
Exemple #15
0
/**
 * Get Price ID
 *
 * @description Retrieves the Price ID given a proper form ID and price (donation) total
 *
 * @param $form_id
 * @param $price
 *
 * @return string $price_id
 */
function give_get_price_id($form_id, $price)
{
    $price_id = 0;
    if (give_has_variable_prices($form_id)) {
        $levels = maybe_unserialize(get_post_meta($form_id, '_give_donation_levels', true));
        foreach ($levels as $level) {
            $level_amount = (double) give_sanitize_amount($level['_give_amount']);
            //check that this indeed the recurring price
            if ($level_amount == $price) {
                $price_id = $level['_give_id']['level_id'];
            }
        }
    }
    return $price_id;
}
Exemple #16
0
/**
 * Donation Levels Output
 *
 * Outputs donation levels based on the specific form ID.
 * The output generated can be overridden by the filters provided or by removing
 * the action and adding your own custom action.
 *
 * @since 1.0
 *
 * @param int $form_id Give Form ID
 *
 * @return void
 */
function give_output_donation_levels($form_id = 0, $args = array())
{
    global $give_options;
    $variable_pricing = give_has_variable_prices($form_id);
    $allow_custom_amount = get_post_meta($form_id, '_give_custom_amount', true);
    $currency_position = isset($give_options['currency_position']) ? $give_options['currency_position'] : 'before';
    $symbol = isset($give_options['currency']) ? give_currency_symbol($give_options['currency']) : '$';
    $currency_output = '<span class="give-currency-symbol give-currency-position-' . $currency_position . '">' . $symbol . '</span>';
    $default_amount = give_format_amount(give_get_default_form_amount($form_id));
    $custom_amount_text = get_post_meta($form_id, '_give_custom_amount_text', true);
    do_action('give_before_donation_levels', $form_id);
    //Set Price, No Custom Amount Allowed means hidden price field
    if ($allow_custom_amount == 'no') {
        ?>

		<input id="give-amount" class="give-amount-hidden" type="hidden" name="give-amount" value="<?php 
        echo $default_amount;
        ?>
" required>
		<p class="set-price give-donation-amount form-row-wide">
			<?php 
        if ($currency_position == 'before') {
            echo $currency_output;
        }
        ?>
			<span id="give-amount" class="give-text-input"><?php 
        echo give_format_amount($default_amount);
        ?>
</span>
		</p>
		<?php 
    } else {
        //Custom Amount Allowed
        ?>
		<div class="give-total-wrap">
			<div class="give-donation-amount form-row-wide">
				<?php 
        if ($currency_position == 'before') {
            echo $currency_output;
        }
        ?>

				<input class="give-text-input" id="give-amount" name="give-amount" type="text" placeholder="" value="<?php 
        echo $default_amount;
        ?>
" required autocomplete="off">

				<?php 
        if ($currency_position == 'after') {
            echo $currency_output;
        }
        ?>

				<p class="give-loading-text give-updating-price-loader" style="display: none;">
					<span class="give-loading-animation"></span> <?php 
        _e('Updating Price', 'Give');
        ?>
					<span class="elipsis">.</span><span class="elipsis">.</span><span class="elipsis">.</span></p>
			</div>
		</div>
	<?php 
    }
    //Custom Amount Text
    if (!empty($custom_amount_text) && !$variable_pricing && $allow_custom_amount == 'yes') {
        ?>
		<p class="give-custom-amount-text"><?php 
        echo $custom_amount_text;
        ?>
</p>
	<?php 
    }
    //Output Variable Pricing Levels
    if ($variable_pricing) {
        give_output_levels($form_id);
    }
    do_action('give_after_donation_levels', $form_id);
}
 /**
  * Add a donation to a given payment
  *
  * @since  1.5
  * @access public
  *
  * @param  int   $form_id The donation form to add
  * @param  array $args Other arguments to pass to the function
  * @param  array $options List of donation options
  *
  * @return bool           True when successful, false otherwise
  */
 public function add_donation($form_id = 0, $args = array(), $options = array())
 {
     $donation = new Give_Donate_Form($form_id);
     // Bail if this post isn't a give donation form
     if (!$donation || $donation->post_type !== 'give_forms') {
         return false;
     }
     // Set some defaults
     $defaults = array('price' => false, 'price_id' => false, 'fees' => array());
     $args = wp_parse_args(apply_filters('give_payment_add_donation_args', $args, $donation->ID), $defaults);
     // Allow overriding the price
     if (false !== $args['price']) {
         $item_price = $args['price'];
     } else {
         // Deal with variable pricing
         if (give_has_variable_prices($donation->ID)) {
             $prices = maybe_unserialize(get_post_meta($form_id, '_give_donation_levels', true));
             $item_price = '';
             //Loop through prices
             foreach ($prices as $price) {
                 //Find a match between price_id and level_id
                 //First verify array keys exists THEN make the match
                 if (isset($args['price_id']) && isset($price['_give_id']['level_id']) && $args['price_id'] == $price['_give_id']['level_id']) {
                     $item_price = $price['_give_amount'];
                 }
             }
             //Fallback to the lowest price point
             if ($item_price == '') {
                 $item_price = give_get_lowest_price_option($donation->ID);
                 $args['price_id'] = give_get_lowest_price_id($donation->ID);
             }
         } else {
             //Simple form price
             $item_price = give_get_form_price($donation->ID);
         }
     }
     // Sanitizing the price here so we don't have a dozen calls later
     $item_price = give_sanitize_amount($item_price);
     $total = round($item_price, give_currency_decimal_filter());
     //Add Options
     $default_options = array();
     if (false !== $args['price_id']) {
         $default_options['price_id'] = (int) $args['price_id'];
     }
     $options = wp_parse_args($options, $default_options);
     // Do not allow totals to go negative
     if ($total < 0) {
         $total = 0;
     }
     $donation = array('name' => $donation->post_title, 'id' => $donation->ID, 'price' => round($total, give_currency_decimal_filter()), 'subtotal' => round($total, give_currency_decimal_filter()), 'fees' => $args['fees'], 'price_id' => $args['price_id'], 'action' => 'add', 'options' => $options);
     $this->pending['donations'][] = $donation;
     $this->increase_subtotal($total);
     return true;
 }
/**
 * Email template tag: {donation}
 *
 * Output the donation form name, and the donation level (if applicable).
 *
 * @param int $payment_id
 *
 * @return string $form_title
 */
function give_email_tag_donation($payment_id)
{
    $payment = new Give_Payment($payment_id);
    $payment_meta = $payment->payment_meta;
    $level_title = give_has_variable_prices($payment_meta['form_id']);
    $separator = $level_title ? '-' : '';
    $form_title = strip_tags(give_get_payment_form_title($payment_meta, false, $separator));
    return !empty($form_title) ? $form_title : esc_html__('There was an error retrieving the donation form name.', 'give');
}
 /**
  * Retrieves Recent Sales
  *
  * @access public
  * @since  1.1
  * @return array
  */
 public function get_recent_donations()
 {
     global $wp_query;
     $sales = array();
     if (!user_can($this->user_id, 'view_give_reports') && !$this->override) {
         return $sales;
     }
     if (isset($wp_query->query_vars['id'])) {
         $query = array();
         $query[] = give_get_payment_by('id', $wp_query->query_vars['id']);
     } elseif (isset($wp_query->query_vars['purchasekey'])) {
         $query = array();
         $query[] = give_get_payment_by('key', $wp_query->query_vars['purchasekey']);
     } elseif (isset($wp_query->query_vars['email'])) {
         $query = give_get_payments(array('meta_key' => '_give_payment_user_email', 'meta_value' => $wp_query->query_vars['email'], 'number' => $this->per_page(), 'page' => $this->get_paged(), 'status' => 'publish'));
     } else {
         $query = give_get_payments(array('number' => $this->per_page(), 'page' => $this->get_paged(), 'status' => 'publish'));
     }
     if ($query) {
         $i = 0;
         foreach ($query as $payment) {
             $payment_meta = give_get_payment_meta($payment->ID);
             $user_info = give_get_payment_meta_user_info($payment->ID);
             $sales['donations'][$i]['ID'] = give_get_payment_number($payment->ID);
             $sales['donations'][$i]['transaction_id'] = give_get_payment_transaction_id($payment->ID);
             $sales['donations'][$i]['key'] = give_get_payment_key($payment->ID);
             $sales['donations'][$i]['total'] = give_get_payment_amount($payment->ID);
             $sales['donations'][$i]['gateway'] = give_get_payment_gateway($payment->ID);
             $sales['donations'][$i]['email'] = give_get_payment_user_email($payment->ID);
             $sales['donations'][$i]['date'] = $payment->post_date;
             $form_id = isset($payment_meta['form_id']) ? $payment_meta['form_id'] : $payment_meta;
             $price = isset($payment_meta['form_id']) ? give_get_form_price($payment_meta['form_id']) : false;
             $price_id = isset($payment_meta['price_id']) ? $payment_meta['price_id'] : null;
             $sales['donations'][$i]['form']['id'] = $form_id;
             $sales['donations'][$i]['form']['name'] = get_the_title($payment_meta['form_id']);
             $sales['donations'][$i]['form']['price'] = $price;
             if (give_has_variable_prices($form_id)) {
                 if (isset($payment_meta['price_id'])) {
                     $price_name = give_get_price_option_name($form_id, $payment_meta['price_id'], $payment->ID);
                     $sales['donations'][$i]['form']['price_name'] = $price_name;
                     $sales['donations'][$i]['form']['price'] = give_get_price_option_amount($form_id, $price_id);
                 }
             }
             $i++;
         }
     }
     return $sales;
 }
Exemple #20
0
/**
 * Generate PDF Reports.
 *
 * Generates PDF report on donations and income for all forms for the current year.
 *
 * @since  1.0
 *
 * @param string $data
 *
 * @uses   give_pdf
 */
function give_generate_pdf($data)
{
    if (!current_user_can('view_give_reports')) {
        wp_die(esc_html__('You do not have permission to generate PDF sales reports.', 'give'), esc_html__('Error', 'give'), array('response' => 403));
    }
    if (!wp_verify_nonce($_GET['_wpnonce'], 'give_generate_pdf')) {
        wp_die(esc_html__('Nonce verification failed.', 'give'), esc_html__('Error', 'give'), array('response' => 403));
    }
    require_once GIVE_PLUGIN_DIR . '/includes/libraries/fpdf/fpdf.php';
    require_once GIVE_PLUGIN_DIR . '/includes/libraries/fpdf/give_pdf.php';
    $daterange = utf8_decode(sprintf(esc_html__('%1$s to %2$s', 'give'), date_i18n(get_option('date_format'), mktime(0, 0, 0, 1, 1, date('Y'))), date_i18n(get_option('date_format'))));
    $pdf = new give_pdf();
    $pdf->AddPage('L', 'A4');
    $pdf->SetTitle(utf8_decode(__('Donation report for the current year for all forms', 'give')));
    $pdf->SetAuthor(utf8_decode(__('Give - Democratizing Generosity', 'give')));
    $pdf->SetCreator(utf8_decode(__('Give - Democratizing Generosity', 'give')));
    $pdf->Image(apply_filters('give_pdf_export_logo', GIVE_PLUGIN_URL . 'assets/images/give-logo-small.png'), 247, 8);
    $pdf->SetMargins(8, 8, 8);
    $pdf->SetX(8);
    $pdf->SetFont('Helvetica', '', 16);
    $pdf->SetTextColor(50, 50, 50);
    $pdf->Cell(0, 3, utf8_decode(__('Donation report for the current year for all forms', 'give')), 0, 2, 'L', false);
    $pdf->SetFont('Helvetica', '', 13);
    $pdf->Ln();
    $pdf->SetTextColor(150, 150, 150);
    $pdf->Cell(0, 6, utf8_decode(__('Date Range: ', 'give')) . $daterange, 0, 2, 'L', false);
    $pdf->Ln();
    $pdf->SetTextColor(50, 50, 50);
    $pdf->SetFont('Helvetica', '', 14);
    $pdf->Cell(0, 10, utf8_decode(__('Table View', 'give')), 0, 2, 'L', false);
    $pdf->SetFont('Helvetica', '', 12);
    $pdf->SetFillColor(238, 238, 238);
    $pdf->Cell(70, 6, utf8_decode(__('Form Name', 'give')), 1, 0, 'L', true);
    $pdf->Cell(30, 6, utf8_decode(__('Price', 'give')), 1, 0, 'L', true);
    $pdf->Cell(50, 6, utf8_decode(__('Categories', 'give')), 1, 0, 'L', true);
    $pdf->Cell(50, 6, utf8_decode(__('Tags', 'give')), 1, 0, 'L', true);
    $pdf->Cell(45, 6, utf8_decode(__('Number of Donations', 'give')), 1, 0, 'L', true);
    $pdf->Cell(35, 6, utf8_decode(__('Income to Date', 'give')), 1, 1, 'L', true);
    $year = date('Y');
    $give_forms = get_posts(array('post_type' => 'give_forms', 'year' => $year, 'posts_per_page' => -1));
    if ($give_forms) {
        $pdf->SetWidths(array(70, 30, 50, 50, 45, 35));
        foreach ($give_forms as $form) {
            $pdf->SetFillColor(255, 255, 255);
            $title = $form->post_title;
            if (give_has_variable_prices($form->ID)) {
                $prices = give_get_variable_prices($form->ID);
                $first = $prices[0]['_give_amount'];
                $last = array_pop($prices);
                $last = $last['_give_amount'];
                if ($first < $last) {
                    $min = $first;
                    $max = $last;
                } else {
                    $min = $last;
                    $max = $first;
                }
                $price = html_entity_decode(give_currency_filter(give_format_amount($min)) . ' - ' . give_currency_filter(give_format_amount($max)));
            } else {
                $price = html_entity_decode(give_currency_filter(give_get_form_price($form->ID)));
            }
            $categories = get_the_term_list($form->ID, 'give_forms_category', '', ', ', '');
            $categories = !is_wp_error($categories) ? strip_tags($categories) : '';
            $tags = get_the_term_list($form->ID, 'give_forms_tag', '', ', ', '');
            $tags = !is_wp_error($tags) ? strip_tags($tags) : '';
            $sales = give_get_form_sales_stats($form->ID);
            $link = get_permalink($form->ID);
            $earnings = html_entity_decode(give_currency_filter(give_get_form_earnings_stats($form->ID)));
            if (function_exists('iconv')) {
                // Ensure characters like euro; are properly converted.
                $price = iconv('UTF-8', 'windows-1252', utf8_encode($price));
                $earnings = iconv('UTF-8', 'windows-1252', utf8_encode($earnings));
            }
            $pdf->Row(array($title, $price, $categories, $tags, $sales, $earnings));
        }
    } else {
        $pdf->SetWidths(array(280));
        $title = utf8_decode(sprintf(esc_html__('No %s found.', 'give'), give_get_forms_label_plural()));
        $pdf->Row(array($title));
    }
    $pdf->Ln();
    $pdf->SetTextColor(50, 50, 50);
    $pdf->SetFont('Helvetica', '', 14);
    $pdf->Cell(0, 10, utf8_decode(__('Graph View', 'give')), 0, 2, 'L', false);
    $pdf->SetFont('Helvetica', '', 12);
    $image = html_entity_decode(urldecode(give_draw_chart_image()));
    $image = str_replace(' ', '%20', $image);
    $pdf->SetX(25);
    $pdf->Image($image . '&file=.png');
    $pdf->Ln(7);
    $pdf->Output(apply_filters('give_sales_earnings_pdf_export_filename', 'give-report-' . date_i18n('Y-m-d')) . '.pdf', 'D');
}
											<?php 
do_action('give_donation_details_tbody_before', $payment_id);
?>
											<td>
												<?php 
echo $payment_meta['form_id'];
?>
											</td>
											<td>
												<?php 
give_get_form_dropdown(array('id' => $payment_meta['form_id'], 'selected' => $payment_meta['form_id'], 'chosen' => true), true);
?>
											</td>
											<td>
												<?php 
$var_prices = give_has_variable_prices($payment_meta['form_id']);
if (empty($var_prices)) {
    echo esc_html__('n/a', 'give');
} else {
    // Variable price dropdown options.
    $variable_price_dropdown_option = array('id' => $payment_meta['form_id'], 'name' => 'give-variable-price', 'chosen' => true, 'show_option_all' => '', 'selected' => $payment_meta['price_id']);
    // Render variable prices select tag html.
    give_get_form_variable_price_dropdown($variable_price_dropdown_option, true);
}
?>
											</td>
											<td>
												<?php 
//Transaction Date
$date_format = get_option('date_format');
echo date_i18n($date_format, $payment_date);