Beispiel #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;
}
Beispiel #2
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;
        }
    }
}
Beispiel #3
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');
}
 /**
  * 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);
 }
Beispiel #5
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;
    }
}
Beispiel #6
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;
    }
}
 /**
  * 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;
 }
 /**
  * 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;
 }