r101951 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101950‎ | r101951 | r101952 >
Date:03:10, 4 November 2011
Author:khorn
Status:ok (Comments)
Tags:
Comment:
Adds to GlobalCollect, two new transactions that are meant to fire as the result of the attempt to do a GET_ORDERSTATUS with credit card.
A local do_transaction now overloads the parent function in the globalcollect adapter, and will divert special transaction directives to an alternate function.
Also defines two functions that are meant to be used in the function filter, to check avs and cvv return values.
Modified paths:
  • /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)

Diff [purge]

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( 'GET_ORDERSTATUS' );
 70+ $_SESSION['order_status'][$oid] = $this->adapter->do_transaction( 'K4sVoodoo' );
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
@@ -29,6 +29,7 @@
3030 $this->var_map = array(
3131 'ACCOUNTNAME' => 'account_name',
3232 'ACCOUNTNUMBER' => 'account_number',
 33+ 'ATTEMPTID' => 'attempt_id',
3334 'AUTHORIZATIONID' => 'authorization_id',
3435 'AMOUNT' => 'amount',
3536 'BANKCHECKDIGIT' => 'bank_check_digit',
@@ -43,6 +44,7 @@
4445 'CVV' => 'cvv',
4546 'DATECOLLECT' => 'date_collect',
4647 'DIRECTDEBITTEXT' => 'direct_debit_text',
 48+ 'EFFORTID' => 'effort_id',
4749 'EMAIL' => 'email',
4850 'EXPIRYDATE' => 'expiration',
4951 'FIRSTNAME' => 'fname',
@@ -61,6 +63,16 @@
6264 'ZIP' => 'zip',
6365 );
6466 }
 67+
 68+ /**
 69+ * Setting some GC-specific defaults.
 70+ * @param array $options These get extracted in the parent.
 71+ */
 72+ function setPostDefaults( $options = array() ) {
 73+ parent::setPostDefaults( $options );
 74+ $this->postdatadefaults['attempt_id'] = '1';
 75+ $this->postdatadefaults['effort_id'] = '1';
 76+ }
6577
6678 /**
6779 * Define return_value_map
@@ -231,6 +243,54 @@
232244 'revised',
233245 )
234246 );
 247+
 248+ $this->transactions['CANCEL_PAYMENT'] = array(
 249+ 'request' => array(
 250+ 'REQUEST' => array(
 251+ 'ACTION',
 252+ 'META' => array(
 253+ 'MERCHANTID',
 254+ 'IPADDRESS',
 255+ 'VERSION'
 256+ ),
 257+ 'PARAMS' => array(
 258+ 'PAYMENT' => array(
 259+ 'ORDERID',
 260+ 'EFFORTID',
 261+ 'ATTEMPTID',
 262+ ),
 263+ )
 264+ )
 265+ ),
 266+ 'values' => array(
 267+ 'ACTION' => 'CANCEL_PAYMENT',
 268+ 'VERSION' => '1.0'
 269+ ),
 270+ );
 271+
 272+ $this->transactions['SET_PAYMENT'] = array(
 273+ 'request' => array(
 274+ 'REQUEST' => array(
 275+ 'ACTION',
 276+ 'META' => array(
 277+ 'MERCHANTID',
 278+ 'IPADDRESS',
 279+ 'VERSION'
 280+ ),
 281+ 'PARAMS' => array(
 282+ 'PAYMENT' => array(
 283+ 'ORDERID',
 284+ 'EFFORTID',
 285+ 'PAYMENTPRODUCTID',
 286+ ),
 287+ )
 288+ )
 289+ ),
 290+ 'values' => array(
 291+ 'ACTION' => 'SET_PAYMENT',
 292+ 'VERSION' => '1.0'
 293+ ),
 294+ );
235295 }
236296
237297 /**
@@ -525,6 +585,76 @@
526586 }
527587
528588 /**
 589+ * Because GC has some processes that involve more than one do_transaction
 590+ * chained together, we're catching those special ones in an overload and
 591+ * letting the rest behave normally.
 592+ */
 593+ public function do_transaction( $transaction ){
 594+ switch ( $transaction ){
 595+ case 'K4sVoodoo' :
 596+ return $this->doK4svoodoo();
 597+ break;
 598+ default:
 599+ return parent::do_transaction( $transaction );
 600+ }
 601+ }
 602+
 603+ //TODO: rename, yo.
 604+ private function doK4svoodoo(){
 605+ global $wgRequest; //this is for pulling vars straight from the querystring
 606+ $pull_vars = array(
 607+ 'CVVRESULT' => 'cvv_result',
 608+ 'AVSRESULT' => 'avs_result',
 609+ );
 610+ $addme = array();
 611+ foreach ( $pull_vars as $theirkey => $ourkey) {
 612+ $tmp = $wgRequest->getVal( $theirkey, null );
 613+ if ( !is_null( $tmp ) ) {
 614+ $addme[$ourkey] = $tmp;
 615+ }
 616+ }
 617+ if ( count( $addme ) ){
 618+ $this->addData( $addme );
 619+ }
 620+
 621+ $status_result = $this->do_transaction( 'GET_ORDERSTATUS' );
 622+
 623+// $status_result['data'];
 624+//
 625+ //TODO: If we've already failed, flame out here instead of later.
 626+
 627+ if ( isset( $status_result['data'] ) && is_array( $status_result['data'] ) ){
 628+ //if they're set, get CVVRESULT && AVSRESULT
 629+ $pull_vars['EFFORTID'] = 'effort_id';
 630+ $pull_vars['ATTEMPTID'] = 'attempt_id';
 631+ $addme = array();
 632+ foreach ( $pull_vars as $theirkey => $ourkey) {
 633+ if ( array_key_exists( $theirkey, $status_result['data'] ) ){
 634+ $addme[$ourkey] = $status_result['data'][$theirkey];
 635+ }
 636+ }
 637+
 638+ if ( count( $addme ) ){
 639+ $this->addData( $addme );
 640+ }
 641+
 642+ //now, either do a cancel or a process, depending on what the filters
 643+ //said we should do.
 644+ switch ( $status_result['action'] ){
 645+ case 'process' :
 646+ $final = $this->do_transaction( 'SET_PAYMENT' );
 647+ break;
 648+ case 'reject' :
 649+ $final = $this->do_transaction( 'CANCEL_PAYMENT' );
 650+ break;
 651+ }
 652+ return $final;
 653+ }
 654+// error_log("Got nothing good back from the first call...");
 655+ return $status_result;
 656+ }
 657+
 658+ /**
529659 * Take the entire response string, and strip everything we don't care about.
530660 * For instance: If it's XML, we only want correctly-formatted XML. Headers must be killed off.
531661 * return a string.
@@ -904,28 +1034,79 @@
9051035
9061036 protected function pre_process_insert_orderwithpayment(){
9071037 if ( $this->getData( 'payment_method' ) === 'cc' ){
908 - $this->runPreProcessHooks(); //this is shortly to move elsewhere.
9091038 $this->addDonorDataToSession();
9101039 }
9111040 }
9121041
9131042 protected function pre_process_get_orderstatus(){
9141043 if ( $this->getData( 'payment_method' ) === 'cc' ){
915 - //if they're set, get CVVRESULT && AVSRESULT
916 - global $wgRequest;
917 - $cvv_result = $wgRequest->getVal( 'CVVRESULT', null );
918 - $avs_result = $wgRequest->getVal( 'AVSRESULT', null );
919 - if ( !is_null($cvv_result) ){
920 - $this->debugarray[] = "CVV result: $cvv_result";
921 - }
922 - if ( !is_null($avs_result) ){
923 - $this->debugarray[] = "AVS result: $avs_result";
924 - }
 1044+ $this->runPreProcessHooks();
9251045 }
9261046 }
9271047
9281048 protected function post_process_get_orderstatus(){
9291049 $this->runPostProcessHooks();
9301050 }
 1051+
 1052+ /**
 1053+ * getCVVResult is intended to be used by the functions filter, to
 1054+ * determine if we want to fail the transaction ourselves or not.
 1055+ */
 1056+ public function getCVVResult(){
 1057+ if ( is_null( $this->getData( 'cvv_result' ) ) ){
 1058+ return null;
 1059+ }
 1060+
 1061+ $result_map = array(
 1062+ 'M' => true, //CVV check performed and valid value.
 1063+ 'N' => false, //CVV checked and no match.
 1064+ 'P' => true, //CVV check not performed, not requested
 1065+ 'S' => false, //Card holder claims no CVV-code on card, issuer states CVV-code should be on card.
 1066+ 'U' => true, //? //Issuer not certified for CVV2.
 1067+ 'Y' => false, //Server provider did not respond.
 1068+ '0' => true, //No service available.
 1069+ );
 1070+
 1071+ $result = $result_map[$this->getData( 'cvv_result' )];
 1072+ return $result;
9311073
 1074+ }
 1075+
 1076+ /**
 1077+ * getAVSResult is intended to be used by the functions filter, to
 1078+ * determine if we want to fail the transaction ourselves or not.
 1079+ */
 1080+ public function getAVSResult(){
 1081+ if ( is_null( $this->getData( 'avs_result' ) ) ){
 1082+ return null;
 1083+ }
 1084+ //Best guess here:
 1085+ //Scale of 0 - 100, of Problem we think this result is likely to cause.
 1086+
 1087+ $result_map = array(
 1088+ 'A' => 50, //Address (Street) matches, Zip does not.
 1089+ 'B' => 50, //Street address match for international transactions. Postal code not verified due to incompatible formats.
 1090+ 'C' => 50, //Street address and postal code not verified for international transaction due to incompatible formats.
 1091+ 'D' => 0, //Street address and postal codes match for international transaction.
 1092+ 'E' => 100, //AVS Error.
 1093+ 'F' => 0, //Address does match and five digit ZIP code does match (UK only).
 1094+ 'G' => 50, //Address information is unavailable; international transaction; non-AVS participant.
 1095+ 'I' => 50, //Address information not verified for international transaction.
 1096+ 'M' => 0, //Street address and postal codes match for international transaction.
 1097+ 'N' => 100, //No Match on Address (Street) or Zip.
 1098+ 'P' => 50, //Postal codes match for international transaction. Street address not verified due to incompatible formats.
 1099+ 'R' => 100, //Retry, System unavailable or Timed out.
 1100+ 'S' => 50, //Service not supported by issuer.
 1101+ 'U' => 50, //Address information is unavailable.
 1102+ 'W' => 50, //9 digit Zip matches, Address (Street) does not.
 1103+ 'X' => 0, //Exact AVS Match.
 1104+ 'Y' => 0, //Address (Street) and 5 digit Zip match.
 1105+ 'Z' => 50, //5 digit Zip matches, Address (Street) does not.
 1106+ '0' => 50, //No service available.
 1107+ );
 1108+
 1109+ $result = $result_map[$this->getData( 'avs_result' )];
 1110+ return $result;
 1111+ }
 1112+
9321113 }
\ No newline at end of file
Index: trunk/extensions/DonationInterface/gateway_common/gateway.adapter.php
@@ -642,16 +642,19 @@
643643 * human-readable assessments of what happened, probably straight from
644644 * the gateway.
645645 * 'action' = (sometimes there) What the pre-commit hooks said we should go
646 - * do with ourselves. Mostly in there for debugging purposes at this
647 - * point, as nothing on the outside should care at all, how we do things
648 - * internally.
 646+ * do with ourselves, if they were fired off.
649647 * 'data' = The data passed back to us from the transaction, in a nice
650648 * key-value array.
651649 */
652650 public function do_transaction( $transaction ) {
 651+ //reset, in case this isn't our first time.
 652+ $this->transaction_results = array();
 653+ $this->setValidationAction('process', true);
 654+
653655 try {
654656 $this->setCurrentTransaction( $transaction );
655 - //update the contribution tracking data
 657+
 658+ //TODO: This is a problem here. Needs to be moved to pre_process or something.
656659 $this->incrementNumAttempt();
657660
658661 //If we have any special pre-process instructions for this
@@ -675,6 +678,7 @@
676679 );
677680 }
678681
 682+ //TODO: Maybe move this to the pre_process functions?
679683 $this->dataObj->updateContributionTracking( defined( 'OWA' ) );
680684
681685 // If the payment processor requires XML, package our data into XML.
@@ -732,6 +736,10 @@
733737
734738 //TODO: Death to the pulled_data parameter!
735739 $this->processResponse( $pulled_data ); //now we've set all the transaction results...
 740+
 741+ //well, almost all.
 742+ $this->setTransactionResult( $this->getValidationAction(), 'action' );
 743+
736744 } else {
737745 self::log( "Transaction Communication failed" . print_r( $this->getTransactionAllResults(), true ) );
738746 }
@@ -783,21 +791,20 @@
784792 // log that the transaction is essentially complete
785793 self::log( $this->getData( 'contribution_tracking_id' ) . " Transaction complete." );
786794
787 - //Session Handling
788795 //getTransactionStatus works here like this, because it only returns
789796 //something other than false if it's the sort of a transaction that can
790797 //denote a successful donation.
791 - $wmfStatus = $this->getTransactionWMFStatus();
792 - switch ( $wmfStatus ){
793 - case 'failed' : //only kill their session if they've tried three (or somehow more) times.
794 - if ( (int)$this->postdata['numAttempt'] < 3 ) {
795 - break;
796 - }
797 - case 'complete' :
798 - case 'pending' :
799 - case 'pending-poke' :
800 - $this->unsetAllSessionData();
801 - }
 798+// $wmfStatus = $this->getTransactionWMFStatus();
 799+// switch ( $wmfStatus ){
 800+// case 'failed' : //only kill their session if they've tried three (or somehow more) times.
 801+// if ( (int)$this->postdata['numAttempt'] < 3 ) {
 802+// break;
 803+// }
 804+// case 'complete' :
 805+// case 'pending' :
 806+// case 'pending-poke' :
 807+// $this->unsetAllSessionData();
 808+// }
802809
803810 $this->debugarray[] = 'numAttempt = ' . $this->postdata['numAttempt'];
804811

Follow-up revisions

RevisionCommit summaryAuthorDate
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

Comments

#Comment by Khorn (WMF) (talk | contribs)   03:14, 4 November 2011

There's still some work I need to get done on this, so while it probably won't make anything actually explode, please do not merge it into anything.

Status & tagging log