r102081 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102080‎ | r102081 | r102082 >
Date:01:47, 5 November 2011
Author:khorn
Status:ok
Tags:
Comment:
Finishes up the first pass on the new scheme we need to use, for confirming a GlobalCollect credit card transaction, and the cvv/avs function filters.
Modified paths:
  • /trunk/extensions/DonationInterface/donationinterface.php (modified) (history)
  • /trunk/extensions/DonationInterface/gateway_common/gateway.adapter.php (modified) (history)
  • /trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php (modified) (history)
  • /trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect_resultswitcher.body.php (modified) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro.adapter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/donationinterface.php
@@ -297,6 +297,39 @@
298298 //this really should be redefined in LocalSettings.
299299 $wgGlobalCollectGatewayAllowedHtmlForms = $wgDonationInterfaceAllowedHtmlForms;
300300 $wgGlobalCollectGatewayAllowedHtmlForms['lightbox1'] = $wgGlobalCollectGatewayHtmlFormDir .'/lightbox1.html';
 301+
 302+ $wgGlobalCollectGatewayCvvMap = array(
 303+ 'M' => true, //CVV check performed and valid value.
 304+ 'N' => false, //CVV checked and no match.
 305+ 'P' => true, //CVV check not performed, not requested
 306+ 'S' => false, //Card holder claims no CVV-code on card, issuer states CVV-code should be on card.
 307+ 'U' => true, //? //Issuer not certified for CVV2.
 308+ 'Y' => false, //Server provider did not respond.
 309+ '0' => true, //No service available.
 310+ );
 311+
 312+ $wgGlobalCollectGatewayAvsMap = array(
 313+ 'A' => 50, //Address (Street) matches, Zip does not.
 314+ 'B' => 50, //Street address match for international transactions. Postal code not verified due to incompatible formats.
 315+ 'C' => 50, //Street address and postal code not verified for international transaction due to incompatible formats.
 316+ 'D' => 0, //Street address and postal codes match for international transaction.
 317+ 'E' => 100, //AVS Error.
 318+ 'F' => 0, //Address does match and five digit ZIP code does match (UK only).
 319+ 'G' => 50, //Address information is unavailable; international transaction; non-AVS participant.
 320+ 'I' => 50, //Address information not verified for international transaction.
 321+ 'M' => 0, //Street address and postal codes match for international transaction.
 322+ 'N' => 100, //No Match on Address (Street) or Zip.
 323+ 'P' => 50, //Postal codes match for international transaction. Street address not verified due to incompatible formats.
 324+ 'R' => 100, //Retry, System unavailable or Timed out.
 325+ 'S' => 50, //Service not supported by issuer.
 326+ 'U' => 50, //Address information is unavailable.
 327+ 'W' => 50, //9 digit Zip matches, Address (Street) does not.
 328+ 'X' => 0, //Exact AVS Match.
 329+ 'Y' => 0, //Address (Street) and 5 digit Zip match.
 330+ 'Z' => 50, //5 digit Zip matches, Address (Street) does not.
 331+ '0' => 50, //No service available.
 332+ );
 333+
301334 }
302335
303336 //PayflowPro gateway globals
Index: trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro.adapter.php
@@ -265,6 +265,7 @@
266266 }
267267
268268 protected function pre_process_card(){
 269+ $this->incrementNumAttempt();
269270 $this->runPreProcessHooks();
270271 }
271272
Index: trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect_resultswitcher.body.php
@@ -66,7 +66,7 @@
6767 $adapter_oid = $adapter_oid['order_id'];
6868 if ( $oid && !empty( $oid ) && $oid === $adapter_oid ) {
6969 if ( !array_key_exists( 'order_status', $_SESSION ) || !array_key_exists( $oid, $_SESSION['order_status'] ) ) {
70 - $_SESSION['order_status'][$oid] = $this->adapter->do_transaction( 'K4sVoodoo' );
 70+ $_SESSION['order_status'][$oid] = $this->adapter->do_transaction( 'Confirm_CreditCard' );
7171 $_SESSION['order_status'][$oid]['data']['count'] = 0;
7272 } else {
7373 $_SESSION['order_status'][$oid]['data']['count'] = $_SESSION['order_status'][$oid]['data']['count'] + 1;
Index: trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php
@@ -287,13 +287,13 @@
288288 'ACTION' => 'GET_ORDERSTATUS',
289289 'VERSION' => '2.0'
290290 ),
291 - 'loop_for_status' => array(
292 - //'pending',
293 - 'pending-poke',
294 - 'complete',
295 - 'failed',
296 - 'revised',
297 - )
 291+// 'loop_for_status' => array(
 292+// //'pending',
 293+// 'pending-poke',
 294+// 'complete',
 295+// 'failed',
 296+// 'revised',
 297+// )
298298 );
299299
300300 $this->transactions['CANCEL_PAYMENT'] = array(
@@ -714,16 +714,16 @@
715715 */
716716 public function do_transaction( $transaction ){
717717 switch ( $transaction ){
718 - case 'K4sVoodoo' :
719 - return $this->doK4svoodoo();
 718+ case 'Confirm_CreditCard' :
 719+ return $this->transactionConfirm_CreditCard();
720720 break;
721721 default:
722722 return parent::do_transaction( $transaction );
723723 }
724724 }
725725
726 - //TODO: rename, yo.
727 - private function doK4svoodoo(){
 726+
 727+ private function transactionConfirm_CreditCard(){
728728 global $wgRequest; //this is for pulling vars straight from the querystring
729729 $pull_vars = array(
730730 'CVVRESULT' => 'cvv_result',
@@ -739,42 +739,101 @@
740740 if ( count( $addme ) ){
741741 $this->addData( $addme );
742742 }
 743+ $logmsg = $this->getData_Raw( 'contribution_tracking_id' ) . ': ';
 744+ $logmsg .= 'CVV Result: ' . $this->getData_Raw( 'cvv_result' );
 745+ $logmsg .= ', AVS Result: ' . $this->getData_Raw( 'avs_result' );
 746+ self::log( $logmsg );
743747
744748 $status_result = $this->do_transaction( 'GET_ORDERSTATUS' );
745749
746 -// $status_result['data'];
747 -//
748 - //TODO: If we've already failed, flame out here instead of later.
 750+ //error_log( "GET_ORDERSTATUS result: " . $status_result );
 751+
 752+ $cancelflag = false; //this will denote the thing we're trying to do with the donation attempt
 753+ $problemflag = false; //this will get set to true, if we can't continue and need to give up and just log the hell out of it.
 754+ $problemmessage = ''; //to be used in conjunction with the flag.
 755+
 756+ //we filtered
 757+ if ( array_key_exists( 'action', $status_result ) && $status_result['action'] != 'process' ){
 758+ $cancelflag = true;
 759+ } elseif ( array_key_exists( 'status', $status_result ) && $status_result['status'] === false ) {
 760+ //can't communicate or internal error
 761+ $problemflag = true;
 762+ }
749763
750 - if ( isset( $status_result['data'] ) && is_array( $status_result['data'] ) ){
751 - //if they're set, get CVVRESULT && AVSRESULT
752 - $pull_vars['EFFORTID'] = 'effort_id';
753 - $pull_vars['ATTEMPTID'] = 'attempt_id';
754 - $addme = array();
755 - foreach ( $pull_vars as $theirkey => $ourkey) {
756 - if ( array_key_exists( $theirkey, $status_result['data'] ) ){
757 - $addme[$ourkey] = $status_result['data'][$theirkey];
758 - }
 764+ if ( !$cancelflag && !$problemflag ) {
 765+ $order_status_results = $this->getTransactionWMFStatus();
 766+ if (!$order_status_results){
 767+ $problemflag = true;
 768+ $problemmessage = "We don't have a Transaction WMF Status after doing a GET_ORDERSTATUS.";
759769 }
 770+ switch ( $order_status_results ){
 771+ //status says no - probably no need to cancel, but why not be explicit?
 772+ case 'failed' :
 773+ case 'revised' :
 774+ $cancelflag = true;
 775+ break;
 776+ }
 777+ }
760778
761 - if ( count( $addme ) ){
762 - $this->addData( $addme );
 779+ //if we got here with no problemflag,
 780+ //confirm or cancel the payment based on $cancelflag
 781+ if ( !$problemflag ){
 782+ if ( isset( $status_result['data'] ) && is_array( $status_result['data'] ) ){
 783+ //if they're set, get CVVRESULT && AVSRESULT
 784+ $pull_vars['EFFORTID'] = 'effort_id';
 785+ $pull_vars['ATTEMPTID'] = 'attempt_id';
 786+ $addme = array();
 787+ foreach ( $pull_vars as $theirkey => $ourkey) {
 788+ if ( array_key_exists( $theirkey, $status_result['data'] ) ){
 789+ $addme[$ourkey] = $status_result['data'][$theirkey];
 790+ }
 791+ }
 792+
 793+ if ( count( $addme ) ){
 794+ $this->addData( $addme );
 795+ }
763796 }
764797
765 - //now, either do a cancel or a process, depending on what the filters
766 - //said we should do.
767 - switch ( $status_result['action'] ){
768 - case 'process' :
769 - $final = $this->do_transaction( 'SET_PAYMENT' );
770 - break;
771 - case 'reject' :
772 - $final = $this->do_transaction( 'CANCEL_PAYMENT' );
773 - break;
 798+ if ( !$cancelflag ){
 799+ $final = $this->do_transaction( 'SET_PAYMENT' );
 800+ if ( isset( $final['status'] ) && $final['status'] === true ) {
 801+ $this->setTransactionWMFStatus( $order_status_results ); //this had damn well better exist if we got this far.
 802+ $this->runPostProcessHooks(); //stomp is in here
 803+ $this->unsetAllSessionData();
 804+ } else {
 805+ $problemflag = true;
 806+ $problemmessage = "SET_PAYMENT couldn't communicate properly!";
 807+ }
 808+ } else {
 809+ $final = $this->do_transaction( 'CANCEL_PAYMENT' );
 810+ if ( isset( $final['status'] ) && $final['status'] === true ) {
 811+ $this->setTransactionWMFStatus( 'failed' );
 812+ $this->unsetAllSessionData();
 813+ } else {
 814+ $problemflag = true;
 815+ $problemmessage = "CANCEL_PAYMENT couldn't communicate properly!";
 816+ }
774817 }
775 - return $final;
776818 }
777 -// error_log("Got nothing good back from the first call...");
778 - return $status_result;
 819+
 820+ if ( $problemflag ){
 821+ //we have probably had a communication problem that could mean stranded payments.
 822+ $problemmessage = $this->getData_Raw( 'contribution_tracking_id' ) . ':' . $this->getData_Raw( 'order_id' ) . ' ' . $problemmessage;
 823+ self::log( $problemmessage );
 824+ //hurm. It would be swell if we had a message that told the user we had some kind of internal error.
 825+ return array(
 826+ 'status' => false,
 827+ //TODO: appropriate messages.
 828+ 'message' => $problemmessage,
 829+ 'errors' => array(
 830+ '1000000' => 'Transaction could not be processed due to an internal error.'
 831+ ),
 832+ 'action' => $this->getValidationAction(),
 833+ );
 834+ }
 835+
 836+// return something better... if we need to!
 837+ return $status_result;
779838 }
780839
781840 /**
@@ -1175,6 +1234,7 @@
11761235 }
11771236
11781237 protected function pre_process_insert_orderwithpayment(){
 1238+ $this->incrementNumAttempt();
11791239 if ( $this->getData_Raw( 'payment_method' ) === 'cc' ){
11801240 $this->addDonorDataToSession();
11811241 }
@@ -1186,8 +1246,10 @@
11871247 }
11881248 }
11891249
1190 - protected function post_process_get_orderstatus(){
1191 - $this->runPostProcessHooks();
 1250+ protected function post_process_insert_orderwithpayment(){
 1251+ if ( $this->getData_Raw( 'payment_method' ) != 'cc' ){
 1252+ $this->runPostProcessHooks();
 1253+ }
11921254 }
11931255
11941256 /**
@@ -1199,17 +1261,9 @@
12001262 return null;
12011263 }
12021264
1203 - $result_map = array(
1204 - 'M' => true, //CVV check performed and valid value.
1205 - 'N' => false, //CVV checked and no match.
1206 - 'P' => true, //CVV check not performed, not requested
1207 - 'S' => false, //Card holder claims no CVV-code on card, issuer states CVV-code should be on card.
1208 - 'U' => true, //? //Issuer not certified for CVV2.
1209 - 'Y' => false, //Server provider did not respond.
1210 - '0' => true, //No service available.
1211 - );
 1265+ $cvv_map = $this->getGlobal( 'CvvMap' );
12121266
1213 - $result = $result_map[$this->getData_Raw( 'cvv_result' )];
 1267+ $result = $cvv_map[$this->getData_Raw( 'cvv_result' )];
12141268 return $result;
12151269
12161270 }
@@ -1225,29 +1279,9 @@
12261280 //Best guess here:
12271281 //Scale of 0 - 100, of Problem we think this result is likely to cause.
12281282
1229 - $result_map = array(
1230 - 'A' => 50, //Address (Street) matches, Zip does not.
1231 - 'B' => 50, //Street address match for international transactions. Postal code not verified due to incompatible formats.
1232 - 'C' => 50, //Street address and postal code not verified for international transaction due to incompatible formats.
1233 - 'D' => 0, //Street address and postal codes match for international transaction.
1234 - 'E' => 100, //AVS Error.
1235 - 'F' => 0, //Address does match and five digit ZIP code does match (UK only).
1236 - 'G' => 50, //Address information is unavailable; international transaction; non-AVS participant.
1237 - 'I' => 50, //Address information not verified for international transaction.
1238 - 'M' => 0, //Street address and postal codes match for international transaction.
1239 - 'N' => 100, //No Match on Address (Street) or Zip.
1240 - 'P' => 50, //Postal codes match for international transaction. Street address not verified due to incompatible formats.
1241 - 'R' => 100, //Retry, System unavailable or Timed out.
1242 - 'S' => 50, //Service not supported by issuer.
1243 - 'U' => 50, //Address information is unavailable.
1244 - 'W' => 50, //9 digit Zip matches, Address (Street) does not.
1245 - 'X' => 0, //Exact AVS Match.
1246 - 'Y' => 0, //Address (Street) and 5 digit Zip match.
1247 - 'Z' => 50, //5 digit Zip matches, Address (Street) does not.
1248 - '0' => 50, //No service available.
1249 - );
 1283+ $avs_map = $this->getGlobal( 'AvsMap' );
12501284
1251 - $result = $result_map[$this->getData_Raw( 'avs_result' )];
 1285+ $result = $avs_map[$this->getData_Raw( 'avs_result' )];
12521286 return $result;
12531287 }
12541288
Index: trunk/extensions/DonationInterface/gateway_common/gateway.adapter.php
@@ -742,8 +742,8 @@
743743 * numeric codes (even if we have to make them up ourselves) and
744744 * human-readable assessments of what happened, probably straight from
745745 * the gateway.
746 - * 'action' = (sometimes there) What the pre-commit hooks said we should go
747 - * do with ourselves, if they were fired off.
 746+ * 'action' = What the pre-commit hooks said we should go do with ourselves.
 747+ * If none were fired, this will be set to 'process'
748748 * 'data' = The data passed back to us from the transaction, in a nice
749749 * key-value array.
750750 */
@@ -754,9 +754,6 @@
755755
756756 try {
757757 $this->setCurrentTransaction( $transaction );
758 -
759 - //TODO: This is a problem here. Needs to be moved to pre_process or something.
760 - $this->incrementNumAttempt();
761758
762759 //If we have any special pre-process instructions for this
763760 //transaction, do 'em.
@@ -868,6 +865,7 @@
869866 'errors' => array(
870867 '1000000' => 'communication failure' //...stupid code.
871868 ),
 869+ 'action' => $this->getValidationAction(),
872870 );
873871 }
874872
@@ -892,30 +890,10 @@
893891 // log that the transaction is essentially complete
894892 self::log( $this->getData_Raw( 'contribution_tracking_id' ) . " Transaction complete." );
895893
896 - //getTransactionStatus works here like this, because it only returns
897 - //something other than false if it's the sort of a transaction that can
898 - //denote a successful donation.
899 -// $wmfStatus = $this->getTransactionWMFStatus();
900 -// switch ( $wmfStatus ){
901 -// case 'failed' : //only kill their session if they've tried three (or somehow more) times.
902 -// if ( (int)$this->getData_Staged('numAttempt') < 3 ) {
903 -// break;
904 -// }
905 -// case 'complete' :
906 -// case 'pending' :
907 -// case 'pending-poke' :
908 -// $this->unsetAllSessionData();
909 -// }
910 -
911894 $this->debugarray[] = 'numAttempt = ' . $this->getData_Staged('numAttempt');
912895
913896 return $this->getTransactionAllResults();
914 -
915 - //speaking of universal form:
916 - //$result['status'] = something I wish could be boiled down to a bool, but that's way too optimistic, I think.
917 - //$result['message'] = whatever we want to display back?
918 - //$result['errors']['code']['message'] =
919 - //$result['data'][$whatever] = values they pass back to us for whatever reason. We might... log it, or pieces of it, or something?
 897+
920898 }
921899
922900 function getCurlBaseOpts() {

Follow-up revisions

RevisionCommit summaryAuthorDate
r102186Adds the original transaction response status to the set_payment response, ju...khorn19:55, 6 November 2011
r102236MFT r90286, r100671, r100837, r100950, r101060, r101063, r101064, r101073, r1......khorn03:06, 7 November 2011
r102237MFT r90286, r100671, r100837, r100950, r101060, r101063, r101064, r101073, r1......khorn03:07, 7 November 2011

Status & tagging log