Adamw has submitted this change and it was merged. 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, 175 insertions(+), 34 deletions(-) Approvals: Adamw: Looks good to me, approved Siebrand: Looks good to me, but someone else must approve jenkins-bot: Verified diff --git a/gateway_common/DonationData.php b/gateway_common/DonationData.php index c9a1f85..02a891d 100644 --- a/gateway_common/DonationData.php +++ b/gateway_common/DonationData.php @@ -157,20 +157,20 @@ * If donor session data has been set, pull the fields in the session that * are populated, and merge that with the data set we already have. */ - protected function integrateDataFromSession(){ + protected function integrateDataFromSession() { + /** if the thing coming in from the session isn't already something, + * replace it. + * if it is: assume that the session data was meant to be replaced + * with better data. + * ...unless it's an explicit $overwrite * */ if ( self::sessionExists() && array_key_exists( 'Donor', $_SESSION ) ) { - //if the thing coming in from the session isn't already something, - //replace it. - //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 ){ + //fields that should always overwrite with their original values + $overwrite = array ( 'referrer' ); + 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' ){ + if ( in_array( $key, $overwrite ) ) { $this->setVal( $key, $val ); } } @@ -1289,11 +1289,47 @@ self::ensureSession(); $donordata = $this->getStompMessageFields(); $donordata[] = 'order_id'; - + foreach ( $donordata as $item ) { if ( $this->isSomething( $item ) ) { $_SESSION['Donor'][$item] = $this->getVal( $item ); } + } + } + + /** + * Add a RapidHTML Form (ffname) to this abridged history of where we've + * been in this session. This lets us do things like construct useful + * "back" links that won't crush all session everything. + * @param string $form_key The 'ffname' that RapidHTML uses to load a + * payments form. Additional: ffname maps to a first-level key in + * $wgDonationInterfaceAllowedHtmlForms + */ + 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; + } + } + + /** + * Get the 'ffname' of the last RapidHTML payment form that successfully + * loaded for this session. + * @return mixed ffname of the last valid payments form if there is one, + * otherwise false. + */ + public function getLastRapidHTMLForm() { + self::ensureSession(); + if ( !array_key_exists( 'PaymentForms', $_SESSION ) || !is_array( $_SESSION['PaymentForms'] ) ) { + return false; + } else { + return end( $_SESSION['PaymentForms'] ); } } @@ -1404,7 +1440,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 +1484,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..4d6c92d 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,15 @@ public function getMerchantID() { return $this->account_config[ 'MerchantID' ]; } + + /** + * Get the 'ffname' of the last RapidHTML payment form that successfully + * loaded for this session. + * @return mixed ffname of the last valid payments form if there is one, + * otherwise false. + */ + public function getLastRapidHTMLForm() { + return $this->dataObj->getLastRapidHTMLForm(); + } + } diff --git a/gateway_common/interface.i18n.php b/gateway_common/interface.i18n.php index 05df741..96cc565 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.', @@ -809,6 +810,10 @@ * $1 - link back to the form to try another credit card * $2 - link to other payment methods * $3 - an e-mail address link such as: mailto:some...@example.com', + 'donate_interface-donate-error-try-again-html' => 'This html-formatted message will be used on dynamic error pages for all payment types. Parameters: +* $1 - link back to the payments form most recently used by the donor, to try again +* $2 - link to other payment methods +* $3 - an e-mail address, where the donor can report problems. Example: problemsdonat...@wikimedia.org', 'donate_interface-donate-error-thank-you-for-your-support' => 'Thank you for your support!', 'donate_interface-error-no-form' => 'Error message given if no form or payment method is available in this language/country/currency.', 'php-response-declined' => 'Error message if the translaction was declined.', 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 8a5572c..19c50b3 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,28 @@ } return $forms; } - + + /** + * Gets the array of settings and capability definitions for the form + * specified in $form_key. + * @global array $wgDonationInterfaceAllowedHtmlForms The global array + * of whitelisted (enabled) RapidHTML forms. + * @param string $form_key The name of the form (ffname) we're looking + * for. Should map to a first-level key in + * $wgDonationInterfaceAllowedHtmlForms. + * @return array|boolean The settings and capability definitions for + * that form in array format, or false if it isn't a valid and enabled + * form. + */ + 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: merged Gerrit-Change-Id: I6b1baffd664ae814740bf57774c9f62859a3eefc Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/extensions/DonationInterface Gerrit-Branch: master Gerrit-Owner: Katie Horn <kh...@wikimedia.org> Gerrit-Reviewer: Adamw <awi...@wikimedia.org> Gerrit-Reviewer: Jeremyb <jer...@tuxmachine.com> Gerrit-Reviewer: Katie Horn <kh...@wikimedia.org> Gerrit-Reviewer: Mwalker <mwal...@wikimedia.org> Gerrit-Reviewer: Siebrand <siebr...@wikimedia.org> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits