r101502 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101501‎ | r101502 | r101503 >
Date:17:14, 1 November 2011
Author:khorn
Status:ok (Comments)
Tags:
Comment:
Actually fixes the api calls that handle gateway forms with _cache_ set to true, and a utm_source_id set.
r101441
Modified paths:
  • /trunk/extensions/DonationInterface/gateway_common/DonationData.php (modified) (history)
  • /trunk/extensions/DonationInterface/gateway_forms/Form.php (modified) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/api_payflowpro_gateway.php (modified) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/pfp_api_controller.js (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/payflowpro_gateway/api_payflowpro_gateway.php
@@ -51,6 +51,9 @@
5252 'gateway' => array(
5353 ApiBase::PARAM_TYPE => 'string',
5454 ),
 55+ 'payment_method' => array(
 56+ ApiBase::PARAM_TYPE => 'string',
 57+ ),
5558 );
5659 }
5760
@@ -58,6 +61,8 @@
5962 return array(
6063 'dispatch' => 'the API method from which to return data',
6164 'tracking_data' => 'A JSON formatted string of data to insert into contribution_tracking',
 65+ 'gateway' => 'The current gateway',
 66+ 'payment_method' => 'The current payment method'
6267 );
6368 }
6469
@@ -148,10 +153,8 @@
149154 * pageref => the url-encoded referrer to the full user-requested URL
150155 */
151156 $tracking_data = $this->parseTrackingData( json_decode( $params[ 'tracking_data' ], true ) );
152 -
153157 //instantiate a new DonationData that behaves like it's owned by the correct gateway.
154158 $donationDataObj = new DonationData( $gateway_class, false, $tracking_data );
155 -
156159 // fetch the order_id
157160 $order_id = $donationDataObj->getVal( 'order_id' );
158161
Index: trunk/extensions/DonationInterface/payflowpro_gateway/pfp_api_controller.js
@@ -17,7 +17,11 @@
1818 'action' : 'pfp',
1919 'dispatch' : 'get_required_dynamic_form_elements',
2020 'format' : 'json',
21 - 'tracking_data' : '{"url": "'+escape(window.location)+'", "pageref": "'+escape(document.referrer)+'"}'
 21+ 'tracking_data' : '{"url": "'+escape(window.location)+
 22+ '", "pageref": "'+escape(document.referrer)+
 23+ '", "gateway": "'+escape(document.gateway)+
 24+ '", "payment_method": "'+escape(document.payment_method)+
 25+ '"}'
2226 }, processFormElements, 'json' );
2327 };
2428
Index: trunk/extensions/DonationInterface/gateway_forms/Form.php
@@ -423,6 +423,7 @@
424424 'action' => $this->form_data['action'],
425425 'owa_session' => $this->form_data['owa_session'],
426426 'owa_ref' => $this->form_data['owa_ref'],
 427+ 'gateway' => $this->form_data['gateway'],
427428 );
428429 }
429430
Index: trunk/extensions/DonationInterface/gateway_common/DonationData.php
@@ -259,23 +259,22 @@
260260 * assigned.
261261 */
262262 function handleContributionTrackingID(){
263 - //TODO: test with _cache_ on.
264 -
265 - //what follows here is the original horrible if statement for comparison to the new line (below).
266 - //TODO: whack this when we know the replacement is solid.
267 -// if ( !empty( $this->normalized ) &&
268 -// ( $this->getVal( 'numAttempt' ) == '0' &&
269 -// ((!$this->getVal( 'utm_source_id' ) == false ) ||
270 -// is_null($this->getVal( '_cache_' )) ) ) ) {
271 -// $this->saveContributionTracking();
272 -// }
273 -
274263 if ( !$this->isSomething( 'contribution_tracking_id' ) &&
275 - ( $this->getVal( 'utm_source_id' ) !== false || !$this->isSomething( '_cache_' ) ) ){
 264+ ( !$this->canCache() ) ){
276265 $this->saveContributionTracking();
277266 }
278267 }
279 -
 268+
 269+
 270+ function canCache(){
 271+ if ( $this->getVal( '_cache_' ) === 'true' ){ //::head. hit. keyboard.::
 272+ if ( $this->isSomething( 'utm_source_id' ) && $this->getVal( 'utm_source_id' ) !== false ){
 273+ return true;
 274+ }
 275+ }
 276+ return false;
 277+ }
 278+
280279 /**
281280 * normalizeAndSanitize helper function.
282281 * Takes all possible sources for the intended donation amount, and
@@ -554,8 +553,14 @@
555554
556555 $utm_source = $this->getVal( 'utm_source' );
557556 $utm_source_id = $this->getVal( 'utm_source_id' );
558 - $payment_method = $this->getVal( 'payment_method' );
559557
 558+ //TODO: Seriously, you need to move this.
 559+ if ( $this->isSomething('payment_method') ){
 560+ $payment_method = $this->getVal( 'payment_method' );
 561+ } else {
 562+ $payment_method = 'cc';
 563+ }
 564+
560565 // this is how the payment method portion of the utm_source should be defined
561566 $correct_payment_method_source = ( $utm_source_id ) ? $payment_method . $utm_source_id . '.' . $payment_method : $payment_method;
562567

Follow-up revisions

RevisionCommit summaryAuthorDate
r101631Defaults utm_source_id to null on a form pull, and checks for not null for ca...khorn15:50, 2 November 2011
r101648MFT r101441, r101502, r101631awjrichards18:17, 2 November 2011
r101752MFT r101441, r101502awjrichards23:53, 2 November 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r101441Fixes the api calls that handle gateway forms with _cache_ set to true, and a...khorn00:07, 1 November 2011

Comments

#Comment by Awjrichards (talk | contribs)   03:56, 2 November 2011
+	function canCache(){
+		if ( $this->getVal( '_cache_' ) === 'true' ){ //::head. hit. keyboard.::
+			if ( $this->isSomething( 'utm_source_id' ) && $this->getVal( 'utm_source_id' ) !== false ){
+				return true;
+			}
+		}
+		return false;
+	}

Because you have utm_source_id defaulting to '0' (from line ~99 of DonationData.php):

'utm_source_id' => $wgRequest->getVal( 'utm_source_id', 0 )

This will /always/ return true when _cache_=true is set. You might consider defaulting utm_source_id to NULL and checking if ( !is_null( $this->getVal( 'utm_source_id' ))).

I know this is the lamest way ever to handle caching. Hopefully we can get around to making this suck less.

Also,

+		//TODO: Seriously, you need to move this. 
+		if ( $this->isSomething('payment_method') ){
+			$payment_method = $this->getVal( 'payment_method' );
+		} else {
+			$payment_method = 'cc';
+		}

I'm not sure you need to do this since you're defaulting payment_method to 'cc' in DonationData (~line 61).

#Comment by Khorn (WMF) (talk | contribs)   15:33, 2 November 2011

Actually, the reason for both of these things is the same tricky thing that messed me up for way too long. When we're coming in through the API, we don't have a form post, so none of the code that defaults the values on a form post pull gets run. I construct the DonationData object with only the values that the API passes back to me (api_payflowpro_gateway.php, line 157). It's faster, but it short-circuits a heck of a lot of stuff that keeps us safer when we're pulling from an entire form. However, as we're only really using the object to set/check the edit token and get a contribution_tracking row, I figured it was not completely insane.

Also, that check for 'true' up there, is actually looking for the string 'true'... and getVal returns the whole value, not just isSomething. I promise it works. :)

#Comment by Khorn (WMF) (talk | contribs)   15:51, 2 November 2011

And, by "I promise it works" apparently I meant "in caching mode". Defaulted utm_source_id to null like you suggested, checked everything again, and NOW... it works. r101631

#Comment by Awjrichards (talk | contribs)   16:00, 2 November 2011

\0/

#Comment by Awjrichards (talk | contribs)   03:57, 2 November 2011

oops accidentally selected 'reverted' rather than 'fixme'.

Status & tagging log