Ejegg has uploaded a new change for review.
https://gerrit.wikimedia.org/r/286254
Change subject: Use TaggedLogger instead of static calls
......................................................................
Use TaggedLogger instead of static calls
Gets prefixes without risking overload.
Bug: T129946
Change-Id: I662686f257a32d22df623b6c2def58405356c51f
---
M PaymentProviders/Adyen/Jobs/ProcessCaptureRequestJob.php
M PaymentProviders/Adyen/Jobs/RecordCaptureJob.php
2 files changed, 30 insertions(+), 26 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/SmashPig
refs/changes/54/286254/1
diff --git a/PaymentProviders/Adyen/Jobs/ProcessCaptureRequestJob.php
b/PaymentProviders/Adyen/Jobs/ProcessCaptureRequestJob.php
index c177634..1d765fb 100644
--- a/PaymentProviders/Adyen/Jobs/ProcessCaptureRequestJob.php
+++ b/PaymentProviders/Adyen/Jobs/ProcessCaptureRequestJob.php
@@ -3,6 +3,7 @@
use SmashPig\Core\Configuration;
use SmashPig\Core\Jobs\RunnableJob;
use SmashPig\Core\Logging\Logger;
+use SmashPig\Core\Logging\TaggedLogger;
use SmashPig\CrmLink\Messages\DonationInterfaceAntifraud;
use SmashPig\CrmLink\Messages\DonationInterfaceMessage;
use SmashPig\PaymentProviders\Adyen\AdyenPaymentsAPI;
@@ -25,6 +26,11 @@
protected $pspReference;
protected $avsResult;
protected $cvvResult;
+ /**
+ * @var TaggedLogger
+ */
+ protected $logger;
+
// Actions to take after examining capture request and queue message
const ACTION_PROCESS = 'process'; // all clear to capture payment
const ACTION_REJECT = 'reject'; // very likely fraud - cancel the
authorization
@@ -47,8 +53,8 @@
}
public function execute() {
- Logger::enterContext( "corr_id-{$this->correlationId}" );
- Logger::info(
+ $this->logger = Logger::getTaggedLogger(
"corr_id-{$this->correlationId}" );
+ $this->logger->info(
"Running capture request job on account
'{$this->account}' with reference '{$this->pspReference}' " .
"and correlation id '{$this->correlationId}'."
);
@@ -59,7 +65,7 @@
// but have not yet received notification of capture success.
Either case can
// occur when a donor submits their credit card details
multiple times against
// a single order ID. We should cancel all the duplicate
authorizations.
- Logger::debug( 'Attempting to locate associated message in
pending queue.' );
+ $this->logger->debug( 'Attempting to locate associated message
in pending queue.' );
/**
* @var \SmashPig\Core\DataStores\KeyedOpaqueDataStore
*/
@@ -72,7 +78,7 @@
case self::ACTION_PROCESS:
// Attempt to capture the payment
$api = $this->getApi();
- Logger::info(
+ $this->logger->info(
"Attempting capture API call for
currency '{$this->currency}', " .
"amount '{$this->amount}', reference
'{$this->pspReference}'."
);
@@ -80,7 +86,7 @@
if ( $captureResult ) {
// Success!
- Logger::info(
+ $this->logger->info(
"Successfully captured payment!
Returned reference: '{$captureResult}'. " .
'Marking pending queue
message as captured.'
);
@@ -91,7 +97,7 @@
// Some kind of error in the request.
We should keep the pending
// message, complain loudly, and move
this capture job to the
// damaged queue.
- Logger::error(
+ $this->logger->error(
"Failed to capture payment on
account '{$this->account}' with reference " .
"'{$this->pspReference}' and correlation id '{$this->correlationId}'.",
$queueMessage
@@ -122,15 +128,14 @@
break;
}
- Logger::leaveContext();
return $success;
}
protected function determineAction( $queueMessage ) {
if ( $queueMessage && ( $queueMessage instanceof
DonationInterfaceMessage ) ) {
- Logger::debug( 'A valid message was obtained from the
pending queue.' );
+ $this->logger->debug( 'A valid message was obtained
from the pending queue.' );
} else {
- Logger::warning(
+ $this->logger->warning(
"Could not find a processable message for PSP
Reference '{$this->pspReference}' and correlation ".
"ID '{$this->correlationId}'.",
$queueMessage
@@ -138,7 +143,7 @@
return self::ACTION_DUPLICATE;
}
if ( $queueMessage->captured ) {
- Logger::info(
+ $this->logger->info(
"Duplicate PSP Reference
'{$this->pspReference}' for correlation ID '{$this->correlationId}'.",
$queueMessage
);
@@ -150,24 +155,24 @@
protected function getRiskAction( DonationInterfaceMessage
$queueMessage ) {
$config = Configuration::getDefaultConfig();
$riskScore = $queueMessage->risk_score ?
$queueMessage->risk_score : 0;
- Logger::debug( "Base risk score from payments site is
$riskScore, " .
+ $this->logger->debug( "Base risk score from payments site is
$riskScore, " .
"raw CVV result is '{$this->cvvResult}' and raw AVS
result is '{$this->avsResult}'." );
$cvvMap = $config->val( 'fraud-filters/cvv-map' );
$avsMap = $config->val( 'fraud-filters/avs-map' );
$scoreBreakdown = array();
if ( array_key_exists( $this->cvvResult, $cvvMap ) ) {
$scoreBreakdown['getCVVResult'] = $cvvScore =
$cvvMap[$this->cvvResult];
- Logger::debug( "CVV result '{$this->cvvResult}' adds
risk score $cvvScore." );
+ $this->logger->debug( "CVV result '{$this->cvvResult}'
adds risk score $cvvScore." );
$riskScore += $cvvScore;
} else {
- Logger::warning( "CVV result '{$this->cvvResult}' not
found in cvv-map.", $cvvMap );
+ $this->logger->warning( "CVV result
'{$this->cvvResult}' not found in cvv-map.", $cvvMap );
}
if ( array_key_exists( $this->avsResult, $avsMap ) ) {
$scoreBreakdown['getAVSResult'] = $avsScore =
$avsMap[$this->avsResult];
- Logger::debug( "AVS result '{$this->avsResult}' adds
risk score $avsScore." );
+ $this->logger->debug( "AVS result '{$this->avsResult}'
adds risk score $avsScore." );
$riskScore += $avsScore;
} else {
- Logger::warning( "AVS result '{$this->avsResult}' not
found in avs-map.", $avsMap );
+ $this->logger->warning( "AVS result
'{$this->avsResult}' not found in avs-map.", $avsMap );
}
$action = self::ACTION_PROCESS;
if ( $riskScore >= $config->val(
'fraud-filters/review-threshold' ) ) {
@@ -184,7 +189,7 @@
$antifraudMessage = DonationInterfaceAntifraud::factory(
$queueMessage, $this->merchantReference, $riskScore,
$scoreBreakdown, $action
);
- Logger::debug( "Sending antifraud message with risk score
$riskScore and action $action." );
+ $this->logger->debug( "Sending antifraud message with risk
score $riskScore and action $action." );
Configuration::getDefaultConfig()->object(
'data-store/antifraud' )->addObject( $antifraudMessage );
}
@@ -198,14 +203,14 @@
}
protected function cancelAuthorization() {
- Logger::debug( "Cancelling authorization with reference
'{$this->pspReference}'" );
+ $this->logger->debug( "Cancelling authorization with reference
'{$this->pspReference}'" );
$api = $this->getApi();
$result = $api->cancel( $this->pspReference );
if ( $result ) {
- Logger::debug( "Successfully cancelled authorization" );
+ $this->logger->debug( "Successfully cancelled
authorization" );
} else {
// Not a big deal
- Logger::warning( "Failed to cancel authorization, it
will remain in the payment console" );
+ $this->logger->warning( "Failed to cancel
authorization, it will remain in the payment console" );
}
}
}
diff --git a/PaymentProviders/Adyen/Jobs/RecordCaptureJob.php
b/PaymentProviders/Adyen/Jobs/RecordCaptureJob.php
index d2eb544..d864c66 100644
--- a/PaymentProviders/Adyen/Jobs/RecordCaptureJob.php
+++ b/PaymentProviders/Adyen/Jobs/RecordCaptureJob.php
@@ -34,39 +34,38 @@
}
public function execute() {
- Logger::enterContext( "corr_id-{$this->correlationId}" );
- Logger::info(
+ $logger = Logger::getTaggedLogger(
"corr_id-{$this->correlationId}" );
+ $logger->info(
"Recording successful capture on account
'{$this->account}' with authorization reference " .
"'{$this->originalReference}' and correlation
id '{$this->correlationId}'."
);
$config = Configuration::getDefaultConfig();
// Find the details from the payment site in the pending queue.
- Logger::debug( 'Attempting to locate associated message in
pending queue' );
+ $logger->debug( 'Attempting to locate associated message in
pending queue' );
$pendingQueue = $config->object( 'data-store/pending' );
$queueMessage = $pendingQueue->queueGetObject( null,
$this->correlationId );
if ( $queueMessage && ( $queueMessage instanceof
DonationInterfaceMessage ) ) {
- Logger::debug( 'A valid message was obtained from the
pending queue' );
+ $logger->debug( 'A valid message was obtained from the
pending queue' );
// Add the gateway transaction ID and send it to the
completed queue
$queueMessage->gateway_txn_id =
$this->originalReference;
$config->object( 'data-store/verified' )->addObject(
$queueMessage );
// Remove it from the pending queue
- Logger::debug( "Removing all references to donation in
pending queue" );
+ $logger->debug( "Removing all references to donation in
pending queue" );
$pendingQueue->queueAckObject();
$pendingQueue->removeObjectsById( $this->correlationId
);
} else {
- Logger::error(
+ $logger->error(
"Could not find a processable message for
authorization Reference '{$this->originalReference}' " .
"and correlation ID
'{$this->correlationId}'.",
$queueMessage
);
}
- Logger::leaveContext();
return true;
}
}
--
To view, visit https://gerrit.wikimedia.org/r/286254
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I662686f257a32d22df623b6c2def58405356c51f
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/SmashPig
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits