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

Change subject: Enable fail page without adapter instance
......................................................................


Enable fail page without adapter instance

When an adapter constructor bombs out, the page can still use this
method to get a semi-appropriate fail page.

Bug: T129376
Change-Id: Ia39d816fb22ab7244206e0bcd7f250ed71ee2990
---
M gateway_common/ResultPages.php
1 file changed, 72 insertions(+), 21 deletions(-)

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



diff --git a/gateway_common/ResultPages.php b/gateway_common/ResultPages.php
index 6653a3f..d7d02ba 100644
--- a/gateway_common/ResultPages.php
+++ b/gateway_common/ResultPages.php
@@ -1,17 +1,22 @@
 <?php
 
+use Psr\Log\LoggerInterface;
+
 class ResultPages {
        /**
         * Get the URL for a page to show donors after a successful donation,
         * with the country code appended as a query string variable
         * @param GatewayType $adapter
         * @param array $extraParams any extra parameters to add to the URL
-        * @return string
+        * @return string full URL of the thank you page
         */
        public static function getThankYouPage( GatewayType $adapter, 
$extraParams = array() ) {
                $page = $adapter::getGlobal( "ThankYouPage" );
                if ( $page ) {
-                       $page = self::appendLanguageAndMakeURL( $page, $adapter 
);
+                       $page = self::appendLanguageAndMakeURL(
+                               $page,
+                               $adapter->getData_Unstaged_Escaped( 'language' )
+                       );
                }
                $extraParams['country'] = $adapter->getData_Unstaged_Escaped( 
'country' );
                return wfAppendQuery( $page, $extraParams );
@@ -19,33 +24,77 @@
 
        /**
         * Get the URL for a page to show donors after a failed donation
-        * @param GatewayType $adapter
-        * @return string
+        * @param GatewayType $adapter instance to use for logger and settings
+        * @return string full URL of the fail page
         */
        public static function getFailPage( GatewayType $adapter ) {
-               // Prefer RapidFail.
-               if ( $adapter::getGlobal( 'RapidFail' ) ) {
-                       $data = $adapter->getData_Unstaged_Escaped();
+               return self::getFailPageFromParams(
+                       $adapter->getGlobal( 'RapidFail' ),
+                       $adapter->getGlobal( 'FailPage' ),
+                       $adapter->getData_Unstaged_Escaped(),
+                       $adapter->getRetryData(),
+                       DonationLoggerFactory::getLogger( $adapter )
+               );
+       }
 
+       /**
+        * Get the URL for a page to show donors after a failed donation without
+        * requiring an adapter instance.
+        * @param string $adapterType adapter class to use for settings and 
logger
+        *                            e.g. AdyenGateway
+        * @param string $logPrefix identifier used to associate log lines with
+        *                          related requests
+        * @return string full URL of the fail page
+        */
+       public static function getFailPageForType( $adapterType, $logPrefix = 
'' ) {
+               return self::getFailPageFromParams(
+                       $adapterType::getGlobal( 'RapidFail' ),
+                       $adapterType::getGlobal( 'FailPage' ),
+                       array(
+                               'gateway' => $adapterType::getIdentifier(),
+                               'payment_method' => '',
+                               'payment_submethod' => '',
+                       ),
+                       array(),
+                       DonationLoggerFactory::getLoggerForType( $adapterType, 
$logPrefix )
+               );
+       }
+
+       /**
+        * @param bool $rapidFail if true, render a form as a fail page rather 
than redirect
+        * @param string $failPage either a wiki page title, or a URL to an 
external wiki
+        *                         page title.
+        * @param array $data information about the current request.
+        *                    language, gateway, payment_method, and 
payment_submethod must be set
+        * @param array $retryData information used to create a link to retry 
the donation
+        * @param Psr\Log\LoggerInterface $logger
+        * @return string full URL of the fail page
+        * @throws MWException
+        */
+       private static function getFailPageFromParams( $rapidFail, $failPage, 
$data, $retryData, LoggerInterface $logger ) {
+               if ( isset( $data['language'] ) ) {
+                       $language = $data['language'];
+               } else {
+                       $language = WmfFramework::getLanguageCode();
+               }
+               // Prefer RapidFail.
+               if ( $rapidFail ) {
                        // choose which fail page to go for.
                        try {
                                $fail_ffname = 
GatewayFormChooser::getBestErrorForm( $data['gateway'], 
$data['payment_method'], $data['payment_submethod'] );
-                               return 
GatewayFormChooser::buildPaymentsFormURL( $fail_ffname, 
$adapter->getRetryData() );
+                               return 
GatewayFormChooser::buildPaymentsFormURL( $fail_ffname, $retryData );
                        } catch ( Exception $e ) {
-                               $logger = DonationLoggerFactory::getLogger( 
$adapter );
                                $logger->error( 'Cannot determine best error 
form. ' . $e->getMessage() );
                        }
                }
-               $page = $adapter::getGlobal( 'FailPage' );
-               if ( filter_var( $page, FILTER_VALIDATE_URL ) ) {
-                       return self::appendLanguageAndMakeURL( $page, $adapter 
);
+               if ( filter_var( $failPage, FILTER_VALIDATE_URL ) ) {
+                       return self::appendLanguageAndMakeURL( $failPage, 
$language );
                }
 
                // FIXME: either add Special:FailPage to avoid depending on 
wiki content,
                // or update the content on payments to be consistent with the 
/lang
                // format of ThankYou pages so we can use 
appendLanguageAndMakeURL here.
-               $failTitle = Title::newFromText( $page );
-               $language = $adapter->getData_Unstaged_Escaped( 'language' );
+               $failTitle = Title::newFromText( $failPage );
                $url = wfAppendQuery( $failTitle->getFullURL(), array( 
'uselang' => $language ) );
 
                return $url;
@@ -53,15 +102,18 @@
 
        /**
         * Get the URL for a page to show donors who cancel their attempt
-        * @param GatewayType $adapter
-        * @return string
+        * @param GatewayType $adapter instance to use for logger and settings
+        * @return string full URL of the cancel page
         */
        public static function getCancelPage( GatewayType $adapter ) {
                $cancelPage = $adapter->getGlobal( 'CancelPage' );
                if ( empty( $cancelPage ) ) {
                        return '';
                }
-               return self::appendLanguageAndMakeURL( $cancelPage, $adapter );
+               return self::appendLanguageAndMakeURL(
+                       $cancelPage,
+                       $adapter->getData_Unstaged_Escaped( 'language' )
+               );
        }
 
        /**
@@ -70,11 +122,10 @@
         * appended onto the end.
         * @param string $url Either a wiki page title, or a URL to an external 
wiki
         * page title.
-        * @param GatewayType $adapter
-        * @return string A URL
+        * @param $language
+        * @return string localized full URL
         */
-       protected static function appendLanguageAndMakeURL( $url, GatewayType 
$adapter ) {
-               $language = $adapter->getData_Unstaged_Escaped( 'language' );
+       protected static function appendLanguageAndMakeURL( $url, $language ) {
                // make sure we don't already have the language in there...
                $dirs = explode('/', $url);
                if ( !is_array( $dirs ) || !in_array( $language, $dirs ) ) {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia39d816fb22ab7244206e0bcd7f250ed71ee2990
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>
Gerrit-Reviewer: AndyRussG <[email protected]>
Gerrit-Reviewer: Awight <[email protected]>
Gerrit-Reviewer: Cdentinger <[email protected]>
Gerrit-Reviewer: Ejegg <[email protected]>
Gerrit-Reviewer: Ssmith <[email protected]>
Gerrit-Reviewer: XenoRyet <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to