Cdentinger has submitted this change and it was merged.
Change subject: Add message to antifraud queue in capture job
......................................................................
Add message to antifraud queue in capture job
TODO: update queue consumer to correctly combine multiple messages
for the same transaction.
Bug: T122244
Change-Id: I527add8e3ff061b7f85dead921eed27beb49f48c
---
M CrmLink/Messages/DonationInterfaceAntifraud.php
M PaymentProviders/Adyen/Jobs/ProcessCaptureRequestJob.php
M config_defaults.php
3 files changed, 44 insertions(+), 4 deletions(-)
Approvals:
Cdentinger: Looks good to me, approved
jenkins-bot: Verified
diff --git a/CrmLink/Messages/DonationInterfaceAntifraud.php
b/CrmLink/Messages/DonationInterfaceAntifraud.php
index 4dc0973..aa836a6 100644
--- a/CrmLink/Messages/DonationInterfaceAntifraud.php
+++ b/CrmLink/Messages/DonationInterfaceAntifraud.php
@@ -17,4 +17,27 @@
public $server = '';
public $user_ip = '';
public $validation_action = '';
+
+ public static function factory(
+ DonationInterfaceMessage $message,
+ $riskScore,
+ $scoreBreakdown = array(),
+ $validationAction = 'process' ) {
+
+ $obj = new DonationInterfaceAntifraud();
+ $obj->risk_score = $riskScore;
+ $obj->score_breakdown = $scoreBreakdown;
+ $obj->validation_action = $validationAction;
+
+ $obj->contribution_tracking_id =
$message->contribution_tracking_id;
+ $obj->date = $message->date;
+ $obj->gateway = $message->gateway;
+ $obj->gateway_txn_id = $message->gateway_txn_id;
+ $obj->order_id = $message->order_id;
+ $obj->payment_method = $message->payment_method;
+ // no 'server' available
+ $obj->user_ip = $message->user_ip;
+
+ return $obj;
+ }
}
diff --git a/PaymentProviders/Adyen/Jobs/ProcessCaptureRequestJob.php
b/PaymentProviders/Adyen/Jobs/ProcessCaptureRequestJob.php
index a38334d..e348ccd 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\CrmLink\Messages\DonationInterfaceAntifraud;
use SmashPig\CrmLink\Messages\DonationInterfaceMessage;
use SmashPig\PaymentProviders\Adyen\AdyenPaymentsAPI;
use SmashPig\PaymentProviders\Adyen\ExpatriatedMessages\Authorisation;
@@ -113,17 +114,27 @@
Logger::debug( "Base risk score from payments site is
$riskScore." );
$cvvMap = $config->val( 'fraud-filters/cvv-map' );
$avsMap = $config->val( 'fraud-filters/avs-map' );
- $threshold = $config->val( 'fraud-filters/risk-threshold' );
+ $scoreBreakdown = array();
if ( array_key_exists( $this->cvvResult, $cvvMap ) ) {
- $cvvScore = $cvvMap[$this->cvvResult];
+ $scoreBreakdown['getCVVResult'] = $cvvScore =
$cvvMap[$this->cvvResult];
Logger::debug( "CVV result {$this->cvvResult} adds risk
score $cvvScore." );
$riskScore += $cvvScore;
}
if ( array_key_exists( $this->avsResult, $avsMap ) ) {
- $avsScore = $avsMap[$this->avsResult];
+ $scoreBreakdown['getAVSResult'] = $avsScore =
$avsMap[$this->avsResult];
Logger::debug( "AVS result {$this->avsResult} adds risk
score $avsScore." );
$riskScore += $avsScore;
}
- return $riskScore < $threshold;
+ $shouldCapture = ( $riskScore < $config->val(
'fraud-filters/risk-threshold' ) );
+ $this->sendAntifraudMessage( $queueMessage, $riskScore,
$scoreBreakdown, $shouldCapture );
+ return $shouldCapture;
+ }
+
+ protected function sendAntifraudMessage( $queueMessage, $riskScore,
$scoreBreakdown, $shouldCapture ) {
+ $action = $shouldCapture ? 'process' : 'review';
+ $antifraudMessage = DonationInterfaceAntifraud::factory(
+ $queueMessage, $riskScore, $scoreBreakdown, $action
+ );
+ Configuration::getDefaultConfig()->obj( 'data-store/antifraud'
)->addObj( $antifraudMessage );
}
}
diff --git a/config_defaults.php b/config_defaults.php
index 9e7919d..5abbb66 100644
--- a/config_defaults.php
+++ b/config_defaults.php
@@ -9,6 +9,11 @@
'inst-args' => array( '/tmp/' ),
),
+ 'antifraud' => array(
+ 'class' =>
'SmashPig\Core\DataStores\StompDataStore',
+ 'inst-args' => array( 'antifraud' ),
+ ),
+
'pending' => array(
'class' =>
'SmashPig\Core\DataStores\StompDataStore',
'inst-args' => array( 'pending' ),
@@ -47,6 +52,7 @@
'convert-string-expressions' => false,
'queues' => array(
+ 'antifraud' =>
'/queue/payments-antifraud',
'limbo' => '/queue/limbo',
'verified' => '/queue/donations',
'failed' => '/queue/failed',
--
To view, visit https://gerrit.wikimedia.org/r/266643
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I527add8e3ff061b7f85dead921eed27beb49f48c
Gerrit-PatchSet: 6
Gerrit-Project: wikimedia/fundraising/SmashPig
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[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