Index: trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php |
— | — | @@ -80,57 +80,13 @@ |
81 | 81 | * |
82 | 82 | */ |
83 | 83 | public function defineTransactions() { |
| 84 | + |
| 85 | + // Define the transaction types and groups |
| 86 | + $this->defineTransactionGroups(); |
| 87 | + $this->defineTransactionTypes(); |
| 88 | + |
84 | 89 | $this->transactions = array( ); |
85 | 90 | |
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 | | - |
135 | 91 | $this->transactions['INSERT_ORDERWITHPAYMENT'] = array( |
136 | 92 | 'request' => array( |
137 | 93 | 'REQUEST' => array( |
— | — | @@ -228,8 +184,159 @@ |
229 | 185 | ) |
230 | 186 | ); |
231 | 187 | } |
| 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 | + } |
232 | 214 | |
233 | 215 | /** |
| 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 | + /** |
234 | 341 | * Take the entire response string, and strip everything we don't care about. |
235 | 342 | * For instance: If it's XML, we only want correctly-formatted XML. Headers must be killed off. |
236 | 343 | * return a string. |
— | — | @@ -416,12 +523,49 @@ |
417 | 524 | * @param string $type request|response |
418 | 525 | * |
419 | 526 | * @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. |
421 | 528 | */ |
422 | 529 | protected function stage_transaction_type( $type = 'request' ) { |
423 | 530 | |
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 | + } |
426 | 570 | } |
427 | 571 | |
428 | 572 | /** |
Index: trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect_gateway.body.php |
— | — | @@ -1,5 +1,25 @@ |
2 | 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 | + */ |
3 | 19 | |
| 20 | +/** |
| 21 | + * GlobalCollectGateway |
| 22 | + * |
| 23 | + */ |
4 | 24 | class GlobalCollectGateway extends GatewayForm { |
5 | 25 | |
6 | 26 | /** |
— | — | @@ -65,47 +85,24 @@ |
66 | 86 | //so stop it. |
67 | 87 | $data = $this->adapter->getDisplayData(); |
68 | 88 | |
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 | | - |
83 | 89 | // dispatch forms/handling |
84 | 90 | if ( $this->adapter->checkTokens() ) { |
85 | 91 | if ( $this->adapter->posted && $data['payment_method'] == 'processed' ) { |
86 | 92 | // The form was submitted and the payment method has been set |
87 | 93 | $this->adapter->log( "Form posted and payment method set." ); |
88 | 94 | |
| 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 | + |
89 | 104 | // Check form for errors |
| 105 | + $form_errors = $this->validateForm( $data, $this->errors, $transactionTypeMeta['validation'] ); |
90 | 106 | |
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 ); |
110 | 107 | // If there were errors, redisplay form, otherwise proceed to next step |
111 | 108 | if ( $form_errors ) { |
112 | 109 | |
— | — | @@ -113,20 +110,14 @@ |
114 | 111 | } else { // The submitted form data is valid, so process it |
115 | 112 | // allow any external validators to have their way with the data |
116 | 113 | // Execute the proper transaction code: |
117 | | - switch ( $transactionType ) { |
118 | 114 | |
119 | | - case 'BANK_TRANSFER': |
120 | | - $this->executeBankTransfer(); |
121 | | - break; |
| 115 | + $result = $this->adapter->do_transaction( 'INSERT_ORDERWITHPAYMENT' ); |
| 116 | + |
| 117 | + $this->displayResultsForDebug( $result ); |
122 | 118 | |
123 | | - case 'INSERT_ORDERWITHPAYMENT': |
124 | | - $this->executeInsertOrderWithPayment(); |
125 | | - break; |
| 119 | + if ( $transactionType == 'credit' ) { |
126 | 120 | |
127 | | - default: |
128 | | - |
129 | | - $message = 'The transaction type [ ' . $transactionType . ' ] was not found.'; |
130 | | - throw new Exception( $message ); |
| 121 | + $this->executeiFrameForCreditCard(); |
131 | 122 | } |
132 | 123 | |
133 | 124 | |
— | — | @@ -135,7 +126,7 @@ |
136 | 127 | } else { |
137 | 128 | // Display form for the first time |
138 | 129 | $oid = $wgRequest->getText( 'order_id' ); |
139 | | - if ( $oid && !empty( $oid ) ) { |
| 130 | + if ( $oid ) { |
140 | 131 | $wgOut->addHTML( "<pre>CAME BACK FROM SOMETHING.</pre>" ); |
141 | 132 | $result = $this->adapter->do_transaction( 'GET_ORDERSTATUS' ); |
142 | 133 | $this->displayResultsForDebug( $result ); |
— | — | @@ -153,31 +144,12 @@ |
154 | 145 | } |
155 | 146 | |
156 | 147 | /** |
157 | | - * Execute BANK_TRANSFER |
| 148 | + * Execute execute iFrame for credit card |
158 | 149 | */ |
159 | | - public function executeBankTransfer() { |
| 150 | + public function executeiFrameForCreditCard() { |
160 | 151 | |
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 | | - |
174 | 152 | global $wgOut; |
175 | 153 | |
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 | | - |
182 | 154 | if ( !empty( $result['data'] ) ) { |
183 | 155 | |
184 | 156 | if ( array_key_exists( 'FORMACTION', $result['data'] ) ) { |