r79439 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79438‎ | r79439 | r79440 >
Date:20:58, 1 January 2011
Author:kaldari
Status:deferred
Tags:
Comment:
adding US specific form for premiums
Modified paths:
  • /trunk/extensions/DonationInterface/payflowpro_gateway/forms/TwoStepTwoColumnPremiumUS.php (added) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/payflowpro_gateway/forms/TwoStepTwoColumnPremiumUS.php
@@ -0,0 +1,322 @@
 2+<?php
 3+
 4+class PayflowProGateway_Form_TwoStepTwoColumnPremiumUS extends PayflowProGateway_Form_TwoStepTwoColumn {
 5+ public function __construct( &$form_data, &$form_errors ) {
 6+ global $wgScriptPath;
 7+
 8+ // set the path to css, before the parent constructor is called, checking to make sure some child class hasn't already set this
 9+ if ( !strlen( $this->getStylePath() ) ) {
 10+ $this->setStylePath( $wgScriptPath . '/extensions/DonationInterface/payflowpro_gateway/forms/css/TwoStepTwoColumnPremium.css' );
 11+ }
 12+
 13+ parent::__construct( $form_data, $form_errors );
 14+ }
 15+
 16+ public function loadPlaceholders() {
 17+ global $wgOut;
 18+ // form placeholder values
 19+ $first = wfMsg( 'payflowpro_gateway-first' );
 20+ $last = wfMsg( 'payflowpro_gateway-last' );
 21+ $street = wfMsg( 'payflowpro_gateway-donor-street' );
 22+ $city = wfMsg( 'payflowpro_gateway-donor-city' );
 23+ $zip = wfMsg( 'payflowpro_gateway-zip-code' );
 24+ $email = wfMsg( 'payflowpro_gateway-donor-email' );
 25+ $js = <<<EOT
 26+<script type="text/javascript">
 27+function loadPlaceholders() {
 28+ var fname = document.getElementById('fname');
 29+ var lname = document.getElementById('lname');
 30+ var street = document.getElementById('street');
 31+ var city = document.getElementById('city');
 32+ var zip = document.getElementById('zip');
 33+ var email = document.getElementById('emailAdd');
 34+ if (fname.value == '') {
 35+ fname.style.color = '#999999';
 36+ fname.value = '$first';
 37+ }
 38+ if (lname.value == '') {
 39+ lname.style.color = '#999999';
 40+ lname.value = '$last';
 41+ }
 42+ if (street.value == '') {
 43+ street.style.color = '#999999';
 44+ street.value = '$street';
 45+ }
 46+ if (city.value == '') {
 47+ city.style.color = '#999999';
 48+ city.value = '$city';
 49+ }
 50+ if (zip.value == '') {
 51+ zip.style.color = '#999999';
 52+ zip.value = '$zip';
 53+ }
 54+ if (email.value == '') {
 55+ email.style.color = '#999999';
 56+ email.value = '$email';
 57+ }
 58+}
 59+addEvent( window, 'load', loadPlaceholders );
 60+
 61+function formCheck( ccform ) {
 62+ var msg = [ 'EmailAdd', 'Fname', 'Lname', 'Street', 'City', 'Zip', 'CardNum', 'Cvv' ];
 63+
 64+ var fields = ["emailAdd","fname","lname","street","city","zip","card_num","cvv" ],
 65+ numFields = fields.length,
 66+ i,
 67+ output = '',
 68+ currField = '';
 69+
 70+ for( i = 0; i < numFields; i++ ) {
 71+ if( document.getElementById( fields[i] ).value == '' ) {
 72+ currField = window['payflowproGatewayErrorMsg'+ msg[i]];
 73+ output += payflowproGatewayErrorMsgJs + ' ' + currField + '.\\r\\n';
 74+ }
 75+ }
 76+
 77+ if (document.getElementById('fname').value == '$first') {
 78+ output += payflowproGatewayErrorMsgJs + ' first name.\\r\\n';
 79+ }
 80+ if (document.getElementById('lname').value == '$last') {
 81+ output += payflowproGatewayErrorMsgJs + ' last name.\\r\\n';
 82+ }
 83+ if (document.getElementById('street').value == '$street') {
 84+ output += payflowproGatewayErrorMsgJs + ' street address.\\r\\n';
 85+ }
 86+ if (document.getElementById('city').value == '$city') {
 87+ output += payflowproGatewayErrorMsgJs + ' city.\\r\\n';
 88+ }
 89+ if (document.getElementById('zip').value == '$zip') {
 90+ output += payflowproGatewayErrorMsgJs + ' zip code.\\r\\n';
 91+ }
 92+
 93+ var stateField = document.getElementById( 'state' );
 94+ if( stateField.options[stateField.selectedIndex].value == '' ) {
 95+ output += payflowproGatewayErrorMsgJs + ' ' + window['payflowproGatewayErrorMsgState'] + '.\\r\\n';
 96+ }
 97+
 98+ // validate email address
 99+ var apos = document.payment.emailAdd.value.indexOf("@");
 100+ var dotpos = document.payment.emailAdd.value.lastIndexOf(".");
 101+
 102+ if( apos < 1 || dotpos-apos < 2 ) {
 103+ output += payflowproGatewayErrorMsgEmail;
 104+ }
 105+
 106+ if( output ) {
 107+ alert( output );
 108+ return false;
 109+ }
 110+}
 111+</script>
 112+EOT;
 113+ $wgOut->addHeadItem( 'placeholders', $js );
 114+ }
 115+
 116+ public function generateFormStart() {
 117+ global $wgOut, $wgRequest, $wgScriptPath;
 118+
 119+ $form = parent::generateBannerHeader();
 120+
 121+ $form .= Xml::openElement( 'table', array( 'width' => '100%', 'cellspacing' => 0, 'cellpadding' => 0, 'border' => 0 ) );
 122+ $form .= Xml::openElement( 'tr' );
 123+ $form .= Xml::openElement( 'td', array( 'id' => 'appeal', 'valign' => 'top' ) );
 124+
 125+ $form .= Xml::openElement( 'div', array( 'id' => 'premium-confirmation' ) );
 126+ $form .= Xml::element( 'img', array( 'src' => $wgScriptPath . "/extensions/DonationInterface/payflowpro_gateway/includes/Wikipedia-ten-tshirt-back.jpg", 'width' => '300', 'height' => '300' ) );
 127+ $form .= wfMsg( 'payflowpro_gateway-shirt-size-2', $wgRequest->getText( 'size' ) );
 128+ $form .= Xml::closeElement( 'div' ); // close div#premium-confirmation
 129+
 130+ $form .= Xml::closeElement( 'td' );
 131+
 132+ $form .= Xml::openElement( 'td', array( 'id' => 'donate', 'valign' => 'top' ) );
 133+
 134+ // add noscript tags for javascript disabled browsers
 135+ $form .= $this->getNoScript();
 136+
 137+ $form .= Xml::tags( 'h2', array( 'id' => 'donate-head' ), wfMsg( 'payflowpro_gateway-please-complete' ) );
 138+
 139+ // provide a place at the top of the form for displaying general messages
 140+ if ( $this->form_errors['general'] ) {
 141+ $form .= Xml::openElement( 'div', array( 'id' => 'mw-payflow-general-error' ) );
 142+ if ( is_array( $this->form_errors['general'] ) ) {
 143+ foreach ( $this->form_errors['general'] as $this->form_errors_msg ) {
 144+ $form .= Xml::tags( 'p', array( 'class' => 'creditcard-error-msg' ), $this->form_errors_msg );
 145+ }
 146+ } else {
 147+ $form .= Xml::tags( 'p', array( 'class' => 'creditcard-error-msg' ), $this->form_errors_msg );
 148+ }
 149+ $form .= Xml::closeElement( 'div' ); // close div#mw-payflow-general-error
 150+ }
 151+
 152+ // Xml::element seems to convert html to htmlentities
 153+ $form .= "<p class='creditcard-error-msg'>" . $this->form_errors['retryMsg'] . "</p>";
 154+ $form .= Xml::openElement( 'form', array( 'name' => 'payment', 'method' => 'post', 'action' => $this->getNoCacheAction(), 'onsubmit' => 'return formCheck(this)', 'autocomplete' => 'off' ) );
 155+
 156+ $form .= $this->generateBillingContainer();
 157+ return $form;
 158+ }
 159+
 160+ public function generateFormEnd() {
 161+ $form = '';
 162+ $form .= $this->generateFormClose();
 163+ return $form;
 164+ }
 165+
 166+ protected function generateBillingContainer() {
 167+ $form = '';
 168+ $form .= Xml::openElement( 'div', array( 'id' => 'payflowpro_gateway-personal-info' ) );
 169+ $form .= Xml::openElement( 'table', array( 'id' => 'payflow-table-donor' ) );
 170+ $form .= $this->generateBillingFields();
 171+ $form .= Xml::closeElement( 'table' ); // close table#payflow-table-donor
 172+ $form .= Xml::closeElement( 'div' ); // close div#payflowpro_gateway-personal-info
 173+
 174+ return $form;
 175+ }
 176+
 177+ protected function generateBillingFields() {
 178+ global $wgScriptPath, $wgPayflowGatewayTest;
 179+
 180+ $form = '';
 181+
 182+ // amount
 183+ $form .= '<tr>';
 184+ $form .= '<td colspan="2">';
 185+ $form .= '<table cellspacing="0" cellpadding="4" border="1" id="donation_amount">';
 186+ $form .= '<tr>';
 187+ $form .= '<td class="amount_header">'.wfMsg( 'payflowpro_gateway-description' ).'</td>';
 188+ $form .= '<td class="amount_header" style="text-align:right;width:75px;">'.wfMsg( 'payflowpro_gateway-donor-amount' ).'</td>';
 189+ $form .= '<td class="amount_header" style="text-align:right;width:75px;">'.wfMsg( 'payflowpro_gateway-donor-currency-label' ).'</td>';
 190+ $form .= '</tr>';
 191+ $form .= '<tr>';
 192+ $form .= '<td class="amount_data">'.wfMsg( 'payflowpro_gateway-donation' ).'</td>';
 193+ $form .= '<td class="amount_data" style="text-align:right;width:75px;">'.$this->form_data['amount'] .
 194+ Html::hidden( 'amount', $this->form_data['amount'] ) .
 195+ '</td>';
 196+ $form .= '<td class="amount_data" style="text-align:right;width:75px;">'.$this->form_data[ 'currency' ] .
 197+ Html::hidden( 'currency_code', $this->form_data['currency'] ) .
 198+ '</td>';
 199+ $form .= '</tr>';
 200+ $form .= '</table>';
 201+ $form .= '</td>';
 202+ $form .= '</tr>';
 203+
 204+ $form .= '<tr>';
 205+ $form .= '<td colspan="2"><h3 class="cc_header">' . wfMsg( 'payflowpro_gateway-cc-form-header-personal' ) .
 206+ Xml::element( 'img', array( 'src' => $wgScriptPath . "/extensions/DonationInterface/payflowpro_gateway/includes/padlock.gif", 'style' => 'vertical-align:baseline;margin-left:8px;' ) ) . '</h3></td>';
 207+ $form .= '</tr>';
 208+
 209+ // card logos
 210+ $form .= '<tr>';
 211+ $form .= '<td class="label"> </td>';
 212+ if ( $this->form_data[ 'currency' ] == 'USD' ) {
 213+ $form .= '<td>' . Xml::element( 'img', array( 'src' => $wgScriptPath . "/extensions/DonationInterface/payflowpro_gateway/includes/credit_card_logos.gif" ) ) . '</td>';
 214+ } else {
 215+ $form .= '<td>' . Xml::element( 'img', array( 'src' => $wgScriptPath . "/extensions/DonationInterface/payflowpro_gateway/includes/credit_card_logos3.gif" ) ) . '</td>';
 216+ }
 217+ $form .= '</tr>';
 218+
 219+ // card number
 220+ $card_num = ( $wgPayflowGatewayTest ) ? $this->form_data[ 'card_num' ] : '';
 221+ $form .= '';
 222+ if ( $this->form_errors['card_num'] ) {
 223+ $form .= '<tr>';
 224+ $form .= '<td colspan=2><span class="creditcard-error-msg">' . $this->form_errors['card_num'] . '</span></td>';
 225+ $form .= '</tr>';
 226+ }
 227+ if ( $this->form_errors['card'] ) {
 228+ $form .= '<tr>';
 229+ $form .= '<td colspan=2><span class="creditcard-error-msg">' . $this->form_errors['card'] . '</span></td>';
 230+ $form .= '</tr>';
 231+ }
 232+ $form .= '<tr>';
 233+ $form .= '<td class="label">' . Xml::label( wfMsg( 'payflowpro_gateway-donor-card-num' ), 'card_num' ) . '</td>';
 234+ $form .= '<td>' . Xml::input( 'card_num', '30', $card_num, array( 'type' => 'text', 'maxlength' => '100', 'id' => 'card_num', 'class' => 'fullwidth', 'autocomplete' => 'off' ) ) .
 235+ '</td>';
 236+ $form .= '</tr>';
 237+
 238+ // expiry
 239+ $form .= '<tr>';
 240+ $form .= '<td class="label">' . Xml::label( wfMsg( 'payflowpro_gateway-donor-expiration' ), 'expiration' ) . '</td>';
 241+ $form .= '<td>' . $this->generateExpiryMonthDropdown() . ' / ' . $this->generateExpiryYearDropdown() . '</td>';
 242+ $form .= '</tr>';
 243+
 244+ // cvv
 245+ $form .= $this->getCvvField();
 246+
 247+ // name
 248+ $form .= '<tr>';
 249+ $form .= '<td colspan=2><span class="creditcard-error-msg">' . $this->form_errors['fname'] . '</span></td>';
 250+ $form .= '</tr>';
 251+ $form .= '<tr>';
 252+ $form .= '<td colspan=2><span class="creditcard-error-msg">' . $this->form_errors['lname'] . '</span></td>';
 253+ $form .= '</tr>';
 254+ $form .= '<tr>';
 255+ $form .= '<td class="label">' . Xml::label( wfMsg( 'payflowpro_gateway-name-on-card' ), 'fname' ) . '</td>';
 256+ $form .= '<td>' . Xml::input( 'fname', '30', $this->form_data['fname'], array( 'type' => 'text', 'onfocus' => 'clearField( this, \''.wfMsg( 'payflowpro_gateway-first' ).'\' )', 'maxlength' => '25', 'class' => 'required', 'id' => 'fname' ) ) .
 257+ Xml::input( 'lname', '30', $this->form_data['lname'], array( 'type' => 'text', 'onfocus' => 'clearField( this, \''.wfMsg( 'payflowpro_gateway-last' ).'\' )', 'maxlength' => '25', 'id' => 'lname' ) ) . '</td>';
 258+ $form .= "</tr>";
 259+
 260+ // street
 261+ $form .= '<tr>';
 262+ $form .= '<td colspan=2><span class="creditcard-error-msg">' . $this->form_errors['street'] . '</span></td>';
 263+ $form .= '</tr>';
 264+ $form .= '<tr>';
 265+ $form .= '<td class="label">' . Xml::label( wfMsg( 'payflowpro_gateway-billing-address' ), 'street' ) . '</td>';
 266+ $form .= '<td>' . Xml::input( 'street', '30', $this->form_data['street'], array( 'type' => 'text', 'onfocus' => 'clearField( this, \''.wfMsg( 'payflowpro_gateway-donor-street' ).'\' )', 'maxlength' => '100', 'id' => 'street', 'class' => 'fullwidth' ) ) .
 267+ '</td>';
 268+ $form .= '</tr>';
 269+
 270+ // city
 271+ $form .= '<tr>';
 272+ $form .= '<td colspan=2><span class="creditcard-error-msg">' . $this->form_errors['city'] . '</span></td>';
 273+ $form .= '</tr>';
 274+ $form .= '<tr>';
 275+ $form .= '<td class="label"> </td>';
 276+ $form .= '<td>' . Xml::input( 'city', '18', $this->form_data['city'], array( 'type' => 'text', 'onfocus' => 'clearField( this, \''.wfMsg( 'payflowpro_gateway-donor-city' ).'\' )', 'maxlength' => '40', 'id' => 'city' ) ) . ' ' .
 277+ $this->generateStateDropdown() . ' ' .
 278+ Xml::input( 'zip', '5', $this->form_data['zip'], array( 'type' => 'text', 'onfocus' => 'clearField( this, \''.wfMsg( 'payflowpro_gateway-zip-code' ).'\' )', 'maxlength' => '10', 'id' => 'zip' ) ) .
 279+ Html::hidden( 'country', 840 ) .
 280+ '</td>';
 281+ $form .= '</tr>';
 282+
 283+ // country
 284+ $form .= '<tr>';
 285+ $form .= '<td colspan=2><span class="creditcard-error-msg">' . $this->form_errors['country'] . '</span></td>';
 286+ $form .= '</tr>';
 287+ $form .= '<tr>';
 288+ $form .= '<td class="label"> </td>';
 289+ $form .= '<td>' . $this->generateCountryDropdown( $this->form_data['country2'] ) . '</td>';
 290+ $form .= '</tr>';
 291+
 292+ // email
 293+ $form .= '<tr>';
 294+ $form .= '<td colspan=2><span class="creditcard-error-msg">' . $this->form_errors['emailAdd'] . '</span></td>';
 295+ $form .= '</tr>';
 296+ $form .= '<tr>';
 297+ $form .= '<td class="label">' . Xml::label( wfMsg( 'payflowpro_gateway-email-receipt' ), 'emailAdd' ) . '</td>';
 298+ $form .= '<td>' . Xml::input( 'emailAdd', '30', $this->form_data['email'], array( 'type' => 'text', 'onfocus' => 'clearField( this, \''.wfMsg( 'payflowpro_gateway-donor-email' ).'\' )', 'maxlength' => '64', 'id' => 'emailAdd', 'class' => 'fullwidth' ) ) .
 299+ '</td>';
 300+ $form .= '</tr>';
 301+
 302+ return $form;
 303+ }
 304+
 305+ /**
 306+ * Generate form closing elements
 307+ */
 308+ public function generateFormClose() {
 309+ $form = '';
 310+ // add hidden fields
 311+ $hidden_fields = $this->getHiddenFields();
 312+ foreach ( $hidden_fields as $field => $value ) {
 313+ $form .= Html::hidden( $field, $value );
 314+ }
 315+
 316+ $form .= Xml::closeElement( 'form' ); // close form 'payment'
 317+ $form .= $this->generateDonationFooter();
 318+ $form .= Xml::closeElement( 'td' );
 319+ $form .= Xml::closeElement( 'tr' );
 320+ $form .= Xml::closeElement( 'table' );
 321+ return $form;
 322+ }
 323+}
Index: trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.php
@@ -37,6 +37,7 @@
3838 $wgAutoloadClasses[ 'PayflowProGateway_Form_TwoStepTwoColumnLetter2' ] = $dir . 'forms/TwoStepTwoColumnLetter2.php';
3939 $wgAutoloadClasses[ 'PayflowProGateway_Form_TwoStepTwoColumnLetter3' ] = $dir . 'forms/TwoStepTwoColumnLetter3.php';
4040 $wgAutoloadClasses[ 'PayflowProGateway_Form_TwoStepTwoColumnPremium' ] = $dir . 'forms/TwoStepTwoColumnPremium.php';
 41+$wgAutoloadClasses[ 'PayflowProGateway_Form_TwoStepTwoColumnPremiumUS' ] = $dir . 'forms/TwoStepTwoColumnPremiumUS.php';
4142 $wgAutoloadClasses[ 'PayflowProGateway_Form_RapidHtml' ] = $dir . 'forms/RapidHtml.php';
4243 $wgAutoloadClasses[ 'PayflowProGateway_Form_SingleColumn' ] = $dir . 'forms/SingleColumn.php';
4344 $wgExtensionMessagesFiles['PayflowProGateway'] = $dir . 'payflowpro_gateway.i18n.php';

Status & tagging log