jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/362295 )

Change subject: Send resultswitcher reloaders to TY page
......................................................................


Send resultswitcher reloaders to TY page

This restores some logic we used to have that kept track of processed
orders in a key outside of the donor data.

TODO: shouldn't globalcollectadapter return true for
isReturnProcessingRequired() ?

Cherry picked and sanitized of test code for deployment.

Bug: T167990
Change-Id: I9d23953e180b85d0d7ae357442760dd5c4d4619c
---
M gateway_common/GatewayPage.php
M gateway_common/gateway.adapter.php
M paypal_gateway/express_checkout/paypal_express.adapter.php
3 files changed, 59 insertions(+), 0 deletions(-)

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



diff --git a/gateway_common/GatewayPage.php b/gateway_common/GatewayPage.php
index 4b1f2ba..1d0d271 100644
--- a/gateway_common/GatewayPage.php
+++ b/gateway_common/GatewayPage.php
@@ -398,6 +398,17 @@
 
                $this->setHeaders();
 
+               if ( $this->isRepeatReturnProcess() ) {
+                       $this->logger->warning(
+                               'Donor is trying to process an 
already-processed payment. ' .
+                               "Adapter Order ID: $oid.\n" .
+                               "Cookies: " . print_r( $_COOKIE, true ) ."\n" .
+                               "User-Agent: " . $_SERVER['HTTP_USER_AGENT']
+                       );
+                       $this->displayThankYouPage( 'repeat return processing' 
);
+                       return;
+               }
+
                if ( $deadSession ){
                        if ( $this->adapter->isReturnProcessingRequired() ) {
                                wfHttpError( 403, 'Forbidden', wfMessage( 
'donate_interface-error-http-403' )->text() );
@@ -429,6 +440,7 @@
                        // feed processDonorReturn all the GET and POST vars
                        $requestValues = $this->getRequest()->getValues();
                        $result = $this->adapter->processDonorReturn( 
$requestValues );
+                       $this->markReturnProcessed();
                        $this->renderResponse( $result );
                        return;
                } else {
@@ -567,4 +579,34 @@
                        );
                }
        }
+
+       protected function isRepeatReturnProcess() {
+               $request = $this->getRequest();
+               $requestProcessId = $this->adapter->getRequestProcessId(
+                       $request->getValues()
+               );
+               $processedRequests = $request->getSessionData( 
'processed_requests' );
+               if ( !$requestProcessId || empty( $processedRequests ) ) {
+                       return false;
+               }
+               return array_key_exists( $requestProcessId, $processedRequests 
);
+       }
+
+       protected function markReturnProcessed() {
+               $request = $this->getRequest();
+               $requestProcessId = $this->adapter->getRequestProcessId(
+                       $request->getValues()
+               );
+               if ( !$requestProcessId ) {
+                       return;
+               }
+               $processedRequests = $request->getSessionData( 
'processed_requests' );
+               if ( !$processedRequests ) {
+                       $processedRequests = array();
+               }
+               // TODO: we could store the results of the last process here, 
but for now
+               // we just indicate we did SOMETHING with it
+               $processedRequests[$requestProcessId] = true;
+               $request->setSessionData( 'processed_requests', 
$processedRequests );
+       }
 }
diff --git a/gateway_common/gateway.adapter.php 
b/gateway_common/gateway.adapter.php
index f26ffd0..9a25296 100644
--- a/gateway_common/gateway.adapter.php
+++ b/gateway_common/gateway.adapter.php
@@ -1452,6 +1452,18 @@
        }
 
        /**
+        * Gateways which return true from isReturnProcessingRequired must
+        * override this with logic to get an ID from the request which will
+        * identify repeated attempts to process the same payment.
+        *
+        * @param array $requestValues
+        * @return int|string Order id
+        */
+       protected function getRequestProcessId( $requestValues ) {
+               return null;
+       }
+
+       /**
         * Process the API response obtained from the payment processor and set
         * properties of transaction_response.
         * Default implementation just says we got a response.
@@ -2945,6 +2957,7 @@
                                'PaymentForms',
                                'numAttempt',
                                'order_status', //for post-payment activities
+                               'processed_requests', //for post-payment 
activities
                                'sequence',
                        );
                        $preservedData = array();
diff --git a/paypal_gateway/express_checkout/paypal_express.adapter.php 
b/paypal_gateway/express_checkout/paypal_express.adapter.php
index 0e62ecb..2a605bb 100644
--- a/paypal_gateway/express_checkout/paypal_express.adapter.php
+++ b/paypal_gateway/express_checkout/paypal_express.adapter.php
@@ -388,6 +388,10 @@
                return true;
        }
 
+       public function getRequestProcessId( $requestValues ) {
+               return $requestValues['token'];
+       }
+
        protected function processResponse( $response ) {
                $this->transaction_response->setData( $response );
                // FIXME: I'm not sure why we're responsible for failing the

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I9d23953e180b85d0d7ae357442760dd5c4d4619c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: deployment
Gerrit-Owner: Ejegg <ej...@ejegg.com>
Gerrit-Reviewer: Ejegg <ej...@ejegg.com>
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