Index: civicrm/trunk/sites/all/modules/paypal_audit/paypal_audit.module |
— | — | @@ -15,6 +15,7 @@ |
16 | 16 | 'access arguments' => array('administer contribution_audit'), |
17 | 17 | 'page callback' => 'drupal_get_form', |
18 | 18 | 'page arguments' => array( 'paypal_audit_settings' ), |
| 19 | + 'type' => MENU_LOCAL_TASK |
19 | 20 | ); |
20 | 21 | |
21 | 22 | return $items; |
— | — | @@ -37,13 +38,55 @@ |
38 | 39 | * Implementation of hook_contribution-audit_find_missing_trxns |
39 | 40 | * @param array $trxns |
40 | 41 | */ |
41 | | -function paypal_audit_contribution_audit_find_missing_trxns( &$trxns, $start_date, $end_date ) { |
| 42 | +function paypal_audit_contribution_audit_find_missing_trxns( $start_date, $end_date ) { |
42 | 43 | $pp_trxns = array(); |
43 | 44 | $pf_trxns = array(); |
44 | 45 | $missing_trxns = array(); |
45 | 46 | |
46 | 47 | // fetch trxns from paypal |
47 | | - $options = array(); |
| 48 | + $options = array( |
| 49 | + 'include_authorization' => 'false', |
| 50 | + 'include_delayedcapture' => 'false', |
| 51 | + 'include_credit' => 'false', |
| 52 | + 'include_void' => 'false', |
| 53 | + 'include_voiceauthorization' => 'false', |
| 54 | + 'show_order_id' => 'false', |
| 55 | + 'show_account_number' => 'false', |
| 56 | + 'show_expires' => 'false', |
| 57 | + 'show_aba_routing_number' => 'false', |
| 58 | + 'show_result_code' => 'false', |
| 59 | + 'show_response_msg' => 'false', |
| 60 | + 'show_comment1' => 'false', |
| 61 | + 'show_comment2' => 'false', |
| 62 | + 'show_tax_amount' => 'false', |
| 63 | + 'show_purchase_order' => 'false', |
| 64 | + 'show_original_transaction_id' => 'false', |
| 65 | + 'show_avs_street_match' => 'false', |
| 66 | + 'show_avs_zip_match' => 'false', |
| 67 | + 'show_invoice_number' => 'false', |
| 68 | + 'show_authcode' => 'false', |
| 69 | + 'show_batch_id' => 'false', |
| 70 | + 'show_csc_match' => 'false', |
| 71 | + 'show_billing_first_name' => 'false', |
| 72 | + 'show_billing_last_name' => 'false', |
| 73 | + 'show_billing_company_name' => 'false', |
| 74 | + 'show_billing_address' => 'false', |
| 75 | + 'show_billing_city' => 'false', |
| 76 | + 'show_billing_state' => 'false', |
| 77 | + 'show_billing_zip' => 'false', |
| 78 | + 'show_billing_email' => 'false', |
| 79 | + 'show_billing_country' => 'true', |
| 80 | + 'show_shipping_first_name' => 'false', |
| 81 | + 'show_shipping_last_name' => 'false', |
| 82 | + 'show_shipping_address' => 'false', |
| 83 | + 'show_shipping_city' => 'false', |
| 84 | + 'show_shipping_state' => 'false', |
| 85 | + 'show_shipping_zip' => 'false', |
| 86 | + 'show_shipping_country' => 'true', |
| 87 | + 'show_customer_code' => 'false', |
| 88 | + 'show_freight_amount' => 'false', |
| 89 | + 'show_duty_amount' => 'false', |
| 90 | + ); |
48 | 91 | $audit = new Paypal_Audit(); |
49 | 92 | $report = $audit->getCustomReport( $start_date, $end_date, $options ); |
50 | 93 | |
— | — | @@ -51,29 +94,28 @@ |
52 | 95 | $columns = $report->getReportResponse()->findColumnNumber( array('Tender Type', 'Transaction ID', 'PayPal Transaction ID' )); |
53 | 96 | watchdog( 'paypal_audit', 'PayPal custom report run complete.', array(), WATCHDOG_DEBUG ); |
54 | 97 | //loop through trxns (each trxn is a reportDataRow object), isolate paypal v non-paypal |
55 | | - foreach( $pp_trxns->getData() as $trxn ) { |
56 | | - if ( $trxn[ $tt_column ] == 'PayPal' ) { |
57 | | - $pp_trxns[ $columns[ 'PayPal Transaction ID' ]] = iterator_to_array( $trxn ); |
| 98 | + foreach( $report->getData() as $trxn ) { |
| 99 | + if ( $trxn->data[ $columns[ 'Tender Type' ]] == 'PayPal' ) { |
| 100 | + $pp_trxns[ $trxn->data[ $columns[ 'PayPal Transaction ID' ]]] = iterator_to_array( $trxn ); |
58 | 101 | } else { |
59 | | - $pf_trxns[ $columns[ 'Transaction ID' ]] = iterator_to_array( $trxn ); |
| 102 | + $pf_trxns[ $trxn->data[ $columns[ 'Transaction ID' ]]] = iterator_to_array( $trxn ); |
60 | 103 | } |
61 | 104 | } |
62 | 105 | |
63 | | - watchdog( 'paypal_audit', 'PayPal transactions present in report: %d', array('%d' => count($pp_trxns)), WATCHDOG_DEBUG ); |
64 | | - watchdog( 'paypal_audit', 'PayflowPro transactions present in report: %d', array('%d' => count($pfp_trxns)), WATCHDOG_DEBUG ); |
| 106 | + watchdog( 'paypal_audit', 'PayPal transactions present in report: @d', array('@d' => count($pp_trxns)), WATCHDOG_DEBUG ); |
| 107 | + watchdog( 'paypal_audit', 'PayflowPro transactions present in report: @d', array('@d' => count($pf_trxns)), WATCHDOG_DEBUG ); |
65 | 108 | |
66 | 109 | //check for missing non-paypal |
67 | 110 | $pp_trxns_missing = paypal_audit_find_missing_pp_trxns( $pp_trxns ); |
68 | | - watchdog( 'paypal_audit', 'PayPal transactions missing: %d', array( '%d', count($pp_trxns_missing)), WATCHDOG_DEBUG ); |
69 | | - array_push( $missing_trxns, paypal_audit_format_trxns( $pp_trxns_missing, $report, 'PayPal' )); |
| 111 | + watchdog( 'paypal_audit', 'PayPal transactions missing: @d', array( '@d' => count($pp_trxns_missing)), WATCHDOG_DEBUG ); |
| 112 | + $missing_trxns = array_merge( $missing_trxns, paypal_audit_format_trxns( $pp_trxns_missing, $report, 'PayPal' )); |
70 | 113 | |
71 | 114 | //check for missing paypal |
72 | 115 | $pf_trxns_missing = paypal_audit_find_missing_pf_trxns( $pf_trxns ); |
73 | | - watchdog( 'paypal_audit', 'PayflowPro transactions missing: %d', array( '%d', count($pfp_trxns_missing)), WATCHDOG_DEBUG ); |
74 | | - array_push( $missing_trxns, paypal_audit_format_trxns( $pf_trxns_missing, $report )); |
| 116 | + watchdog( 'paypal_audit', 'PayflowPro transactions missing: @d', array( '@d' => count($pf_trxns_missing)), WATCHDOG_DEBUG ); |
| 117 | + $missing_trxns = array_merge( $missing_trxns, paypal_audit_format_trxns( $pf_trxns_missing, $report )); |
75 | 118 | |
76 | | - // add to $trxns and return |
77 | | - array_merge( $trxns, $missing_trxns_formatted); |
| 119 | + return $missing_trxns; |
78 | 120 | } |
79 | 121 | |
80 | 122 | /** |
— | — | @@ -94,7 +136,7 @@ |
95 | 137 | FROM civicrm_contribution |
96 | 138 | WHERE trxn_id LIKE 'PAYPAL %s' OR trxn_id LIKE 'RECURRING PAYPAL %s'"; |
97 | 139 | $result = db_query( $query, $pp_trxn_id . "%" ); |
98 | | - if ( !$result->rowCount() ) array_push( $missing_trxns, $pp_trxns[ $pp_trxn_id ] ); |
| 140 | + if ( !$result->num_rows ) array_push( $missing_trxns, $pp_trxns[ $pp_trxn_id ] ); |
99 | 141 | } |
100 | 142 | |
101 | 143 | $dbs->use_default(); |
— | — | @@ -119,7 +161,7 @@ |
120 | 162 | foreach ( array_keys( $pf_trxns ) as $pf_trxn_id ) { |
121 | 163 | $query = "SELECT {trxn_id} FROM civicrm_contribution WHERE trxn_id LIKE 'PAYFLOWPRO %s'"; |
122 | 164 | $result = db_query( $query, $pf_trxn_id . "%" ); |
123 | | - if ( !$result->rowCount() ) array_push( $missing_trxns, $pf_trxns[ $pf_trxn_id ] ); |
| 165 | + if ( !$result->num_rows ) array_push( $missing_trxns, $pf_trxns[ $pf_trxn_id ] ); |
124 | 166 | } |
125 | 167 | |
126 | 168 | $dbs->use_default(); |
— | — | @@ -133,49 +175,24 @@ |
134 | 176 | * will need to be fetched out of the minfraud or other logs... |
135 | 177 | * @param unknown_type $trxns |
136 | 178 | */ |
137 | | -function paypal_audit_format_trxns( $trxns, $reprot_obj, $gateway='PayflowPro' ) { |
| 179 | +function paypal_audit_format_trxns( $trxns, $report_obj, $gateway='PayflowPro' ) { |
138 | 180 | $trxns_formatted = array(); |
139 | 181 | |
140 | 182 | /** |
141 | 183 | * {"contribution_tracking_id":"4983928","optout":"0","anonymous":"1","comment":null,"email":"xmarquez.b@gmail.com","size":null,"premium_language":null,"first_name":"Xavier","last_name":"Marquez Barreto","street_address":"Pto Azul Mz A-5 Villa 3","supplemental_address_1":null,"city":"Guayaquil","state_province":"Guayas","country":"EC","postal_code":"752","last_name_2":"Barreto","first_name_2":"Xavier Marquez","street_address_2":"Pto Azul Mz A-5 Villa 3","supplemental_address_2":null,"city_2":"Guayaquil","state_province_2":"Guayas","country_2":"EC","postal_code_2":"752","gateway":"paypal","gateway_txn_id":"6N71347241984711L","original_currency":"USD","original_gross":"3.00","fee":"0.39","gross":"3.00","net":2.61,"date":1303195718} |
142 | 184 | */ |
143 | | - $map = array( |
144 | | - "contribution_tracking_id" => '', |
145 | | - 'optout' => '', |
146 | | - 'anonymous' => '', |
147 | | - 'comment' => '', |
148 | | - 'email' => '', |
149 | | - 'first_name' => '', |
150 | | - 'last_name' => '', |
151 | | - 'street_address' => '', |
152 | | - 'city' => '', |
153 | | - 'state_province' => '', |
154 | | - 'postal_code' => '', |
155 | | - 'country' => 'Billing Country', |
156 | | - 'gateway' => '', |
157 | | - 'gateway_txn_id' => ( $gateway == 'PayflowPro' ) ? 'Transaction ID' : 'PayPal Transaction ID', |
158 | | - 'original_currency' => 'Currency Symbol', |
159 | | - 'original_gross' => '', |
160 | | - 'fee' => '', |
161 | | - 'gross' => 'Amount', |
162 | | - 'fee' => '', |
163 | | - 'net' => '', |
164 | | - 'date' => 'Settled Date', |
165 | | - ); |
166 | | - |
| 185 | + $fields = array( 'Billing Country', 'Shipping Country', 'Transaction ID', 'PayPal Transaction ID', 'Currency Symbol', 'Amount', 'Time'); |
| 186 | + $columns = $report_obj->getReportResponse()->findColumnNumber( $fields ); |
| 187 | + |
167 | 188 | foreach ( $trxns as $trxn ) { |
168 | | - foreach( $map as $key => $value ) { |
169 | | - if ( !strlen( $value )) { |
170 | | - $formatted_trxn[ $key ] = ''; |
171 | | - } else { |
172 | | - $colNum = $report->getReportResponse()->findColumnNumber( $value ); |
173 | | - if ( $key == 'date' ) { |
174 | | - $formatted_trxn[ $key ] = strtotime( $trxn[ $colNum ] ); |
175 | | - } else { |
176 | | - $formatted_trxn[ $key ] = $trxn[ $colNum ]; |
177 | | - } |
178 | | - } |
179 | | - } |
| 189 | + $formatted_trxn = array(); |
| 190 | + $formatted_trxn['country'] = ( strlen( $trxn[ $columns[ 'Shipping Country' ]] )) ? $trxn[ $columns[ 'Shipping Country' ]] : $trxn[ $columns[ 'Billing Country']]; |
| 191 | + $formatted_trxn['gateway'] = strtolower( $gateway ); |
| 192 | + $formatted_trxn['gateway_txn_id'] = ( $gateway == 'PayflowPro' ) ? $trxn[ $columns[ 'Transaction ID' ]] : $trxn[ $columns[ 'PayPal Transaction ID']]; |
| 193 | + $formatted_trxn['original_currency'] = $trxn[ $columns[ 'Currency Symbol' ]]; |
| 194 | + $formatted_trxn['gross'] = $trxn[ $columns[ 'Amount' ]]; |
| 195 | + $formatted_trxn['date'] = strtotime( $trxn[ $columns[ 'Time' ]] ); |
| 196 | + |
180 | 197 | array_push( $trxns_formatted, $formatted_trxn ); |
181 | 198 | } |
182 | 199 | |
Index: civicrm/trunk/sites/all/modules/paypal_audit/paypal_audit.php |
— | — | @@ -14,15 +14,15 @@ |
15 | 15 | public function getCustomReport( $start_date, $end_date, $options=array() ) { |
16 | 16 | require_once( variable_get( 'paypal_audit_dir', CONTRIBUTION_AUDIT_PAYFLOW_AUDIT_DIR ) . "PayflowReportTypes.php"); |
17 | 17 | |
18 | | - $time_bounds = array( $this->fixTime( $start_date ), $this->fixTime( $endDate )); |
| 18 | + $time_bounds = array( $this->fixTime( $start_date ) . " 00:00:00", $this->fixTime( $end_date ) . " 23:59:59"); |
19 | 19 | |
20 | 20 | $report = new CustomReport( $time_bounds ); |
21 | 21 | $report_options = $report->getOptions( true ); |
22 | | - array_push( $report_options, $options ); |
| 22 | + $report_options = array_merge( $report_options, $options ); |
23 | 23 | $report->setOptions( $report_options ); |
24 | 24 | $report->runReport(); |
25 | 25 | |
26 | | - return $results; |
| 26 | + return $report->getResults(); |
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
— | — | @@ -30,6 +30,6 @@ |
31 | 31 | * @param string Representation of date/time |
32 | 32 | */ |
33 | 33 | public function fixTime( $time ) { |
34 | | - return date( strtotime( 'Y-m-d', strtotime( $time ))); |
| 34 | + return date( 'Y-m-d', strtotime( $time )); |
35 | 35 | } |
36 | | -} |
\ No newline at end of file |
| 36 | +} |