Katie Horn has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/88914


Change subject: Dyanmic Error Pages, Part 1
......................................................................

Dyanmic Error Pages, Part 1

Shouldn't functionally change anything we have at the moment, so it should be 
safe to merge.
The first step toward having dynamic error pages. This also fixes the back link 
so it will go to the most recently used payment form, instead of some crazy 
place on donate.
What's missing: The switch that will enable us to use this error page, instead 
of the static one.
Also, the appeal param isn't sticky, so if you're relying on css in on-wiki 
appeals to alter forms, STOP IT.

Change-Id: I6b1baffd664ae814740bf57774c9f62859a3eefc
---
M gateway_common/DonationData.php
M gateway_common/gateway.adapter.php
M gateway_common/interface.i18n.php
M gateway_forms/RapidHtml.php
A gateway_forms/rapidhtml/html/error-cc.html
M globalcollect_gateway/globalcollect.adapter.php
M special/GatewayFormChooser.php
7 files changed, 138 insertions(+), 28 deletions(-)


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

diff --git a/gateway_common/DonationData.php b/gateway_common/DonationData.php
index c9a1f85..c1fc192 100644
--- a/gateway_common/DonationData.php
+++ b/gateway_common/DonationData.php
@@ -164,13 +164,13 @@
                        //if it is: assume that the session data was meant to 
be replaced 
                        //with better data.  
                        //...unless it's referrer. 
-                       foreach ( $_SESSION['Donor'] as $key => $val ){
+                       foreach ( $_SESSION['Donor'] as $key => $val ) {
                                if ( !$this->isSomething( $key ) ){
                                        $this->setVal( $key, $val );
                                } else {
-                                       //TODO: Change this to a switch 
statement if we get more 
-                                       //fields in here. 
-                                       if ( $key === 'referrer' ){
+                                       //fields that should always overwrite 
with their original values
+                                       $overwrite = array ( 'referrer' );
+                                       if ( in_array( $key, $overwrite ) ) {
                                                $this->setVal( $key, $val );
                                        }
                                }
@@ -1289,10 +1289,37 @@
                self::ensureSession();
                $donordata = $this->getStompMessageFields();
                $donordata[] = 'order_id';
-               
+               $donordata[] = 'form_stack'; //the forms we've been to
+
                foreach ( $donordata as $item ) {
                        if ( $this->isSomething( $item ) ) {
                                $_SESSION['Donor'][$item] = $this->getVal( 
$item );
+                       }
+               }
+       }
+
+       public function pushRapidHTMLForm( $form_key ) {
+               self::ensureSession();
+
+               if ( !array_key_exists( 'PaymentForms', $_SESSION ) || 
!is_array( $_SESSION['PaymentForms'] ) ) {
+                       $_SESSION['PaymentForms'] = array ( );
+               }
+
+               //don't want duplicates
+               if ( $this->getLastRapidHTMLForm() != $form_key ) {
+                       $_SESSION['PaymentForms'][] = $form_key;
+               }
+       }
+
+       public function getLastRapidHTMLForm() {
+               self::ensureSession();
+               if ( !array_key_exists( 'PaymentForms', $_SESSION ) || 
!is_array( $_SESSION['PaymentForms'] ) ) {
+                       return false;
+               } else {
+                       if ( sizeof( $_SESSION['PaymentForms'] > 0 ) ) {
+                               return $_SESSION['PaymentForms'][sizeof( 
$_SESSION['PaymentForms'] ) - 1];
+                       } else {
+                               return false;
                        }
                }
        }
@@ -1404,7 +1431,7 @@
         * /extensions/DonationData/activemq_stomp/activemq_stomp.php
         * to somewhere in DonationData.         * 
         */
-       public function getStompMessageFields(){
+       public static function getStompMessageFields() {
                $stomp_fields = array(
                        'contribution_tracking_id',
                        'optout',
@@ -1448,7 +1475,7 @@
                );
                return $stomp_fields;
        }
-       
+
        /**
         * Basically, this is a wrapper for the $wgRequest wasPosted function 
that 
         * won't give us notices if we weren't even a web request. 
diff --git a/gateway_common/gateway.adapter.php 
b/gateway_common/gateway.adapter.php
index e4f5d87..63909f0 100644
--- a/gateway_common/gateway.adapter.php
+++ b/gateway_common/gateway.adapter.php
@@ -1747,6 +1747,16 @@
        }
 
        /**
+        * Pushes a RapidHTML form to the user's session, so we have the option
+        * to usefully go back to the last available one.
+        * This should only be used when we actually load a good one.
+        * @param type $form
+        */
+       public function pushRapidHTMLForm( $form ) {
+               $this->dataObj->pushRapidHTMLForm( $form );
+       }
+
+       /**
         * Destroys the session completely. 
         * Note: This will leave the cookie behind! It just won't go to 
anything at 
         * all. 
@@ -2688,4 +2698,9 @@
        public function getMerchantID() {
                return $this->account_config[ 'MerchantID' ];
        }
+
+       public function getLastRapidHTMLForm() {
+               return $this->dataObj->getLastRapidHTMLForm();
+       }
+
 }
diff --git a/gateway_common/interface.i18n.php 
b/gateway_common/interface.i18n.php
index 05df741..7a6ccd0 100644
--- a/gateway_common/interface.i18n.php
+++ b/gateway_common/interface.i18n.php
@@ -215,6 +215,7 @@
        'donate_interface-error-msg-country-calc' => 'Error - We are unable to 
accept your donation at this time.',
        'donate_interface-error-msg-fiscal_number' => 'fiscal number',
        'donate_interface-donate-error-try-a-different-card' => 'Please [$1 try 
a different card] or one of our [$2 other ways to give] or contact us at $3',
+       'donate_interface-donate-error-try-again-html' => 'Please <a 
href="$1">try again</a>, try one of our <a href="$2">other ways to give</a>, or 
contact us at <a href="mailto:$3";>$3</a>',
        'donate_interface-donate-error-thank-you-for-your-support' => 'Thank 
you for your support!',
        'donate_interface-error-no-form' => 'We were unable to find a donation 
form matching your parameters. Please contact [mailto:don...@wikimedia.org our 
help team] for more information.',
        'php-response-declined' => 'Your transaction could not be accepted.',
diff --git a/gateway_forms/RapidHtml.php b/gateway_forms/RapidHtml.php
index 0b6a93a..ea509b0 100644
--- a/gateway_forms/RapidHtml.php
+++ b/gateway_forms/RapidHtml.php
@@ -68,7 +68,7 @@
                '@bank_code',
                '@bank_name',
                '@bank_check_digit',
-        '@branch_code',
+               '@branch_code',
                // Boletos
                '@fiscal_number',
                // Not actually data tokens, but available to you in html form:
@@ -79,6 +79,7 @@
                // @appeal_title -> name of the appeal title to load
                // @verisign_logo -> placeholder to load the secure verisign 
logo
                // @select_country -> generates a select containing all country 
names
+               '@ffname_retry', //form name for retries (used by error pages)
        );
 
        /**
@@ -486,6 +487,18 @@
                        }
                }
 
+               if ( array_key_exists( 'special_type', $allowedForms[$form_key] 
) ) {
+                       if ( $allowedForms[$form_key]['special_type'] === 
'error' ) {
+                               //add data we're going to need for the error 
page!
+                               $back_form = 
$this->gateway->getLastRapidHTMLForm();
+                               //If this is just the one thing, we might move 
this inside DonationData for clarity's sake...
+                               $this->gateway->addData( array ( 'ffname_retry' 
=> GatewayFormChooser::buildPaymentsFormURL( $back_form ) ) );
+                       }
+               } else {
+                       //No special type... let's add this to the form stack 
and call it good.
+                       $this->gateway->pushRapidHTMLForm( $form_key );
+               }
+
                $this->html_file_path = $allowedForms[$form_key]['file'];
        }
 
@@ -541,4 +554,5 @@
 
                return $output;
        }
+
 }
diff --git a/gateway_forms/rapidhtml/html/error-cc.html 
b/gateway_forms/rapidhtml/html/error-cc.html
new file mode 100644
index 0000000..0f14633
--- /dev/null
+++ b/gateway_forms/rapidhtml/html/error-cc.html
@@ -0,0 +1,29 @@
+<style type="text/css">
+       div.error-box {
+               margin: auto;
+               width: 70%;
+               border: solid black 2px;
+               padding: 20px;
+               text-align:center;
+       }
+       div.error-box .header {
+               color: #CC0000;
+       }
+
+       /* hide existing UI elements */
+       .firstHeading {
+               display: none;
+       }
+</style>
+
+<div class="error-box">
+       <big>
+               <span class="header">
+                       %php-response-declined%
+               </span>
+               <br/><br/>
+               
%donate_interface-donate-error-try-again-html|@ffname_retry|//wikimediafoundation.org/wiki/Ways_to_Give/en|problemsdonat...@wikimedia.org%
+               <br/><br/>
+               %donate_interface-donate-error-thank-you-for-your-support%
+       </big>
+</div>
\ No newline at end of file
diff --git a/globalcollect_gateway/globalcollect.adapter.php 
b/globalcollect_gateway/globalcollect.adapter.php
index f561f7e..a5b3fad 100644
--- a/globalcollect_gateway/globalcollect.adapter.php
+++ b/globalcollect_gateway/globalcollect.adapter.php
@@ -2282,9 +2282,7 @@
        
        protected function pre_process_insert_orderwithpayment(){
                $this->incrementNumAttempt();
-               if ( $this->getData_Unstaged_Escaped( 'payment_method' ) === 
'cc' ){
-                       $this->addDonorDataToSession();
-               }
+               $this->addDonorDataToSession();
        }
        
        /**
diff --git a/special/GatewayFormChooser.php b/special/GatewayFormChooser.php
index 735a888..2f834d3 100644
--- a/special/GatewayFormChooser.php
+++ b/special/GatewayFormChooser.php
@@ -51,17 +51,9 @@
                        return;
                }
 
-               // And... construct the URL
-               $params = array(
-                       'form_name' => "RapidHtml",
-                       'appeal' => "JimmyQuote",
-                       'ffname' => $form,
+               $params = array (
                        'recurring' => $recurring,
                );
-
-               if( DataValidator::value_appears_in( 'redirect', $forms[$form] 
) ){
-                       $params['redirect'] = '1';
-               }
 
                // Pass any other params that are set. We do not skip ffname or 
form_name because
                // we wish to retain the query string override.
@@ -73,17 +65,42 @@
                        }
                }
 
-               // set the default redirect
-               $redirectURL = $this->getTitleFor( 
ucfirst($forms[$form]['gateway']) . "Gateway" )->getLocalUrl( $params );
-
-               // This is an error condition, so we return something reasonable
-               // TODO: Figure out something better to do
-//             $redirectURL = 
"https://wikimediafoundation.org/wiki/Ways_to_Give";;
+               $redirectURL = self::buildPaymentsFormURL( $form, $params );
 
                // Perform the redirection
                $this->getOutput()->redirect( $redirectURL );
        }
-       
+
+       /**
+        * $other_params will override everything except $form_key (ffname)
+        * @param type $form_key
+        * @param type $other_params
+        */
+       static function buildPaymentsFormURL( $form_key, $other_params = array 
( ) ) {
+               // And... construct the URL
+               $params = array (
+                       'form_name' => "RapidHtml",
+                       'appeal' => "JimmyQuote",
+                       'ffname' => $form_key,
+               );
+
+               if ( array_key_exists( 'ffname', $other_params ) ) {
+                       unset( $other_params['ffname'] );
+               }
+
+               $params = array_merge( $params, $other_params );
+
+               $form_info = self::getFormDefinition( $form_key );
+
+               if ( DataValidator::value_appears_in( 'redirect', $form_info ) 
) {
+                       $params['redirect'] = '1';
+               }
+
+               // set the default redirect
+               //TODO: this is going to be a problem here if we start defining 
more than one gateway per form.
+               return self::getTitleFor( ucfirst( $form_info['gateway'] ) . 
"Gateway" )->getLocalUrl( $params );
+       }
+
        /**
         * Gets all the valid forms that match the provided paramters. 
         * @global array $wgDonationInterfaceAllowedHtmlForms Contains all 
whitelisted forms and meta data
@@ -182,7 +199,16 @@
                }
                return $forms;
        }
-       
+
+       static function getFormDefinition( $form_key ) {
+               global $wgDonationInterfaceAllowedHtmlForms;
+               if ( array_key_exists( $form_key, 
$wgDonationInterfaceAllowedHtmlForms ) ) {
+                       return $wgDonationInterfaceAllowedHtmlForms[$form_key];
+               } else {
+                       return false;
+               }
+       }
+
        /**
         * Return an array of all the currently enabled gateways. 
         * I had hoped there would be more to this...

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6b1baffd664ae814740bf57774c9f62859a3eefc
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Katie Horn <kh...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to