https://www.mediawiki.org/wiki/Special:Code/MediaWiki/101951
Revision: 101951
Author: khorn
Date: 2011-11-04 03:10:44 +0000 (Fri, 04 Nov 2011)
Log Message:
-----------
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
trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php
trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect_resultswitcher.body.php
Modified: trunk/extensions/DonationInterface/gateway_common/gateway.adapter.php
===================================================================
--- trunk/extensions/DonationInterface/gateway_common/gateway.adapter.php
2011-11-04 03:07:07 UTC (rev 101950)
+++ trunk/extensions/DonationInterface/gateway_common/gateway.adapter.php
2011-11-04 03:10:44 UTC (rev 101951)
@@ -642,16 +642,19 @@
* human-readable assessments of what happened, probably
straight from
* the gateway.
* 'action' = (sometimes there) What the pre-commit hooks said we
should go
- * do with ourselves. Mostly in there for debugging
purposes at this
- * point, as nothing on the outside should care at all,
how we do things
- * internally.
+ * do with ourselves, if they were fired off.
* 'data' = The data passed back to us from the transaction, in a
nice
* key-value array.
*/
public function do_transaction( $transaction ) {
+ //reset, in case this isn't our first time.
+ $this->transaction_results = array();
+ $this->setValidationAction('process', true);
+
try {
$this->setCurrentTransaction( $transaction );
- //update the contribution tracking data
+
+ //TODO: This is a problem here. Needs to be moved to
pre_process or something.
$this->incrementNumAttempt();
//If we have any special pre-process instructions for
this
@@ -675,6 +678,7 @@
);
}
+ //TODO: Maybe move this to the pre_process functions?
$this->dataObj->updateContributionTracking( defined(
'OWA' ) );
// If the payment processor requires XML, package our
data into XML.
@@ -732,6 +736,10 @@
//TODO: Death to the pulled_data parameter!
$this->processResponse( $pulled_data ); //now
we've set all the transaction results...
+
+ //well, almost all.
+ $this->setTransactionResult(
$this->getValidationAction(), 'action' );
+
} else {
self::log( "Transaction Communication failed" .
print_r( $this->getTransactionAllResults(), true ) );
}
@@ -783,21 +791,20 @@
// log that the transaction is essentially complete
self::log( $this->getData( 'contribution_tracking_id' ) . "
Transaction complete." );
- //Session Handling
//getTransactionStatus works here like this, because it only
returns
//something other than false if it's the sort of a transaction
that can
//denote a successful donation.
- $wmfStatus = $this->getTransactionWMFStatus();
- switch ( $wmfStatus ){
- case 'failed' : //only kill their session if they've
tried three (or somehow more) times.
- if ( (int)$this->postdata['numAttempt'] < 3 ) {
- break;
- }
- case 'complete' :
- case 'pending' :
- case 'pending-poke' :
- $this->unsetAllSessionData();
- }
+// $wmfStatus = $this->getTransactionWMFStatus();
+// switch ( $wmfStatus ){
+// case 'failed' : //only kill their session if they've
tried three (or somehow more) times.
+// if ( (int)$this->postdata['numAttempt'] < 3 ) {
+// break;
+// }
+// case 'complete' :
+// case 'pending' :
+// case 'pending-poke' :
+// $this->unsetAllSessionData();
+// }
$this->debugarray[] = 'numAttempt = ' .
$this->postdata['numAttempt'];
Modified:
trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php
===================================================================
---
trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php
2011-11-04 03:07:07 UTC (rev 101950)
+++
trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php
2011-11-04 03:10:44 UTC (rev 101951)
@@ -29,6 +29,7 @@
$this->var_map = array(
'ACCOUNTNAME' => 'account_name',
'ACCOUNTNUMBER' => 'account_number',
+ 'ATTEMPTID' => 'attempt_id',
'AUTHORIZATIONID' => 'authorization_id',
'AMOUNT' => 'amount',
'BANKCHECKDIGIT' => 'bank_check_digit',
@@ -43,6 +44,7 @@
'CVV' => 'cvv',
'DATECOLLECT' => 'date_collect',
'DIRECTDEBITTEXT' => 'direct_debit_text',
+ 'EFFORTID' => 'effort_id',
'EMAIL' => 'email',
'EXPIRYDATE' => 'expiration',
'FIRSTNAME' => 'fname',
@@ -61,6 +63,16 @@
'ZIP' => 'zip',
);
}
+
+ /**
+ * Setting some GC-specific defaults.
+ * @param array $options These get extracted in the parent.
+ */
+ function setPostDefaults( $options = array() ) {
+ parent::setPostDefaults( $options );
+ $this->postdatadefaults['attempt_id'] = '1';
+ $this->postdatadefaults['effort_id'] = '1';
+ }
/**
* Define return_value_map
@@ -231,6 +243,54 @@
'revised',
)
);
+
+ $this->transactions['CANCEL_PAYMENT'] = array(
+ 'request' => array(
+ 'REQUEST' => array(
+ 'ACTION',
+ 'META' => array(
+ 'MERCHANTID',
+ 'IPADDRESS',
+ 'VERSION'
+ ),
+ 'PARAMS' => array(
+ 'PAYMENT' => array(
+ 'ORDERID',
+ 'EFFORTID',
+ 'ATTEMPTID',
+ ),
+ )
+ )
+ ),
+ 'values' => array(
+ 'ACTION' => 'CANCEL_PAYMENT',
+ 'VERSION' => '1.0'
+ ),
+ );
+
+ $this->transactions['SET_PAYMENT'] = array(
+ 'request' => array(
+ 'REQUEST' => array(
+ 'ACTION',
+ 'META' => array(
+ 'MERCHANTID',
+ 'IPADDRESS',
+ 'VERSION'
+ ),
+ 'PARAMS' => array(
+ 'PAYMENT' => array(
+ 'ORDERID',
+ 'EFFORTID',
+ 'PAYMENTPRODUCTID',
+ ),
+ )
+ )
+ ),
+ 'values' => array(
+ 'ACTION' => 'SET_PAYMENT',
+ 'VERSION' => '1.0'
+ ),
+ );
}
/**
@@ -525,6 +585,76 @@
}
/**
+ * Because GC has some processes that involve more than one
do_transaction
+ * chained together, we're catching those special ones in an overload
and
+ * letting the rest behave normally.
+ */
+ public function do_transaction( $transaction ){
+ switch ( $transaction ){
+ case 'K4sVoodoo' :
+ return $this->doK4svoodoo();
+ break;
+ default:
+ return parent::do_transaction( $transaction );
+ }
+ }
+
+ //TODO: rename, yo.
+ private function doK4svoodoo(){
+ global $wgRequest; //this is for pulling vars straight from the
querystring
+ $pull_vars = array(
+ 'CVVRESULT' => 'cvv_result',
+ 'AVSRESULT' => 'avs_result',
+ );
+ $addme = array();
+ foreach ( $pull_vars as $theirkey => $ourkey) {
+ $tmp = $wgRequest->getVal( $theirkey, null );
+ if ( !is_null( $tmp ) ) {
+ $addme[$ourkey] = $tmp;
+ }
+ }
+ if ( count( $addme ) ){
+ $this->addData( $addme );
+ }
+
+ $status_result = $this->do_transaction( 'GET_ORDERSTATUS' );
+
+// $status_result['data'];
+//
+ //TODO: If we've already failed, flame out here instead of
later.
+
+ if ( isset( $status_result['data'] ) && is_array(
$status_result['data'] ) ){
+ //if they're set, get CVVRESULT && AVSRESULT
+ $pull_vars['EFFORTID'] = 'effort_id';
+ $pull_vars['ATTEMPTID'] = 'attempt_id';
+ $addme = array();
+ foreach ( $pull_vars as $theirkey => $ourkey) {
+ if ( array_key_exists( $theirkey,
$status_result['data'] ) ){
+ $addme[$ourkey] =
$status_result['data'][$theirkey];
+ }
+ }
+
+ if ( count( $addme ) ){
+ $this->addData( $addme );
+ }
+
+ //now, either do a cancel or a process, depending on
what the filters
+ //said we should do.
+ switch ( $status_result['action'] ){
+ case 'process' :
+ $final = $this->do_transaction(
'SET_PAYMENT' );
+ break;
+ case 'reject' :
+ $final = $this->do_transaction(
'CANCEL_PAYMENT' );
+ break;
+ }
+ return $final;
+ }
+// error_log("Got nothing good back from the first call...");
+ return $status_result;
+ }
+
+ /**
* Take the entire response string, and strip everything we don't care
about.
* For instance: If it's XML, we only want correctly-formatted XML.
Headers must be killed off.
* return a string.
@@ -904,28 +1034,79 @@
protected function pre_process_insert_orderwithpayment(){
if ( $this->getData( 'payment_method' ) === 'cc' ){
- $this->runPreProcessHooks(); //this is shortly to move
elsewhere.
$this->addDonorDataToSession();
}
}
protected function pre_process_get_orderstatus(){
if ( $this->getData( 'payment_method' ) === 'cc' ){
- //if they're set, get CVVRESULT && AVSRESULT
- global $wgRequest;
- $cvv_result = $wgRequest->getVal( 'CVVRESULT', null );
- $avs_result = $wgRequest->getVal( 'AVSRESULT', null );
- if ( !is_null($cvv_result) ){
- $this->debugarray[] = "CVV result: $cvv_result";
- }
- if ( !is_null($avs_result) ){
- $this->debugarray[] = "AVS result: $avs_result";
- }
+ $this->runPreProcessHooks();
}
}
protected function post_process_get_orderstatus(){
$this->runPostProcessHooks();
}
+
+ /**
+ * getCVVResult is intended to be used by the functions filter, to
+ * determine if we want to fail the transaction ourselves or not.
+ */
+ public function getCVVResult(){
+ if ( is_null( $this->getData( 'cvv_result' ) ) ){
+ return null;
+ }
+
+ $result_map = array(
+ 'M' => true, //CVV check performed and valid value.
+ 'N' => false, //CVV checked and no match.
+ 'P' => true, //CVV check not performed, not requested
+ 'S' => false, //Card holder claims no CVV-code on card,
issuer states CVV-code should be on card.
+ 'U' => true, //? //Issuer not certified for CVV2.
+ 'Y' => false, //Server provider did not respond.
+ '0' => true, //No service available.
+ );
+
+ $result = $result_map[$this->getData( 'cvv_result' )];
+ return $result;
+ }
+
+ /**
+ * getAVSResult is intended to be used by the functions filter, to
+ * determine if we want to fail the transaction ourselves or not.
+ */
+ public function getAVSResult(){
+ if ( is_null( $this->getData( 'avs_result' ) ) ){
+ return null;
+ }
+ //Best guess here:
+ //Scale of 0 - 100, of Problem we think this result is likely
to cause.
+
+ $result_map = array(
+ 'A' => 50, //Address (Street) matches, Zip does not.
+ 'B' => 50, //Street address match for international
transactions. Postal code not verified due to incompatible formats.
+ 'C' => 50, //Street address and postal code not
verified for international transaction due to incompatible formats.
+ 'D' => 0, //Street address and postal codes match for
international transaction.
+ 'E' => 100, //AVS Error.
+ 'F' => 0, //Address does match and five digit ZIP code
does match (UK only).
+ 'G' => 50, //Address information is unavailable;
international transaction; non-AVS participant.
+ 'I' => 50, //Address information not verified for
international transaction.
+ 'M' => 0, //Street address and postal codes match for
international transaction.
+ 'N' => 100, //No Match on Address (Street) or Zip.
+ 'P' => 50, //Postal codes match for international
transaction. Street address not verified due to incompatible formats.
+ 'R' => 100, //Retry, System unavailable or Timed out.
+ 'S' => 50, //Service not supported by issuer.
+ 'U' => 50, //Address information is unavailable.
+ 'W' => 50, //9 digit Zip matches, Address (Street) does
not.
+ 'X' => 0, //Exact AVS Match.
+ 'Y' => 0, //Address (Street) and 5 digit Zip match.
+ 'Z' => 50, //5 digit Zip matches, Address (Street) does
not.
+ '0' => 50, //No service available.
+ );
+
+ $result = $result_map[$this->getData( 'avs_result' )];
+ return $result;
+ }
+
}
\ No newline at end of file
Modified:
trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect_resultswitcher.body.php
===================================================================
---
trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect_resultswitcher.body.php
2011-11-04 03:07:07 UTC (rev 101950)
+++
trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect_resultswitcher.body.php
2011-11-04 03:10:44 UTC (rev 101951)
@@ -66,7 +66,7 @@
$adapter_oid = $adapter_oid['order_id'];
if ( $oid && !empty( $oid ) && $oid === $adapter_oid ) {
if ( !array_key_exists( 'order_status',
$_SESSION ) || !array_key_exists( $oid, $_SESSION['order_status'] ) ) {
- $_SESSION['order_status'][$oid] =
$this->adapter->do_transaction( 'GET_ORDERSTATUS' );
+ $_SESSION['order_status'][$oid] =
$this->adapter->do_transaction( 'K4sVoodoo' );
$_SESSION['order_status'][$oid]['data']['count'] = 0;
} else {
$_SESSION['order_status'][$oid]['data']['count'] =
$_SESSION['order_status'][$oid]['data']['count'] + 1;
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs