Index: trunk/extensions/DonationInterface/tests/DonationDataTestCase.php |
— | — | @@ -317,7 +317,7 @@ |
318 | 318 | public static function ensureSession() { |
319 | 319 | public function checkTokens() { |
320 | 320 | function wasPosted(){ |
321 | | - public static function getUtmSource( $utm_source = null, $utm_source_id = null ) { |
| 321 | + function setUtmSource() { |
322 | 322 | public function getOptOuts() { |
323 | 323 | public function getCleanTrackingData( $clean_optouts = false ) { |
324 | 324 | function saveContributionTracking() { |
Index: trunk/extensions/DonationInterface/payflowpro_gateway/api_payflowpro_gateway.php |
— | — | @@ -2,7 +2,7 @@ |
3 | 3 | /** |
4 | 4 | * PayflowPro Gateway API extension |
5 | 5 | * 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. |
7 | 7 | */ |
8 | 8 | |
9 | 9 | class ApiPayflowProGateway extends ApiBase { |
— | — | @@ -11,7 +11,7 @@ |
12 | 12 | * An array of valid dispatch methods |
13 | 13 | */ |
14 | 14 | public $validDispatchMethods = array( 'dispatch_get_required_dynamic_form_elements' ); |
15 | | - |
| 15 | + |
16 | 16 | /** |
17 | 17 | * API for PayflowProGateway extension |
18 | 18 | * |
— | — | @@ -26,7 +26,7 @@ |
27 | 27 | // extract and validate the parameters |
28 | 28 | $params = $this->extractRequestParams(); |
29 | 29 | $this->validateParams( $params ); |
30 | | - |
| 30 | + |
31 | 31 | // route 'dispatch' requests to the appropriate method |
32 | 32 | if ( strlen( $params[ 'dispatch' ] ) ) { |
33 | 33 | $method = $this->getDispatchMethod( $params[ 'dispatch' ] ); |
— | — | @@ -48,6 +48,9 @@ |
49 | 49 | 'tracking_data' => array( |
50 | 50 | ApiBase::PARAM_TYPE => 'string', |
51 | 51 | ), |
| 52 | + 'gateway' => array( |
| 53 | + ApiBase::PARAM_TYPE => 'string', |
| 54 | + ), |
52 | 55 | ); |
53 | 56 | } |
54 | 57 | |
— | — | @@ -73,7 +76,7 @@ |
74 | 77 | if ( isset( $params[ 'dispatch' ] ) && strlen( $params[ 'dispatch' ] ) ) { |
75 | 78 | $method = $this->getDispatchMethod( $params[ 'dispatch' ] ); |
76 | 79 | 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' ); |
78 | 81 | } |
79 | 82 | |
80 | 83 | // make sure we have tracking data for get_required_dynamic_form_elements |
— | — | @@ -122,18 +125,21 @@ |
123 | 126 | * elements. |
124 | 127 | */ |
125 | 128 | protected function dispatch_get_required_dynamic_form_elements( $params ) { |
126 | | - global $wgPayflowProGatewaySalt; |
127 | 129 | |
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 | + |
138 | 144 | /** |
139 | 145 | * retrieve and unpack the json encoded string of tracking data |
140 | 146 | * |
— | — | @@ -142,12 +148,19 @@ |
143 | 149 | * pageref => the url-encoded referrer to the full user-requested URL |
144 | 150 | */ |
145 | 151 | $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' ); |
146 | 158 | |
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(); |
149 | 161 | |
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 ); |
152 | 165 | |
153 | 166 | // this try/catch design pattern stolen from ClickTracking/ApiSpecialClickTracking.php |
154 | 167 | try { |
— | — | @@ -175,11 +188,7 @@ |
176 | 189 | // add the referrer to the tracked_data array |
177 | 190 | $tracking_data[ 'referrer' ] = urldecode( $unparsed_tracking_data[ 'pageref' ] ); |
178 | 191 | |
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. |
184 | 193 | return $tracking_data; |
185 | 194 | } |
186 | 195 | |
Index: trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php |
— | — | @@ -40,7 +40,7 @@ |
41 | 41 | |
42 | 42 | // dispatch forms/handling |
43 | 43 | if ( $this->adapter->checkTokens() ) { |
44 | | - if ( $this->adapter->posted) { |
| 44 | + if ( $this->adapter->posted ) { |
45 | 45 | // The form was submitted and the payment method has been set |
46 | 46 | // Check form for errors |
47 | 47 | $form_errors = $this->validateForm( $this->errors ); |
Index: trunk/extensions/DonationInterface/payflowpro_gateway/forms/js/lightbox1.js |
— | — | @@ -147,7 +147,7 @@ |
148 | 148 | 'zip': $( "input[name='zip']" ).val(), |
149 | 149 | 'emailAdd': $( "input[name='emailAdd']" ).val(), |
150 | 150 | 'country': $( "input[name='country']" ).val(), |
151 | | - 'payment_method': 'card', |
| 151 | + 'payment_method': 'cc', |
152 | 152 | 'language': 'en', |
153 | 153 | |
154 | 154 | '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 @@ |
157 | 157 | 'zip': $( "input[name='zip']" ).val(), |
158 | 158 | 'emailAdd': $( "input[name='emailAdd']" ).val(), |
159 | 159 | 'country': $( "input[name='country']" ).val(), |
160 | | - 'payment_method': 'card', |
| 160 | + 'payment_method': 'cc', |
161 | 161 | 'language': language, |
162 | 162 | 'card_type': $( "input[name='cardtype']:checked" ).val().toLowerCase(), |
163 | 163 | 'contribution_tracking_id': $( "input[name='contribution_tracking_id']" ).val(), |
Index: trunk/extensions/DonationInterface/globalcollect_gateway/forms/js/lightbox1.js |
— | — | @@ -138,7 +138,7 @@ |
139 | 139 | 'zip': $( "input[name='zip']" ).val(), |
140 | 140 | 'emailAdd': $( "input[name='emailAdd']" ).val(), |
141 | 141 | 'country': $( "input[name='country']" ).val(), |
142 | | - 'payment_method': 'card', |
| 142 | + 'payment_method': 'cc', |
143 | 143 | 'language': 'en', |
144 | 144 | 'card_type': 'visa', |
145 | 145 | |
Index: trunk/extensions/DonationInterface/gateway_common/donation.api.php |
— | — | @@ -34,7 +34,7 @@ |
35 | 35 | $gatewayObj = new GlobalCollectAdapter(); |
36 | 36 | switch ( $method ) { |
37 | 37 | // TODO: add other payment methods |
38 | | - case 'card': |
| 38 | + case 'cc': |
39 | 39 | $result = $gatewayObj->do_transaction( 'INSERT_ORDERWITHPAYMENT' ); |
40 | 40 | break; |
41 | 41 | default: |
— | — | @@ -138,7 +138,7 @@ |
139 | 139 | 'zip' => '94104', |
140 | 140 | 'emailAdd' => 'test@example.com', |
141 | 141 | 'country' => 'US', |
142 | | - 'payment_method' => 'card', |
| 142 | + 'payment_method' => 'cc', |
143 | 143 | 'language' => 'en', |
144 | 144 | 'card_type' => 'american', |
145 | 145 | ); |
Index: trunk/extensions/DonationInterface/gateway_common/DonationData.php |
— | — | @@ -18,14 +18,15 @@ |
19 | 19 | $this->populateData( $test, $data ); |
20 | 20 | } |
21 | 21 | |
22 | | - function populateData( $test = false, $testdata = false ) { |
| 22 | + function populateData( $test = false, $external_data = false ) { |
23 | 23 | global $wgRequest; |
24 | 24 | $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(); |
27 | 29 | } else { |
28 | 30 | $this->normalized = array( |
29 | | - 'posted' => 'true', //moderately sneaky. |
30 | 31 | 'amount' => $wgRequest->getText( 'amount', null ), |
31 | 32 | 'amountGiven' => $wgRequest->getText( 'amountGiven', null ), |
32 | 33 | 'amountOther' => $wgRequest->getText( 'amountOther', null ), |
— | — | @@ -57,14 +58,15 @@ |
58 | 59 | 'expiration' => $wgRequest->getText( 'mos' ) . substr( $wgRequest->getText( 'year' ), 2, 2 ), |
59 | 60 | 'cvv' => $wgRequest->getText( 'cvv' ), |
60 | 61 | 'currency' => $wgRequest->getText( 'currency_code', 'USD' ), |
61 | | - 'payment_method' => $wgRequest->getText( 'payment_method' ), |
| 62 | + 'payment_method' => $wgRequest->getText( 'payment_method', 'cc' ), |
62 | 63 | 'payment_submethod' => $wgRequest->getText( 'payment_submethod', null ), // Used by GlobalCollect for payment types |
63 | 64 | 'issuer_id' => $wgRequest->getText( 'issuer_id' ), |
64 | 65 | 'order_id' => $wgRequest->getText( 'order_id', null ), //as far as I know, this won't actually ever pull anything back. |
65 | 66 | 'i_order_id' => $wgRequest->getText( 'i_order_id', null ), //internal id for each contribution attempt |
66 | 67 | 'numAttempt' => $wgRequest->getVal( 'numAttempt', '0' ), |
67 | 68 | '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 ), |
69 | 71 | 'utm_medium' => $wgRequest->getText( 'utm_medium' ), |
70 | 72 | 'utm_campaign' => $wgRequest->getText( 'utm_campaign' ), |
71 | 73 | // try to honor the user-set language (uselang), otherwise the language set in the URL (language) |
— | — | @@ -110,10 +112,6 @@ |
111 | 113 | //if it is: assume that the session data was meant to be replaced |
112 | 114 | //with better data. |
113 | 115 | //...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. |
118 | 116 | foreach ( $_SESSION['Donor'] as $key => $val ){ |
119 | 117 | if ( !$this->isSomething( $key ) ){ |
120 | 118 | $this->setVal( $key, $val ); |
— | — | @@ -137,76 +135,72 @@ |
138 | 136 | } |
139 | 137 | |
140 | 138 | 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 | + ); |
151 | 146 | |
152 | | - // randomly select a credit card |
153 | | - $card_index = array_rand( $cards ); |
| 147 | + // randomly select a credit card |
| 148 | + $card_index = array_rand( $cards ); |
154 | 149 | |
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]] ); |
157 | 152 | |
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 | + ); |
211 | 205 | } |
212 | 206 | |
213 | 207 | /** |
— | — | @@ -245,6 +239,7 @@ |
246 | 240 | |
247 | 241 | function normalizeAndSanitize() { |
248 | 242 | if ( !empty( $this->normalized ) ) { |
| 243 | + $this->setUtmSource(); |
249 | 244 | $this->setNormalizedAmount(); |
250 | 245 | $this->setNormalizedOrderIDs(); |
251 | 246 | $this->setGateway(); |
— | — | @@ -324,7 +319,7 @@ |
325 | 320 | /** |
326 | 321 | * Generate an order id exactly once for this go-round. |
327 | 322 | */ |
328 | | - function generateOrderId() { |
| 323 | + static function generateOrderId() { |
329 | 324 | static $order_id = null; |
330 | 325 | if ( $order_id === null ) { |
331 | 326 | $order_id = ( double ) microtime() * 1000000 . mt_rand( 1000, 9999 ); |
— | — | @@ -546,50 +541,27 @@ |
547 | 542 | } |
548 | 543 | |
549 | 544 | /** |
550 | | - * Get the utm_source string |
551 | | - * |
| 545 | + * normalizeAndSanitize helper function. |
| 546 | + * |
552 | 547 | * Checks to see if the utm_source is set properly for the credit card |
553 | 548 | * form including any cc form variants (identified by utm_source_id). If |
554 | 549 | * anything cc form related is out of place for the utm_source, this |
555 | 550 | * will fix it. |
556 | 551 | * |
557 | 552 | * 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 |
564 | 553 | */ |
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; |
567 | 562 | |
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 | | - |
591 | 563 | // 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. |
594 | 566 | } |
595 | 567 | |
596 | 568 | // split the utm_source into its parts for easier manipulation |
— | — | @@ -601,13 +573,14 @@ |
602 | 574 | $source_parts[0] = ''; |
603 | 575 | |
604 | 576 | // 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] : '' ); |
606 | 578 | |
607 | 579 | // 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; |
609 | 581 | |
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 ); |
612 | 585 | } |
613 | 586 | |
614 | 587 | /** |
— | — | @@ -637,9 +610,11 @@ |
638 | 611 | * Compares tracking data array to list of valid tracking fields and |
639 | 612 | * removes any extra tracking fields/data. Also sets empty values to |
640 | 613 | * '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 |
642 | 617 | */ |
643 | | - public function getCleanTrackingData() { |
| 618 | + public function getCleanTrackingData( $unset = false ) { |
644 | 619 | |
645 | 620 | // define valid tracking fields |
646 | 621 | $tracking_fields = array( |
— | — | @@ -658,7 +633,9 @@ |
659 | 634 | if ( $this->isSomething( $value ) ) { |
660 | 635 | $tracking_data[$value] = $this->getVal( $value ); |
661 | 636 | } else { |
662 | | - $tracking_data[$value] = null; |
| 637 | + if ( !$unset ){ |
| 638 | + $tracking_data[$value] = null; |
| 639 | + } |
663 | 640 | } |
664 | 641 | } |
665 | 642 | |
— | — | @@ -670,7 +647,7 @@ |
671 | 648 | * @return boolean true if we got a contribution tracking # back, false if |
672 | 649 | * something went wrong. |
673 | 650 | */ |
674 | | - function saveContributionTracking() { |
| 651 | + public function saveContributionTracking() { |
675 | 652 | |
676 | 653 | $tracked_contribution = $this->getCleanTrackingData(); |
677 | 654 | |
— | — | @@ -717,9 +694,6 @@ |
718 | 695 | * @param array $data Form data |
719 | 696 | * @param bool $force If set to true, will ensure that contribution tracking is updated |
720 | 697 | */ |
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. |
724 | 698 | public function updateContributionTracking( $force = false ) { |
725 | 699 | // ony update contrib tracking if we're coming from a single-step landing page |
726 | 700 | // which we know with cc# in utm_source or if force=true or if contribution_tracking_id is not set |
— | — | @@ -735,12 +709,12 @@ |
736 | 710 | return true; |
737 | 711 | } ///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. |
738 | 712 | |
739 | | - $tracked_contribution = $this->getCleanTrackingData(); |
740 | | - |
741 | 713 | // if contrib tracking id is not already set, we need to insert the data, otherwise update |
742 | 714 | if ( !$this->getVal( 'contribution_tracking_id' ) ) { |
| 715 | + $tracked_contribution = $this->getCleanTrackingData(); |
743 | 716 | $this->setVal( 'contribution_tracking_id', $this->insertContributionTracking( $tracked_contribution ) ); |
744 | 717 | } else { |
| 718 | + $tracked_contribution = $this->getCleanTrackingData( true ); |
745 | 719 | $db->update( 'contribution_tracking', $tracked_contribution, array( 'id' => $this->getVal( 'contribution_tracking_id' ) ) ); |
746 | 720 | } |
747 | 721 | } |
— | — | @@ -748,7 +722,7 @@ |
749 | 723 | public function addDonorDataToSession() { |
750 | 724 | self::ensureSession(); |
751 | 725 | $donordata = $this->getStompMessageFields(); |
752 | | - |
| 726 | + |
753 | 727 | foreach ( $donordata as $item ) { |
754 | 728 | if ( $this->isSomething( $item ) ) { |
755 | 729 | $_SESSION['Donor'][$item] = $this->getVal( $item ); |
— | — | @@ -855,7 +829,6 @@ |
856 | 830 | ); |
857 | 831 | return $stomp_fields; |
858 | 832 | } |
859 | | - |
860 | 833 | } |
861 | 834 | |
862 | 835 | ?> |