jenkins-bot has submitted this change and it was merged.

Change subject: Another safeguard around MC-forbidden retries
......................................................................


Another safeguard around MC-forbidden retries

Adds a force_cancel key to transaction results that we
can check up in the Confirm_CreditCard transaction

Always send an antimessage at the start of Confirm_CreditCard for
everything except orphans.

Change-Id: Iead30f3d3d6a9f5d25f14d14261b9129aae973c6
---
M globalcollect_gateway/globalcollect.adapter.php
M tests/Adapter/GlobalCollect/GlobalCollectTestCase.php
M tests/includes/test_gateway/test.adapter.php
3 files changed, 38 insertions(+), 21 deletions(-)

Approvals:
  Katie Horn: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/globalcollect_gateway/globalcollect.adapter.php 
b/globalcollect_gateway/globalcollect.adapter.php
index 8f91e1a..f51bc77 100644
--- a/globalcollect_gateway/globalcollect.adapter.php
+++ b/globalcollect_gateway/globalcollect.adapter.php
@@ -234,7 +234,8 @@
                        'internal-0000' => 'donate_interface-processing-error', 
// Failed failed pre-process checks.
                        'internal-0001' => 'donate_interface-processing-error', 
// Transaction could not be processed due to an internal error.
                        'internal-0002' => 'donate_interface-processing-error', 
// Communication failure
-                       
+                       'internal-0003' => 'donate_interface-processing-error', 
// Toxic card, don't retry on pain of $1000+ fine
+
                        // Do bank validation messages
                        //'dbv-50'      => 
'globalcollect_gateway-response-dbv-50', // Account number format incorrect
                        //'dbv-80'      => 
'globalcollect_gateway-response-dbv-80', // Account details missing
@@ -1125,6 +1126,9 @@
                        $logmsg = 'CVV Result from querystring: ' . 
$this->getData_Unstaged_Escaped( 'cvv_result' );
                        $logmsg .= ', AVS Result from querystring: ' . 
$this->getData_Unstaged_Escaped( 'avs_result' );
                        $this->log( $logmsg );
+                       //add an antimessage for everything but orphans
+                       $this->log( 'Adding Antimessage' );
+                       $this->doLimboStompTransaction( true );
                } else { //this is an orphan transaction.
                        $is_orphan = true;
                        //have to change this code range: All these are usually 
"pending" and
@@ -1139,7 +1143,6 @@
                $problemflag = false; //this will get set to true, if we can't 
continue and need to give up and just log the hell out of it.
                $problemmessage = ''; //to be used in conjunction with the flag.
                $problemseverity = LOG_ERR; //to be used also in conjunction 
with the flag, to route the message to the appropriate log. Urf.
-               $add_antimessage = false; //this tells us if we should add an 
antimessage when we are done or not.
                $original_status_code = NULL;
 
                $loopcount = $this->getGlobal( 'RetryLoopCount' );
@@ -1170,7 +1173,11 @@
                        $logmsg .= ', AVS Result from XML: ' . 
$this->getData_Unstaged_Escaped( 'avs_result' );
                        $this->log( $logmsg );
 
-                       if ( $is_orphan ) {
+                       if ( array_key_exists( 'force_cancel', $status_result ) 
&& $status_result['force_cancel'] ) {
+                               $cancelflag = true; //don't retry or MasterCard 
will fine us
+                       }
+
+                       if ( $is_orphan && !$cancelflag ) {
                                if ( $loops === 0 ){ //only want to do this 
once - it's not going to change.
                                        $this->runAntifraudHooks();
                                }
@@ -1179,8 +1186,7 @@
 
                        //we filtered
                        if ( array_key_exists( 'action', $status_result ) && 
$status_result['action'] != 'process' ){
-                               $cancelflag = true;
-                               $add_antimessage = true; //don't retry: We've 
fraud-failed them intentionally.
+                               $cancelflag = true; //don't retry: We've 
fraud-failed them intentionally.
                        } elseif ( array_key_exists( 'status', $status_result ) 
&& $status_result['status'] === false ) {
                        //can't communicate or internal error
                                $problemflag = true;
@@ -1210,16 +1216,14 @@
                                        $problemmessage = "We don't have an 
order status after doing a GET_ORDERSTATUS.";
                                }
                                switch ( $order_status_results ){
-                                       case 'failed' :                         
-                                       case 'revised' :  
-                                               $add_antimessage = true;
+                                       case 'failed' :
+                                       case 'revised' :
                                                $cancelflag = true; //makes 
sure we don't try to confirm.
                                                break 2;
                                        case 'complete' :
                                                $problemflag = true; //nothing 
to be done.
                                                $problemmessage = 
"GET_ORDERSTATUS reports that the payment is already complete.";
                                                $problemseverity = LOG_INFO;
-                                               $add_antimessage = true;
                                                break 2;
                                        case 'pending-poke' :
                                                if ( $is_orphan && !$gotCVV ){
@@ -1240,7 +1244,6 @@
                                                                        //ack 
and die. 
                                                                        
$problemflag = true; //nothing to be done.
                                                                        
$problemmessage = "DO_FINISHPAYMENT says the payment failed. Giving up 
forever.";
-                                                                       
$add_antimessage = true;
                                                                        
$this->finalizeInternalStatus('failed');
                                                                }
                                                        } else {
@@ -1303,20 +1306,11 @@
                                         * us there is nothing to cancel.
                                         */
                                        $this->finalizeInternalStatus( 'failed' 
);
-                                       $add_antimessage = true;
                                } else {
                                        //in case we got wiped out, set the 
final status to what it was before. 
                                        $this->finalizeInternalStatus( 
$order_status_results );
                                }
                        }
-               }
-               
-               if ( $add_antimessage && !$is_orphan ) {
-                       //As it happens, we can't remove things from the queue 
here: It 
-                       //takes way too dang long. (~5 seconds!)
-                       //So, instead, I'll add an anti-message and deal with 
it later. (~.01 seconds) 
-                       $this->log( 'Adding Antimessage' );
-                       $this->doLimboStompTransaction( true );
                }
                
                if ( $problemflag || $cancelflag ){
@@ -1778,9 +1772,15 @@
                                case 430354: //issuer unknown
                                case 430357: //lost or stolen card
                                        // All of these should stop us from 
retrying at all
-                                       // Clear out the retry vars and return 
immediately
+                                       // Null out the retry vars and return 
immediately
                                        $retryVars = null;
                                        $this->log( "Got error code $errCode, 
not retrying to avoid MasterCard fines.", LOG_INFO );
+                                       $this->setTransactionResult( true, 
'force_cancel' );
+                                       $this->setTransactionResult( array(
+                                                       'internal-0003' => 
$this->getErrorMapByCodeAndTranslate( 'internal-0003' ),
+                                               ),
+                                               'errors'
+                                       );
                                        return $errCode;
                                case 430285: //most common declined cc code.
                                case 430396: //not authorized to cardholder, 
whatever that means.
diff --git a/tests/Adapter/GlobalCollect/GlobalCollectTestCase.php 
b/tests/Adapter/GlobalCollect/GlobalCollectTestCase.php
index 0df46ba..b06a461 100644
--- a/tests/Adapter/GlobalCollect/GlobalCollectTestCase.php
+++ b/tests/Adapter/GlobalCollect/GlobalCollectTestCase.php
@@ -334,12 +334,20 @@
                $init = $this->getDonorTestData( 'US' );
                unset( $init['order_id'] );
                $init['ffname'] = 'cc-vmad';
+               //Make it not look like an orphan
+               $this->setMwGlobals( 'wgRequest',
+                       new FauxRequest( array(
+                               'CVVRESULT' => 'M',
+                               'AVSRESULT' => '0'
+                       ), false ) );
 
-               //Expired card should not retry, even if there's an order id 
collision
+               //Toxic card should not retry, even if there's an order id 
collision
                $gateway = $this->getFreshGatewayObject( $init );
                $gateway->setDummyGatewayResponseCode( $code );
                $gateway->do_transaction( 'Confirm_CreditCard' );
                $this->assertEquals( 1, count( $gateway->curled ), "Gateway 
kept trying even with response code $code!  MasterCard could fine us a thousand 
bucks for that!" );
+               $this->assertEquals( 1, count( $gateway->limbo_stomps ), 
"Gateway sent no limbostomps for code $code!  Should have sent an antimessage!" 
);
+               $this->assertEquals( true, $gateway->limbo_stomps[0], "Gateway 
sent wrong stomp message for code $code!  Should have sent an antimessage!" );
        }
 
        public function mcNoRetryCodeProvider() {
diff --git a/tests/includes/test_gateway/test.adapter.php 
b/tests/includes/test_gateway/test.adapter.php
index 4689515..996db44 100644
--- a/tests/includes/test_gateway/test.adapter.php
+++ b/tests/includes/test_gateway/test.adapter.php
@@ -103,6 +103,8 @@
 
        public $curled = array ( );
 
+       public $limbo_stomps = array ( );
+
        /**
         * Also set a useful MerchantID.
         */
@@ -176,6 +178,13 @@
        }
 
        /**
+        * Stub out the limboStomp fn and record the calls
+        * @param type $antiMessage
+        */
+       public function doLimboStompTransaction( $antiMessage = false ) {
+               $this->limbo_stomps[] = $antiMessage;
+       }
+       /**
        * Trap the error log so we can use it in testing
        * @param type $msg
        * @param type $log_level

-- 
To view, visit https://gerrit.wikimedia.org/r/166607
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Iead30f3d3d6a9f5d25f14d14261b9129aae973c6
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>
Gerrit-Reviewer: Awight <[email protected]>
Gerrit-Reviewer: Katie Horn <[email protected]>
Gerrit-Reviewer: Ssmith <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to