Index: trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php |
— | — | @@ -159,19 +159,16 @@ |
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
163 | | - * Build the submission form sans submit button |
| 163 | + * Build and displays form to user |
164 | 164 | * |
165 | | - * This allows for additional form elements/processing to be handled |
166 | | - * by extra modules (eg during 'challenge' action) |
167 | | - * |
168 | | - * See $this->fnPayflowDisplayForm |
| 165 | + * @param $data Array: array of posted user input |
| 166 | + * @param $error Array: array of error messages returned by validate_form function |
| 167 | + * |
| 168 | + * The message at the top of the form can be edited in the payflow_gateway.i18.php file |
169 | 169 | */ |
170 | | - public function fnPayflowGenerateFormBody( &$data, &$error ) { |
171 | | - require_once( 'includes/stateAbbreviations.inc' ); |
172 | | - require_once( 'includes/countryCodes.inc' ); |
173 | | - |
174 | | - global $wgOut, $wgLang, $wgPayflowGatewayHeader, $wgPayflowGatewayTest; |
175 | | - |
| 170 | + public function fnPayflowDisplayForm( $data, &$error ) { |
| 171 | + global $wgOut, $wgRequest, $wgPayflowGatewayDefaultForm; |
| 172 | + |
176 | 173 | // save contrib tracking id early to track abondonment |
177 | 174 | if ( $data[ 'numAttempt' ] == '0' ) { |
178 | 175 | if ( !$tracked = $this->fnPayflowSaveContributionTracking( $data ) ) { |
— | — | @@ -179,297 +176,22 @@ |
180 | 177 | wfDebugLog( 'payflowpro_gateway', 'Unable to save data to the contribution_tracking table ' . $when ); |
181 | 178 | } |
182 | 179 | } |
183 | | - |
184 | | - // create drop down of countries |
185 | | - $countries = countryCodes(); |
186 | | - |
187 | | - foreach( $countries as $value => $fullName ) { |
188 | | - if ( $value == $data['country'] ) { |
189 | | - $countryMenu .= Xml::option( $fullName, $value, true ); |
190 | | - } else { |
191 | | - $countryMenu .= Xml::option( $fullName, $value, false ); } |
192 | | - } |
193 | | - |
194 | | - //common HTML tags for table |
195 | | - $endCell = '</td><td>'; |
196 | | - $endRow = '</td></tr> <tr><td>'; |
197 | | - |
198 | | - //create drop down of credit card types |
199 | | - $cardOptions = array( |
200 | | - 'visa' => wfMsg( 'payflow_gateway-card-name-visa' ), |
201 | | - 'mastercard' => wfMsg( 'payflow_gateway-card-name-mc' ), |
202 | | - 'american' => wfMsg( 'payflow_gateway-card-name-amex' ), |
203 | | - 'discover' => wfMsg( 'payflow_gateway-card-name-discover' ), |
204 | | - ); |
205 | | - |
206 | | - foreach( $cardOptions as $value => $fullName ) { |
207 | | - if ( $value == $data[ 'card' ] && $wgPayflowGatewayTest ) { |
208 | | - $cardOptionsMenu .= Xml::option( $fullName, $value, true ); |
209 | | - } else { |
210 | | - $cardOptionsMenu .= Xml::option( $fullName, $value, false ); |
211 | | - } |
212 | | - } |
213 | 180 | |
214 | | - if ( $data['expiration'] ) { |
215 | | - $mo = substr( $data['expiration'], 0, 2); |
216 | | - $yr = substr( $data['expiration'], 2, 2); |
217 | | - } |
| 181 | + $form_class = ( strlen( $wgRequest->getText( 'form_name' ))) ? $wgRequest->getText( 'form_name' ) : $wgPayflowGatewayDefaultForm; |
218 | 182 | |
219 | | - //create expiration month menu |
220 | | - $expMos = ''; |
221 | | - |
222 | | - for( $i = 1; $i < 13; $i++ ) { |
223 | | - if ( $i == $mo && $wgPayflowGatewayTest ) { |
224 | | - $expMos .= Xml::option( $wgLang->getMonthName( $i ), str_pad( $i, 2, '0', STR_PAD_LEFT ), true ); |
225 | | - } else { |
226 | | - $expMos .= Xml::option( $wgLang->getMonthName( $i ), str_pad( $i, 2, '0', STR_PAD_LEFT ), false ); |
| 183 | + // make sure our form class exists before going on, if not try loading default form class |
| 184 | + $class_name = "PayflowProGateway_Form_" . $form_class; |
| 185 | + if ( !class_exists( $class_name )) { |
| 186 | + $class_name_orig = $class_name; |
| 187 | + $class_name = "PayflowProGateway_Form_" . $wgPayflowGatewayDefaultForm; |
| 188 | + if ( !class_exists( $class_name )) { |
| 189 | + throw new MWException( 'Could not load form ' . $class_name_orig . ' nor default form ' . $class_name ); |
227 | 190 | } |
228 | 191 | } |
229 | | - |
230 | | - //create expiration year menu |
231 | | - $expYr = ''; |
232 | | - |
233 | | - for( $i = 0; $i < 11; $i++ ) { |
234 | | - if ( date( 'Y' ) + $i == substr(date('Y'), 0, 2) . $yr && $wgPayflowGatewayTest ) { |
235 | | - $expYr .= Xml::option( date( 'Y' ) + $i, date( 'Y' ) + $i, true ); |
236 | | - } else { |
237 | | - $expYr .= Xml::option( date( 'Y' ) + $i, date( 'Y' ) + $i, false ); |
238 | | - } |
239 | | - } |
240 | | - |
241 | | - $states = statesMenuXML(); |
242 | | - |
243 | | - $stateMenu = ''; |
244 | 192 | |
245 | | - foreach( $states as $value => $fullName ) { |
246 | | - if ( $value == $data['state'] ) { |
247 | | - $stateMenu .= Xml::option( $fullName, $value, true ); |
248 | | - } else $stateMenu .= Xml::option( $fullName, $value, false ); |
249 | | - } |
250 | | - |
251 | | - //currencies |
252 | | - //get available currencies |
253 | | - $currencies = $this->fnPayflowReturnCurrencies(); |
254 | | - |
255 | | - $currencyMenu = ''; |
256 | | - |
257 | | - foreach( $currencies as $value => $fullName ) { |
258 | | - $currencyMenu .= Xml::option( $fullName, $value ); |
259 | | - } |
260 | | - |
261 | | - // Build currency options |
262 | | - $default_currency = $data['currency']; |
263 | | - |
264 | | - $currency_options = ''; |
265 | | - |
266 | | - foreach ( $currencies as $code => $name ) { |
267 | | - $selected = ''; |
268 | | - if ( $code == $default_currency ) { |
269 | | - $selected = ' selected="selected"'; |
270 | | - } |
271 | | - $currency_options .= '<option value="' . $code . '"' . $selected . '>' . wfMsg( 'donate_interface-' . $code ) . '</option>'; |
272 | | - } |
273 | | - |
274 | | - // intro text |
275 | | - if ( $wgPayflowGatewayHeader ) { |
276 | | - $header = str_replace( '@language', $data['language'], $wgPayflowGatewayHeader ); |
277 | | - $wgOut->addHtml( $wgOut->parse( $header )); |
278 | | - } |
279 | | - |
280 | | - $form = Xml::openElement( 'div', array( 'id' => 'mw-creditcard' ) ); |
281 | | - /*Xml::openElement( 'div', array( 'id' => 'mw-creditcard-intro' ) ) . |
282 | | - Xml::tags( 'p', array( 'class' => 'mw-creditcard-intro-msg' ), wfMsg( 'payflowpro_gateway-form-message' ) ) . |
283 | | - Xml::closeElement( 'div' );*/ |
284 | | - |
285 | | - // provide a place at the top of the form for displaying general messages |
286 | | - if ( $error['general'] ) { |
287 | | - $form .= Xml::openElement( 'div', array( 'id' => 'mw-payflow-general-error' )); |
288 | | - if ( is_array( $error['general'] )) { |
289 | | - foreach ( $error['general'] as $error_msg ) { |
290 | | - $form .= Xml::tags( 'p', array( 'class' => 'creditcard-error-msg' ), $error_msg ); |
291 | | - } |
292 | | - } else { |
293 | | - $form .= Xml::tags( 'p', array( 'class' => 'creditcard-error-msg' ), $error_msg ); |
294 | | - } |
295 | | - $form .= Xml::closeElement( 'div' ); |
296 | | - } |
297 | | - |
298 | | - // open form |
299 | | - $form .= Xml::openElement( 'div', array( 'id' => 'mw-creditcard-form' ) ) . |
300 | | - Xml::element( 'p', array( 'class' => 'creditcard-error-msg' ), $error['retryMsg'] ); |
301 | | - $form .= Xml::openElement( 'form', array( 'name' => 'payment', 'method' => 'post', 'action' => '', 'onsubmit' => 'return validate_form(this)', 'autocomplete' => 'off' ) ); |
302 | | - $form .= Xml::openElement( 'div', array( 'class' => 'payflow-cc-form-section', 'id' => 'payflowpro_gateway-personal-info' )); ; |
303 | | - $form .= Xml::tags( 'h3', array( 'class' => 'payflow-cc-form-header','id' => 'payflow-cc-form-header-personal' ), wfMsg( 'payflowpro_gateway-cc-form-header-personal' )); |
304 | | - // donor amount and name |
305 | | - $form .= Xml::openElement( 'table', array( 'id' => 'payflow-table-donor' ) ); |
306 | | - $form .= '<tr><td>'; |
307 | | - $form .= Xml::label( wfMsg( 'payflowpro_gateway-donor-fname' ), 'fname' ) . |
308 | | - $endCell . |
309 | | - Xml::input( 'fname', '30', $data['fname'], array( 'maxlength' => '15', 'class' => 'required', 'id' => 'fname' ) ) . |
310 | | - '<span class="creditcard-error-msg">' . ' ' . $error['fname'] . '</span>' . |
311 | | - $endRow . |
312 | | - Xml::label( wfMsg( 'payflowpro_gateway-donor-mname' ), 'mname' ) . |
313 | | - $endCell . |
314 | | - Xml::input( 'mname', '30', $data['mname'], array( 'maxlength' => '15', 'id' => 'mname' ) ) . |
315 | | - $endRow . |
316 | | - Xml::label( wfMsg( 'payflowpro_gateway-donor-lname' ), 'lname' ) . |
317 | | - $endCell . |
318 | | - Xml::input( 'lname', '30', $data['lname'], array( 'maxlength' => '15', 'id' => 'lname' ) ) . |
319 | | - '<span class="creditcard-error-msg">' . ' ' . $error['lname'] . '</span>' . |
320 | | - $endRow; |
321 | | - |
322 | | - //donor address |
323 | | - $form .= Xml::label( wfMsg( 'payflowpro_gateway-donor-country' ), 'country' ) . |
324 | | - $endCell . |
325 | | - Xml::openElement( 'select', array( 'name' => 'country', 'id' => 'country', 'onchange' => 'return disableStates( this )' ) ) . |
326 | | - $countryMenu . |
327 | | - Xml::closeElement( 'select' ) . |
328 | | - '<span class="creditcard-error-msg">' . ' ' . $error['country'] . '</span>' . |
329 | | - $endRow . |
330 | | - Xml::label( wfMsg( 'payflowpro_gateway-donor-street' ), 'street' ) . |
331 | | - $endCell . |
332 | | - Xml::input( 'street', '30', $data['street'], array( 'maxlength' => '30', 'id' => 'street' ) ) . |
333 | | - '<span class="creditcard-error-msg">' . ' ' . $error['street'] . '</span>' . |
334 | | - $endRow . |
335 | | - Xml::label( wfMsg( 'payflowpro_gateway-donor-city' ), 'city' ) . |
336 | | - $endCell . |
337 | | - Xml::input( 'city', '30', $data['city'], array( 'maxlength' => '20', 'id' => 'city' ) ) . |
338 | | - '<span class="creditcard-error-msg">' . ' ' . $error['city'] . '</span>' . |
339 | | - $endRow . |
340 | | - Xml::label( wfMsg( 'payflowpro_gateway-donor-state' ), 'state' ) . |
341 | | - $endCell . |
342 | | - Xml::openElement( 'select', array( 'name' => 'state', 'id' => 'state' ) ) . |
343 | | - $stateMenu . |
344 | | - Xml::closeElement( 'select' ) . |
345 | | - '<span class="creditcard-error-msg">' . ' ' . $error['state'] . '</span>' . |
346 | | - $endRow . |
347 | | - Xml::label( wfMsg( 'payflowpro_gateway-donor-postal' ), 'zip' ) . |
348 | | - $endCell . |
349 | | - Xml::input( 'zip', '30', $data['zip'], array( 'maxlength' => '9', 'id' => 'zip' ) ) . |
350 | | - '<span class="creditcard-error-msg">' . ' ' . $error['zip'] . '</span>' . |
351 | | - $endRow . |
352 | | - Xml::label( wfMsg( 'payflowpro_gateway-donor-email' ), 'emailAdd' ) . |
353 | | - $endCell . |
354 | | - Xml::input( 'emailAdd', '30', $data['email'], array( 'maxlength' => '64', 'id' => 'emailAdd' ) ) . |
355 | | - '<span class="creditcard-error-msg">' . ' ' . $error['emailAdd'] . '</span>' . |
356 | | - '</td></tr>' . |
357 | | - Xml::closeElement( 'table' ); |
358 | | - $form .= Xml::closeElement( 'div' ); |
359 | | - |
360 | | - // credit card info |
361 | | - global $wgScriptPath; |
362 | | - $card_num = ( $wgPayflowGatewayTest ) ? $data[ 'card_num' ] : ''; |
363 | | - $cvv = ( $wgPayflowGatewayTest ) ? $data[ 'cvv' ] : ''; |
364 | | - $form .= Xml::openElement( 'div', array( 'class' => 'payflow-cc-form-section', 'id' => 'payflowpro_gateway-payment-info' )); |
365 | | - $form .= Xml::tags( 'h3', array( 'class' => 'payflow-cc-form-header', 'id' => 'payflow-cc-form-header-payment' ), wfMsg( 'payflowpro_gateway-cc-form-header-payment' )); |
366 | | - $form .= Xml::openElement( 'table', array( 'id' => 'payflow-table-cc' ) ); |
367 | | - $form .= '<tr><td>'; |
368 | | - $form .= Xml::label(wfMsg( 'payflowpro_gateway-amount-legend' ), 'amount', array( 'maxlength' => '10' ) ) . |
369 | | - $endCell . |
370 | | - Xml::input( 'amount', '7', $data['amount'], array( 'id' => 'amount' ) ) . |
371 | | - '<span class="creditcard-error-msg">' . ' ' . $error['invalidamount'] . '</span>' . |
372 | | - Xml::openElement( 'select', array( 'name' => 'currency_code', 'id' => "input_currency_code" )) . |
373 | | - $currency_options . |
374 | | - Xml::closeElement( 'select' ) . |
375 | | - $endRow . |
376 | | - '</td><td>' .Xml::openElement( 'img', array( 'src' => $wgScriptPath . "/extensions/DonationInterface/payflowpro_gateway/includes/credit_card_logos.gif" )) . |
377 | | - $endRow . |
378 | | - Xml::label( wfMsg( 'payflowpro_gateway-donor-card' ), 'card' ) . |
379 | | - $endCell . |
380 | | - Xml::openElement( 'select', array( 'name' => 'card', 'id' => 'card' ) ) . |
381 | | - $cardOptionsMenu . |
382 | | - Xml::closeElement( 'select') . |
383 | | - $endRow . |
384 | | - Xml::label( wfMsg( 'payflowpro_gateway-donor-card-num' ), 'card_num' ) . |
385 | | - $endCell . |
386 | | - Xml::input( 'card_num', '30', $card_num, array( 'maxlength' => '100', 'id' => 'card_num', 'autocomplete' => 'off' ) ) . |
387 | | - '<span class="creditcard-error-msg">' . ' ' . $error['card_num'] . '</span>' . |
388 | | - '</tr><tr><td></td><td>' . |
389 | | - '<span class="creditcard-error-msg">' . ' ' . $error['card'] . '</span>' . |
390 | | - $endRow . |
391 | | - Xml::label( wfMsg( 'payflowpro_gateway-donor-expiration' ), 'expiration' ) . |
392 | | - $endCell . |
393 | | - Xml::openElement( 'select', array( 'name' => 'mos', 'id' => 'expiration' ) ) . |
394 | | - $expMos . |
395 | | - Xml::closeElement( 'select' ) . |
396 | | - Xml::openElement( 'select', array( 'name' => 'year', 'id' => 'year' ) ) . |
397 | | - $expYr . |
398 | | - Xml::closeElement( 'select' ) . |
399 | | - $endRow . |
400 | | - Xml::label( wfMsg( 'payflowpro_gateway-donor-security' ), 'cvv' ) . |
401 | | - $endCell . |
402 | | - Xml::input( 'cvv', '5', $cvv, array( 'maxlength' => '10', 'id' => 'cvv', 'autocomplete' => 'off') ) . |
403 | | - '<a href="javascript:PopupCVV();">' . wfMsg( 'word-separator' ) . wfMsg( 'payflowpro_gateway-cvv-link' ) . '</a>' . |
404 | | - '<span class="creditcard-error-msg">' . ' ' . $error['cvv'] . '</span>' . |
405 | | - '</td></tr>' . |
406 | | - Xml::closeElement( 'table' ); |
407 | | - |
408 | | - return $form; |
409 | | - } |
410 | | - |
411 | | - /** |
412 | | - * Build the submit portion of the submission form |
413 | | - * |
414 | | - * @fixme There is an open div from fnPayflowGenerateFormBody that this closes |
415 | | - * at the end of the method. This should probably not be the case, but |
416 | | - * was the only way I could think of gracefully handling this quickly. |
417 | | - * |
418 | | - * See $this->fnPayflowDiplayForm |
419 | | - */ |
420 | | - public function fnPayflowGenerateFormSubmit( &$data, &$error ) { |
421 | | - // submit button and close form |
422 | | - $form .= Xml::openElement( 'div', array( 'id' => 'payflowpro_gateway-form-submit')); |
423 | | - $form .= Xml::openElement( 'div', array( 'id' => 'mw-donate-submit-button' )) . |
424 | | - Xml::submitButton( wfMsg( 'payflowpro_gateway-submit-button' )); |
425 | | - $form .= Xml::closeElement( 'div' ); |
426 | | - $form .= Xml::openElement( 'div', array( 'class' => 'mw-donate-submessage', 'id' => 'payflowpro_gateway-donate-submessage' ) ) . |
427 | | - wfMsg( 'payflowpro_gateway-donate-click' ); |
428 | | - $form .= Xml::closeElement( 'div' ); |
429 | | - $form .= Xml::closeElement( 'div' ); |
430 | | - $form .= Xml::closeElement( 'div' ); |
431 | | - $form .= Xml::openElement( 'div', array( 'class' => 'payflow-cc-form-section', 'id' => 'payflowpro_gateway-donate-addl-info' )); |
432 | | - $form .= Xml::tags( 'p', array( 'class' => '' ), |
433 | | - wfMsg( 'payflowpro_gateway-credit-storage-processing' ) ) . |
434 | | - Xml::tags( 'p', array( 'class' => ''), |
435 | | - wfMsg( 'payflowpro_gateway-question-comment' ) ); |
436 | | - $form .= Xml::closeElement( 'div' ); |
437 | | - |
438 | | - // add hidden fields |
439 | | - $form .= Xml::hidden( 'utm_source', $data['utm_source'] ) . |
440 | | - Xml::hidden( 'utm_medium', $data['utm_medium'] ) . |
441 | | - Xml::hidden( 'utm_campaign', $data['utm_campaign'] ) . |
442 | | - Xml::hidden( 'language', $data['language'] ) . |
443 | | - Xml::hidden( 'referrer', $data['referrer'] ) . |
444 | | - Xml::hidden( 'comment', $data['comment'] ) . |
445 | | - Xml::hidden( 'comment-option', $data['anonymous'] ) . |
446 | | - Xml::hidden( 'email', $data['optout'] ) . |
447 | | - Xml::hidden( 'process', 'CreditCard' ) . |
448 | | - Xml::hidden( 'payment_method', 'processed' ) . |
449 | | - Xml::hidden( 'token', $data['token'] ) . |
450 | | - Xml::hidden( 'orderid', $data['order_id'] ) . |
451 | | - Xml::hidden( 'numAttempt', $data['numAttempt'] ) . |
452 | | - Xml::hidden( 'contribution_tracking_id', $data['contribution_tracking_id'] ) . |
453 | | - Xml::hidden( 'data_hash', $data[ 'data_hash' ] ) . |
454 | | - Xml::hidden( 'action', $data[ 'action' ] ); |
455 | | - |
456 | | - $form .= Xml::closeElement( 'form' ) . |
457 | | - Xml::closeElement( 'div' ) . |
458 | | - Xml::closeElement( 'div' ); |
459 | | - return $form; |
460 | | - } |
461 | | - |
462 | | - /** |
463 | | - * Build and displays form to user |
464 | | - * |
465 | | - * @param $data Array: array of posted user input |
466 | | - * @param $error Array: array of error messages returned by validate_form function |
467 | | - * |
468 | | - * The message at the top of the form can be edited in the payflow_gateway.i18.php file |
469 | | - */ |
470 | | - public function fnPayflowDisplayForm( $data, &$error ) { |
471 | | - global $wgOut; |
472 | | - $form = $this->fnPayflowGenerateFormBody( $data, $error ); |
473 | | - $form .= $this->fnPayflowGenerateFormSubmit( $data, $error ); |
| 193 | + $form_obj = new $class_name( $data, $error ); |
| 194 | + $form = $form_obj->generateFormBody(); |
| 195 | + $form .= $form_obj->generateFormSubmit(); |
474 | 196 | $wgOut->addHTML( $form ); |
475 | 197 | } |
476 | 198 | |
— | — | @@ -1003,7 +725,7 @@ |
1004 | 726 | function fnPayflowMatchEditToken( $val, $salt='' ) { |
1005 | 727 | // fetch a salted version of the session token |
1006 | 728 | $sessionToken = $this->fnPayflowEditToken( $salt ); |
1007 | | - if ( $val != $sessionToken ) { |
| 729 | + if ( $val != $session_token ) { |
1008 | 730 | wfDebug( "PayflowproGateway::fnPayflowMatchEditToken: broken session data\n" ); |
1009 | 731 | } |
1010 | 732 | return $val == $sessionToken; |