r98470 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98469‎ | r98470 | r98471 >
Date:22:10, 29 September 2011
Author:jpostlethwaite
Status:resolved (Comments)
Tags:fundraising 
Comment:
Added a form for BANK_TRANSFER.
Modified paths:
  • /branches/fundraising/extensions/DonationInterface/gateway_forms/TwoStepAmount.php (added) (history)

Diff [purge]

Index: branches/fundraising/extensions/DonationInterface/gateway_forms/TwoStepAmount.php
@@ -0,0 +1,261 @@
 2+<?php
 3+/**
 4+ * Wikimedia Foundation
 5+ *
 6+ * LICENSE
 7+ *
 8+ * This program is free software; you can redistribute it and/or modify
 9+ * it under the terms of the GNU General Public License as published by
 10+ * the Free Software Foundation; either version 2 of the License, or
 11+ * (at your option) any later version.
 12+ *
 13+ * This program is distributed in the hope that it will be useful,
 14+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 16+ * GNU General Public License for more details.
 17+ *
 18+ * @since r98249
 19+ * @author Jeremy Postlethwaite <jpostlethwaite@wikimedia.org>
 20+ */
 21+
 22+/**
 23+ * This form is designed for bank transfers
 24+ */
 25+class Gateway_Form_TwoStepAmount extends Gateway_Form {
 26+
 27+ public function __construct( &$form_data, &$form_errors, &$gateway ) {
 28+ global $wgOut;
 29+
 30+ $form_data['transaction_type'] = 'BANK_TRANSFER';
 31+ parent::__construct( $form_data, $form_errors, $gateway );
 32+
 33+ // we only want to load this JS if the form is being rendered
 34+ $this->loadValidateJs(); // validation JS
 35+
 36+ $this->loadPlaceholders();
 37+ }
 38+
 39+ public function loadPlaceholders() {
 40+ global $wgOut;
 41+ // form placeholder values
 42+ $first = wfMsg( 'payflowpro_gateway-donor-fname' );
 43+ $last = wfMsg( 'payflowpro_gateway-donor-lname' );
 44+ $js = <<<EOT
 45+<script type="text/javascript">
 46+function loadPlaceholders() {
 47+ var fname = document.getElementById('fname');
 48+ var lname = document.getElementById('lname');
 49+ var amountOther = document.getElementById('amountOther');
 50+ if (fname.value == '') {
 51+ fname.style.color = '#999999';
 52+ fname.value = '$first';
 53+ }
 54+ if (lname.value == '') {
 55+ lname.style.color = '#999999';
 56+ lname.value = '$last';
 57+ }
 58+}
 59+addEvent( window, 'load', loadPlaceholders );
 60+
 61+function formCheck( ccform ) {
 62+ var msg = [ 'EmailAdd', 'Fname', 'Lname', 'Street', 'City', 'Zip' ];
 63+
 64+ var fields = ["emailAdd","fname","lname","street","city","zip" ],
 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+ var countryField = document.getElementById( 'country' );
 84+ if( countryField.options[countryField.selectedIndex].value == '' ) {
 85+ output += payflowproGatewayErrorMsgJs + ' ' + window['payflowproGatewayErrorMsgCountry'] + '.\\r\\n';
 86+ }
 87+
 88+ // validate email address
 89+ var apos = document.payment.emailAdd.value.indexOf("@");
 90+ var dotpos = document.payment.emailAdd.value.lastIndexOf(".");
 91+
 92+ if( apos < 1 || dotpos-apos < 2 ) {
 93+ output += payflowproGatewayErrorMsgEmail;
 94+ }
 95+
 96+ if( output ) {
 97+ alert( output );
 98+ return false;
 99+ } else {
 100+ return true;
 101+ }
 102+}
 103+</script>
 104+EOT;
 105+ $wgOut->addHeadItem( 'placeholders', $js );
 106+ }
 107+
 108+ /**
 109+ * Required method for constructing the entire form
 110+ *
 111+ * This can of course be overloaded by a child class.
 112+ * @return string The entire form HTML
 113+ */
 114+ public function getForm() {
 115+ $form = $this->generateFormStart();
 116+ $form .= $this->getCaptchaHTML();
 117+ $form .= $this->generateFormEnd();
 118+ return $form;
 119+ }
 120+
 121+ public function generateFormStart() {
 122+ $form = $this->generateBannerHeader();
 123+
 124+ $form .= Xml::openElement( 'div', array( 'id' => 'mw-creditcard' ) );
 125+
 126+ // provide a place at the top of the form for displaying general messages
 127+ if ( $this->form_errors['general'] ) {
 128+ $form .= Xml::openElement( 'div', array( 'id' => 'mw-payflow-general-error' ) );
 129+ if ( is_array( $this->form_errors['general'] ) ) {
 130+ foreach ( $this->form_errors['general'] as $this->form_errors_msg ) {
 131+ $form .= Xml::tags( 'p', array( 'class' => 'creditcard-error-msg' ), $this->form_errors_msg );
 132+ }
 133+ } else {
 134+ $form .= Xml::tags( 'p', array( 'class' => 'creditcard-error-msg' ), $this->form_errors_msg );
 135+ }
 136+ $form .= Xml::closeElement( 'div' );
 137+ }
 138+
 139+ // add noscript tags for javascript disabled browsers
 140+ $form .= $this->getNoScript();
 141+
 142+ // open form
 143+ $form .= Xml::openElement( 'div', array( 'id' => 'mw-creditcard-form' ) );
 144+
 145+ // Xml::element seems to convert html to htmlentities
 146+ $form .= "<p class='creditcard-error-msg'>" . $this->form_errors['retryMsg'] . "</p>";
 147+ $form .= Xml::openElement( 'form', array( 'name' => 'payment', 'method' => 'post', 'action' => $this->getNoCacheAction(), 'onsubmit' => 'return formCheck(this)', 'autocomplete' => 'off' ) );
 148+
 149+ $form .= Xml::openElement( 'div', array( 'id' => 'left-column', 'class' => 'payflow-cc-form-section' ) );
 150+ $form .= $this->generatePersonalContainer();
 151+ $form .= $this->generatePaymentContainer();
 152+ $form .= $this->generateFormSubmit();
 153+ $form .= Xml::closeElement( 'div' ); // close div#left-column
 154+
 155+ //$form .= Xml::openElement( 'div', array( 'id' => 'right-column', 'class' => 'payflow-cc-form-section' ) );
 156+
 157+ return $form;
 158+ }
 159+
 160+ public function generateFormSubmit() {
 161+ // submit button
 162+ $form = Xml::openElement( 'div', array( 'id' => 'payflowpro_gateway-form-submit' ) );
 163+ $form .= Xml::openElement( 'div', array( 'id' => 'mw-donate-submit-button' ) );
 164+ // $form .= Xml::submitButton( wfMsg( 'payflowpro_gateway-submit-button' ));
 165+ $form .= Xml::element( 'input', array( 'class' => 'button-plain', 'value' => wfMsg( 'payflowpro_gateway-cc-button' ), 'type' => 'submit' ) );
 166+ $form .= Xml::closeElement( 'div' ); // close div#mw-donate-submit-button
 167+ $form .= Xml::openElement( 'div', array( 'class' => 'mw-donate-submessage', 'id' => 'payflowpro_gateway-donate-submessage' ) ) .
 168+ wfMsg( 'payflowpro_gateway-donate-click' );
 169+ $form .= Xml::closeElement( 'div' ); // close div#payflowpro_gateway-donate-submessage
 170+ $form .= Xml::closeElement( 'div' ); // close div#payflowpro_gateway-form-submit
 171+ return $form;
 172+ }
 173+
 174+ public function generateFormEnd() {
 175+ $form = '';
 176+ // add hidden fields
 177+ $hidden_fields = $this->getHiddenFields();
 178+ foreach ( $hidden_fields as $field => $value ) {
 179+ $form .= Html::hidden( $field, $value );
 180+ }
 181+
 182+ $value = 'BANK_TRANSFER';
 183+ //$form .= Html::hidden( $field, $value );
 184+ //$form .= Xml::closeElement( 'div' ); // close div#right-column
 185+ $form .= Xml::closeElement( 'form' );
 186+ $form .= Xml::closeElement( 'div' ); // close div#mw-creditcard-form
 187+ $form .= $this->generateDonationFooter();
 188+ $form .= Xml::closeElement( 'div' ); // div#close mw-creditcard
 189+ return $form;
 190+ }
 191+
 192+ protected function generatePersonalContainer() {
 193+ $form = '';
 194+ $form .= Xml::openElement( 'div', array( 'id' => 'payflowpro_gateway-personal-info' ) ); ;
 195+ //$form .= Xml::tags( 'h3', array( 'class' => 'payflow-cc-form-header', 'id' => 'payflow-cc-form-header-personal' ), wfMsg( 'payflowpro_gateway-cc-form-header-personal' ) );
 196+ $form .= Xml::openElement( 'table', array( 'id' => 'payflow-table-donor' ) );
 197+
 198+ $form .= $this->generatePersonalFields();
 199+
 200+ $form .= Xml::closeElement( 'table' ); // close table#payflow-table-donor
 201+ $form .= Xml::closeElement( 'div' ); // close div#payflowpro_gateway-personal-info
 202+
 203+ return $form;
 204+ }
 205+
 206+ protected function generatePersonalFields() {
 207+ // first name
 208+ $form = $this->getNameField();
 209+
 210+ // country
 211+ $form .= $this->getCountryField();
 212+
 213+ // street
 214+ $form .= $this->getStreetField();
 215+
 216+
 217+ // city
 218+ $form .= $this->getCityField();
 219+
 220+ // state
 221+ $form .= $this->getStateField();
 222+
 223+ // zip
 224+ $form .= $this->getZipField();
 225+
 226+ // email
 227+ $form .= $this->getEmailField();
 228+
 229+ return $form;
 230+ }
 231+
 232+ protected function generatePaymentContainer() {
 233+ $form = '';
 234+ // credit card info
 235+ $form .= Xml::openElement( 'div', array( 'id' => 'payflowpro_gateway-payment-info' ) );
 236+ //$form .= Xml::tags( 'h3', array( 'class' => 'payflow-cc-form-header', 'id' => 'payflow-cc-form-header-payment' ), wfMsg( 'payflowpro_gateway-cc-form-header-payment' ) );
 237+ $form .= Xml::openElement( 'table', array( 'id' => 'payflow-table-cc' ) );
 238+
 239+ $form .= $this->generatePaymentFields();
 240+
 241+ $form .= Xml::closeElement( 'table' ); // close table#payflow-table-cc
 242+ $form .= Xml::closeElement( 'div' ); // close div#payflowpro_gateway-payment-info
 243+
 244+ return $form;
 245+ }
 246+
 247+ protected function generatePaymentFields() {
 248+ global $wgScriptPath;
 249+
 250+ // amount
 251+ $form = '<tr>';
 252+ $form .= '<td colspan="2"><span class="creditcard-error-msg">' . $this->form_errors['invalidamount'] . '</span></td>';
 253+ $form .= '</tr>';
 254+ $form .= '<tr>';
 255+ $form .= '<td class="label">' . Xml::label( wfMsg( 'payflowpro_gateway-donor-amount' ), 'amount' ) . '</td>';
 256+ $form .= '<td>' . Xml::input( 'amount', '7', $this->form_data['amount'], array( 'type' => 'text', 'maxlength' => '10', 'id' => 'amount' ) ) .
 257+ ' ' . $this->generateCurrencyDropdown() . '</td>';
 258+ $form .= '</tr>';
 259+
 260+ return $form;
 261+ }
 262+}
Property changes on: branches/fundraising/extensions/DonationInterface/gateway_forms/TwoStepAmount.php
___________________________________________________________________
Added: svn:eol-style
1263 + native
Added: svn:mime-type
2264 + text/plain
Added: svn:keywords
3265 + Author Date HeadURL Header Id Revision

Follow-up revisions

RevisionCommit summaryAuthorDate
r100207See r98470 - Cleaning up form code and reordering function calls.jpostlethwaite03:11, 19 October 2011

Comments

#Comment by Awjrichards (talk | contribs)   22:25, 7 October 2011
+		// we only want to load this JS if the form is being rendered
+		$this->loadValidateJs(); // validation JS
+
+		$this->loadPlaceholders();

These should probably be called before the parent constructor.

loadPlaceholders() will need to be replaced with the ResourceLoader-ified version of this method that was just added to trunk, though I imagine we'll take care of this when merging this branch back into trunk.

+		//$form .= Html::hidden( $field, $value );
+		//$form .= Xml::closeElement( 'div' ); // close div#right-column

Are these supposed to be commented out? I don't see $value used anywhere else in that function.

Also, I wonder if we should change the element ids to something other than 'payflowpro-' for this, but perhaps that's a non-issue.

#Comment by Awjrichards (talk | contribs)   22:26, 7 October 2011

oops, marked 'ok' on accident. resetting to fixme.

#Comment by Jpostlethwaite (talk | contribs)   23:23, 7 October 2011

This is only being used for testing, at this point, for BANK_TRANSFER.

We also need to update messaging for GlobalCollect.

#Comment by Jpostlethwaite (talk | contribs)   03:26, 19 October 2011

Reordered constructor as suggested.

Removed commented out fields.

Messaging will be dealt with in another fashion. This form is used for testing at this point.

Status & tagging log