Ejegg has submitted this change and it was merged.
Change subject: Update smash-pig lib
......................................................................
Update smash-pig lib
Change-Id: I14d7c66b5b913f734e60164e430f8a46db8ec850
---
M composer/installed.json
R wikimedia/smash-pig/PaymentProviders/Amazon/Actions/AddMessageToQueue.php
M wikimedia/smash-pig/PaymentProviders/Amazon/Actions/AssociateRefundParent.php
M wikimedia/smash-pig/PaymentProviders/Amazon/AmazonApi.php
M wikimedia/smash-pig/PaymentProviders/Amazon/Audit/RefundReport.php
M wikimedia/smash-pig/PaymentProviders/Amazon/Audit/SettlementReport.php
M
wikimedia/smash-pig/PaymentProviders/Amazon/ExpatriatedMessages/AmazonMessage.php
M
wikimedia/smash-pig/PaymentProviders/Amazon/ExpatriatedMessages/PaymentRefund.php
M wikimedia/smash-pig/PaymentProviders/Amazon/Tests/phpunit/AuditTest.php
M wikimedia/smash-pig/PaymentProviders/Amazon/Tests/phpunit/NormalizeTest.php
M wikimedia/smash-pig/PaymentProviders/AstroPay/Audit/AstroPayAudit.php
M wikimedia/smash-pig/PaymentProviders/AstroPay/Tests/phpunit/AuditTest.php
M wikimedia/smash-pig/PaymentProviders/Worldpay/Audit/WorldpayAudit.php
A wikimedia/smash-pig/PaymentProviders/Worldpay/Audit/WpgReconciliationFile.php
M wikimedia/smash-pig/composer.json
M wikimedia/smash-pig/config_defaults.php
16 files changed, 162 insertions(+), 26 deletions(-)
Approvals:
Ejegg: Verified; Looks good to me, approved
diff --git a/composer/installed.json b/composer/installed.json
index c7e7d5a..cf114a1 100644
--- a/composer/installed.json
+++ b/composer/installed.json
@@ -839,7 +839,7 @@
"source": {
"type": "git",
"url":
"https://gerrit.wikimedia.org/r/wikimedia/fundraising/SmashPig.git",
- "reference": "b5ff2a7d5f17aaaa33a169ca101cbea639769c90"
+ "reference": "24e682ffbc686736eeab569d20200afd5c4dc248"
},
"require": {
"amzn/login-and-pay-with-amazon-sdk-php": "dev-master",
@@ -849,7 +849,7 @@
"symfony/event-dispatcher": ">=2.1,<2.4-dev",
"symfony/http-foundation": ">=2.1,<2.4-dev"
},
- "time": "2015-10-08 14:32:04",
+ "time": "2015-10-14 20:28:15",
"type": "library",
"installation-source": "source",
"autoload": {
diff --git
a/wikimedia/smash-pig/PaymentProviders/Amazon/Actions/IncomingMessage.php
b/wikimedia/smash-pig/PaymentProviders/Amazon/Actions/AddMessageToQueue.php
similarity index 91%
rename from
wikimedia/smash-pig/PaymentProviders/Amazon/Actions/IncomingMessage.php
rename to
wikimedia/smash-pig/PaymentProviders/Amazon/Actions/AddMessageToQueue.php
index 24ce59e..697934e 100644
--- a/wikimedia/smash-pig/PaymentProviders/Amazon/Actions/IncomingMessage.php
+++ b/wikimedia/smash-pig/PaymentProviders/Amazon/Actions/AddMessageToQueue.php
@@ -5,7 +5,7 @@
use SmashPig\Core\Logging\Logger;
use SmashPig\Core\Messages\ListenerMessage;
-class IncomingMessage implements IListenerMessageAction {
+class AddMessageToQueue implements IListenerMessageAction {
public function execute( ListenerMessage $msg ) {
//FIXME: I don't like this dispatch style
$destinationQueue = $msg->getDestinationQueue();
diff --git
a/wikimedia/smash-pig/PaymentProviders/Amazon/Actions/AssociateRefundParent.php
b/wikimedia/smash-pig/PaymentProviders/Amazon/Actions/AssociateRefundParent.php
index 0d8beb3..0f5e83c 100644
---
a/wikimedia/smash-pig/PaymentProviders/Amazon/Actions/AssociateRefundParent.php
+++
b/wikimedia/smash-pig/PaymentProviders/Amazon/Actions/AssociateRefundParent.php
@@ -1,8 +1,9 @@
<?php namespace SmashPig\PaymentProviders\Amazon\Actions;
use SmashPig\Core\Actions\IListenerMessageAction;
-use SmashPig\Core\SmashPigException;
use SmashPig\Core\Logging\Logger;
+use SmashPig\Core\Messages\ListenerMessage;
+use SmashPig\Core\SmashPigException;
use SmashPig\PaymentProviders\Amazon\AmazonApi;
/**
@@ -16,10 +17,11 @@
if ( get_class( $msg ) !== self::MESSAGE_CLASS ) {
return true;
}
- $refundId = $msg->gateway_txn_id;
+ $refundId = $msg->getGatewayTransactionId();
+ Logger::info( "Looking up ID of original transaction for refund
$refundId" );
try {
$parentId = AmazonApi::findRefundParentId( $refundId );
- $msg['gateway_parent_id'] = $parentId;
+ $msg->setParentId( $parentId );
return true;
} catch( SmashPigException $ex ) {
Logger::error( $ex->getMessage() );
diff --git a/wikimedia/smash-pig/PaymentProviders/Amazon/AmazonApi.php
b/wikimedia/smash-pig/PaymentProviders/Amazon/AmazonApi.php
index cffecb3..10bbc38 100644
--- a/wikimedia/smash-pig/PaymentProviders/Amazon/AmazonApi.php
+++ b/wikimedia/smash-pig/PaymentProviders/Amazon/AmazonApi.php
@@ -37,11 +37,7 @@
"No authorizations found for order reference
$orderReferenceId!"
);
}
- if ( is_array( $details['IdList']['member'] ) ) {
- $authorizationIds = $details['IdList']['member'];
- } else {
- $authorizationIds = array( $details['IdList']['member']
);
- }
+ $authorizationIds = ( array ) $details['IdList']['member'];
// Check the status of each authorization against the order
reference
foreach ( $authorizationIds as $id ) {
$authResult = $client->getAuthorizationDetails( array(
diff --git a/wikimedia/smash-pig/PaymentProviders/Amazon/Audit/RefundReport.php
b/wikimedia/smash-pig/PaymentProviders/Amazon/Audit/RefundReport.php
index 797ff54..614eca0 100644
--- a/wikimedia/smash-pig/PaymentProviders/Amazon/Audit/RefundReport.php
+++ b/wikimedia/smash-pig/PaymentProviders/Amazon/Audit/RefundReport.php
@@ -48,7 +48,7 @@
);
$msg['gateway'] = 'amazon';
$msg['gateway_parent_id'] = $csv->currentCol( 'AmazonCaptureId'
);
- $msg['gateway_txn_id'] = $csv->currentCol( 'AmazonRefundId' );
+ $msg['gateway_refund_id'] = $csv->currentCol( 'AmazonRefundId'
);
$msg['gross'] = $csv->currentCol( 'RefundAmount' );
$msg['gross_currency'] = $csv->currentCol( 'CurrencyCode' );
if ( $csv->currentCol( 'RefundType' ) === 'SellerInitiated' ) {
diff --git
a/wikimedia/smash-pig/PaymentProviders/Amazon/Audit/SettlementReport.php
b/wikimedia/smash-pig/PaymentProviders/Amazon/Audit/SettlementReport.php
index 0867801..9b8f524 100644
--- a/wikimedia/smash-pig/PaymentProviders/Amazon/Audit/SettlementReport.php
+++ b/wikimedia/smash-pig/PaymentProviders/Amazon/Audit/SettlementReport.php
@@ -34,7 +34,6 @@
}
/**
- *
* @param HeadedCsvReader $csv
* @throws OutOfBoundsException
*/
diff --git
a/wikimedia/smash-pig/PaymentProviders/Amazon/ExpatriatedMessages/AmazonMessage.php
b/wikimedia/smash-pig/PaymentProviders/Amazon/ExpatriatedMessages/AmazonMessage.php
index b8c5bb3..2a99c98 100644
---
a/wikimedia/smash-pig/PaymentProviders/Amazon/ExpatriatedMessages/AmazonMessage.php
+++
b/wikimedia/smash-pig/PaymentProviders/Amazon/ExpatriatedMessages/AmazonMessage.php
@@ -9,7 +9,6 @@
protected $currency;
protected $date;
protected $gross;
- protected $merchantReference;
/**
* Do common normalizations. Subclasses should perform normalizations
diff --git
a/wikimedia/smash-pig/PaymentProviders/Amazon/ExpatriatedMessages/PaymentRefund.php
b/wikimedia/smash-pig/PaymentProviders/Amazon/ExpatriatedMessages/PaymentRefund.php
index c142ef0..0d043fd 100644
---
a/wikimedia/smash-pig/PaymentProviders/Amazon/ExpatriatedMessages/PaymentRefund.php
+++
b/wikimedia/smash-pig/PaymentProviders/Amazon/ExpatriatedMessages/PaymentRefund.php
@@ -21,11 +21,6 @@
$this->currency = $details['RefundAmount']['CurrencyCode'];
$this->gross = $details['RefundAmount']['Amount'];
// TODO: do we need to use FeeRefunded for anything?
-
- // Note: When we programmatically refund anything, we'll have
to set
- // the seller refund reference ID to the Amazon ID of the
capture we're
- // refunding, to avoid a torturous dance of many API calls to
find it
- $this->gateway_parent_id = $details['RefundReferenceId'];
}
public function normalizeForQueue() {
@@ -42,4 +37,8 @@
return $queueMsg;
}
+
+ public function setParentId( $parentId ) {
+ $this->gateway_parent_id = $parentId;
+ }
}
diff --git
a/wikimedia/smash-pig/PaymentProviders/Amazon/Tests/phpunit/AuditTest.php
b/wikimedia/smash-pig/PaymentProviders/Amazon/Tests/phpunit/AuditTest.php
index 7531250..0c5e16d 100644
--- a/wikimedia/smash-pig/PaymentProviders/Amazon/Tests/phpunit/AuditTest.php
+++ b/wikimedia/smash-pig/PaymentProviders/Amazon/Tests/phpunit/AuditTest.php
@@ -56,7 +56,7 @@
'gateway_parent_id' => 'P01-4968629-7654321-C070794',
'gross_currency' => 'USD',
'type' => 'refund',
- 'gateway_txn_id' => 'P01-4968629-7654321-R017571',
+ 'gateway_refund_id' => 'P01-4968629-7654321-R017571',
);
$this->assertEquals( $expected, $actual, 'Did not parse refund
correctly' );
}
@@ -75,7 +75,7 @@
'gross' => '1.00',
'gateway_parent_id' => 'P01-4968629-2345678-C070794',
'gross_currency' => 'USD',
- 'gateway_txn_id' => 'P01-4968629-2345678-R017571',
+ 'gateway_refund_id' => 'P01-4968629-2345678-R017571',
'type' => 'chargeback',
);
$this->assertEquals( $expected, $actual, 'Did not parse
chargeback correctly' );
diff --git
a/wikimedia/smash-pig/PaymentProviders/Amazon/Tests/phpunit/NormalizeTest.php
b/wikimedia/smash-pig/PaymentProviders/Amazon/Tests/phpunit/NormalizeTest.php
index de7c56b..84c23f0 100644
---
a/wikimedia/smash-pig/PaymentProviders/Amazon/Tests/phpunit/NormalizeTest.php
+++
b/wikimedia/smash-pig/PaymentProviders/Amazon/Tests/phpunit/NormalizeTest.php
@@ -42,12 +42,13 @@
}
function testNormalizeRefundCompleted() {
+ $id = 'P01-0000000-0000000-C' . mt_rand( 10000, 99999 );
$expected = array(
'correlationId' => 'amazon-P01-0000000-0000000-R00000',
'gross_currency' => 'USD',
'date' => 1357002061,
'gateway' => 'amazon',
- 'gateway_parent_id' => 'P01-0000000-0000000-C00000',
+ 'gateway_parent_id' => $id,
'gateway_refund_id' => 'P01-0000000-0000000-R00000',
'gross' => '10.0',
'gross_currency' => 'USD',
@@ -58,6 +59,7 @@
'propertiesExcludedFromExport',
);
$message = new RefundCompleted( $this->refundCompleted );
+ $message->setParentId( $id );
$normalized = $this->normalizedToArray(
$message->normalizeForQueue() );
foreach ( $stripFields as $field ) {
unset( $normalized[$field] );
diff --git
a/wikimedia/smash-pig/PaymentProviders/AstroPay/Audit/AstroPayAudit.php
b/wikimedia/smash-pig/PaymentProviders/AstroPay/Audit/AstroPayAudit.php
index fcf46fc..6288a86 100644
--- a/wikimedia/smash-pig/PaymentProviders/AstroPay/Audit/AstroPayAudit.php
+++ b/wikimedia/smash-pig/PaymentProviders/AstroPay/Audit/AstroPayAudit.php
@@ -97,7 +97,7 @@
protected function parseRefund( array $row, array &$msg ) {
$msg['contribution_tracking_id'] =
$this->getContributionTrackingId( $row['Transaction Invoice'] );
$msg['gateway_parent_id'] = $row['Transaction Reference'];
- $msg['gateway_refund_id'] = 'RFD ' . $row['Reference'];
+ $msg['gateway_refund_id'] = $row['Reference'];
$msg['gross_currency'] = $row['currency'];
$msg['log_id'] = $row['Transaction Invoice'];
$msg['type'] = strtolower( $row['Type'] );
diff --git
a/wikimedia/smash-pig/PaymentProviders/AstroPay/Tests/phpunit/AuditTest.php
b/wikimedia/smash-pig/PaymentProviders/AstroPay/Tests/phpunit/AuditTest.php
index 9eeed82..229050b 100644
--- a/wikimedia/smash-pig/PaymentProviders/AstroPay/Tests/phpunit/AuditTest.php
+++ b/wikimedia/smash-pig/PaymentProviders/AstroPay/Tests/phpunit/AuditTest.php
@@ -48,7 +48,7 @@
'date' => 1434747909,
'gross' => '5.00',
'gateway_parent_id' => '7654321',
- 'gateway_refund_id' => 'RFD 12345',
+ 'gateway_refund_id' => '12345',
'gross_currency' => 'BRL',
'log_id' => '314159265.0',
'type' => 'refund',
@@ -70,7 +70,7 @@
'date' => 1434747909,
'gross' => '5.00',
'gateway_parent_id' => '7654321',
- 'gateway_refund_id' => 'RFD 12345',
+ 'gateway_refund_id' => '12345',
'gross_currency' => 'BRL',
'log_id' => '314159265.0',
'type' => 'chargeback',
diff --git
a/wikimedia/smash-pig/PaymentProviders/Worldpay/Audit/WorldpayAudit.php
b/wikimedia/smash-pig/PaymentProviders/Worldpay/Audit/WorldpayAudit.php
index a5ccec5..4cd2226 100644
--- a/wikimedia/smash-pig/PaymentProviders/Worldpay/Audit/WorldpayAudit.php
+++ b/wikimedia/smash-pig/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/wikimedia/smash-pig/PaymentProviders/Worldpay/Audit/WpgReconciliationFile.php
b/wikimedia/smash-pig/PaymentProviders/Worldpay/Audit/WpgReconciliationFile.php
new file mode 100644
index 0000000..3193bae
--- /dev/null
+++
b/wikimedia/smash-pig/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 {}
diff --git a/wikimedia/smash-pig/composer.json
b/wikimedia/smash-pig/composer.json
index 8f56671..be9f26e 100644
--- a/wikimedia/smash-pig/composer.json
+++ b/wikimedia/smash-pig/composer.json
@@ -16,6 +16,10 @@
{
"name": "Adam Roses Wight",
"email": "[email protected]"
+ },
+ {
+ "name": "Elliott Eggleston",
+ "email": "[email protected]"
}
],
"require": {
diff --git a/wikimedia/smash-pig/config_defaults.php
b/wikimedia/smash-pig/config_defaults.php
index ca9fa67..85a4589 100644
--- a/wikimedia/smash-pig/config_defaults.php
+++ b/wikimedia/smash-pig/config_defaults.php
@@ -14,6 +14,11 @@
'inst-args' => array( 'pending' ),
),
+ 'refund' => array(
+ 'class' =>
'SmashPig\Core\DataStores\StompDataStore',
+ 'inst-args' => array( 'refund' ),
+ ),
+
'limbo' => array(
'class' =>
'SmashPig\Core\DataStores\StompDataStore',
'inst-args' => array( 'limbo' ),
@@ -117,9 +122,9 @@
'amazon' => array(
'actions' => array(
-
'SmashPig\PaymentProviders\Amazon\Actions\IncomingMessage',
'SmashPig\PaymentProviders\Amazon\Actions\CloseOrderReference',
'SmashPig\PaymentProviders\Amazon\Actions\AssociateRefundParent',
+
'SmashPig\PaymentProviders\Amazon\Actions\AddMessageToQueue',
),
'endpoints' => array(
--
To view, visit https://gerrit.wikimedia.org/r/246410
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I14d7c66b5b913f734e60164e430f8a46db8ec850
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm/vendor
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[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