Ejegg has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/364794 )

Change subject: WIP recover from dead sessions via EC token
......................................................................

WIP recover from dead sessions via EC token

We're nowhere near hitting the RAM limit of our memcache instance.

Store an extra copy of the initial session data for PayPal express checkout
donors in memcache, keyed with the EC token. When a donor comes back with
no session information for whatever reason, try to restore the data from
memcache

Bug: T167923
Change-Id: I9fac867d8d101ca2b0365fe15ec52ba151226967
---
M paypal_gateway/express_checkout/paypal_express.adapter.php
M paypal_gateway/express_checkout/paypal_express_resultswitcher.body.php
2 files changed, 47 insertions(+), 0 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface 
refs/changes/94/364794/1

diff --git a/paypal_gateway/express_checkout/paypal_express.adapter.php 
b/paypal_gateway/express_checkout/paypal_express.adapter.php
index c614407..76613bb 100644
--- a/paypal_gateway/express_checkout/paypal_express.adapter.php
+++ b/paypal_gateway/express_checkout/paypal_express.adapter.php
@@ -1,6 +1,7 @@
 <?php
 
 use Psr\Log\LogLevel;
+use SmashPig\Core\Context;
 
 /**
  * PayPal Express Checkout name value pair integration
@@ -422,6 +423,7 @@
                                $this->addResponseData( $this->unstageKeys( 
$response ) );
                                $this->transaction_response->setRedirect(
                                        $this->account_config['RedirectURL'] . 
$response['TOKEN'] );
+                               $this->backupDonorDataInMemcache( 
$response['TOKEN'] );
                                break;
                        case 'GetExpressCheckoutDetails':
                                $this->checkResponseAck( $response );
@@ -592,4 +594,41 @@
        public function getTransactionGatewayTxnID() {
                return $this->getData_Unstaged_Escaped( 'gateway_txn_id' );
        }
+
+       public function backupDonorDataInMemcache( $token ) {
+               $cache = $this->getCache();
+               $cacheKey = $this->makeCacheKey( $token );
+               $cacheItem = $cache->getItem( $cacheKey );
+               if ( !$cacheItem->isHit() ) {
+                       $cacheItem->set(
+                               $this->getData_Unstaged_Escaped()
+                       );
+               }
+               // EC tokens are valid for 3 hrs
+               $cacheItem->expiresAfter( 60 * 60 * 3 );
+               $cache->save( $cacheItem );
+       }
+
+       public function restoreSessionFromMemcache( $token ) {
+               $cache = $this->getCache();
+               $cacheKey = $this->makeCacheKey( $token );
+               $cacheItem = $cache->getItem( $cacheKey );
+               if ( !$cacheItem->isHit() ) {
+                       $this->logger->warning( "Could not find donor data for 
token $token" );
+                       return false;
+               }
+               $this->logger->info( "Restoring lost session data from cache 
for token $token" );
+               $this->addRequestData( $cacheItem->get() );
+               $this->session_addDonorData();
+               return true;
+       }
+
+       protected function getCache() {
+               $spConfig = Context::get()->getGlobalConfiguration();
+               return $spConfig->object( 'cache' );
+       }
+
+       protected function makeCacheKey( $token ) {
+               return 'DonationInterface-PayPalExpress-' . $token;
+       }
 }
diff --git 
a/paypal_gateway/express_checkout/paypal_express_resultswitcher.body.php 
b/paypal_gateway/express_checkout/paypal_express_resultswitcher.body.php
index 80b0c17..4a322fe 100644
--- a/paypal_gateway/express_checkout/paypal_express_resultswitcher.body.php
+++ b/paypal_gateway/express_checkout/paypal_express_resultswitcher.body.php
@@ -5,6 +5,14 @@
        protected $gatewayIdentifier = PaypalExpressAdapter::IDENTIFIER;
 
        protected function handleRequest() {
+               // Some donors are coming back from paypal with no session
+               // cookies. We can still identify them by the token, though.
+               if ( !$this->$this->adapter->session_hasDonorData() ) {
+                       $token = $this->getRequest()->getVal( 'token' );
+                       if ( $token ) {
+                               $this->adapter->restoreSessionFromMemcache( 
$token );
+                       }
+               }
                $this->adapter->setCurrentTransaction( 'ProcessReturn' );
                $this->handleResultRequest();
        }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9fac867d8d101ca2b0365fe15ec52ba151226967
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

Reply via email to