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

Change subject: WIP processDonorReturn returns PaymentResult
......................................................................

WIP processDonorReturn returns PaymentResult

More functional, allows more options than just success or failure.

Bug: T163458
Change-Id: I423c77c983e873d556c708c085cbffecf545068b
---
M adyen_gateway/adyen.adapter.php
M astropay_gateway/astropay.adapter.php
M gateway_common/GatewayPage.php
M gateway_common/GatewayType.php
M gateway_common/gateway.adapter.php
M paypal_gateway/express_checkout/paypal_express.adapter.php
6 files changed, 21 insertions(+), 12 deletions(-)


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

diff --git a/adyen_gateway/adyen.adapter.php b/adyen_gateway/adyen.adapter.php
index 77f4f64..7de5da5 100644
--- a/adyen_gateway/adyen.adapter.php
+++ b/adyen_gateway/adyen.adapter.php
@@ -222,6 +222,7 @@
        /**
         * @param array $requestValues GET/POST params from request
         * @throws ResponseProcessingException
+        * @return PaymentResult
         */
        public function processDonorReturn( $requestValues ) {
                // Always called outside do_transaction, so just make a new 
response object
@@ -254,6 +255,7 @@
                $this->transaction_response->setGatewayTransactionId( 
$gateway_txn_id );
 
                $result_code = isset( $requestValues['authResult'] ) ? 
$requestValues['authResult'] : '';
+               $paymentResult = null;
                if ( $result_code == 'PENDING' || $result_code == 'AUTHORISED' 
) {
                        // Both of these are listed as pending because we have 
to submit a capture
                        // request on 'AUTHORIZATION' ipn message receipt.
@@ -266,19 +268,23 @@
                        if ( $action === 'process' ) {
                                $this->logger->info( "User came back as pending 
or authorised, placing in payments-init queue" );
                                $this->finalizeInternalStatus( 
FinalStatus::PENDING );
+                               $paymentResult = PaymentResult::newSuccess();
                        } else {
                                $this->logger->info(
                                        "User came back authorized but with 
action $action. " .
                                        "Showing a fail page, but leaving 
details in case of manual capture."
                                );
                                $this->finalizeInternalStatus( 
FinalStatus::FAILED );
+                               $paymentResult = PaymentResult::newFailure();
                        }
                }
                else {
                        $this->finalizeInternalStatus( FinalStatus::FAILED );
+                       $paymentResult = PaymentResult::newFailure();
                        $this->logger->info( "Negative response from gateway. 
Full response: " . print_r( $requestValues, TRUE ) );
                }
                $this->postProcessDonation();
+               return $paymentResult;
        }
 
        /**
diff --git a/astropay_gateway/astropay.adapter.php 
b/astropay_gateway/astropay.adapter.php
index 3788d93..581b679 100644
--- a/astropay_gateway/astropay.adapter.php
+++ b/astropay_gateway/astropay.adapter.php
@@ -299,6 +299,10 @@
                $this->logger->info( "Payment status $status coming back to 
ResultSwitcher" );
                $this->finalizeInternalStatus( $status );
                $this->postProcessDonation();
+               return PaymentResult::fromResults(
+                       $this->transaction_response,
+                       $status
+               );
        }
 
        /**
diff --git a/gateway_common/GatewayPage.php b/gateway_common/GatewayPage.php
index a41cd23..eb466de 100644
--- a/gateway_common/GatewayPage.php
+++ b/gateway_common/GatewayPage.php
@@ -429,17 +429,9 @@
                if ( $this->adapter->checkTokens() ) {
                        // feed processDonorReturn all the GET and POST vars
                        $requestValues = $this->getRequest()->getValues();
-                       $this->adapter->processDonorReturn( $requestValues );
-                       $status = $this->adapter->getFinalStatus();
-
-                       switch ( $status ) {
-                       case FinalStatus::COMPLETE:
-                       case FinalStatus::PENDING:
-                       case FinalStatus::PENDING_POKE:
-                               $this->displayThankYouPage( $status );
-                               return;
-                       }
-                       $this->logger->info( "Displaying fail page for final 
status $status" );
+                       $result = $this->adapter->processDonorReturn( 
$requestValues );
+                       $this->renderResponse( $result );
+                       return;
                } else {
                        $this->logger->error( "Resultswitcher: Token Check 
Failed. Order ID: $oid" );
                }
diff --git a/gateway_common/GatewayType.php b/gateway_common/GatewayType.php
index 3d42622..8389b1c 100644
--- a/gateway_common/GatewayType.php
+++ b/gateway_common/GatewayType.php
@@ -51,6 +51,7 @@
         * Perform any additional processing required when donor returns from
         * payment processor site. Should set the final status.
         * @param array $requestValues all GET and POST values from the request
+        * @return PaymentResult
         */
        public function processDonorReturn( $requestValues );
 
diff --git a/gateway_common/gateway.adapter.php 
b/gateway_common/gateway.adapter.php
index 62e3922..85fc888 100644
--- a/gateway_common/gateway.adapter.php
+++ b/gateway_common/gateway.adapter.php
@@ -1474,9 +1474,11 @@
        /**
         * Default implementation sets status to complete.
         * @param array $requestValues all GET and POST values from the request
+        * @return PaymentResult
         */
        public function processDonorReturn( $requestValues ) {
                $this->finalizeInternalStatus( FinalStatus::COMPLETE );
+               return PaymentResult::newSuccess();
        }
 
        /**
diff --git a/paypal_gateway/express_checkout/paypal_express.adapter.php 
b/paypal_gateway/express_checkout/paypal_express.adapter.php
index 90a1671..4fee2d4 100644
--- a/paypal_gateway/express_checkout/paypal_express.adapter.php
+++ b/paypal_gateway/express_checkout/paypal_express.adapter.php
@@ -489,7 +489,7 @@
                $resultData = $this->do_transaction( 'DoExpressCheckoutPayment' 
);
                if ( !$resultData->getCommunicationStatus() ) {
                        $this->finalizeInternalStatus( FinalStatus::FAILED );
-                       return;
+                       return PaymentResult::newFailure();
                }
 
                if ( $this->getData_Unstaged_Escaped( 'recurring' ) ) {
@@ -504,6 +504,10 @@
                                        'Failed to create a recurring profile', 
ResponseCodes::UNKNOWN );
                        }
                }
+               return PaymentResult::fromResults(
+                       $this->getTransactionResponse(),
+                       $this->getFinalStatus()
+               );
        }
 
        /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I423c77c983e873d556c708c085cbffecf545068b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>

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

Reply via email to