r101441 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101440‎ | r101441 | r101442 >
Date:00:07, 1 November 2011
Author:khorn
Status:ok
Tags:
Comment:
Fixes the api calls that handle gateway forms with _cache_ set to true, and a utm_source_id set.
Had to clean up some less than ideal code to do this, mostly in DonationData. Biggest sub-news here is that now we can load in non-test donation data from wherever we want on construct, and that the last of the fields that were calculated on load (particularly from a form) have been moved off to the Normalize and Sanitize portion of the show.
Also: 'card' is now no longer a valid payment_method. ('cc' is the new correct answer)
Modified paths:
  • /trunk/extensions/DonationInterface/gateway_common/DonationData.php (modified) (history)
  • /trunk/extensions/DonationInterface/gateway_common/donation.api.php (modified) (history)
  • /trunk/extensions/DonationInterface/gateway_forms/includes/payflowUser.inc (deleted) (history)
  • /trunk/extensions/DonationInterface/globalcollect_gateway/forms/js/lightbox1.js (modified) (history)
  • /trunk/extensions/DonationInterface/globalcollect_gateway/forms/js/webitects_2_3step.js (modified) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/api_payflowpro_gateway.php (modified) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/forms/js/lightbox1.js (modified) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php (modified) (history)
  • /trunk/extensions/DonationInterface/tests/DonationDataTestCase.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/tests/DonationDataTestCase.php
@@ -317,7 +317,7 @@
318318 public static function ensureSession() {
319319 public function checkTokens() {
320320 function wasPosted(){
321 - public static function getUtmSource( $utm_source = null, $utm_source_id = null ) {
 321+ function setUtmSource() {
322322 public function getOptOuts() {
323323 public function getCleanTrackingData( $clean_optouts = false ) {
324324 function saveContributionTracking() {
Index: trunk/extensions/DonationInterface/payflowpro_gateway/api_payflowpro_gateway.php
@@ -2,7 +2,7 @@
33 /**
44 * PayflowPro Gateway API extension
55 * Call with api.php?action=pfp
6 - * TODO: Determine if this is being used by anything anymore, and if so, what.
 6+ * TODO: Move this somewhere that looks more gateway-agnostic.
77 */
88
99 class ApiPayflowProGateway extends ApiBase {
@@ -11,7 +11,7 @@
1212 * An array of valid dispatch methods
1313 */
1414 public $validDispatchMethods = array( 'dispatch_get_required_dynamic_form_elements' );
15 -
 15+
1616 /**
1717 * API for PayflowProGateway extension
1818 *
@@ -26,7 +26,7 @@
2727 // extract and validate the parameters
2828 $params = $this->extractRequestParams();
2929 $this->validateParams( $params );
30 -
 30+
3131 // route 'dispatch' requests to the appropriate method
3232 if ( strlen( $params[ 'dispatch' ] ) ) {
3333 $method = $this->getDispatchMethod( $params[ 'dispatch' ] );
@@ -48,6 +48,9 @@
4949 'tracking_data' => array(
5050 ApiBase::PARAM_TYPE => 'string',
5151 ),
 52+ 'gateway' => array(
 53+ ApiBase::PARAM_TYPE => 'string',
 54+ ),
5255 );
5356 }
5457
@@ -73,7 +76,7 @@
7477 if ( isset( $params[ 'dispatch' ] ) && strlen( $params[ 'dispatch' ] ) ) {
7578 $method = $this->getDispatchMethod( $params[ 'dispatch' ] );
7679 if ( !in_array( $method, $this->validDispatchMethods ) || !method_exists( $this, $method ) ) {
77 - $this->dieUsage( "Invalid dispatch method <<<$method>>> passed to the PayflowPro Gatweay API.", 'unknown_method' );
 80+ $this->dieUsage( "Invalid dispatch method <<<$method>>> passed to the Donation Interface Gateway API.", 'unknown_method' );
7881 }
7982
8083 // make sure we have tracking data for get_required_dynamic_form_elements
@@ -122,18 +125,21 @@
123126 * elements.
124127 */
125128 protected function dispatch_get_required_dynamic_form_elements( $params ) {
126 - global $wgPayflowProGatewaySalt;
127129
128 - // fetch the order_id
129 - //TODO: This include should be *very* deprecated. All the functionality there has been
130 - //recently eaten by gateway.adapter.php and DontationData.php.
131 - require_once( 'includes/payflowUser.inc' );
132 - $payflow_data = payflowUser();
133 - $order_id = $payflow_data[ 'order_id' ];
134 -
135 - // fetch the CSRF prevention token and set it if it's not already set
136 - $token = PayflowProGateway::fnPayflowEditToken( $wgPayflowProGatewaySalt );
137 -
 130+ //Get the gateway class name. We don't need to instantiate: Just get the name
 131+ //so we can get a new DonationData that *thinks* it's being instantiated by
 132+ //the relevent gateway class.
 133+ $gateway_class = '';
 134+ switch ( $params['gateway'] ){
 135+ case 'globalcollect' :
 136+ $gateway_class = 'GlobalCollectAdapter';
 137+ break;
 138+ case 'payflowpro' :
 139+ default:
 140+ $gateway_class = 'PayflowProAdapter';
 141+ break;
 142+ }
 143+
138144 /**
139145 * retrieve and unpack the json encoded string of tracking data
140146 *
@@ -142,12 +148,19 @@
143149 * pageref => the url-encoded referrer to the full user-requested URL
144150 */
145151 $tracking_data = $this->parseTrackingData( json_decode( $params[ 'tracking_data' ], true ) );
 152+
 153+ //instantiate a new DonationData that behaves like it's owned by the correct gateway.
 154+ $donationDataObj = new DonationData( $gateway_class, false, $tracking_data );
 155+
 156+ // fetch the order_id
 157+ $order_id = $donationDataObj->getVal( 'order_id' );
146158
147 - // clean up tracking data to make sure everything is set correctly
148 - $tracking_data = PayflowProGateway::cleanTrackingData( $tracking_data, true );
 159+ // fetch the CSRF prevention token and set it if it's not already set
 160+ $token = $donationDataObj->token_getSaltedSessionToken();
149161
150 - // fetch the contribution_tracking_id by inserting tracking data to contrib tracking table
151 - $contribution_tracking_id = PayflowProGateway::insertContributionTracking( $tracking_data );
 162+ //I'd just call DD's saveContributionTracking, but we need all the parts out here.
 163+ $tracking_data = $donationDataObj->getCleanTrackingData();
 164+ $contribution_tracking_id = $donationDataObj::insertContributionTracking( $tracking_data );
152165
153166 // this try/catch design pattern stolen from ClickTracking/ApiSpecialClickTracking.php
154167 try {
@@ -175,11 +188,7 @@
176189 // add the referrer to the tracked_data array
177190 $tracking_data[ 'referrer' ] = urldecode( $unparsed_tracking_data[ 'pageref' ] );
178191
179 - // ensure the utm_source is formatted correctly
180 - $utm_source_str = ( isset( $tracking_data[ 'utm_source' ] ) ) ? $tracking_data[ 'utm_source' ] : null;
181 - $utm_source_id = ( isset( $tracking_data[ 'utm_source_id' ] ) ) ? $tracking_data[ 'utm_source_id' ] : null;
182 - $tracking_data[ 'utm_source' ] = PayflowProGateway::getUtmSource( $utm_source_str, $utm_source_id );
183 -
 192+ //DonationData handles the utm normalization now.
184193 return $tracking_data;
185194 }
186195
Index: trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php
@@ -40,7 +40,7 @@
4141
4242 // dispatch forms/handling
4343 if ( $this->adapter->checkTokens() ) {
44 - if ( $this->adapter->posted) {
 44+ if ( $this->adapter->posted ) {
4545 // The form was submitted and the payment method has been set
4646 // Check form for errors
4747 $form_errors = $this->validateForm( $this->errors );
Index: trunk/extensions/DonationInterface/payflowpro_gateway/forms/js/lightbox1.js
@@ -147,7 +147,7 @@
148148 'zip': $( "input[name='zip']" ).val(),
149149 'emailAdd': $( "input[name='emailAdd']" ).val(),
150150 'country': $( "input[name='country']" ).val(),
151 - 'payment_method': 'card',
 151+ 'payment_method': 'cc',
152152 'language': 'en',
153153
154154 'expiration': $( "input[name='expiration']" ).val(),
Index: trunk/extensions/DonationInterface/gateway_forms/includes/payflowUser.inc
@@ -1,80 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * Payflow Pro account information
6 - * Payflow individual account information must be defined in the LocalSettings.php file
7 - */
8 -function payflowUser() {
9 - // User account information from LocalSettings.php
10 - global $wgPayflowProPartnerID,
11 - $wgPayflowProVendorID,
12 - $wgPayflowProUserID,
13 - $wgPayflowProPassword,
14 - $wgPayflowProURL,
15 - $wgPayflowProTestingURL,
16 - $wgPayflowGatewayTest;
17 -
18 - $payflow_data = array(
19 - 'partner' => $wgPayflowProPartnerID, // PayPal or original authorized reseller
20 - 'vendor' => $wgPayflowProVendorID, // paypal merchant login ID
21 - 'user' => $wgPayflowProUserID, // if one or more users are set up, authorized user ID, else same as VENDOR
22 - 'password' => $wgPayflowProPassword, // merchant login password
23 - 'paypalurl' => $wgPayflowProURL,
24 - 'testingurl' => $wgPayflowProTestingURL, // Payflow testing URL
25 - 'trxtype' => 'S', // transaction type - all donations are a sale
26 - 'tender' => 'C', // credit card - all transactions in this case are credit cards
27 - 'verbosity' => 'MEDIUM', // level of detail in Payflow response
28 - 'user_ip' => ( $wgPayflowGatewayTest ) ? '12.12.12.12' : wfGetIP(), // current user's IP address
29 - 'order_id' => payflowGetOrderId(),
30 - 'i_order_id' => payflowGetInternalOrderId(),
31 - );
32 -
33 - return $payflow_data;
34 -}
35 -
36 -/**
37 - * Fetch and return the 'order_id' for a transaction
38 - *
39 - * Since transactions to PayPal are initially matched internally on their end
40 - * with the 'order_id' field, but we don't actually care what the order id is,
41 - * we generate a sufficiently random number to avoid duplication.
42 - *
43 - * We go ahead and always generate a random order id becuse if PayPal detects
44 - * the same order_id more than once, it considers the request a duplicate, even
45 - * if the data is completely different.
46 - *
47 - * @return int
48 - */
49 -function payflowGetOrderId() {
50 - return generateOrderId();
51 -}
52 -
53 -/**
54 - * Generate an internal order id
55 - *
56 - * This is only used internally for tracking a user's 'session' with the credit
57 - * card form. I mean 'session' in the sense of the moment a credit card page
58 - * is loaded for the first time (nothing posted to it - a discrete donation
59 - * session) as opposed to the $_SESSION - as the $_SESSION id could potentially
60 - * not change between contribution attempts.
61 - */
62 -function payflowGetInternalOrderId() {
63 - global $wgRequest;
64 -
65 - // is an order_id already set?
66 - $i_order_id = $wgRequest->getText( 'i_order_id', 0 );
67 -
68 - // if the form was not just posted OR there's no order_id set, generate one.
69 - if ( !$wgRequest->wasPosted() || !$i_order_id ) {
70 - $i_order_id = generateOrderId();
71 - }
72 -
73 - return $i_order_id;
74 -}
75 -
76 -/**
77 - * Generate an order id
78 - */
79 -function generateOrderId() {
80 - return (double) microtime() * 1000000 . mt_rand();
81 -}
\ No newline at end of file
Index: trunk/extensions/DonationInterface/globalcollect_gateway/forms/js/webitects_2_3step.js
@@ -156,7 +156,7 @@
157157 'zip': $( "input[name='zip']" ).val(),
158158 'emailAdd': $( "input[name='emailAdd']" ).val(),
159159 'country': $( "input[name='country']" ).val(),
160 - 'payment_method': 'card',
 160+ 'payment_method': 'cc',
161161 'language': language,
162162 'card_type': $( "input[name='cardtype']:checked" ).val().toLowerCase(),
163163 'contribution_tracking_id': $( "input[name='contribution_tracking_id']" ).val(),
Index: trunk/extensions/DonationInterface/globalcollect_gateway/forms/js/lightbox1.js
@@ -138,7 +138,7 @@
139139 'zip': $( "input[name='zip']" ).val(),
140140 'emailAdd': $( "input[name='emailAdd']" ).val(),
141141 'country': $( "input[name='country']" ).val(),
142 - 'payment_method': 'card',
 142+ 'payment_method': 'cc',
143143 'language': 'en',
144144 'card_type': 'visa',
145145
Index: trunk/extensions/DonationInterface/gateway_common/donation.api.php
@@ -34,7 +34,7 @@
3535 $gatewayObj = new GlobalCollectAdapter();
3636 switch ( $method ) {
3737 // TODO: add other payment methods
38 - case 'card':
 38+ case 'cc':
3939 $result = $gatewayObj->do_transaction( 'INSERT_ORDERWITHPAYMENT' );
4040 break;
4141 default:
@@ -138,7 +138,7 @@
139139 'zip' => '94104',
140140 'emailAdd' => 'test@example.com',
141141 'country' => 'US',
142 - 'payment_method' => 'card',
 142+ 'payment_method' => 'cc',
143143 'language' => 'en',
144144 'card_type' => 'american',
145145 );
Index: trunk/extensions/DonationInterface/gateway_common/DonationData.php
@@ -18,14 +18,15 @@
1919 $this->populateData( $test, $data );
2020 }
2121
22 - function populateData( $test = false, $testdata = false ) {
 22+ function populateData( $test = false, $external_data = false ) {
2323 global $wgRequest;
2424 $this->normalized = array( );
25 - if ( $test ) {
26 - $this->populateData_Test( $testdata );
 25+ if ( is_array( $external_data ) ){
 26+ $this->normalized = $external_data;
 27+ } elseif ( $test ) {
 28+ $this->populateData_Test();
2729 } else {
2830 $this->normalized = array(
29 - 'posted' => 'true', //moderately sneaky.
3031 'amount' => $wgRequest->getText( 'amount', null ),
3132 'amountGiven' => $wgRequest->getText( 'amountGiven', null ),
3233 'amountOther' => $wgRequest->getText( 'amountOther', null ),
@@ -57,14 +58,15 @@
5859 'expiration' => $wgRequest->getText( 'mos' ) . substr( $wgRequest->getText( 'year' ), 2, 2 ),
5960 'cvv' => $wgRequest->getText( 'cvv' ),
6061 'currency' => $wgRequest->getText( 'currency_code', 'USD' ),
61 - 'payment_method' => $wgRequest->getText( 'payment_method' ),
 62+ 'payment_method' => $wgRequest->getText( 'payment_method', 'cc' ),
6263 'payment_submethod' => $wgRequest->getText( 'payment_submethod', null ), // Used by GlobalCollect for payment types
6364 'issuer_id' => $wgRequest->getText( 'issuer_id' ),
6465 'order_id' => $wgRequest->getText( 'order_id', null ), //as far as I know, this won't actually ever pull anything back.
6566 'i_order_id' => $wgRequest->getText( 'i_order_id', null ), //internal id for each contribution attempt
6667 'numAttempt' => $wgRequest->getVal( 'numAttempt', '0' ),
6768 'referrer' => ( $wgRequest->getVal( 'referrer' ) ) ? $wgRequest->getVal( 'referrer' ) : $wgRequest->getHeader( 'referer' ),
68 - 'utm_source' => self::getUtmSource(), //TODO: yes. That.
 69+ 'utm_source' => $wgRequest->getText( 'utm_source' ),
 70+ 'utm_source_id' => $wgRequest->getVal( 'utm_source_id', 0 ),
6971 'utm_medium' => $wgRequest->getText( 'utm_medium' ),
7072 'utm_campaign' => $wgRequest->getText( 'utm_campaign' ),
7173 // try to honor the user-set language (uselang), otherwise the language set in the URL (language)
@@ -110,10 +112,6 @@
111113 //if it is: assume that the session data was meant to be replaced
112114 //with better data.
113115 //...unless it's referrer.
114 - //TODO: Keep an eye on anything that is calculated programmatically
115 - //during the form data pull, and not afterward in the normalize bits.
116 - //TODO: Stop calculating things during the actual data pull, because
117 - //that's totally bogus.
118116 foreach ( $_SESSION['Donor'] as $key => $val ){
119117 if ( !$this->isSomething( $key ) ){
120118 $this->setVal( $key, $val );
@@ -137,76 +135,72 @@
138136 }
139137
140138 function populateData_Test( $testdata = false ) {
141 - if ( is_array( $testdata ) ) {
142 - $this->normalized = $testdata;
143 - } else {
144 - // define arrays of cc's and cc #s for random selection
145 - $cards = array( 'american' );
146 - $card_nums = array(
147 - 'american' => array(
148 - 378282246310005
149 - ),
150 - );
 139+ // define arrays of cc's and cc #s for random selection
 140+ $cards = array( 'american' );
 141+ $card_nums = array(
 142+ 'american' => array(
 143+ 378282246310005
 144+ ),
 145+ );
151146
152 - // randomly select a credit card
153 - $card_index = array_rand( $cards );
 147+ // randomly select a credit card
 148+ $card_index = array_rand( $cards );
154149
155 - // randomly select a credit card #
156 - $card_num_index = array_rand( $card_nums[$cards[$card_index]] );
 150+ // randomly select a credit card #
 151+ $card_num_index = array_rand( $card_nums[$cards[$card_index]] );
157152
158 - global $wgRequest; //TODO: ARRRGHARGHARGH. That is all.
159 -
160 - $this->normalized = array(
161 - 'amount' => "35",
162 - 'amountOther' => '',
163 - 'email' => 'test@example.com',
164 - 'fname' => 'Tester',
165 - 'mname' => 'T.',
166 - 'lname' => 'Testington',
167 - 'street' => '548 Market St.',
168 - 'city' => 'San Francisco',
169 - 'state' => 'CA',
170 - 'zip' => '94104',
171 - 'country' => 'US',
172 - 'fname2' => 'Testy',
173 - 'lname2' => 'Testerson',
174 - 'street2' => '123 Telegraph Ave.',
175 - 'city2' => 'Berkeley',
176 - 'state2' => 'CA',
177 - 'zip2' => '94703',
178 - 'country2' => 'US',
179 - 'size' => 'small',
180 - 'premium_language' => 'es',
181 - 'card_num' => $card_nums[$cards[$card_index]][$card_num_index],
182 - 'card_type' => $cards[$card_index],
183 - 'expiration' => date( 'my', strtotime( '+1 year 1 month' ) ),
184 - 'cvv' => '001',
185 - 'currency' => 'USD',
186 - 'payment_method' => $wgRequest->getText( 'payment_method' ),
187 - 'payment_submethod' => $wgRequest->getText( 'payment_submethod' ),
188 - 'issuer_id' => $wgRequest->getText( 'issuer_id' ),
189 - 'order_id' => '1234567890',
190 - 'i_order_id' => '1234567890',
191 - 'numAttempt' => 0,
192 - 'referrer' => 'http://www.baz.test.com/index.php?action=foo&action=bar',
193 - 'utm_source' => self::getUtmSource(),
194 - 'utm_medium' => $wgRequest->getText( 'utm_medium' ),
195 - 'utm_campaign' => $wgRequest->getText( 'utm_campaign' ),
196 - 'language' => 'en',
197 - 'comment-option' => $wgRequest->getText( 'comment-option' ),
198 - 'comment' => $wgRequest->getText( 'comment' ),
199 - 'email-opt' => $wgRequest->getText( 'email-opt' ),
200 - // test_string has been disabled - may no longer be needed.
201 - //'test_string' => $wgRequest->getText( 'process' ),
202 - 'token' => '',
203 - 'contribution_tracking_id' => $wgRequest->getText( 'contribution_tracking_id' ),
204 - 'data_hash' => $wgRequest->getText( 'data_hash' ),
205 - 'action' => $wgRequest->getText( 'action' ),
206 - 'gateway' => 'payflowpro',
207 - 'owa_session' => $wgRequest->getText( 'owa_session', null ),
208 - 'owa_ref' => 'http://localhost/defaultTestData',
209 - );
210 - }
 153+ //This array should be populated with general test defaults, or
 154+ //(preferably) mappings to random stuff... if we keep this around at all.
 155+ //Certainly nothing pulled from a form post or get.
 156+ $this->normalized = array(
 157+ 'amount' => "35",
 158+ 'amountOther' => '',
 159+ 'email' => 'test@example.com',
 160+ 'fname' => 'Tester',
 161+ 'mname' => 'T.',
 162+ 'lname' => 'Testington',
 163+ 'street' => '548 Market St.',
 164+ 'city' => 'San Francisco',
 165+ 'state' => 'CA',
 166+ 'zip' => '94104',
 167+ 'country' => 'US',
 168+ 'fname2' => 'Testy',
 169+ 'lname2' => 'Testerson',
 170+ 'street2' => '123 Telegraph Ave.',
 171+ 'city2' => 'Berkeley',
 172+ 'state2' => 'CA',
 173+ 'zip2' => '94703',
 174+ 'country2' => 'US',
 175+ 'size' => 'small',
 176+ 'premium_language' => 'es',
 177+ 'card_num' => $card_nums[$cards[$card_index]][$card_num_index],
 178+ 'card_type' => $cards[$card_index],
 179+ 'expiration' => date( 'my', strtotime( '+1 year 1 month' ) ),
 180+ 'cvv' => '001',
 181+ 'currency' => 'USD',
 182+ 'payment_method' => 'cc',
 183+ 'payment_submethod' => '', //cards have no payment submethods.
 184+ 'issuer_id' => '',
 185+ 'order_id' => '1234567890',
 186+ 'i_order_id' => '1234567890',
 187+ 'numAttempt' => 0,
 188+ 'referrer' => 'http://www.baz.test.com/index.php?action=foo&action=bar',
 189+ 'utm_source' => 'test_src',
 190+ 'utm_source_id' => 0,
 191+ 'utm_medium' => 'test_medium',
 192+ 'utm_campaign' => 'test_campaign',
 193+ 'language' => 'en',
 194+ 'comment-option' => 0,
 195+ 'comment' => 0,
 196+ 'email-opt' => 0,
 197+ 'token' => '',
 198+ 'contribution_tracking_id' => '',
 199+ 'data_hash' => '',
 200+ 'action' => '',
 201+ 'gateway' => 'payflowpro',
 202+ 'owa_session' => '',
 203+ 'owa_ref' => 'http://localhost/defaultTestData',
 204+ );
211205 }
212206
213207 /**
@@ -245,6 +239,7 @@
246240
247241 function normalizeAndSanitize() {
248242 if ( !empty( $this->normalized ) ) {
 243+ $this->setUtmSource();
249244 $this->setNormalizedAmount();
250245 $this->setNormalizedOrderIDs();
251246 $this->setGateway();
@@ -324,7 +319,7 @@
325320 /**
326321 * Generate an order id exactly once for this go-round.
327322 */
328 - function generateOrderId() {
 323+ static function generateOrderId() {
329324 static $order_id = null;
330325 if ( $order_id === null ) {
331326 $order_id = ( double ) microtime() * 1000000 . mt_rand( 1000, 9999 );
@@ -546,50 +541,27 @@
547542 }
548543
549544 /**
550 - * Get the utm_source string
551 - *
 545+ * normalizeAndSanitize helper function.
 546+ *
552547 * Checks to see if the utm_source is set properly for the credit card
553548 * form including any cc form variants (identified by utm_source_id). If
554549 * anything cc form related is out of place for the utm_source, this
555550 * will fix it.
556551 *
557552 * the utm_source is structured as: banner.landing_page.payment_instrument
558 - *
559 - * @param string $utm_source The utm_source for tracking - if not passed directly,
560 - * we try to figure it out from the request object
561 - * @param int $utm_source_id The utm_source_id for tracking - if not passed directly,
562 - * we try to figure it out from the request object
563 - * @return string The full utm_source
564553 */
565 - public static function getUtmSource( $utm_source = null, $utm_source_id = null ) {
566 - global $wgRequest;
 554+ protected function setUtmSource() {
 555+
 556+ $utm_source = $this->getVal( 'utm_source' );
 557+ $utm_source_id = $this->getVal( 'utm_source_id' );
 558+ $payment_method = $this->getVal( 'payment_method' );
 559+
 560+ // this is how the payment method portion of the utm_source should be defined
 561+ $correct_payment_method_source = ( $utm_source_id ) ? $payment_method . $utm_source_id . '.' . $payment_method : $payment_method;
567562
568 - /**
569 - * fetch whatever was passed in as the utm_source
570 - *
571 - * if utm_source was not passed in as a param, we try to divine it from
572 - * the request. if it's not set there, no big deal, we'll just be
573 - * missing some tracking data.
574 - */
575 - if ( is_null( $utm_source ) ) {
576 - $utm_source = $wgRequest->getText( 'utm_source' );
577 - }
578 -
579 - /**
580 - * if we have a utm_source_id, then the user is on a single-step credit card form.
581 - * if that's the case, we treat the single-step credit card form as a landing page,
582 - * which we label as cc#, where # = the utm_source_id
583 - */
584 - if ( is_null( $utm_source_id ) ) {
585 - $utm_source_id = $wgRequest->getVal( 'utm_source_id', 0 );
586 - }
587 -
588 - // this is how the CC portion of the utm_source should be defined
589 - $correct_cc_source = ( $utm_source_id ) ? 'cc' . $utm_source_id . '.cc' : 'cc';
590 -
591563 // check to see if the utm_source is already correct - if so, return
592 - if ( preg_match( '/' . str_replace( ".", "\.", $correct_cc_source ) . '$/', $utm_source ) ) {
593 - return $utm_source;
 564+ if ( !is_null( $utm_source ) && preg_match( '/' . str_replace( ".", "\.", $correct_payment_method_source ) . '$/', $utm_source ) ) {
 565+ return; //nothing to do.
594566 }
595567
596568 // split the utm_source into its parts for easier manipulation
@@ -601,13 +573,14 @@
602574 $source_parts[0] = '';
603575
604576 // if the utm_source_id is set, set the landing page portion of the string to cc#
605 - $source_parts[1] = ( $utm_source_id ) ? 'cc' . $utm_source_id : ( isset( $source_parts[1] ) ? $source_parts[1] : '' );
 577+ $source_parts[1] = ( $utm_source_id ) ? $payment_method . $utm_source_id : ( isset( $source_parts[1] ) ? $source_parts[1] : '' );
606578
607579 // the payment instrument portion should always be 'cc' if this method is being accessed
608 - $source_parts[2] = 'cc';
 580+ $source_parts[2] = $payment_method;
609581
610 - // return a reconstructed string
611 - return implode( ".", $source_parts );
 582+ // reconstruct, and set the value.
 583+ $utm_source = implode( ".", $source_parts );
 584+ $this->setVal( 'utm_source' , $utm_source );
612585 }
613586
614587 /**
@@ -637,9 +610,11 @@
638611 * Compares tracking data array to list of valid tracking fields and
639612 * removes any extra tracking fields/data. Also sets empty values to
640613 * 'null' values.
641 - * @param bool $clean_opouts
 614+ * @param bool $unset If set to true, empty values will be unset from the
 615+ * return array, rather than set to null. (default: false)
 616+ * @return array Clean tracking data
642617 */
643 - public function getCleanTrackingData() {
 618+ public function getCleanTrackingData( $unset = false ) {
644619
645620 // define valid tracking fields
646621 $tracking_fields = array(
@@ -658,7 +633,9 @@
659634 if ( $this->isSomething( $value ) ) {
660635 $tracking_data[$value] = $this->getVal( $value );
661636 } else {
662 - $tracking_data[$value] = null;
 637+ if ( !$unset ){
 638+ $tracking_data[$value] = null;
 639+ }
663640 }
664641 }
665642
@@ -670,7 +647,7 @@
671648 * @return boolean true if we got a contribution tracking # back, false if
672649 * something went wrong.
673650 */
674 - function saveContributionTracking() {
 651+ public function saveContributionTracking() {
675652
676653 $tracked_contribution = $this->getCleanTrackingData();
677654
@@ -717,9 +694,6 @@
718695 * @param array $data Form data
719696 * @param bool $force If set to true, will ensure that contribution tracking is updated
720697 */
721 - //Looks like two places: Either right before a paypal redirect (if that's still a thing) or
722 - //just prior to curling something up to some server somewhere.
723 - //I took care of the one just prior to curling.
724698 public function updateContributionTracking( $force = false ) {
725699 // ony update contrib tracking if we're coming from a single-step landing page
726700 // which we know with cc# in utm_source or if force=true or if contribution_tracking_id is not set
@@ -735,12 +709,12 @@
736710 return true;
737711 } ///wait, what? TODO: This line was straight copied from the _gateway.body. Find out if there's a good reason we're not returning false here.
738712
739 - $tracked_contribution = $this->getCleanTrackingData();
740 -
741713 // if contrib tracking id is not already set, we need to insert the data, otherwise update
742714 if ( !$this->getVal( 'contribution_tracking_id' ) ) {
 715+ $tracked_contribution = $this->getCleanTrackingData();
743716 $this->setVal( 'contribution_tracking_id', $this->insertContributionTracking( $tracked_contribution ) );
744717 } else {
 718+ $tracked_contribution = $this->getCleanTrackingData( true );
745719 $db->update( 'contribution_tracking', $tracked_contribution, array( 'id' => $this->getVal( 'contribution_tracking_id' ) ) );
746720 }
747721 }
@@ -748,7 +722,7 @@
749723 public function addDonorDataToSession() {
750724 self::ensureSession();
751725 $donordata = $this->getStompMessageFields();
752 -
 726+
753727 foreach ( $donordata as $item ) {
754728 if ( $this->isSomething( $item ) ) {
755729 $_SESSION['Donor'][$item] = $this->getVal( $item );
@@ -855,7 +829,6 @@
856830 );
857831 return $stomp_fields;
858832 }
859 -
860833 }
861834
862835 ?>

Follow-up revisions

RevisionCommit summaryAuthorDate
r101502Actually fixes the api calls that handle gateway forms with _cache_ set to tr...khorn17:14, 1 November 2011
r101648MFT r101441, r101502, r101631awjrichards18:17, 2 November 2011
r101669The data used for a paypal redirect needs to be our raw, unstaged data: Not t...khorn20:10, 2 November 2011
r101752MFT r101441, r101502awjrichards23:53, 2 November 2011

Status & tagging log