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

Change subject: Move Final Status out of transaction_results, use consts
......................................................................


Move Final Status out of transaction_results, use consts

Final status is not inherent to the transaction result, so let's move it out.
Also define consts for each of the valid values

Bug: T98063
Change-Id: I97024487c4559dd18fd697c321660952c1ce51db
---
M DonationInterface.php
M adyen_gateway/adyen.adapter.php
M amazon_gateway/amazon.adapter.php
M amazon_gateway/amazon_gateway.body.php
M astropay_gateway/astropay.adapter.php
A gateway_common/FinalStatus.php
M gateway_common/GatewayPage.php
M gateway_common/PaymentResult.php
M gateway_common/gateway.adapter.php
M globalcollect_gateway/globalcollect.adapter.php
M globalcollect_gateway/globalcollect_resultswitcher.body.php
M globalcollect_gateway/scripts/orphan_adapter.php
M paypal_gateway/paypal.adapter.php
M tests/Adapter/Astropay/AstropayTest.php
M worldpay_gateway/worldpay.adapter.php
15 files changed, 124 insertions(+), 129 deletions(-)

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



diff --git a/DonationInterface.php b/DonationInterface.php
index 38c8a42..a40a791 100644
--- a/DonationInterface.php
+++ b/DonationInterface.php
@@ -107,6 +107,7 @@
 $wgAutoloadClasses['DonationLogProcessor'] = $donationinterface_dir . 
'gateway_common/DonationLogProcessor.php';
 $wgAutoloadClasses['DonationQueue'] = $donationinterface_dir . 
'gateway_common/DonationQueue.php';
 $wgAutoloadClasses['EncodingMangler'] = $donationinterface_dir . 
'gateway_common/EncodingMangler.php';
+$wgAutoloadClasses['FinalStatus'] = $donationinterface_dir . 
'gateway_common/FinalStatus.php';
 $wgAutoloadClasses['GatewayAdapter'] = $donationinterface_dir . 
'gateway_common/gateway.adapter.php';
 $wgAutoloadClasses['GatewayPage'] = $donationinterface_dir . 
'gateway_common/GatewayPage.php';
 $wgAutoloadClasses['GatewayType'] = $donationinterface_dir . 
'gateway_common/gateway.adapter.php';
diff --git a/adyen_gateway/adyen.adapter.php b/adyen_gateway/adyen.adapter.php
index 5fbaf5e..27f0c4f 100644
--- a/adyen_gateway/adyen.adapter.php
+++ b/adyen_gateway/adyen.adapter.php
@@ -493,11 +493,11 @@
                        // Both of these are listed as pending because we have 
to submit a capture
                        // request on 'AUTHORIZATION' ipn message receipt.
                        $this->logger->info( "User came back as pending or 
authorised, placing in pending queue" );
-                       $this->finalizeInternalStatus( 'pending' );
+                       $this->finalizeInternalStatus( FinalStatus::PENDING );
                }
                else {
                        $this->logger->info( "Negative response from gateway. 
Full response: " . print_r( $request_vars, TRUE ) );
-                       $this->finalizeInternalStatus( 'failed' );
+                       $this->finalizeInternalStatus( FinalStatus::FAILED );
                        return ResponseCodes::UNKNOWN;
                }
                $this->setTransactionResult( $gateway_txn_id, 'gateway_txn_id' 
);
diff --git a/amazon_gateway/amazon.adapter.php 
b/amazon_gateway/amazon.adapter.php
index 6c60e14..2a33e13 100644
--- a/amazon_gateway/amazon.adapter.php
+++ b/amazon_gateway/amazon.adapter.php
@@ -272,7 +272,7 @@
 
                                parent::do_transaction( $transaction );
 
-                               if ( $this->getFinalStatus() == 'complete' ) {
+                               if ( $this->getFinalStatus() === 
FinalStatus::COMPLETE ) {
                                        $this->unstaged_data = 
$this->dataObj->getDataEscaped(); // XXX not cool.
                                        $this->runPostProcessHooks();
                                        $this->doLimboStompTransaction( true );
@@ -288,7 +288,7 @@
 
                        default:
                                $this->logger->critical( "At $transaction; THIS 
IS NOT DEFINED!" );
-                               $this->finalizeInternalStatus( 'failed' );
+                               $this->finalizeInternalStatus( 
FinalStatus::FAILED );
                }
 
                return $this->getTransactionAllResults();
@@ -322,11 +322,11 @@
                                        $ctid = 
$this->getData_Unstaged_Escaped( 'contribution_tracking_id' );
                                        $this->logger->alert( "$ctid failed 
orderid verification but has txnid '$txnid'. Investigation required." );
                                        if ( $this->getGlobal( 
'UseOrderIdValidation' ) ) {
-                                               $this->finalizeInternalStatus( 
'failed' );
+                                               $this->finalizeInternalStatus( 
FinalStatus::FAILED );
                                                return;
                                        }
                                } else {
-                                       $this->finalizeInternalStatus( 'failed' 
);
+                                       $this->finalizeInternalStatus( 
FinalStatus::FAILED );
                                        return;
                                }
                        }
@@ -338,21 +338,21 @@
                        $this->logger->info( "Transaction $txnid returned with 
status " . $this->dataObj->getVal_Escaped( 'gateway_status' ) );
                        switch ( $this->dataObj->getVal_Escaped( 
'gateway_status' ) ) {
                                case 'PS':  // Payment success
-                                       $this->finalizeInternalStatus( 
'complete' );
+                                       $this->finalizeInternalStatus( 
FinalStatus::COMPLETE );
                                        $this->doStompTransaction();
                                        break;
 
                                case 'PI':  // Payment initiated, it will 
complete later
-                                       $this->finalizeInternalStatus( 
'pending' );
+                                       $this->finalizeInternalStatus( 
FinalStatus::PENDING );
                                        $this->doStompTransaction();
                                        break;
 
                                case 'SS':  // Subscription success -- 
processing handled by the IPN listener
-                                       
$this->finalizeInternalStatus('complete');
+                                       $this->finalizeInternalStatus( 
FinalStatus::COMPLETE );
                                        break;
 
                                case 'SI':  // Subscription initiated -- 
processing handled by the IPN listener
-                                       
$this->finalizeInternalStatus('pending');
+                                       $this->finalizeInternalStatus( 
FinalStatus::PENDING );
                                        break;
 
                                case 'PF':  // Payment failed
@@ -362,7 +362,7 @@
                                        $status = 
$this->dataObj->getVal_Escaped( 'gateway_status' );
                                        $errString = 
$this->dataObj->getVal_Escaped( 'error_message' );
                                        $this->logger->info( "Transaction 
$txnid failed with ($status) $errString" );
-                                       $this->finalizeInternalStatus( 'failed' 
);
+                                       $this->finalizeInternalStatus( 
FinalStatus::FAILED );
                                        break;
                        }
                } else {
@@ -427,7 +427,7 @@
        function processResponse( $response, &$retryVars = null ) {
                if ( ( $this->getCurrentTransaction() == 'VerifySignature' ) && 
( $response['data'] == true ) ) {
                        $this->logger->info( "Transaction failed in response 
data verification." );
-                       $this->finalizeInternalStatus( 'failed' );
+                       $this->finalizeInternalStatus( FinalStatus::FAILED );
                }
        }
 
diff --git a/amazon_gateway/amazon_gateway.body.php 
b/amazon_gateway/amazon_gateway.body.php
index 7792149..b518e52 100644
--- a/amazon_gateway/amazon_gateway.body.php
+++ b/amazon_gateway/amazon_gateway.body.php
@@ -60,7 +60,8 @@
 
                                $status = $this->adapter->getFinalStatus();
 
-                               if ( ( $status == 'complete' ) || ( $status == 
'pending' ) ) {
+                               // FIXME: Isn't this why we have 
$goToThankYouOn?
+                               if ( $status === FinalStatus::COMPLETE || 
$status === FinalStatus::PENDING ) {
                                        $this->getOutput()->redirect( 
$this->adapter->getThankYouPage() );
                                }
                                else {
diff --git a/astropay_gateway/astropay.adapter.php 
b/astropay_gateway/astropay.adapter.php
index 6758629..2395c6e 100644
--- a/astropay_gateway/astropay.adapter.php
+++ b/astropay_gateway/astropay.adapter.php
@@ -113,13 +113,13 @@
        function defineReturnValueMap() {
                $this->return_value_map = array();
                // 6: Transaction not found in the system
-               $this->addCodeRange( 'PaymentStatus', 'result', 'failed', 6 );
+               $this->addCodeRange( 'PaymentStatus', 'result', 
FinalStatus::FAILED, 6 );
                // 7: Pending transaction awaiting approval
-               $this->addCodeRange( 'PaymentStatus', 'result', 'pending', 7 );
+               $this->addCodeRange( 'PaymentStatus', 'result', 
FinalStatus::PENDING, 7 );
                // 8: Operation rejected by bank
-               $this->addCodeRange( 'PaymentStatus', 'result', 'failed', 8 );
+               $this->addCodeRange( 'PaymentStatus', 'result', 
FinalStatus::FAILED, 8 );
                // 9: Amount Paid.  Transaction successfully concluded
-               $this->addCodeRange( 'PaymentStatus', 'result', 'complete', 9 );
+               $this->addCodeRange( 'PaymentStatus', 'result', 
FinalStatus::COMPLETE, 9 );
        }
 
        /**
diff --git a/gateway_common/FinalStatus.php b/gateway_common/FinalStatus.php
new file mode 100644
index 0000000..062d080
--- /dev/null
+++ b/gateway_common/FinalStatus.php
@@ -0,0 +1,12 @@
+<?php
+
+/**
+ * Allowed values for final status of a payment attempt
+ */
+class FinalStatus {
+       const COMPLETE = 'complete';
+       const FAILED = 'failed';
+       const PENDING = 'pending';
+       const PENDING_POKE = 'pending-poke';
+       const REVISED = 'revised';
+}
diff --git a/gateway_common/GatewayPage.php b/gateway_common/GatewayPage.php
index 0146cca..885c91c 100644
--- a/gateway_common/GatewayPage.php
+++ b/gateway_common/GatewayPage.php
@@ -479,8 +479,8 @@
                        // adapter the GET/POST params harvested here.
                        if ( NULL === $this->adapter->processResponse( 
$response ) ) {
                                switch ( $this->adapter->getFinalStatus() ) {
-                               case 'complete':
-                               case 'pending':
+                               case FinalStatus::COMPLETE:
+                               case FinalStatus::PENDING:
                                        $this->getOutput()->redirect( 
$this->adapter->getThankYouPage() );
                                        return;
                                }
diff --git a/gateway_common/PaymentResult.php b/gateway_common/PaymentResult.php
index bed6add..ba198b5 100644
--- a/gateway_common/PaymentResult.php
+++ b/gateway_common/PaymentResult.php
@@ -110,7 +110,7 @@
         * @param string $finalStatus final transaction status.
         */
        static public function fromResults( $data, $finalStatus ) {
-               if ( $finalStatus === 'failed' ) {
+               if ( $finalStatus === FinalStatus::FAILED ) {
                        return PaymentResult::newFailure();
                }
                if ( $data === false ) {
diff --git a/gateway_common/gateway.adapter.php 
b/gateway_common/gateway.adapter.php
index fe1113c..012fcb5 100644
--- a/gateway_common/gateway.adapter.php
+++ b/gateway_common/gateway.adapter.php
@@ -302,6 +302,11 @@
         * @var array
         */
        protected $transaction_results;
+       /**
+        * @var string When the smoke clears, this should be set to one of the
+        * constants defined in @see FinalStatus
+        */
+       protected $final_status;
        protected $validation_errors;
        protected $manual_errors = array();
        protected $current_transaction;
@@ -328,14 +333,6 @@
        const GLOBAL_PREFIX = 'wgDonationGateway'; //...for example.
 
        public $log_outbound = FALSE; //This should be set to true for gateways 
that don't return the request in the response. @see buildLogXML()
-
-       protected $valid_statuses = array(
-               'complete',
-               'pending',
-               'pending-poke',
-               'failed',
-               'revised',
-       );
 
        /**
         * Default response type to be the same as communication type.
@@ -1097,6 +1094,7 @@
 
                //reset, in case this isn't our first time.
                $this->setTransactionResult( array() );
+               $this->final_status = false;
                $this->setValidationAction('process', true);
                $errCode = null;
 
@@ -1748,8 +1746,7 @@
         * @param string $transaction The transaction these codes map to.
         * @param string $key The (incoming) field name containing the numeric 
codes
         * we're defining here.
-        * @param string $action Limited to the values 'complete', 'pending',
-        * 'pending-poke', 'failed' and 'revised'.
+        * @param string $action One of the constants defined in @see 
FinalStatus.
         * @param int $lower The integer value of the lower-bound in this code 
range.
         * @param int $upper Optional: The integer value of the upper-bound in 
the
         * code range. If omitted, it will make a range of one value: The lower 
bound.
@@ -1757,9 +1754,6 @@
         * @return void
         */
        protected function addCodeRange( $transaction, $key, $action, $lower, 
$upper = null ) {
-               if ( !$this->validTransactionWMFStatus( $action ) ) {
-                       throw new UnexpectedValueException( "Transaction WMF 
Status $action is invalid." );
-               }
                if ( $upper === null ) {
                        $this->return_value_map[$transaction][$key][$lower] = 
$action;
                } else {
@@ -1774,7 +1768,7 @@
         * @param       string                  $key                    The key 
to lookup in the transaction such as STATUSID
         * @param       integer|string  $code                   This gets 
converted to an integer if the values is numeric.
         * FIXME: We should be pulling $code out of the current transaction 
fields, internally.
-        *
+        * FIXME: Rename to reflect that these are Final Status values, not 
validation actions
         * @return      null|string     Returns the code action if a valid code 
is supplied. Otherwise, the return is null.
         */
        public function findCodeAction( $transaction, $key, $code ) {
@@ -1843,12 +1837,12 @@
        protected function doStompTransaction() {
                $status = $this->getFinalStatus();
                switch ( $status ) {
-                       case 'complete':
+                       case FinalStatus::COMPLETE:
                                $this->pushMessage( 'complete' );
                                break;
 
-                       case 'pending':
-                       case 'pending-poke':
+                       case FinalStatus::PENDING:
+                       case FinalStatus::PENDING_POKE:
                                // FIXME: I don't understand what the pending 
queue does.
                                $this->pushMessage( 'pending' );
                                break;
@@ -2248,21 +2242,14 @@
         * $transaction_results array. This is the one we care about for 
switching
         * on overall behavior. Otherwise, returns false.
         * @return mixed Final Transaction results status, or false if not set.
-        * Possible valid statuses are: 'complete', 'pending', 'pending-poke', 
'failed' and 'revised'.
+        * Should be one of the constants defined in @see FinalStatus
         */
        public function getFinalStatus() {
-               if ( is_array( $this->transaction_results ) && 
array_key_exists( 'FINAL_STATUS', $this->transaction_results ) ) {
-                       return $this->transaction_results['FINAL_STATUS'];
+               if ( $this->final_status ) {
+                       return $this->final_status;
                } else {
                        return false;
                }
-       }
-
-       public function validTransactionWMFStatus( $status = null ) {
-               if ( $status == null ) {
-                       $status = $this->getFinalStatus();
-               }
-               return in_array( $status, $this->valid_statuses );
        }
 
        /**
@@ -2273,14 +2260,10 @@
         * of the donation process on our end. Further attempts by the same user
         * will be seen as starting over.
         * @param string $status The final status of one discrete donation 
attempt,
-        * can be one of five values: 'complete', 'pending', 'pending-poke',
-        * 'failed', 'revised'
+        * can be one of constants defined in @see FinalStatus
         * @throws UnexpectedValueException
         */
        public function finalizeInternalStatus( $status ) {
-               if ( !$this->validTransactionWMFStatus( $status ) ) {
-                       throw new UnexpectedValueException( "Transaction WMF 
Status $status is invalid." );
-               }
 
                /**
                 * Handle session stuff!
@@ -2296,13 +2279,13 @@
                $this->incrementNumAttempt();
                $force = false;
                switch ( $status ) {
-                       case 'complete':
-                       case 'pending':
-                       case 'pending-poke':
+                       case FinalStatus::COMPLETE:
+                       case FinalStatus::PENDING:
+                       case FinalStatus::PENDING_POKE:
                                $force = true;
                                break;
-                       case 'failed':
-                       case 'revised':
+                       case FinalStatus::FAILED:
+                       case FinalStatus::REVISED:
                                $force = false;
                                break;
                }
@@ -2312,14 +2295,14 @@
 
                $this->sendFinalStatusMessage( $status );
 
-               $this->transaction_results['FINAL_STATUS'] = $status;
+               $this->final_status = $status;
        }
 
        /**
         * Easily-child-overridable log component of setting the final
         * transaction status, which will only ever be set at the very end of a
         * transaction workflow.
-        * @param type $status
+        * @param string $status one of the constants defined in @see 
FinalStatus
         */
        public function logFinalStatus( $status ){
                $action = $this->getValidationAction();
diff --git a/globalcollect_gateway/globalcollect.adapter.php 
b/globalcollect_gateway/globalcollect.adapter.php
index 05ae480..0da485a 100644
--- a/globalcollect_gateway/globalcollect.adapter.php
+++ b/globalcollect_gateway/globalcollect.adapter.php
@@ -341,21 +341,21 @@
                        'OK' => true,
                        'NOK' => false,
                );
-               $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'pending', 
0, 70 );
-               $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'failed', 
100, 180 );
-               $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 
'pending-poke', 200 ); //The cardholder was successfully authenticated... but 
we have to DO_FINISHPAYMENT
-               $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'failed', 
220, 280 );
-               $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'pending', 
300 );
-               $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'failed', 
310, 350 );
-               $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'revised', 
400 );
-               $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 
'pending-poke', 525 ); //"The payment was challenged by your Fraud Ruleset and 
is pending" - we never see this.
-               $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'pending', 
550 );
-               $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 
'pending-poke', 600 ); //Payments sit here until we SET_PAYMENT
-               $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'pending', 
625, 650 );
-               $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'complete', 
800, 975 ); //these are all post-authorized, but technically pre-settled...
-               $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'complete', 
1000, 1050 );
-               $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'failed', 
1100, 99999 );
-               $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'failed', 
100000, 999999 ); // 102020 - ACTION 130 IS NOT ALLOWED FOR MERCHANT NNN, 
IPADDRESS NNN.NNN.NNN.NNN
+               $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 
FinalStatus::PENDING, 0, 70 );
+               $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 
FinalStatus::FAILED, 100, 180 );
+               $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 
FinalStatus::PENDING_POKE, 200 ); //The cardholder was successfully 
authenticated... but we have to DO_FINISHPAYMENT
+               $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 
FinalStatus::FAILED, 220, 280 );
+               $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 
FinalStatus::PENDING, 300 );
+               $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 
FinalStatus::FAILED, 310, 350 );
+               $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 
FinalStatus::REVISED, 400 );
+               $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 
FinalStatus::PENDING_POKE, 525 ); //"The payment was challenged by your Fraud 
Ruleset and is pending" - we never see this.
+               $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 
FinalStatus::PENDING, 550 );
+               $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 
FinalStatus::PENDING_POKE, 600 ); //Payments sit here until we SET_PAYMENT
+               $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 
FinalStatus::PENDING, 625, 650 );
+               $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 
FinalStatus::COMPLETE, 800, 975 ); //these are all post-authorized, but 
technically pre-settled...
+               $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 
FinalStatus::COMPLETE, 1000, 1050 );
+               $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 
FinalStatus::FAILED, 1100, 99999 );
+               $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 
FinalStatus::FAILED, 100000, 999999 ); // 102020 - ACTION 130 IS NOT ALLOWED 
FOR MERCHANT NNN, IPADDRESS NNN.NNN.NNN.NNN
 
 
                $this->defineGoToThankYouOn();
@@ -390,16 +390,16 @@
         *
         * Denied:
         * - failed
-        * - Any thing else not defined in $goToThankYouOn
+        * - Any thing else not defined @see FinalStatus
         *
         */
        public function defineGoToThankYouOn() {
 
                $this->goToThankYouOn = array(
-                       'complete',
-                       'pending',
-                       'pending-poke',
-                       'revised',
+                       FinalStatus::COMPLETE,
+                       FinalStatus::PENDING,
+                       FinalStatus::PENDING_POKE,
+                       FinalStatus::REVISED,
                );
        }
 
@@ -1186,7 +1186,7 @@
                        //...aside from the fact that if the user has gotten 
this far, they left
                        //the part where they could add more data.
                        //By now, "incomplete" definitely means "failed" for 
0-70.
-                       $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 
'failed', 0, 70 );
+                       $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 
FinalStatus::FAILED, 0, 70 );
                }
 
                $cancelflag = false; //this will denote the thing we're trying 
to do with the donation attempt
@@ -1235,7 +1235,7 @@
 
                        if ( $is_orphan && !$cancelflag && isset( 
$status_result['data'] ) ) {
                                $action = $this->findCodeAction( 
'GET_ORDERSTATUS', 'STATUSID', $status_result['data']['STATUSID'] );
-                               if ( $action === 'pending-poke' && !$ran_hooks 
){ //only want to do this once - it's not going to change.
+                               if ( $action === FinalStatus::PENDING_POKE && 
!$ran_hooks ){ //only want to do this once - it's not going to change.
                                        $this->runAntifraudHooks();
                                        $ran_hooks = true;
                                }
@@ -1274,16 +1274,16 @@
                                        $problemmessage = "We don't have an 
order status after doing a GET_ORDERSTATUS.";
                                }
                                switch ( $order_status_results ){
-                                       case 'failed' :
-                                       case 'revised' :
+                                       case FinalStatus::FAILED :
+                                       case FinalStatus::REVISED :
                                                $cancelflag = true; //makes 
sure we don't try to confirm.
                                                break 2;
-                                       case 'complete' :
+                                       case FinalStatus::COMPLETE :
                                                $problemflag = true; //nothing 
to be done.
                                                $problemmessage = 
"GET_ORDERSTATUS reports that the payment is already complete.";
                                                $problemseverity = 
LogLevel::INFO;
                                                break 2;
-                                       case 'pending-poke' :
+                                       case FinalStatus::PENDING_POKE :
                                                if ( $is_orphan && !$gotCVV ){
                                                        $problemflag = true;
                                                        $problemmessage = 
"Unable to retrieve orphan cvv/avs results (Communication problem?).";
@@ -1304,11 +1304,11 @@
                                                        //Check the txn status 
and result code to see if we should bother continuing
                                                        if ( 
$this->getTransactionStatus() ){
                                                                
$this->logger->info( "DO_FINISHPAYMENT ($loops) returned with status ID " . 
$dopayment_data['STATUSID'] );
-                                                               if ( 
$this->findCodeAction( 'GET_ORDERSTATUS', 'STATUSID', 
$dopayment_data['STATUSID'] ) === 'failed' ){
+                                                               if ( 
$this->findCodeAction( 'GET_ORDERSTATUS', 'STATUSID', 
$dopayment_data['STATUSID'] ) === FinalStatus::FAILED ){
                                                                        //ack 
and die.
                                                                        
$problemflag = true; //nothing to be done.
                                                                        
$problemmessage = "DO_FINISHPAYMENT says the payment failed. Giving up 
forever.";
-                                                                       
$this->finalizeInternalStatus('failed');
+                                                                       
$this->finalizeInternalStatus( FinalStatus::FAILED );
                                                                }
                                                        } else {
                                                                
$this->logger->error( "DO_FINISHPAYMENT ($loops) returned NOK" );
@@ -1320,7 +1320,7 @@
                                                        break 2; //no need to 
loop.
                                                }
 
-                                       case 'pending' :
+                                       case FinalStatus::PENDING :
                                                //if it's really pending at 
this point, we need to...
                                                //...leave it alone. If we're 
orphan slaying, this will stay in the queue.
                                                break 2;
@@ -1351,13 +1351,13 @@
                        if ( !$cancelflag ) {
                                $final = $this->do_transaction( 'SET_PAYMENT' );
                                if ( isset( $final['status'] ) && 
$final['status'] === true ) {
-                                       $this->finalizeInternalStatus( 
'complete' );
+                                       $this->finalizeInternalStatus( 
FinalStatus::COMPLETE );
                                        //get the old status from the first 
txn, and add in the part where we set the payment.
                                        $this->setTransactionResult( "Original 
Response Status (pre-SET_PAYMENT): " . $original_status_code, 'txn_message' );
                                        $this->runPostProcessHooks();  //stomp 
is in here
                                        $add_antimessage = true; //TODO: use or 
remove
                                } else {
-                                       $this->finalizeInternalStatus( 'failed' 
);
+                                       $this->finalizeInternalStatus( 
FinalStatus::FAILED );
                                        $problemflag = true;
                                        $problemmessage = "SET_PAYMENT couldn't 
communicate properly!";
                                }
@@ -1370,7 +1370,7 @@
                                         * In fact, GC will error out if we try 
to do that, and tell
                                         * us there is nothing to cancel.
                                         */
-                                       $this->finalizeInternalStatus( 'failed' 
);
+                                       $this->finalizeInternalStatus( 
FinalStatus::FAILED );
                                } else {
                                        //in case we got wiped out, set the 
final status to what it was before.
                                        $this->finalizeInternalStatus( 
$order_status_results );
@@ -1414,7 +1414,7 @@
                        $result = $this->do_transaction('GET_ORDERSTATUS');
                        $data = $this->getTransactionData();
                        $orderStatus = $this->findCodeAction( 
'GET_ORDERSTATUS', 'STATUSID', $data['STATUSID'] );
-                       if ( $this->getTransactionStatus() && $orderStatus == 
'pending-poke' ) {
+                       if ( $this->getTransactionStatus() && $orderStatus === 
FinalStatus::PENDING_POKE ) {
                                
$this->transactions['SET_PAYMENT']['values']['PAYMENTPRODUCTID'] = 
$result['data']['PAYMENTPRODUCTID'];
                                $result = $this->do_transaction('SET_PAYMENT');
                        }
@@ -1430,7 +1430,7 @@
                        $result = 
$this->do_transaction('INSERT_ORDERWITHPAYMENT');
                        if (isset($result['status']) && $result['status'])
                        {
-                               if ($this->getFinalStatus() == 'pending-poke')
+                               if ( $this->getFinalStatus() === 
FinalStatus::PENDING_POKE )
                                {
                                        $txn_data = $this->getTransactionData();
                                        $original_status_code = isset( 
$txn_data['STATUSID']) ? $txn_data['STATUSID'] : 'NOT SET';
@@ -1438,10 +1438,10 @@
                                        $result = 
$this->do_transaction('SET_PAYMENT');
                                        if (isset($result['status']) && 
$result['status'] === true)
                                        {
-                                               $this->finalizeInternalStatus( 
'complete' );
+                                               $this->finalizeInternalStatus( 
FinalStatus::COMPLETE );
                                                $this->doLimboStompTransaction( 
true );
                                        } else {
-                                               $this->finalizeInternalStatus( 
'failed' );
+                                               $this->finalizeInternalStatus( 
FinalStatus::FAILED );
                                                //get the old status from the 
first txn, and add in the part where we set the payment.
                                                $this->setTransactionResult( 
"Original Response Status (pre-SET_PAYMENT): " . $original_status_code, 
'txn_message' );
                                        }
@@ -1543,7 +1543,7 @@
                                        if ( array_key_exists( 
'additional_success_status', $payment_info ) && is_array( 
$payment_info['additional_success_status'] ) ){
                                                foreach ( 
$payment_info['additional_success_status'] as $status ){
                                                        //mangle the definition 
of success.
-                                                       $this->addCodeRange( 
'GET_ORDERSTATUS', 'STATUSID', 'complete', $status );
+                                                       $this->addCodeRange( 
'GET_ORDERSTATUS', 'STATUSID', FinalStatus::COMPLETE, $status );
                                                }
                                        }
                                        if ( $this->getTransactionStatus() ) {
@@ -1576,7 +1576,7 @@
                                if ( isset( $data['STATUSID'] ) ) {
                                        $this->finalizeInternalStatus( 
$this->findCodeAction( 'GET_ORDERSTATUS', 'STATUSID', $data['STATUSID'] ) );
                                } else {
-                                       $this->finalizeInternalStatus( 'failed' 
);
+                                       $this->finalizeInternalStatus( 
FinalStatus::FAILED );
                                }
                                $data['ORDER'] = $this->xmlChildrenToArray( 
$response, 'ORDER' );
                                break;
@@ -1642,7 +1642,7 @@
         * @param array    $data    The data array
         *
         * @throws UnexpectedValueException
-        * @return boolean
+        * @return string One of the constants defined in @see FinalStatus
         */
        public function checkDoBankValidation( &$data ) {
                $checks = &$data['CHECKSPERFORMED'];
@@ -1652,16 +1652,14 @@
                $isWarning = 0;
                $isNotChecked = 0;
 
-               $return = 'failed';
-
                if ( !is_array( $checks['CHECKS'] ) ) {
                        // Should we trigger an error if no checks are 
performed?
                        // For now, just return failed.
-                       return $return;
+                       return FinalStatus::FAILED;
                }
 
                // We only mark validation as a failure if we have warnings or 
errors.
-               $return = 'complete';
+               $return = FinalStatus::COMPLETE;
 
                foreach ( $checks['CHECKS'] as $checkCode => $checkResult ) {
                        // Prefix error codes with dbv for DO_BANKVALIDATION
@@ -1691,16 +1689,16 @@
 
                // The return text needs to match something in @see 
$this->defineGoToThankYouOn()
                if ( $isPass ) {
-                       $return = 'complete';
+                       $return = FinalStatus::COMPLETE;
                }
 
                if ( $isWarning ) {
                        $this->logger->error( 'Got warnings from bank 
validation: ' . print_r( $data['errors'], TRUE ) );
-                       $return = 'complete';
+                       $return = FinalStatus::COMPLETE;
                }
 
                if ( $isError ) {
-                       $return = 'failed';
+                       $return = FinalStatus::FAILED;
                }
 
                return $return;
@@ -2367,7 +2365,7 @@
                if ( $this->getTransactionStatus() === true ) {
                        $data = $this->getTransactionData();
                        $action = $this->findCodeAction( 'GET_ORDERSTATUS', 
'STATUSID', $data['STATUSID'] );
-                       if ($action != 'failed'){
+                       if ( $action != FinalStatus::FAILED ){
                                $this->doLimboStompTransaction();
                        }
                }
diff --git a/globalcollect_gateway/globalcollect_resultswitcher.body.php 
b/globalcollect_gateway/globalcollect_resultswitcher.body.php
index d258764..e20cfa9 100644
--- a/globalcollect_gateway/globalcollect_resultswitcher.body.php
+++ b/globalcollect_gateway/globalcollect_resultswitcher.body.php
@@ -115,12 +115,12 @@
 
                                if ( $this->adapter->getFinalStatus() ){
                                        switch ( 
$this->adapter->getFinalStatus() ) {
-                                               case 'complete':
-                                               case 'pending':
-                                               case 'pending-poke':
+                                               case FinalStatus::COMPLETE:
+                                               case FinalStatus::PENDING:
+                                               case FinalStatus::PENDING_POKE:
                                                        $go = 
$this->adapter->getThankYouPage();
                                                        break;
-                                               case 'failed':
+                                               case FinalStatus::FAILED:
                                                        $go = 
$this->getDeclinedResultPage();
                                                        break;
                                        }
diff --git a/globalcollect_gateway/scripts/orphan_adapter.php 
b/globalcollect_gateway/scripts/orphan_adapter.php
index d14bbfe..bc700b8 100644
--- a/globalcollect_gateway/scripts/orphan_adapter.php
+++ b/globalcollect_gateway/scripts/orphan_adapter.php
@@ -161,11 +161,11 @@
 
                $status = $this->getFinalStatus();
                switch ( $status ) {
-                       case 'complete':
+                       case FinalStatus::COMPLETE:
                                $hook = 'gwStomp';
                                break;
-                       case 'pending':
-                       case 'pending-poke':
+                       case FinalStatus::PENDING:
+                       case FinalStatus::PENDING_POKE:
                                $hook = 'gwPendingStomp';
                                break;
                }
diff --git a/paypal_gateway/paypal.adapter.php 
b/paypal_gateway/paypal.adapter.php
index 2c74b4b..5d2cabe 100644
--- a/paypal_gateway/paypal.adapter.php
+++ b/paypal_gateway/paypal.adapter.php
@@ -200,7 +200,7 @@
                        case 'DonateRecurring':
                                $this->transactions[ $transaction ][ 'url' ] = 
$this->getGlobal( 'URL' ) . '?' . http_build_query( $this->buildRequestParams() 
);
                                $result = parent::do_transaction( $transaction 
);
-                               $this->finalizeInternalStatus( 'complete' );
+                               $this->finalizeInternalStatus( 
FinalStatus::COMPLETE );
                                return $result;
                }
        }
diff --git a/tests/Adapter/Astropay/AstropayTest.php 
b/tests/Adapter/Astropay/AstropayTest.php
index 6bf2c27..1f3d47d 100644
--- a/tests/Adapter/Astropay/AstropayTest.php
+++ b/tests/Adapter/Astropay/AstropayTest.php
@@ -225,7 +225,7 @@
                $result = $gateway->processResponse( $response );
                $status = $gateway->getFinalStatus();
                $this->assertNull( $result );
-               $this->assertEquals( 'complete', $status );
+               $this->assertEquals( FinalStatus::COMPLETE, $status );
        }
 
        /**
@@ -253,6 +253,6 @@
                $result = $gateway->processResponse( $response );
                $status = $gateway->getFinalStatus();
                $this->assertNull( $result );
-               $this->assertEquals( 'failed', $status );
+               $this->assertEquals( FinalStatus::FAILED, $status );
        }
 }
diff --git a/worldpay_gateway/worldpay.adapter.php 
b/worldpay_gateway/worldpay.adapter.php
index f3d28ac..7316aca 100644
--- a/worldpay_gateway/worldpay.adapter.php
+++ b/worldpay_gateway/worldpay.adapter.php
@@ -683,15 +683,15 @@
                // Anything other than 2170 must be treated as failure for PT-C.
                // ***LOOK AT THIS COMMENT: If you add AuthorizePaymentForFraud 
success statuses here,
                // you will need to whack a finalizeInternalStatus in 
do_transaction_QueryAuthorizeDeposit
-               $this->addCodeRange( 'AuthorizePaymentForFraud', 'MessageCode', 
'failed', 2000, 2049 );
-               $this->addCodeRange( 'AuthorizePaymentForFraud', 'MessageCode', 
'failed', 2051, 2099 );
-               $this->addCodeRange( 'AuthorizePaymentForFraud', 'MessageCode', 
'failed', 2101, 2999 );
+               $this->addCodeRange( 'AuthorizePaymentForFraud', 'MessageCode', 
FinalStatus::FAILED, 2000, 2049 );
+               $this->addCodeRange( 'AuthorizePaymentForFraud', 'MessageCode', 
FinalStatus::FAILED, 2051, 2099 );
+               $this->addCodeRange( 'AuthorizePaymentForFraud', 'MessageCode', 
FinalStatus::FAILED, 2101, 2999 );
 
-               $this->addCodeRange( 'AuthorizeAndDepositPayment', 
'MessageCode', 'failed', 2000, 2049 );
-               $this->addCodeRange( 'AuthorizeAndDepositPayment', 
'MessageCode', 'complete', 2050 );
-               $this->addCodeRange( 'AuthorizeAndDepositPayment', 
'MessageCode', 'failed', 2051, 2099 );
-               $this->addCodeRange( 'AuthorizeAndDepositPayment', 
'MessageCode', 'complete', 2100 );
-               $this->addCodeRange( 'AuthorizeAndDepositPayment', 
'MessageCode', 'failed', 2101, 2999 );
+               $this->addCodeRange( 'AuthorizeAndDepositPayment', 
'MessageCode', FinalStatus::FAILED, 2000, 2049 );
+               $this->addCodeRange( 'AuthorizeAndDepositPayment', 
'MessageCode', FinalStatus::COMPLETE, 2050 );
+               $this->addCodeRange( 'AuthorizeAndDepositPayment', 
'MessageCode', FinalStatus::FAILED, 2051, 2099 );
+               $this->addCodeRange( 'AuthorizeAndDepositPayment', 
'MessageCode', FinalStatus::COMPLETE, 2100 );
+               $this->addCodeRange( 'AuthorizeAndDepositPayment', 
'MessageCode', FinalStatus::FAILED, 2101, 2999 );
        }
 
        function defineVarMap() {
@@ -824,7 +824,7 @@
                if ( $code ) {
                        //determine if the response code is, in fact, an error.
                        $action = $this->findCodeAction( 
$this->getCurrentTransaction(), 'MessageCode', $code );
-                       if ( $action === 'failed' ) {
+                       if ( $action === FinalStatus::FAILED ) {
                                //use generic internals, I think.
                                //I can't tell if I'm being lazy here, or if we 
genuinely don't need to get specific with this.
                                $errors[$code] = ( $this->getGlobal( 
'DisplayDebug' ) ) ? '*** ' . $message : $this->getErrorMapByCodeAndTranslate( 
'internal-0003' );
@@ -1151,7 +1151,7 @@
                $result = $this->do_transaction( 'QueryTokenData' );
                if ( !$this->getTransactionStatus() ) {
                        $this->logger->error( 'Failed transaction because 
QueryTokenData failed' );
-                       $this->finalizeInternalStatus( 'failed' );
+                       $this->finalizeInternalStatus( FinalStatus::FAILED );
                        return $result;
                }
 
@@ -1161,7 +1161,7 @@
                        $result = $this->do_transaction( 
'AuthorizePaymentForFraud' );
                        if ( !$this->getTransactionStatus() ) {
                                $this->logger->info( 'Failed transaction 
because AuthorizePaymentForFraud failed' );
-                               $this->finalizeInternalStatus( 'failed' );
+                               $this->finalizeInternalStatus( 
FinalStatus::FAILED );
                                return $result;
                        }
                        $code = $result[ 'data' ][ 'MessageCode' ];
@@ -1183,7 +1183,7 @@
                $result = $this->do_transaction( 'AuthorizeAndDepositPayment' );
                if ( !$this->getTransactionStatus() ) {
                        $this->logger->info( 'Failed transaction because 
AuthorizeAndDepositPayment failed' );
-                       $this->finalizeInternalStatus( 'failed' );
+                       $this->finalizeInternalStatus( FinalStatus::FAILED );
                        return $result;
                }
                $code = $result[ 'data' ][ 'MessageCode' ];
@@ -1198,7 +1198,7 @@
                                'Finalizing transaction at 
AuthorizeAndDepositPayment to failed because MessageCode (' .
                                $code . ') was unknown.'
                        );
-                       $this->finalizeInternalStatus( 'failed' );
+                       $this->finalizeInternalStatus( FinalStatus::FAILED );
                }
                return $result;
        }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I97024487c4559dd18fd697c321660952c1ce51db
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Ejegg <eeggles...@wikimedia.org>
Gerrit-Reviewer: Awight <awi...@wikimedia.org>
Gerrit-Reviewer: Ssmith <ssm...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to