1 <?php
2 3 4 5 6 7 8 9 10 11 12
13
14
15 if ( ! defined( 'ABSPATH' ) ) exit;
16
17 18 19 20 21
22 class EDD_Payments_Export extends EDD_Export {
23 24 25 26 27
28 public $export_type = 'payments';
29
30 31 32 33 34 35 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 57 58 59 60 61 62 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
87 $id = isset( $payment_meta['cart_details'] ) ? $download['id'] : $download;
88
89
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
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 }