/**
  * Get the Export Data
  *
  * @access public
  * @since 1.5
  * @global object $wpdb Used to query the database using the WordPress
  *   Database API
  * @return array $data The data for the CSV file
  */
 public function get_data()
 {
     $customer = new Give_Customer($this->customer_id);
     $payments = $this->get_stored_data('give_recount_customer_payments_' . $customer->id, array());
     $offset = ($this->step - 1) * $this->per_step;
     $step_items = array_slice($payments, $offset, $this->per_step);
     if (count($step_items) > 0) {
         $pending_total = (double) $this->get_stored_data('give_stats_customer_pending_total' . $customer->id, 0);
         $step_total = 0;
         $found_payment_ids = $this->get_stored_data('give_stats_found_payments_' . $customer->id, array());
         foreach ($step_items as $payment) {
             $payment = get_post($payment->ID);
             if (is_null($payment) || is_wp_error($payment) || 'give_payment' !== $payment->post_type) {
                 $missing_payments = $this->get_stored_data('give_stats_missing_payments' . $customer->id, array());
                 $missing_payments[] = $payment->ID;
                 $this->store_data('give_stats_missing_payments' . $customer->id, $missing_payments);
                 continue;
             }
             $should_process_payment = 'publish' == $payment->post_status ? true : false;
             $should_process_payment = apply_filters('give_customer_recount_should_process_payment', $should_process_payment, $payment);
             if (true === $should_process_payment) {
                 $found_payment_ids[] = $payment->ID;
                 if (apply_filters('give_customer_recount_sholud_increase_value', true, $payment)) {
                     $payment_amount = give_get_payment_amount($payment->ID);
                     $step_total += $payment_amount;
                 }
             }
         }
         $updated_total = $pending_total + $step_total;
         $this->store_data('give_stats_customer_pending_total' . $customer->id, $updated_total);
         $this->store_data('give_stats_found_payments_' . $customer->id, $found_payment_ids);
         return true;
     }
     return false;
 }
 /**
  * Get the Export Data.
  *
  * @access public
  * @since 1.5
  * @global object $wpdb Used to query the database using the WordPress database API.
  * @return array $data The data for the CSV file.
  */
 public function get_data()
 {
     global $wpdb;
     $data = array();
     $args = array('number' => 30, 'page' => $this->step, 'status' => $this->status);
     if (!empty($this->start) || !empty($this->end)) {
         $args['date_query'] = array(array('after' => date('Y-n-d 00:00:00', strtotime($this->start)), 'before' => date('Y-n-d 23:59:59', strtotime($this->end)), 'inclusive' => true));
     }
     //echo json_encode($args ); exit;
     $payments = give_get_payments($args);
     if ($payments) {
         foreach ($payments as $payment) {
             $payment_meta = give_get_payment_meta($payment->ID);
             $user_info = give_get_payment_meta_user_info($payment->ID);
             $total = give_get_payment_amount($payment->ID);
             $user_id = isset($user_info['id']) && $user_info['id'] != -1 ? $user_info['id'] : $user_info['email'];
             $products = '';
             $skus = '';
             if (is_numeric($user_id)) {
                 $user = get_userdata($user_id);
             } else {
                 $user = false;
             }
             $data[] = array('id' => $payment->ID, 'seq_id' => give_get_payment_number($payment->ID), 'email' => $payment_meta['email'], 'first' => $user_info['first_name'], 'last' => $user_info['last_name'], 'address1' => isset($user_info['address']['line1']) ? $user_info['address']['line1'] : '', 'address2' => isset($user_info['address']['line2']) ? $user_info['address']['line2'] : '', 'city' => isset($user_info['address']['city']) ? $user_info['address']['city'] : '', 'state' => isset($user_info['address']['state']) ? $user_info['address']['state'] : '', 'country' => isset($user_info['address']['country']) ? $user_info['address']['country'] : '', 'zip' => isset($user_info['address']['zip']) ? $user_info['address']['zip'] : '', 'form_id' => isset($payment_meta['form_id']) ? $payment_meta['form_id'] : '', 'form_name' => isset($payment_meta['form_title']) ? $payment_meta['form_title'] : '', 'skus' => $skus, 'amount' => html_entity_decode(give_format_amount($total)), 'gateway' => give_get_gateway_admin_label(get_post_meta($payment->ID, '_give_payment_gateway', true)), 'trans_id' => give_get_payment_transaction_id($payment->ID), 'key' => $payment_meta['key'], 'date' => $payment->post_date, 'user' => $user ? $user->display_name : __('guest', 'give'), 'status' => give_get_payment_status($payment, true));
         }
         $data = apply_filters('give_export_get_data', $data);
         $data = apply_filters('give_export_get_data_' . $this->export_type, $data);
         return $data;
     }
     return false;
 }
function my_give_google_analytics_event($payment, $give_receipt_args)
{
    if ($give_receipt_args['payment_id']) {
        // Use a meta value so we only send the beacon once.
        if (get_post_meta($payment->ID, 'give_ga_beacon_sent', true)) {
            return;
        }
        $total = give_get_payment_amount($payment->ID);
        ?>
		<script type="text/javascript">

				ga('require', 'ecommerce', 'ecommerce.js');

				ga('ecommerce:addTransaction', {
					'id': '<?php 
        echo esc_js(give_get_payment_number($payment->ID));
        ?>
', // Transaction ID. Required.
					'affiliation': '<?php 
        echo esc_js(get_bloginfo('name'));
        ?>
', // Affiliation or store name.
					'revenue': '<?php 
        echo esc_js($total);
        ?>
' // donation amount.
				});

				ga('ecommerce:send');

		</script>
		<?php 
        update_post_meta($payment->ID, 'give_ga_beacon_sent', true);
    }
}
 /**
  * Get the Export Data
  *
  * @access public
  * @since 1.5
  * @global object $wpdb Used to query the database using the WordPress
  *   Database API
  * @return array $data The data for the CSV file
  */
 public function get_data()
 {
     if ($this->step == 1) {
         $this->delete_data('give_temp_recount_income');
     }
     $total = get_option('give_temp_recount_income', false);
     if (false === $total) {
         $total = (double) 0;
         $this->store_data('give_temp_recount_income', $total);
     }
     $accepted_statuses = apply_filters('give_recount_accepted_statuses', array('publish'));
     $args = apply_filters('give_recount_income_args', array('number' => $this->per_step, 'page' => $this->step, 'status' => $accepted_statuses, 'fields' => 'ids'));
     $payments = give_get_payments($args);
     if (!empty($payments)) {
         foreach ($payments as $payment) {
             $total += give_get_payment_amount($payment);
         }
         if ($total < 0) {
             $totals = 0;
         }
         $total = round($total, give_currency_decimal_filter());
         $this->store_data('give_temp_recount_income', $total);
         return true;
     }
     update_option('give_income_total', $total);
     set_transient('give_income_total', $total, 86400);
     return false;
 }
 /**
  * Get the Export Data
  *
  * @access public
  * @since 1.5
  * @global object $wpdb Used to query the database using the WordPress
  *   Database API
  * @return array $data The data for the CSV file
  */
 public function get_data()
 {
     $args = array('number' => $this->per_step, 'offset' => $this->per_step * ($this->step - 1), 'orderby' => 'id', 'order' => 'DESC');
     $customers = Give()->customers->get_customers($args);
     if ($customers) {
         $allowed_payment_status = apply_filters('give_recount_customer_payment_statuses', give_get_payment_status_keys());
         foreach ($customers as $customer) {
             $attached_payment_ids = explode(',', $customer->payment_ids);
             $attached_args = array('post__in' => $attached_payment_ids, 'number' => -1, 'status' => $allowed_payment_status);
             $attached_payments = (array) give_get_payments($attached_args);
             $unattached_args = array('post__not_in' => $attached_payment_ids, 'number' => -1, 'status' => $allowed_payment_status, 'meta_query' => array(array('key' => '_give_payment_user_email', 'value' => $customer->email, 'compare' => '=')));
             $unattached_payments = give_get_payments($unattached_args);
             $payments = array_merge($attached_payments, $unattached_payments);
             $purchase_value = 0.0;
             $purchase_count = 0;
             $payment_ids = array();
             if ($payments) {
                 foreach ($payments as $payment) {
                     $should_process_payment = 'publish' == $payment->post_status ? true : false;
                     $should_process_payment = apply_filters('give_customer_recount_should_process_payment', $should_process_payment, $payment);
                     if (true === $should_process_payment) {
                         if (apply_filters('give_customer_recount_should_increase_value', true, $payment)) {
                             $purchase_value += give_get_payment_amount($payment->ID);
                         }
                         if (apply_filters('give_customer_recount_should_increase_count', true, $payment)) {
                             $purchase_count++;
                         }
                     }
                     $payment_ids[] = $payment->ID;
                 }
             }
             $payment_ids = implode(',', $payment_ids);
             $customer_update_data = array('purchase_count' => $purchase_count, 'purchase_value' => $purchase_value, 'payment_ids' => $payment_ids);
             $customer_instance = new Give_Customer($customer->id);
             $customer_instance->update($customer_update_data);
         }
         return true;
     }
     return false;
 }
 /**
  * Get the Export Data
  *
  * @access public
  * @since  1.0
  * @global object $wpdb Used to query the database using the WordPress
  *                      Database API
  * @return array $data The data for the CSV file
  */
 public function get_data()
 {
     global $wpdb, $give_options;
     $data = array();
     $payments = give_get_payments(array('offset' => 0, 'number' => -1, 'mode' => give_is_test_mode() ? 'test' : 'live', 'status' => isset($_POST['give_export_payment_status']) ? $_POST['give_export_payment_status'] : 'any', 'month' => isset($_POST['month']) ? absint($_POST['month']) : date('n'), 'year' => isset($_POST['year']) ? absint($_POST['year']) : date('Y')));
     foreach ($payments as $payment) {
         $payment_meta = give_get_payment_meta($payment->ID);
         $user_info = give_get_payment_meta_user_info($payment->ID);
         $total = give_get_payment_amount($payment->ID);
         $user_id = isset($user_info['id']) && $user_info['id'] != -1 ? $user_info['id'] : $user_info['email'];
         $form_id = isset($payment_meta['form_id']) ? $payment_meta['form_id'] : '';
         $form_title = isset($payment_meta['form_title']) ? $payment_meta['form_title'] : '';
         if (is_numeric($user_id)) {
             $user = get_userdata($user_id);
         } else {
             $user = false;
         }
         $data[] = array('id' => $payment->ID, 'seq_id' => give_get_payment_number($payment->ID), 'email' => $payment_meta['email'], 'first' => $user_info['first_name'], 'last' => $user_info['last_name'], 'address1' => isset($user_info['address']['line1']) ? $user_info['address']['line1'] : '', 'address2' => isset($user_info['address']['line2']) ? $user_info['address']['line2'] : '', 'city' => isset($user_info['address']['city']) ? $user_info['address']['city'] : '', 'state' => isset($user_info['address']['state']) ? $user_info['address']['state'] : '', 'country' => isset($user_info['address']['country']) ? $user_info['address']['country'] : '', 'zip' => isset($user_info['address']['zip']) ? $user_info['address']['zip'] : '', 'amount' => html_entity_decode(give_format_amount($total)), 'form_id' => $form_id, 'form' => $form_title, 'gateway' => give_get_gateway_admin_label(get_post_meta($payment->ID, '_give_payment_gateway', true)), 'trans_id' => give_get_payment_transaction_id($payment->ID), 'key' => $payment_meta['key'], 'date' => $payment->post_date, 'user' => $user ? $user->display_name : __('guest', 'give'), 'status' => give_get_payment_status($payment, true));
     }
     $data = apply_filters('give_export_get_data', $data);
     $data = apply_filters('give_export_get_data_' . $this->export_type, $data);
     return $data;
 }
/**
 * Email template tag: price
 * The total price of the donation
 *
 * @param int $payment_id
 *
 * @return string price
 */
function give_email_tag_price($payment_id)
{
    $price = give_currency_filter(give_format_amount(give_get_payment_amount($payment_id)), give_get_payment_currency_code($payment_id));
    return html_entity_decode($price, ENT_COMPAT, 'UTF-8');
}
Exemple #8
0
/**
 * Returns the admin label for the specified gateway
 *
 * @since 1.0.8.3
 *
 * @param string $gateway Name of the gateway to retrieve a label for
 *
 * @return string Gateway admin label
 */
function give_get_gateway_admin_label($gateway)
{
    $gateways = give_get_enabled_payment_gateways();
    $label = isset($gateways[$gateway]) ? $gateways[$gateway]['admin_label'] : $gateway;
    $payment = isset($_GET['id']) ? absint($_GET['id']) : false;
    if ($gateway == 'manual' && $payment) {
        if (give_get_payment_amount($payment) == 0) {
            $label = __('Test Donation', 'give');
        }
    }
    return apply_filters('give_gateway_admin_label', $label, $gateway);
}
 /**
  * Retrieve payments.
  *
  * The query can be modified in two ways; either the action before the
  * query is run, or the filter on the arguments (existing mainly for backwards
  * compatibility).
  *
  * @access public
  * @since  1.0
  * @return object
  */
 public function get_payments()
 {
     do_action('give_pre_get_payments', $this);
     $query = new WP_Query($this->args);
     if ('payments' != $this->args['output']) {
         return $query->posts;
     }
     if ($query->have_posts()) {
         while ($query->have_posts()) {
             $query->the_post();
             $details = new stdClass();
             $payment_id = get_post()->ID;
             $details->ID = $payment_id;
             $details->date = get_post()->post_date;
             $details->post_status = get_post()->post_status;
             $details->total = give_get_payment_amount($payment_id);
             $details->fees = give_get_payment_fees($payment_id);
             $details->key = give_get_payment_key($payment_id);
             $details->gateway = give_get_payment_gateway($payment_id);
             $details->user_info = give_get_payment_meta_user_info($payment_id);
             if (give_get_option('enable_sequential')) {
                 $details->payment_number = give_get_payment_number($payment_id);
             }
             $this->payments[] = apply_filters('give_payment', $details, $payment_id, $this);
         }
         wp_reset_postdata();
     }
     do_action('give_post_get_payments', $this);
     return $this->payments;
 }
 /**
  * Retrieve earning stats
  *
  * @access public
  * @since  1.0
  *
  * @param $form_id    INT The donation form to retrieve stats for. If false, gets stats for all forms
  * @param $start_date string|bool The starting date for which we'd like to filter our donation earnings stats. If false, we'll use the default start date of `this_month`
  * @param $end_date   string|bool The end date for which we'd like to filter our sale stats. If false, we'll use the default end date of `this_month`
  *
  * @return float|int
  */
 public function get_earnings($form_id = 0, $start_date = false, $end_date = false)
 {
     global $wpdb;
     $this->setup_dates($start_date, $end_date);
     // Make sure start date is valid
     if (is_wp_error($this->start_date)) {
         return $this->start_date;
     }
     // Make sure end date is valid
     if (is_wp_error($this->end_date)) {
         return $this->end_date;
     }
     add_filter('posts_where', array($this, 'payments_where'));
     if (empty($form_id)) {
         // Global earning stats
         $args = array('post_type' => 'give_payment', 'nopaging' => true, 'post_status' => array('publish', 'revoked'), 'fields' => 'ids', 'update_post_term_cache' => false, 'suppress_filters' => false, 'start_date' => $this->start_date, 'end_date' => $this->end_date, 'give_transient_type' => 'give_earnings');
         $args = apply_filters('give_stats_earnings_args', $args);
         $key = 'give_stats_' . substr(md5(serialize($args)), 0, 15);
         $earnings = get_transient($key);
         if (false === $earnings) {
             $sales = get_posts($args);
             $earnings = 0;
             if ($sales) {
                 $sales = implode(',', $sales);
                 $earnings += $wpdb->get_var("SELECT SUM(meta_value) FROM {$wpdb->postmeta} WHERE meta_key = '_give_payment_total' AND post_id IN({$sales})");
             }
             // Cache the results for one hour
             set_transient($key, $earnings, HOUR_IN_SECONDS);
         }
     } else {
         // Donation form specific earning stats
         global $give_logs, $wpdb;
         $args = array('post_parent' => $form_id, 'nopaging' => true, 'log_type' => 'sale', 'fields' => 'ids', 'suppress_filters' => false, 'start_date' => $this->start_date, 'end_date' => $this->end_date, 'give_transient_type' => 'give_earnings');
         $args = apply_filters('give_stats_earnings_args', $args);
         $key = 'give_stats_' . substr(md5(serialize($args)), 0, 15);
         //Set transient for faster stats
         $earnings = get_transient($key);
         if (false === $earnings) {
             $log_ids = $give_logs->get_connected_logs($args, 'sale');
             $earnings = 0;
             if ($log_ids) {
                 $log_ids = implode(',', $log_ids);
                 $payment_ids = $wpdb->get_col("SELECT meta_value FROM {$wpdb->postmeta} WHERE meta_key='_give_log_payment_id' AND post_id IN ({$log_ids});");
                 foreach ($payment_ids as $payment_id) {
                     $earnings += give_get_payment_amount($payment_id);
                 }
             }
             // Cache the results for one hour
             set_transient($key, $earnings, 60 * 60);
         }
     }
     //remove our filter
     remove_filter('posts_where', array($this, 'payments_where'));
     //return earnings
     return round($earnings, give_currency_decimal_filter());
 }
/**
 * Send Offline Donation Admin Notice
 *
 * Sends a notice to site admins about the pending donation
 *
 * @since       1.0
 *
 * @param int $payment_id
 *
 * @return void
 *
 */
function give_offline_send_admin_notice($payment_id = 0)
{
    /* Send an email notification to the admin */
    $admin_email = give_get_admin_notice_emails();
    $user_info = give_get_payment_meta_user_info($payment_id);
    if (isset($user_info['id']) && $user_info['id'] > 0) {
        $user_data = get_userdata($user_info['id']);
        $name = $user_data->display_name;
    } elseif (isset($user_info['first_name']) && isset($user_info['last_name'])) {
        $name = $user_info['first_name'] . ' ' . $user_info['last_name'];
    } else {
        $name = $user_info['email'];
    }
    $amount = give_currency_filter(give_format_amount(give_get_payment_amount($payment_id)));
    $admin_subject = apply_filters('give_offline_admin_donation_notification_subject', esc_attr__('New Pending Donation', 'give'), $payment_id);
    $admin_message = esc_attr__('Dear Admin,', 'give') . "\n\n";
    $admin_message .= esc_attr__('An offline donation has been made on your website: ', 'give') . get_bloginfo('name') . ' ';
    $admin_message .= esc_attr__('Hooray! The donation is in a pending status and is awaiting payment. Donation instructions have been emailed to the donor. Once you receive payment, be sure to mark the donation as complete using the link below.', 'give') . "\n\n";
    $admin_message .= '<strong>' . esc_attr__('Donor: ', 'give') . '</strong>' . '{fullname}' . "\n";
    $admin_message .= '<strong>' . esc_attr__('Amount: ', 'give') . '</strong>' . '{amount}' . "\n\n";
    $admin_message .= sprintf('<a href="%1$s">%2$s</a>', admin_url('edit.php?post_type=give_forms&page=give-payment-history&view=view-order-details&id=' . $payment_id), esc_html__('Click Here to View and/or Update Donation Details', 'give')) . "\n\n";
    $admin_message = apply_filters('give_offline_admin_donation_notification', $admin_message, $payment_id);
    $admin_message = give_do_email_tags($admin_message, $payment_id);
    $attachments = apply_filters('give_offline_admin_donation_notification_attachments', array(), $payment_id);
    $admin_headers = apply_filters('give_offline_admin_donation_notification_headers', array(), $payment_id);
    //Send Email
    $emails = Give()->emails;
    if (!empty($admin_headers)) {
        $emails->__set('headers', $admin_headers);
    }
    $emails->send($admin_email, $admin_subject, $admin_message, $attachments);
}
Exemple #12
0
											</td>
											<td>
												<a href="<?php 
echo get_permalink($payment_meta['form_id']);
?>
"><?php 
echo $payment_meta['form_title'];
?>
</a>
											</td>
											<td><?php 
echo date('m/d/Y', $payment_date) . ' ' . date_i18n('H:i', $payment_date);
?>
</td>
											<td><?php 
echo esc_html(give_currency_filter(give_format_amount(give_get_payment_amount($payment_id))));
?>
</td>
											<?php 
do_action('give_donation_details_tbody_after', $payment_id);
?>

										</tr>
									</table>

								</div>
								<!-- /.inside -->


							</div>
							<!-- /#give-donation-overview -->
Exemple #13
0
/**
 * Get Payment Amount
 *
 * Get the fully formatted payment amount. The payment amount is retrieved using give_get_payment_amount() and is then sent through give_currency_filter() and  give_format_amount() to format the amount correctly.
 *
 * @since       1.0
 *
 * @param int $payment_id Payment ID
 *
 * @return string $amount Fully formatted payment amount
 */
function give_payment_amount($payment_id = 0)
{
    $amount = give_get_payment_amount($payment_id);
    return give_currency_filter(give_format_amount($amount), give_get_payment_currency_code($payment_id));
}
Exemple #14
0
/**
 * Reduces earnings and donation stats when a donation is refunded
 *
 * @since 1.0
 *
 * @param $payment_id
 * @param $new_status
 * @param $old_status
 *
 * @return void
 */
function give_undo_donation_on_refund($payment_id, $new_status, $old_status)
{
    if ('publish' != $old_status && 'revoked' != $old_status) {
        return;
    }
    if ('refunded' != $new_status) {
        return;
    }
    // Set necessary vars
    $payment_meta = give_get_payment_meta($payment_id);
    $amount = give_get_payment_amount($payment_id);
    // Undo this purchase
    give_undo_purchase($payment_meta['form_id'], $payment_id);
    // Decrease total earnings
    give_decrease_total_earnings($amount);
    // Decrement the stats for the donor
    $donor_id = give_get_payment_customer_id($payment_id);
    if ($donor_id) {
        Give()->customers->decrement_stats($donor_id, $amount);
    }
    // Clear the This Month earnings (this_monththis_month is NOT a typo)
    delete_transient(md5('give_earnings_this_monththis_month'));
}
 /**
  * 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;
 }
        ?>
			<tr class="give_purchase_row">
				<?php 
        do_action('give_purchase_history_row_start', $post->ID, $donation_data);
        ?>
				<td class="give_purchase_id">#<?php 
        echo give_get_payment_number($post->ID);
        ?>
</td>
				<td class="give_purchase_date"><?php 
        echo date_i18n(get_option('date_format'), strtotime(get_post_field('post_date', $post->ID)));
        ?>
</td>
				<td class="give_purchase_amount">
					<span class="give_purchase_amount"><?php 
        echo give_currency_filter(give_format_amount(give_get_payment_amount($post->ID)));
        ?>
</span>
				</td>
				<td class="give_purchase_details">
					<?php 
        if ($post->post_status != 'publish') {
            ?>
						<span class="give_purchase_status <?php 
            echo $post->post_status;
            ?>
"><?php 
            echo give_get_payment_status($post, true);
            ?>
</span>
						<a href="<?php 
Exemple #17
0
/**
 * Process PayPal IPN Refunds
 *
 * @since 1.0
 *
 * @param array $data       IPN Data
 * @param int   $payment_id The payment ID.
 *
 * @return void
 */
function give_process_paypal_refund($data, $payment_id = 0)
{
    // Collect payment details
    if (empty($payment_id)) {
        return;
    }
    if (get_post_status($payment_id) == 'refunded') {
        return;
        // Only refund payments once
    }
    $payment_amount = give_get_payment_amount($payment_id);
    $refund_amount = $data['payment_gross'] * -1;
    if (number_format((double) $refund_amount, 2) < number_format((double) $payment_amount, 2)) {
        give_insert_payment_note($payment_id, sprintf(esc_html__('Partial PayPal refund processed: %s', 'give'), $data['parent_txn_id']));
        return;
        // This is a partial refund
    }
    give_insert_payment_note($payment_id, sprintf(esc_html__('PayPal Payment #%s Refunded for reason: %s', 'give'), $data['parent_txn_id'], $data['reason_code']));
    give_insert_payment_note($payment_id, sprintf(esc_html__('PayPal Refund Transaction ID: %s', 'give'), $data['txn_id']));
    give_update_payment_status($payment_id, 'refunded');
}
Exemple #18
0
/**
 * Sale Notification Template Body
 *
 * @since  1.0
 *
 * @param int   $payment_id   Payment ID
 * @param array $payment_data Payment Data
 *
 * @return string $email_body Body of the email
 */
function give_get_donation_notification_body_content($payment_id = 0, $payment_data = array())
{
    global $give_options;
    $user_info = maybe_unserialize($payment_data['user_info']);
    $email = give_get_payment_user_email($payment_id);
    if (isset($user_info['id']) && $user_info['id'] > 0) {
        $user_data = get_userdata($user_info['id']);
        $name = $user_data->display_name;
    } elseif (isset($user_info['first_name']) && isset($user_info['last_name'])) {
        $name = $user_info['first_name'] . ' ' . $user_info['last_name'];
    } else {
        $name = $email;
    }
    $gateway = give_get_gateway_admin_label(get_post_meta($payment_id, '_give_payment_gateway', true));
    $default_email_body = __('Hello', 'give') . "\n\n" . __('A donation has been made', 'give') . ".\n\n";
    $default_email_body .= sprintf(__('%s sold:', 'give'), give_get_forms_label_plural()) . "\n\n";
    $default_email_body .= __('Donor: ', 'give') . " " . html_entity_decode($name, ENT_COMPAT, 'UTF-8') . "\n";
    $default_email_body .= __('Amount: ', 'give') . " " . html_entity_decode(give_currency_filter(give_format_amount(give_get_payment_amount($payment_id))), ENT_COMPAT, 'UTF-8') . "\n";
    $default_email_body .= __('Payment Method: ', 'give') . " " . $gateway . "\n\n";
    $default_email_body .= __('Thank you', 'give');
    $email = isset($give_options['donation_notification']) ? stripslashes($give_options['donation_notification']) : $default_email_body;
    $email_body = give_do_email_tags($email, $payment_id);
    return apply_filters('give_donation_notification', wpautop($email_body), $payment_id, $payment_data);
}
 /**
  * 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 #20
0
/**
 * Send Offline Donation Admin Notice
 *
 * @description Sends a notice to site admins about the pending donation
 *
 * @since       1.0
 *
 * @param int $payment_id
 *
 * @return void
 *
 */
function give_offline_send_admin_notice($payment_id = 0)
{
    /* Send an email notification to the admin */
    $admin_email = give_get_admin_notice_emails();
    $user_info = give_get_payment_meta_user_info($payment_id);
    if (isset($user_info['id']) && $user_info['id'] > 0) {
        $user_data = get_userdata($user_info['id']);
        $name = $user_data->display_name;
    } elseif (isset($user_info['first_name']) && isset($user_info['last_name'])) {
        $name = $user_info['first_name'] . ' ' . $user_info['last_name'];
    } else {
        $name = $user_info['email'];
    }
    $amount = give_currency_filter(give_format_amount(give_get_payment_amount($payment_id)));
    $admin_subject = apply_filters('give_offline_admin_donation_notification_subject', __('New Pending Donation', 'give'), $payment_id);
    $admin_message = __('Dear Admin,', 'give') . "\n\n" . __('An offline donation has been made', 'give') . ".\n\n";
    $order_url = admin_url('edit.php?post_type=give_forms&page=give-payment-history&view=view-order-details&id=' . $payment_id);
    $admin_message .= __('Donor: ', 'give') . " " . html_entity_decode($name, ENT_COMPAT, 'UTF-8') . "\n";
    $admin_message .= __('Amount: ', 'give') . " " . html_entity_decode($amount, ENT_COMPAT, 'UTF-8') . "\n\n";
    $admin_message .= __('There is a new pending donation awaiting payment. Donation instructions have been emailed to the donor. Once you receive payment, be sure to mark the donation as complete using the link below.', 'give') . "\n\n";
    $admin_message .= sprintf(__('View Donation Details: %s.', 'give'), $order_url) . "\n\n";
    $admin_message = apply_filters('give_offline_admin_donation_notification', $admin_message, $payment_id);
    $admin_headers = apply_filters('give_offline_admin_donation_notification_headers', array(), $payment_id);
    $attachments = apply_filters('give_offline_admin_donation_notification_attachments', array(), $payment_id);
    wp_mail($admin_email, $admin_subject, $admin_message, $admin_headers, $attachments);
}
Exemple #21
0
/**
 *
 * Process the payment details edit
 *
 * @access      private
 *
 * @param $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(__('You do not have permission to edit this payment record', 'give'), __('Error', 'give'), array('response' => 403));
    }
    check_admin_referer('give_update_payment_details_nonce');
    // Retrieve the payment ID
    $payment_id = absint($data['give_payment_id']);
    // Retrieve existing payment meta
    $meta = give_get_payment_meta($payment_id);
    $user_info = give_get_payment_meta_user_info($payment_id);
    $status = $data['give-payment-status'];
    $user_id = isset($data['give-payment-user-id']) ? intval($data['give-payment-user-id']) : '';
    $date = sanitize_text_field($data['give-payment-date']);
    $hour = sanitize_text_field($data['give-payment-time-hour']);
    $form_id = give_get_payment_form_id($payment_id);
    // 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]);
    $date = date('Y-m-d', strtotime($date)) . ' ' . $hour . ':' . $minute . ':00';
    $curr_total = give_sanitize_amount(give_get_payment_amount($payment_id));
    $new_total = give_sanitize_amount($_POST['give-payment-total']);
    $curr_customer_id = sanitize_text_field($data['give-current-customer']);
    $new_customer_id = sanitize_text_field($data['customer-id']);
    do_action('give_update_edited_purchase', $payment_id);
    // Update main payment record
    $updated = wp_update_post(array('ID' => $payment_id, 'edit_date' => true, 'post_date' => $date));
    if (0 === $updated) {
        wp_die(esc_attr__('Error Updating Payment', 'give'), esc_attr__('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_attr__('New Customers require a name and email address', 'give'));
        }
        $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 customer, assume the previous customer
                $customer_changed = false;
                $customer = new Give_Customer($curr_customer_id);
                give_set_error('give-payment-new-customer-fail', __('Error creating new customer', '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 purchase was completed and not ever refunded, adjust stats of customers
        if ('revoked' == $status || 'publish' == $status) {
            $previous_customer->decrease_purchase_count();
            $previous_customer->decrease_value($new_total);
            $customer->increase_purchase_count();
            $customer->increase_value($new_total);
        }
        update_post_meta($payment_id, '_give_payment_customer_id', $customer->id);
    }
    // Set new meta values
    $user_info['id'] = $customer->user_id;
    $user_info['email'] = $customer->email;
    $user_info['first_name'] = $first_name;
    $user_info['last_name'] = $last_name;
    $user_info['address'] = $address;
    $meta['user_info'] = $user_info;
    // 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
    give_update_payment_status($payment_id, $status);
    give_update_payment_meta($payment_id, '_give_payment_user_id', $customer->user_id);
    give_update_payment_meta($payment_id, '_give_payment_user_email', $customer->email);
    give_update_payment_meta($payment_id, '_give_payment_meta', $meta);
    give_update_payment_meta($payment_id, '_give_payment_total', $new_total);
    // Adjust total store earnings if the payment total has been changed
    if ($new_total !== $curr_total && ('publish' == $status || 'revoked' == $status)) {
        if ($new_total > $curr_total) {
            // Increase if our new total is higher
            $difference = $new_total - $curr_total;
            give_increase_total_earnings($difference);
            $form = new Give_Donate_Form($form_id);
            $form->increase_earnings($difference);
        } elseif ($curr_total > $new_total) {
            // Decrease if our new total is lower
            $difference = $curr_total - $new_total;
            give_decrease_total_earnings($difference);
            $form = new Give_Donate_Form($form_id);
            $form->decrease_earnings($difference);
        }
    }
    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;
}
function x_donation_by_user_id($user_id)
{
    $donations = give_get_users_purchases($user_id, 20, true, 'any');
    $doanttion_per_user[0] = 0;
    if ($donations) {
        foreach ($donations as $post) {
            setup_postdata($post);
            $doanttion_per_user[] = give_get_payment_amount($post->ID);
        }
        wp_reset_postdata();
    }
    return array_sum($doanttion_per_user);
}
 /**
  * Gets the log entries for the current view
  *
  * @access public
  * @since  1.0
  * @global object $give_logs Give Logs Object
  * @return array $logs_data Array of all the Log entires
  */
 public function get_logs()
 {
     global $give_logs;
     // Prevent the queries from getting cached. Without this there are occasional memory issues for some installs
     wp_suspend_cache_addition(true);
     $logs_data = array();
     $paged = $this->get_paged();
     $give_form = empty($_GET['s']) ? $this->get_filtered_give_form() : null;
     $user = $this->get_filtered_user();
     $log_query = array('post_parent' => $give_form, 'log_type' => 'sale', 'paged' => $paged, 'meta_query' => $this->get_meta_query());
     $logs = $give_logs->get_connected_logs($log_query);
     if ($logs) {
         foreach ($logs as $log) {
             $payment_id = get_post_meta($log->ID, '_give_log_payment_id', true);
             // Make sure this payment hasn't been deleted
             if (get_post($payment_id)) {
                 $user_info = give_get_payment_meta_user_info($payment_id);
                 $payment_meta = give_get_payment_meta($payment_id);
                 $payment_amount = give_get_payment_amount($payment_id);
                 $logs_data[] = array('ID' => '<span class="give-item-label give-item-label-gray">' . $log->ID . '</span>', 'payment_id' => $payment_id, 'form' => $log->post_parent, 'amount' => $payment_amount, 'user_id' => $user_info['id'], 'user_name' => $user_info['first_name'] . ' ' . $user_info['last_name'], 'date' => get_post_field('post_date', $payment_id));
             }
         }
     }
     return $logs_data;
 }
 /**
  * Remove a payment from this customer, then triggers reducing stats
  *
  * @since  1.0
  *
  * @param  integer $payment_id   The Payment ID to remove
  * @param  bool    $update_stats For backwards compatibility, if we should increase the stats or not
  *
  * @return boolean             If the removal was successful
  */
 public function remove_payment($payment_id = 0, $update_stats = true)
 {
     if (empty($payment_id)) {
         return false;
     }
     $new_payment_ids = '';
     if (!empty($this->payment_ids)) {
         $payment_ids = array_map('absint', explode(',', $this->payment_ids));
         $pos = array_search($payment_id, $payment_ids);
         if (false === $pos) {
             return false;
         }
         unset($payment_ids[$pos]);
         $payment_ids = array_filter($payment_ids);
         $new_payment_ids = implode(',', array_unique(array_values($payment_ids)));
     }
     do_action('give_customer_pre_remove_payment', $payment_id, $this->id);
     $payment_removed = $this->update(array('payment_ids' => $new_payment_ids));
     if ($payment_removed) {
         $this->payment_ids = $new_payment_ids;
         if ($update_stats) {
             // We removed this payment successfully, decrement the stats
             $payment_amount = give_get_payment_amount($payment_id);
             if (!empty($payment_amount)) {
                 $this->decrease_value($payment_amount);
             }
             $this->decrease_purchase_count();
         }
     }
     do_action('give_customer_post_remove_payment', $payment_removed, $payment_id, $this->id);
     return $payment_removed;
 }
 /**
  * Get items
  *
  * @see Pronamic_Pay_PaymentDataInterface::get_items()
  * @return Pronamic_IDeal_Items
  */
 public function get_items()
 {
     // Items
     $items = new Pronamic_IDeal_Items();
     // Item
     // We only add one total item, because iDEAL cant work with negative price items (discount)
     $item = new Pronamic_IDeal_Item();
     $item->setNumber($this->get_order_id());
     $item->setDescription($this->get_description());
     // @see http://plugins.trac.wordpress.org/browser/woocommerce/tags/1.5.2.1/classes/class-wc-order.php#L50
     $item->setPrice(give_get_payment_amount($this->donation_id));
     $item->setQuantity(1);
     $items->addItem($item);
     return $items;
 }