r71221 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71220‎ | r71221 | r71222 >
Date:00:03, 18 August 2010
Author:awjrichards
Status:deferred
Tags:
Comment:
Changed payflow response parsing to explode entire response string into an array (rather than old whack string parsing), partly as per http://www.mediawiki.org/wiki/Special:Code/MediaWiki/69650#c8461
Modified paths:
  • /trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php
@@ -698,19 +698,19 @@
699699
700700 // prepare NVP response for sorting and outputting
701701 $responseArray = array();
702 -
703 - while( strlen( $result ) ) {
704 - // name
705 - $namepos = strpos( $result, '=' );
706 - $nameval = substr( $result, 0, $namepos );
707 - // value
708 - $valuepos = strpos( $result, '&' ) ? strpos( $result, '&' ) : strlen( $result );
709 - $valueval = substr( $result, $namepos + 1, $valuepos - $namepos - 1 );
710 - // decoding the respose
711 - $responseArray[$nameval] = $valueval;
712 - $result = substr( $result, $valuepos + 1, strlen( $result ) );
 702+
 703+ /**
 704+ * The result response string looks like:
 705+ * RESULT=7&PNREF=E79P2C651DC2&RESPMSG=Field format error&HOSTCODE=10747&DUPLICATE=1
 706+ * We want to turn this into an array of key value pairs, so explode on '&' and then
 707+ * split up the resulting strings into $key => $value
 708+ */
 709+ $result_arr = explode( "&", $result );
 710+ foreach ( $result_arr as $result_pair ) {
 711+ list( $key, $value ) = split( "=", $result_pair );
 712+ $responseArray[ $key ] = $value;
713713 }
714 -
 714+
715715 // errors fall into three categories, "try again please", "sorry it didn't work out", and "approved"
716716 // get the result code for response array
717717 $resultCode = $responseArray['RESULT'];
@@ -724,7 +724,6 @@
725725 $errorCode = $this->fnPayflowGetResponseMsg( $resultCode, $responseMsg );
726726
727727 // if approved, display results and send transaction to the queue
728 -
729728 if( $errorCode == '1' ) {
730729 $this->fnPayflowDisplayApprovedResults( $data, $responseArray, $responseMsg );
731730 // give user a second chance to enter incorrect data

Status & tagging log