Index: trunk/extensions/DonationInterface/payflowpro_gateway/api_payflowpro_gateway.php |
— | — | @@ -120,8 +120,39 @@ |
121 | 121 | * elements. |
122 | 122 | */ |
123 | 123 | protected function dispatch_get_required_dynamic_form_elements( $params ) { |
124 | | - global $wgPayflowGatewaySalt; |
| 124 | + global $wgPayflowGatewaySalt, $wgUseSquid; |
125 | 125 | |
| 126 | + /** |
| 127 | + * if we are not Squid-caching, we do not want to generate the dynamic data via the API |
| 128 | + * |
| 129 | + * when non-squid caching, the data should be generated in payflowpro_gateway.body.php, so |
| 130 | + * if we were to do it here as well, tracking information could be skewed. |
| 131 | + * |
| 132 | + * ths js to hit the api shouldn't even get loaded if squid is not enabled, but |
| 133 | + * we do this just in case. |
| 134 | + */ |
| 135 | + if ( !$wgUseSquid ) { |
| 136 | + return; |
| 137 | + } |
| 138 | + |
| 139 | + // increse numattempt |
| 140 | + $numAttempt = $params[ 'numAttempt' ] + 1; |
| 141 | + |
| 142 | + try { |
| 143 | + $this->getResult()->addValue( array( 'dynamic_form_elements' ), 'numAttempt', $numAttempt ); |
| 144 | + $this->getResult()->addValue( array( 'dynamic_form_elements' ), 'token', $token ); |
| 145 | + } catch ( Exception $e ) {} |
| 146 | + |
| 147 | + |
| 148 | + /** |
| 149 | + * If this is not the first numAttempt AND we have a valid session, |
| 150 | + * we do not need to load the dynamic values |
| 151 | + */ |
| 152 | + $token_match = PayflowProGateway::fnPayflowMatchEditToken( $params[ 'token' ], $wgpayflowGatewaySalt ); |
| 153 | + if ( $numAttempt > 1 && $token_match ) { |
| 154 | + return; |
| 155 | + } |
| 156 | + |
126 | 157 | // fetch the order_id |
127 | 158 | require_once( 'includes/payflowUser.inc' ); |
128 | 159 | $payflow_data = payflowUser(); |
— | — | @@ -149,7 +180,6 @@ |
150 | 181 | try { |
151 | 182 | // add dynamic elements to result object |
152 | 183 | $this->getResult()->addValue( array( 'dynamic_form_elements' ), 'orderid', $order_id ); |
153 | | - $this->getResult()->addValue( array( 'dynamic_form_elements' ), 'token', $token ); |
154 | 184 | $this->getResult()->addValue( array( 'dynamic_form_elements' ), 'contribution_tracking_id', $contribution_tracking_id ); |
155 | 185 | $this->getResult()->addValue( array( 'dynamic_form_elements' ), 'tracking_data', $tracking_data ); |
156 | 186 | } catch ( Exception $e ) { |
Index: trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php |
— | — | @@ -108,26 +108,19 @@ |
109 | 109 | |
110 | 110 | $payflow_data = payflowUser(); |
111 | 111 | |
112 | | - // if _cache_ is requested by the user, do not set a session/token; dynamic data will be loaded via ajax |
113 | | - if ( $wgRequest->getText( '_cache_', false ) ) { |
114 | | - $cache = true; |
115 | | - $token = ''; |
116 | | - $token_match = false; |
| 112 | + // if we have squid caching enabled, set the maxage |
| 113 | + global $wgUseSquid, $wgPayflowSMaxAge; |
| 114 | + if ( $wgUseSquid ) { |
| 115 | + $wgOut->setSquidMaxage( $wgPayflowSMaxAge ); |
| 116 | + } |
| 117 | + |
| 118 | + // establish the edit token to prevent csrf |
| 119 | + $token = self::fnPayflowEditToken( $wgPayflowGatewaySalt ); |
117 | 120 | |
118 | | - // if we have squid caching enabled, set the maxage |
119 | | - global $wgUseSquid, $wgPayflowSMaxAge; |
120 | | - if ( $wgUseSquid ) $wgOut->setSquidMaxage( $wgPayflowSMaxAge ); |
121 | | - } else { |
122 | | - $cache = false; |
123 | | - |
124 | | - // establish the edit token to prevent csrf |
125 | | - $token = self::fnPayflowEditToken( $wgPayflowGatewaySalt ); |
126 | | - |
127 | | - // match token |
128 | | - $token_check = ( $wgRequest->getText( 'token' ) ) ? $wgRequest->getText( 'token' ) : $token; |
129 | | - $token_match = $this->fnPayflowMatchEditToken( $token_check, $wgPayflowGatewaySalt ); |
130 | | - } |
131 | | - |
| 121 | + // match token |
| 122 | + $token_check = ( $wgRequest->getText( 'token' ) ) ? $wgRequest->getText( 'token' ) : $token; |
| 123 | + $token_match = self::fnPayflowMatchEditToken( $token_check, $wgPayflowGatewaySalt ); |
| 124 | + |
132 | 125 | $this->setHeaders(); |
133 | 126 | |
134 | 127 | // Populate form data |
— | — | @@ -148,8 +141,9 @@ |
149 | 142 | if ( $token_match ) { |
150 | 143 | |
151 | 144 | if ( $data['payment_method'] == 'processed' ) { |
152 | | - // increase the count of attempts |
153 | | - ++$data['numAttempt']; |
| 145 | + // increase the count of attempts (if we're not using Squid [which means we're using the API to control numAttempt] |
| 146 | + global $wgUseSquid; |
| 147 | + if ( !$wgUseSquid ) ++$data['numAttempt']; |
154 | 148 | |
155 | 149 | // Check form for errors and redisplay with messages |
156 | 150 | $form_errors = $this->fnPayflowValidateForm( $data, $this->errors ); |
— | — | @@ -195,10 +189,7 @@ |
196 | 190 | $this->fnPayflowDisplayForm( $data, $this->errors ); |
197 | 191 | } |
198 | 192 | } else { |
199 | | - if ( !$cache ) { |
200 | | - // if we're not caching, there's a token mismatch |
201 | | - $this->errors['general']['token-mismatch'] = wfMsg( 'payflowpro_gateway-token-mismatch' ); |
202 | | - } |
| 193 | + $this->errors['general']['token-mismatch'] = wfMsg( 'payflowpro_gateway-token-mismatch' ); |
203 | 194 | $this->fnPayflowDisplayForm( $data, $this->errors ); |
204 | 195 | } |
205 | 196 | } |
— | — | @@ -212,10 +203,10 @@ |
213 | 204 | * The message at the top of the form can be edited in the payflow_gateway.i18n.php file |
214 | 205 | */ |
215 | 206 | public function fnPayflowDisplayForm( &$data, &$error ) { |
216 | | - global $wgOut, $wgRequest; |
| 207 | + global $wgOut, $wgRequest, $wgUseSquid; |
217 | 208 | |
218 | 209 | // save contrib tracking id early to track abondonment |
219 | | - if ( $data[ 'numAttempt' ] == '0' && ( !$wgRequest->getText( 'utm_source_id', false ) || $wgRequest->getText( '_nocache_' ) == 'true' ) ) { |
| 210 | + if ( !$wgUseSquid && !is_null( $data[ 'contribution_tracking_id' ] )) { |
220 | 211 | $tracked = $this->fnPayflowSaveContributionTracking( $data ); |
221 | 212 | if ( !$tracked ) { |
222 | 213 | $when = time(); |
— | — | @@ -889,7 +880,7 @@ |
890 | 881 | * @var mixed $salt |
891 | 882 | * @return bool |
892 | 883 | */ |
893 | | - function fnPayflowMatchEditToken( $val, $salt = '' ) { |
| 884 | + public static function fnPayflowMatchEditToken( $val, $salt = '' ) { |
894 | 885 | // fetch a salted version of the session token |
895 | 886 | $sessionToken = self::fnPayflowEditToken( $salt ); |
896 | 887 | if ( $val != $sessionToken ) { |
— | — | @@ -974,7 +965,7 @@ |
975 | 966 | 'email-opt' => $wgRequest->getText( 'email-opt' ), |
976 | 967 | 'test_string' => $wgRequest->getText( 'process' ), |
977 | 968 | 'token' => $token, |
978 | | - 'contribution_tracking_id' => $wgRequest->getText( 'contribution_tracking_id' ), |
| 969 | + 'contribution_tracking_id' => $wgRequest->getText( 'contribution_tracking_id', null ), |
979 | 970 | 'data_hash' => $wgRequest->getText( 'data_hash' ), |
980 | 971 | 'action' => $wgRequest->getText( 'action' ), |
981 | 972 | 'gateway' => 'payflowpro', |
— | — | @@ -1011,7 +1002,7 @@ |
1012 | 1003 | 'email-opt' => $wgRequest->getText( 'email-opt' ), |
1013 | 1004 | 'test_string' => $wgRequest->getText( 'process' ), // for showing payflow string during testing |
1014 | 1005 | 'token' => $token, |
1015 | | - 'contribution_tracking_id' => $wgRequest->getText( 'contribution_tracking_id' ), |
| 1006 | + 'contribution_tracking_id' => $wgRequest->getText( 'contribution_tracking_id', null ), |
1016 | 1007 | 'data_hash' => $wgRequest->getText( 'data_hash' ), |
1017 | 1008 | 'action' => $wgRequest->getText( 'action' ), |
1018 | 1009 | 'gateway' => 'payflowpro', // this may need to become dynamic in the future |
Index: trunk/extensions/DonationInterface/payflowpro_gateway/forms/TwoStepTwoColumn.php |
— | — | @@ -10,6 +10,8 @@ |
11 | 11 | // we only want to load this JS if the form is being rendered |
12 | 12 | $this->loadValidateJs(); // validation JS |
13 | 13 | |
| 14 | + if ( $WgUseSquid ) $this->loadApiJs(); // API/Ajax JS - only if we're caching |
| 15 | + |
14 | 16 | // form placeholder values |
15 | 17 | $first = wfMsg( 'payflowpro_gateway-first' ); |
16 | 18 | $last = wfMsg( 'payflowpro_gateway-last' ); |
Index: trunk/extensions/DonationInterface/payflowpro_gateway/forms/OneStepTwoColumn.php |
— | — | @@ -4,7 +4,7 @@ |
5 | 5 | public $paypal = false; // true for paypal only version |
6 | 6 | |
7 | 7 | public function __construct( &$form_data, &$form_errors ) { |
8 | | - global $wgOut; |
| 8 | + global $wgOut, $wgUseSquid; |
9 | 9 | |
10 | 10 | parent::__construct( $form_data, $form_errors ); |
11 | 11 | |
— | — | @@ -14,7 +14,7 @@ |
15 | 15 | // we only want to load this JS if the form is being rendered |
16 | 16 | $this->loadValidateJs(); // validation JS |
17 | 17 | |
18 | | - $this->loadApiJs(); // API/Ajax JS |
| 18 | + if ( $WgUseSquid ) $this->loadApiJs(); // API/Ajax JS - only if we're caching |
19 | 19 | |
20 | 20 | // form placeholder values |
21 | 21 | $first = wfMsg( 'payflowpro_gateway-first' ); |
Index: trunk/extensions/DonationInterface/payflowpro_gateway/pfp_api_controller.js |
— | — | @@ -1,23 +1,37 @@ |
2 | 2 | ( function( $ ) { |
3 | 3 | $.getDynamicFormElements = function(){ |
4 | | - var tracking_data = {"url": escape(window.location), "pageref": escape(document.referrer)}; |
| 4 | + var numAttempt = $('input[name=numAttempt]').val(); |
| 5 | + var token = $('input[name=token]').val(); |
| 6 | + |
| 7 | + var tracking_data = '{"url": "' + escape(window.location) + '",' + \ |
| 8 | + '"pageref": "' + escape(document.referrer) + '",' + \ |
| 9 | + '"token": "' + escape( token ) + '",' + \ |
| 10 | + '"numAttempt": "' + escape( numAttempt ) + '"}'; |
5 | 11 | |
6 | 12 | var processFormElements = function (data, status){ |
7 | | - $('input[name=orderid]').val(data['dynamic_form_elements']['orderid']); |
8 | | - $('input[name=token]').val(data['dynamic_form_elements']['token']); |
9 | | - $('input[name=contribution_tracking_id]').val(data['dynamic_form_elements']['contribution_tracking_id']); |
10 | | - $('input[name=utm_source]').val(data['dynamic_form_elements']['tracking_data']['utm_source']); |
11 | | - $('input[name=utm_medium]').val(data['dynamic_form_elements']['tracking_data']['utm_medium']); |
12 | | - $('input[name=utm_campaign]').val(data['dynamic_form_elements']['tracking_data']['utm_campaign']); |
13 | | - $('input[name=referrer]').val(data['dynamic_form_elements']['tracking_data']['referrer']); |
14 | | - $('input[name=language]').val(data['dynamic_form_elements']['tracking_data']['language']); |
| 13 | + // set the numAttempt and the token |
| 14 | + $('input[name=numAttempt]').val(data['dynamic_form_elements']['numAttempt']); |
| 15 | + $('input[name=token]').val(data['dynamic_form_elements']['token']); |
| 16 | + |
| 17 | + // early return if non-required dynamic form elements are set |
| 18 | + if ( typeof data['dynamic_form_elements']['contribution_tracking_id'] == 'undefined' ) { |
| 19 | + return; |
| 20 | + } |
| 21 | + $('input[name=orderid]').val(data['dynamic_form_elements']['orderid']); |
| 22 | + $('input[name=token]').val(data['dynamic_form_elements']['token']); |
| 23 | + $('input[name=contribution_tracking_id]').val(data['dynamic_form_elements']['contribution_tracking_id']); |
| 24 | + $('input[name=utm_source]').val(data['dynamic_form_elements']['tracking_data']['utm_source']); |
| 25 | + $('input[name=utm_medium]').val(data['dynamic_form_elements']['tracking_data']['utm_medium']); |
| 26 | + $('input[name=utm_campaign]').val(data['dynamic_form_elements']['tracking_data']['utm_campaign']); |
| 27 | + $('input[name=referrer]').val(data['dynamic_form_elements']['tracking_data']['referrer']); |
| 28 | + $('input[name=language]').val(data['dynamic_form_elements']['tracking_data']['language']); |
15 | 29 | }; |
16 | 30 | |
17 | 31 | $.post( wgScriptPath + '/api.php?' + Math.random() , { |
18 | 32 | 'action' : 'pfp', |
19 | 33 | 'dispatch' : 'get_required_dynamic_form_elements', |
20 | 34 | 'format' : 'json', |
21 | | - 'tracking_data' : '{"url": "'+escape(window.location)+'", "pageref": "'+escape(document.referrer)+'"}' |
| 35 | + 'tracking_data' : tracking_data |
22 | 36 | }, processFormElements, 'json' ); |
23 | 37 | }; |
24 | 38 | |
— | — | @@ -25,7 +39,4 @@ |
26 | 40 | |
27 | 41 | } )( jQuery ); |
28 | 42 | |
29 | | -// Do not fire the AJAX request if _nocache_ is set or we are not using a single-step form (known by lack of utm_source_id) |
30 | | -if( String(window.location).indexOf( '_cache_' ) != -1 && String(window.location).indexOf( 'utm_source_id' ) != -1){ |
31 | | - jQuery( document ).ready( jQuery.getDynamicFormElements ); |
32 | | -} |
\ No newline at end of file |
| 43 | +jQuery( document ).ready( jQuery.getDynamicFormElements ); |
\ No newline at end of file |