r86598 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86597‎ | r86598 | r86599 >
Date:07:19, 21 April 2011
Author:awjrichards
Status:deferred
Tags:
Comment:
Many bug fixes - watchdog statements all now typo free and working correctly, fixed time bounds in paypal_audit.php, using array_merge rather than array_push where appropriate (>_<), now rather than relying on stupid complicated mapping array for mapping paypal report items -> our own trxn format we just one-off each of the of the fields, added options for report run to remove report cruft, now properly pulling data out of the report rows
Modified paths:
  • /civicrm/trunk/sites/all/modules/paypal_audit/paypal_audit.module (modified) (history)
  • /civicrm/trunk/sites/all/modules/paypal_audit/paypal_audit.php (modified) (history)

Diff [purge]

Index: civicrm/trunk/sites/all/modules/paypal_audit/paypal_audit.module
@@ -15,6 +15,7 @@
1616 'access arguments' => array('administer contribution_audit'),
1717 'page callback' => 'drupal_get_form',
1818 'page arguments' => array( 'paypal_audit_settings' ),
 19+ 'type' => MENU_LOCAL_TASK
1920 );
2021
2122 return $items;
@@ -37,13 +38,55 @@
3839 * Implementation of hook_contribution-audit_find_missing_trxns
3940 * @param array $trxns
4041 */
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 ) {
4243 $pp_trxns = array();
4344 $pf_trxns = array();
4445 $missing_trxns = array();
4546
4647 // 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+ );
4891 $audit = new Paypal_Audit();
4992 $report = $audit->getCustomReport( $start_date, $end_date, $options );
5093
@@ -51,29 +94,28 @@
5295 $columns = $report->getReportResponse()->findColumnNumber( array('Tender Type', 'Transaction ID', 'PayPal Transaction ID' ));
5396 watchdog( 'paypal_audit', 'PayPal custom report run complete.', array(), WATCHDOG_DEBUG );
5497 //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 );
58101 } else {
59 - $pf_trxns[ $columns[ 'Transaction ID' ]] = iterator_to_array( $trxn );
 102+ $pf_trxns[ $trxn->data[ $columns[ 'Transaction ID' ]]] = iterator_to_array( $trxn );
60103 }
61104 }
62105
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 );
65108
66109 //check for missing non-paypal
67110 $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' ));
70113
71114 //check for missing paypal
72115 $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 ));
75118
76 - // add to $trxns and return
77 - array_merge( $trxns, $missing_trxns_formatted);
 119+ return $missing_trxns;
78120 }
79121
80122 /**
@@ -94,7 +136,7 @@
95137 FROM civicrm_contribution
96138 WHERE trxn_id LIKE 'PAYPAL %s' OR trxn_id LIKE 'RECURRING PAYPAL %s'";
97139 $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 ] );
99141 }
100142
101143 $dbs->use_default();
@@ -119,7 +161,7 @@
120162 foreach ( array_keys( $pf_trxns ) as $pf_trxn_id ) {
121163 $query = "SELECT {trxn_id} FROM civicrm_contribution WHERE trxn_id LIKE 'PAYFLOWPRO %s'";
122164 $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 ] );
124166 }
125167
126168 $dbs->use_default();
@@ -133,49 +175,24 @@
134176 * will need to be fetched out of the minfraud or other logs...
135177 * @param unknown_type $trxns
136178 */
137 -function paypal_audit_format_trxns( $trxns, $reprot_obj, $gateway='PayflowPro' ) {
 179+function paypal_audit_format_trxns( $trxns, $report_obj, $gateway='PayflowPro' ) {
138180 $trxns_formatted = array();
139181
140182 /**
141183 * {"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}
142184 */
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+
167188 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+
180197 array_push( $trxns_formatted, $formatted_trxn );
181198 }
182199
Index: civicrm/trunk/sites/all/modules/paypal_audit/paypal_audit.php
@@ -14,15 +14,15 @@
1515 public function getCustomReport( $start_date, $end_date, $options=array() ) {
1616 require_once( variable_get( 'paypal_audit_dir', CONTRIBUTION_AUDIT_PAYFLOW_AUDIT_DIR ) . "PayflowReportTypes.php");
1717
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");
1919
2020 $report = new CustomReport( $time_bounds );
2121 $report_options = $report->getOptions( true );
22 - array_push( $report_options, $options );
 22+ $report_options = array_merge( $report_options, $options );
2323 $report->setOptions( $report_options );
2424 $report->runReport();
2525
26 - return $results;
 26+ return $report->getResults();
2727 }
2828
2929 /**
@@ -30,6 +30,6 @@
3131 * @param string Representation of date/time
3232 */
3333 public function fixTime( $time ) {
34 - return date( strtotime( 'Y-m-d', strtotime( $time )));
 34+ return date( 'Y-m-d', strtotime( $time ));
3535 }
36 -}
\ No newline at end of file
 36+}

Status & tagging log