jenkins-bot has submitted this change and it was merged. Change subject: Fix Adyen audit downloads ......................................................................
Fix Adyen audit downloads Oops, I was pushing an object instead of an array. Bug: T148216 Change-Id: I8c8215bb2c5875bf3eae0fc13eb2a86f60f9c510 --- M PaymentProviders/Adyen/ExpatriatedMessages/ReportAvailable.php M PaymentProviders/Adyen/Jobs/DownloadReportJob.php A PaymentProviders/Adyen/Tests/phpunit/ReportAvailableTest.php 3 files changed, 86 insertions(+), 8 deletions(-) Approvals: Cdentinger: Looks good to me, approved jenkins-bot: Verified diff --git a/PaymentProviders/Adyen/ExpatriatedMessages/ReportAvailable.php b/PaymentProviders/Adyen/ExpatriatedMessages/ReportAvailable.php index 3ad91d6..062ab66 100644 --- a/PaymentProviders/Adyen/ExpatriatedMessages/ReportAvailable.php +++ b/PaymentProviders/Adyen/ExpatriatedMessages/ReportAvailable.php @@ -1,7 +1,8 @@ <?php namespace SmashPig\PaymentProviders\Adyen\ExpatriatedMessages; -use SmashPig\Core\Context; use SmashPig\Core\Logging\Logger; +use SmashPig\Core\QueueConsumers\BaseQueueConsumer; +use SmashPig\CrmLink\Messages\SourceFields; use SmashPig\PaymentProviders\Adyen\Jobs\DownloadReportJob; class ReportAvailable extends AdyenMessage { @@ -20,14 +21,16 @@ $this->reason ); - $jobQueueObj = Context::get()->getConfiguration()->object( 'data-store/jobs-adyen' ); + $jobQueue = BaseQueueConsumer::getQueue( 'jobs-adyen' ); if ( strpos( $this->pspReference, 'settlement_detail_report' ) === 0 ) { - $jobQueueObj->push( - DownloadReportJob::factory( - $this->merchantAccountCode, - $this->reason - ) + $jobObject = DownloadReportJob::factory( + $this->merchantAccountCode, + $this->reason ); + // FIXME: write queue wrapper to do these next two steps + SourceFields::addToMessage( $jobObject ); + $jobArray = json_decode( $jobObject->toJson(), true ); + $jobQueue->push( $jobArray ); } else { // We don't know how to handle this report yet Logger::notice( "Do not know how to handle report with name '{$this->pspReference}'" ); diff --git a/PaymentProviders/Adyen/Jobs/DownloadReportJob.php b/PaymentProviders/Adyen/Jobs/DownloadReportJob.php index 37f3ed1..147e12d 100644 --- a/PaymentProviders/Adyen/Jobs/DownloadReportJob.php +++ b/PaymentProviders/Adyen/Jobs/DownloadReportJob.php @@ -12,6 +12,8 @@ * @package SmashPig\PaymentProviders\Adyen\Jobs */ class DownloadReportJob extends RunnableJob { + // Helps locate these in e.g. damaged message db + public $gateway = 'adyen'; /** @var TaggedLogger */ protected $logger; @@ -20,7 +22,9 @@ protected $reportUrl; protected $downloadLoc; - protected $propertiesExcludedFromExport = array( 'logger' ); + protected $propertiesExcludedFromExport = array( + 'logger', 'downloadLoc' + ); public static function factory( $account, $url ) { $obj = new DownloadReportJob(); diff --git a/PaymentProviders/Adyen/Tests/phpunit/ReportAvailableTest.php b/PaymentProviders/Adyen/Tests/phpunit/ReportAvailableTest.php new file mode 100644 index 0000000..d6ed607 --- /dev/null +++ b/PaymentProviders/Adyen/Tests/phpunit/ReportAvailableTest.php @@ -0,0 +1,71 @@ +<?php +namespace SmashPig\PaymentProviders\Adyen\Tests; + +use PHPQueue\Interfaces\FifoQueueStore; +use SmashPig\Core\Configuration; +use SmashPig\Core\Context; +use SmashPig\Core\QueueConsumers\BaseQueueConsumer; +use SmashPig\Core\UtcDate; +use SmashPig\PaymentProviders\Adyen\ExpatriatedMessages\ReportAvailable; +use SmashPig\Tests\BaseSmashPigUnitTestCase; + +class ReportAvailableTest extends BaseSmashPigUnitTestCase { + /** + * @var Configuration + */ + protected $config; + + /** + * @var FifoQueueStore + */ + protected $jobQueue; + + public function setUp() { + parent::setUp(); + $this->config = AdyenTestConfiguration::createWithSuccessfulApi(); + Context::initWithLogger( $this->config ); + $this->jobQueue = BaseQueueConsumer::getQueue( 'jobs-adyen' ); + $this->jobQueue->createTable( 'jobs-adyen' ); + } + + public function testReportAvailable() { + $filename = 'settlement_detail_report_2016_10_13.csv'; + $account = 'WikimediaTest'; + $url = "https://example.com/reports/download/MerchantAccount/$account/$filename"; + $reportAvailable = new ReportAvailable(); + + $reportAvailable->correlationId = 'adyen-' . mt_rand(); + $reportAvailable->merchantAccountCode = $account; + $reportAvailable->merchantReference = mt_rand(); + $reportAvailable->pspReference = $filename; + $reportAvailable->reason = $url; + $reportAvailable->eventDate = '2016-10-14T12:06:20.496+02:00'; + + $reportAvailable->runActionChain(); + + $job = $this->jobQueue->pop(); + + $now = UtcDate::getUtcTimestamp(); + $diff = abs( $job['source_enqueued_time'] ) - $now; + $this->assertTrue( $diff < 60, 'Odd enqueued time' ); + $unsetFields = array( + 'source_enqueued_time', 'source_host', 'source_run_id', + 'source_version', 'propertiesExcludedFromExport', + 'propertiesExportedAsKeys', + ); + foreach ( $unsetFields as $fieldName ) { + unset( $job[$fieldName] ); + } + $expected = array( + 'php-message-class' => 'SmashPig\PaymentProviders\Adyen\Jobs\DownloadReportJob', + 'reportUrl' => $url, + 'account' => $account, + 'source_name' => 'SmashPig', + 'source_type' => 'listener', + 'correlationId' => '', + 'gateway' => 'adyen', + ); + $this->assertEquals( $expected, $job ); + } + +} -- To view, visit https://gerrit.wikimedia.org/r/315999 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I8c8215bb2c5875bf3eae0fc13eb2a86f60f9c510 Gerrit-PatchSet: 1 Gerrit-Project: wikimedia/fundraising/SmashPig Gerrit-Branch: master Gerrit-Owner: Ejegg <eeggles...@wikimedia.org> Gerrit-Reviewer: Awight <awi...@wikimedia.org> Gerrit-Reviewer: Cdentinger <cdentin...@wikimedia.org> Gerrit-Reviewer: Siebrand <siebr...@kitano.nl> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits