Easy Digital Downloads
  • Package
  • Class
  • Tree

Packages

  • EDD
    • Admin
      • Actions
      • Add-ons
      • Dashboard
      • Discounts
      • Downloads
      • Export
      • Notices
      • Pages
      • Payments
      • Reports
      • Settings
      • System
      • Upgrades
      • Upload
      • Welcome
    • Cart
    • Checkout
    • Classes
      • API
      • Fees
      • HTML
      • Roles
      • Session
    • Emails
    • Functions
      • AJAX
      • Compatibility
      • Errors
      • Formatting
      • Install
      • Login
      • Taxes
      • Templates
    • Gateways
    • Logging
    • Payments
    • Shortcodes
    • Widgets

Classes

  • EDD_API_Request_Log_Table
  • EDD_Customer_Reports_Table
  • EDD_Customers_Export
  • EDD_Download_History_Export
  • EDD_Download_Reports_Table
  • EDD_Export
  • EDD_File_Downloads_Log_Table
  • EDD_Gateway_Error_Log_Table
  • EDD_Payments_Export
  • EDD_Sales_Log_Table

Functions

  • edd_draw_chart_image
  • edd_estimated_monthly_stats
  • edd_generate_pdf
  • edd_get_report_dates
  • edd_log_default_views
  • edd_log_views
  • edd_logs_view_api_requests
  • edd_logs_view_file_downloads
  • edd_logs_view_gateway_errors
  • edd_logs_view_sales
  • edd_parse_report_dates
  • edd_report_views
  • edd_reporting_contextual_help
  • edd_reports_customers_table
  • edd_reports_default_views
  • edd_reports_downloads_table
  • edd_reports_earnings
  • edd_reports_graph
  • edd_reports_graph_controls
  • edd_reports_page
  • edd_reports_tab_export
  • edd_reports_tab_logs
  • edd_reports_tab_reports
  • edd_reports_taxes
  1 <?php
  2 /**
  3  * Payments Export Class
  4  *
  5  * This class handles payment export
  6  *
  7  * @package     EDD
  8  * @subpackage  Admin/Reports
  9  * @copyright   Copyright (c) 2013, Pippin Williamson
 10  * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
 11  * @since       1.4.4
 12  */
 13 
 14 // Exit if accessed directly
 15 if ( ! defined( 'ABSPATH' ) ) exit;
 16 
 17 /**
 18  * EDD_Payments_Export Class
 19  *
 20  * @since 1.4.4
 21  */
 22 class EDD_Payments_Export extends EDD_Export {
 23     /**
 24      * Our export type. Used for export-type specific filters/actions
 25      * @var string
 26      * @since 1.4.4
 27      */
 28     public $export_type = 'payments';
 29 
 30     /**
 31      * Set the CSV columns
 32      *
 33      * @access public
 34      * @since 1.4.4
 35      * @return array $cols All the columns
 36      */
 37     public function csv_cols() {
 38         $cols = array(
 39             'id'       => __( 'ID',   'edd' ),
 40             'email'    => __( 'Email', 'edd' ),
 41             'first'    => __( 'First Name', 'edd' ),
 42             'last'     => __( 'Last Name', 'edd' ),
 43             'products' => __( 'Products', 'edd' ),
 44             'amount'   => __( 'Amount', 'edd' ),
 45             'tax'      => __( 'Tax', 'edd' ),
 46             'gateway'  => __( 'Payment Method', 'edd' ),
 47             'key'      => __( 'Purchase Key', 'edd' ),
 48             'date'     => __( 'Date', 'edd' ),
 49             'user'     => __( 'User', 'edd' ),
 50             'status'   => __( 'Status', 'edd' )
 51         );
 52         return $cols;
 53     }
 54 
 55     /**
 56      * Get the Export Data
 57      *
 58      * @access public
 59      * @since 1.4.4
 60      * @global object $wpdb Used to query the database using the WordPress
 61      *   Database API
 62      * @return array $data The data for the CSV file
 63      */
 64     public function get_data() {
 65         global $wpdb;
 66 
 67         $data = array();
 68 
 69         $payments = edd_get_payments( array(
 70             'offset'  => 0,
 71             'number'  => -1,
 72             'mode'    => edd_is_test_mode() ? 'test' : 'live',
 73             'status'  => isset( $_POST['edd_export_payment_status'] ) ? $_POST['edd_export_payment_status'] : 'any'
 74         ) );
 75 
 76         foreach ( $payments as $payment ) {
 77             $payment_meta   = edd_get_payment_meta( $payment->ID );
 78             $user_info      = edd_get_payment_meta_user_info( $payment->ID );
 79             $downloads      = edd_get_payment_meta_cart_details( $payment->ID );
 80             $total          = isset( $payment_meta['amount'] ) ? $payment_meta['amount'] : 0.00;
 81             $user_id        = isset( $user_info['id'] ) && $user_info['id'] != -1 ? $user_info['id'] : $user_info['email'];
 82             $products       = '';
 83 
 84             if ( $downloads ) {
 85                 foreach ( $downloads as $key => $download ) {
 86                     // Download ID
 87                     $id = isset( $payment_meta['cart_details'] ) ? $download['id'] : $download;
 88 
 89                     // If the download has variable prices, override the default price
 90                     $price_override = isset( $payment_meta['cart_details'] ) ? $download['price'] : null;
 91 
 92                     $price = edd_get_download_final_price( $id, $user_info, $price_override );
 93 
 94                     // Display the Downoad Name
 95                     $products .= get_the_title( $id ) . ' - ';
 96 
 97                     if ( isset( $downloads[ $key ]['item_number'] ) ) {
 98                         $price_options = $downloads[ $key ]['item_number']['options'];
 99 
100                         if ( isset( $price_options['price_id'] ) ) {
101                             $products .= edd_get_price_option_name( $id, $price_options['price_id'] ) . ' - ';
102                         }
103                     }
104                     $products .= html_entity_decode( edd_currency_filter( $price ) );
105 
106                     if ( $key != ( count( $downloads ) -1 ) ) {
107                         $products .= ' / ';
108                     }
109                 }
110             }
111 
112             if ( is_numeric( $user_id ) ) {
113                 $user = get_userdata( $user_id );
114             } else {
115                 $user = false;
116             }
117 
118             $data[] = array(
119                 'id'       => $payment->ID,
120                 'email'    => $payment_meta['email'],
121                 'first'    => $user_info['first_name'],
122                 'last'     => $user_info['last_name'],
123                 'products' => $products,
124                 'amount'   => html_entity_decode( edd_currency_filter( edd_format_amount( $total ) ) ),
125                 'tax'      => html_entity_decode( edd_payment_tax( $payment->ID, $payment_meta ) ),
126                 'discount' => isset( $user_info['discount'] ) && $user_info['discount'] != 'none' ? $user_info['discount'] : __( 'none', 'edd' ),
127                 'gateway'  => edd_get_gateway_admin_label( get_post_meta( $payment->ID, '_edd_payment_gateway', true ) ),
128                 'key'      => $payment_meta['key'],
129                 'date'     => $payment->post_date,
130                 'user'     => $user ? $user->display_name : __( 'guest', 'edd' ),
131                 'status'   => edd_get_payment_status( $payment, true )
132             );
133 
134         }
135 
136         $data = apply_filters( 'edd_export_get_data', $data );
137         $data = apply_filters( 'edd_export_get_data_' . $this->export_type, $data );
138 
139         return $data;
140     }
141 }
Easy Digital Downloads API documentation generated by ApiGen 2.8.0