Index: branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect_gateway.body.php |
— | — | @@ -117,21 +117,9 @@ |
118 | 118 | $result = $this->adapter->do_transaction( 'INSERT_ORDERWITHPAYMENT' ); |
119 | 119 | //$result = $this->adapter->do_transaction( 'TEST_CONNECTION' ); |
120 | 120 | |
121 | | - $wgOut->addHTML( $result['message'] ); |
122 | | - if ( !empty( $result['errors'] ) ) { |
123 | | - $wgOut->addHTML( "<ul>" ); |
124 | | - foreach ( $result['errors'] as $code => $value ) { |
125 | | - $wgOut->addHTML( "<li>Error $code: $value" ); |
126 | | - } |
127 | | - $wgOut->addHTML( "</ul>" ); |
128 | | - } |
| 121 | + $this->displayResultsForDebug($result); |
129 | 122 | |
130 | 123 | if ( !empty( $result['data'] ) ) { |
131 | | - $wgOut->addHTML( "<ul>" ); |
132 | | - foreach ( $result['data'] as $key => $value ) { |
133 | | - $wgOut->addHTML( "<li>$key: $value" ); |
134 | | - } |
135 | | - $wgOut->addHTML( "</ul>" ); |
136 | 124 | |
137 | 125 | if (array_key_exists('FORMACTION', $result['data'])){ |
138 | 126 | $paymentFrame = Xml::openElement( 'iframe', |
— | — | @@ -191,6 +179,13 @@ |
192 | 180 | } |
193 | 181 | } else { |
194 | 182 | // Display form for the first time |
| 183 | + $oid = $wgRequest->getText( 'order_id' ); |
| 184 | + if ($oid && !empty($oid)){ |
| 185 | + $wgOut->addHTML("<pre>CAME BACK FROM SOMETHING.</pre>"); |
| 186 | + $result = $this->adapter->do_transaction( 'GET_ORDERSTATUS' ); |
| 187 | + $this->displayResultsForDebug($result); |
| 188 | + |
| 189 | + } |
195 | 190 | $this->adapter->log( "Not posted, or not processed. Showing the form for the first time." ); |
196 | 191 | $this->fnPayflowDisplayForm( $data, $this->errors ); |
197 | 192 | } |
— | — | @@ -202,6 +197,37 @@ |
203 | 198 | $this->fnPayflowDisplayForm( $data, $this->errors ); |
204 | 199 | } |
205 | 200 | } |
| 201 | + |
| 202 | + function displayResultsForDebug($results){ |
| 203 | + global $wgOut; |
| 204 | + $wgOut->addHTML( $results['message'] ); |
| 205 | + |
| 206 | + if ( !empty( $results['errors'] ) ) { |
| 207 | + $wgOut->addHTML( "<ul>" ); |
| 208 | + foreach ( $results['errors'] as $code => $value ) { |
| 209 | + $wgOut->addHTML( "<li>Error $code: $value" ); |
| 210 | + } |
| 211 | + $wgOut->addHTML( "</ul>" ); |
| 212 | + } |
| 213 | + |
| 214 | + if ( !empty( $results['data'] ) ) { |
| 215 | + $wgOut->addHTML( "<ul>" ); |
| 216 | + foreach ( $results['data'] as $key => $value ) { |
| 217 | + if (is_array($value)){ |
| 218 | + $wgOut->addHTML( "<li>$key:<ul>" ); |
| 219 | + foreach ($value as $key2 => $val2){ |
| 220 | + $wgOut->addHTML( "<li>$key2: $val2" ); |
| 221 | + } |
| 222 | + $wgOut->addHTML( "</ul>" ); |
| 223 | + } else { |
| 224 | + $wgOut->addHTML( "<li>$key: $value" ); |
| 225 | + } |
| 226 | + } |
| 227 | + $wgOut->addHTML( "</ul>" ); |
| 228 | + } else { |
| 229 | + $wgOut->addHTML("Empty Results"); |
| 230 | + } |
| 231 | + } |
206 | 232 | |
207 | 233 | /** |
208 | 234 | * Build and display form to user |
Index: branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php |
— | — | @@ -14,11 +14,12 @@ |
15 | 15 | $this->postdata['amount'] = $this->postdata['amount'] * 100; |
16 | 16 | |
17 | 17 | $card_type = ''; |
18 | | - if (array_key_exists('card_type', $this->postdata)){ |
| 18 | + if (array_key_exists('card_type', $this->postdata) && !empty($this->postdata['card_type'])){ |
19 | 19 | $card_type = $this->postdata['card_type']; |
20 | 20 | } else { |
21 | 21 | $card_type = $this->postdatadefaults['card_type']; |
22 | 22 | } |
| 23 | + |
23 | 24 | switch ( $card_type ) { |
24 | 25 | case 'visa': |
25 | 26 | $this->postdata['card_type'] = 1; |
— | — | @@ -152,6 +153,28 @@ |
153 | 154 | 'ACTION' => 'TEST_CONNECTION' |
154 | 155 | ) |
155 | 156 | ); |
| 157 | + |
| 158 | + $this->transactions['GET_ORDERSTATUS'] = array( |
| 159 | + 'request' => array( |
| 160 | + 'REQUEST' => array( |
| 161 | + 'ACTION', |
| 162 | + 'META' => array( |
| 163 | + 'MERCHANTID', |
| 164 | +// 'IPADDRESS', |
| 165 | + 'VERSION' |
| 166 | + ), |
| 167 | + 'PARAMS' => array( |
| 168 | + 'ORDER' => array( |
| 169 | + 'ORDERID', |
| 170 | + ), |
| 171 | + ) |
| 172 | + ) |
| 173 | + ), |
| 174 | + 'values' => array( |
| 175 | + 'ACTION' => 'GET_ORDERSTATUS', |
| 176 | + 'VERSION' => '2.0' |
| 177 | + ) |
| 178 | + ); |
156 | 179 | } |
157 | 180 | |
158 | 181 | /** |
— | — | @@ -212,31 +235,22 @@ |
213 | 236 | */ |
214 | 237 | function getResponseData( $response ) { |
215 | 238 | $data = array( ); |
216 | | - foreach ( $response->getElementsByTagName( 'ROW' ) as $node ) { |
217 | | - foreach ( $node->childNodes as $childnode ) { |
218 | | - if ( trim( $childnode->nodeValue ) != '' ) { |
219 | | - $data[$childnode->nodeName] = $childnode->nodeValue; |
220 | | - } |
221 | | - } |
222 | | - } |
223 | 239 | |
224 | | - foreach ( $response->getElementsByTagName( 'ORDER' ) as $node ) { |
225 | | - foreach ( $node->childNodes as $childnode ) { |
226 | | - if ( trim( $childnode->nodeValue ) != '' ) { |
227 | | - $data['RequestOrder-' . $childnode->nodeName] = $childnode->nodeValue; |
228 | | - } |
229 | | - } |
| 240 | + $transaction = $this->currentTransaction(); |
| 241 | + |
| 242 | + switch ( $transaction ) { |
| 243 | + case 'INSERT_ORDERWITHPAYMENT': |
| 244 | + $data = $this->xmlChildrenToArray($response, 'ROW'); |
| 245 | + $data['ORDER'] = $this->xmlChildrenToArray($response, 'ORDER'); |
| 246 | + $data['PAYMENT'] = $this->xmlChildrenToArray($response, 'PAYMENT'); |
| 247 | + break; |
| 248 | + case 'GET_ORDERSTATUS': |
| 249 | + $data = $this->xmlChildrenToArray($response, 'STATUS'); |
| 250 | + $data['ORDER'] = $this->xmlChildrenToArray($response, 'ORDER'); |
| 251 | + break; |
230 | 252 | } |
231 | 253 | |
232 | | - foreach ( $response->getElementsByTagName( 'PAYMENT' ) as $node ) { |
233 | | - foreach ( $node->childNodes as $childnode ) { |
234 | | - if ( trim( $childnode->nodeValue ) != '' ) { |
235 | | - $data['RequestPayment-' . $childnode->nodeName] = $childnode->nodeValue; |
236 | | - } |
237 | | - } |
238 | | - } |
239 | 254 | |
240 | | - |
241 | 255 | self::log( "Returned Data: " . print_r( $data, true ) ); |
242 | 256 | return $data; |
243 | 257 | } |
Index: branches/fundraising/extensions/DonationInterface/gateway_common/gateway.adapter.php |
— | — | @@ -125,6 +125,7 @@ |
126 | 126 | */ |
127 | 127 | function setPostDefaults() { |
128 | 128 | $returnTitle = Title::newFromText( 'Donate-thanks/en' ); |
| 129 | +// $returnTitle = Title::newFromText( 'Special:GlobalCollectGateway' ); |
129 | 130 | $returnto = $returnTitle->getFullURL(); |
130 | 131 | |
131 | 132 | $this->postdatadefaults = array( |
— | — | @@ -275,10 +276,8 @@ |
276 | 277 | if ( $this->getCommunicationType() === 'xml' ) { |
277 | 278 | $this->getStopwatch(__FUNCTION__); |
278 | 279 | $xml = $this->buildRequestXML(); |
279 | | - $this->saveCommunicationStats("-BuildingRequestXML"); |
280 | | - $this->getStopwatch(__FUNCTION__, true); |
| 280 | + $this->saveCommunicationStats(__FUNCTION__, "Building Request XML", "Transaction = $transaction"); |
281 | 281 | $returned = $this->curl_transaction( $xml ); |
282 | | - $this->saveCommunicationStats(); |
283 | 282 | //put the response in a universal form, and return it. |
284 | 283 | } |
285 | 284 | |
— | — | @@ -377,7 +376,8 @@ |
378 | 377 | */ |
379 | 378 | protected function curl_transaction( $data ) { |
380 | 379 | // assign header data necessary for the curl_setopt() function |
381 | | - |
| 380 | + $this->getStopwatch(__FUNCTION__, true); |
| 381 | + |
382 | 382 | $ch = curl_init(); |
383 | 383 | |
384 | 384 | $headers = $this->getCurlBaseHeaders(); |
— | — | @@ -413,6 +413,8 @@ |
414 | 414 | } |
415 | 415 | } |
416 | 416 | |
| 417 | + $this->saveCommunicationStats(__FUNCTION__, $this->currentTransaction(), "Request:" . print_r($data, true) . "\nResponse" . print_r($return, true)); |
| 418 | + |
417 | 419 | if ( $return['headers']['http_code'] != 200 ) { |
418 | 420 | $return['result'] = false; |
419 | 421 | //TODO: i18n here! |
— | — | @@ -527,14 +529,23 @@ |
528 | 530 | return $clock; |
529 | 531 | } |
530 | 532 | |
531 | | - function saveCommunicationStats( $additional = '' ) { //easier than looking at logs... |
| 533 | + /** |
| 534 | + * |
| 535 | + * @param type $function |
| 536 | + * @param type $additional |
| 537 | + * @param type $vars |
| 538 | + */ |
| 539 | + function saveCommunicationStats( $function = '', $additional = '', $vars = '' ) { //easier than looking at logs... |
532 | 540 | $params = array(); |
533 | 541 | if (self::getGlobal('SaveCommStats')){ //TODO: I should do this for real at some point. |
534 | 542 | $db = ContributionTrackingProcessor::contributionTrackingConnection(); |
535 | 543 | $params['contribution_id'] = $this->dataObj->getVal( 'contribution_tracking_id' ); |
536 | 544 | $params['ts'] = $db->timestamp(); |
537 | 545 | $params['duration'] = $this->getStopwatch(__FUNCTION__); |
538 | | - $params['gateway'] = self::getGatewayName() . $additional; |
| 546 | + $params['gateway'] = self::getGatewayName(); |
| 547 | + $params['function'] = $function; |
| 548 | + $params['vars'] = $vars; |
| 549 | + $params['additional'] = $additional; |
539 | 550 | |
540 | 551 | //can we check to see if the table exists? Bah, I should almost certianly do this Fer Reals. |
541 | 552 | |
— | — | @@ -542,5 +553,17 @@ |
543 | 554 | } |
544 | 555 | |
545 | 556 | } |
| 557 | + |
| 558 | + function xmlChildrenToArray($xml, $nodename){ |
| 559 | + $data = array(); |
| 560 | + foreach ( $xml->getElementsByTagName( $nodename ) as $node ) { |
| 561 | + foreach ( $node->childNodes as $childnode ) { |
| 562 | + if ( trim( $childnode->nodeValue ) != '' ) { |
| 563 | + $data[$childnode->nodeName] = $childnode->nodeValue; |
| 564 | + } |
| 565 | + } |
| 566 | + } |
| 567 | + return $data; |
| 568 | + } |
546 | 569 | |
547 | 570 | } |
Index: branches/fundraising/extensions/DonationInterface/gateway_common/DonationData.php |
— | — | @@ -235,6 +235,15 @@ |
236 | 236 | function setNormalizedOrderIDs() { |
237 | 237 | //basically, we need a new order_id every time we come through here, but if there's an internal already there, |
238 | 238 | //we want to use that one internally. So. |
| 239 | + |
| 240 | + //Exception: If we pass in an order ID in the querystring: Don't mess with it. |
| 241 | + //TODO: I'm pretty sure I'm not supposed to do this directly. |
| 242 | + if (array_key_exists('order_id', $_GET)){ |
| 243 | + $this->setVal( 'order_id', $_GET['order_id'] ); |
| 244 | + $this->setVal( 'i_order_id', $_GET['order_id'] ); |
| 245 | + return; |
| 246 | + } |
| 247 | + |
239 | 248 | $this->setVal( 'order_id', $this->generateOrderId() ); |
240 | 249 | |
241 | 250 | if ( !$this->isSomething( 'i_order_id' ) ) { |