jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/369748 )
Change subject: Add AuditParser interface, other audit cleanup ...................................................................... Add AuditParser interface, other audit cleanup Get rid of unnecessary / undeclared fields, fix missing 'use', reset fileData on each new parse. Breaking change: Amazon audit parser renamed, just have to update the class name in the amazon audit module within crm. Change-Id: Icf3f9d927b6d3623aaf3d5c072f7d0b2e15c4307 --- A Core/DataFiles/AuditParser.php M PaymentProviders/Adyen/Audit/AdyenAudit.php M PaymentProviders/Adyen/ReferenceData.php R PaymentProviders/Amazon/Audit/AmazonAudit.php M PaymentProviders/Amazon/Audit/RefundReport.php M PaymentProviders/Amazon/Audit/SettlementReport.php M PaymentProviders/Amazon/Tests/phpunit/AuditTest.php M PaymentProviders/AstroPay/Audit/AstroPayAudit.php M PaymentProviders/Ingenico/Audit/IngenicoAudit.php M PaymentProviders/Ingenico/ReferenceData.php 10 files changed, 108 insertions(+), 95 deletions(-) Approvals: Mepps: Looks good to me, approved jenkins-bot: Verified diff --git a/Core/DataFiles/AuditParser.php b/Core/DataFiles/AuditParser.php new file mode 100644 index 0000000..5dd777e --- /dev/null +++ b/Core/DataFiles/AuditParser.php @@ -0,0 +1,14 @@ +<?php + +namespace SmashPig\Core\DataFiles; + +interface AuditParser { + + /** + * Parse an audit file and normalize records + * + * @param string $path Full path of the file to be parsed + * @return array of donation, refund, and chargeback records + */ + public function parseFile( $path ); +} diff --git a/PaymentProviders/Adyen/Audit/AdyenAudit.php b/PaymentProviders/Adyen/Audit/AdyenAudit.php index 3ea8745..e30a79d 100644 --- a/PaymentProviders/Adyen/Audit/AdyenAudit.php +++ b/PaymentProviders/Adyen/Audit/AdyenAudit.php @@ -1,6 +1,8 @@ <?php namespace SmashPig\PaymentProviders\Adyen\Audit; use OutOfBoundsException; +use SmashPig\Core\DataFiles\AuditParser; +use SmashPig\Core\Logging\Logger; use SmashPig\Core\NormalizationException; use SmashPig\Core\UtcDate; use SmashPig\PaymentProviders\Adyen\ReferenceData; @@ -12,11 +14,41 @@ * Sends donations, chargebacks, and refunds to queue. * https://docs.adyen.com/manuals/reporting-manual/settlement-detail-report-structure/settlement-detail-report-journal-types */ -class AdyenAudit { +class AdyenAudit implements AuditParser { - protected $columnHeaders; - protected $ignoredStatuses; - protected $fileData = array(); + protected $columnHeaders = array( + 'Company Account', + 'Merchant Account', + 'Psp Reference', + 'Merchant Reference', + 'Payment Method', + 'Creation Date', + 'TimeZone', + 'Type', + 'Modification Reference', + 'Gross Currency', + 'Gross Debit (GC)', + 'Gross Credit (GC)', + 'Exchange Rate', + 'Net Currency', + 'Net Debit (NC)', + 'Net Credit (NC)', + 'Commission (NC)', + 'Markup (NC)', + 'Scheme Fees (NC)', + 'Interchange (NC)', + 'Payment Method Variant', + 'Modification Merchant Reference', + 'Batch Number', + 'Reserved4', + 'Reserved5', + 'Reserved6', + 'Reserved7', + 'Reserved8', + 'Reserved9', + 'Reserved10', + ); + protected static $ignoredTypes = array( 'fee', 'misccosts', @@ -38,52 +70,18 @@ 'paidoutreversed', ); - public function __construct() { - $this->columnHeaders = array( - 'Company Account', - 'Merchant Account', - 'Psp Reference', - 'Merchant Reference', - 'Payment Method', - 'Creation Date', - 'TimeZone', - 'Type', - 'Modification Reference', - 'Gross Currency', - 'Gross Debit (GC)', - 'Gross Credit (GC)', - 'Exchange Rate', - 'Net Currency', - 'Net Debit (NC)', - 'Net Credit (NC)', - 'Commission (NC)', - 'Markup (NC)', - 'Scheme Fees (NC)', - 'Interchange (NC)', - 'Payment Method Variant', - 'Modification Merchant Reference', - 'Batch Number', - 'Reserved4', - 'Reserved5', - 'Reserved6', - 'Reserved7', - 'Reserved8', - 'Reserved9', - 'Reserved10', - ); - } + protected $fileData; - // TODO base class this? public function parseFile( $path ) { - $this->path = $path; - $this->file = fopen( $path, 'r' ); + $this->fileData = array(); + $file = fopen( $path, 'r' ); $ignoreLines = 1; for ( $i = 0; $i < $ignoreLines; $i++ ) { - fgets( $this->file ); + fgets( $file ); } - while ( $line = fgetcsv( $this->file, 0, ',', '"', '\\' ) ) { + while ( $line = fgetcsv( $file, 0, ',', '"', '\\' ) ) { try { $this->parseLine( $line ); } catch ( NormalizationException $ex ) { @@ -91,7 +89,7 @@ Logger::error( $ex->getMessage() ); } } - fclose( $this->file ); + fclose( $file ); return $this->fileData; } diff --git a/PaymentProviders/Adyen/ReferenceData.php b/PaymentProviders/Adyen/ReferenceData.php index f4c5713..c973f7a 100644 --- a/PaymentProviders/Adyen/ReferenceData.php +++ b/PaymentProviders/Adyen/ReferenceData.php @@ -4,7 +4,7 @@ class ReferenceData { - static $methods = array( + protected static $methods = array( 'alipay' => array( 'method' => 'ew', 'submethod' => 'ew_alipay', diff --git a/PaymentProviders/Amazon/Audit/AuditParser.php b/PaymentProviders/Amazon/Audit/AmazonAudit.php similarity index 84% rename from PaymentProviders/Amazon/Audit/AuditParser.php rename to PaymentProviders/Amazon/Audit/AmazonAudit.php index d474c89..2d9db5d 100644 --- a/PaymentProviders/Amazon/Audit/AuditParser.php +++ b/PaymentProviders/Amazon/Audit/AmazonAudit.php @@ -1,11 +1,12 @@ <?php namespace SmashPig\PaymentProviders\Amazon\Audit; use SmashPig\Core\Context; +use SmashPig\Core\DataFiles\AuditParser; /** * Parses off-Amazon payments reports retrieved from MWS */ -class AuditParser { +class AmazonAudit implements AuditParser { public function parseFile( $path ) { $config = Context::get()->getProviderConfiguration(); diff --git a/PaymentProviders/Amazon/Audit/RefundReport.php b/PaymentProviders/Amazon/Audit/RefundReport.php index 614eca0..7b745b7 100644 --- a/PaymentProviders/Amazon/Audit/RefundReport.php +++ b/PaymentProviders/Amazon/Audit/RefundReport.php @@ -10,13 +10,14 @@ * http://amazonpayments.s3.amazonaws.com/documents/Sample%20Settlement%20Report.pdf#page=25 */ class RefundReport { - protected $fileData = array(); + protected $fileData; public static function isMine( $filename ) { return preg_match( '/.*REFUND_DATA.*csv/', $filename ); } public function parse( $path ) { + $this->fileData = array(); $csv = new HeadedCsvReader( $path, ',', 4096, 0 ); while ( $csv->valid() ) { diff --git a/PaymentProviders/Amazon/Audit/SettlementReport.php b/PaymentProviders/Amazon/Audit/SettlementReport.php index c96e28a..7fd3804 100644 --- a/PaymentProviders/Amazon/Audit/SettlementReport.php +++ b/PaymentProviders/Amazon/Audit/SettlementReport.php @@ -12,13 +12,14 @@ */ class SettlementReport { - protected $fileData = array(); + protected $fileData; public static function isMine( $filename ) { return preg_match( '/.*SETTLEMENT_DATA.*csv/', $filename ); } public function parse( $path ) { + $this->fileData = array(); // Skip 5 lines at start of file; $csv = new HeadedCsvReader( $path, ',', 4096, 5 ); diff --git a/PaymentProviders/Amazon/Tests/phpunit/AuditTest.php b/PaymentProviders/Amazon/Tests/phpunit/AuditTest.php index 29f13b0..aca8e15 100644 --- a/PaymentProviders/Amazon/Tests/phpunit/AuditTest.php +++ b/PaymentProviders/Amazon/Tests/phpunit/AuditTest.php @@ -3,7 +3,7 @@ use SmashPig\Core\Context; use SmashPig\Tests\BaseSmashPigUnitTestCase; -use SmashPig\PaymentProviders\Amazon\Audit\AuditParser; +use SmashPig\PaymentProviders\Amazon\Audit\AmazonAudit; /** * Verify Amazon audit file processor functions @@ -20,7 +20,7 @@ * Normal donation */ public function testProcessDonation() { - $processor = new AuditParser(); + $processor = new AmazonAudit(); $output = $processor->parseFile( __DIR__ . '/../Data/audit/2015-10-01-SETTLEMENT_DATA_371273040777777.csv' ); $this->assertEquals( 1, count( $output ), 'Should have found one donation' ); $actual = $output[0]; @@ -42,7 +42,7 @@ * Now try a refund */ public function testProcessRefund() { - $processor = new AuditParser(); + $processor = new AmazonAudit(); $output = $processor->parseFile( __DIR__ . '/../Data/audit/2015-10-06-REFUND_DATA_414749300022222.csv' ); $this->assertEquals( 1, count( $output ), 'Should have found one refund' ); $actual = $output[0]; @@ -62,7 +62,7 @@ * And a chargeback */ public function testProcessChargeback() { - $processor = new AuditParser(); + $processor = new AmazonAudit(); $output = $processor->parseFile( __DIR__ . '/../Data/audit/2015-10-06-REFUND_DATA_414749300033333.csv' ); $this->assertEquals( 1, count( $output ), 'Should have found one chargeback' ); $actual = $output[0]; diff --git a/PaymentProviders/AstroPay/Audit/AstroPayAudit.php b/PaymentProviders/AstroPay/Audit/AstroPayAudit.php index dc19101..9ef92f2 100644 --- a/PaymentProviders/AstroPay/Audit/AstroPayAudit.php +++ b/PaymentProviders/AstroPay/Audit/AstroPayAudit.php @@ -1,59 +1,55 @@ <?php namespace SmashPig\PaymentProviders\AstroPay\Audit; use OutOfBoundsException; +use SmashPig\Core\DataFiles\AuditParser; use SmashPig\Core\Logging\Logger; use SmashPig\Core\NormalizationException; use SmashPig\Core\UtcDate; use SmashPig\PaymentProviders\AstroPay\ReferenceData; -class AstroPayAudit { +class AstroPayAudit implements AuditParser { - protected $columnHeaders; - protected $ignoredStatuses; - protected $fileData = array(); - protected $file; + protected $columnHeaders = array( + 'Type', // 'Payment' or 'Refund' + 'Creation date', // YYYY-MM-dd HH:mm:ss + 'Settlement date', // same format + 'Reference', // gateway_trxn_id + 'Invoice', // ct_id.attempt_num + 'Country', + 'Payment Method', // corresponds to our payment_submethod + 'Payment Method Type', // our payment_method + 'Net Amount (local)', + 'Amount (USD)', // gross, including fee + 'currency', // yup, this one is lower case + 'Status', + 'User Mail', + // These two fields refer to the original donation for refunds + 'Transaction Reference', + 'Transaction Invoice', + 'Fee', // In USD. AstroPay's processing fee + 'IOF', // In USD. Fee for financial transactions in Brazil + // The IOF is included in AstroPay's fee, but broken out by request + ); - public function __construct() { - $this->columnHeaders = array( - 'Type', // 'Payment' or 'Refund' - 'Creation date', // YYYY-MM-dd HH:mm:ss - 'Settlement date', // same format - 'Reference', // gateway_trxn_id - 'Invoice', // ct_id.attempt_num - 'Country', - 'Payment Method', // corresponds to our payment_submethod - 'Payment Method Type', // our payment_method - 'Net Amount (local)', - 'Amount (USD)', // gross, including fee - 'currency', // yup, this one is lower case - 'Status', - 'User Mail', - // These two fields refer to the original donation for refunds - 'Transaction Reference', - 'Transaction Invoice', - 'Fee', // In USD. AstroPay's processing fee - 'IOF', // In USD. Fee for financial transactions in Brazil - // The IOF is included in AstroPay's fee, but broken out by request - ); - // We don't need do anything with some audit lines - $this->ignoredStatuses = array( - 'Cancelled', // User pressed cancel or async payment expired - 'In process', // Chargeback is... charging back? 'Settled' means done - 'Reimbursed', // Chargeback settled in our favor - not refunding - 'Waiting Details', // Refund is in limbo; we'll wait for 'Completed' - ); - } + protected $ignoredStatuses = array( + 'Cancelled', // User pressed cancel or async payment expired + 'In process', // Chargeback is... charging back? 'Settled' means done + 'Reimbursed', // Chargeback settled in our favor - not refunding + 'Waiting Details', // Refund is in limbo; we'll wait for 'Completed' + ); + + protected $fileData; public function parseFile( $path ) { - $this->path = $path; - $this->file = fopen( $path, 'r' ); + $this->fileData = array(); + $file = fopen( $path, 'r' ); $ignoreLines = 1; for ( $i = 0; $i < $ignoreLines; $i++ ) { - fgets( $this->file ); + fgets( $file ); } - while ( $line = fgetcsv( $this->file, 0, ';', '"', '\\' ) ) { + while ( $line = fgetcsv( $file, 0, ';', '"', '\\' ) ) { try { $this->parseLine( $line ); } catch ( NormalizationException $ex ) { @@ -61,7 +57,7 @@ Logger::error( $ex->getMessage() ); } } - fclose( $this->file ); + fclose( $file ); return $this->fileData; } diff --git a/PaymentProviders/Ingenico/Audit/IngenicoAudit.php b/PaymentProviders/Ingenico/Audit/IngenicoAudit.php index 738c06d..2adc816 100644 --- a/PaymentProviders/Ingenico/Audit/IngenicoAudit.php +++ b/PaymentProviders/Ingenico/Audit/IngenicoAudit.php @@ -3,13 +3,14 @@ use DOMDocument; use DOMElement; use RuntimeException; +use SmashPig\Core\DataFiles\AuditParser; use SmashPig\Core\Logging\Logger; use SmashPig\Core\UtcDate; use SmashPig\PaymentProviders\Ingenico\ReferenceData; -class IngenicoAudit { +class IngenicoAudit implements AuditParser { - protected $fileData = array(); + protected $fileData; protected $donationMap = array( 'PaymentAmount' => 'gross', @@ -51,6 +52,7 @@ ); public function parseFile( $path ) { + $this->fileData = array(); $unzippedFullPath = $this->getUnzippedFile( $path ); // load the XML into a DOMDocument. diff --git a/PaymentProviders/Ingenico/ReferenceData.php b/PaymentProviders/Ingenico/ReferenceData.php index 25e5a86..b2f69c4 100644 --- a/PaymentProviders/Ingenico/ReferenceData.php +++ b/PaymentProviders/Ingenico/ReferenceData.php @@ -7,7 +7,7 @@ class ReferenceData { // FIXME: replace this whole class with payment_(sub)method.yaml files - static $methods = array( + protected static $methods = array( '1' => array( 'payment_method' => 'cc', 'payment_submethod' => 'visa' ), '2' => array( 'payment_method' => 'cc', 'payment_submethod' => 'amex' ), '3' => array( 'payment_method' => 'cc', 'payment_submethod' => 'mc' ), -- To view, visit https://gerrit.wikimedia.org/r/369748 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Icf3f9d927b6d3623aaf3d5c072f7d0b2e15c4307 Gerrit-PatchSet: 2 Gerrit-Project: wikimedia/fundraising/SmashPig Gerrit-Branch: master Gerrit-Owner: Ejegg <ej...@ejegg.com> Gerrit-Reviewer: Ejegg <ej...@ejegg.com> Gerrit-Reviewer: Mepps <me...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits