r106902 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106901‎ | r106902 | r106903 >
Date:00:27, 21 December 2011
Author:jpostlethwaite
Status:deferred
Tags:fundraising 
Comment:
Renamed and moved TwoStepAmount to UniversalTestForm into tests.
Modified paths:
  • /trunk/extensions/DonationInterface/globalcollect_gateway/forms/TwoStepAmount.php (deleted) (history)
  • /trunk/extensions/DonationInterface/tests/resources/forms/UniversalTestForm.php (added) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/tests/resources/forms/UniversalTestForm.php
@@ -0,0 +1,977 @@
 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+ /**
 28+ * The default value of section header tags.
 29+ *
 30+ * A value of 3 => h3
 31+ *
 32+ * @var integer $sectionHeaderLevel
 33+ */
 34+ public $sectionHeaderLevel = 3;
 35+
 36+ /**
 37+ * The appeal
 38+ *
 39+ * @var string $appeal
 40+ */
 41+ public $appeal = '';
 42+
 43+ /**
 44+ * The default appeal
 45+ *
 46+ */
 47+ const DEFAULT_APPEAL = <<<HTML
 48+ <h2 id="appeal-head"> <span class="mw-headline" id="From_Wikipedia_programmer_Brandon_Harris">From Wikipedia programmer Brandon Harris</span></h2>
 49+ <div id="appeal-body" class="plainlinks">
 50+ <p>I feel like I'm living the first line of my obituary.</p>
 51+ <p>I don't think there will be anything else that I do in my life as important as what I do now for Wikipedia. We're not just building an encyclopedia, we're working to make people free. When we have access to free knowledge, we are better people. We understand the world is bigger than us, and we become infected with tolerance and understanding.</p>
 52+ <p>Wikipedia is the 5th largest website in the world. I work at the small non-profit that keeps it on the web. We don't run ads because doing so would sacrifice our independence. The site is not and should never be a propaganda tool.</p>
 53+ <p>Our work is possible because of donations from our readers. Will you help protect Wikipedia by donating $5, $10, $20 or whatever you can afford?</p>
 54+ <p>I work at the Wikimedia Foundation because everything in my soul tells me it's the right thing to do. I've worked at huge tech companies, doing some job to build some crappy thing that's designed to steal money from some kid who doesn't know it. I would come home from work crushed.</p>
 55+ <p>You might not know this, but the Wikimedia Foundation operates with a very small staff. Most other top-ten sites have tens of thousands of people and massive budgets. But they produce a fraction of what we pull off with sticks and wire.</p>
 56+ <p>When you give to Wikipedia, you're supporting free knowledge around the world. You're not only leaving a legacy for your children and for their children, you're elevating people around the world who have access to this treasure. You're assuring that one day everyone else will too.</p>
 57+ <p>Thank you,</p>
 58+ <p><strong>Brandon Harris</strong><br /></p>
 59+ <p>Programmer, Wikimedia Foundation</p>
 60+ </div>
 61+HTML;
 62+
 63+ ////////////////////////////////////////////////////////////////////////////
 64+ //
 65+ // Form methods
 66+ //
 67+ ////////////////////////////////////////////////////////////////////////////
 68+
 69+ /**
 70+ * Initialize the form
 71+ *
 72+ * This is called at the end of the constructor
 73+ *
 74+ */
 75+ protected function init() {
 76+
 77+ // Initialize the appeal
 78+ $this->appeal = self::DEFAULT_APPEAL;
 79+
 80+ $this->loadResources();
 81+ }
 82+
 83+ /**
 84+ * Required method for returning the full HTML for a form.
 85+ *
 86+ * @return string The entire form HTML
 87+ */
 88+ public function getForm() {
 89+
 90+ return $this->getFormPage();
 91+
 92+ $form = '';
 93+
 94+ $form .= $this->generateFormStart();
 95+ $form .= $this->generateFormEnd();
 96+ return $form;
 97+ }
 98+
 99+ /**
 100+ * Get the form messages by type.
 101+ *
 102+ * Since this displays to the end user, if a key does not exist, it fails
 103+ * silently and returns an empty string.
 104+ *
 105+ * @param string $type
 106+ * @param array $options
 107+ *
 108+ * @todo
 109+ * - Move to the parent class
 110+ * - This returns error messages by paragraph tags, but it may be better to do this as a list.
 111+ *
 112+ * @return string Returns an HTML string
 113+ */
 114+ protected function getFormMessagesByType( $type, $options = array() ) {
 115+
 116+ if ( isset( $options['type'] ) ) {
 117+ unset( $options['type'] );
 118+ }
 119+
 120+ extract( $options );
 121+
 122+ $defaultErrorClass = 'payment_error_message payment_error_message_' . strtolower( $type );
 123+
 124+ $errorClass = isset( $errorClass ) ? $errorClass : $defaultErrorClass;
 125+
 126+ $return = '';
 127+
 128+ if ( isset( $this->form_errors[ $type ] ) ) {
 129+
 130+ if ( is_array( $this->form_errors[ $type ] ) ) {
 131+
 132+ // Loop through messages and display them as paragraphs
 133+ foreach ( $this->form_errors[ $type ] as $message ) {
 134+ $return .= Xml::tags( 'p', array( 'class' => $errorClass ), $message );
 135+ }
 136+ } else {
 137+
 138+ // Display single message
 139+ $return .= Xml::tags( 'p', array( 'class' => $errorClass ), $this->form_errors[ $type ] );
 140+ }
 141+ }
 142+
 143+ return $return;
 144+ }
 145+
 146+ /**
 147+ * Get the form messages
 148+ *
 149+ * @param array $options
 150+ *
 151+ * @return string Returns an HTML string
 152+ */
 153+ protected function getFormMessages( $options = array() ) {
 154+
 155+ $return = '';
 156+
 157+ // We want this container to exist so it can be populated with javascript messages.
 158+ $return .= Xml::openElement( 'div', array( 'id' => 'payment_form_messages' ) );
 159+
 160+ $return .= $this->getFormMessagesByType('general');
 161+
 162+ $return .= $this->getFormMessagesByType('invalidamount');
 163+
 164+ $return .= $this->getFormMessagesByType('retryMsg');
 165+
 166+ $return .= Xml::closeElement( 'div' ); // payment_form_messages
 167+
 168+ return $return;
 169+ }
 170+
 171+ /**
 172+ * Get the section header tag
 173+ *
 174+ * @param string $section The section label
 175+ * @param array $options
 176+ *
 177+ * @return string Returns an HTML string
 178+ */
 179+ protected function getFormSectionHeaderTag( $section, $options = array() ) {
 180+
 181+ // Make sure $section does not get overridden.
 182+ if ( isset( $options['section'] ) ) {
 183+
 184+ unset( $options['section'] );
 185+ }
 186+
 187+ extract( $options );
 188+
 189+ $headerLevel = isset( $headerLevel ) ? (integer) $headerLevel : (integer) $this->sectionHeaderLevel;
 190+ $headerId = isset( $headerId ) ? (string) $headerId : '';
 191+ $headerClass = isset( $headerClass ) ? (string) $headerClass : '';
 192+
 193+ // Set maximum level to 6
 194+ $headerLevel = ( $headerLevel > 6 ) ? 6 : $headerLevel;
 195+
 196+ // Set minimum level to 2
 197+ $headerLevel = ( $headerLevel < 2 ) ? 2 : $headerLevel;
 198+
 199+ $headerTag = 'h' . $headerLevel;
 200+
 201+ $headerOptions = array();
 202+
 203+ // Add a header class
 204+ if ( !empty( $headerClass ) ) {
 205+ $headerOptions['class'] = $headerClass;
 206+ }
 207+
 208+ // Add a header id
 209+ if ( !empty( $headerId ) ) {
 210+ $headerOptions['id'] = $headerId;
 211+ }
 212+
 213+ $return = Xml::tags( $headerTag, $headerOptions, $section );
 214+
 215+ return $return;
 216+ }
 217+
 218+ /**
 219+ * Load form resources
 220+ */
 221+ protected function loadResources() {
 222+
 223+ $this->loadValidateJs();
 224+ }
 225+
 226+ /**
 227+ * Load extra javascript
 228+ */
 229+ protected function loadValidateJs() {
 230+ global $wgOut;
 231+ $wgOut->addModules( 'gc.form.core.validate' );
 232+
 233+ $js = "\n" . '<script type="text/javascript">'
 234+ . "var validatePaymentForm = {
 235+ formId: '" . $this->getFormId() . "',
 236+ payment_method: '" . $this->getPaymentMethod() . "',
 237+ payment_submethod: '" . $this->getPaymentSubmethod() . "',
 238+ }"
 239+ . '</script>' . "\n";
 240+ $wgOut->addHeadItem( 'loadValidateJs', $js );
 241+ }
 242+
 243+ ////////////////////////////////////////////////////////////////////////////
 244+ //
 245+ // Get and set html snippets of code for form
 246+ //
 247+ ////////////////////////////////////////////////////////////////////////////
 248+
 249+ /**
 250+ * Set the appeal
 251+ *
 252+ * @param string $appeal The html appeal text
 253+ * @param array $options
 254+ *
 255+ * @return string Returns an HTML string
 256+ */
 257+ protected function setAppeal( $appeal, $options = array() ) {
 258+
 259+ $this->appeal = $appeal;
 260+ }
 261+
 262+ /**
 263+ * Get the appeal
 264+ *
 265+ * @param array $options
 266+ *
 267+ * @return string Returns an HTML string
 268+ */
 269+ protected function getAppeal( $options = array() ) {
 270+
 271+ $return = '';
 272+
 273+ $return .= Xml::openElement( 'div', array( 'id' => 'appeal' ) );
 274+
 275+ $return .= Xml::openElement( 'div', array( 'id' => 'appeal-content' ) );
 276+
 277+ $return .= $this->appeal;
 278+
 279+ $return .= Xml::closeElement( 'div' ); // appeal-content
 280+
 281+ $return .= Xml::closeElement( 'div' ); // appeal
 282+
 283+ return $return;
 284+ }
 285+
 286+ /**
 287+ * Generate the bank transfer component
 288+ *
 289+ * Nothing is being added right now.
 290+ *
 291+ * @param array $options
 292+ *
 293+ * @return string Returns an HTML string
 294+ */
 295+ protected function getBankTransfer( $options = array() ) {
 296+
 297+ extract( $options );
 298+
 299+ $return = '';
 300+
 301+ return $return;
 302+ }
 303+
 304+ /**
 305+ * Generate the credit card component
 306+ *
 307+ * Nothing is being added right now.
 308+ *
 309+ * @param array $options
 310+ *
 311+ * @return string Returns an HTML string
 312+ */
 313+ protected function getCreditCard( $options = array() ) {
 314+
 315+ extract( $options );
 316+
 317+ $return = '';
 318+
 319+ return $return;
 320+ }
 321+
 322+ /**
 323+ * Generate the direct debit component
 324+ *
 325+ * @param array $options
 326+ *
 327+ * @return string Returns an HTML string
 328+ */
 329+ protected function getDirectDebit( $options = array() ) {
 330+
 331+ extract( $options );
 332+
 333+ $return = '';
 334+
 335+ $ignore = isset( $ignore ) ? (array) $ignore : array();
 336+
 337+ if ( $this->getPaymentMethod() != 'dd' ) {
 338+
 339+ // No direct debit fields need to be loaded.
 340+ return $return;
 341+ }
 342+
 343+ $fields = array(
 344+ 'account_name' => array( 'required' => true, ),
 345+ 'account_number' => array( 'required' => true, ),
 346+ 'authorization_id' => array( 'required' => true, ),
 347+ 'bank_check_digit' => array( 'required' => true, ),
 348+ 'bank_code' => array( 'required' => true, ),
 349+ 'bank_name' => array( 'required' => true, ),
 350+ 'branch_code' => array( 'required' => true, ),
 351+ 'iban' => array( 'required' => true, ),
 352+ );
 353+
 354+ $country = !is_null( $this->getEscapedValue( 'country' ) ) ? $this->getEscapedValue( 'country' ) : '';
 355+
 356+ if ( $country == 'AT' ) {
 357+
 358+ unset( $fields['bank_check_digit'] );
 359+ unset( $fields['branch_code'] );
 360+ unset( $fields['iban'] );
 361+ }
 362+ elseif ( $country == 'BE' ) {
 363+
 364+ unset( $fields['branch_code'] );
 365+ unset( $fields['iban'] );
 366+ }
 367+ elseif ( $country == 'IT' ) {
 368+
 369+ unset( $fields['iban'] );
 370+ }
 371+ elseif ( $country == 'NL' ) {
 372+
 373+ unset( $fields['bank_check_digit'] );
 374+ unset( $fields['branch_code'] );
 375+ unset( $fields['iban'] );
 376+ }
 377+ elseif ( $country == 'ES' ) {
 378+
 379+ unset( $fields['iban'] );
 380+ }
 381+
 382+
 383+ foreach ( $fields as $field => $meta ) {
 384+
 385+ // Skip ignored fields
 386+ if ( in_array( $field, $ignore ) ) {
 387+
 388+ continue;
 389+ }
 390+
 391+ $return .= '<tr>';
 392+ $return .= '<td class="label">' . Xml::label( wfMsg( 'donate_interface-dd-' . $field ), $field ) . '</td>';
 393+
 394+ $return .= '<td>';
 395+
 396+ $required = isset ( $meta['required'] ) ? (boolean) $meta['required'] : false ;
 397+ $elementClass = '';
 398+ $elementClass .= $required ? ' required ' : '' ;
 399+ $elementClass = trim( $elementClass );
 400+
 401+ $return .= Xml::input( $field, '', $this->getEscapedValue( $field ), array( 'class' => $elementClass, 'type' => 'text', 'maxlength' => '32', 'id' => $field ) );
 402+ $return .= '</td>';
 403+ $return .= '</tr>';
 404+ }
 405+
 406+ return $return;
 407+ }
 408+
 409+ /**
 410+ * Get the end of the form
 411+ *
 412+ * This method gets the hidden fields and appends the closing form tag.
 413+ *
 414+ * @param array $options
 415+ *
 416+ * @return string Returns an HTML string
 417+ */
 418+ protected function getFormEnd( $options = array() ) {
 419+
 420+ extract( $options );
 421+
 422+ $return = '';
 423+
 424+ $return .= $this->generateFormSubmit();
 425+
 426+ // Add hidden fields
 427+ foreach ( $this->getHiddenFields() as $field => $value ) {
 428+
 429+ $return .= Html::hidden( $field, $value );
 430+ }
 431+
 432+ $return .= Xml::closeElement( 'form' );
 433+
 434+ return $return;
 435+ }
 436+
 437+ /**
 438+ * Get the page including form and content
 439+ *
 440+ * @param array $options
 441+ *
 442+ * @return string Returns an HTML string
 443+ */
 444+ protected function getFormPage( $options = array() ) {
 445+
 446+ extract( $options );
 447+
 448+ $return = '';
 449+
 450+ $headerLevel = isset( $headerLevel ) ? (integer) $headerLevel : 3;
 451+
 452+ // Tell the user they need JavaScript enabled.
 453+ $return .= $this->getNoScript();
 454+
 455+ // Display the form messages
 456+ $return .= $this->getFormMessages( $options );
 457+
 458+ $return .= Xml::openElement( 'div', array( 'id' => 'payment_form_container' ) );
 459+
 460+ $return .= $this->getFormStart();
 461+
 462+ $return .= $this->getCaptchaHTML();
 463+
 464+ $return .= $this->getFormSectionAmount();
 465+
 466+ $return .= $this->getFormSectionPersonal();
 467+
 468+ $return .= $this->getFormSectionPayment();
 469+
 470+ $return .= $this->getFormEnd();
 471+
 472+ $return .= $this->generateDonationFooter();
 473+
 474+ $return .= Xml::closeElement( 'div' ); // payment_form_container
 475+
 476+ // Display the appeal
 477+ $return .= $this->getAppeal( $options );
 478+
 479+ return $return;
 480+ }
 481+
 482+ /**
 483+ * Get the page including form and content
 484+ *
 485+ * @param array $options
 486+ *
 487+ * @return string Returns an HTML string
 488+ */
 489+ protected function generateFormSubmit( $options = array() ) {
 490+
 491+ extract( $options );
 492+
 493+ $return = '';
 494+
 495+ // submit button
 496+ $return .= Xml::openElement( 'div', array( 'id' => 'payment_gateway-form-submit' ) );
 497+ $return .= Xml::openElement( 'div', array( 'id' => 'mw-donate-submit-button' ) );
 498+ $return .= Xml::element( 'input', array( 'class' => 'button-plain', 'value' => wfMsg( 'donate_interface-submit-button' ), 'type' => 'submit' ) );
 499+ $return .= Xml::closeElement( 'div' ); // close div#mw-donate-submit-button
 500+ $return .= Xml::closeElement( 'div' ); // close div#payment_gateway-form-submit
 501+
 502+ return $return;
 503+ }
 504+
 505+ /**
 506+ * Get the start of the form
 507+ *
 508+ * @param array $options
 509+ *
 510+ * @return string Returns an HTML string
 511+ */
 512+ protected function getFormStart( $options = array() ) {
 513+
 514+ extract( $options );
 515+
 516+ $return = '';
 517+
 518+ $formOptions = array(
 519+ 'action' => $this->getNoCacheAction(),
 520+ 'autocomplete' => 'off',
 521+ 'id' => $this->getFormId(),
 522+ 'method' => 'post',
 523+ 'name' => $this->getFormName(),
 524+ 'onsubmit' => '',
 525+ );
 526+
 527+ // Xml::element seems to convert html to htmlentities
 528+ $return .= Xml::openElement( 'form', $formOptions );
 529+
 530+ return $return;
 531+ }
 532+
 533+ /**
 534+ * Generate the bank transfer component
 535+ *
 536+ * Nothing is being added right now.
 537+ *
 538+ * @param array $options
 539+ *
 540+ * @return string Returns an HTML string
 541+ */
 542+ protected function getRealTimeBankTransfer( $options = array() ) {
 543+
 544+ extract( $options );
 545+
 546+ $return = '';
 547+
 548+ $payment_submethod = $this->gateway->getPaymentSubmethodMeta( $this->getPaymentSubmethod() );
 549+ if ( !isset( $payment_submethod['issuerids'] ) || empty( $payment_submethod['issuerids'] ) ) {
 550+
 551+ // No issuer_id to load
 552+ return $return;
 553+ }
 554+
 555+ $selectOptions = '';
 556+
 557+ // generate dropdown of issuer_ids
 558+ foreach ( $payment_submethod['issuerids'] as $issuer_id => $issuer_id_label ) {
 559+ $selected = ( $this->getEscapedValue( 'issuer_id' ) == $issuer_id ) ? true : false;
 560+ //$selectOptions .= Xml::option( wfMsg( 'donate_interface-rtbt-' . $issuer_id ), $issuer_id_label, $selected );
 561+ $selectOptions .= Xml::option( $issuer_id_label, $issuer_id, $selected );
 562+ }
 563+ $return .= '<tr>';
 564+ $return .= '<td class="label">' . Xml::label( wfMsg( 'donate_interface-rtbt-issuer_id' ), 'issuer_id' ) . '</td>';
 565+
 566+ $return .= '<td>';
 567+ $return .= Xml::openElement(
 568+ 'select',
 569+ array(
 570+ 'name' => 'issuer_id',
 571+ 'id' => 'issuer_id',
 572+ 'onchange' => '',
 573+ ) );
 574+ $return .= $selectOptions;
 575+ $return .= Xml::closeElement( 'select' );
 576+
 577+ $return .= '</td>';
 578+ $return .= '</tr>';
 579+
 580+ return $return;
 581+ }
 582+
 583+ ////////////////////////////////////////////////////////////////////////////
 584+ //
 585+ // Form sections
 586+ //
 587+ ////////////////////////////////////////////////////////////////////////////
 588+
 589+ /**
 590+ * Get the donation amount section
 591+ *
 592+ * @param array $options
 593+ *
 594+ * Fields:
 595+ * - amount|amountRadio
 596+ * - currency_code
 597+ *
 598+ * @return string Returns an HTML string
 599+ */
 600+ protected function getFormSectionAmount( $options = array() ) {
 601+
 602+ $return = '';
 603+
 604+ $id = 'section_amount';
 605+
 606+ $headerOptions = $options;
 607+
 608+ $headerOptions['id'] = $id . '_header';
 609+
 610+ $return .= $this->getFormSectionHeaderTag( wfMsg( 'donate_interface-payment_method-' . $this->getPaymentMethod() ), $headerOptions );
 611+
 612+ $return .= Xml::openElement( 'div', array( 'id' => $id ) ); // $id
 613+
 614+ $radioOptions = array();
 615+ $radioOptions['showCardsOnCurrencyChange'] = false;
 616+
 617+ $country = !is_null( $this->getEscapedValue( 'country' ) ) ? $this->getEscapedValue( 'country' ) : '';
 618+
 619+ if ( $country == 'SG' ) {
 620+ $radioOptions['setCurrency'] = 'SGD';
 621+ }
 622+
 623+ $return .= $this->generateAmountByRadio( $radioOptions );
 624+
 625+ $return .= Xml::closeElement( 'div' ); // $id
 626+
 627+ return $return;
 628+ }
 629+
 630+ /**
 631+ * Get the personal information section
 632+ *
 633+ * @param array $options
 634+ *
 635+ * Fields:
 636+ * - fname
 637+ * - lname
 638+ * - email
 639+ * - street
 640+ * - city
 641+ * - zip
 642+ * - country
 643+ *
 644+ * @return string Returns an HTML string
 645+ */
 646+ protected function getFormSectionPersonal( $options = array() ) {
 647+
 648+ $return = '';
 649+
 650+ $id = 'section_personal';
 651+
 652+ $headerOptions = $options;
 653+
 654+ $headerOptions['id'] = $id . '_header';
 655+
 656+ $return .= $this->getFormSectionHeaderTag( wfMsg( 'donate_interface-cc-form-header-personal' ), $headerOptions );
 657+
 658+ $return .= Xml::openElement( 'div', array( 'id' => $id ) ); // $id
 659+
 660+ $return .= Xml::openElement( 'table', array( 'id' => $id . '_table' ) );
 661+
 662+ $return .= $this->getNameField();
 663+
 664+ // email
 665+ $return .= $this->getEmailField();
 666+
 667+ // street
 668+ $return .= $this->getStreetField();
 669+
 670+ // city
 671+ $return .= $this->getCityField();
 672+
 673+ // state
 674+ $return .= $this->getStateField();
 675+
 676+ // zip
 677+ $return .= $this->getZipField();
 678+
 679+ // country
 680+ $return .= $this->getCountryField();
 681+
 682+ $return .= Xml::closeElement( 'table' ); // close $id . '_table'
 683+
 684+ $return .= Xml::closeElement( 'div' ); // $id
 685+
 686+ return $return;
 687+ }
 688+
 689+ /**
 690+ * Get the payment information section
 691+ *
 692+ * @param array $options
 693+ *
 694+ * Fields:
 695+ * - rtbt
 696+ * - bt
 697+ * - dd
 698+ *
 699+ * @return string Returns an HTML string
 700+ */
 701+ protected function getFormSectionPayment( $options = array() ) {
 702+
 703+ $return = '';
 704+
 705+ $id = 'section_personal';
 706+
 707+ $headerOptions = $options;
 708+
 709+ $headerOptions['id'] = $id . '_header';
 710+
 711+ $return .= $this->getFormSectionHeaderTag( wfMsg( 'donate_interface-cc-form-header-payment' ), $headerOptions );
 712+
 713+ $return .= Xml::openElement( 'div', array( 'id' => $id ) ); // $id
 714+
 715+ $return .= Xml::openElement( 'table', array( 'id' => $id . '_table' ) );
 716+
 717+ switch ( $this->getPaymentMethod() ) {
 718+ case 'bt':
 719+ $return .= $this->getBankTransfer();
 720+ break;
 721+ case 'cc':
 722+ $return .= $this->getCreditCard();
 723+ break;
 724+ case 'dd':
 725+ $return .= $this->getDirectDebit();
 726+ break;
 727+ case 'rtbt':
 728+ $return .= $this->getRealTimeBankTransfer();
 729+ break;
 730+ default:
 731+ $return .= $this->getCreditCard();
 732+ break;
 733+ }
 734+
 735+ $return .= Xml::closeElement( 'table' ); // close $id . '_table'
 736+
 737+ $return .= Xml::closeElement( 'div' ); // $id
 738+
 739+ return $return;
 740+ }
 741+
 742+ ////////////////////////////////////////////////////////////////////////////
 743+ //
 744+ // Deprecated
 745+ //
 746+ ////////////////////////////////////////////////////////////////////////////
 747+
 748+ /**
 749+ * Generate the payment information
 750+ *
 751+ * @todo
 752+ * - a large part of this method is for debugging and may need to be removed.
 753+ */
 754+ public function generateFormPaymentInformation() {
 755+
 756+ $form = '';
 757+
 758+ // Payment debugging information
 759+ $form .= Xml::openElement( 'div', array( 'id' => 'mw-payment-information' ) );
 760+
 761+ $form .= Xml::tags( 'h2', array(), 'Payment debugging information' );
 762+
 763+ $form .= Xml::openElement( 'ul', array() ); // open div#mw-payment-information ul
 764+ $form .= Xml::tags( 'li', array(), 'payment_method: ' . $this->getPaymentMethod() );
 765+ $form .= Xml::tags( 'li', array(), 'payment_submethod: ' . $this->getPaymentSubmethod() );
 766+
 767+ if ( !is_null( $this->getEscapedValue( 'issuer_id' ) ) ) {
 768+ $form .= Xml::tags( 'li', array(), 'issuer_id: ' . $this->getEscapedValue( 'issuer_id' ) );
 769+ }
 770+
 771+ $form .= Xml::closeElement( 'ul' ); // close div#mw-payment-information ul
 772+
 773+ $form .= Xml::tags( 'h3', array(), 'Payment choices' );
 774+
 775+ $form .= Xml::tags( 'h4', array(), 'Payment method:' );
 776+
 777+ $form .= Xml::openElement( 'ul', array() ); // open div#mw-payment-information ul
 778+
 779+ // Payment methods that are not supported by this form.
 780+ $ignorePaymentMethod = array( 'cc', );
 781+
 782+ // Loop through forms to display
 783+ foreach ( $this->gateway->getPaymentMethods() as $payment_method => $payment_methodMeta ) {
 784+
 785+ if ( in_array( $payment_method, $ignorePaymentMethod ) ) {
 786+ continue;
 787+ }
 788+
 789+ $form .= Xml::openElement( 'li', array() );
 790+
 791+ $form .= Xml::tags( 'span', array(), $payment_method );
 792+
 793+ foreach ( $payment_methodMeta['types'] as $payment_submethod ) {
 794+ $form .= ' - ' . Xml::tags( 'a', array('href'=>'?form_name=TwoStepAmount&payment_method=' . $payment_method . '&payment_submethod=' . $payment_submethod), $payment_submethod );
 795+ }
 796+
 797+ $form .= Xml::closeElement( 'li' );
 798+ }
 799+
 800+ $form .= Xml::closeElement( 'ul' ); // close div#mw-payment-information ul
 801+
 802+ $form .= Xml::closeElement( 'div' ); // close div#mw-payment-information
 803+
 804+ return $form;
 805+ }
 806+
 807+ /**
 808+ * Generate the issuerId for real time bank transfer
 809+ */
 810+ public function generateFormIssuerIdDropdown() {
 811+
 812+ $form = '';
 813+ //return $form;
 814+
 815+ $payment_submethod = $this->gateway->getPaymentSubmethodMeta( $this->getPaymentSubmethod() );
 816+ if ( !isset( $payment_submethod['issuerids'] ) || empty( $payment_submethod['issuerids'] ) ) {
 817+
 818+ // No issuer_id to load
 819+ return $form;
 820+ }
 821+
 822+ $selectOptions = '';
 823+
 824+ // generate dropdown of issuer_ids
 825+ foreach ( $payment_submethod['issuerids'] as $issuer_id => $issuer_id_label ) {
 826+ $selected = ( $this->getEscapedValue( 'issuer_id' ) == $issuer_id ) ? true : false;
 827+ //$selectOptions .= Xml::option( wfMsg( 'donate_interface-rtbt-' . $issuer_id ), $issuer_id_label, $selected );
 828+ $selectOptions .= Xml::option( $issuer_id_label, $issuer_id, $selected );
 829+ }
 830+ $form .= '<tr>';
 831+ $form .= '<td class="label">' . Xml::label( wfMsg( 'donate_interface-rtbt-issuer_id' ), 'issuer_id' ) . '</td>';
 832+
 833+ $form .= '<td>';
 834+ $form .= Xml::openElement(
 835+ 'select',
 836+ array(
 837+ 'name' => 'issuer_id',
 838+ 'id' => 'issuer_id',
 839+ 'onchange' => '',
 840+ ) );
 841+ $form .= $selectOptions;
 842+ $form .= Xml::closeElement( 'select' );
 843+
 844+ $form .= '</td>';
 845+ $form .= '</tr>';
 846+
 847+ return $form;
 848+ }
 849+
 850+
 851+ /**
 852+ * Generate the first part of the form
 853+ */
 854+ public function generateFormStart() {
 855+
 856+ $form = '';
 857+
 858+ //$form .= $this->generateBannerHeader();
 859+
 860+ $form .= Xml::openElement( 'div', array( 'id' => 'mw-creditcard' ) );
 861+
 862+ // provide a place at the top of the form for displaying general messages
 863+ if ( $this->form_errors['general'] ) {
 864+ $form .= Xml::openElement( 'div', array( 'id' => 'mw-payment-general-error' ) );
 865+ if ( is_array( $this->form_errors['general'] ) ) {
 866+ foreach ( $this->form_errors['general'] as $this->form_errors_msg ) {
 867+ $form .= Xml::tags( 'p', array( 'class' => 'creditcard-error-msg' ), $this->form_errors_msg );
 868+ }
 869+ } else {
 870+ $form .= Xml::tags( 'p', array( 'class' => 'creditcard-error-msg' ), $this->form_errors_msg );
 871+ }
 872+ $form .= Xml::closeElement( 'div' );
 873+ }
 874+
 875+ // add noscript tags for javascript disabled browsers
 876+ $form .= $this->getNoScript();
 877+
 878+ $form .= $this->generateFormPaymentInformation();
 879+
 880+ // open form
 881+ $form .= Xml::openElement( 'div', array( 'id' => 'mw-creditcard-form' ) );
 882+
 883+ // Xml::element seems to convert html to htmlentities
 884+ $form .= "<p class='creditcard-error-msg'>" . $this->form_errors['retryMsg'] . "</p>";
 885+ $form .= Xml::openElement( 'form', array( 'id' => $this->getFormId(), 'name' => $this->getFormName(), 'method' => 'post', 'action' => $this->getNoCacheAction(), 'onsubmit' => '', 'autocomplete' => 'off' ) );
 886+
 887+ $form .= Xml::openElement( 'div', array( 'id' => 'left-column', 'class' => 'payment-cc-form-section' ) );
 888+ $form .= $this->generatePersonalContainer();
 889+ $form .= $this->generatePaymentContainer();
 890+ $form .= $this->generateFormSubmit();
 891+ $form .= Xml::closeElement( 'div' ); // close div#left-column
 892+
 893+ //$form .= Xml::openElement( 'div', array( 'id' => 'right-column', 'class' => 'payment-cc-form-section' ) );
 894+
 895+ return $form;
 896+ }
 897+
 898+ public function generateFormEnd() {
 899+ $form = '';
 900+ // add hidden fields
 901+ $hidden_fields = $this->getHiddenFields();
 902+ foreach ( $hidden_fields as $field => $value ) {
 903+ $form .= Html::hidden( $field, $value );
 904+ }
 905+
 906+ $form .= Xml::closeElement( 'form' );
 907+ $form .= Xml::closeElement( 'div' ); // close div#mw-creditcard-form
 908+ $form .= $this->generateDonationFooter();
 909+ $form .= Xml::closeElement( 'div' ); // div#close mw-creditcard
 910+ return $form;
 911+ }
 912+
 913+ protected function generatePersonalContainer() {
 914+ $form = '';
 915+ $form .= Xml::openElement( 'div', array( 'id' => 'payment_gateway-personal-info' ) ); ;
 916+ //$form .= Xml::tags( 'h3', array( 'class' => 'payment-cc-form-header', 'id' => 'payment-cc-form-header-personal' ), wfMsg( 'donate_interface-cc-form-header-personal' ) );
 917+ $form .= Xml::openElement( 'table', array( 'id' => 'payment-table-donor' ) );
 918+
 919+ $form .= $this->generatePersonalFields();
 920+
 921+ $form .= Xml::closeElement( 'table' ); // close table#payment-table-donor
 922+ $form .= Xml::closeElement( 'div' ); // close div#payment_gateway-personal-info
 923+
 924+ return $form;
 925+ }
 926+
 927+ protected function generatePersonalFields() {
 928+ // first name
 929+ $form = $this->getNameField();
 930+
 931+ // country
 932+ $form .= $this->getCountryField();
 933+
 934+ // street
 935+ $form .= $this->getStreetField();
 936+
 937+
 938+ // city
 939+ $form .= $this->getCityField();
 940+
 941+ // state
 942+ $form .= $this->getStateField();
 943+
 944+ // zip
 945+ $form .= $this->getZipField();
 946+
 947+ // email
 948+ $form .= $this->getEmailField();
 949+
 950+ return $form;
 951+ }
 952+
 953+ protected function generatePaymentContainer() {
 954+ $form = '';
 955+ // credit card info
 956+ $form .= Xml::openElement( 'div', array( 'id' => 'donation-payment-info' ) );
 957+ //$form .= Xml::tags( 'h3', array( 'class' => 'payment-cc-form-header', 'id' => 'payment-cc-form-header-payment' ), wfMsg( 'donate_interface-cc-form-header-payment' ) );
 958+ $form .= Xml::openElement( 'table', array( 'id' => 'donation-table-cc' ) );
 959+
 960+ $form .= $this->generatePaymentFields();
 961+
 962+ $form .= Xml::closeElement( 'table' ); // close table#payment-table-cc
 963+ $form .= Xml::closeElement( 'div' ); // close div#payment_gateway-payment-info
 964+
 965+ return $form;
 966+ }
 967+
 968+ protected function generatePaymentFields() {
 969+ // amount
 970+ $form .= $this->generateAmountByRadio();
 971+
 972+ $form .= $this->generateFormIssuerIdDropdown();
 973+ $form .= $this->generateFormDirectDebit();
 974+
 975+
 976+ return $form;
 977+ }
 978+}
Property changes on: trunk/extensions/DonationInterface/tests/resources/forms/UniversalTestForm.php
___________________________________________________________________
Added: svn:mergeinfo
1979 Merged /trunk/extensions/DonationInterface/payflowpro_gateway/forms/TwoStepAmount.php:r95445-96492
2980 Merged /branches/fundraising/extensions/DonationInterface/gateway_forms/TwoStepAmount.php:r95724-100157
Added: svn:eol-style
3981 + native
Added: svn:mime-type
4982 + text/plain
Added: svn:keywords
5983 + Author Date HeadURL Header Id Revision
Index: trunk/extensions/DonationInterface/globalcollect_gateway/forms/TwoStepAmount.php
@@ -1,977 +0,0 @@
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 - /**
28 - * The default value of section header tags.
29 - *
30 - * A value of 3 => h3
31 - *
32 - * @var integer $sectionHeaderLevel
33 - */
34 - public $sectionHeaderLevel = 3;
35 -
36 - /**
37 - * The appeal
38 - *
39 - * @var string $appeal
40 - */
41 - public $appeal = '';
42 -
43 - /**
44 - * The default appeal
45 - *
46 - */
47 - const DEFAULT_APPEAL = <<<HTML
48 - <h2 id="appeal-head"> <span class="mw-headline" id="From_Wikipedia_programmer_Brandon_Harris">From Wikipedia programmer Brandon Harris</span></h2>
49 - <div id="appeal-body" class="plainlinks">
50 - <p>I feel like I'm living the first line of my obituary.</p>
51 - <p>I don't think there will be anything else that I do in my life as important as what I do now for Wikipedia. We're not just building an encyclopedia, we're working to make people free. When we have access to free knowledge, we are better people. We understand the world is bigger than us, and we become infected with tolerance and understanding.</p>
52 - <p>Wikipedia is the 5th largest website in the world. I work at the small non-profit that keeps it on the web. We don't run ads because doing so would sacrifice our independence. The site is not and should never be a propaganda tool.</p>
53 - <p>Our work is possible because of donations from our readers. Will you help protect Wikipedia by donating $5, $10, $20 or whatever you can afford?</p>
54 - <p>I work at the Wikimedia Foundation because everything in my soul tells me it's the right thing to do. I've worked at huge tech companies, doing some job to build some crappy thing that's designed to steal money from some kid who doesn't know it. I would come home from work crushed.</p>
55 - <p>You might not know this, but the Wikimedia Foundation operates with a very small staff. Most other top-ten sites have tens of thousands of people and massive budgets. But they produce a fraction of what we pull off with sticks and wire.</p>
56 - <p>When you give to Wikipedia, you're supporting free knowledge around the world. You're not only leaving a legacy for your children and for their children, you're elevating people around the world who have access to this treasure. You're assuring that one day everyone else will too.</p>
57 - <p>Thank you,</p>
58 - <p><strong>Brandon Harris</strong><br /></p>
59 - <p>Programmer, Wikimedia Foundation</p>
60 - </div>
61 -HTML;
62 -
63 - ////////////////////////////////////////////////////////////////////////////
64 - //
65 - // Form methods
66 - //
67 - ////////////////////////////////////////////////////////////////////////////
68 -
69 - /**
70 - * Initialize the form
71 - *
72 - * This is called at the end of the constructor
73 - *
74 - */
75 - protected function init() {
76 -
77 - // Initialize the appeal
78 - $this->appeal = self::DEFAULT_APPEAL;
79 -
80 - $this->loadResources();
81 - }
82 -
83 - /**
84 - * Required method for returning the full HTML for a form.
85 - *
86 - * @return string The entire form HTML
87 - */
88 - public function getForm() {
89 -
90 - return $this->getFormPage();
91 -
92 - $form = '';
93 -
94 - $form .= $this->generateFormStart();
95 - $form .= $this->generateFormEnd();
96 - return $form;
97 - }
98 -
99 - /**
100 - * Get the form messages by type.
101 - *
102 - * Since this displays to the end user, if a key does not exist, it fails
103 - * silently and returns an empty string.
104 - *
105 - * @param string $type
106 - * @param array $options
107 - *
108 - * @todo
109 - * - Move to the parent class
110 - * - This returns error messages by paragraph tags, but it may be better to do this as a list.
111 - *
112 - * @return string Returns an HTML string
113 - */
114 - protected function getFormMessagesByType( $type, $options = array() ) {
115 -
116 - if ( isset( $options['type'] ) ) {
117 - unset( $options['type'] );
118 - }
119 -
120 - extract( $options );
121 -
122 - $defaultErrorClass = 'payment_error_message payment_error_message_' . strtolower( $type );
123 -
124 - $errorClass = isset( $errorClass ) ? $errorClass : $defaultErrorClass;
125 -
126 - $return = '';
127 -
128 - if ( isset( $this->form_errors[ $type ] ) ) {
129 -
130 - if ( is_array( $this->form_errors[ $type ] ) ) {
131 -
132 - // Loop through messages and display them as paragraphs
133 - foreach ( $this->form_errors[ $type ] as $message ) {
134 - $return .= Xml::tags( 'p', array( 'class' => $errorClass ), $message );
135 - }
136 - } else {
137 -
138 - // Display single message
139 - $return .= Xml::tags( 'p', array( 'class' => $errorClass ), $this->form_errors[ $type ] );
140 - }
141 - }
142 -
143 - return $return;
144 - }
145 -
146 - /**
147 - * Get the form messages
148 - *
149 - * @param array $options
150 - *
151 - * @return string Returns an HTML string
152 - */
153 - protected function getFormMessages( $options = array() ) {
154 -
155 - $return = '';
156 -
157 - // We want this container to exist so it can be populated with javascript messages.
158 - $return .= Xml::openElement( 'div', array( 'id' => 'payment_form_messages' ) );
159 -
160 - $return .= $this->getFormMessagesByType('general');
161 -
162 - $return .= $this->getFormMessagesByType('invalidamount');
163 -
164 - $return .= $this->getFormMessagesByType('retryMsg');
165 -
166 - $return .= Xml::closeElement( 'div' ); // payment_form_messages
167 -
168 - return $return;
169 - }
170 -
171 - /**
172 - * Get the section header tag
173 - *
174 - * @param string $section The section label
175 - * @param array $options
176 - *
177 - * @return string Returns an HTML string
178 - */
179 - protected function getFormSectionHeaderTag( $section, $options = array() ) {
180 -
181 - // Make sure $section does not get overridden.
182 - if ( isset( $options['section'] ) ) {
183 -
184 - unset( $options['section'] );
185 - }
186 -
187 - extract( $options );
188 -
189 - $headerLevel = isset( $headerLevel ) ? (integer) $headerLevel : (integer) $this->sectionHeaderLevel;
190 - $headerId = isset( $headerId ) ? (string) $headerId : '';
191 - $headerClass = isset( $headerClass ) ? (string) $headerClass : '';
192 -
193 - // Set maximum level to 6
194 - $headerLevel = ( $headerLevel > 6 ) ? 6 : $headerLevel;
195 -
196 - // Set minimum level to 2
197 - $headerLevel = ( $headerLevel < 2 ) ? 2 : $headerLevel;
198 -
199 - $headerTag = 'h' . $headerLevel;
200 -
201 - $headerOptions = array();
202 -
203 - // Add a header class
204 - if ( !empty( $headerClass ) ) {
205 - $headerOptions['class'] = $headerClass;
206 - }
207 -
208 - // Add a header id
209 - if ( !empty( $headerId ) ) {
210 - $headerOptions['id'] = $headerId;
211 - }
212 -
213 - $return = Xml::tags( $headerTag, $headerOptions, $section );
214 -
215 - return $return;
216 - }
217 -
218 - /**
219 - * Load form resources
220 - */
221 - protected function loadResources() {
222 -
223 - $this->loadValidateJs();
224 - }
225 -
226 - /**
227 - * Load extra javascript
228 - */
229 - protected function loadValidateJs() {
230 - global $wgOut;
231 - $wgOut->addModules( 'gc.form.core.validate' );
232 -
233 - $js = "\n" . '<script type="text/javascript">'
234 - . "var validatePaymentForm = {
235 - formId: '" . $this->getFormId() . "',
236 - payment_method: '" . $this->getPaymentMethod() . "',
237 - payment_submethod: '" . $this->getPaymentSubmethod() . "',
238 - }"
239 - . '</script>' . "\n";
240 - $wgOut->addHeadItem( 'loadValidateJs', $js );
241 - }
242 -
243 - ////////////////////////////////////////////////////////////////////////////
244 - //
245 - // Get and set html snippets of code for form
246 - //
247 - ////////////////////////////////////////////////////////////////////////////
248 -
249 - /**
250 - * Set the appeal
251 - *
252 - * @param string $appeal The html appeal text
253 - * @param array $options
254 - *
255 - * @return string Returns an HTML string
256 - */
257 - protected function setAppeal( $appeal, $options = array() ) {
258 -
259 - $this->appeal = $appeal;
260 - }
261 -
262 - /**
263 - * Get the appeal
264 - *
265 - * @param array $options
266 - *
267 - * @return string Returns an HTML string
268 - */
269 - protected function getAppeal( $options = array() ) {
270 -
271 - $return = '';
272 -
273 - $return .= Xml::openElement( 'div', array( 'id' => 'appeal' ) );
274 -
275 - $return .= Xml::openElement( 'div', array( 'id' => 'appeal-content' ) );
276 -
277 - $return .= $this->appeal;
278 -
279 - $return .= Xml::closeElement( 'div' ); // appeal-content
280 -
281 - $return .= Xml::closeElement( 'div' ); // appeal
282 -
283 - return $return;
284 - }
285 -
286 - /**
287 - * Generate the bank transfer component
288 - *
289 - * Nothing is being added right now.
290 - *
291 - * @param array $options
292 - *
293 - * @return string Returns an HTML string
294 - */
295 - protected function getBankTransfer( $options = array() ) {
296 -
297 - extract( $options );
298 -
299 - $return = '';
300 -
301 - return $return;
302 - }
303 -
304 - /**
305 - * Generate the credit card component
306 - *
307 - * Nothing is being added right now.
308 - *
309 - * @param array $options
310 - *
311 - * @return string Returns an HTML string
312 - */
313 - protected function getCreditCard( $options = array() ) {
314 -
315 - extract( $options );
316 -
317 - $return = '';
318 -
319 - return $return;
320 - }
321 -
322 - /**
323 - * Generate the direct debit component
324 - *
325 - * @param array $options
326 - *
327 - * @return string Returns an HTML string
328 - */
329 - protected function getDirectDebit( $options = array() ) {
330 -
331 - extract( $options );
332 -
333 - $return = '';
334 -
335 - $ignore = isset( $ignore ) ? (array) $ignore : array();
336 -
337 - if ( $this->getPaymentMethod() != 'dd' ) {
338 -
339 - // No direct debit fields need to be loaded.
340 - return $return;
341 - }
342 -
343 - $fields = array(
344 - 'account_name' => array( 'required' => true, ),
345 - 'account_number' => array( 'required' => true, ),
346 - 'authorization_id' => array( 'required' => true, ),
347 - 'bank_check_digit' => array( 'required' => true, ),
348 - 'bank_code' => array( 'required' => true, ),
349 - 'bank_name' => array( 'required' => true, ),
350 - 'branch_code' => array( 'required' => true, ),
351 - 'iban' => array( 'required' => true, ),
352 - );
353 -
354 - $country = !is_null( $this->getEscapedValue( 'country' ) ) ? $this->getEscapedValue( 'country' ) : '';
355 -
356 - if ( $country == 'AT' ) {
357 -
358 - unset( $fields['bank_check_digit'] );
359 - unset( $fields['branch_code'] );
360 - unset( $fields['iban'] );
361 - }
362 - elseif ( $country == 'BE' ) {
363 -
364 - unset( $fields['branch_code'] );
365 - unset( $fields['iban'] );
366 - }
367 - elseif ( $country == 'IT' ) {
368 -
369 - unset( $fields['iban'] );
370 - }
371 - elseif ( $country == 'NL' ) {
372 -
373 - unset( $fields['bank_check_digit'] );
374 - unset( $fields['branch_code'] );
375 - unset( $fields['iban'] );
376 - }
377 - elseif ( $country == 'ES' ) {
378 -
379 - unset( $fields['iban'] );
380 - }
381 -
382 -
383 - foreach ( $fields as $field => $meta ) {
384 -
385 - // Skip ignored fields
386 - if ( in_array( $field, $ignore ) ) {
387 -
388 - continue;
389 - }
390 -
391 - $return .= '<tr>';
392 - $return .= '<td class="label">' . Xml::label( wfMsg( 'donate_interface-dd-' . $field ), $field ) . '</td>';
393 -
394 - $return .= '<td>';
395 -
396 - $required = isset ( $meta['required'] ) ? (boolean) $meta['required'] : false ;
397 - $elementClass = '';
398 - $elementClass .= $required ? ' required ' : '' ;
399 - $elementClass = trim( $elementClass );
400 -
401 - $return .= Xml::input( $field, '', $this->getEscapedValue( $field ), array( 'class' => $elementClass, 'type' => 'text', 'maxlength' => '32', 'id' => $field ) );
402 - $return .= '</td>';
403 - $return .= '</tr>';
404 - }
405 -
406 - return $return;
407 - }
408 -
409 - /**
410 - * Get the end of the form
411 - *
412 - * This method gets the hidden fields and appends the closing form tag.
413 - *
414 - * @param array $options
415 - *
416 - * @return string Returns an HTML string
417 - */
418 - protected function getFormEnd( $options = array() ) {
419 -
420 - extract( $options );
421 -
422 - $return = '';
423 -
424 - $return .= $this->generateFormSubmit();
425 -
426 - // Add hidden fields
427 - foreach ( $this->getHiddenFields() as $field => $value ) {
428 -
429 - $return .= Html::hidden( $field, $value );
430 - }
431 -
432 - $return .= Xml::closeElement( 'form' );
433 -
434 - return $return;
435 - }
436 -
437 - /**
438 - * Get the page including form and content
439 - *
440 - * @param array $options
441 - *
442 - * @return string Returns an HTML string
443 - */
444 - protected function getFormPage( $options = array() ) {
445 -
446 - extract( $options );
447 -
448 - $return = '';
449 -
450 - $headerLevel = isset( $headerLevel ) ? (integer) $headerLevel : 3;
451 -
452 - // Tell the user they need JavaScript enabled.
453 - $return .= $this->getNoScript();
454 -
455 - // Display the form messages
456 - $return .= $this->getFormMessages( $options );
457 -
458 - $return .= Xml::openElement( 'div', array( 'id' => 'payment_form_container' ) );
459 -
460 - $return .= $this->getFormStart();
461 -
462 - $return .= $this->getCaptchaHTML();
463 -
464 - $return .= $this->getFormSectionAmount();
465 -
466 - $return .= $this->getFormSectionPersonal();
467 -
468 - $return .= $this->getFormSectionPayment();
469 -
470 - $return .= $this->getFormEnd();
471 -
472 - $return .= $this->generateDonationFooter();
473 -
474 - $return .= Xml::closeElement( 'div' ); // payment_form_container
475 -
476 - // Display the appeal
477 - $return .= $this->getAppeal( $options );
478 -
479 - return $return;
480 - }
481 -
482 - /**
483 - * Get the page including form and content
484 - *
485 - * @param array $options
486 - *
487 - * @return string Returns an HTML string
488 - */
489 - protected function generateFormSubmit( $options = array() ) {
490 -
491 - extract( $options );
492 -
493 - $return = '';
494 -
495 - // submit button
496 - $return .= Xml::openElement( 'div', array( 'id' => 'payment_gateway-form-submit' ) );
497 - $return .= Xml::openElement( 'div', array( 'id' => 'mw-donate-submit-button' ) );
498 - $return .= Xml::element( 'input', array( 'class' => 'button-plain', 'value' => wfMsg( 'donate_interface-submit-button' ), 'type' => 'submit' ) );
499 - $return .= Xml::closeElement( 'div' ); // close div#mw-donate-submit-button
500 - $return .= Xml::closeElement( 'div' ); // close div#payment_gateway-form-submit
501 -
502 - return $return;
503 - }
504 -
505 - /**
506 - * Get the start of the form
507 - *
508 - * @param array $options
509 - *
510 - * @return string Returns an HTML string
511 - */
512 - protected function getFormStart( $options = array() ) {
513 -
514 - extract( $options );
515 -
516 - $return = '';
517 -
518 - $formOptions = array(
519 - 'action' => $this->getNoCacheAction(),
520 - 'autocomplete' => 'off',
521 - 'id' => $this->getFormId(),
522 - 'method' => 'post',
523 - 'name' => $this->getFormName(),
524 - 'onsubmit' => '',
525 - );
526 -
527 - // Xml::element seems to convert html to htmlentities
528 - $return .= Xml::openElement( 'form', $formOptions );
529 -
530 - return $return;
531 - }
532 -
533 - /**
534 - * Generate the bank transfer component
535 - *
536 - * Nothing is being added right now.
537 - *
538 - * @param array $options
539 - *
540 - * @return string Returns an HTML string
541 - */
542 - protected function getRealTimeBankTransfer( $options = array() ) {
543 -
544 - extract( $options );
545 -
546 - $return = '';
547 -
548 - $payment_submethod = $this->gateway->getPaymentSubmethodMeta( $this->getPaymentSubmethod() );
549 - if ( !isset( $payment_submethod['issuerids'] ) || empty( $payment_submethod['issuerids'] ) ) {
550 -
551 - // No issuer_id to load
552 - return $return;
553 - }
554 -
555 - $selectOptions = '';
556 -
557 - // generate dropdown of issuer_ids
558 - foreach ( $payment_submethod['issuerids'] as $issuer_id => $issuer_id_label ) {
559 - $selected = ( $this->getEscapedValue( 'issuer_id' ) == $issuer_id ) ? true : false;
560 - //$selectOptions .= Xml::option( wfMsg( 'donate_interface-rtbt-' . $issuer_id ), $issuer_id_label, $selected );
561 - $selectOptions .= Xml::option( $issuer_id_label, $issuer_id, $selected );
562 - }
563 - $return .= '<tr>';
564 - $return .= '<td class="label">' . Xml::label( wfMsg( 'donate_interface-rtbt-issuer_id' ), 'issuer_id' ) . '</td>';
565 -
566 - $return .= '<td>';
567 - $return .= Xml::openElement(
568 - 'select',
569 - array(
570 - 'name' => 'issuer_id',
571 - 'id' => 'issuer_id',
572 - 'onchange' => '',
573 - ) );
574 - $return .= $selectOptions;
575 - $return .= Xml::closeElement( 'select' );
576 -
577 - $return .= '</td>';
578 - $return .= '</tr>';
579 -
580 - return $return;
581 - }
582 -
583 - ////////////////////////////////////////////////////////////////////////////
584 - //
585 - // Form sections
586 - //
587 - ////////////////////////////////////////////////////////////////////////////
588 -
589 - /**
590 - * Get the donation amount section
591 - *
592 - * @param array $options
593 - *
594 - * Fields:
595 - * - amount|amountRadio
596 - * - currency_code
597 - *
598 - * @return string Returns an HTML string
599 - */
600 - protected function getFormSectionAmount( $options = array() ) {
601 -
602 - $return = '';
603 -
604 - $id = 'section_amount';
605 -
606 - $headerOptions = $options;
607 -
608 - $headerOptions['id'] = $id . '_header';
609 -
610 - $return .= $this->getFormSectionHeaderTag( wfMsg( 'donate_interface-payment_method-' . $this->getPaymentMethod() ), $headerOptions );
611 -
612 - $return .= Xml::openElement( 'div', array( 'id' => $id ) ); // $id
613 -
614 - $radioOptions = array();
615 - $radioOptions['showCardsOnCurrencyChange'] = false;
616 -
617 - $country = !is_null( $this->getEscapedValue( 'country' ) ) ? $this->getEscapedValue( 'country' ) : '';
618 -
619 - if ( $country == 'SG' ) {
620 - $radioOptions['setCurrency'] = 'SGD';
621 - }
622 -
623 - $return .= $this->generateAmountByRadio( $radioOptions );
624 -
625 - $return .= Xml::closeElement( 'div' ); // $id
626 -
627 - return $return;
628 - }
629 -
630 - /**
631 - * Get the personal information section
632 - *
633 - * @param array $options
634 - *
635 - * Fields:
636 - * - fname
637 - * - lname
638 - * - email
639 - * - street
640 - * - city
641 - * - zip
642 - * - country
643 - *
644 - * @return string Returns an HTML string
645 - */
646 - protected function getFormSectionPersonal( $options = array() ) {
647 -
648 - $return = '';
649 -
650 - $id = 'section_personal';
651 -
652 - $headerOptions = $options;
653 -
654 - $headerOptions['id'] = $id . '_header';
655 -
656 - $return .= $this->getFormSectionHeaderTag( wfMsg( 'donate_interface-cc-form-header-personal' ), $headerOptions );
657 -
658 - $return .= Xml::openElement( 'div', array( 'id' => $id ) ); // $id
659 -
660 - $return .= Xml::openElement( 'table', array( 'id' => $id . '_table' ) );
661 -
662 - $return .= $this->getNameField();
663 -
664 - // email
665 - $return .= $this->getEmailField();
666 -
667 - // street
668 - $return .= $this->getStreetField();
669 -
670 - // city
671 - $return .= $this->getCityField();
672 -
673 - // state
674 - $return .= $this->getStateField();
675 -
676 - // zip
677 - $return .= $this->getZipField();
678 -
679 - // country
680 - $return .= $this->getCountryField();
681 -
682 - $return .= Xml::closeElement( 'table' ); // close $id . '_table'
683 -
684 - $return .= Xml::closeElement( 'div' ); // $id
685 -
686 - return $return;
687 - }
688 -
689 - /**
690 - * Get the payment information section
691 - *
692 - * @param array $options
693 - *
694 - * Fields:
695 - * - rtbt
696 - * - bt
697 - * - dd
698 - *
699 - * @return string Returns an HTML string
700 - */
701 - protected function getFormSectionPayment( $options = array() ) {
702 -
703 - $return = '';
704 -
705 - $id = 'section_personal';
706 -
707 - $headerOptions = $options;
708 -
709 - $headerOptions['id'] = $id . '_header';
710 -
711 - $return .= $this->getFormSectionHeaderTag( wfMsg( 'donate_interface-cc-form-header-payment' ), $headerOptions );
712 -
713 - $return .= Xml::openElement( 'div', array( 'id' => $id ) ); // $id
714 -
715 - $return .= Xml::openElement( 'table', array( 'id' => $id . '_table' ) );
716 -
717 - switch ( $this->getPaymentMethod() ) {
718 - case 'bt':
719 - $return .= $this->getBankTransfer();
720 - break;
721 - case 'cc':
722 - $return .= $this->getCreditCard();
723 - break;
724 - case 'dd':
725 - $return .= $this->getDirectDebit();
726 - break;
727 - case 'rtbt':
728 - $return .= $this->getRealTimeBankTransfer();
729 - break;
730 - default:
731 - $return .= $this->getCreditCard();
732 - break;
733 - }
734 -
735 - $return .= Xml::closeElement( 'table' ); // close $id . '_table'
736 -
737 - $return .= Xml::closeElement( 'div' ); // $id
738 -
739 - return $return;
740 - }
741 -
742 - ////////////////////////////////////////////////////////////////////////////
743 - //
744 - // Deprecated
745 - //
746 - ////////////////////////////////////////////////////////////////////////////
747 -
748 - /**
749 - * Generate the payment information
750 - *
751 - * @todo
752 - * - a large part of this method is for debugging and may need to be removed.
753 - */
754 - public function generateFormPaymentInformation() {
755 -
756 - $form = '';
757 -
758 - // Payment debugging information
759 - $form .= Xml::openElement( 'div', array( 'id' => 'mw-payment-information' ) );
760 -
761 - $form .= Xml::tags( 'h2', array(), 'Payment debugging information' );
762 -
763 - $form .= Xml::openElement( 'ul', array() ); // open div#mw-payment-information ul
764 - $form .= Xml::tags( 'li', array(), 'payment_method: ' . $this->getPaymentMethod() );
765 - $form .= Xml::tags( 'li', array(), 'payment_submethod: ' . $this->getPaymentSubmethod() );
766 -
767 - if ( !is_null( $this->getEscapedValue( 'issuer_id' ) ) ) {
768 - $form .= Xml::tags( 'li', array(), 'issuer_id: ' . $this->getEscapedValue( 'issuer_id' ) );
769 - }
770 -
771 - $form .= Xml::closeElement( 'ul' ); // close div#mw-payment-information ul
772 -
773 - $form .= Xml::tags( 'h3', array(), 'Payment choices' );
774 -
775 - $form .= Xml::tags( 'h4', array(), 'Payment method:' );
776 -
777 - $form .= Xml::openElement( 'ul', array() ); // open div#mw-payment-information ul
778 -
779 - // Payment methods that are not supported by this form.
780 - $ignorePaymentMethod = array( 'cc', );
781 -
782 - // Loop through forms to display
783 - foreach ( $this->gateway->getPaymentMethods() as $payment_method => $payment_methodMeta ) {
784 -
785 - if ( in_array( $payment_method, $ignorePaymentMethod ) ) {
786 - continue;
787 - }
788 -
789 - $form .= Xml::openElement( 'li', array() );
790 -
791 - $form .= Xml::tags( 'span', array(), $payment_method );
792 -
793 - foreach ( $payment_methodMeta['types'] as $payment_submethod ) {
794 - $form .= ' - ' . Xml::tags( 'a', array('href'=>'?form_name=TwoStepAmount&payment_method=' . $payment_method . '&payment_submethod=' . $payment_submethod), $payment_submethod );
795 - }
796 -
797 - $form .= Xml::closeElement( 'li' );
798 - }
799 -
800 - $form .= Xml::closeElement( 'ul' ); // close div#mw-payment-information ul
801 -
802 - $form .= Xml::closeElement( 'div' ); // close div#mw-payment-information
803 -
804 - return $form;
805 - }
806 -
807 - /**
808 - * Generate the issuerId for real time bank transfer
809 - */
810 - public function generateFormIssuerIdDropdown() {
811 -
812 - $form = '';
813 - //return $form;
814 -
815 - $payment_submethod = $this->gateway->getPaymentSubmethodMeta( $this->getPaymentSubmethod() );
816 - if ( !isset( $payment_submethod['issuerids'] ) || empty( $payment_submethod['issuerids'] ) ) {
817 -
818 - // No issuer_id to load
819 - return $form;
820 - }
821 -
822 - $selectOptions = '';
823 -
824 - // generate dropdown of issuer_ids
825 - foreach ( $payment_submethod['issuerids'] as $issuer_id => $issuer_id_label ) {
826 - $selected = ( $this->getEscapedValue( 'issuer_id' ) == $issuer_id ) ? true : false;
827 - //$selectOptions .= Xml::option( wfMsg( 'donate_interface-rtbt-' . $issuer_id ), $issuer_id_label, $selected );
828 - $selectOptions .= Xml::option( $issuer_id_label, $issuer_id, $selected );
829 - }
830 - $form .= '<tr>';
831 - $form .= '<td class="label">' . Xml::label( wfMsg( 'donate_interface-rtbt-issuer_id' ), 'issuer_id' ) . '</td>';
832 -
833 - $form .= '<td>';
834 - $form .= Xml::openElement(
835 - 'select',
836 - array(
837 - 'name' => 'issuer_id',
838 - 'id' => 'issuer_id',
839 - 'onchange' => '',
840 - ) );
841 - $form .= $selectOptions;
842 - $form .= Xml::closeElement( 'select' );
843 -
844 - $form .= '</td>';
845 - $form .= '</tr>';
846 -
847 - return $form;
848 - }
849 -
850 -
851 - /**
852 - * Generate the first part of the form
853 - */
854 - public function generateFormStart() {
855 -
856 - $form = '';
857 -
858 - //$form .= $this->generateBannerHeader();
859 -
860 - $form .= Xml::openElement( 'div', array( 'id' => 'mw-creditcard' ) );
861 -
862 - // provide a place at the top of the form for displaying general messages
863 - if ( $this->form_errors['general'] ) {
864 - $form .= Xml::openElement( 'div', array( 'id' => 'mw-payment-general-error' ) );
865 - if ( is_array( $this->form_errors['general'] ) ) {
866 - foreach ( $this->form_errors['general'] as $this->form_errors_msg ) {
867 - $form .= Xml::tags( 'p', array( 'class' => 'creditcard-error-msg' ), $this->form_errors_msg );
868 - }
869 - } else {
870 - $form .= Xml::tags( 'p', array( 'class' => 'creditcard-error-msg' ), $this->form_errors_msg );
871 - }
872 - $form .= Xml::closeElement( 'div' );
873 - }
874 -
875 - // add noscript tags for javascript disabled browsers
876 - $form .= $this->getNoScript();
877 -
878 - $form .= $this->generateFormPaymentInformation();
879 -
880 - // open form
881 - $form .= Xml::openElement( 'div', array( 'id' => 'mw-creditcard-form' ) );
882 -
883 - // Xml::element seems to convert html to htmlentities
884 - $form .= "<p class='creditcard-error-msg'>" . $this->form_errors['retryMsg'] . "</p>";
885 - $form .= Xml::openElement( 'form', array( 'id' => $this->getFormId(), 'name' => $this->getFormName(), 'method' => 'post', 'action' => $this->getNoCacheAction(), 'onsubmit' => '', 'autocomplete' => 'off' ) );
886 -
887 - $form .= Xml::openElement( 'div', array( 'id' => 'left-column', 'class' => 'payment-cc-form-section' ) );
888 - $form .= $this->generatePersonalContainer();
889 - $form .= $this->generatePaymentContainer();
890 - $form .= $this->generateFormSubmit();
891 - $form .= Xml::closeElement( 'div' ); // close div#left-column
892 -
893 - //$form .= Xml::openElement( 'div', array( 'id' => 'right-column', 'class' => 'payment-cc-form-section' ) );
894 -
895 - return $form;
896 - }
897 -
898 - public function generateFormEnd() {
899 - $form = '';
900 - // add hidden fields
901 - $hidden_fields = $this->getHiddenFields();
902 - foreach ( $hidden_fields as $field => $value ) {
903 - $form .= Html::hidden( $field, $value );
904 - }
905 -
906 - $form .= Xml::closeElement( 'form' );
907 - $form .= Xml::closeElement( 'div' ); // close div#mw-creditcard-form
908 - $form .= $this->generateDonationFooter();
909 - $form .= Xml::closeElement( 'div' ); // div#close mw-creditcard
910 - return $form;
911 - }
912 -
913 - protected function generatePersonalContainer() {
914 - $form = '';
915 - $form .= Xml::openElement( 'div', array( 'id' => 'payment_gateway-personal-info' ) ); ;
916 - //$form .= Xml::tags( 'h3', array( 'class' => 'payment-cc-form-header', 'id' => 'payment-cc-form-header-personal' ), wfMsg( 'donate_interface-cc-form-header-personal' ) );
917 - $form .= Xml::openElement( 'table', array( 'id' => 'payment-table-donor' ) );
918 -
919 - $form .= $this->generatePersonalFields();
920 -
921 - $form .= Xml::closeElement( 'table' ); // close table#payment-table-donor
922 - $form .= Xml::closeElement( 'div' ); // close div#payment_gateway-personal-info
923 -
924 - return $form;
925 - }
926 -
927 - protected function generatePersonalFields() {
928 - // first name
929 - $form = $this->getNameField();
930 -
931 - // country
932 - $form .= $this->getCountryField();
933 -
934 - // street
935 - $form .= $this->getStreetField();
936 -
937 -
938 - // city
939 - $form .= $this->getCityField();
940 -
941 - // state
942 - $form .= $this->getStateField();
943 -
944 - // zip
945 - $form .= $this->getZipField();
946 -
947 - // email
948 - $form .= $this->getEmailField();
949 -
950 - return $form;
951 - }
952 -
953 - protected function generatePaymentContainer() {
954 - $form = '';
955 - // credit card info
956 - $form .= Xml::openElement( 'div', array( 'id' => 'donation-payment-info' ) );
957 - //$form .= Xml::tags( 'h3', array( 'class' => 'payment-cc-form-header', 'id' => 'payment-cc-form-header-payment' ), wfMsg( 'donate_interface-cc-form-header-payment' ) );
958 - $form .= Xml::openElement( 'table', array( 'id' => 'donation-table-cc' ) );
959 -
960 - $form .= $this->generatePaymentFields();
961 -
962 - $form .= Xml::closeElement( 'table' ); // close table#payment-table-cc
963 - $form .= Xml::closeElement( 'div' ); // close div#payment_gateway-payment-info
964 -
965 - return $form;
966 - }
967 -
968 - protected function generatePaymentFields() {
969 - // amount
970 - $form .= $this->generateAmountByRadio();
971 -
972 - $form .= $this->generateFormIssuerIdDropdown();
973 - $form .= $this->generateFormDirectDebit();
974 -
975 -
976 - return $form;
977 - }
978 -}

Follow-up revisions

RevisionCommit summaryAuthorDate
r112287MFT r101785, r105938, r105941, r105953, r106109, r106158, r106259, r106366, r...khorn01:29, 24 February 2012

Status & tagging log