r100411 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100410‎ | r100411 | r100412 >
Date:04:52, 21 October 2011
Author:jpostlethwaite
Status:deferred (Comments)
Tags:fundraising 
Comment:
Removed BANK_TRANSFER as a transaction. Set it as a transaction type. Added transaction groups that include transaction types. Also added real time bank transfer payment method.
Modified paths:
  • /trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php (modified) (history)
  • /trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect_gateway.body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php
@@ -80,57 +80,13 @@
8181 *
8282 */
8383 public function defineTransactions() {
 84+
 85+ // Define the transaction types and groups
 86+ $this->defineTransactionGroups();
 87+ $this->defineTransactionTypes();
 88+
8489 $this->transactions = array( );
8590
86 - $this->transactions['BANK_TRANSFER'] = array(
87 - 'request' => array(
88 - 'REQUEST' => array(
89 - 'ACTION',
90 - 'META' => array(
91 - 'MERCHANTID',
92 - // 'IPADDRESS',
93 - 'VERSION'
94 - ),
95 - 'PARAMS' => array(
96 - 'ORDER' => array(
97 - 'ORDERID',
98 - 'AMOUNT',
99 - 'CURRENCYCODE',
100 - 'LANGUAGECODE',
101 - 'COUNTRYCODE',
102 - 'MERCHANTREFERENCE'
103 - ),
104 - 'PAYMENT' => array(
105 - 'PAYMENTPRODUCTID',
106 - 'AMOUNT',
107 - 'CURRENCYCODE',
108 - 'LANGUAGECODE',
109 - 'COUNTRYCODE',
110 - 'HOSTEDINDICATOR',
111 - 'RETURNURL',
112 -// 'INVOICENUMBER',
113 -// 'CUSTOMERBANKNAME',
114 -// 'CUSTOMERACCOUNTHOLDERNAME',
115 -// 'CUSTOMERBANKACCOUNT',
116 -// 'CUSTOMERBANKCITY',
117 - 'FIRSTNAME',
118 - 'SURNAME',
119 - 'STREET',
120 - 'CITY',
121 - 'STATE',
122 - 'ZIP',
123 - 'EMAIL',
124 - )
125 - )
126 - )
127 - ),
128 - 'values' => array(
129 - 'ACTION' => 'INSERT_ORDERWITHPAYMENT',
130 - 'HOSTEDINDICATOR' => '1',
131 - 'PAYMENTPRODUCTID' => '11',
132 - ),
133 - );
134 -
13591 $this->transactions['INSERT_ORDERWITHPAYMENT'] = array(
13692 'request' => array(
13793 'REQUEST' => array(
@@ -228,8 +184,159 @@
229185 )
230186 );
231187 }
 188+
 189+ /**
 190+ * Define transaction groups
 191+ *
 192+ * At some point, we are going to need methods to get this information to display available forms
 193+ *
 194+ * @todo
 195+ * - This is not in use. This is a map to @see GlobalCollectAdapter::defineTransactionTypes()
 196+ *
 197+ */
 198+ private function defineTransactionGroups() {
 199+
 200+ $this->transaction_groups = array();
 201+
 202+ $this->transaction_groups['rtbt'] = array(
 203+ 'label' => 'Real time bank transfer',
 204+ 'types' => array( 'rtbt_ideal', 'rtbt_eps', 'rtbt_sofortuberweisung', 'rtbt_nordea_sweeden', 'rtbt_enets', ),
 205+ );
 206+
 207+ $this->transaction_groups['bt'] = array(
 208+ 'label' => 'Bank transfer',
 209+ 'types' => array( 'bt', ),
 210+ 'validation' => array( 'creditCard' => false, )
 211+ //'forms' => array( 'Gateway_Form_TwoStepAmount', ),
 212+ );
 213+ }
232214
233215 /**
 216+ * Define transaction types
 217+ *
 218+ */
 219+ private function defineTransactionTypes() {
 220+
 221+ $this->transaction_types = array();
 222+
 223+ /*
 224+ * Bank transfers
 225+ */
 226+
 227+ // Bank Transfer
 228+ $this->transaction_types['bt'] = array(
 229+ 'paymentproductid' => 11,
 230+ 'label' => 'Bank Transfer',
 231+ 'group' => 'bt',
 232+ 'validation' => array( 'creditCard' => false, ),
 233+ );
 234+
 235+ /*
 236+ * Real time bank transfers
 237+ */
 238+
 239+ // Nordea (Sweeden)
 240+ $this->transaction_types['rtbt_nordea_sweeden'] = array(
 241+ 'paymentproductid' => 805,
 242+ 'label' => 'Nordea (Sweeden)',
 243+ 'group' => 'rtbt',
 244+ 'validation' => array( 'creditCard' => false, ),
 245+ );
 246+
 247+ // Ideal
 248+ $this->transaction_types['rtbt_ideal'] = array(
 249+ 'paymentproductid' => 809,
 250+ 'label' => 'Ideal',
 251+ 'group' => 'rtbt',
 252+ 'validation' => array( 'creditCard' => false, ),
 253+ );
 254+
 255+ // eNETS
 256+ $this->transaction_types['rtbt_enets'] = array(
 257+ 'paymentproductid' => 810,
 258+ 'label' => 'eNETS',
 259+ 'group' => 'rtbt',
 260+ 'validation' => array( 'creditCard' => false, ),
 261+ );
 262+
 263+ // Sofortuberweisung/DIRECTebanking
 264+ $this->transaction_types['rtbt_sofortuberweisung'] = array(
 265+ 'paymentproductid' => 836,
 266+ 'label' => 'Sofortuberweisung/DIRECTebanking',
 267+ 'group' => 'rtbt',
 268+ 'validation' => array( 'creditCard' => false, ),
 269+ );
 270+
 271+ // eps Online-Überweisung
 272+ $this->transaction_types['rtbt_eps'] = array(
 273+ 'paymentproductid' => 856,
 274+ 'label' => 'eps Online-Überweisung',
 275+ 'group' => 'rtbt',
 276+ 'validation' => array( 'creditCard' => false, ),
 277+ 'issuerids' => array(
 278+ 824 => 'Bankhaus Spängler',
 279+ 825 => 'Hypo Tirol Bank',
 280+ 822 => 'NÖ HYPO',
 281+ 823 => 'Voralberger HYPO',
 282+ 828 => 'P.S.K.',
 283+ 829 => 'Easy',
 284+ 826 => 'Erste Bank und Sparkassen',
 285+ 827 => 'BAWAG',
 286+ 820 => 'Raifeissen',
 287+ 821 => 'Volksbanken Gruppe',
 288+ 831 => 'Sparda-Bank',
 289+ )
 290+ );
 291+ }
 292+
 293+ /**
 294+ * Get a transaction group meta
 295+ *
 296+ * @param string $group Groups contain transaction types
 297+ */
 298+ public function getTransactionGroupMeta( $group ) {
 299+
 300+ if ( isset( $this->transaction_groups[ $group ] ) ) {
 301+
 302+ return $this->transaction_groups[ $group ];
 303+ }
 304+ else {
 305+ $message = 'The transaction group [ ' . $group . ' ] was not found.';
 306+ throw new Exception( $message );
 307+ }
 308+ }
 309+
 310+ /**
 311+ * Get a transaction type meta
 312+ *
 313+ * @param string $transactionType Transaction types are mapped to paymentproductid
 314+ */
 315+ public function getTransactionTypeMeta( $transactionType, $options = array() ) {
 316+
 317+ extract( $options );
 318+
 319+ $log = isset( $log ) ? (boolean) $log : false ;
 320+
 321+ if ( isset( $this->transaction_types[ $transactionType ] ) ) {
 322+
 323+ if ( $log ) {
 324+ $this->log( 'Getting transaction type: ' . ( string ) $transactionType );
 325+ }
 326+
 327+ // Ensure that the validation index is set.
 328+ if ( !isset( $this->transaction_types[ $transactionType ]['validation'] ) ) {
 329+ $this->transaction_types[ $transactionType ]['validation'] = array();
 330+ }
 331+
 332+ return $this->transaction_types[ $transactionType ];
 333+ }
 334+ else {
 335+ $message = 'The transaction type [ ' . $transactionType . ' ] was not found.';
 336+ throw new Exception( $message );
 337+ }
 338+ }
 339+
 340+ /**
234341 * Take the entire response string, and strip everything we don't care about.
235342 * For instance: If it's XML, we only want correctly-formatted XML. Headers must be killed off.
236343 * return a string.
@@ -416,12 +523,49 @@
417524 * @param string $type request|response
418525 *
419526 * @todo
420 - * - This still needs to be deployed. This will alter the paymentproductid.
 527+ * - ISSUERID will need to provide a dropdown for rtbt_ideal and rtbt_ideal.
421528 */
422529 protected function stage_transaction_type( $type = 'request' ) {
423530
424 - //$this->postdata['transaction_type'] = $this->currentTransaction();
425 - //$this->var_map['PAYMENTPRODUCTID'] = 0;
 531+ $transaction_type = array_key_exists( 'transaction_type', $this->postdata ) ? $this->postdata['transaction_type']: false;
 532+
 533+ // These will be grouped and ordred by payment product id
 534+ switch ( $transaction_type ) {
 535+
 536+ /* Bank transfer */
 537+ case 'bt':
 538+ $this->postdata['payment_product'] = 11;
 539+ $this->var_map['PAYMENTPRODUCTID'] = 'payment_product';
 540+ break;
 541+
 542+ /* Real time bank transfer */
 543+ case 'rtbt_nordea_sweeden':
 544+ $this->postdata['payment_product'] = 805;
 545+ $this->var_map['PAYMENTPRODUCTID'] = 'payment_product';
 546+ break;
 547+
 548+ case 'rtbt_ideal':
 549+ $this->postdata['payment_product'] = 809;
 550+ $this->var_map['PAYMENTPRODUCTID'] = 'payment_product';
 551+ //$this->var_map['ISSUERID'] = 'issuer';
 552+ break;
 553+
 554+ case 'rtbt_enets':
 555+ $this->postdata['payment_product'] = 810;
 556+ $this->var_map['PAYMENTPRODUCTID'] = 'payment_product';
 557+ break;
 558+
 559+ case 'rtbt_sofortuberweisung':
 560+ $this->postdata['payment_product'] = 836;
 561+ $this->var_map['PAYMENTPRODUCTID'] = 'payment_product';
 562+ break;
 563+
 564+ case 'rtbt_eps':
 565+ $this->postdata['payment_product'] = 856;
 566+ $this->var_map['PAYMENTPRODUCTID'] = 'payment_product';
 567+ //$this->var_map['ISSUERID'] = 'issuer';
 568+ break;
 569+ }
426570 }
427571
428572 /**
Index: trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect_gateway.body.php
@@ -1,5 +1,25 @@
22 <?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+ */
319
 20+/**
 21+ * GlobalCollectGateway
 22+ *
 23+ */
424 class GlobalCollectGateway extends GatewayForm {
525
626 /**
@@ -65,47 +85,24 @@
6686 //so stop it.
6787 $data = $this->adapter->getDisplayData();
6888
69 - /*
70 - * The $transactionType should default to false.
71 - *
72 - * This is being introduced after INSERT_ORDERWITHPAYMENT was built.
73 - * Until all INSERT_ORDERWITHPAYMENT can be set in the proper forms, it
74 - * will be set as the default.
75 - */
76 - $transactionType = false;
77 - $transactionType = ( isset( $data['transaction_type'] ) && !empty( $data['transaction_type'] ) ) ? $data['transaction_type'] : 'INSERT_ORDERWITHPAYMENT';
78 -
79 - $this->adapter->log( '$transactionType: Default is set to: INSERT_ORDERWITHPAYMENT, this is a temporary hack for backwards compatibility.' );
80 - $this->adapter->log( 'Setting transaction type: ' . ( string ) $data['transaction_type'] );
81 -
82 -
8389 // dispatch forms/handling
8490 if ( $this->adapter->checkTokens() ) {
8591 if ( $this->adapter->posted && $data['payment_method'] == 'processed' ) {
8692 // The form was submitted and the payment method has been set
8793 $this->adapter->log( "Form posted and payment method set." );
8894
 95+ /*
 96+ * The $transactionType should default to false.
 97+ *
 98+ * An invalid $transactionType will cause an error.
 99+ */
 100+ $transactionType = ( isset( $data['transaction_type'] ) && !empty( $data['transaction_type'] ) ) ? $data['transaction_type'] : false;
 101+
 102+ $transactionTypeMeta = $this->adapter->getTransactionTypeMeta( $transactionType, array( 'log' => true, ) );
 103+
89104 // Check form for errors
 105+ $form_errors = $this->validateForm( $data, $this->errors, $transactionTypeMeta['validation'] );
90106
91 - $options = array( );
92 - switch ( $transactionType ) {
93 -
94 - case 'BANK_TRANSFER':
95 - $options['creditCard'] = false;
96 - break;
97 -
98 - case 'INSERT_ORDERWITHPAYMENT':
99 - $options['creditCard'] = false;
100 - break;
101 -
102 - default:
103 - $options['creditCard'] = false;
104 - }
105 -
106 - $form_errors = $this->validateForm( $data, $this->errors, $options );
107 - unset( $options );
108 -
109 - //$form_errors = $this->fnValidateForm( $data, $this->errors );
110107 // If there were errors, redisplay form, otherwise proceed to next step
111108 if ( $form_errors ) {
112109
@@ -113,20 +110,14 @@
114111 } else { // The submitted form data is valid, so process it
115112 // allow any external validators to have their way with the data
116113 // Execute the proper transaction code:
117 - switch ( $transactionType ) {
118114
119 - case 'BANK_TRANSFER':
120 - $this->executeBankTransfer();
121 - break;
 115+ $result = $this->adapter->do_transaction( 'INSERT_ORDERWITHPAYMENT' );
 116+
 117+ $this->displayResultsForDebug( $result );
122118
123 - case 'INSERT_ORDERWITHPAYMENT':
124 - $this->executeInsertOrderWithPayment();
125 - break;
 119+ if ( $transactionType == 'credit' ) {
126120
127 - default:
128 -
129 - $message = 'The transaction type [ ' . $transactionType . ' ] was not found.';
130 - throw new Exception( $message );
 121+ $this->executeiFrameForCreditCard();
131122 }
132123
133124
@@ -135,7 +126,7 @@
136127 } else {
137128 // Display form for the first time
138129 $oid = $wgRequest->getText( 'order_id' );
139 - if ( $oid && !empty( $oid ) ) {
 130+ if ( $oid ) {
140131 $wgOut->addHTML( "<pre>CAME BACK FROM SOMETHING.</pre>" );
141132 $result = $this->adapter->do_transaction( 'GET_ORDERSTATUS' );
142133 $this->displayResultsForDebug( $result );
@@ -153,31 +144,12 @@
154145 }
155146
156147 /**
157 - * Execute BANK_TRANSFER
 148+ * Execute execute iFrame for credit card
158149 */
159 - public function executeBankTransfer() {
 150+ public function executeiFrameForCreditCard() {
160151
161 - //global $wgOut;
162 -
163 - $result = $this->adapter->do_transaction( 'BANK_TRANSFER' );
164 - $this->adapter->addDonorDataToSession();
165 -
166 - $this->displayResultsForDebug( $result );
167 - }
168 -
169 - /**
170 - * Execute INSERT_ORDERWITHPAYMENT
171 - */
172 - public function executeInsertOrderWithPayment() {
173 -
174152 global $wgOut;
175153
176 - $result = $this->adapter->do_transaction( 'INSERT_ORDERWITHPAYMENT' );
177 - $this->adapter->addDonorDataToSession();
178 - //$result = $this->adapter->do_transaction( 'TEST_CONNECTION' );
179 -
180 - $this->displayResultsForDebug( $result );
181 -
182154 if ( !empty( $result['data'] ) ) {
183155
184156 if ( array_key_exists( 'FORMACTION', $result['data'] ) ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r100643Commenting out parts of r100462, r100461, r100411, in order to get CC in Glob...khorn20:07, 24 October 2011
r100648Fixed the issues with credit cards for r100643.jpostlethwaite21:32, 24 October 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r100408Documentation cleanup. Added public declarations to methods.jpostlethwaite04:19, 21 October 2011

Comments

#Comment by Khorn (WMF) (talk | contribs)   20:10, 24 October 2011

Parts of this broke CC in GlobalCollect. Those parts were commented out in r100643. Please fix asap.

#Comment by Jpostlethwaite (talk | contribs)   21:35, 24 October 2011

Fixed in r100648.

#Comment by Khorn (WMF) (talk | contribs)   02:20, 27 October 2011

Cool. At this point, all of the things I would have had more comments about (mostly repeating code type things), have been taken care of in later revisions.

Status & tagging log