Ejegg has submitted this change and it was merged.
Change subject: WPG RECON (SMASHPIG)
......................................................................
WPG RECON (SMASHPIG)
Change-Id: I68ee79b99a4058ce6dc3ba468cd2f3c5b27e1647
---
M PaymentProviders/Worldpay/Audit/WorldpayAudit.php
A PaymentProviders/Worldpay/Audit/WpgReconciliationFile.php
2 files changed, 130 insertions(+), 0 deletions(-)
Approvals:
Ejegg: Looks good to me, approved
diff --git a/PaymentProviders/Worldpay/Audit/WorldpayAudit.php
b/PaymentProviders/Worldpay/Audit/WorldpayAudit.php
index a5ccec5..4cd2226 100644
--- a/PaymentProviders/Worldpay/Audit/WorldpayAudit.php
+++ b/PaymentProviders/Worldpay/Audit/WorldpayAudit.php
@@ -4,6 +4,7 @@
class WorldpayAudit {
+ // FIXME this never gets called and refers to a non-existent class
function retrieveFiles() {
AuditRetriever::retrieveAll( 'worldpay' );
}
@@ -19,6 +20,7 @@
'SmashPig\PaymentProviders\Worldpay\Audit\TransactionReconciliationFile',
// FIXME: Disabled due to brokenness.
//'SmashPig\PaymentProviders\Worldpay\Audit\LynkReconciliationFile',
+
'SmashPig\PaymentProviders\Worldpay\Audit\WpgReconciliationFile',
);
$data = array();
diff --git a/PaymentProviders/Worldpay/Audit/WpgReconciliationFile.php
b/PaymentProviders/Worldpay/Audit/WpgReconciliationFile.php
new file mode 100644
index 0000000..3193bae
--- /dev/null
+++ b/PaymentProviders/Worldpay/Audit/WpgReconciliationFile.php
@@ -0,0 +1,128 @@
+<?php
+namespace SmashPig\PaymentProviders\Worldpay\Audit;
+
+use \Exception;
+
+use SmashPig\Core\Logging\Logger;
+
+class WpgReconciliationFile {
+
+ const filenamePattern = '/WPG_AUDIT/';
+
+ protected $recordTypes;
+ protected $fileData = array( );
+
+ function __construct() {
+ $this->columnHeaders = array(
+ 'OrderCode',
+ 'Date',
+ 'PaymentMethod',
+ 'Status',
+ 'CurrencyCode',
+ 'Amount',
+ 'Commission',
+ 'Batch ID',
+ );
+ }
+
+ static function isMine( $path ) {
+ $filename = basename( $path );
+ return preg_match( self::filenamePattern, $filename );
+ }
+
+ function parse( $path ) {
+ $this->path = $path;
+ $this->file = fopen( $path, 'r' );
+
+ $ignoreLines = 1;
+ for ( $i = 0; $i < $ignoreLines; $i++ ) {
+ fgets( $this->file );
+ }
+
+ while ( $line = fgetcsv( $this->file, 0, "\t" ) ) {
+ try {
+ $this->parseLine( $line );
+ } catch ( JunkRowException $ex ) {
+ Logger::error( $ex->getMessage() );
+ }
+ }
+ fclose( $this->file );
+ return $this->fileData;
+ }
+
+ /**
+ * Parse one line.
+ */
+ protected function parseLine( $line ) {
+ $row = array_combine( $this->columnHeaders, $line );
+ $msg = $this->normalize( $row );
+ if ( $msg ) {
+ $this->fileData[] = $msg;
+ }
+ }
+
+ /**
+ * Normalize the pieces of the message that exist, according to the
+ * definition of a standard WMF queue message.
+ *
+ * Defaults should always be left up to the relevant queue consumer.
+ *
+ * See https://wikitech.wikimedia.org/wiki/Fundraising/Queue_messages
+ */
+ protected function normalize( $record ) {
+ $msg = array();
+
+ switch ( $record['Status'] ) {
+ case 'SENT_FOR_AUTHORISATION':
+ case 'SETTLED':
+ case 'AUTHORISED':
+ case 'REFUSED':
+ case 'SENT_FOR_REFUND':
+ return null;
+ case 'CAPTURED':
+ $queue = 'donations';
+ break;
+ case 'REFUNDED':
+ $queue = 'refund';
+ break;
+ default:
+ throw new JunkRowException( "Unknown
transaction type: " . $record['Status'] );
+ }
+
+ $msg['date'] = strtotime( $record['Date'] . ' UTC' );
+ $msg['gateway'] = 'worldpay';
+ $msg['gross'] = $record['Amount'];
+
+ if ( $queue === 'refund' ) {
+ $msg['gross_currency'] = $record['CurrencyCode'];
+ $msg['gateway_parent_id'] = $record['OrderCode'];
+ $msg['gateway_refund_id'] = $record['OrderCode'] . 'R';
+ $msg['type'] = 'refund';
+ return $msg;
+ }
+
+ $msg['gateway_txn_id'] = $record['OrderCode'];
+ $msg['currency'] = $record['CurrencyCode'];
+ $msg['payment_method'] = 'cc'; //this one is okay, because WP
only does cc at this point. Maybe forever?
+ $msg['payment_submethod'] = $this->lookupCardType(
$record['PaymentMethod'] );
+
+ return $msg;
+ }
+
+ protected function lookupCardType( $rawType ) {
+ $mapping = array(
+ 'CARTEBLEUE-SSL' => 'cb',
+ 'CB-SSL' => 'mc', // XXX this means visa or MC, no way
to tell
+ 'AMEX-SSL' => 'amex',
+ );
+
+ if ( array_key_exists( $rawType, $mapping ) ) {
+ return $mapping[$rawType];
+ }
+
+ Logger::warning( "Unknown card type [{$rawType}]" );
+ return $rawType;
+ }
+}
+
+class JunkRowException extends Exception {}
--
To view, visit https://gerrit.wikimedia.org/r/244486
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I68ee79b99a4058ce6dc3ba468cd2f3c5b27e1647
Gerrit-PatchSet: 7
Gerrit-Project: wikimedia/fundraising/SmashPig
Gerrit-Branch: master
Gerrit-Owner: Cdentinger <[email protected]>
Gerrit-Reviewer: Awight <[email protected]>
Gerrit-Reviewer: Cdentinger <[email protected]>
Gerrit-Reviewer: Ejegg <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits