Awight has uploaded a new change for review. https://gerrit.wikimedia.org/r/300707
Change subject: Remove WorldPay ...................................................................... Remove WorldPay Change-Id: Ib00387c20bf576f40d486139199617c8a743df09 --- D sites/all/modules/wmf_audit/worldpay/WorldpayAuditProcessor.php D sites/all/modules/wmf_audit/worldpay/worldpay_audit.info D sites/all/modules/wmf_audit/worldpay/worldpay_audit.module 3 files changed, 0 insertions(+), 303 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm refs/changes/07/300707/1 diff --git a/sites/all/modules/wmf_audit/worldpay/WorldpayAuditProcessor.php b/sites/all/modules/wmf_audit/worldpay/WorldpayAuditProcessor.php deleted file mode 100644 index e1871d8..0000000 --- a/sites/all/modules/wmf_audit/worldpay/WorldpayAuditProcessor.php +++ /dev/null @@ -1,229 +0,0 @@ -<?php - -use SmashPig\PaymentProviders\Worldpay\Audit\WorldpayAudit; - -class WorldpayAuditProcessor extends BaseAuditProcessor { - - protected $name = 'worldpay'; - - /** - * The regex to use to determine if a file is a reconciliation file for this - * gateway. - * @return string regular expression - */ - protected function regex_for_recon() { - //WP recon files look like the following thing: - // MA.PISCESSW.#M.RECON.WIKI.D280514 - // or - // TranDetVer2_530860_11-26-2014_8'27'08 AM.csv - // or - // WPG_AUDIT_YYYYMMDDhhmm.txt - return '/\.RECON\.WIKI\.|TranDetVer2|^WPG_AUDIT_\d{12}\.\w{3}$/'; - } - - /** - * Given a reconciliation file name, pull the date out of the filename and - * return it in YYYYMMDD format. - * @param string $file Name of the recon file (not full path) - * @return string date in YYYYMMDD format - */ - protected function get_recon_file_sort_key( $file ) { - // FIXME: this is two-fer-one functionality. Unmash. - - if ( preg_match( '/\.RECON\.WIKI\./', $file ) ) { - //WP recon files look like the following thing: - // MA.PISCESSW.#M.RECON.WIKI.D280514 - //For that, we'd want to return 20140518 - $parts = explode( '.', $file ); - $end_piece = $parts[count( $parts ) - 1]; - $date = '20' . substr( $end_piece, 5, 2 ) . substr( $end_piece, 3, 2 ) . substr( $end_piece, 1, 2 ); - return $date; - } elseif ( preg_match( '/TranDetVer2/', $file ) ) { - // These files have the equally crazy format: - // TranDetVer2_60879_6-21-2014_8'27'38 AM.csv - $parts = explode( '_', $file ); - $dateStr = $parts[2]; - $dateParts = explode( '-', $dateStr ); - $date = $dateParts[2] . str_pad( $dateParts[0], 2, '0' ) . str_pad( $dateParts[1], 2, '0' ); - return $date; - } elseif ( preg_match( '/WPG_AUDIT/', $file ) ) { - // WPG audit files look like WPG_AUDIT_YYYYMMDDhhmm.csv - return substr( $file, 10, 12 ); - } - throw new Exception( "Cannot parse date in surprise file {$file}" ); - } - - /** - * In order to create the distilled "working" log files, we need to grep through - * the uncompressed log file for lines that contain a copy of our original - * communication with the payment provider. This function returns the string - * that, when used in a command-line grep statement against a payments log, will - * pick out all instances of communication with the 3rd party that contain donor - * information that is not included in the recon file, but which we need to - * re-fuse with the recon data and save in civicrm. - * @return string the pattern we're going to grep for in the payments logs - */ - protected function get_log_distilling_grep_string() { - return 'Request XML.*TMSTN.*<TransactionType>PT.*<RequestType>S<'; - } - - protected function get_audit_parser() { - return new WorldpayAudit(); - } - - /** - * In order to match data in working payments logs with the data we're trying to - * rebuild, we will need to grep for something. This, actually. - * @param string $order_id The order id (transaction id) of what we're looking for. - * @return string the pattern to grep for, for this specific transaction - */ - protected function get_log_line_grep_string( $order_id ) { - return "<OrderNumber>{$order_id}</OrderNumber>"; - } - - protected function parse_log_line( $logline ) { - $xml_data = $this->parse_xml_log_line( $logline ); - $normal = array(); - - // normalize the $xml_data - $nodemap = array( - 'OrderNumber' => 'gateway_txn_id', - 'Amount' => 'gross', - 'REMOTE_ADDR' => 'user_ip', - 'FirstName' => 'first_name', - 'LastName' => 'last_name', - 'Address1' => 'street_address', //N0NE PROVIDED - 'ZipCode' => 'postal_code', //0 - 'CountryCode' => 'country', - 'Email' => 'email', - 'contribution_tracking_id' => 'contribution_tracking_id', //passed through, because I already set this manually - ); - - foreach ( $xml_data as $key => $value ) { - if ( array_key_exists( $key, $nodemap ) ) { - $normal[$nodemap[$key]] = $value; - } - } - - if ( array_key_exists( 'CurrencyId', $xml_data ) ) { - $normal['currency'] = $this->get_currency_code_from_stupid_number( $xml_data['CurrencyId'] ); - } - - $unsets = array( - 'street_address' => 'N0NE PROVIDED', - 'postal_code' => '0', - ); - - foreach ( $unsets as $key => $value ) { - if ( array_key_exists( $key, $normal ) && $normal[$key] === $value ) { - unset( $normal[$key] ); - } - } - return $normal; - } - - /** - * The name of the outermost node in the log XML we're going to try to make - * sense of. Usually, this is "XML", but apparently not all the time. Huh. - * @return string node name - */ - protected function get_log_line_xml_outermost_node() { - return 'TMSTN'; - } - - /** - * This would probably make more sense if this was not the same as the - * outermost. WP is really... flat. - * *ahem* - * If the XML is complete (not truncated by syslog), then the data just comes - * straight from the child nodes of the parent nodes defined here. - * @return array Names of the nodes whose children describe donor data. - */ - protected function get_log_line_xml_parent_nodes() { - return array( - 'TMSTN' - ); - } - - /** - * If the XML happens to be incomplete (truncated by syslog), we avoid total - * tragedy by searching whatever is left for individual complete data nodes. - * Yes: This has happened before. - * @return array Names of the nodes whose children describe donor data. - */ - protected function get_log_line_xml_data_nodes() { - return array( - 'OrderNumber', - 'Amount', - 'REMOTE_ADDR', - 'FirstName', - 'LastName', - 'Address1', - 'ZipCode', - 'CountryCode', - 'Email', - ); - } - - /** - * Takes whatever we've found in the xml, and whatever we've found in the recon - * file, and makes them get along. If that works, it fuses them into a normal - * message. - * Presumably, if we're calling this function, we already have reason to believe - * that the xml and recon data supplied go together. There should always be some - * internal sanity checking, though. Stuff can get weird. - * @param array $log_data Transaction data from payments log xml - * @param array $recon_data Transaction data from the recon file - * @return array|false The re-fused and normalized data, or false if something - * went wrong. - */ - protected function merge_data( $log_data, $recon_data ) { - //just port these - $believe = array( //because we have no choice - 'gateway', //ha - 'date', - 'payment_method', - 'payment_submethod', - 'gross', - ); - - foreach ( $believe as $key ) { - if ( array_key_exists( $key, $recon_data ) ) { - $log_data[$key] = $recon_data[$key]; - } else { - wmf_audit_log_error( "Recon data is missing expected key $key. " . print_r( $recon_data, true ), 'DATA_INCOMPLETE' ); - } - } - - return $log_data; - } - - /** - * HELPER FUNCTIONS - * ...only this file will ever call them. - */ - - /** - * Instead of using sane ISO codes for currencies, WP uses a long list of - * numbers that everybody immediately turns back into the ISO codes at the - * earliest convenience. - * This array is backwards, because I straight up copied it from - * DonationInterface. Not even sorry. - * @staticvar array $flipped The currency code array in the format we need to do - * an easy lookup. - * @param int $number The number that appears in WP payments log XML for the - * currency code. - * @return string The ISO currency code - */ - protected function get_currency_code_from_stupid_number( $number ) { - static $flipped = array(); - if ( empty( $flipped ) ) { - $flipped = array_flip( WorldpayAdapter::$CURRENCY_CODES ); - } - if ( array_key_exists( $number, $flipped ) ) { - return $flipped[$number]; - } else { - wmf_audit_log_error( __FUNCTION__ . ": No currency found for code $number", 'MISSING_MANDATORY_DATA' ); - } - } -} diff --git a/sites/all/modules/wmf_audit/worldpay/worldpay_audit.info b/sites/all/modules/wmf_audit/worldpay/worldpay_audit.info deleted file mode 100644 index 430d3e3..0000000 --- a/sites/all/modules/wmf_audit/worldpay/worldpay_audit.info +++ /dev/null @@ -1,7 +0,0 @@ -name = Worldpay Audit -description = Auditing framework for contacts and contributions that come in through nightly reconciliation files, for Worldpay -core = 7.x -dependencies[] = wmf_audit -package = WMF Audit -configure = admin/config/wmf_audit/worldpay_audit -files[] = WorldpayAuditProcessor.php diff --git a/sites/all/modules/wmf_audit/worldpay/worldpay_audit.module b/sites/all/modules/wmf_audit/worldpay/worldpay_audit.module deleted file mode 100644 index 07d0687..0000000 --- a/sites/all/modules/wmf_audit/worldpay/worldpay_audit.module +++ /dev/null @@ -1,67 +0,0 @@ -<?php - -// Defaults -define( 'WP_AUDIT_RECON_PARSER_DIR', '/usr/local/src/WP_Parser_Lib' ); -define( 'WP_AUDIT_RECON_FILES_DIR', '/usr/local/src/recon_files' ); -define( 'WP_AUDIT_RECON_COMPLETED_DIR', '/usr/local/src/recon_files-completed' ); -define( 'WP_AUDIT_WORKING_LOG_DIR', '/usr/local/src/log_files-working' ); -define( 'WP_AUDIT_LOG_SEARCH_PAST_DAYS', 7 ); -define( 'WP_AUDIT_TEST_MODE', true ); - -/** - * Implementation of hook_menu() - */ -function worldpay_audit_menu() { - $items = array(); - - $items['admin/config/wmf_audit/worldpay_audit'] = array( - 'title' => 'Worldpay Audit', - 'description' => t( 'Configure WMF audit settings.' ), - 'access arguments' => array( 'administer wmf_audit' ), - 'page callback' => 'drupal_get_form', - 'page arguments' => array( 'worldpay_audit_settings' ), - ); - - return $items; -} - -/** - * Callback for menu - */ -function worldpay_audit_settings() { - $form['worldpay_audit_recon_files_dir'] = array( - '#type' => 'textfield', - '#title' => t( 'Directory containing incoming reconciliation files' ), - '#required' => TRUE, - '#default_value' => variable_get( 'worldpay_audit_recon_files_dir', WP_AUDIT_RECON_FILES_DIR ), - ); - $form['worldpay_audit_recon_completed_dir'] = array( - '#type' => 'textfield', - '#title' => t( 'Directory for completed reconciliation files' ), - '#required' => TRUE, - '#default_value' => variable_get( 'worldpay_audit_recon_completed_dir', WP_AUDIT_RECON_COMPLETED_DIR ), - ); - $form['worldpay_audit_working_log_dir'] = array( - '#type' => 'textfield', - '#title' => t( 'Working directory for payments logs (Not the source - that is defined at the wmf_audit level)' ), - '#required' => TRUE, - '#default_value' => variable_get( 'worldpay_audit_working_log_dir', WP_AUDIT_WORKING_LOG_DIR ), - ); - $form['worldpay_audit_test_mode'] = array( - '#type' => 'checkbox', - '#title' => t( 'When this box is checked, no stomp messages will be sent.' ), - '#required' => FALSE, - '#default_value' => variable_get( 'worldpay_audit_test_mode', WP_AUDIT_TEST_MODE ), - ); - $form['worldpay_audit_log_search_past_days'] = array( - '#type' => 'textfield', - '#title' => t( 'Plus or minus log search (in days)' ), - '#required' => TRUE, - '#default_value' => variable_get( 'worldpay_audit_log_search_past_days', WP_AUDIT_LOG_SEARCH_PAST_DAYS ), - ); - return system_settings_form( $form ); -} - -function worldpay_audit_create_processor( $options ) { - return new WorldpayAuditProcessor( $options ); -} -- To view, visit https://gerrit.wikimedia.org/r/300707 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib00387c20bf576f40d486139199617c8a743df09 Gerrit-PatchSet: 1 Gerrit-Project: wikimedia/fundraising/crm Gerrit-Branch: master Gerrit-Owner: Awight <awi...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits