r97579 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97578‎ | r97579 | r97580 >
Date:23:48, 19 September 2011
Author:khorn
Status:ok (Comments)
Tags:fundraising 
Comment:
Wraps up the basic requirements for fundraiser cards #280 and #300.
Modified paths:
  • /branches/fundraising/extensions/DonationInterface/donationinterface.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/gateway_common/DonationData.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/gateway_common/gateway.adapter.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect_gateway.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect_resultswitcher.body.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/modules/iframe.liberator.js (modified) (history)

Diff [purge]

Index: branches/fundraising/extensions/DonationInterface/donationinterface.php
@@ -61,6 +61,13 @@
6262 //THE GATEWAYS WILL RESET THIS when they are instantiated. You can override it, but it won't stick around that way.
6363 $wgDonationInterfaceTest = false;
6464
 65+
 66+/**
 67+ * Default Thank You and Fail pages for all of donationinterface - language will be calc'd and appended at runtime.
 68+ */
 69+$wgDonationInterfaceThankYouPage = 'Donate-thanks';
 70+$wgDonationInterfaceFailPage = 'Donate-error';
 71+
6572 //This is going to be a little funky.
6673 //Override this in LocalSettings.php BEFORE you include this file, if you want
6774 //to disable gateways.
@@ -98,7 +105,7 @@
99106 $wgResourceModules['iframe.liberator'] = array(
100107 'scripts' => 'iframe.liberator.js',
101108 'position' => 'top'
102 -) + $wgResourceTemplate;
 109+ ) + $wgResourceTemplate;
103110
104111 function efDonationInterfaceUnitTests( &$files ) {
105112 $files[] = dirname( __FILE__ ) . '/tests/GatewayAdapterTest.php';
Index: branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect_resultswitcher.body.php
@@ -41,8 +41,18 @@
4242 global $wgRequest, $wgOut, $wgExtensionAssetsPath,
4343 $wgPayFlowProGatewayCSSVersion;
4444
45 - $wgOut->allowClickjacking();
46 - $wgOut->addModules( 'iframe.liberator' );
 45+ $referrer = $wgRequest->getHeader( 'referer' );
 46+
 47+ global $wgServer;
 48+ //TODO: Whitelist! We only want to do this for servers we are configured to like!
 49+ //I didn't do this already, because this may turn out to be backwards anyway. It might be good to do the work in the iframe,
 50+ //and then pop out. Maybe. We're probably going to have to test it a couple different ways, for user experience.
 51+ //However, we're _definitely_ going to need to pop out _before_ we redirect to the thank you or fail pages.
 52+ if ( strpos( $referrer, $wgServer ) === false ) {
 53+ $wgOut->allowClickjacking();
 54+ $wgOut->addModules( 'iframe.liberator' );
 55+ return;
 56+ }
4757
4858 $wgOut->addExtensionStyle(
4959 $wgExtensionAssetsPath . '/DonationInterface/gateway_forms/css/gateway.css?284' .
@@ -55,9 +65,42 @@
5666 if ( $this->adapter->checkTokens() ) {
5767 // Display form for the first time
5868 $oid = $wgRequest->getText( 'order_id' );
59 - if ( $oid && !empty( $oid ) ) {
60 - $result = $this->adapter->do_transaction( 'GET_ORDERSTATUS' );
 69+ $adapter_oid = $this->adapter->getData();
 70+ $adapter_oid = $adapter_oid['order_id'];
 71+ if ( $oid && !empty( $oid ) && $oid === $adapter_oid ) {
 72+ if ( !array_key_exists( 'order_status', $_SESSION ) || !array_key_exists( $oid, $_SESSION['order_status'] ) ) {
 73+ $_SESSION['order_status'][$oid] = $this->adapter->do_transaction( 'GET_ORDERSTATUS' );
 74+ $_SESSION['order_status'][$oid]['data']['count'] = 0;
 75+ } else {
 76+ $_SESSION['order_status'][$oid]['data']['count'] = $_SESSION['order_status'][$oid]['data']['count'] + 1;
 77+ }
 78+ $result = $_SESSION['order_status'][$oid];
6179 $this->displayResultsForDebug( $result );
 80+ //do the switching between the... stuff.
 81+
 82+ switch ( $result['data']['WMF_STATUS'] ) {
 83+ case 'complete':
 84+ $wgOut->addHTML( "Add successful stomp message, go to the thank you page..." );
 85+ $go = $this->adapter->getThankYouPage();
 86+ break;
 87+ case 'pending':
 88+ $wgOut->addHTML( "Add pending stomp message, go to the thank you page..." );
 89+ $go = $this->adapter->getThankYouPage();
 90+ break;
 91+ case 'pending-poke':
 92+ $wgOut->addHTML( "Add pending stomp message, go to the thank you page, add some indicator that we need to do something." );
 93+ $go = $this->adapter->getThankYouPage();
 94+ break;
 95+ case 'failed':
 96+ $wgOut->addHTML( "Toss it, go to fail page..." );
 97+ $go = $this->adapter->getFailPage();
 98+ break;
 99+ }
 100+
 101+ //TODO: Save your user session data before you get here...
 102+ $this->adapter->unsetAllGatewaySessionData();
 103+ $wgOut->addHTML( "<br>Redirecting to page $go" );
 104+ $wgOut->redirect( $go );
62105 }
63106 $this->adapter->log( "Not posted, or not processed. Showing the form for the first time." );
64107 } else {
@@ -97,14 +140,14 @@
98141 } else {
99142 $wgOut->addHTML( "Empty Results" );
100143 }
101 - if (array_key_exists('Donor', $_SESSION)){
102 - $wgOut->addHTML("Session Donor Vars:<ul>");
103 - foreach ($_SESSION['Donor'] as $key=>$val){
 144+ if ( array_key_exists( 'Donor', $_SESSION ) ) {
 145+ $wgOut->addHTML( "Session Donor Vars:<ul>" );
 146+ foreach ( $_SESSION['Donor'] as $key => $val ) {
104147 $wgOut->addHTML( "<li>$key: $val" );
105148 }
106 - $wgOut->addHTML("</ul>");
 149+ $wgOut->addHTML( "</ul>" );
107150 } else {
108 - $wgOut->addHTML("No Session Donor Vars:<ul>");
 151+ $wgOut->addHTML( "No Session Donor Vars:<ul>" );
109152 }
110153 }
111154
Index: branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php
@@ -145,7 +145,8 @@
146146 ),
147147 'values' => array(
148148 'ACTION' => 'INSERT_ORDERWITHPAYMENT',
149 - 'HOSTEDINDICATOR' => '1'
 149+ 'HOSTEDINDICATOR' => '1',
 150+ //'PAYMENTPRODUCTID' => '11',
150151 ),
151152 );
152153
@@ -258,7 +259,7 @@
259260 break;
260261 case 'GET_ORDERSTATUS':
261262 $data = $this->xmlChildrenToArray( $response, 'STATUS' );
262 - $data['WMF_TRANSLATEDCODE'] = $this->findCodeAction( 'GET_ORDERSTATUS', 'STATUSID', $data['STATUSID'] );
 263+ $data['WMF_STATUS'] = $this->findCodeAction( 'GET_ORDERSTATUS', 'STATUSID', $data['STATUSID'] );
263264 $data['ORDER'] = $this->xmlChildrenToArray( $response, 'ORDER' );
264265 break;
265266 }
Index: branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect_gateway.php
@@ -114,4 +114,10 @@
115115 * should be in USD.
116116 */
117117 $wgGlobalCollectGatewayPriceFloor = '1.00';
118 -$wgGlobalCollectGatewayPriceCieling = '10000.00';
 118+$wgGlobalCollectGatewayPriceCeiling = '10000.00';
 119+
 120+/**
 121+ * Thank You & Fail pages.
 122+ */
 123+$wgGlobalCollectGatewayThankYouPage = $wgDonationInterfaceThankYouPage;
 124+$wgGlobalCollectGatewayFailPage = $wgDonationInterfaceFailPage;
\ No newline at end of file
Index: branches/fundraising/extensions/DonationInterface/modules/iframe.liberator.js
@@ -1,4 +1,3 @@
2 -
32 if (top.frames.length!=0){
43 top.location=self.document.location;
54 }
\ No newline at end of file
Index: branches/fundraising/extensions/DonationInterface/gateway_common/gateway.adapter.php
@@ -124,7 +124,6 @@
125125 * Override this in children if you want different defaults.
126126 */
127127 function setPostDefaults() {
128 -// $returnTitle = Title::newFromText( 'Donate-thanks/en' );
129128 $returnTitle = Title::newFromText( 'Special:GlobalCollectGatewayResult' );
130129 $returnto = $returnTitle->getFullURL();
131130
@@ -140,6 +139,24 @@
141140 );
142141 }
143142
 143+ function getThankYouPage() {
 144+ global $wgLang;
 145+ $language = $wgLang->getCode();
 146+ $page = self::getGlobal( "ThankYouPage" ) . "/$language";
 147+ $returnTitle = Title::newFromText( $page );
 148+ $returnto = $returnTitle->getFullURL();
 149+ return $returnto;
 150+ }
 151+
 152+ function getFailPage() {
 153+ global $wgLang;
 154+ $language = $wgLang->getCode();
 155+ $page = self::getGlobal( "FailPage" ) . "/$language";
 156+ $returnTitle = Title::newFromText( $page );
 157+ $returnto = $returnTitle->getFullURL();
 158+ return $returnto;
 159+ }
 160+
144161 function checkTokens() {
145162 return $this->dataObj->checkTokens();
146163 }
@@ -619,9 +636,13 @@
620637 //if we walk straight off the end...
621638 return null;
622639 }
623 -
624 - function addDonorDataToSession(){
 640+
 641+ function addDonorDataToSession() {
625642 $this->dataObj->addDonorDataToSession();
626643 }
627644
 645+ function unsetAllGatewaySessionData() {
 646+ $this->dataObj->unsetAllDDSessionData();
 647+ }
 648+
628649 }
Index: branches/fundraising/extensions/DonationInterface/gateway_common/DonationData.php
@@ -235,15 +235,14 @@
236236 function setNormalizedOrderIDs() {
237237 //basically, we need a new order_id every time we come through here, but if there's an internal already there,
238238 //we want to use that one internally. So.
239 -
240239 //Exception: If we pass in an order ID in the querystring: Don't mess with it.
241240 //TODO: I'm pretty sure I'm not supposed to do this directly.
242 - if (array_key_exists('order_id', $_GET)){
 241+ if ( array_key_exists( 'order_id', $_GET ) ) {
243242 $this->setVal( 'order_id', $_GET['order_id'] );
244243 $this->setVal( 'i_order_id', $_GET['order_id'] );
245244 return;
246245 }
247 -
 246+
248247 $this->setVal( 'order_id', $this->generateOrderId() );
249248
250249 if ( !$this->isSomething( 'i_order_id' ) ) {
@@ -651,8 +650,8 @@
652651 $db->update( 'contribution_tracking', $tracked_contribution, array( 'id' => $this->getVal( 'contribution_tracking_id' ) ) );
653652 }
654653 }
655 -
656 - public function addDonorDataToSession(){
 654+
 655+ public function addDonorDataToSession() {
657656 self::ensureSession();
658657 $donordata = array(
659658 'email',
@@ -664,16 +663,26 @@
665664 'state',
666665 'zip',
667666 'country',
 667+ 'contribution_tracking_id'
668668 );
669 -
670 - foreach ($donordata as $item){
671 - if ($this->isSomething($item)){
672 - $_SESSION['Donor'][$item] = $this->getVal($item);
 669+
 670+ foreach ( $donordata as $item ) {
 671+ if ( $this->isSomething( $item ) ) {
 672+ $_SESSION['Donor'][$item] = $this->getVal( $item );
673673 }
674674 }
675 -
676675 }
677676
 677+ /**
 678+ * TODO: Consider putting all the session data for a gateway under something like
 679+ * $_SESSION[$gateway_identifier]
 680+ * so we can kill it all with one stroke.
 681+ */
 682+ public function unsetAllDDSessionData() {
 683+ unset( $_SESSION['Donor'] );
 684+ $this->unsetEditToken();
 685+ }
 686+
678687 }
679688
680689 ?>

Comments

#Comment by Khorn (WMF) (talk | contribs)   18:42, 23 September 2011

Please note that this branch is in the middle of a serious refactoring, and is by no means ready to be merged back into trunk. (Latest DonationInterface branch rev at the time of this comment is r97833.)

Status & tagging log