r97213 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97212‎ | r97213 | r97214 >
Date:22:10, 15 September 2011
Author:khorn
Status:ok (Comments)
Tags:fundraising 
Comment:
Adds the ability to get the order status from GC.
Modified paths:
  • /branches/fundraising/extensions/DonationInterface/gateway_common/DonationData.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/gateway_common/gateway.adapter.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect_gateway.body.php (modified) (history)

Diff [purge]

Index: branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect_gateway.body.php
@@ -117,21 +117,9 @@
118118 $result = $this->adapter->do_transaction( 'INSERT_ORDERWITHPAYMENT' );
119119 //$result = $this->adapter->do_transaction( 'TEST_CONNECTION' );
120120
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);
129122
130123 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>" );
136124
137125 if (array_key_exists('FORMACTION', $result['data'])){
138126 $paymentFrame = Xml::openElement( 'iframe',
@@ -191,6 +179,13 @@
192180 }
193181 } else {
194182 // 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+ }
195190 $this->adapter->log( "Not posted, or not processed. Showing the form for the first time." );
196191 $this->fnPayflowDisplayForm( $data, $this->errors );
197192 }
@@ -202,6 +197,37 @@
203198 $this->fnPayflowDisplayForm( $data, $this->errors );
204199 }
205200 }
 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+ }
206232
207233 /**
208234 * Build and display form to user
Index: branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php
@@ -14,11 +14,12 @@
1515 $this->postdata['amount'] = $this->postdata['amount'] * 100;
1616
1717 $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'])){
1919 $card_type = $this->postdata['card_type'];
2020 } else {
2121 $card_type = $this->postdatadefaults['card_type'];
2222 }
 23+
2324 switch ( $card_type ) {
2425 case 'visa':
2526 $this->postdata['card_type'] = 1;
@@ -152,6 +153,28 @@
153154 'ACTION' => 'TEST_CONNECTION'
154155 )
155156 );
 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+ );
156179 }
157180
158181 /**
@@ -212,31 +235,22 @@
213236 */
214237 function getResponseData( $response ) {
215238 $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 - }
223239
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;
230252 }
231253
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 - }
239254
240 -
241255 self::log( "Returned Data: " . print_r( $data, true ) );
242256 return $data;
243257 }
Index: branches/fundraising/extensions/DonationInterface/gateway_common/gateway.adapter.php
@@ -125,6 +125,7 @@
126126 */
127127 function setPostDefaults() {
128128 $returnTitle = Title::newFromText( 'Donate-thanks/en' );
 129+// $returnTitle = Title::newFromText( 'Special:GlobalCollectGateway' );
129130 $returnto = $returnTitle->getFullURL();
130131
131132 $this->postdatadefaults = array(
@@ -275,10 +276,8 @@
276277 if ( $this->getCommunicationType() === 'xml' ) {
277278 $this->getStopwatch(__FUNCTION__);
278279 $xml = $this->buildRequestXML();
279 - $this->saveCommunicationStats("-BuildingRequestXML");
280 - $this->getStopwatch(__FUNCTION__, true);
 280+ $this->saveCommunicationStats(__FUNCTION__, "Building Request XML", "Transaction = $transaction");
281281 $returned = $this->curl_transaction( $xml );
282 - $this->saveCommunicationStats();
283282 //put the response in a universal form, and return it.
284283 }
285284
@@ -377,7 +376,8 @@
378377 */
379378 protected function curl_transaction( $data ) {
380379 // assign header data necessary for the curl_setopt() function
381 -
 380+ $this->getStopwatch(__FUNCTION__, true);
 381+
382382 $ch = curl_init();
383383
384384 $headers = $this->getCurlBaseHeaders();
@@ -413,6 +413,8 @@
414414 }
415415 }
416416
 417+ $this->saveCommunicationStats(__FUNCTION__, $this->currentTransaction(), "Request:" . print_r($data, true) . "\nResponse" . print_r($return, true));
 418+
417419 if ( $return['headers']['http_code'] != 200 ) {
418420 $return['result'] = false;
419421 //TODO: i18n here!
@@ -527,14 +529,23 @@
528530 return $clock;
529531 }
530532
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...
532540 $params = array();
533541 if (self::getGlobal('SaveCommStats')){ //TODO: I should do this for real at some point.
534542 $db = ContributionTrackingProcessor::contributionTrackingConnection();
535543 $params['contribution_id'] = $this->dataObj->getVal( 'contribution_tracking_id' );
536544 $params['ts'] = $db->timestamp();
537545 $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;
539550
540551 //can we check to see if the table exists? Bah, I should almost certianly do this Fer Reals.
541552
@@ -542,5 +553,17 @@
543554 }
544555
545556 }
 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+ }
546569
547570 }
Index: branches/fundraising/extensions/DonationInterface/gateway_common/DonationData.php
@@ -235,6 +235,15 @@
236236 function setNormalizedOrderIDs() {
237237 //basically, we need a new order_id every time we come through here, but if there's an internal already there,
238238 //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+
239248 $this->setVal( 'order_id', $this->generateOrderId() );
240249
241250 if ( !$this->isSomething( 'i_order_id' ) ) {

Comments

#Comment by Khorn (WMF) (talk | contribs)   18:41, 23 September 2011

Please note that this branch is in the middle of a serious refactoring, and is by no means ready to be merged back into trunk. (Latest DonationInterface branch rev at the time of this comment is r97833.)

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

Will need to add unit testing for this code.

Status & tagging log