Ejegg has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/359213 )
Change subject: WIP send resultswitcher reloaders to TY page ...................................................................... WIP 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: tests Also TODO: shouldn't globalcollectadapter return true for isReturnProcessingRequired() ? 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, 53 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface refs/changes/13/359213/1 diff --git a/gateway_common/GatewayPage.php b/gateway_common/GatewayPage.php index 4b1f2ba..9401b8f 100644 --- a/gateway_common/GatewayPage.php +++ b/gateway_common/GatewayPage.php @@ -400,6 +400,14 @@ if ( $deadSession ){ if ( $this->adapter->isReturnProcessingRequired() ) { + if ( $this->isRepeatReturnProcess() ) { + $this->logger->warning( + 'Resultswitcher: session is dead, but the donor ' . + 'is trying to process an already-processed payment.' + ); + $this->displayThankYouPage( 'repeat return processing' ); + return; + } wfHttpError( 403, 'Forbidden', wfMessage( 'donate_interface-error-http-403' )->text() ); throw new RuntimeException( 'Resultswitcher: Request forbidden. No active donation in the session. ' . @@ -429,6 +437,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 +576,31 @@ ); } } + + protected function isRepeatReturnProcess() { + $request = $this->getRequest(); + $requestProcessId = $this->adapter->getRequestProcessId( + $request->getValues() + ); + $processedRequests = $request->getSessionData( 'processed_requests' ); + 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/359213 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9d23953e180b85d0d7ae357442760dd5c4d4619c Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/DonationInterface Gerrit-Branch: master Gerrit-Owner: Ejegg <ej...@ejegg.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits