/**
  * Get the data being exported
  *
  * @access      public
  * @since       1.2
  * @return      array
  */
 public function get_data()
 {
     global $edd_logs;
     $data = array();
     $args = array('nopaging' => true, 'post_type' => 'edd_payment', 'meta_key' => '_edd_payment_shipping_status', 'meta_value' => '1', 'fields' => 'ids');
     $payments = get_posts($args);
     if ($payments) {
         foreach ($payments as $payment) {
             $user_info = edd_get_payment_meta_user_info($payment);
             $downloads = edd_get_payment_meta_cart_details($payment);
             $products = '';
             if ($downloads) {
                 foreach ($downloads as $key => $download) {
                     // Display the Downoad Name
                     $products .= get_the_title($download['id']);
                     if ($key != count($downloads) - 1) {
                         $products .= ' / ';
                     }
                 }
             }
             $data[] = array('id' => $payment, 'date' => get_post_field('post_date', $payment), 'first_name' => $user_info['first_name'], 'last_name' => $user_info['last_name'], 'email' => $user_info['email'], 'address' => $user_info['shipping_info']['address'], 'address2' => !empty($user_info['shipping_info']['address2']) ? $user_info['shipping_info']['address2'] : '', 'city' => $user_info['shipping_info']['city'], 'state' => $user_info['shipping_info']['state'], 'zip' => $user_info['shipping_info']['zip'], 'country' => $user_info['shipping_info']['country'], 'amount' => edd_get_payment_amount($payment), 'tax' => edd_get_payment_tax($payment), 'gateway' => edd_get_payment_gateway($payment), 'key' => edd_get_payment_key($payment), 'products' => $products, 'status' => get_post_field('post_status', $payment));
         }
     }
     $data = apply_filters('edd_export_get_data', $data);
     $data = apply_filters('edd_export_get_data_' . $this->export_type, $data);
     return $data;
 }
function ck_edd_user_download_button($purchase_form, $args)
{
    global $edd_options;
    if (!is_user_logged_in()) {
        return $purchase_form;
    }
    $download_id = (string) $args['download_id'];
    $current_user_id = get_current_user_id();
    // If the user has purchased this item, itterate through their purchases to get the specific
    // purchase data and pull out the key and email associated with it. This is necessary for the
    // generation of the download link
    if (edd_has_user_purchased($current_user_id, $download_id, $variable_price_id = null)) {
        $user_purchases = edd_get_users_purchases($current_user_id, -1, false, 'complete');
        foreach ($user_purchases as $purchase) {
            $cart_items = edd_get_payment_meta_cart_details($purchase->ID);
            $item_ids = wp_list_pluck($cart_items, 'id');
            if (in_array($download_id, $item_ids)) {
                $email = edd_get_payment_user_email($purchase->ID);
                $payment_key = edd_get_payment_key($purchase->ID);
            }
        }
        $download_ids = array();
        if (edd_is_bundled_product($download_id)) {
            $download_ids = edd_get_bundled_products($download_id);
        } else {
            $download_ids[] = $download_id;
        }
        // Setup the style and colors associated with the settings
        $style = isset($edd_options['button_style']) ? $edd_options['button_style'] : 'button';
        $color = isset($edd_options['checkout_color']) ? $edd_options['checkout_color'] : 'blue';
        $new_purchase_form = '';
        foreach ($download_ids as $item) {
            // Attempt to get the file data associated with this download
            $download_data = edd_get_download_files($item, null);
            if ($download_data) {
                foreach ($download_data as $filekey => $file) {
                    // Generate the file URL and then make a link to it
                    $file_url = edd_get_download_file_url($payment_key, $email, $filekey, $item, null);
                    $new_purchase_form .= '<a href="' . $file_url . '" class="' . $style . ' ' . $color . ' edd-submit"><span class="edd-add-to-cart-label">Download ' . $file['name'] . '</span></a>&nbsp;';
                }
            }
            // As long as we ended up with links to show, use them.
            if (!empty($new_purchase_form)) {
                $purchase_form = '<h4>' . __('You already own this product. Download it now:', 'edd') . '</h4>' . $new_purchase_form;
            }
        }
    }
    return $purchase_form;
}
Exemple #3
0
 /**
  * Sets attendee data on order posts
  *
  * @since 4.1
  *
  * @param int $order_id EDD Order ID
  * @param array $post_data Data submitted via POST during checkout
  */
 public function save_attendee_meta_to_order($order_id, $post_data)
 {
     $order_items = edd_get_payment_meta_cart_details($order_id);
     // Bail if the order is empty
     if (empty($order_items)) {
         return;
     }
     $product_ids = array();
     // gather product ids
     foreach ((array) $order_items as $item) {
         if (empty($item['id'])) {
             continue;
         }
         $product_ids[] = $item['id'];
     }
     $meta_object = Tribe__Tickets_Plus__Main::instance()->meta();
     // build the custom meta data that will be stored in the order meta
     if (!($order_meta = $meta_object->build_order_meta($product_ids))) {
         return;
     }
     // store the custom meta on the order
     update_post_meta($order_id, Tribe__Tickets_Plus__Meta::META_KEY, $order_meta, true);
     // clear out product custom meta data cookies
     foreach ($product_ids as $product_id) {
         $meta_object->clear_meta_cookie_data($product_id);
     }
 }
/**
 * Resend the Email Purchase Receipt. (This can be done from the Payment History page)
 *
 * @since 1.0
 * @param array $data Payment Data
 * @return void
 */
function edd_resend_purchase_receipt($data)
{
    $purchase_id = absint($data['purchase_id']);
    if (empty($purchase_id)) {
        return;
    }
    if (!current_user_can('edit_shop_payments')) {
        wp_die(__('You do not have permission to edit this payment record', 'easy-digital-downloads'), __('Error', 'easy-digital-downloads'), array('response' => 403));
    }
    $email = !empty($_GET['email']) ? sanitize_text_field($_GET['email']) : '';
    if (empty($email)) {
        $customer = new EDD_Customer(edd_get_payment_customer_id($purchase_id));
        $email = $customer->email;
    }
    edd_email_purchase_receipt($purchase_id, false, $email);
    // Grab all downloads of the purchase and update their file download limits, if needed
    // This allows admins to resend purchase receipts to grant additional file downloads
    $downloads = edd_get_payment_meta_cart_details($purchase_id, true);
    if (is_array($downloads)) {
        foreach ($downloads as $download) {
            $limit = edd_get_file_download_limit($download['id']);
            if (!empty($limit)) {
                edd_set_file_download_limit_override($download['id'], $purchase_id);
            }
        }
    }
    wp_redirect(add_query_arg(array('edd-message' => 'email_sent', 'edd-action' => false, 'purchase_id' => false)));
    exit;
}
function pw_edd_sl_license_length($expiration, $payment_id, $download_id, $license_id)
{
    $purchase_details = edd_get_payment_meta_cart_details($payment_id);
    $price_id = false;
    foreach ($purchase_details as $item) {
        if ((int) $item['id'] === (int) $download_id) {
            if (!empty($item['item_number']['options'])) {
                foreach ($item['item_number']['options'] as $option) {
                    $price_id = (int) $option['price_id'];
                }
            }
        }
    }
    if ($price_id !== false) {
        switch ($price_id) {
            case 0:
                $expiration = '+10 years';
                break;
            case 1:
                $expiration = '+2 years';
                break;
            case 2:
                $expiration = '+1 year';
                break;
        }
    }
    return $expiration;
}
 /**
  * Get the Export Data
  *
  * @access public
  * @since 1.4.4
  * @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, $edd_options;
     $data = array();
     $payments = edd_get_payments(array('offset' => 0, 'number' => -1, 'mode' => edd_is_test_mode() ? 'test' : 'live', 'status' => isset($_POST['edd_export_payment_status']) ? $_POST['edd_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 = edd_get_payment_meta($payment->ID);
         $user_info = edd_get_payment_meta_user_info($payment->ID);
         $downloads = edd_get_payment_meta_cart_details($payment->ID);
         $total = isset($payment_meta['amount']) ? $payment_meta['amount'] : 0.0;
         $user_id = isset($user_info['id']) && $user_info['id'] != -1 ? $user_info['id'] : $user_info['email'];
         $products = '';
         $skus = '';
         if ($downloads) {
             foreach ($downloads as $key => $download) {
                 // Download ID
                 $id = isset($payment_meta['cart_details']) ? $download['id'] : $download;
                 // If the download has variable prices, override the default price
                 $price_override = isset($payment_meta['cart_details']) ? $download['price'] : null;
                 $price = edd_get_download_final_price($id, $user_info, $price_override);
                 // Display the Downoad Name
                 $products .= get_the_title($id) . ' - ';
                 if (edd_use_skus()) {
                     $sku = edd_get_download_sku($id);
                     if (!empty($sku)) {
                         $skus .= $sku;
                     }
                 }
                 if (isset($downloads[$key]['item_number']) && isset($downloads[$key]['item_number']['options'])) {
                     $price_options = $downloads[$key]['item_number']['options'];
                     if (isset($price_options['price_id'])) {
                         $products .= edd_get_price_option_name($id, $price_options['price_id']) . ' - ';
                     }
                 }
                 $products .= html_entity_decode(edd_currency_filter($price));
                 if ($key != count($downloads) - 1) {
                     $products .= ' / ';
                     if (edd_use_skus()) {
                         $skus .= ' / ';
                     }
                 }
             }
         }
         if (is_numeric($user_id)) {
             $user = get_userdata($user_id);
         } else {
             $user = false;
         }
         $data[] = array('id' => $payment->ID, 'email' => $payment_meta['email'], 'first' => $user_info['first_name'], 'last' => $user_info['last_name'], 'products' => $products, 'skus' => $skus, 'amount' => html_entity_decode(edd_format_amount($total)), 'tax' => html_entity_decode(edd_get_payment_tax($payment->ID, $payment_meta)), 'discount' => isset($user_info['discount']) && $user_info['discount'] != 'none' ? $user_info['discount'] : __('none', 'edd'), 'gateway' => edd_get_gateway_admin_label(get_post_meta($payment->ID, '_edd_payment_gateway', true)), 'key' => $payment_meta['key'], 'date' => $payment->post_date, 'user' => $user ? $user->display_name : __('guest', 'edd'), 'status' => edd_get_payment_status($payment, true));
         if (!edd_use_skus()) {
             unset($data['skus']);
         }
     }
     $data = apply_filters('edd_export_get_data', $data);
     $data = apply_filters('edd_export_get_data_' . $this->export_type, $data);
     return $data;
 }
 public function render_tag_content($payment_id = 0)
 {
     $output = '';
     $cart_items = edd_get_payment_meta_cart_details($payment_id, true);
     foreach ($cart_items as $item) {
         // do something to $output for each cart item
     }
     return $output;
 }
 /**
  * Get the Export Data
  *
  * @access public
  * @since 2.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 $edd_logs, $wpdb;
     $accepted_statuses = apply_filters('edd_recount_accepted_statuses', array('publish', 'revoked'));
     if ($this->step == 1) {
         $this->delete_data('edd_temp_recount_download_stats');
     }
     $totals = $this->get_stored_data('edd_temp_recount_download_stats');
     if (false === $totals) {
         $totals = array('earnings' => (double) 0, 'sales' => 0);
         $this->store_data('edd_temp_recount_download_stats', $totals);
     }
     $args = apply_filters('edd_recount_download_stats_args', array('post_parent' => $this->download_id, 'post_type' => 'edd_log', 'posts_per_page' => $this->per_step, 'post_status' => 'publish', 'paged' => $this->step, 'log_type' => 'sale', 'fields' => 'ids'));
     $log_ids = $edd_logs->get_connected_logs($args, 'sale');
     $this->_log_ids_debug = array();
     if ($log_ids) {
         $log_ids = implode(',', $log_ids);
         $payment_ids = $wpdb->get_col("SELECT meta_value FROM {$wpdb->postmeta} WHERE meta_key='_edd_log_payment_id' AND post_id IN ({$log_ids})");
         unset($log_ids);
         $payment_ids = implode(',', $payment_ids);
         $payments = $wpdb->get_results("SELECT ID, post_status FROM {$wpdb->posts} WHERE ID IN (" . $payment_ids . ")");
         unset($payment_ids);
         foreach ($payments as $payment) {
             if (!in_array($payment->post_status, $accepted_statuses)) {
                 continue;
             }
             $items = edd_get_payment_meta_cart_details($payment->ID);
             foreach ($items as $item) {
                 if ($item['id'] != $this->download_id) {
                     continue;
                 }
                 $this->_log_ids_debug[] = $payment->ID;
                 $amount = $item['price'];
                 if (!empty($item['fees'])) {
                     foreach ($item['fees'] as $fee) {
                         // Only let negative fees affect earnings
                         if ($fee['amount'] > 0) {
                             continue;
                         }
                         $amount += $fee['amount'];
                     }
                 }
                 $totals['sales']++;
                 $totals['earnings'] += $amount;
             }
         }
         $this->store_data('edd_temp_recount_download_stats', $totals);
         return true;
     }
     update_post_meta($this->download_id, '_edd_download_sales', $totals['sales']);
     update_post_meta($this->download_id, '_edd_download_earnings', $totals['earnings']);
     return false;
 }
Exemple #9
0
/**
 * Maybe log a recommendation sale
 * Iterates through items in the payment and if one is a recommendation logs it
 *
 * @since  1.2.6
 * @param  int $payment_id The Payment ID being completed
 * @return void
 */
function edd_rp_log_recommendation_sale($payment_id)
{
    $payment_items = edd_get_payment_meta_cart_details($payment_id, true);
    foreach ($payment_items as $item) {
        if (!empty($item['item_number']['recommendation_source'])) {
            $edd_log = new EDD_Logging();
            $log_data = array('post_parent' => $item['item_number']['recommendation_source'], 'post_date' => edd_get_payment_completed_date($payment_id), 'log_type' => 'recommendation_sale');
            $log_meta = array('payment_id' => $payment_id, 'download_id' => $item['id'], 'price' => $item['price'], 'quantity' => $item['quantity'], 'item_price' => $item['item_price']);
            $log_entry = $edd_log->insert_log($log_data, $log_meta);
        }
    }
}
 /**
  * Add points for purchase
  * 
  * Handles to add points for purchases
  *
  * @package Easy Digital Downloads - Points and Rewards
  * @since 1.0.0
  */
 public function edd_points_add_point_for_complete_purchase($payment_id)
 {
     global $edd_options, $current_user;
     //get payment data
     $paymentdata = edd_get_payment_meta($payment_id);
     $userdata = edd_get_payment_meta_user_info($payment_id);
     $user_id = isset($userdata['id']) && !empty($userdata['id']) ? $userdata['id'] : 0;
     //get discount towards points
     $gotdiscount = $this->model->edd_points_get_payment_discount($payment_id);
     //check user has redeemed points or not & user_id should not empty
     if (isset($gotdiscount) && !empty($gotdiscount) && !empty($user_id)) {
         //get discounte price from points
         $discountedpoints = $this->model->edd_points_calculate_points($gotdiscount);
         //update user points
         edd_points_minus_points_from_user($discountedpoints, $user_id);
         //points label
         $pointslable = $this->model->edd_points_get_points_label($discountedpoints);
         //record data logs for redeem for purchase
         $post_data = array('post_title' => sprintf(__('Redeem %s for purchase', 'eddpoints'), $pointslable), 'post_content' => sprintf(__('%s redeemed for purchasing download by redeeming the points and get discounts.', 'eddpoints'), $pointslable), 'post_author' => $user_id);
         //log meta array
         $log_meta = array('userpoint' => $discountedpoints, 'events' => 'redeemed_purchase', 'operation' => 'minus');
         //insert entry in log
         $this->logs->edd_points_insert_logs($post_data, $log_meta);
         // set order meta, regardless of whether any points were earned, just so we know the process took place
         update_post_meta($payment_id, '_edd_points_order_redeemed', $discountedpoints);
     }
     //end if to check points redeemed taken by buyer or not
     // get cartdata from older order
     $cartdata = edd_get_payment_meta_cart_details($payment_id);
     //get bought points for points downloads types
     $boughtpoints = $this->model->edd_points_get_bought_points($cartdata);
     //get cart points from cartdata and payment discount given to user
     $cartpoints = $this->model->edd_points_get_user_checkout_points($cartdata, $gotdiscount);
     //add bought points to cart points
     $cartpoints = !empty($boughtpoints) ? $cartpoints + $boughtpoints : $cartpoints;
     //check checkout points earned points or user id is not empty
     if (!empty($cartpoints) && !empty($user_id)) {
         //points label
         $pointslable = $this->model->edd_points_get_points_label($cartpoints);
         //get user points after subtracting the redemption points
         $userpoints = edd_points_get_user_points();
         $post_data = array('post_title' => sprintf(__('%s earned for purchasing the downloads.', 'eddpoints'), $pointslable), 'post_content' => sprintf(__('Get %s for purchasing the downloads.', 'eddpoints'), $pointslable), 'post_author' => $user_id);
         $log_meta = array('userpoint' => $cartpoints, 'events' => 'earned_purchase', 'operation' => 'add');
         //insert entry in log
         $this->logs->edd_points_insert_logs($post_data, $log_meta);
         //update user points
         edd_points_add_points_to_user($cartpoints, $user_id);
         // set order meta, regardless of whether any points were earned, just so we know the process took place
         update_post_meta($payment_id, '_edd_points_order_earned', $cartpoints);
     }
     //end if to check checkout points should not empty
 }
 /**
  * Get the data being exported
  *
  * @return array $data
  */
 public function get_data()
 {
     global $wpdb;
     $data = array();
     $campaign = $this->campaign;
     $campaign = atcf_get_campaign($campaign);
     $backers = $campaign->backers();
     if (empty($backers)) {
         return $data;
     }
     foreach ($backers as $log) {
         $payment_id = get_post_meta($log->ID, '_edd_log_payment_id', true);
         $payment = get_post($payment_id);
         $payment_meta = edd_get_payment_meta($payment_id);
         $user_info = edd_get_payment_meta_user_info($payment_id);
         $downloads = edd_get_payment_meta_cart_details($payment_id);
         $total = edd_get_payment_amount($payment_id);
         $user_id = isset($user_info['id']) && $user_info['id'] != -1 ? $user_info['id'] : $user_info['email'];
         $products = '';
         if ($downloads) {
             foreach ($downloads as $key => $download) {
                 // Download ID
                 $id = isset($payment_meta['cart_details']) ? $download['id'] : $download;
                 // If the download has variable prices, override the default price
                 $price_override = isset($payment_meta['cart_details']) ? $download['price'] : null;
                 $price = edd_get_download_final_price($id, $user_info, $price_override);
                 // Display the Downoad Name
                 $products .= get_the_title($id) . ' - ';
                 if (isset($downloads[$key]['item_number'])) {
                     $price_options = $downloads[$key]['item_number']['options'];
                     if (isset($price_options['price_id'])) {
                         $products .= edd_get_price_option_name($id, $price_options['price_id']) . ' - ';
                     }
                 }
                 $products .= html_entity_decode(edd_currency_filter($price));
                 if ($key != count($downloads) - 1) {
                     $products .= ' / ';
                 }
             }
         }
         if (is_numeric($user_id)) {
             $user = get_userdata($user_id);
         } else {
             $user = false;
         }
         $shipping = isset($payment_meta['shipping']) ? $payment_meta['shipping'] : null;
         $data[] = apply_filters('atcf_csv_cols_values', array('id' => $payment_id, 'email' => $payment_meta['email'], 'first' => $user_info['first_name'], 'last' => $user_info['last_name'], 'shipping' => isset($shipping) ? implode("\n", $shipping) : '', 'products' => $products, 'amount' => html_entity_decode(edd_currency_filter(edd_format_amount($total))), 'tax' => html_entity_decode(edd_payment_tax($payment_id, $payment_meta)), 'discount' => isset($user_info['discount']) && $user_info['discount'] != 'none' ? $user_info['discount'] : __('none', 'atcf'), 'gateway' => edd_get_gateway_admin_label(get_post_meta($payment_id, '_edd_payment_gateway', true)), 'key' => $payment_meta['key'], 'date' => date_i18n(get_option('date_format'), strtotime($payment->post_date)), 'user' => $user ? $user->display_name : __('guest', 'atcf'), 'status' => edd_get_payment_status($payment, true)), $payment_id);
     }
     $data = apply_filters('edd_export_get_data', $data);
     $data = apply_filters('edd_export_get_data_' . $this->export_type, $data);
     return $data;
 }
Exemple #12
0
 function wplms_edd_completed_purchase($payment_id, $new_status, $old_status)
 {
     if ($old_status == 'publish' || $old_status == 'complete') {
         return;
     }
     // Make sure that payments are only completed once
     // Make sure the payment completion is only processed when new status is complete
     if ($new_status != 'publish' && $new_status != 'complete') {
         return;
     }
     $user_id = get_current_user_id();
     $cart_items = edd_get_payment_meta_cart_details($payment_id);
     foreach ($cart_items as $key => $cart_item) {
         $item_id = isset($cart_item['id']) ? $cart_item['id'] : $cart_item;
         if (is_numeric($item_id) && get_post_type($item_id) == 'download') {
             $courses = vibe_sanitize(get_post_meta($item_id, 'vibe_courses', false));
             $subscribed = get_post_meta($product_id, 'vibe_subscription', true);
             if (vibe_validate($subscribed)) {
                 $duration = get_post_meta($product_id, 'vibe_duration', true);
                 $product_duration_parameter = apply_filters('vibe_product_duration_parameter', 86400);
                 // Product duration for subscription based
                 $t = time() + $duration * $product_duration_parameter;
                 foreach ($courses as $course) {
                     update_post_meta($course, $user_id, 0);
                     update_user_meta($user_id, $course, $t);
                     $group_id = get_post_meta($course, 'vibe_group', true);
                     if (isset($group_id) && $group_id != '') {
                         groups_join_group($group_id, $user_id);
                     }
                     bp_course_record_activity(array('action' => __('Student subscribed for course ', 'vibe') . get_the_title($course), 'content' => __('Student ', 'vibe') . bp_core_get_userlink($user_id) . __(' subscribed for course ', 'vibe') . get_the_title($course) . __(' for ', 'vibe') . $duration . __(' days', 'vibe'), 'type' => 'subscribe_course', 'item_id' => $course, 'primary_link' => get_permalink($course), 'secondary_item_id' => $user_id));
                 }
             } else {
                 if (isset($courses) && is_array($courses)) {
                     foreach ($courses as $course) {
                         $duration = get_post_meta($course, 'vibe_duration', true);
                         $course_duration_parameter = apply_filters('vibe_course_duration_parameter', 86400);
                         // Course duration for subscription based
                         $t = time() + $duration * $course_duration_parameter;
                         update_post_meta($course, $user_id, 0);
                         update_user_meta($user_id, $course, $t);
                         $group_id = get_post_meta($course, 'vibe_group', true);
                         if (isset($group_id) && $group_id != '') {
                             groups_join_group($group_id, $user_id);
                         }
                         bp_course_record_activity(array('action' => __('Student subscribed for course ', 'vibe') . get_the_title($course), 'content' => __('Student ', 'vibe') . bp_core_get_userlink($user_id) . __(' subscribed for course ', 'vibe') . get_the_title($course) . __(' for ', 'vibe') . $duration . __(' days', 'vibe'), 'type' => 'subscribe_course', 'item_id' => $course, 'primary_link' => get_permalink($course), 'secondary_item_id' => $user_id));
                     }
                 }
             }
         }
     }
 }
/**
 * The {downloads} email tag
 */
function sumobi_edd_email_tag_downloads($payment_id)
{
    $cart_items = edd_get_payment_meta_cart_details($payment_id);
    $download_list = '<ul>';
    if ($cart_items) {
        foreach ($cart_items as $item) {
            $title = sprintf('<a href="%s">%s</a>', get_permalink($item['id']), get_the_title($item['id']));
            $download_list .= '<li>' . $title . '<br/>';
            $download_list .= '</li>';
        }
    }
    $download_list .= '</ul>';
    return $download_list;
}
function pw_edd_sl_license_at_limit($ret = false, $license_id = 0, $limit = 0, $download_id = 0)
{
    $purchase_id = get_post_meta($license_id, '_edd_sl_payment_id', true);
    $purchase_date = new DateTime(get_post_field('post_date', $purchase_id));
    $limit_date = new DateTime('2013-01-01');
    if ($purchase_date < $limit_date) {
        // licenses purchased before January 1, 2013 are unlimited
        return false;
    }
    $purchase_details = edd_get_payment_meta_cart_details($purchase_id);
    $price_id = false;
    foreach ($purchase_details as $item) {
        if ($item['id'] == $download_id) {
            if (!empty($item['item_number']['options'])) {
                foreach ($item['item_number']['options'] as $option) {
                    $price_id = (int) $option['price_id'];
                }
            }
        }
    }
    if ($price_id !== false) {
        switch ($price_id) {
            case 0:
                $limit = 1;
                // single site license
                break;
            case 1:
                $limit = 5;
                // up to 5 sites
                break;
            case 2:
                $limit = 0;
                // unlimited
                break;
        }
        $site_count = absint(get_post_meta($license_id, '_edd_sl_site_count', true));
        // check to make sure a limit is in place
        if ($limit > 0) {
            if ($site_count >= absint($limit)) {
                $ret = true;
                // license is at limit
            }
        }
    }
    return $ret;
}
/**
 * Payment actions
 *
 * @since 1.1
*/
function edd_csau_payment_actions($payment_id)
{
    $cart_details = edd_get_payment_meta_cart_details($payment_id);
    if (is_array($cart_details)) {
        // Increase purchase count and earnings
        foreach ($cart_details as $download) {
            // "bundle" or "default"
            $download_type = edd_get_download_type($download['id']);
            $price_id = isset($download['options']['price_id']) ? (int) $download['options']['price_id'] : false;
            // Increase earnings, and fire actions once per quantity number
            for ($i = 0; $i < $download['quantity']; $i++) {
                if (!edd_is_test_mode() || apply_filters('edd_log_test_payment_stats', false)) {
                    if (isset($download['item_number']['cross_sell'])) {
                        $type = 'cross_sell';
                    } elseif (isset($download['item_number']['upsell'])) {
                        $type = 'upsell';
                    } else {
                        $type = null;
                    }
                    if ($type) {
                        edd_csau_increase_purchase_count($download['id'], $type);
                        edd_csau_increase_earnings($download['id'], $download['price'], $type);
                        edd_csau_record_sale_in_log($download['id'], $payment_id, $price_id, $type);
                    }
                }
                $types[] = $type;
                $types = array_unique(array_filter($types));
            }
        }
        // Clear the total earnings cache
        delete_transient('edd_' . $type . '_earnings_total');
    }
    if ($types) {
        foreach ($types as $type) {
            // store the total amount of cross-sell earnings
            update_post_meta($payment_id, '_edd_payment_' . $type . '_total', edd_csau_calculate_sales($payment_id, $type));
            $amount = edd_csau_get_payment_amount($payment_id, $type);
            // increase earnings
            edd_csau_increase_total_earnings($amount, $type);
        }
    }
}
Exemple #16
0
 function eddThankYou($payment, $edd_receipt_args = NULL)
 {
     global $tcm;
     $tcm->Log->debug('Ecommerce: EDD THANKYOU');
     $tcm->Log->debug('Ecommerce: NEW EDD ORDERID=%s', $payment->ID);
     $cart = edd_get_payment_meta_cart_details($payment->ID, TRUE);
     $productsIds = array();
     foreach ($cart as $key => $item) {
         if (isset($item['id'])) {
             $k = intval($item['id']);
             if ($k) {
                 $v = $item['name'];
                 $productsIds[] = $k;
                 $tcm->Log->debug('Ecommerce: ITEM %s=%s IN CART', $k, $v);
             }
         }
     }
     $args = array('pluginId' => TCM_PLUGINS_EDD, 'productsIds' => $productsIds, 'categoriesIds' => array(), 'tagsIds' => array());
     $tcm->Options->pushConversionSnippets($args);
 }
/**
 * Resend the Email Purchase Receipt. (This can be done from the Payment History page)
 *
 * @since 1.0
 * @param array $data Payment Data
 * @return void
 */
function edd_resend_purchase_receipt($data)
{
    $purchase_id = absint($data['purchase_id']);
    if (empty($purchase_id)) {
        return;
    }
    edd_email_purchase_receipt($purchase_id, false);
    // Grab all downloads of the purchase and update their file download limits, if needed
    // This allows admins to resend purchase receipts to grant additional file downloads
    $downloads = edd_get_payment_meta_cart_details($purchase_id, true);
    if (is_array($downloads)) {
        foreach ($downloads as $download) {
            $limit = edd_get_file_download_limit($download['id']);
            if (!empty($limit)) {
                edd_set_file_download_limit_override($download['id'], $purchase_id);
            }
        }
    }
    wp_redirect(add_query_arg(array('edd-message' => 'email_sent', 'edd-action' => false, 'purchase_id' => false)));
    exit;
}
 public function recount()
 {
     global $edd_logs, $wpdb;
     if (empty($_GET['post'])) {
         return;
     }
     if (!current_user_can('edit_products')) {
         wp_die('Cheating');
     }
     $download_id = absint($_GET['post']);
     if (!get_post($download_id)) {
         return;
     }
     $args = array('post_parent' => $download_id, 'log_type' => 'sale', 'nopaging' => true, 'fields' => 'ids');
     $log_ids = $edd_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='_edd_log_payment_id' AND post_id IN ({$log_ids});");
         foreach ($payment_ids as $payment_id) {
             $items = edd_get_payment_meta_cart_details($payment_id);
             foreach ($items as $item) {
                 if ($item['id'] != $download_id) {
                     continue;
                 }
                 $earnings += $item['price'];
             }
         }
     }
     if (!empty($earnings)) {
         update_post_meta($download_id, '_edd_download_earnings', $earnings);
     }
     $args = array('action' => 'edit', 'post' => $download_id);
     $base_url = admin_url('post.php');
     wp_redirect(add_query_arg($args, $base_url));
     exit;
 }
global $edd_receipt_args;
$payment = get_post($edd_receipt_args['id']);
if (empty($payment)) {
    ?>

	<div class="edd_errors edd-alert edd-alert-error">
		<?php 
    _e('The specified receipt ID appears to be invalid', 'easy-digital-downloads');
    ?>
	</div>

<?php 
    return;
}
$meta = edd_get_payment_meta($payment->ID);
$cart = edd_get_payment_meta_cart_details($payment->ID, true);
$user = edd_get_payment_meta_user_info($payment->ID);
$email = edd_get_payment_user_email($payment->ID);
$status = edd_get_payment_status($payment, true);
?>
<table id="edd_purchase_receipt">
	<thead>
		<?php 
do_action('edd_payment_receipt_before', $payment, $edd_receipt_args);
?>

		<?php 
if ($edd_receipt_args['payment_id']) {
    ?>
		<tr>
			<th><strong><?php 
 public function pre_fetch()
 {
     global $edd_logs, $wpdb;
     if ($this->step == 1) {
         $this->delete_data('edd_temp_recount_all_total');
         $this->delete_data('edd_temp_recount_all_stats');
         $this->delete_data('edd_temp_payment_items');
         $this->delete_data('edd_temp_processed_payments');
     }
     $accepted_statuses = apply_filters('edd_recount_accepted_statuses', array('publish', 'revoked'));
     $total = $this->get_stored_data('edd_temp_recount_all_total');
     if (false === $total) {
         $total = 0;
         $payment_items = $this->get_stored_data('edd_temp_payment_items');
         if (false === $payment_items) {
             $payment_items = array();
             $this->store_data('edd_temp_payment_items', $payment_items);
         }
         $all_downloads = $this->get_stored_data('edd_temp_download_ids');
         if (false === $all_downloads) {
             $args = array('post_status' => 'any', 'post_type' => 'download', 'posts_per_page' => -1, 'fields' => 'ids');
             $all_downloads = get_posts($args);
             $this->store_data('edd_temp_download_ids', $all_downloads);
         }
         $args = apply_filters('edd_recount_download_stats_total_args', array('post_parent__in' => $all_downloads, 'post_type' => 'edd_log', 'post_status' => 'publish', 'log_type' => 'sale', 'fields' => 'ids', 'nopaging' => true));
         $all_logs = $edd_logs->get_connected_logs($args, 'sale');
         if ($all_logs) {
             $log_ids = implode(',', $all_logs);
             $payment_ids = $wpdb->get_col("SELECT meta_value FROM {$wpdb->postmeta} WHERE meta_key='_edd_log_payment_id' AND post_id IN ({$log_ids})");
             unset($log_ids);
             $payment_ids = implode(',', $payment_ids);
             $payments = $wpdb->get_results("SELECT ID, post_status FROM {$wpdb->posts} WHERE ID IN (" . $payment_ids . ")");
             unset($payment_ids);
             foreach ($payments as $payment) {
                 if (!in_array($payment->post_status, $accepted_statuses)) {
                     continue;
                 }
                 if (!array_key_exists($payment->ID, $payment_items)) {
                     $items = edd_get_payment_meta_cart_details($payment->ID);
                     $payment_items[$payment->ID] = $items;
                 }
             }
             $total = count($all_logs);
         }
         $this->store_data('edd_temp_payment_items', $payment_items);
         $this->store_data('edd_recount_all_total', $total);
     }
 }
 * @return void
*/
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
    wp_die(__('Payment ID not supplied. Please try again', 'edd'), __('Error', 'edd'));
}
// Setup the variables
$payment_id = absint($_GET['id']);
$number = edd_get_payment_number($payment_id);
$item = get_post($payment_id);
// Sanity check... fail if purchase ID is invalid
if (!is_object($item) || $item->post_type != 'edd_payment') {
    wp_die(__('The specified ID does not belong to a payment. Please try again', 'edd'), __('Error', 'edd'));
}
$payment_meta = edd_get_payment_meta($payment_id);
$transaction_id = esc_attr(edd_get_payment_transaction_id($payment_id));
$cart_items = edd_get_payment_meta_cart_details($payment_id);
$user_id = edd_get_payment_user_id($payment_id);
$customer_id = edd_get_payment_customer_id($payment_id);
$payment_date = strtotime($item->post_date);
$unlimited = edd_payment_has_unlimited_downloads($payment_id);
$user_info = edd_get_payment_meta_user_info($payment_id);
$address = !empty($user_info['address']) ? $user_info['address'] : array('line1' => '', 'line2' => '', 'city' => '', 'country' => '', 'state' => '', 'zip' => '');
$gateway = edd_get_payment_gateway($payment_id);
$currency_code = edd_get_payment_currency_code($payment_id);
?>
<div class="wrap edd-wrap">
	<h2><?php 
printf(__('Payment %s', 'edd'), $number);
?>
</h2>
	<?php 
/**
 * Verifies a download purchase using a purchase key and email.
 *
 * @deprecated Please avoid usage of this function in favor of the tokenized urls with edd_validate_url_token()
 * introduced in EDD 2.3
 *
 * @since 1.0
 *
 * @param int    $download_id
 * @param string $key
 * @param string $email
 * @param string $expire
 * @param int    $file_key
 *
 * @return bool True if payment and link was verified, false otherwise
 */
function edd_verify_download_link($download_id = 0, $key = '', $email = '', $expire = '', $file_key = 0)
{
    $meta_query = array('relation' => 'AND', array('key' => '_edd_payment_purchase_key', 'value' => $key), array('key' => '_edd_payment_user_email', 'value' => $email));
    $accepted_stati = apply_filters('edd_allowed_download_stati', array('publish', 'complete'));
    $payments = get_posts(array('meta_query' => $meta_query, 'post_type' => 'edd_payment', 'post_status' => $accepted_stati));
    if ($payments) {
        foreach ($payments as $payment) {
            $cart_details = edd_get_payment_meta_cart_details($payment->ID, true);
            if (!empty($cart_details)) {
                foreach ($cart_details as $cart_key => $cart_item) {
                    if ($cart_item['id'] != $download_id) {
                        continue;
                    }
                    $price_options = isset($cart_item['item_number']['options']) ? $cart_item['item_number']['options'] : false;
                    $price_id = isset($price_options['price_id']) ? $price_options['price_id'] : false;
                    $file_condition = edd_get_file_price_condition($cart_item['id'], $file_key);
                    // Check to see if the file download limit has been reached
                    if (edd_is_file_at_download_limit($cart_item['id'], $payment->ID, $file_key, $price_id)) {
                        wp_die(apply_filters('edd_download_limit_reached_text', __('Sorry but you have hit your download limit for this file.', 'edd')), __('Error', 'edd'), array('response' => 403));
                    }
                    // If this download has variable prices, we have to confirm that this file was included in their purchase
                    if (!empty($price_options) && $file_condition != 'all' && edd_has_variable_prices($cart_item['id'])) {
                        if ($file_condition == $price_options['price_id']) {
                            return $payment->ID;
                        }
                    }
                    // Make sure the link hasn't expired
                    if (base64_encode(base64_decode($expire, true)) === $expire) {
                        $expire = base64_decode($expire);
                        // If it is a base64 string, decode it. Old expiration dates were in base64
                    }
                    if (current_time('timestamp') > $expire) {
                        wp_die(apply_filters('edd_download_link_expired_text', __('Sorry but your download link has expired.', 'edd')), __('Error', 'edd'), array('response' => 403));
                    }
                    return $payment->ID;
                    // Payment has been verified and link is still valid
                }
            }
        }
    } else {
        wp_die(__('No payments matching your request were found.', 'edd'), __('Error', 'edd'), array('response' => 403));
    }
    // Payment not verified
    return false;
}
/**
 * Figure out the Paypal account info to send the funds to.
 *
 * @since Astoundify Crowdfunding 1.8
 *
 * @return $receivers
 */
function atcf_edap_adaptive_receivers($receivers, $payment_id)
{
    global $edd_options;
    $campaign_id = null;
    $cart_items = edd_get_payment_meta_cart_details($payment_id);
    if (!$cart_items || empty($cart_items)) {
        return $receivers;
    }
    foreach ($cart_items as $item) {
        $campaign_id = $item['id'];
        break;
    }
    if (0 == get_post($campaign_id)->ID) {
        return $receivers;
    }
    $campaign = atcf_get_campaign($campaign_id);
    return atcf_gateway_paypal_adaptive_payments_receivers($campaign);
}
/**
 * Reduces earnings and sales stats when a purchase is refunded
 *
 * @since 1.8.2
 * @param $data Arguments passed
 * @return void
 */
function edd_undo_purchase_on_refund($payment_id, $new_status, $old_status)
{
    if ('publish' != $old_status && 'revoked' != $old_status) {
        return;
    }
    if ('refunded' != $new_status) {
        return;
    }
    $downloads = edd_get_payment_meta_cart_details($payment_id);
    if ($downloads) {
        foreach ($downloads as $download) {
            edd_undo_purchase($download['id'], $payment_id);
        }
    }
    // Decrease store earnings
    $amount = edd_get_payment_amount($payment_id);
    edd_decrease_total_earnings($amount);
    // Decrement the stats for the customer
    $customer_id = edd_get_payment_customer_id($payment_id);
    if ($customer_id) {
        $customer = new EDD_Customer($customer_id);
        $customer->decrease_value($amount);
        $customer->decrease_purchase_count();
    }
    // Clear the This Month earnings (this_monththis_month is NOT a typo)
    delete_transient(md5('edd_earnings_this_monththis_month'));
}
 /**
  * Generate and store all the attendees information for a new order.
  * @param $order_id
  */
 public function generate_tickets($order_id)
 {
     // Bail if we already generated the info for this order
     $done = get_post_meta($order_id, self::$order_has_tickets, true);
     if (!empty($done)) {
         return;
     }
     $has_tickets = false;
     // Get the items purchased in this order
     $order_items = edd_get_payment_meta_cart_details($order_id);
     // Bail if the order is empty
     if (empty($order_items)) {
         return;
     }
     // Iterate over each product
     foreach ((array) $order_items as $item) {
         $product_id = isset($item['id']) ? $item['id'] : false;
         // Get the event this tickets is for
         $event_id = get_post_meta($product_id, self::$event_key, true);
         if (!empty($event_id)) {
             $has_tickets = true;
             // Iterate over all the amount of tickets purchased (for this product)
             $quantity = intval($item['quantity']);
             for ($i = 0; $i < $quantity; $i++) {
                 $attendee = array('post_status' => 'publish', 'post_title' => $order_id . ' | ' . $item['name'] . ' | ' . ($i + 1), 'post_type' => self::ATTENDEE_OBJECT, 'ping_status' => 'closed');
                 // Insert individual ticket purchased
                 $attendee_id = wp_insert_post($attendee);
                 update_post_meta($attendee_id, self::ATTENDEE_PRODUCT_KEY, $product_id);
                 update_post_meta($attendee_id, self::ATTENDEE_ORDER_KEY, $order_id);
                 update_post_meta($attendee_id, self::ATTENDEE_EVENT_KEY, $event_id);
                 update_post_meta($attendee_id, self::$security_code, $this->generate_security_code($order_id, $attendee_id));
             }
         }
     }
     if ($has_tickets) {
         update_post_meta($order_id, self::$order_has_tickets, '1');
         // Send the email to the user
         do_action('eddtickets-send-tickets-email', $order_id);
     }
 }
/**
 * Gets the download links for each item purchased
 *
 * @since 1.1.5
 * @param int $payment_id The ID of the payment to retrieve download links for
 * @return string
 */
function edd_get_purchase_download_links($payment_id = 0)
{
    $downloads = edd_get_payment_meta_cart_details($payment_id, true);
    $payment_key = edd_get_payment_key($payment_id);
    $email = edd_get_payment_user_email($payment_id);
    $links = '<ul class="edd_download_links">';
    foreach ($downloads as $download) {
        $links .= '<li>';
        $links .= '<h3 class="edd_download_link_title">' . esc_html(get_the_title($download['id'])) . '</h3>';
        $price_id = isset($download['options']) && isset($download['options']['price_id']) ? $download['options']['price_id'] : null;
        $files = edd_get_download_files($download['id'], $price_id);
        if (is_array($files)) {
            foreach ($files as $filekey => $file) {
                $links .= '<div class="edd_download_link_file">';
                $links .= '<a href="' . esc_url(edd_get_download_file_url($payment_key, $email, $filekey, $download['id'], $price_id)) . '">';
                if (isset($file['name'])) {
                    $links .= esc_html($file['name']);
                } else {
                    $links .= esc_html($file['file']);
                }
                $links .= '</a>';
                $links .= '</div>';
            }
        }
        $links .= '</li>';
    }
    $links .= '</ul>';
    return $links;
}
Exemple #27
0
 public function vendor_can_view_receipt($user_can_view, $edd_receipt_id)
 {
     if (!$edd_receipt_id) {
         return false;
     }
     $payment_id = !empty($_GET['order_id']) ? absint($_GET['order_id']) : false;
     if ($payment_id) {
         $cart = edd_get_payment_meta_cart_details($payment_id);
         foreach ($cart as $item) {
             $item = get_post($item['id']);
             if ($item->post_author == get_current_user_id()) {
                 $user_can_view = true;
                 break;
             }
         }
     }
     return $user_can_view;
 }
 /**
  * Send purchase details to MailChimp's Ecommerce360 extension.
  *
  * @param  integer $payment_id    [description]
  * @return bool
  */
 public function record_ecommerce360_purchase($payment_id = 0)
 {
     // Make sure an API key has been entered
     if (empty($this->key)) {
         return FALSE;
     }
     // Don't record details if we're in test mode
     if (edd_is_test_mode()) {
         return FALSE;
     }
     $payment = edd_get_payment_meta($payment_id);
     $user_info = edd_get_payment_meta_user_info($payment_id);
     $amount = edd_get_payment_amount($payment_id);
     $cart_details = edd_get_payment_meta_cart_details($payment_id);
     $tax = edd_get_payment_tax($payment_id);
     if (is_array($cart_details)) {
         $items = array();
         // Increase purchase count and earnings
         foreach ($cart_details as $index => $download) {
             // Get the categories that this download belongs to, if any
             $post = edd_get_download($download['id']);
             $terms = get_the_terms($download['id'], 'download_category');
             if ($terms && !is_wp_error($terms)) {
                 $categories = array();
                 foreach ($terms as $term) {
                     $categories[] = $term->name;
                 }
                 $category_id = $terms[0]->term_id;
                 $category_name = join(" - ", $categories);
             } else {
                 $category_id = 1;
                 $category_name = 'Download';
             }
             // "bundle" or "default"
             $download_type = edd_get_download_type($download['id']);
             $download['sku'] = edd_get_download_sku($download['id']);
             // if ( 'bundle' == $download_type ) {
             //   $downloads = edd_get_bundled_products( $download_id );
             //   if ( $downloads ) {
             //     foreach ( $downloads as $d_id ) {
             //       # Do something
             //     }
             //   }
             // }
             $item = array('line_num' => $index + 1, 'product_id' => (int) $download['id'], 'product_name' => $download['name'], 'category_id' => $category_id, 'category_name' => $category_name, 'qty' => $download['quantity'], 'cost' => $download['subtotal']);
             if ($download['sku'] !== '-') {
                 $item['sku'] = $download['sku'];
                 // optional, 30 char limit
             }
             $items[] = $item;
         }
         $order = array('id' => (string) $payment_id, 'email' => $user_info['email'], 'total' => $amount, 'store_id' => self::_edd_ec360_get_store_id(), 'store_name' => home_url(), 'items' => $items, 'order_date' => get_the_date('Y-n-j', $payment_id));
         // Set Ecommerce360 variables if they exist
         $campaign_id = get_post_meta($payment_id, '_edd_mc_campaign_id', true);
         $email_id = get_post_meta($payment_id, '_edd_mc_email_id', true);
         if (!empty($campaign_id)) {
             $order['campaign_id'] = $campaign_id;
         }
         if (!empty($email_id)) {
             $order['email_id'] = $email_id;
         }
         if ($tax != 0) {
             $order['tax'] = $tax;
             // double, optional
         }
         // Send to MailChimp
         $options = array('CURLOPT_FOLLOWLOCATION' => false);
         $mailchimp = new EDD_MailChimp_API($this->key, $options);
         try {
             $result = $mailchimp->call('ecomm/order-add', array('order' => $order));
             edd_insert_payment_note($payment_id, __('Order details have been added to MailChimp successfully', 'eddmc'));
         } catch (Exception $e) {
             edd_insert_payment_note($payment_id, __('MailChimp Ecommerce360 Error: ', 'eddmc') . $e->getMessage());
             return FALSE;
         }
         return TRUE;
     } else {
         return FALSE;
     }
 }
 /**
  * Get the Export Data
  *
  * @access public
  * @since 2.4
  * @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 H:i:s', strtotime($this->start)), 'before' => date('Y-n-d H:i:s', strtotime($this->end)), 'inclusive' => true));
     }
     //echo json_encode($args ); exit;
     $payments = edd_get_payments($args);
     if ($payments) {
         foreach ($payments as $payment) {
             $payment_meta = edd_get_payment_meta($payment->ID);
             $user_info = edd_get_payment_meta_user_info($payment->ID);
             $downloads = edd_get_payment_meta_cart_details($payment->ID);
             $total = edd_get_payment_amount($payment->ID);
             $user_id = isset($user_info['id']) && $user_info['id'] != -1 ? $user_info['id'] : $user_info['email'];
             $products = '';
             $skus = '';
             if ($downloads) {
                 foreach ($downloads as $key => $download) {
                     // Download ID
                     $id = isset($payment_meta['cart_details']) ? $download['id'] : $download;
                     // If the download has variable prices, override the default price
                     $price_override = isset($payment_meta['cart_details']) ? $download['price'] : null;
                     $price = edd_get_download_final_price($id, $user_info, $price_override);
                     // Display the Downoad Name
                     $products .= get_the_title($id) . ' - ';
                     if (edd_use_skus()) {
                         $sku = edd_get_download_sku($id);
                         if (!empty($sku)) {
                             $skus .= $sku;
                         }
                     }
                     if (isset($downloads[$key]['item_number']) && isset($downloads[$key]['item_number']['options'])) {
                         $price_options = $downloads[$key]['item_number']['options'];
                         if (isset($price_options['price_id'])) {
                             $products .= edd_get_price_option_name($id, $price_options['price_id'], $payment->ID) . ' - ';
                         }
                     }
                     $products .= html_entity_decode(edd_currency_filter($price));
                     if ($key != count($downloads) - 1) {
                         $products .= ' / ';
                         if (edd_use_skus()) {
                             $skus .= ' / ';
                         }
                     }
                 }
             }
             if (is_numeric($user_id)) {
                 $user = get_userdata($user_id);
             } else {
                 $user = false;
             }
             $data[] = array('id' => $payment->ID, 'seq_id' => edd_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'] : '', 'products' => $products, 'skus' => $skus, 'amount' => html_entity_decode(edd_format_amount($total)), 'tax' => html_entity_decode(edd_format_amount(edd_get_payment_tax($payment->ID, $payment_meta))), 'discount' => isset($user_info['discount']) && $user_info['discount'] != 'none' ? $user_info['discount'] : __('none', 'edd'), 'gateway' => edd_get_gateway_admin_label(get_post_meta($payment->ID, '_edd_payment_gateway', true)), 'trans_id' => edd_get_payment_transaction_id($payment->ID), 'key' => $payment_meta['key'], 'date' => $payment->post_date, 'user' => $user ? $user->display_name : __('guest', 'edd'), 'status' => edd_get_payment_status($payment, true));
         }
         $data = apply_filters('edd_export_get_data', $data);
         $data = apply_filters('edd_export_get_data_' . $this->export_type, $data);
         return $data;
     }
     return false;
 }
 /**
  * Retrieve earning stats
  *
  * @access public
  * @since 1.8
  * @param INT $download_id The download product to retrieve stats for. If false, gets stats for all products
  * @param string|bool $start_date The starting date for which we'd like to filter our sale stats. If false, we'll use the default start date of `this_month`
  * @param string|bool $end_date 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`
  * @param bool $include_taxes If taxes should be included in the earnings graphs
  * @return float|int Total amount of sales based on the passed arguments.
  */
 public function get_earnings($download_id = 0, $start_date = false, $end_date = false, $include_taxes = true)
 {
     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($download_id)) {
         // Global earning stats
         $args = array('post_type' => 'edd_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, 'edd_transient_type' => 'edd_earnings', 'include_taxes' => $include_taxes);
         $args = apply_filters('edd_stats_earnings_args', $args);
         $cached = get_transient('edd_stats_earnings');
         $key = md5(json_encode($args));
         if (!isset($cached[$key])) {
             $sales = get_posts($args);
             $earnings = 0;
             if ($sales) {
                 $sales = implode(',', array_map('intval', $sales));
                 $total_earnings = $wpdb->get_var("SELECT SUM(meta_value) FROM {$wpdb->postmeta} WHERE meta_key = '_edd_payment_total' AND post_id IN ({$sales})");
                 $total_tax = 0;
                 if (!$include_taxes) {
                     $total_tax = $wpdb->get_var("SELECT SUM(meta_value) FROM {$wpdb->postmeta} WHERE meta_key = '_edd_payment_tax' AND post_id IN ({$sales})");
                 }
                 $total_earnings = apply_filters('edd_payment_stats_earnings_total', $total_earnings, $sales, $args);
                 $earnings += $total_earnings - $total_tax;
             }
             // Cache the results for one hour
             $cached[$key] = $earnings;
             set_transient('edd_stats_earnings', $cached, HOUR_IN_SECONDS);
         }
     } else {
         // Download specific earning stats
         global $edd_logs, $wpdb;
         $args = array('post_parent' => $download_id, 'nopaging' => true, 'log_type' => 'sale', 'fields' => 'ids', 'suppress_filters' => false, 'start_date' => $this->start_date, 'end_date' => $this->end_date, 'edd_transient_type' => 'edd_earnings', 'include_taxes' => $include_taxes);
         $args = apply_filters('edd_stats_earnings_args', $args);
         $cached = get_transient('edd_stats_earnings');
         $key = md5(json_encode($args));
         if (!isset($cached[$key])) {
             $this->timestamp = false;
             $log_ids = $edd_logs->get_connected_logs($args, 'sale');
             $earnings = 0;
             if ($log_ids) {
                 $log_ids = implode(',', array_map('intval', $log_ids));
                 $payment_ids = $wpdb->get_col("SELECT DISTINCT meta_value FROM {$wpdb->postmeta} WHERE meta_key = '_edd_log_payment_id' AND post_id IN ({$log_ids});");
                 foreach ($payment_ids as $payment_id) {
                     $items = edd_get_payment_meta_cart_details($payment_id);
                     foreach ($items as $cart_key => $item) {
                         if ($item['id'] != $download_id) {
                             continue;
                         }
                         $earnings += $item['price'];
                         // Check if there are any item specific fees
                         if (!empty($item['fees'])) {
                             foreach ($item['fees'] as $key => $fee) {
                                 $earnings += $fee['amount'];
                             }
                         }
                         $earnings = apply_filters('edd_payment_stats_item_earnings', $earnings, $payment_id, $cart_key, $item);
                         if (!$include_taxes) {
                             $earnings -= edd_get_payment_item_tax($payment_id, $cart_key);
                         }
                     }
                 }
             }
             // Cache the results for one hour
             $cached[$key] = $earnings;
             set_transient('edd_stats_earnings', $cached, HOUR_IN_SECONDS);
         }
     }
     remove_filter('posts_where', array($this, 'payments_where'));
     $result = $cached[$key];
     return round($result, edd_currency_decimal_filter());
 }