r98498 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98497‎ | r98498 | r98499 >
Date:01:45, 30 September 2011
Author:khorn
Status:ok (Comments)
Tags:fundraising 
Comment:
Rebuilding the payflowpro gateway and adapter, Part 2 of Several!
This giant chunk focuses mainly on getting the Extras in to the abstraction game. This involved redefining all of the hooks, and writing some get/set functions on the gateway adapter objects, among other things.
Modified paths:
  • /branches/fundraising/extensions/DonationInterface/extras/conversion_log/conversion_log.body.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/extras/conversion_log/conversion_log.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/extras/custom_filters/custom_filters.body.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/extras/custom_filters/custom_filters.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/extras/custom_filters/filters/minfraud/minfraud.body.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/extras/custom_filters/filters/minfraud/minfraud.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/extras/custom_filters/filters/referrer/referrer.body.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/extras/custom_filters/filters/referrer/referrer.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/extras/custom_filters/filters/source/source.body.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/extras/custom_filters/filters/source/source.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/extras/extras.body.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/extras/extras.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/extras/minfraud/ccfd/CreditCardFraudDetection.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/extras/minfraud/ccfd/HTTPBase.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/extras/minfraud/ccfd/LocationVerification.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/extras/minfraud/ccfd/TelephoneVerification.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/extras/minfraud/minfraud.body.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/extras/minfraud/minfraud.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/extras/minfraud/tests/minfraudTest.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/extras/recaptcha/recaptcha-php/recaptchalib.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/extras/recaptcha/recaptcha.body.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/extras/recaptcha/recaptcha.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/gateway_common/DonationData.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/gateway_common/GatewayForm.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/gateway_common/gateway.adapter.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/gateway_forms/Form.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)
  • /branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect_resultswitcher.body.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/payflowpro_gateway/payflowpro.adapter.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php (modified) (history)

Diff [purge]

Index: branches/fundraising/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php
@@ -22,7 +22,7 @@
2323 $wgOut->addExtensionStyle(
2424 $wgExtensionAssetsPath . '/DonationInterface/gateway_forms/css/gateway.css?284' .
2525 $CSSVersion );
26 -
 26+
2727 // Hide unneeded interface elements
2828 $wgOut->addModules( 'donationInterface.skinOverride' );
2929
@@ -63,8 +63,6 @@
6464 // The form was submitted and the payment method has been set
6565 $this->adapter->log( "Form posted and payment method set." );
6666
67 - // increase the count of attempts
68 - //++$data['numAttempt'];
6967 // Check form for errors
7068 $form_errors = $this->fnValidateForm( $data, $this->errors );
7169
@@ -74,25 +72,25 @@
7573 } else { // The submitted form data is valid, so process it
7674 // allow any external validators to have their way with the data
7775 self::log( $data['order_id'] . " Preparing to query MaxMind" );
78 - wfRunHooks( 'PayflowGatewayValidate', array( &$this, &$data ) );
 76+ wfRunHooks( 'GatewayValidate', array( &$this->adapter ) );
7977 self::log( $data['order_id'] . ' Finished querying Maxmind' );
8078
8179 // if the transaction was flagged for review
8280 if ( $this->action == 'review' ) {
8381 // expose a hook for external handling of trxns flagged for review
84 - wfRunHooks( 'PayflowGatewayReview', array( &$this, &$data ) );
 82+ wfRunHooks( 'GatewayReview', array( &$this->adapter ) );
8583 }
8684
8785 // if the transaction was flagged to be 'challenged'
8886 if ( $this->action == 'challenge' ) {
8987 // expose a hook for external handling of trxns flagged for challenge (eg captcha)
90 - wfRunHooks( 'PayflowGatewayChallenge', array( &$this, &$data ) );
 88+ wfRunHooks( 'GatewayChallenge', array( &$this->adapter ) );
9189 }
9290
9391 // if the transaction was flagged for rejection
9492 if ( $this->action == 'reject' ) {
9593 // expose a hook for external handling of trxns flagged for rejection
96 - wfRunHooks( 'PayflowGatewayReject', array( &$this, &$data ) );
 94+ wfRunHooks( 'GatewayReject', array( &$this->adapter ) );
9795
9896 $this->fnPayflowDisplayDeclinedResults( '' );
9997 $this->fnPayflowUnsetEditToken();
@@ -101,12 +99,12 @@
102100 // if the transaction was flagged for processing
103101 if ( $this->action == 'process' ) {
104102 // expose a hook for external handling of trxns ready for processing
105 - wfRunHooks( 'PayflowGatewayProcess', array( &$this, &$data ) );
 103+ wfRunHooks( 'GatewayProcess', array( &$this->adapter ) );
106104 $this->fnPayflowProcessTransaction( $data, $payflow_data );
107105 }
108106
109107 // expose a hook for any post processing
110 - wfRunHooks( 'PayflowGatewayPostProcess', array( &$this, &$data ) );
 108+ wfRunHooks( 'GatewayPostProcess', array( &$this->adapter ) );
111109 }
112110 } else {
113111 // Display form for the first time
@@ -380,7 +378,7 @@
381379 $wgOut->addHTML( '<h3 class="response_message">' . $responseMsg . '</h3>' );
382380
383381 // translate country code into text
384 - $countries = $this->getCountries();
 382+ $countries = GatewayForm::getCountries();
385383
386384 $rows = array(
387385 'title' => array( wfMsg( 'payflowpro_gateway-post-transaction' ) ),
Index: branches/fundraising/extensions/DonationInterface/payflowpro_gateway/payflowpro.adapter.php
@@ -104,7 +104,7 @@
105105 $responseArray[$key] = $value;
106106 }
107107
108 - self::log( "Here is the response as an array: " . print_r( $responseArray, true ) ); //I am apparently a huge fibber.
 108+ self::log( "Here is the response as an array: " . print_r( $responseArray, true ) );
109109 return $responseArray;
110110 }
111111
@@ -121,8 +121,11 @@
122122 }
123123
124124 /**
125 - * Parse the response to get the errors in a format we can log and otherwise deal with.
126 - * return a key/value array of codes (if they exist) and messages.
 125+ * Interpret response code, return
 126+ * 1 if approved
 127+ * 2 if declined
 128+ * 3 if invalid data was submitted by user
 129+ * 4 all other errors
127130 */
128131 function getResponseErrors( $response ) {
129132
@@ -188,7 +191,8 @@
189192 * Process the entire response gott'd by the last four functions.
190193 */
191194 function processResponse( $response ) {
192 -
 195+ //set the transaction result message
 196+ $this->setTransactionResult( $response['RESPMSG'], 'txn_message' );
193197 }
194198
195199 function defineStagedVars() {
Index: branches/fundraising/extensions/DonationInterface/extras/custom_filters/custom_filters.body.php
@@ -1,6 +1,7 @@
22 <?php
33
4 -class PayflowProGateway_Extras_CustomFilters extends PayflowProGateway_Extras {
 4+class Gateway_Extras_CustomFilters extends Gateway_Extras {
 5+
56 /**
67 * A value for tracking the 'riskiness' of a transaction
78 *
@@ -18,35 +19,15 @@
1920 public $action_ranges;
2021
2122 /**
22 - * A container for the gateway object
23 - *
24 - * This gets populated on construction.
25 - * @var object
26 - */
27 - public $gateway_object;
28 -
29 - /**
30 - * A container for data from the gateway
31 - *
32 - * This gets populated on construction.
33 - */
34 - public $gateway_data;
35 -
36 - /**
3723 * A container for an instance of self
3824 */
3925 static $instance;
4026
41 - public function __construct( &$pfp_gateway_object, &$data ) {
42 - parent::__construct();
43 -
44 - $this->gateway_object =& $pfp_gateway_object;
45 - $this->gateway_data =& $data;
46 -
47 - // load user action ranges and risk score
48 - global $wgPayflowGatewayCustomFiltersActionRanges, $wgPayflowGatewayCustomFiltersRiskScore;
49 - if ( isset( $wgPayflowGatewayCustomFiltersActionRanges ) ) $this->action_ranges = $wgPayflowGatewayCustomFiltersActionRanges;
50 - if ( isset( $wgPayflowGatewayCustomFiltersRiskScore ) ) $this->risk_score = $wgPayflowGatewayCustomFiltersRiskScore;
 27+ public function __construct( &$gateway_adapter ) {
 28+ parent::__construct( &$gateway_adapter ); //gateway_adapter is set in there.
 29+ // load user action ranges and risk score
 30+ $this->action_ranges = $this->getGlobal( 'CustomFiltersActionRanges' );
 31+ $this->risk_score = $this->getGlobal( 'CustomFiltersRiskScore' );
5132 }
5233
5334 /**
@@ -56,11 +37,13 @@
5738 */
5839 public function determineAction() {
5940 // possible risk scores are between 0 and 100
60 - if ( $this->risk_score < 0 ) $this->risk_score = 0;
61 - if ( $this->risk_score > 100 ) $this->risk_score = 100;
 41+ if ( $this->risk_score < 0 )
 42+ $this->risk_score = 0;
 43+ if ( $this->risk_score > 100 )
 44+ $this->risk_score = 100;
6245
6346 foreach ( $this->action_ranges as $action => $range ) {
64 - if ( $this->risk_score >= $range[0] && $this->risk_score <= $range[1] ) {
 47+ if ( $this->risk_score >= $range[0] && $this->risk_score <= $range[1] ) {
6548 return $action;
6649 }
6750 }
@@ -71,22 +54,23 @@
7255 */
7356 public function validate() {
7457 // expose a hook for custom filters
75 - wfRunHooks( 'PayflowGatewayCustomFilter', array( &$this ) );
76 - $this->gateway_object->action = $this->determineAction();
 58+ wfRunHooks( 'GatewayCustomFilter', array( &$this->gateway_adapter, &$this ) );
 59+ $this->gateway_adapter->action = $this->determineAction();
7760
78 - $log_msg = '"' . $this->gateway_object->action . "\"\t\"" . $this->risk_score . "\"";
79 - $this->log( $this->gateway_data['contribution_tracking_id'], 'Filtered', $log_msg );
 61+ $log_msg = '"' . $this->gateway_adapter->action . "\"\t\"" . $this->risk_score . "\"";
 62+ $this->log( $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'Filtered', $log_msg );
8063 return TRUE;
8164 }
8265
83 - static function onValidate( &$pfp_gateway_object, &$data ) {
84 - return self::singleton( $pfp_gateway_object, $data )->validate();
 66+ static function onValidate( &$gateway_adapter ) {
 67+ return self::singleton( &$gateway_adapter )->validate();
8568 }
8669
87 - static function singleton( &$pfp_gateway_object, &$data ) {
 70+ static function singleton( &$gateway_adapter ) {
8871 if ( !self::$instance ) {
89 - self::$instance = new self( $pfp_gateway_object, $data );
 72+ self::$instance = new self( &$gateway_adapter );
9073 }
9174 return self::$instance;
9275 }
 76+
9377 }
Index: branches/fundraising/extensions/DonationInterface/extras/custom_filters/custom_filters.php
@@ -1,4 +1,5 @@
22 <?php
 3+
34 /**
45 * Provides a unified way to define and run custom filters for incoming transactions
56 *
@@ -7,30 +8,29 @@
89 * needed to perform more complex validation/filtering of transactions.
910 *
1011 * The actual filters themselves are regular MW extensions and can optional be organized in filters/
11 - * They should be invoked by using the 'PayflowGatewayCustomFilter' hook, which will pass the entire
 12+ * They should be invoked by using the 'GatewayCustomFilter' hook, which will pass the entire
1213 * CustomFilter object to the filter. The gateway object and its data are included in the CustomFilter
1314 * object.
1415 */
15 -
1616 if ( !defined( 'MEDIAWIKI' ) ) {
17 - die( "This file is part of the MinFraud for PayflowPro Gateway extension. It is not a valid entry point.\n" );
 17+ die( "This file is part of the MinFraud for Gateway extension. It is not a valid entry point.\n" );
1818 }
1919
20 -$wgExtensionCredits['payflowprogateway_custom_filters'][] = array(
21 - 'name' => 'custom filters',
22 - 'author' => 'Arthur Richards',
23 - 'url' => '',
24 - 'description' => 'This extension provides a way to define custom filters for incoming transactions for the Payflow Pro gateway.'
 20+$wgExtensionCredits['gateway_custom_filters'][] = array(
 21+ 'name' => 'custom filters',
 22+ 'author' => 'Arthur Richards',
 23+ 'url' => '',
 24+ 'description' => 'This extension provides a way to define custom filters for incoming transactions for the gateway.'
2525 );
2626
2727 /**
2828 * Define the action to take for a given $risk_score
2929 */
30 -$wgPayflowGatewayCustomFiltersActionRanges = array(
31 - 'process' => array( 0, 100 ),
32 - 'review' => array( -1, -1 ),
 30+$wgDonationInterfaceCustomFiltersActionRanges = array(
 31+ 'process' => array( 0, 100 ),
 32+ 'review' => array( -1, -1 ),
3333 'challenge' => array( -1, -1 ),
34 - 'reject' => array( -1, -1 ),
 34+ 'reject' => array( -1, -1 ),
3535 );
3636
3737 /**
@@ -40,9 +40,9 @@
4141 * $action_ranges. This is built assuming a range of possible risk scores
4242 * as 0-100, although you can probably bend this as needed.
4343 */
44 -$wgPayflowGatewayCustomFiltersRiskScore = 0;
 44+$wgDonationInterfaceCustomFiltersRiskScore = 0;
4545
4646 $dir = dirname( __FILE__ ) . "/";
47 -$wgAutoloadClasses['PayflowProGateway_Extras_CustomFilters'] = $dir . "custom_filters.body.php";
 47+$wgAutoloadClasses['Gateway_Extras_CustomFilters'] = $dir . "custom_filters.body.php";
4848
49 -$wgHooks["PayflowGatewayValidate"][] = array( 'PayflowProGateway_Extras_CustomFilters::onValidate' );
 49+$wgHooks["GatewayValidate"][] = array( 'Gateway_Extras_CustomFilters::onValidate' );
Index: branches/fundraising/extensions/DonationInterface/extras/custom_filters/filters/source/source.body.php
@@ -1,6 +1,7 @@
22 <?php
33
4 -class PayflowProGateway_Extras_CustomFilters_Source extends PayflowProGateway_Extras {
 4+class Gateway_Extras_CustomFilters_Source extends Gateway_Extras {
 5+
56 /**
67 * Container for an instance of self
78 * @var object
@@ -13,14 +14,14 @@
1415 */
1516 public $cfo;
1617
17 - public function __construct( &$custom_filter_object ) {
18 - parent::__construct();
19 - $this->cfo =& $custom_filter_object;
 18+ public function __construct( &$gateway_adapter, &$custom_filter_object ) {
 19+ parent::__construct( &$gateway_adapter );
 20+ $this->cfo = & $custom_filter_object;
2021 }
2122
2223 public function filter() {
2324 // pull out the source from the filter object
24 - $source = $this->cfo->gateway_data['utm_source'];
 25+ $source = $this->gateway_adapter->getData( 'utm_source' );
2526
2627 // a very complex filtering algorithm for sources
2728 global $wgCustomFiltersSrcRules;
@@ -37,9 +38,7 @@
3839 $log_msg .= "\t\"" . addslashes( $regex ) . "\"";
3940 $log_msg .= "\t\"" . $this->cfo->risk_score . "\"";
4041 $this->log(
41 - $this->cfo->gateway_data['contribution_tracking_id'],
42 - 'Filter: Source',
43 - $log_msg
 42+ $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'Filter: Source', $log_msg
4443 );
4544 }
4645 }
@@ -57,4 +56,5 @@
5857 }
5958 return self::$instance;
6059 }
 60+
6161 }
Index: branches/fundraising/extensions/DonationInterface/extras/custom_filters/filters/source/source.php
@@ -1,16 +1,16 @@
22 <?php
 3+
34 /**
45 * Provides a method for filtering transactions based on source
56 *
67 * To install:
78 * require_once( "$IP/extensions/DonationInterface/extras/custom_filters/filters/source/source.php" );
89 */
9 -
1010 if ( !defined( 'MEDIAWIKI' ) ) {
11 - die( "This file is part of the source custom filter part of the PayflowPro Gateway extension. It is not a valid entry point\n" );
 11+ die( "This file is part of the source custom filter part of the Gateway extension. It is not a valid entry point\n" );
1212 }
1313
14 -$wgExtensionCredits['payflowprogateway_customfilters_source'][] = array(
 14+$wgExtensionCredits['gateway_customfilters_source'][] = array(
1515 'name' => 'custom filter: source',
1616 'author' => 'Arthur Richards',
1717 'url' => '',
@@ -28,7 +28,7 @@
2929 * $wgCustomFiltersSrcRules['support.cc'] = "100";
3030 * // increases risk score for trxns with source of 'support.cc' referrals by 100
3131 */
32 -$wgCustomFiltersSrcRules = array();
 32+$wgCustomFiltersSrcRules = array( );
3333
34 -$wgAutoloadClasses['PayflowProGateway_Extras_CustomFilters_Source'] = dirname( __FILE__ ) . "/source.body.php";
35 -$wgHooks["PayflowGatewayCustomFilter"][] = array( 'PayflowProGateway_Extras_CustomFilters_Source::onFilter' );
 34+$wgAutoloadClasses['Gateway_Extras_CustomFilters_Source'] = dirname( __FILE__ ) . "/source.body.php";
 35+$wgHooks["GatewayCustomFilter"][] = array( 'Gateway_Extras_CustomFilters_Source::onFilter' );
Index: branches/fundraising/extensions/DonationInterface/extras/custom_filters/filters/minfraud/minfraud.body.php
@@ -1,4 +1,5 @@
22 <?php
 3+
34 /**
45 * Wrapper for using minFraud extra as a custom filter
56 *
@@ -6,37 +7,34 @@
78 * with slight modifications. So all we do here is overload validate()
89 * and add in some extra customFilters specific stuff.
910 */
 11+class Gateway_Extras_CustomFilters_MinFraud extends Gateway_Extras_MinFraud {
1012
11 -class PayflowProGateway_Extras_CustomFilters_MinFraud extends PayflowProGateway_Extras_MinFraud {
1213 static $instance;
1314
1415 public function filter( &$custom_filter_object ) {
15 - $pfp_gateway_object =& $custom_filter_object->gateway_object;
16 - $data =& $custom_filter_object->gateway_data;
17 -
1816 // see if we can bypass minfraud
19 - if ( $this->can_bypass_minfraud( $pfp_gateway_object, $data ) ) return TRUE;
 17+ if ( $this->can_bypass_minfraud() )
 18+ return TRUE;
2019
21 - $minfraud_query = $this->build_query( $data );
22 - $this->query_minfraud( $minfraud_query );
23 - $pfp_gateway_object->action = 'Filter';
 20+ $minfraud_query = $this->build_query( $this->gateway_adapter->getData() );
 21+ $this->query_minfraud( $minfraud_query );
 22+ $this->gateway_adapter->action = 'Filter';
2423
2524 $custom_filter_object->risk_score += $this->minfraud_response['riskScore'];
2625
2726 // Write the query/response to the log
2827 // @fixme this will cause the 'action' to be logged even though it's premature here
29 - $this->log_query( $minfraud_query, $pfp_gateway_object, $data );
 28+ $this->log_query( $minfraud_query );
3029 return TRUE;
31 -
3230 }
3331
34 - static function onFilter( &$custom_filter_object ) {
35 - return self::singleton()->filter( $custom_filter_object );
 32+ static function onFilter( &$gateway_adapter, &$custom_filter_object ) {
 33+ return self::singleton( &$gateway_adapter )->filter( $custom_filter_object );
3634 }
3735
38 - static function singleton() {
 36+ static function singleton( &$gateway_adapter ) {
3937 if ( !self::$instance ) {
40 - self::$instance = new self;
 38+ self::$instance = new self( &$gateway_adapter );
4139 }
4240 return self::$instance;
4341 }
Index: branches/fundraising/extensions/DonationInterface/extras/custom_filters/filters/minfraud/minfraud.php
@@ -1,4 +1,5 @@
22 <?php
 3+
34 /**
45 * Custom filter using minFraud
56 *
@@ -14,12 +15,11 @@
1516 * To install:
1617 * require_once( "$IP/extensions/DonationInterface/extras/custom_filters/filters/minfraud.php" );
1718 */
18 -
19 - $wgExtensionCredits['payflowprogateway_extras_customfilters_minfraud'][] = array(
20 - 'name' => 'minfraud custom filter',
 19+$wgExtensionCredits['gateway_extras_customfilters_minfraud'][] = array(
 20+ 'name' => 'minfraud custom filter',
2121 'author' => 'Arthur Richards',
2222 'url' => '',
23 - 'description' => 'This extension uses the MaxMind minFraud service as a validator for the Payflow Pro gateway via custom filters.'
 23+ 'description' => 'This extension uses the MaxMind minFraud service as a validator for the gateway via custom filters.'
2424 );
2525
2626 /**
@@ -36,11 +36,12 @@
3737 $wgMinFraudStandalone = FALSE;
3838
3939 $dir = dirname( __FILE__ ) . "/";
40 -$wgAutoloadClasses['PayflowProGateway_Extras_MinFraud'] = $dir . "../../../minfraud/minfraud.body.php";
41 -$wgAutoloadClasses['PayflowProGateway_Extras_CustomFilters_MinFraud'] = $dir . "minfraud.body.php";
 40+$wgAutoloadClasses['Gateway_Extras_MinFraud'] = $dir . "../../../minfraud/minfraud.body.php";
 41+$wgAutoloadClasses['Gateway_Extras_CustomFilters_MinFraud'] = $dir . "minfraud.body.php";
4242 $wgExtensionFunctions[] = 'efCustomFiltersMinFraudSetup';
4343
4444 function efCustomFiltersMinFraudSetup() {
4545 global $wgMinFraudStandalone, $wgHooks;
46 - if ( !$wgMinFraudStandalone ) $wgHooks[ 'PayflowGatewayCustomFilter' ][] = array( "PayflowProGateway_Extras_CustomFilters_MinFraud::onFilter" );
 46+ if ( !$wgMinFraudStandalone )
 47+ $wgHooks['GatewayCustomFilter'][] = array( "Gateway_Extras_CustomFilters_MinFraud::onFilter" );
4748 }
Index: branches/fundraising/extensions/DonationInterface/extras/custom_filters/filters/referrer/referrer.php
@@ -1,16 +1,16 @@
22 <?php
 3+
34 /**
45 * Provides a method for filtering transactions based on referrer
56 *
67 * To install:
78 * require_once( "$IP/extensions/DonationInterface/extras/custom_filters/filters/referrer/referrer.php" );
89 */
9 -
1010 if ( !defined( 'MEDIAWIKI' ) ) {
11 - die( "This file is part of the referrer custom filter part of the PayflowPro Gateway extension. It is not a valid entry point\n" );
 11+ die( "This file is part of the referrer custom filter part of the Gateway extension. It is not a valid entry point\n" );
1212 }
1313
14 -$wgExtensionCredits['payflowprogateway_customfilters_referrer'][] = array(
 14+$wgExtensionCredits['gateway_customfilters_referrer'][] = array(
1515 'name' => 'custom filter: referrer',
1616 'author' => 'Arthur Richards',
1717 'url' => '',
@@ -28,7 +28,7 @@
2929 * $wgCustomFiltersRefRules['fraud\.com'] = "100";
3030 * // increases risk score for trxns with http://fraud.com referrals by 100
3131 */
32 -$wgCustomFiltersRefRules = array();
 32+$wgCustomFiltersRefRules = array( );
3333
34 -$wgAutoloadClasses['PayflowProGateway_Extras_CustomFilters_Referrer'] = dirname( __FILE__ ) . "/referrer.body.php";
35 -$wgHooks["PayflowGatewayCustomFilter"][] = array( 'PayflowProGateway_Extras_CustomFilters_Referrer::onFilter' );
 34+$wgAutoloadClasses['Gateway_Extras_CustomFilters_Referrer'] = dirname( __FILE__ ) . "/referrer.body.php";
 35+$wgHooks["GatewayCustomFilter"][] = array( 'Gateway_Extras_CustomFilters_Referrer::onFilter' );
Index: branches/fundraising/extensions/DonationInterface/extras/custom_filters/filters/referrer/referrer.body.php
@@ -1,6 +1,7 @@
22 <?php
33
4 -class PayflowProGateway_Extras_CustomFilters_Referrer extends PayflowProGateway_Extras {
 4+class Gateway_Extras_CustomFilters_Referrer extends Gateway_Extras {
 5+
56 /**
67 * Container for an instance of self
78 * @var object
@@ -13,14 +14,14 @@
1415 */
1516 public $cfo;
1617
17 - public function __construct( &$custom_filter_object ) {
18 - parent::__construct();
19 - $this->cfo =& $custom_filter_object;
 18+ public function __construct( &$gateway_adapter, &$custom_filter_object ) {
 19+ parent::__construct( &$gateway_adapter );
 20+ $this->cfo = & $custom_filter_object;
2021 }
2122
2223 public function filter() {
23 - // pull out the referrer from the filter object
24 - $referrer = $this->cfo->gateway_data['referrer'];
 24+ // pull out the referrer from the gateway_adapter
 25+ $referrer = $this->gateway_adapter->getData( 'referrer' );
2526
2627 // a very complex filtering algorithm for referrers
2728 global $wgCustomFiltersRefRules;
@@ -37,9 +38,7 @@
3839 $log_msg .= "\t\"" . addslashes( $regex ) . "\"";
3940 $log_msg .= "\t\"" . $this->cfo->risk_score . "\"";
4041 $this->log(
41 - $this->cfo->gateway_data['contribution_tracking_id'],
42 - 'Filter: Referrer',
43 - $log_msg
 42+ $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'Filter: Referrer', $log_msg
4443 );
4544 }
4645 }
@@ -57,4 +56,5 @@
5857 }
5958 return self::$instance;
6059 }
 60+
6161 }
Index: branches/fundraising/extensions/DonationInterface/extras/minfraud/ccfd/HTTPBase.php
@@ -20,6 +20,7 @@
2121 */
2222
2323 class HTTPBase {
 24+
2425 var $server;
2526 var $numservers;
2627 var $url;
@@ -35,406 +36,408 @@
3637 var $wsIpaddrCacheFile;
3738 var $useDNS;
3839 var $ipstr;
39 - function __construct() {
40 - $this->isSecure = 0;
41 - $this->debug = 0;
42 - $this->timeout = 0;
43 - $this->check_field = "score";
44 - $this->wsIpaddrRefreshTimeout = 18000;
45 - $this->wsIpaddrCacheFile = $this->_getTempDir() . "/maxmind.ws.cache";
46 - if ( $this->debug == 1 ) {
47 - print "wsIpaddrRefreshTimeout: " . $this->wsIpaddrRefreshTimeout . "\n";
48 - print "wsIpaddrCacheFile: " . $this->wsIpaddrCacheFile . "\n";
49 - print "useDNS: " . $this->useDNS . "\n";
50 - }
51 - }
5240
53 - // this function sets the checked field
54 - function set_check_field( $f ) {
55 - $this->check_field = $f;
56 - }
 41+ //TODO: Instead of passing the gateway_adapter all over the place, we might consider integrating everything for real.
 42+ function __construct( &$gateway_adapter ) {
 43+ $this->gateway_adapter = &$gateway_adapter;
 44+ $this->isSecure = 0;
 45+ $this->debug = 0;
 46+ $this->timeout = 0;
 47+ $this->check_field = "score";
 48+ $this->wsIpaddrRefreshTimeout = 18000;
 49+ $this->wsIpaddrCacheFile = $this->_getTempDir() . "/maxmind.ws.cache";
 50+ if ( $this->debug == 1 ) {
 51+ print "wsIpaddrRefreshTimeout: " . $this->wsIpaddrRefreshTimeout . "\n";
 52+ print "wsIpaddrCacheFile: " . $this->wsIpaddrCacheFile . "\n";
 53+ print "useDNS: " . $this->useDNS . "\n";
 54+ }
 55+ }
5756
58 - // this function sets the allowed fields
59 - function set_allowed_fields( $i ) {
60 - $this->allowed_fields = $i;
61 - $this->num_allowed_fields = count( $i );
62 - }
 57+ // this function sets the checked field
 58+ function set_check_field( $f ) {
 59+ $this->check_field = $f;
 60+ }
6361
64 - // this function queries the servers
65 - function query() {
66 - // query every server in the list
67 - if ( !$this->useDNS ) {
68 - $ipstr = $this->readIpAddressFromCache();
69 - if ( $this->debug == 1 ) {
70 - print "using ip addresses, IPs are " . $ipstr . "\n";
71 - }
72 - }
73 - // query every server using its ip address
74 - // if there was success reading the ip addresses
75 - // from the web or the cache file
76 - if ( $ipstr ) {
77 - $ipaddr = explode( ";", $ipstr );
78 - $numipaddr = count( $ipaddr );
79 - for ( $i = 0; $i < $numipaddr; $i++ ) {
80 - $result = $this->querySingleServer( $ipaddr[$i] );
81 - if ( $this->debug == 1 ) {
82 - print "ip address: " . $ipaddr[$i] . "\n";
83 - print "result: " . $result . "\n";
 62+ // this function sets the allowed fields
 63+ function set_allowed_fields( $i ) {
 64+ $this->allowed_fields = $i;
 65+ $this->num_allowed_fields = count( $i );
8466 }
85 - if ( $result ) {
86 - return $result;
87 - }
88 - }
89 - }
9067
91 - // query every server using its domain name
92 - for ( $i = 0; $i < $this->numservers; $i++ ) {
93 - $result = $this->querySingleServer( $this->server[$i] );
94 - if ( $this->debug == 1 ) {
95 - print "server: " . $this->server[$i] . "\nresult: " . $result . "\n";
96 - }
97 - if ( $result ) {
98 - return $result;
99 - }
100 - }
101 - return 0;
102 - }
 68+ // this function queries the servers
 69+ function query() {
 70+ // query every server in the list
 71+ if ( !$this->useDNS ) {
 72+ $ipstr = $this->readIpAddressFromCache();
 73+ if ( $this->debug == 1 ) {
 74+ print "using ip addresses, IPs are " . $ipstr . "\n";
 75+ }
 76+ }
 77+ // query every server using its ip address
 78+ // if there was success reading the ip addresses
 79+ // from the web or the cache file
 80+ if ( $ipstr ) {
 81+ $ipaddr = explode( ";", $ipstr );
 82+ $numipaddr = count( $ipaddr );
 83+ for ( $i = 0; $i < $numipaddr; $i++ ) {
 84+ $result = $this->querySingleServer( $ipaddr[$i] );
 85+ if ( $this->debug == 1 ) {
 86+ print "ip address: " . $ipaddr[$i] . "\n";
 87+ print "result: " . $result . "\n";
 88+ }
 89+ if ( $result ) {
 90+ return $result;
 91+ }
 92+ }
 93+ }
10394
104 - // this function takes a input hash and stores it in the hash named queries
105 - function input( $vars ) {
106 - $numinputkeys = count( $vars ); // get the number of keys in the input hash
107 - $inputkeys = array_keys( $vars ); // get a array of keys in the input hash
108 - for ( $i = 0; $i < $numinputkeys; $i++ ) {
109 - $key = $inputkeys[$i];
110 - if ( $this->allowed_fields[$key] == 1 ) {
111 - // if key is a allowed field then store it in
112 - // the hash named queries
113 - $this->queries[$key] = urlencode( $this->filter_field( $key, $vars[$key] ) );
114 - } else {
115 - print "invalid input $key - perhaps misspelled field?";
116 - return 0;
117 - }
118 - }
119 - $this->queries["clientAPI"] = $this->API_VERSION;
120 - }
 95+ // query every server using its domain name
 96+ for ( $i = 0; $i < $this->numservers; $i++ ) {
 97+ $result = $this->querySingleServer( $this->server[$i] );
 98+ if ( $this->debug == 1 ) {
 99+ print "server: " . $this->server[$i] . "\nresult: " . $result . "\n";
 100+ }
 101+ if ( $result ) {
 102+ return $result;
 103+ }
 104+ }
 105+ return 0;
 106+ }
121107
122 - // sub-class should override this if it needs to filter inputs
123 - function filter_field( $key, $value ) {
124 - return $value;
125 - }
 108+ // this function takes a input hash and stores it in the hash named queries
 109+ function input( $vars ) {
 110+ $numinputkeys = count( $vars ); // get the number of keys in the input hash
 111+ $inputkeys = array_keys( $vars ); // get a array of keys in the input hash
 112+ for ( $i = 0; $i < $numinputkeys; $i++ ) {
 113+ $key = $inputkeys[$i];
 114+ if ( $this->allowed_fields[$key] == 1 ) {
 115+ // if key is a allowed field then store it in
 116+ // the hash named queries
 117+ $this->queries[$key] = urlencode( $this->filter_field( $key, $vars[$key] ) );
 118+ } else {
 119+ print "invalid input $key - perhaps misspelled field?";
 120+ return 0;
 121+ }
 122+ }
 123+ $this->queries["clientAPI"] = $this->API_VERSION;
 124+ }
126125
127 - // this function returns the output from the server
128 - function output() {
129 - return $this->outputstr;
130 - }
 126+ // sub-class should override this if it needs to filter inputs
 127+ function filter_field( $key, $value ) {
 128+ return $value;
 129+ }
131130
132 - // write the ip Addresses and the time right now to
133 - // the cache file
134 - function writeIpAddressToCache( $filename, $ipstr ) {
135 - $datetime = time();
136 - $fh = fopen( $this->wsIpaddrCacheFile, 'w' );
137 - fwrite( $fh, $ipstr . "\n" );
138 - fwrite( $fh, $datetime . "\n" );
139 - fclose( $fh );
140 - if ( $this->debug == 1 ) {
141 - print "writing ip address to cache\n";
142 - print "ip str: " . $ipstr . "\n";
143 - print "date time: " . $datetime . "\n";
144 - }
145 - }
 131+ // this function returns the output from the server
 132+ function output() {
 133+ return $this->outputstr;
 134+ }
146135
147 - function readIpAddressFromCache() {
148 - // if the cache file exists then
149 - // read the ip addresses and the time
150 - // IPs were cached
151 - if ( file_exists( $this->wsIpaddrCacheFile ) ) {
152 - $fh = fopen( $this->wsIpaddrCacheFile, 'r' );
153 - $ipstr = fgets( $fh, 1024 );
154 - $ipstr = rtrim( $ipstr );
155 - $datetime = fgets( $fh, 1024 );
156 - $datetime = rtrim( $datetime );
157 - fclose( $fh );
158 - }
 136+ // write the ip Addresses and the time right now to
 137+ // the cache file
 138+ function writeIpAddressToCache( $filename, $ipstr ) {
 139+ $datetime = time();
 140+ $fh = fopen( $this->wsIpaddrCacheFile, 'w' );
 141+ fwrite( $fh, $ipstr . "\n" );
 142+ fwrite( $fh, $datetime . "\n" );
 143+ fclose( $fh );
 144+ if ( $this->debug == 1 ) {
 145+ print "writing ip address to cache\n";
 146+ print "ip str: " . $ipstr . "\n";
 147+ print "date time: " . $datetime . "\n";
 148+ }
 149+ }
159150
160 - // if the ip addresses expired or don't exist then
161 - // get them from the web and write
162 - // them to the cache file
163 - if ( ( ( time() - $datetime ) > $this->wsIpaddrRefreshTimeout ) | ( !$ipstr ) ) {
164 - $tryIpstr = $this->readIpAddressFromWeb();
165 - if ( $tryIpstr ) {
166 - $ipstr = $tryIpstr;
167 - } else {
168 - if ( $this->debug == 1 ) {
169 - print "Warning, unable to get ws_ipaddr from www.maxmind.com\n";
170 - }
171 - }
172 - // we write to cache whether or not we were able to get $tryIpStr, since
173 - // in case DNS goes down, we don't want to check app/ws_ipaddr over and over
174 - $this->writeIpAddressToCache( $this->wsIpaddrCacheFile, $ipstr );
175 - }
176 - if ( $this->debug == 1 ) {
177 - print "reading ip address from cache\n";
178 - print "ip str: " . $ipstr . "\n";
179 - print "date time: " . $datetime . "\n";
180 - }
181 - // return the ip addresses
182 - return $ipstr;
183 - }
 151+ function readIpAddressFromCache() {
 152+ // if the cache file exists then
 153+ // read the ip addresses and the time
 154+ // IPs were cached
 155+ if ( file_exists( $this->wsIpaddrCacheFile ) ) {
 156+ $fh = fopen( $this->wsIpaddrCacheFile, 'r' );
 157+ $ipstr = fgets( $fh, 1024 );
 158+ $ipstr = rtrim( $ipstr );
 159+ $datetime = fgets( $fh, 1024 );
 160+ $datetime = rtrim( $datetime );
 161+ fclose( $fh );
 162+ }
184163
185 - function readIpAddressFromWeb() {
186 - // check if the curl module exists
187 - $url = "http://www.maxmind.com/app/ws_ipaddr";
188 - if ( extension_loaded( 'curl' ) ) {
189 - // open curl
190 - $ch = curl_init();
 164+ // if the ip addresses expired or don't exist then
 165+ // get them from the web and write
 166+ // them to the cache file
 167+ if ( ( ( time() - $datetime ) > $this->wsIpaddrRefreshTimeout ) | (!$ipstr ) ) {
 168+ $tryIpstr = $this->readIpAddressFromWeb();
 169+ if ( $tryIpstr ) {
 170+ $ipstr = $tryIpstr;
 171+ } else {
 172+ if ( $this->debug == 1 ) {
 173+ print "Warning, unable to get ws_ipaddr from www.maxmind.com\n";
 174+ }
 175+ }
 176+ // we write to cache whether or not we were able to get $tryIpStr, since
 177+ // in case DNS goes down, we don't want to check app/ws_ipaddr over and over
 178+ $this->writeIpAddressToCache( $this->wsIpaddrCacheFile, $ipstr );
 179+ }
 180+ if ( $this->debug == 1 ) {
 181+ print "reading ip address from cache\n";
 182+ print "ip str: " . $ipstr . "\n";
 183+ print "date time: " . $datetime . "\n";
 184+ }
 185+ // return the ip addresses
 186+ return $ipstr;
 187+ }
191188
192 - // set curl options
193 - curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
194 - curl_setopt( $ch, CURLOPT_URL, $url );
195 - curl_setopt( $ch, CURLOPT_TIMEOUT, $this->timeout );
 189+ function readIpAddressFromWeb() {
 190+ // check if the curl module exists
 191+ $url = "http://www.maxmind.com/app/ws_ipaddr";
 192+ if ( extension_loaded( 'curl' ) ) {
 193+ // open curl
 194+ $ch = curl_init();
196195
197 - // get the content
198 - $content = curl_exec( $ch );
199 - $content = rtrim( $content );
200 - if ( $this->debug == 1 ) {
201 - print "using curl\n";
202 - }
203 - } else {
204 - // we using HTTP without curl
 196+ // set curl options
 197+ curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
 198+ curl_setopt( $ch, CURLOPT_URL, $url );
 199+ curl_setopt( $ch, CURLOPT_TIMEOUT, $this->timeout );
205200
206 - // parse the url to get
207 - // host, path and query
208 - $url3 = parse_url( $url );
209 - $host = $url3["host"];
210 - $path = $url3["path"];
 201+ // get the content
 202+ $content = curl_exec( $ch );
 203+ $content = rtrim( $content );
 204+ if ( $this->debug == 1 ) {
 205+ print "using curl\n";
 206+ }
 207+ } else {
 208+ // we using HTTP without curl
 209+ // parse the url to get
 210+ // host, path and query
 211+ $url3 = parse_url( $url );
 212+ $host = $url3["host"];
 213+ $path = $url3["path"];
211214
212 - // open the connection
213 - $fp = fsockopen ( $host, 80, $errno, $errstr, $this->timeout );
214 - if ( $fp ) {
215 - // send the request
216 - fputs ( $fp, "GET $path HTTP/1.0\nHost: " . $host . "\n\n" );
217 - while ( !feof( $fp ) ) {
218 - $buf .= fgets( $fp, 128 );
219 - }
220 - $lines = preg_split( "/\n/", $buf );
221 - // get the content
222 - $content = $lines[count( $lines ) -1];
223 - // close the connection
224 - fclose( $fp );
225 - }
226 - if ( $this->debug == 1 ) {
227 - print "using fsockopen\n";
228 - }
229 - }
230 - if ( $this->debug == 1 ) {
231 - print "readIpAddressFromWeb found ip addresses: " . $content . "\n";
232 - }
233 - // TODO fix regexp so that it checks if it only has IP addresses
234 - if ( preg_match( "/([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/", $content ) ) {
235 - return $content;
236 - }
237 - return "";
238 - }
 215+ // open the connection
 216+ $fp = fsockopen( $host, 80, $errno, $errstr, $this->timeout );
 217+ if ( $fp ) {
 218+ // send the request
 219+ fputs( $fp, "GET $path HTTP/1.0\nHost: " . $host . "\n\n" );
 220+ while ( !feof( $fp ) ) {
 221+ $buf .= fgets( $fp, 128 );
 222+ }
 223+ $lines = preg_split( "/\n/", $buf );
 224+ // get the content
 225+ $content = $lines[count( $lines ) - 1];
 226+ // close the connection
 227+ fclose( $fp );
 228+ }
 229+ if ( $this->debug == 1 ) {
 230+ print "using fsockopen\n";
 231+ }
 232+ }
 233+ if ( $this->debug == 1 ) {
 234+ print "readIpAddressFromWeb found ip addresses: " . $content . "\n";
 235+ }
 236+ // TODO fix regexp so that it checks if it only has IP addresses
 237+ if ( preg_match( "/([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/", $content ) ) {
 238+ return $content;
 239+ }
 240+ return "";
 241+ }
239242
240 - // this function queries a single server
241 - function querySingleServer( $server ) {
242 - global $wgPayflowProGatewayUseHTTPProxy, $wgPayflowProGatewayHTTPProxy;
 243+ // this function queries a single server
 244+ function querySingleServer( $server ) {
 245+ $useHTTPProxy = $this->gateway_adapter->getGlobal( 'UseHTTPProxy' );
 246+ $HTTPProxy = $this->gateway_adapter->getGlobal( 'HTTPProxy' );
243247
244 - // check if we using the Secure HTTPS proctol
245 - if ( $this->isSecure == 1 ) {
246 - $scheme = "https://"; // Secure HTTPS proctol
247 - } else {
248 - $scheme = "http://"; // Regular HTTP proctol
249 - }
 248+ // check if we using the Secure HTTPS proctol
 249+ if ( $this->isSecure == 1 ) {
 250+ $scheme = "https://"; // Secure HTTPS proctol
 251+ } else {
 252+ $scheme = "http://"; // Regular HTTP proctol
 253+ }
250254
251 - // build a query string from the hash called queries
252 - $numquerieskeys = count( $this->queries ); // get the number of keys in the hash called queries
253 - $querieskeys = array_keys( $this->queries ); // get a array of keys in the hash called queries
254 - if ( $this->debug == 1 ) {
255 - print "number of query keys " . $numquerieskeys . "\n";
256 - }
 255+ // build a query string from the hash called queries
 256+ $numquerieskeys = count( $this->queries ); // get the number of keys in the hash called queries
 257+ $querieskeys = array_keys( $this->queries ); // get a array of keys in the hash called queries
 258+ if ( $this->debug == 1 ) {
 259+ print "number of query keys " . $numquerieskeys . "\n";
 260+ }
257261
258 - $query_string = "";
 262+ $query_string = "";
259263
260 - for ( $i = 0; $i < $numquerieskeys; $i++ ) {
261 - // for each element in the hash called queries
262 - // append the key and value of the element to the query string
263 - $key = $querieskeys[$i];
264 - $value = $this->queries[$key];
265 - // encode the key and value before adding it to the string
266 - // $key = urlencode($key);
267 - // $value = urlencode($value);
268 - if ( $this->debug == 1 ) {
269 - print " query key " . $key . " query value " . $value . "\n";
270 - }
271 - $query_string = $query_string . $key . "=" . $value;
272 - if ( $i < $numquerieskeys - 1 ) {
273 - $query_string = $query_string . "&";
274 - }
275 - }
 264+ for ( $i = 0; $i < $numquerieskeys; $i++ ) {
 265+ // for each element in the hash called queries
 266+ // append the key and value of the element to the query string
 267+ $key = $querieskeys[$i];
 268+ $value = $this->queries[$key];
 269+ // encode the key and value before adding it to the string
 270+ // $key = urlencode($key);
 271+ // $value = urlencode($value);
 272+ if ( $this->debug == 1 ) {
 273+ print " query key " . $key . " query value " . $value . "\n";
 274+ }
 275+ $query_string = $query_string . $key . "=" . $value;
 276+ if ( $i < $numquerieskeys - 1 ) {
 277+ $query_string = $query_string . "&";
 278+ }
 279+ }
276280
277 - // check if the curl module exists
278 - if ( extension_loaded( 'curl' ) ) {
279 - // use curl
280 - if ( $this->debug == 1 ) {
281 - print "using curl\n";
282 - }
 281+ // check if the curl module exists
 282+ if ( extension_loaded( 'curl' ) ) {
 283+ // use curl
 284+ if ( $this->debug == 1 ) {
 285+ print "using curl\n";
 286+ }
283287
284 - // open curl
285 - $ch = curl_init();
 288+ // open curl
 289+ $ch = curl_init();
286290
287 - $url = $scheme . $server . "/" . $this->url;
 291+ $url = $scheme . $server . "/" . $this->url;
288292
289 - // set curl options
290 - if ( $this->debug == 1 ) {
291 - print "url " . $url . "\n";
292 - }
293 - curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
294 - curl_setopt( $ch, CURLOPT_URL, $url );
295 - curl_setopt( $ch, CURLOPT_TIMEOUT, $this->timeout );
296 - curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
 293+ // set curl options
 294+ if ( $this->debug == 1 ) {
 295+ print "url " . $url . "\n";
 296+ }
 297+ curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
 298+ curl_setopt( $ch, CURLOPT_URL, $url );
 299+ curl_setopt( $ch, CURLOPT_TIMEOUT, $this->timeout );
 300+ curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
297301
298 - // this option lets you store the result in a string
299 - curl_setopt( $ch, CURLOPT_POST, 1 );
300 - curl_setopt( $ch, CURLOPT_POSTFIELDS, $query_string );
 302+ // this option lets you store the result in a string
 303+ curl_setopt( $ch, CURLOPT_POST, 1 );
 304+ curl_setopt( $ch, CURLOPT_POSTFIELDS, $query_string );
301305
302 - // set proxy settings if necessary
303 - if ( $wgPayflowProGatewayUseHTTPProxy ) {
304 - curl_setopt( $ch, CURLOPT_HTTPPROXYTUNNEL, 1 );
305 - curl_setopt( $ch, CURLOPT_PROXY, $wgPayflowProGatewayHTTPProxy );
306 - }
 306+ // set proxy settings if necessary
 307+ if ( $useHTTPProxy ) {
 308+ curl_setopt( $ch, CURLOPT_HTTPPROXYTUNNEL, 1 );
 309+ curl_setopt( $ch, CURLOPT_PROXY, $HTTPProxy );
 310+ }
307311
308 - // get the content
309 - $content = curl_exec( $ch );
 312+ // get the content
 313+ $content = curl_exec( $ch );
310314
311 - // For some reason curl_errno returns an error even when function works
312 - // Until we figure this out, will ignore curl errors - (not good i know)
 315+ // For some reason curl_errno returns an error even when function works
 316+ // Until we figure this out, will ignore curl errors - (not good i know)
313317 // $e = curl_errno($ch);//get error or sucess
314 -
315318 // if (($e == 1) & ($this->isSecure == 1)) {
316 - // HTTPS does not work print error message
 319+ // HTTPS does not work print error message
317320 // print "error: this version of curl does not support HTTPS try build curl with SSL or specify \$ccfs->isSecure = 0\n";
318321 // }
319322 // if ($e > 0) {
320 - // we get a error msg print it
 323+ // we get a error msg print it
321324 // print "Received error message $e from curl: " . curl_error($ch) . "\n";
322325 // return 0;
323326 // }
324 - // close curl
325 - curl_close( $ch );
326 - } else {
327 - // curl does not exist
328 - // use the fsockopen function,
329 - // the fgets function and the fclose function
330 - if ( $this->debug == 1 ) {
331 - print "using fsockopen for querySingleServer\n";
332 - }
 327+ // close curl
 328+ curl_close( $ch );
 329+ } else {
 330+ // curl does not exist
 331+ // use the fsockopen function,
 332+ // the fgets function and the fclose function
 333+ if ( $this->debug == 1 ) {
 334+ print "using fsockopen for querySingleServer\n";
 335+ }
333336
334 - $url = $scheme . $server . "/" . $this->url . "?" . $query_string;
335 - if ( $this->debug == 1 ) {
336 - print "url " . $url . " " . "\n";
337 - }
 337+ $url = $scheme . $server . "/" . $this->url . "?" . $query_string;
 338+ if ( $this->debug == 1 ) {
 339+ print "url " . $url . " " . "\n";
 340+ }
338341
339 - // now check if we are using regular HTTP
340 - if ( $this->isSecure == 0 ) {
341 - // we using regular HTTP
 342+ // now check if we are using regular HTTP
 343+ if ( $this->isSecure == 0 ) {
 344+ // we using regular HTTP
 345+ // parse the url to get
 346+ // host, path and query
 347+ $url3 = parse_url( $url );
 348+ $host = $url3["host"];
 349+ $path = $url3["path"];
 350+ $query = $url3["query"];
342351
343 - // parse the url to get
344 - // host, path and query
345 - $url3 = parse_url( $url );
346 - $host = $url3["host"];
347 - $path = $url3["path"];
348 - $query = $url3["query"];
 352+ // open the connection
 353+ $fp = fsockopen( $host, 80, $errno, $errstr, $this->timeout );
 354+ if ( $fp ) {
 355+ // send the request
 356+ $post = "POST $path HTTP/1.0\nHost: " . $host . "\nContent-type: application/x-www-form-urlencoded\nUser-Agent: Mozilla 4.0\nContent-length: " . strlen( $query ) . "\nConnection: close\n\n$query";
 357+ fputs( $fp, $post );
 358+ while ( !feof( $fp ) ) {
 359+ $buf .= fgets( $fp, 128 );
 360+ }
 361+ $lines = preg_split( "/\n/", $buf );
 362+ // get the content
 363+ $content = $lines[count( $lines ) - 1];
 364+ // close the connection
 365+ fclose( $fp );
 366+ } else {
 367+ return 0;
 368+ }
 369+ } else {
 370+ // secure HTTPS requires CURL
 371+ print "error: you need to install curl if you want secure HTTPS or specify the variable to be $ccfs->isSecure = 0";
 372+ return 0;
 373+ }
 374+ }
349375
350 - // open the connection
351 - $fp = fsockopen ( $host, 80, $errno, $errstr, $this->timeout );
352 - if ( $fp ) {
353 - // send the request
354 - $post = "POST $path HTTP/1.0\nHost: " . $host . "\nContent-type: application/x-www-form-urlencoded\nUser-Agent: Mozilla 4.0\nContent-length: " . strlen( $query ) . "\nConnection: close\n\n$query";
355 - fputs ( $fp, $post );
356 - while ( !feof( $fp ) ) {
357 - $buf .= fgets( $fp, 128 );
358 - }
359 - $lines = preg_split( "/\n/", $buf );
360 - // get the content
361 - $content = $lines[count( $lines ) -1];
362 - // close the connection
363 - fclose( $fp );
364 - } else {
365 - return 0;
366 - }
367 - } else {
368 - // secure HTTPS requires CURL
369 - print "error: you need to install curl if you want secure HTTPS or specify the variable to be $ccfs->isSecure = 0";
370 - return 0;
371 - }
372 - }
 376+ if ( $this->debug == 1 ) {
 377+ print "content = " . $content . "\n";
 378+ }
 379+ // get the keys and values from
 380+ // the string content and store them
 381+ // the hash named outputstr
 382+ // split content into pairs containing both
 383+ // the key and the value
 384+ $keyvaluepairs = explode( ";", $content );
373385
374 - if ( $this->debug == 1 ) {
375 - print "content = " . $content . "\n";
376 - }
377 - // get the keys and values from
378 - // the string content and store them
379 - // the hash named outputstr
 386+ // get the number of key and value pairs
 387+ $numkeyvaluepairs = count( $keyvaluepairs );
380388
381 - // split content into pairs containing both
382 - // the key and the value
383 - $keyvaluepairs = explode( ";", $content );
 389+ // for each pair store key and value into the
 390+ // hash named outputstr
 391+ $this->outputstr = array( );
 392+ for ( $i = 0; $i < $numkeyvaluepairs; $i++ ) {
 393+ // split the pair into a key and a value
 394+ list( $key, $value ) = explode( "=", $keyvaluepairs[$i] );
 395+ if ( $this->debug == 1 ) {
 396+ print " output " . $key . " = " . $value . "\n";
 397+ }
 398+ // store the key and the value into the
 399+ // hash named outputstr
 400+ $this->outputstr[$key] = $value;
 401+ }
 402+ // check if outputstr has the score if outputstr does not have
 403+ // the score return 0
 404+ if ( $this->outputstr[$this->check_field] == "" ) {
 405+ return 0;
 406+ }
 407+ // one other way to do it
 408+ // if (!array_key_exists("score",$this->outputstr)) {
 409+ // return 0;
 410+ // }
 411+ return 1;
 412+ }
384413
385 - // get the number of key and value pairs
386 - $numkeyvaluepairs = count( $keyvaluepairs );
 414+ function _getTempDir() {
 415+ if ( ini_get( 'upload_tmp_dir' ) ) {
 416+ return ini_get( 'upload_tmp_dir' );
 417+ }
387418
388 - // for each pair store key and value into the
389 - // hash named outputstr
390 - $this->outputstr = array();
391 - for ( $i = 0; $i < $numkeyvaluepairs; $i++ ) {
392 - // split the pair into a key and a value
393 - list( $key, $value ) = explode( "=", $keyvaluepairs[$i] );
394 - if ( $this->debug == 1 ) {
395 - print " output " . $key . " = " . $value . "\n";
396 - }
397 - // store the key and the value into the
398 - // hash named outputstr
399 - $this->outputstr[$key] = $value;
400 - }
401 - // check if outputstr has the score if outputstr does not have
402 - // the score return 0
403 - if ( $this->outputstr[$this->check_field] == "" ) {
404 - return 0;
405 - }
406 - // one other way to do it
407 - // if (!array_key_exists("score",$this->outputstr)) {
408 - // return 0;
409 - // }
410 - return 1;
411 - }
 419+ if ( substr( PHP_OS, 0, 3 ) != 'WIN' ) {
 420+ return '/tmp';
 421+ }
412422
413 - function _getTempDir() {
414 - if ( ini_get( 'upload_tmp_dir' ) ) {
415 - return ini_get( 'upload_tmp_dir' );
416 - }
 423+ if ( isset( $_ENV['TMP'] ) ) {
 424+ return $_ENV['TMP'];
 425+ }
417426
418 - if ( substr( PHP_OS, 0, 3 ) != 'WIN' ) {
419 - return '/tmp';
420 - }
 427+ if ( isset( $_ENV['TEMP'] ) ) {
 428+ return $_ENV['TEMP'];
 429+ }
421430
422 - if ( isset( $_ENV['TMP'] ) ) {
423 - return $_ENV['TMP'];
424 - }
 431+ if ( is_dir( 'c:\\windows\\temp' ) ) {
 432+ return 'c:\\windows\\temp';
 433+ }
425434
426 - if ( isset( $_ENV['TEMP'] ) ) {
427 - return $_ENV['TEMP'];
428 - }
 435+ if ( is_dir( 'c:\\winnt\\temp' ) ) {
 436+ return 'c:\\winnt\\temp';
 437+ }
429438
430 - if ( is_dir( 'c:\\windows\\temp' ) ) {
431 - return 'c:\\windows\\temp';
432 - }
 439+ return '.';
 440+ }
433441
434 - if ( is_dir( 'c:\\winnt\\temp' ) ) {
435 - return 'c:\\winnt\\temp';
436 - }
 442+}
437443
438 - return '.';
439 - }
440 -}
441444 ?>
Index: branches/fundraising/extensions/DonationInterface/extras/minfraud/ccfd/LocationVerification.php
@@ -20,31 +20,34 @@
2121 */
2222
2323 require_once ( "HTTPBase.php" );
 24+
2425 class LocationVerification extends HTTPBase {
25 - var $server;
26 - var $numservers;
27 - var $API_VERSION;
2826
29 - function __construct() {
30 - parent::__construct();
31 - $this->isSecure = 1; // use HTTPS by default
 27+ var $server;
 28+ var $numservers;
 29+ var $API_VERSION;
3230
33 - // set the allowed_fields hash
34 - $this->allowed_fields["i"] = 1;
35 - $this->allowed_fields["city"] = 1;
36 - $this->allowed_fields["region"] = 1;
37 - $this->allowed_fields["postal"] = 1;
38 - $this->allowed_fields["country"] = 1;
39 - $this->allowed_fields["license_key"] = 1;
40 - $this->num_allowed_fields = count( $this->allowed_fields );
 31+ function __construct( &$gateway_adapter ) {
 32+ parent::__construct( &$gateway_adapter );
 33+ $this->isSecure = 1; // use HTTPS by default
 34+ // set the allowed_fields hash
 35+ $this->allowed_fields["i"] = 1;
 36+ $this->allowed_fields["city"] = 1;
 37+ $this->allowed_fields["region"] = 1;
 38+ $this->allowed_fields["postal"] = 1;
 39+ $this->allowed_fields["country"] = 1;
 40+ $this->allowed_fields["license_key"] = 1;
 41+ $this->num_allowed_fields = count( $this->allowed_fields );
4142
42 - // set the url of the web service
43 - $this->url = "app/locvr";
44 - $this->check_field = "distance";
 43+ // set the url of the web service
 44+ $this->url = "app/locvr";
 45+ $this->check_field = "distance";
4546
46 - $this->server = array( "www.maxmind.com", "www2.maxmind.com" );
47 - $this->numservers = count( $this->server );
48 - $this->API_VERSION = 'PHP/1.4';
49 - }
 47+ $this->server = array( "www.maxmind.com", "www2.maxmind.com" );
 48+ $this->numservers = count( $this->server );
 49+ $this->API_VERSION = 'PHP/1.4';
 50+ }
 51+
5052 }
 53+
5154 ?>
Index: branches/fundraising/extensions/DonationInterface/extras/minfraud/ccfd/CreditCardFraudDetection.php
@@ -20,64 +20,67 @@
2121 */
2222
2323 require_once ( "HTTPBase.php" );
 24+
2425 class CreditCardFraudDetection extends HTTPBase {
25 - var $server;
26 - var $numservers;
27 - var $API_VERSION;
2826
29 - function __construct() {
30 - parent::__construct();
31 - $this->isSecure = 1; // use HTTPS by default
 27+ var $server;
 28+ var $numservers;
 29+ var $API_VERSION;
3230
33 - // set the allowed_fields hash
34 - $this->allowed_fields["i"] = 1;
35 - $this->allowed_fields["domain"] = 1;
36 - $this->allowed_fields["city"] = 1;
37 - $this->allowed_fields["region"] = 1;
38 - $this->allowed_fields["postal"] = 1;
39 - $this->allowed_fields["country"] = 1;
40 - $this->allowed_fields["bin"] = 1;
41 - $this->allowed_fields["binName"] = 1;
42 - $this->allowed_fields["binPhone"] = 1;
43 - $this->allowed_fields["custPhone"] = 1;
44 - $this->allowed_fields["license_key"] = 1;
45 - $this->allowed_fields["requested_type"] = 1;
46 - $this->allowed_fields["forwardedIP"] = 1;
47 - $this->allowed_fields["emailMD5"] = 1;
48 - $this->allowed_fields["shipAddr"] = 1;
49 - $this->allowed_fields["shipCity"] = 1;
50 - $this->allowed_fields["shipRegion"] = 1;
51 - $this->allowed_fields["shipPostal"] = 1;
52 - $this->allowed_fields["shipCountry"] = 1;
53 - $this->allowed_fields["txnID"] = 1;
54 - $this->allowed_fields["sessionID"] = 1;
55 - $this->allowed_fields["usernameMD5"] = 1;
56 - $this->allowed_fields["passwordMD5"] = 1;
57 - $this->allowed_fields["user_agent"] = 1;
58 - $this->allowed_fields["accept_language"] = 1;
 31+ function __construct( &$gateway_adapter ) {
 32+ parent::__construct( &$gateway_adapter );
 33+ $this->isSecure = 1; // use HTTPS by default
 34+ // set the allowed_fields hash
 35+ $this->allowed_fields["i"] = 1;
 36+ $this->allowed_fields["domain"] = 1;
 37+ $this->allowed_fields["city"] = 1;
 38+ $this->allowed_fields["region"] = 1;
 39+ $this->allowed_fields["postal"] = 1;
 40+ $this->allowed_fields["country"] = 1;
 41+ $this->allowed_fields["bin"] = 1;
 42+ $this->allowed_fields["binName"] = 1;
 43+ $this->allowed_fields["binPhone"] = 1;
 44+ $this->allowed_fields["custPhone"] = 1;
 45+ $this->allowed_fields["license_key"] = 1;
 46+ $this->allowed_fields["requested_type"] = 1;
 47+ $this->allowed_fields["forwardedIP"] = 1;
 48+ $this->allowed_fields["emailMD5"] = 1;
 49+ $this->allowed_fields["shipAddr"] = 1;
 50+ $this->allowed_fields["shipCity"] = 1;
 51+ $this->allowed_fields["shipRegion"] = 1;
 52+ $this->allowed_fields["shipPostal"] = 1;
 53+ $this->allowed_fields["shipCountry"] = 1;
 54+ $this->allowed_fields["txnID"] = 1;
 55+ $this->allowed_fields["sessionID"] = 1;
 56+ $this->allowed_fields["usernameMD5"] = 1;
 57+ $this->allowed_fields["passwordMD5"] = 1;
 58+ $this->allowed_fields["user_agent"] = 1;
 59+ $this->allowed_fields["accept_language"] = 1;
5960
6061
61 - $this->num_allowed_fields = count( $this->allowed_fields );
 62+ $this->num_allowed_fields = count( $this->allowed_fields );
6263
63 - // set the url of the web service
64 - $this->url = "app/ccv2r";
65 - $this->check_field = "score";
66 - $this->server = array( "minfraud3.maxmind.com", "minfraud1.maxmind.com", "minfraud2.maxmind.com" );
67 - $this->numservers = count( $this->server );
68 - $this->API_VERSION = 'PHP/1.49';
69 - }
 64+ // set the url of the web service
 65+ $this->url = "app/ccv2r";
 66+ $this->check_field = "score";
 67+ $this->server = array( "minfraud3.maxmind.com", "minfraud1.maxmind.com", "minfraud2.maxmind.com" );
 68+ $this->numservers = count( $this->server );
 69+ $this->API_VERSION = 'PHP/1.49';
 70+ }
7071
71 - function filter_field( $key, $value ) {
72 - if ( $key == 'emailMD5' ) {
73 - if ( preg_match( '/@/', $value ) ) {
74 - return md5( strtolower( $value ) );
75 - }
76 - } elseif ( $key == 'usernameMD5' || $key == 'passwordMD5' ) {
77 - if ( strlen( $value ) != 32 ) {
78 - return md5( strtolower( $value ) );
79 - }
80 - }
81 - return $value;
82 - }
 72+ function filter_field( $key, $value ) {
 73+ if ( $key == 'emailMD5' ) {
 74+ if ( preg_match( '/@/', $value ) ) {
 75+ return md5( strtolower( $value ) );
 76+ }
 77+ } elseif ( $key == 'usernameMD5' || $key == 'passwordMD5' ) {
 78+ if ( strlen( $value ) != 32 ) {
 79+ return md5( strtolower( $value ) );
 80+ }
 81+ }
 82+ return $value;
 83+ }
 84+
8385 }
 86+
8487 ?>
Index: branches/fundraising/extensions/DonationInterface/extras/minfraud/ccfd/TelephoneVerification.php
@@ -1,26 +1,31 @@
22 <?php
 3+
34 require_once ( "HTTPBase.php" );
 5+
46 class TelephoneVerification extends HTTPBase {
5 - var $server;
6 - var $numservers;
7 - var $API_VERSION;
8 - function __construct() {
9 - parent::__construct();
10 - $this->isSecure = 1; // use HTTPS by default
117
12 - // set the allowed_fields hash
13 - $this->allowed_fields["l"] = 1;
14 - $this->allowed_fields["phone"] = 1;
15 - $this->allowed_fields["verify_code"] = 1;
16 - $this->num_allowed_fields = count( $this->allowed_fields );
 8+ var $server;
 9+ var $numservers;
 10+ var $API_VERSION;
1711
18 - // set the url of the web service
19 - $this->url = "app/telephone_http";
20 - $this->check_field = "refid";
21 - $this->server = array( "www.maxmind.com", "www2.maxmind.com" );
22 - $this->numservers = count( $this->server );
23 - $this->API_VERSION = 'PHP/1.4';
24 - $this->timeout = 30;
25 - }
 12+ function __construct( &$gateway_adapter ) {
 13+ parent::__construct( &$gateway_adapter );
 14+ $this->isSecure = 1; // use HTTPS by default
 15+ // set the allowed_fields hash
 16+ $this->allowed_fields["l"] = 1;
 17+ $this->allowed_fields["phone"] = 1;
 18+ $this->allowed_fields["verify_code"] = 1;
 19+ $this->num_allowed_fields = count( $this->allowed_fields );
 20+
 21+ // set the url of the web service
 22+ $this->url = "app/telephone_http";
 23+ $this->check_field = "refid";
 24+ $this->server = array( "www.maxmind.com", "www2.maxmind.com" );
 25+ $this->numservers = count( $this->server );
 26+ $this->API_VERSION = 'PHP/1.4';
 27+ $this->timeout = 30;
 28+ }
 29+
2630 }
 31+
2732 ?>
Index: branches/fundraising/extensions/DonationInterface/extras/minfraud/tests/minfraudTest.php
@@ -1,25 +1,29 @@
22 <?php
 3+
34 /**
45 * @fixme wfGetIP() in minfraud.body.php wonks this up
56 */
67 require_once "PHPUnit/Framework.php";
78
8 -class minfraudTest extends PHPUnit_Framework_TestCase
9 -{
 9+class minfraudTest extends PHPUnit_Framework_TestCase {
 10+
1011 protected function setUp() {
1112 $dir = dirname( __FILE__ ) . '/';
1213 require_once( $dir . '../../extras.php' );
1314 require_once( $dir . '../minfraud.body.php' );
1415 require_once( $dir . "../../../includes/countryCodes.inc" );
15 - global $wgPayflowGatewayLog;
16 - $wgPayflowGatewayLog = dirname( __FILE__ ) . "/test_log";
 16+ global $wgDonationInterfaceExtrasLog;
 17+ $wgDonationInterfaceExtrasLog = dirname( __FILE__ ) . "/test_log";
1718 $license_key = 'XBCKSF4gnHA7';
18 - $this->fixture = new PayflowProGateway_Extras_MinFraud( $license_key );
 19+ global $wgPayflowProGatewayTest;
 20+ $wgPayflowProGatewayTest = true;
 21+ $adapter = new PayflowProAdapter();
 22+ $this->fixture = new Gateway_Extras_MinFraud( &$adapter, $license_key );
1923 }
2024
2125 protected function tearDown() {
22 - global $wgPayflowGatewayLog;
23 - unlink( $wgPayflowGatewayLog );
 26+ global $wgDonationInterfaceExtrasLog;
 27+ unlink( $wgDonationInterfaceExtrasLog );
2428 }
2529
2630 public function testCcfdInstance() {
@@ -43,8 +47,8 @@
4448 $this->assertArrayHasKey( "bin", $query );
4549 $this->assertArrayHasKey( "txnID", $query );
4650 $this->assertArrayNotHasKey( "foo", $query ); // make sure we're not adding extraneous info
47 - $this->assertNotContains( "@", $query[ 'domain' ] ); // make sure we're only getting domains from email addresses
48 - $this->assertEquals( 6, strlen( $query[ 'bin' ] ) ); // make sure our bin is 6 digits long
 51+ $this->assertNotContains( "@", $query['domain'] ); // make sure we're only getting domains from email addresses
 52+ $this->assertEquals( 6, strlen( $query['bin'] ) ); // make sure our bin is 6 digits long
4953 }
5054
5155 public function queryDataProvider() {
@@ -68,11 +72,11 @@
6973 /**
7074 * @dataProvider queryDataProvider
7175 */
72 -/* public function testQueryMinfraud( $data ) {
73 - $query = $this->fixture->build_query( $data );
74 - $this->fixture->query_minfraud( $query );
75 - $this->assertType( 'array', $this->fixture->minfraud_response );
76 - }*/
 76+ /* public function testQueryMinfraud( $data ) {
 77+ $query = $this->fixture->build_query( $data );
 78+ $this->fixture->query_minfraud( $query );
 79+ $this->assertType( 'array', $this->fixture->minfraud_response );
 80+ } */
7781
7882 /**
7983 * @dataProvider hashValidateFalseData
@@ -81,10 +85,18 @@
8286 $this->assertFalse( $this->fixture->validate_minfraud_query( $data ) );
8387 }
8488
 89+ public function setExtrasGlobal( $varname, $value ) {
 90+ //Just set the one for the adapter.
 91+ $adapter_prefix = $this->fixture->gateway_adapter->getGlobalPrefix();
 92+ $globalname = $adapter_prefix . $varname;
 93+ global $$globalname;
 94+ $$globalname = $value;
 95+ }
 96+
8597 public function hashValidateFalseData() {
8698 return array(
8799 array(
88 - array(),
 100+ array( ),
89101 array( 'license_key' => 'a' ),
90102 array(
91103 'license_key' => 'a',
@@ -154,29 +166,26 @@
155167 }
156168
157169 public function testLogging() {
158 - global $wgPayflowGatewayLog;
 170+ global $wgDonationInterfaceExtrasLog;
159171 $this->fixture->log( '', '', "\"foo\"" );
160 - $new_fh = fopen( $wgPayflowGatewayLog, 'r' );
161 - $this->assertEquals( '"' . date( 'c' ) . '"' . "\t\"\"\t\"\"\t\"foo\"\n", fread( $new_fh, filesize( $wgPayflowGatewayLog ) ) );
 172+ $new_fh = fopen( $wgDonationInterfaceExtrasLog, 'r' );
 173+ $this->assertEquals( '"' . date( 'c' ) . '"' . "\t\"\"\t\"\"\t\"foo\"\n", fread( $new_fh, filesize( $wgDonationInterfaceExtrasLog ) ) );
162174 fclose( $new_fh );
163175 }
164176
165177 public function testGenerateHash() {
166 - global $wgPayflowProGatewaySalt;
167 - $wgPayflowProGatewaySalt = 'salt';
 178+ $this->setExtrasGlobal( 'Salt', 'salt' );
168179 $this->assertEquals( '5a9ee1e4a15adbf03b3ef9f7baa6caffa9f6bcd72c736498f045c073e57753e7b244bc97fe82b075eabd80778a4d56eb14406e9a1ac4b13737b2c3fd8c3717e8', $this->fixture->generate_hash( 'foo' ) );
169180 }
170181
171182 public function testCompareHash() {
172 - global $wgPayflowProGatewaySalt;
173 - $wgPayflowProGatewaySalt = 'salt';
 183+ $this->setExtrasGlobal( 'Salt', 'salt' );
174184 $this->assertTrue( $this->fixture->compare_hash( '5a9ee1e4a15adbf03b3ef9f7baa6caffa9f6bcd72c736498f045c073e57753e7b244bc97fe82b075eabd80778a4d56eb14406e9a1ac4b13737b2c3fd8c3717e8', 'foo' ) );
175185 $this->assertFalse( $this->fixture->compare_hash( '5a9ee1e4a15adbf03b3ef9f7baa6caffa9f6bcd72c736498f045c073e57753e7b244bc97fe82b075eabd80778a4d56eb14406e9a1ac4b13737b2c3fd8c3717e8', 'bar' ) );
176186 }
177187
178188 public function testBypassMinfraud() {
179 - global $wgPayflowProGatewaySalt;
180 - $wgPayflowProGatewaySalt = 'salt';
 189+ $this->setExtrasGlobal( 'Salt', 'salt' );
181190 $data = array(
182191 'action' => '4bd7857c851039d1e07a434800fe752c6bd99aec61c325aef460441be1b95c3ab5236e43c8d06f41d77715dbd3cf94e679b86422ec3204f00ad433501e5005e9',
183192 'data_hash' => '029ef6f5c2a165215b5a92ff1a194e4a6de8c668d6193582da42713f119c1b07d8358b5cd94a3bd51c9aa50709c8533295215ce3cce8c2b61e69078d789bc3f3',
@@ -191,4 +200,5 @@
192201 $data[] = 'bar';
193202 $this->assertFalse( $this->fixture->can_bypass_minfraud( $this->fixture, $data ) );
194203 }
 204+
195205 }
Index: branches/fundraising/extensions/DonationInterface/extras/minfraud/minfraud.body.php
@@ -1,6 +1,7 @@
22 <?php
3 -class PayflowProGateway_Extras_MinFraud extends PayflowProGateway_Extras {
43
 4+class Gateway_Extras_MinFraud extends Gateway_Extras {
 5+
56 /**
67 * Full response from minFraud
78 * @var public array
@@ -16,14 +17,14 @@
1718 /**
1819 * User-definable riskScore ranges for actions to take
1920 *
20 - * Overload with $wgMinFraudActionRanges
 21+ * Overload with $wgMinFraudActionRanges
2122 * @var public array
2223 */
2324 public $action_ranges = array(
24 - 'process' => array( 0, 100 ),
25 - 'review' => array( -1, -1 ),
26 - 'challenge' => array( -1, -1 ),
27 - 'reject' => array( -1, -1 ),
 25+ 'process' => array( 0, 100 ),
 26+ 'review' => array( -1, -1 ),
 27+ 'challenge' => array( -1, -1 ),
 28+ 'reject' => array( -1, -1 ),
2829 );
2930
3031 /**
@@ -37,8 +38,8 @@
3839 */
3940 static $instance;
4041
41 - function __construct( $license_key = NULL ) {
42 - parent::__construct();
 42+ function __construct( &$gateway_adapter, $license_key = NULL ) {
 43+ parent::__construct( &$gateway_adapter );
4344 $dir = dirname( __FILE__ ) . '/';
4445 require_once( $dir . "ccfd/CreditCardFraudDetection.php" );
4546 require_once( $dir . "../../includes/countryCodes.inc" );
@@ -50,46 +51,48 @@
5152 }
5253 $this->minfraud_license_key = ( $license_key ) ? $license_key : $wgMinFraudLicenseKey;
5354
54 - if ( isset( $wgMinFraudActionRanges ) ) $this->action_ranges = $wgMinFraudActionRanges;
 55+ if ( isset( $wgMinFraudActionRanges ) )
 56+ $this->action_ranges = $wgMinFraudActionRanges;
5557 }
5658
5759 /**
5860 * Query minFraud with the transaction, set actions to take and make a log entry
5961 *
60 - * Accessible via $wgHooks[ 'PayflowGatewayValidate' ]
61 - * @param object PayflowPro Gateway object
 62+ * Accessible via $wgHooks[ 'GatewayValidate' ]
 63+ * @param object Gateway object
6264 * @param array The array of data generated from an attempted transaction
6365 */
64 - public function validate( &$pfp_gateway_object, &$data ) {
 66+ public function validate() {
6567 // see if we can bypass minfraud
66 - if ( $this->can_bypass_minfraud( $pfp_gateway_object, $data ) ) return TRUE;
 68+ if ( $this->can_bypass_minfraud() )
 69+ return TRUE;
6770
68 - $minfraud_query = $this->build_query( $data );
 71+ $minfraud_query = $this->build_query( $this->gateway_adapter->getData() );
6972 $this->query_minfraud( $minfraud_query );
70 - $pfp_gateway_object->action = $this->determine_action( $this->minfraud_response[ 'riskScore' ] );
 73+ $this->gateway_adapter->action = $this->determine_action( $this->minfraud_response['riskScore'] );
7174
7275 // reset the data hash
73 - if ( isset( $data[ 'data_hash' ] ) ) unset( $data[ 'data_hash' ] );
74 - $data[ 'action' ] = $this->generate_hash( $pfp_gateway_object->action );
75 - $data[ 'data_hash' ] = $this->generate_hash( serialize( $data ) );
 76+ $this->gateway_adapter->unsetHash();
 77+ $this->gateway_adapter->setActionHash( $this->generate_hash( $this->gateway_adapter->action ) );
 78+ $this->gateway_adapter->setHash( $this->generate_hash( $this->gateway_adapter->getData() ) );
7679
7780 // Write the query/response to the log
78 - $this->log_query( $minfraud_query, $pfp_gateway_object, $data );
 81+ $this->log_query( $minfraud_query );
7982 return TRUE;
8083 }
8184
8285 /**
8386 * Logs a minFraud query and its response
8487 */
85 - public function log_query( $minfraud_query, $pfp_gateway_object, $data ) {
 88+ public function log_query( $minfraud_query ) {
8689 if ( $this->log_fh ) {
87 - $log_message = '"' . addslashes( $data[ 'comment' ] ) . '"';
88 - $log_message .= "\t" . '"' . addslashes( $data[ 'amount' ] . ' ' . $data[ 'currency' ] ) . '"';
 90+ $log_message = '"' . addslashes( $this->gateway_adapter->getData( 'comment' ) ) . '"';
 91+ $log_message .= "\t" . '"' . addslashes( $this->gateway_adapter->getData( 'amount' ) . ' ' . $this->gateway_adapter->getData( 'currency' ) ) . '"';
8992 $log_message .= "\t" . '"' . addslashes( json_encode( $minfraud_query ) ) . '"';
9093 $log_message .= "\t" . '"' . addslashes( json_encode( $this->minfraud_response ) ) . '"';
91 - $log_message .= "\t" . '"' . addslashes( $pfp_gateway_object->action ) . '"';
92 - $log_message .= "\t" . '"' . addslashes( $data[ 'referrer' ] ) . '"';
93 - $this->log( $data[ 'contribution_tracking_id' ], 'minFraud query', $log_message );
 94+ $log_message .= "\t" . '"' . addslashes( $this->gateway_adapter->action ) . '"';
 95+ $log_message .= "\t" . '"' . addslashes( $this->gateway_adapter->getData( 'referrer' ) ) . '"';
 96+ $this->log( $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'minFraud query', $log_message );
9497 }
9598 }
9699
@@ -102,40 +105,37 @@
103106 * assume the transaction has already gone through the minFraud check and can be passed
104107 * on to the appropriate action.
105108 *
106 - * @param object $pfp_gateway_object The PayflowPro gateway object
107 - * @param array $data The array of data from the form submission
108109 * @return bool
109110 */
110 - public function can_bypass_minfraud( &$pfp_gateway_object, &$data ) {
 111+ public function can_bypass_minfraud() {
111112 // if the data bits data_hash and action are not set, we need to hit minFraud
112 - if ( !strlen( $data[ 'data_hash' ] ) || !strlen( $data[ 'action' ] ) ) {
 113+ $localdata = $this->gateway_adapter->getData();
 114+ if ( !strlen( $localdata['data_hash'] ) || !strlen( $localdata['action'] ) ) {
113115 return FALSE;
114116 }
115117
116 - $data_hash = $data[ 'data_hash' ]; // the data hash passed in by the form submission
117 - $num_attempt = $data[ 'numAttempt' ]; // the num_attempt has been increased by one, so we have to adjust slightly
118 - $data[ 'numAttempt' ] = $num_attempt - 1;
119 -
120 - // unset these values from the data aray since they are not part of the overall data hash
121 - unset( $data[ 'data_hash' ] );
 118+ $data_hash = $localdata['data_hash']; // the data hash passed in by the form submission
 119+ // unset these values since they are not part of the overall data hash
 120+ $this->gateway_adapter->unsetHash();
 121+ unset( $localdata['data_hash'] );
122122 // compare the data hash to make sure it's legit
123 - if ( $this->compare_hash( $data_hash, serialize( $data ) ) ) {
124 - $data[ 'numAttempt' ] = $num_attempt; // reset the current num attempt
125 - $data[ 'data_hash' ] = $this->generate_hash( serialize( $data ) ); // hash the data array
 123+ if ( $this->compare_hash( $data_hash, serialize( $localdata ) ) ) {
126124
 125+ $this->gateway_adapter->setHash( $this->generate_hash( $this->gateway_adapter->getData() ) ); // hash the data array
127126 // check to see if we have a valid action set for us to bypass minfraud
128127 $actions = array( 'process', 'challenge', 'review', 'reject' );
129 - $action_hash = $data[ 'action' ]; // a hash of the action to take passed in by the form submission
 128+ $action_hash = $localdata['action']; // a hash of the action to take passed in by the form submission
130129 foreach ( $actions as $action ) {
131130 if ( $this->compare_hash( $action_hash, $action ) ) {
132131 // set the action that should be taken
133 - $pfp_gateway_object->action = $action;
 132+ $this->gateway_adapter->action = $action;
134133 return TRUE;
135134 }
136135 }
137136 } else {
138137 // log potential tampering
139 - if ( $this->log_fh ) $this->log( $data[ 'contribution_tracking_id'], 'Data hash/action mismatch' );
 138+ if ( $this->log_fh )
 139+ $this->log( $localdata['contribution_tracking_id'], 'Data hash/action mismatch' );
140140 }
141141
142142 return FALSE;
@@ -147,7 +147,7 @@
148148 */
149149 public function get_ccfd() {
150150 if ( !$this->ccfd ) {
151 - $this->ccfd = new CreditCardFraudDetection;
 151+ $this->ccfd = new CreditCardFraudDetection( &$this->gateway_adapter );
152152 }
153153 return $this->ccfd;
154154 }
@@ -172,20 +172,20 @@
173173 );
174174
175175 // minfraud license key
176 - $minfraud_array[ "license_key" ] = $this->minfraud_license_key;
 176+ $minfraud_array["license_key"] = $this->minfraud_license_key;
177177
178178 // user's IP address
179 - $minfraud_array[ "i" ] = ( $wgDonationInterfaceTest ) ? '12.12.12.12' : wfGetIP();
 179+ $minfraud_array["i"] = ( $wgDonationInterfaceTest ) ? '12.12.12.12' : wfGetIP();
180180
181181 // user's user agent
182182 global $wgRequest;
183 - $minfraud_array[ "user_agent" ] = $wgRequest->getHeader( 'user-agent' );
 183+ $minfraud_array["user_agent"] = $wgRequest->getHeader( 'user-agent' );
184184
185185 // user's language
186 - $minfraud_array[ 'accept_language' ] = $wgRequest->getHeader( 'accept-language' );
 186+ $minfraud_array['accept_language'] = $wgRequest->getHeader( 'accept-language' );
187187
188188 // fetch the array of country codes
189 - $country_codes = PayflowProGateway::getCountries();
 189+ $country_codes = GatewayForm::getCountries();
190190
191191 // loop through the map and add pertinent values from $data to the hash
192192 foreach ( $map as $key => $value ) {
@@ -193,19 +193,19 @@
194194 // do some data processing to clean up values for minfraud
195195 switch ( $key ) {
196196 case "domain": // get just the domain from the email address
197 - $newdata[ $value ] = substr( strstr( $data[ $value ], '@' ), 1 );
 197+ $newdata[$value] = substr( strstr( $data[$value], '@' ), 1 );
198198 break;
199199 case "bin": // get just the first 6 digits from CC#
200 - $newdata[ $value ] = substr( $data[ $value ], 0, 6 );
 200+ $newdata[$value] = substr( $data[$value], 0, 6 );
201201 break;
202202 case "country":
203 - $newdata[ $value ] = $country_codes[ $data[ $value ]];
 203+ $newdata[$value] = $country_codes[$data[$value]];
204204 break;
205205 default:
206 - $newdata[ $value ] = $data[ $value ];
 206+ $newdata[$value] = $data[$value];
207207 }
208208
209 - $minfraud_array[ $key ] = $newdata[ $value ];
 209+ $minfraud_array[$key] = $newdata[$value];
210210 }
211211
212212 return $minfraud_array;
@@ -229,7 +229,7 @@
230230 * there is a value for a required field and if its length is > 0
231231 *
232232 * @param array $minfraud_query which is the array you would pass to
233 - * minfraud in a query
 233+ * minfraud in a query
234234 * @result bool
235235 */
236236 public function validate_minfraud_query( array $minfraud_query ) {
@@ -244,8 +244,8 @@
245245 );
246246
247247 foreach ( $reqd_fields as $reqd_field ) {
248 - if ( !isset( $minfraud_query[ $reqd_field ] ) ||
249 - strlen( $minfraud_query[ $reqd_field ] ) < 1 ) {
 248+ if ( !isset( $minfraud_query[$reqd_field] ) ||
 249+ strlen( $minfraud_query[$reqd_field] ) < 1 ) {
250250 return FALSE;
251251 }
252252 }
@@ -261,7 +261,7 @@
262262 * @param float risk score (returned from minFraud)
263263 * @return array of actions to be taken
264264 */
265 - public function determine_action( $risk_score ) {
 265+ public function determine_action( $risk_score ) {
266266 foreach ( $this->action_ranges as $action => $range ) {
267267 if ( $risk_score >= $range[0] && $risk_score <= $range[1] ) {
268268 return $action;
@@ -269,14 +269,15 @@
270270 }
271271 }
272272
273 - static function onValidate( &$pfp_gateway_object, &$data ) {
274 - return self::singleton()->validate( $pfp_gateway_object, $data );
 273+ static function onValidate( &$gateway_adapter ) {
 274+ return self::singleton( &$gateway_adapter )->validate();
275275 }
276276
277 - static function singleton() {
 277+ static function singleton( &$gateway_adapter ) {
278278 if ( !self::$instance ) {
279 - self::$instance = new self;
 279+ self::$instance = new self( &$gateway_adapter );
280280 }
281281 return self::$instance;
282282 }
 283+
283284 }
Index: branches/fundraising/extensions/DonationInterface/extras/minfraud/minfraud.php
@@ -1,4 +1,5 @@
22 <?php
 3+
34 /**
45 * Validates a transaction against MaxMind's minFraud service
56 *
@@ -8,16 +9,15 @@
910 * require_once( "$IP/extensions/DonationInterface/extras/minfraud/minfraud.php" );
1011 *
1112 */
12 -
1313 if ( !defined( 'MEDIAWIKI' ) ) {
14 - die( "This file is part of the MinFraud for PayflowPro Gateway extension. It is not a valid entry point.\n" );
 14+ die( "This file is part of the MinFraud for Gateway extension. It is not a valid entry point.\n" );
1515 }
1616
17 -$wgExtensionCredits['payflowprogateway_extras_minfraud'][] = array(
 17+$wgExtensionCredits['gateway_extras_minfraud'][] = array(
1818 'name' => 'minfraud',
1919 'author' => 'Arthur Richards',
2020 'url' => '',
21 - 'description' => 'This extension uses the MaxMind minFraud service as a validator for the Payflow Pro gateway.'
 21+ 'description' => 'This extension uses the MaxMind minFraud service as a validator for the gateway.'
2222 );
2323
2424 /**
@@ -32,9 +32,9 @@
3333 * The value for one of these keys is an array representing the lower
3434 * and upper bounds for that action. For instance,
3535 * $wgMinFraudActionRagnes = array(
36 - * 'process' => array( 0, 100)
37 - * ...
38 - * );
 36+ * 'process' => array( 0, 100)
 37+ * ...
 38+ * );
3939 * means that any transaction with a risk score greather than or equal
4040 * to 0 and less than or equal to 100 will be given the 'process' action.
4141 *
@@ -55,7 +55,7 @@
5656 * Define whether or not to run minFraud in stand alone mode
5757 *
5858 * If this is set to run in standalone, these scripts will be
59 - * accessed directly via the "PayflowGatewayValidate" hook.
 59+ * accessed directly via the "GatewayValidate" hook.
6060 * You may not want to run this in standalone mode if you prefer
6161 * to use this in conjunction with Custom Filters. This has the
6262 * advantage of sharing minFraud info with other filters.
@@ -63,12 +63,13 @@
6464 $wgMinFraudStandalone = TRUE;
6565
6666 $dir = dirname( __FILE__ ) . "/";
67 -$wgAutoloadClasses['PayflowProGateway_Extras_MinFraud'] = $dir . "minfraud.body.php";
 67+$wgAutoloadClasses['Gateway_Extras_MinFraud'] = $dir . "minfraud.body.php";
6868
6969 $wgExtensionFunctions[] = 'efMinFraudSetup';
7070
7171 function efMinFraudSetup() {
72 - // if we're in standalone mode, use the PayflowGatewayValidate hook
 72+ // if we're in standalone mode, use the GatewayValidate hook
7373 global $wgMinFraudStandalone, $wgHooks;
74 - if ( $wgMinFraudStandalone ) $wgHooks["PayflowGatewayValidate"][] = array( 'PayflowProGateway_Extras_MinFraud::onValidate' );
 74+ if ( $wgMinFraudStandalone )
 75+ $wgHooks["GatewayValidate"][] = array( 'Gateway_Extras_MinFraud::onValidate' );
7576 }
Index: branches/fundraising/extensions/DonationInterface/extras/conversion_log/conversion_log.body.php
@@ -1,39 +1,40 @@
22 <?php
3 -class PayflowProGateway_Extras_ConversionLog extends PayflowProGateway_Extras {
 3+
 4+class Gateway_Extras_ConversionLog extends Gateway_Extras {
 5+
46 static $instance;
57
68 /**
7 - * Logs the response from a payflow transaction
 9+ * Logs the response from a transaction
810 */
9 - public function post_process( &$pfp_gateway_object, &$data ) {
 11+ public function post_process() {
1012 // if the trxn has been outright rejected, log it
11 - if ( $pfp_gateway_object->action == 'reject' ) {
 13+ if ( $this->gateway_adapter->action == 'reject' ) {
1214 $this->log(
13 - $data[ 'contribution_tracking_id' ],
14 - 'Rejected'
 15+ $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'Rejected'
1516 );
1617 return TRUE;
1718 }
1819
19 - // make sure the payflow response property has been set (signifying a transaction has been made)
20 - if ( !$pfp_gateway_object->payflow_response ) return FALSE;
 20+ // make sure the response property has been set (signifying a transaction has been made)
 21+ if ( !$this->gateway_adapter->getTransactionAllResults() )
 22+ return FALSE;
2123
2224 $this->log(
23 - $data[ 'contribution_tracking_id' ],
24 - "Payflow response: " . addslashes( $pfp_gateway_object->payflow_response[ 'RESPMSG' ] ),
25 - '"' . addslashes( json_encode( $pfp_gateway_object->payflow_response ) ) . '"'
 25+ $this->gateway_adapter->getData( 'contribution_tracking_id' ), "Gateway response: " . addslashes( $this->gateway_adapter->getTransactionMessage() ), '"' . addslashes( json_encode( $this->gateway_adapter->getTransactionData() ) ) . '"'
2626 );
2727 return TRUE;
2828 }
2929
30 - static function onPostProcess( &$pfp_gateway_object, &$data ) {
31 - return self::singleton()->post_process( $pfp_gateway_object, $data );
 30+ static function onPostProcess( &$gateway_adapter ) {
 31+ return self::singleton( $gateway_adapter )->post_process();
3232 }
3333
34 - static function singleton() {
 34+ static function singleton( &$gateway_adapter ) {
3535 if ( !self::$instance ) {
36 - self::$instance = new self;
 36+ self::$instance = new self( $gateway_adapter );
3737 }
3838 return self::$instance;
3939 }
 40+
4041 }
Index: branches/fundraising/extensions/DonationInterface/extras/conversion_log/conversion_log.php
@@ -1,26 +1,26 @@
22 <?php
 3+
34 /**
4 - * Extra to log payflow response during post processing hook
 5+ * Extra to log gateway response during post processing hook
56 *
67 * @fixme Class/file names should likely change to reflect change in purpose...
78 *
89 * To install:
910 * require_once( "$IP/extensions/DonationInterface/extras/conversion_log/conversion_log.php"
1011 */
11 -
1212 if ( !defined( 'MEDIAWIKI' ) ) {
13 - die( "This file is part of the Conversion Log for PayflowPro Gateway extension. It is not a valid entry point.\n" );
 13+ die( "This file is part of the Conversion Log for Gateway extension. It is not a valid entry point.\n" );
1414 }
1515
16 -$wgExtensionCredits['payflowprogateway_extras_conversionLog'][] = array(
17 - 'name' => 'conversion log',
18 - 'author' => 'Arthur Richards',
19 - 'url' => '',
20 - 'description' => "This extension handles logging for Payflow Gateway extension 'extras'"
 16+$wgExtensionCredits['gateway_extras_conversionLog'][] = array(
 17+ 'name' => 'conversion log',
 18+ 'author' => 'Arthur Richards',
 19+ 'url' => '',
 20+ 'description' => "This extension handles logging for Gateway extension 'extras'"
2121 );
2222
2323 $dir = dirname( __FILE__ ) . "/";
24 -$wgAutoloadClasses['PayflowProGateway_Extras_ConversionLog'] = $dir . "conversion_log.body.php";
 24+$wgAutoloadClasses['Gateway_Extras_ConversionLog'] = $dir . "conversion_log.body.php";
2525
2626 // Sets the 'conversion log' as logger for post-processing
27 -$wgHooks["PayflowGatewayPostProcess"][] = array( "PayflowProGateway_Extras_ConversionLog::onPostProcess" );
 27+$wgHooks["GatewayPostProcess"][] = array( "Gateway_Extras_ConversionLog::onPostProcess" );
Index: branches/fundraising/extensions/DonationInterface/extras/extras.body.php
@@ -1,21 +1,38 @@
22 <?php
 3+
34 /**
4 - * An abstract class for payflowpro gateway 'extras'
 5+ * An abstract class for gateway 'extras'
56 */
 7+abstract class Gateway_Extras {
68
7 -abstract class PayflowProGateway_Extras {
89 /**
910 * File handle for log file
1011 * @var public
1112 */
1213 public $log_fh = NULL;
 14+ public $gateway_adapter;
1315
14 - public function __construct() {
15 - global $wgPayflowGatewayLog;
 16+ public function __construct( &$gateway_adapter ) {
 17+ $this->gateway_adapter = &$gateway_adapter;
 18+
 19+ $extrasLog = $this->getGlobal( 'ExtrasLog' );
1620 // prepare the log file if the user has specified one
17 - if ( strlen( $wgPayflowGatewayLog ) > 0 ) $this->prepare_log_file( $wgPayflowGatewayLog );
 21+ if ( strlen( $extrasLog ) > 0 )
 22+ $this->prepare_log_file( $extrasLog );
1823 }
1924
 25+ function getGlobal( $varname ) {
 26+ //basically, if the global is defined in the adapter, use the overridden value.
 27+ //otherwise, grab the default.
 28+ $ret = $this->gateway_adapter->getGlobal( $varname );
 29+ if ( empty( $ret ) ) {
 30+ $globalname = 'wgDonationInterface' . $varname;
 31+ global $$globalname;
 32+ $ret = $$globalname;
 33+ }
 34+ return $ret;
 35+ }
 36+
2037 /**
2138 * Prepare logging mechanism
2239 *
@@ -25,19 +42,16 @@
2643 * @param string path to log file
2744 */
2845 protected function prepare_log_file( $log_file ) {
29 -
 46+
3047 if ( strtolower( $log_file ) == "syslog" ) {
3148
32 - $this->log_fh = 'syslog';
33 -
34 - } elseif( is_file( $log_file )) {
35 -
 49+ $this->log_fh = 'syslog';
 50+ } elseif ( is_file( $log_file ) ) {
 51+
3652 $this->log_fh = fopen( $log_file, 'a+' );
37 -
3853 } else {
3954
4055 $this->log_fh = null;
41 -
4256 }
4357 }
4458
@@ -54,26 +68,20 @@
5569 echo "what log file?";
5670 return;
5771 }
58 -
 72+
5973 // format the message
6074 $msg = '"' . date( 'c' ) . '"';
6175 $msg .= "\t" . '"' . $id . '"';
6276 $msg .= "\t" . '"' . $status . '"';
6377 $msg .= "\t" . $data . "\n";
64 -
 78+
6579 // write to the log
6680 if ( $this->log_fh == 'syslog' ) { //use syslog facility
6781 // replace tabs with spaces - maybe do this universally? cuz who needs tabs.
6882 $msg = str_replace( "\t", " ", $msg );
69 -
70 - openlog( "payflowpro_gateway_trxn", LOG_ODELAY, LOG_SYSLOG );
71 - syslog( $log_level, $msg );
72 - closelog();
73 -
 83+ $this->gateway_adapter->log( $msg, $log_level, '_trxn' );
7484 } else { //write to file
75 -
7685 fwrite( $this->log_fh, $msg );
77 -
7886 }
7987 }
8088
@@ -83,8 +91,8 @@
8492 * @return string The hash of the data
8593 */
8694 public function generate_hash( $data ) {
87 - global $wgPayflowProGatewaySalt;
88 - return hash( "sha512", $wgPayflowProGatewaySalt . $data );
 95+ $salt = $this->getGlobal( 'Salt' );
 96+ return hash( "sha512", $salt . $data );
8997 }
9098
9199 /**
@@ -105,6 +113,8 @@
106114 * Close the open log file handler if it's open
107115 */
108116 public function __destruct() {
109 - if ( is_resource( $this->log_fh ) ) fclose( $this->log_fh );
 117+ if ( is_resource( $this->log_fh ) )
 118+ fclose( $this->log_fh );
110119 }
 120+
111121 }
Index: branches/fundraising/extensions/DonationInterface/extras/recaptcha/recaptcha-php/recaptchalib.php
@@ -42,8 +42,7 @@
4343 */
4444
4545 // global MW variables that should be available
46 -global $wgPayflowRecaptchaUseHTTPProxy, $wgPayflowRecaptchaHTTPProxy,
47 - $wgPayflowRecaptchaTimeout, $wgPayflowRecaptchaUseSSL, $wgPayflowRecaptchaComsRetryLimit;
 46+global $wgReCaptchaConfData;
4847
4948 /**
5049 * The reCAPTCHA server URL's
@@ -55,16 +54,18 @@
5655 /**
5756 * Proxy settings
5857 */
59 -define( "RECAPTCHA_USE_HTTP_PROXY", $wgPayflowRecaptchaUseHTTPProxy );
60 -define( "RECAPTCHA_HTTP_PROXY", $wgPayflowRecaptchaHTTPProxy );
 58+define( "RECAPTCHA_USE_HTTP_PROXY", $wgReCaptchaConfData['UseHTTPProxy'] );
 59+define( "RECAPTCHA_HTTP_PROXY", $wgReCaptchaConfData['HTTPProxy'] );
6160
6261 /**
6362 * Other reCAPTCHA settings
6463 */
65 -define( "RECAPTCHA_TIMEOUT", $wgPayflowRecaptchaTimeout );
66 -define( "RECAPTCHA_PROTOCOL", $wgPayflowRecaptchaUseSSL ); //http or https
67 -define( "RECAPTCHA_RETRY_LIMIT", $wgPayflowRecaptchaComsRetryLimit );
 64+define( "RECAPTCHA_TIMEOUT", $wgReCaptchaConfData['UseHTTPProxy'] );
 65+define( "RECAPTCHA_PROTOCOL", $wgReCaptchaConfData['UseSSL'] ); //http or https
 66+define( "RECAPTCHA_RETRY_LIMIT", $wgReCaptchaConfData['ComsRetryLimit'] );
6867
 68+define( "RECAPTCHA_GATEWAY", $wgReCaptchaConfData['GatewayClass'] );
 69+
6970 /**
7071 * Encodes the given data into a query string format
7172 * @param $data - array of string elements to be encoded
@@ -125,7 +126,8 @@
126127
127128 $response = '';
128129 if ( false == ( $fs = @fsockopen( $host, $port, $errno, $errstr, 10 ) ) ) {
129 - PayflowProGateway::log( 'Failed communicating with reCaptcha.' );
 130+ $c = RECAPTCHA_GATEWAY;
 131+ $c::log( 'Failed communicating with reCaptcha.' );
130132 die ( 'Could not open socket' );
131133 }
132134
@@ -158,20 +160,22 @@
159161 curl_setopt( $ch, CURLOPT_HEADER, true );
160162 curl_setopt( $ch, CURLOPT_HTTPHEADER, array( "Host: " . $host ) );
161163
 164+ $c = RECAPTCHA_GATEWAY;
 165+
162166 // set proxy settings if necessary
163167 if ( RECAPTCHA_USE_HTTP_PROXY ) {
164 - PayflowProGateway::log( 'Using http proxy ' . RECAPTCHA_HTTP_PROXY );
 168+ $c::log( 'Using http proxy ' . RECAPTCHA_HTTP_PROXY );
165169 curl_setopt( $ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP );
166170 curl_setopt( $ch, CURLOPT_PROXY, RECAPTCHA_HTTP_PROXY );
167171 }
168172
169173 // try up to three times
170174 for ( $i = 0; $i < RECAPTCHA_RETRY_LIMIT; $i++ ) {
171 - PayflowProGateway::log( 'Preparing to communicate with reCaptcha via cURL at ' . $url . '.' );
 175+ $c::log( 'Preparing to communicate with reCaptcha via cURL at ' . $url . '.' );
172176 $response = curl_exec( $ch );
173 - PayflowProGateway::log( "Finished communicating with reCaptcha." );
 177+ $c::log( "Finished communicating with reCaptcha." );
174178 if ( $response ) {
175 - PayflowProGateway::log( 'Response from reCaptcha: ' . $response );
 179+ $c::log( 'Response from reCaptcha: ' . $response );
176180 break;
177181 }
178182 }
@@ -186,7 +190,7 @@
187191 * the user entered the correct values.
188192 */
189193 if ( !$response ) {
190 - PayflowProGateway::log( 'Failed communicating with reCaptcha: ' . curl_error( $ch ) );
 194+ $c::log( 'Failed communicating with reCaptcha: ' . curl_error( $ch ) );
191195 $response = "true\r\n\r\nsuccess";
192196 }
193197
Index: branches/fundraising/extensions/DonationInterface/extras/recaptcha/recaptcha.php
@@ -1,20 +1,20 @@
22 <?php
 3+
34 /**
45 * Extra to expose a recaptcha for 'challenged' transactions
56 *
67 * To install:
78 * require_once( "$IP/extensions/DonationInterface/extras/recaptcha/recaptcha.php"
89 */
9 -
1010 if ( !defined( 'MEDIAWIKI' ) ) {
11 - die( "This file is part of the ReCaptcha for PayflowPro Gateway extension. It is not a valid entry point.\n" );
 11+ die( "This file is part of the ReCaptcha for Gateway extension. It is not a valid entry point.\n" );
1212 }
1313
14 -$wgExtensionCredits['payflowgateway_extras_recaptcha'][] = array(
15 - 'name' => 'reCaptcha',
16 - 'author' => 'Arthur Richards',
17 - 'url' => '',
18 - 'description' => "This extension exposes a reCpathca for 'challenged' transactions in the Payflowpro Gateway"
 14+$wgExtensionCredits['extras_recaptcha'][] = array(
 15+ 'name' => 'reCaptcha',
 16+ 'author' => 'Arthur Richards',
 17+ 'url' => '',
 18+ 'description' => "This extension exposes a reCpathca for 'challenged' transactions in the Gateway"
1919 );
2020
2121 /**
@@ -23,33 +23,33 @@
2424 * These can be obtained at:
2525 * http://www.google.com/recaptcha/whyrecaptcha
2626 */
27 -$wgPayflowRecaptchaPublicKey = '';
28 -$wgPayflowRecaptchaPrivateKey = '';
 27+$wgDonationInterfaceRecaptchaPublicKey = '';
 28+$wgDonationInterfaceRecaptchaPrivateKey = '';
2929
3030 // Timeout (in seconds) for communicating with reCatpcha
31 -$wgPayflowRecaptchaTimeout = 2;
 31+$wgDonationInterfaceRecaptchaTimeout = 2;
3232
3333 /**
3434 * HTTP Proxy settings
3535 *
36 - * Default to settings in PayflowPro Gateway
 36+ * Default to settings in DonationInterface
3737 */
38 -$wgPayflowRecaptchaUseHTTPProxy = $wgPayflowProGatewayUseHTTPProxy;
39 -$wgPayflowRecaptchaHTTPProxy = $wgPayflowProGatewayHTTPProxy;
 38+$wgDonationInterfaceRecaptchaUseHTTPProxy = $wgDonationInterfaceUseHTTPProxy;
 39+$wgDonationInterfaceRecaptchaHTTPProxy = $wgDonationInterfaceHTTPProxy;
4040
4141 /**
4242 * Use SSL to communicate with reCaptcha
4343 */
44 -$wgPayflowRecaptchaUseSSL = 1;
 44+$wgDonationInterfaceRecaptchaUseSSL = 1;
4545
4646 /**
4747 * The # of times to retry communicating with reCaptcha if communication fails
4848 * @var int
4949 */
50 -$wgPayflowRecaptchaComsRetryLimit = 3;
 50+$wgDonationInterfaceRecaptchaComsRetryLimit = 3;
5151
5252 $dir = dirname( __FILE__ ) . "/";
53 -$wgAutoloadClasses['PayflowProGateway_Extras_ReCaptcha'] = $dir . "recaptcha.body.php";
 53+$wgAutoloadClasses['Gateway_Extras_ReCaptcha'] = $dir . "recaptcha.body.php";
5454
5555 // Set reCpatcha as plugin for 'challenge' action
56 -$wgHooks["PayflowGatewayChallenge"][] = array( "PayflowProGateway_Extras_ReCaptcha::onChallenge" );
 56+$wgHooks["GatewayChallenge"][] = array( "Gateway_Extras_ReCaptcha::onChallenge" );
Index: branches/fundraising/extensions/DonationInterface/extras/recaptcha/recaptcha.body.php
@@ -3,7 +3,7 @@
44 * Validates a transaction against MaxMind's minFraud service
55 */
66
7 -class PayflowProGateway_Extras_reCaptcha extends PayflowProGateway_Extras {
 7+class Gateway_Extras_reCaptcha extends Gateway_Extras {
88
99 /**
1010 * Container for singelton instance of self
@@ -16,9 +16,19 @@
1717 */
1818 public $recap_err;
1919
20 - public function __construct() {
21 - parent::__construct();
22 -
 20+ public function __construct( &$gateway_adapter ) {
 21+ parent::__construct( &$gateway_adapter );
 22+
 23+ //stash all the vars that reCaptcha is going to need in a global just for it.
 24+ //I know this is vaguely unpleasant, but it's the quickest way back to zero.
 25+ global $wgReCaptchaConfData;
 26+ $wgReCaptchaConfData['UseHTTPProxy'] = $this->getGlobal( 'RecaptchaUseHTTPProxy' );
 27+ $wgReCaptchaConfData['HTTPProxy'] = $this->getGlobal( 'RecaptchaHTTPProxy' );
 28+ $wgReCaptchaConfData['Timeout'] = $this->getGlobal( 'RecaptchaTimeout' );
 29+ $wgReCaptchaConfData['UseSSL'] = $this->getGlobal( 'RecaptchaUseSSL' );
 30+ $wgReCaptchaConfData['ComsRetryLimit'] = $this->getGlobal( 'RecaptchaComsRetryLimit' );
 31+ $wgReCaptchaConfData['GatewayClass'] = $this->gateway_adapter->getGatewayAdapterClass(); //for properly routing the logging
 32+
2333 // load the reCaptcha API
2434 require_once( dirname( __FILE__ ) . '/recaptcha-php/recaptchalib.php' );
2535 }
@@ -26,44 +36,49 @@
2737 /**
2838 * Handle the challenge logic
2939 */
30 - public function challenge( &$pfp_gateway_object, &$data ) {
 40+ public function challenge() {
3141 // if captcha posted, validate
3242 if ( isset( $_POST[ 'recaptcha_response_field' ] ) ) {
3343 // check the captcha response
3444 $captcha_resp = $this->check_captcha();
3545 if ( $captcha_resp->is_valid ) {
3646 // if validated, update the action and move on
37 - $this->log( $data[ 'contribution_tracking_id' ], 'Captcha passed' );
38 - $pfp_gateway_object->action = "process";
 47+ $this->log( $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'Captcha passed' );
 48+ $this->gateway_adapter->action = "process";
3949 return TRUE;
4050 } else {
4151 $this->recap_err = $captcha_resp->error;
42 - $this->log( $data[ 'contribution_tracking_id' ], 'Captcha failed' );
 52+ $this->log( $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'Captcha failed' );
4353 }
4454 }
4555 // display captcha
46 - $this->display_captcha( $pfp_gateway_object, $data );
 56+ $this->display_captcha();
4757 return TRUE;
4858 }
4959
5060 /**
5161 * Display the submission form with the captcha injected into it
5262 */
53 - public function display_captcha( &$pfp_gateway_object, &$data ) {
54 - global $wgOut, $wgPayflowRecaptchaPublicKey, $wgPayflowRecaptchaUseSSL;
 63+ public function display_captcha() {
 64+ global $wgOut;
 65+ $publicKey = $this->getGlobal( 'RecaptchaPublicKey' );
 66+ $useSSL = $this->getGlobal( 'RecaptchaUseSSL' );
5567
5668 // log that a captcha's been triggered
57 - $this->log( $data[ 'contribution_tracking_id' ], 'Captcha triggered' );
 69+ $this->log( $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'Captcha triggered' );
5870
5971 // construct the HTML used to display the captcha
6072 $captcha_html = Xml::openElement( 'div', array( 'id' => 'mw-donate-captcha' ) );
61 - $captcha_html .= recaptcha_get_html( $wgPayflowRecaptchaPublicKey, $this->recap_err, $wgPayflowRecaptchaUseSSL );
62 - $captcha_html .= '<span class="creditcard-error-msg">' . wfMsg( 'payflowpro_gateway-error-msg-captcha-please' ) . '</span>';
 73+ $captcha_html .= recaptcha_get_html( $publicKey, $this->recap_err, $useSSL );
 74+ $captcha_html .= '<span class="creditcard-error-msg">' . wfMsg( $this->gateway_adapter->getIdentifier() . '_gateway-error-msg-captcha-please' ) . '</span>';
6375 $captcha_html .= Xml::closeElement( 'div' ); // close div#mw-donate-captcha
6476
6577 // load up the form class
66 - $form_class = $pfp_gateway_object->getFormClass();
67 - $form_obj = new $form_class( $data, $pfp_gateway_object->errors );
 78+ $form_class = $this->gateway_adapter->getFormClass();
 79+
 80+ //hmm. Looking at this now, makes me want to say
 81+ //TODO: Refactor the Form Class constructors. Again.
 82+ $form_obj = new $form_class( $this->gateway_adapter->getData(), $this->gateway_adapter->getValidationErrors(), $this->gateway_adapter);
6883
6984 // set the captcha HTML to use in the form
7085 $form_obj->setCaptchaHTML( $captcha_html );
@@ -76,8 +91,9 @@
7792 * Check recaptcha answer
7893 */
7994 public function check_captcha() {
80 - global $wgPayflowRecaptchaPrivateKey, $wgRequest;
81 - $resp = recaptcha_check_answer( $wgPayflowRecaptchaPrivateKey,
 95+ global $wgRequest;
 96+ $privateKey = $this->getGlobal( 'RecaptchaPrivateKey' );
 97+ $resp = recaptcha_check_answer( $privateKey,
8298 wfGetIP(),
8399 $wgRequest->getText( 'recaptcha_challenge_field' ),
84100 $wgRequest->getText( 'recaptcha_response_field' ) );
@@ -85,13 +101,13 @@
86102 return $resp;
87103 }
88104
89 - static function onChallenge( &$pfp_gateway_object, &$data ) {
90 - return self::singleton()->challenge( $pfp_gateway_object, $data );
 105+ static function onChallenge( &$gateway_adapter ) {
 106+ return self::singleton( &$gateway_adapter )->challenge();
91107 }
92108
93 - static function singleton() {
 109+ static function singleton( &$gateway_adapter ) {
94110 if ( !self::$instance ) {
95 - self::$instance = new self;
 111+ self::$instance = new self( &$gateway_adapter );
96112 }
97113 return self::$instance;
98114 }
Index: branches/fundraising/extensions/DonationInterface/extras/extras.php
@@ -1,29 +1,29 @@
22 <?php
 3+
34 /**
4 - * An abstract class and set up for payflowpro gateway 'extras'
 5+ * An abstract class and set up for gateway 'extras'
56 *
67 * To install:
78 * require_once( "$IP/extensions/DonationInterface/extras/extras.php"
89 * Note: This should be specified in LocalSettings.php BEFORE requiring any of the other 'extras'
910 */
10 -
1111 if ( !defined( 'MEDIAWIKI' ) ) {
12 - die( "This file is part of PayflowPro Gateway extension. It is not a valid entry point.\n" );
 12+ die( "This file is part of Gateway extension. It is not a valid entry point.\n" );
1313 }
1414
15 -$wgExtensionCredits['payflowprogateway_extras'][] = array(
16 - 'name' => 'extras',
17 - 'author' => 'Arthur Richards',
18 - 'url' => '',
19 - 'description' => "This extension handles some of the set up required for PayflowPro Gateway extras"
 15+$wgExtensionCredits['gateway_extras'][] = array(
 16+ 'name' => 'extras',
 17+ 'author' => 'Arthur Richards',
 18+ 'url' => '',
 19+ 'description' => "This extension handles some of the set up required for Gateway extras"
2020 );
2121
2222 /**
23 - * Full path to file to use for logging for Payflowpro Gateway scripts
 23+ * Full path to file to use for logging for Gateway scripts
2424 *
2525 * Declare in LocalSettings.php
2626 */
27 -$wgPayflowGatewayLog = '';
 27+$wgDonationInterfaceExtrasLog = '';
2828
2929 $dir = dirname( __FILE__ ) . "/";
30 -$wgAutoloadClasses['PayflowProGateway_Extras'] = $dir . "extras.body.php";
\ No newline at end of file
 30+$wgAutoloadClasses['Gateway_Extras'] = $dir . "extras.body.php";
\ No newline at end of file
Index: branches/fundraising/extensions/DonationInterface/gateway_forms/Form.php
@@ -123,15 +123,6 @@
124124 }
125125
126126 /**
127 - * Fetch the array of iso country codes => country names
128 - * @return array
129 - */
130 - public function getCountries() {
131 - require_once( dirname( __FILE__ ) . '/includes/countryCodes.inc' );
132 - return countryCodes();
133 - }
134 -
135 - /**
136127 * Generate the menu select of countries
137128 * @fixme It would be great if we could default the country to the user's locale
138129 * @fixme We should also do a locale-based asort on the country dropdown
@@ -142,7 +133,7 @@
143134 $country_options = '';
144135
145136 // create a new array of countries with potentially translated country names for alphabetizing later
146 - foreach ( $this->getCountries() as $iso_value => $full_name ) {
 137+ foreach ( GatewayForm::getCountries() as $iso_value => $full_name ) {
147138 $countries[$iso_value] = wfMsg( 'payflowpro_gateway-country-dropdown-' . $iso_value );
148139 }
149140
Index: branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect_resultswitcher.body.php
@@ -160,7 +160,7 @@
161161 * @return array
162162 */
163163 public function prepareStompTransaction( $data, $responseArray, $responseMsg ) {
164 - $countries = $this->getCountries();
 164+ $countries = GatewayForm::getCountries();
165165
166166 $transaction = array( );
167167
Index: branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect_gateway.body.php
@@ -85,8 +85,6 @@
8686 // The form was submitted and the payment method has been set
8787 $this->adapter->log( "Form posted and payment method set." );
8888
89 - // increase the count of attempts
90 - //++$data['numAttempt'];
9189 // Check form for errors
9290
9391 $options = array();
@@ -133,40 +131,9 @@
134132 throw new Exception( $message );
135133 }
136134
137 -// self::log( $data[ 'order_id' ] . " Preparing to query MaxMind" );
138 -// wfRunHooks( 'PayflowGatewayValidate', array( &$this, &$data ) );
139 -// self::log( $data[ 'order_id' ] . ' Finished querying Maxmind' );
140 -//
141 -// // if the transaction was flagged for review
142 -// if ( $this->action == 'review' ) {
143 -// // expose a hook for external handling of trxns flagged for review
144 -// wfRunHooks( 'PayflowGatewayReview', array( &$this, &$data ));
145 -// }
146 -//
147 -// // if the transaction was flagged to be 'challenged'
148 -// if ( $this->action == 'challenge' ) {
149 -// // expose a hook for external handling of trxns flagged for challenge (eg captcha)
150 -// wfRunHooks( 'PayflowGatewayChallenge', array( &$this, &$data ) );
151 -// }
152 -//
153 -// // if the transaction was flagged for rejection
154 -// if ( $this->action == 'reject' ) {
155 -// // expose a hook for external handling of trxns flagged for rejection
156 -// wfRunHooks( 'PayflowGatewayReject', array( &$this, &$data ) );
157 -//
158 -// $this->fnPayflowDisplayDeclinedResults( '' );
159 -// $this->fnPayflowUnsetEditToken();
160 -// }
161 -//
162 -// // if the transaction was flagged for processing
163 -// if ( $this->action == 'process' ) {
164 -// // expose a hook for external handling of trxns ready for processing
165 -// wfRunHooks( 'PayflowGatewayProcess', array( &$this, &$data ) );
166 -// $this->fnGlobalCollectProcessTransaction( $data, $payflow_data );
167 -// }
168 -//
169 -// // expose a hook for any post processing
170 -// wfRunHooks( 'PayflowGatewayPostProcess', array( &$this, &$data ) );
 135+
 136+ //TODO: add all the hooks back in.
 137+
171138 }
172139 } else {
173140 // Display form for the first time
Index: branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php
@@ -282,7 +282,8 @@
283283 }
284284
285285 function processResponse( $response ) {
286 - //TODO: Stuff.
 286+ //set the transaction result message
 287+ $this->setTransactionResult( "Response Status: " . $response['STATUSID'], 'txn_message' ); //TODO: Translate for GC.
287288 }
288289
289290 function defineStagedVars() {
Index: branches/fundraising/extensions/DonationInterface/gateway_common/gateway.adapter.php
@@ -97,6 +97,9 @@
9898 protected $postdatadefaults;
9999 protected $xmlDoc;
100100 protected $dataObj;
 101+ protected $transaction_results;
 102+ protected $form_class;
 103+ protected $validation_errors;
101104
102105 //ALL OF THESE need to be redefined in the children. Much voodoo depends on the accuracy of these constants.
103106 const GATEWAY_NAME = 'Donation Gateway';
@@ -176,7 +179,11 @@
177180 if ( empty( $val ) ) {
178181 return $this->postdata;
179182 } else {
180 - return $this->postdata[$val];
 183+ if ( array_key_exists( $val, $this->postdata ) ) {
 184+ return $this->postdata[$val];
 185+ } else {
 186+ return null;
 187+ }
181188 }
182189 }
183190
@@ -324,12 +331,13 @@
325332 function do_transaction( $transaction ) {
326333 $this->currentTransaction( $transaction );
327334 //update the contribution tracking data
 335+ $this->incrementNumAttempt();
328336 $this->dataObj->updateContributionTracking( defined( 'OWA' ) );
329337 if ( $this->getCommunicationType() === 'xml' ) {
330338 $this->getStopwatch( "buildRequestXML" );
331339 $xml = $this->buildRequestXML();
332340 $this->saveCommunicationStats( "buildRequestXML", $transaction );
333 - $returned = $this->curl_transaction( $xml );
 341+ $txn_ok = $this->curl_transaction( $xml );
334342 //put the response in a universal form, and return it.
335343 }
336344
@@ -339,37 +347,45 @@
340348 $this->getStopwatch( "buildRequestNameValueString" );
341349 $namevalstring = $this->buildRequestNameValueString();
342350 $this->saveCommunicationStats( "buildRequestNameValueString", $transaction );
343 - $returned = $this->curl_transaction( $namevalstring );
 351+ $txn_ok = $this->curl_transaction( $namevalstring );
344352 //put the response in a universal form, and return it.
345353 }
346354
347 - self::log( "RETURNED FROM CURL:" . print_r( $returned, true ) );
348 - if ( $returned['result'] === false ) { //couldn't make contact. Bail.
349 - return $returned;
 355+ if ( $txn_ok === false ) { //nothing to process, so we have to build it manually
 356+ self::log( "Transaction Communication failed" . print_r( $this->getTransactionAllResults(), true ) );
 357+ return array(
 358+ 'status' => false,
 359+ 'message' => "$transaction Communication Failed!",
 360+ 'errors' => array(
 361+ '1000000' => 'communication failure' //...stupid code.
 362+ ),
 363+ );
350364 }
351365
352 - //get the status of the response
353 - $formatted = $this->getFormattedResponse( $returned['result'] );
354 - $returned['status'] = $this->getResponseStatus( $formatted );
 366+ self::log( "RETURNED FROM CURL:" . print_r( $this->getTransactionAllResults(), true ) );
355367
356 - //get errors
357 - $returned['errors'] = $this->getResponseErrors( $formatted );
 368+ //set the status of the response
 369+ $formatted = $this->getFormattedResponse( $this->getTransactionRawResponse() );
 370+ $this->setTransactionResult( $this->getResponseStatus( $formatted ), 'status' );
358371
 372+ //set errors
 373+ $this->setTransactionResult( $this->getResponseErrors( $formatted ), 'errors' );
 374+
359375 //if we're still okay (hey, even if we're not), get relevent dataz.
360 - $returned['data'] = $this->getResponseData( $formatted );
 376+ $this->setTransactionResult( $this->getResponseData( $formatted ), 'data' );
361377
362 - $this->processResponse( $returned );
 378+ $this->processResponse( $formatted );
363379
364380 //TODO: Actually pull these from somewhere legit.
365 - if ( $returned['status'] === true ) {
366 - $returned['message'] = "$transaction Transaction Successful!";
367 - } elseif ( $returned['status'] === false ) {
368 - $returned['message'] = "$transaction Transaction FAILED!";
 381+ if ( $this->getTransactionStatus() === true ) {
 382+ $this->setTransactionResult( "$transaction Transaction Successful!", 'message' );
 383+ } elseif ( $this->getTransactionStatus() === false ) {
 384+ $this->setTransactionResult( "$transaction Transaction FAILED!", 'message' );
369385 } else {
370 - $returned['message'] = "$transaction Transaction... weird. I have no idea what happened there.";
 386+ $this->setTransactionResult( "$transaction Transaction... weird. I have no idea what happened there.", 'message' );
371387 }
372388
373 - return $returned;
 389+ return $this->getTransactionAllResults();
374390
375391 //speaking of universal form:
376392 //$result['status'] = something I wish could be boiled down to a bool, but that's way too optimistic, I think.
@@ -398,7 +414,7 @@
399415 // set proxy settings if necessary
400416 if ( self::getGlobal( 'UseHTTPProxy' ) ) {
401417 $opts[CURLOPT_HTTPPROXYTUNNEL] = 1;
402 - $opts[CURLOPT_PROXY] = self::getGlobal( 'UseHTTPProxy' );
 418+ $opts[CURLOPT_PROXY] = self::getGlobal( 'HTTPProxy' );
403419 }
404420 return $opts;
405421 }
@@ -455,38 +471,39 @@
456472 // in case there is a general network issue
457473 $i = 1;
458474
459 - $return = array( );
 475+ $results = array( );
460476
461477 while ( $i++ <= 3 ) {
462478 self::log( $this->postdatadefaults['order_id'] . ' Preparing to send transaction to ' . self::getGatewayName() );
463 - $return['result'] = curl_exec( $ch );
464 - $return['headers'] = curl_getinfo( $ch );
 479+ $results['result'] = curl_exec( $ch );
 480+ $results['headers'] = curl_getinfo( $ch );
465481
466 - if ( $return['headers']['http_code'] != 200 && $return['headers']['http_code'] != 403 ) {
 482+ if ( $results['headers']['http_code'] != 200 && $results['headers']['http_code'] != 403 ) {
467483 self::log( $this->postdatadefaults['order_id'] . ' Failed sending transaction to ' . self::getGatewayName() . ', retrying' );
468484 sleep( 1 );
469 - } elseif ( $return['headers']['http_code'] == 200 || $return['headers']['http_code'] == 403 ) {
 485+ } elseif ( $results['headers']['http_code'] == 200 || $results['headers']['http_code'] == 403 ) {
470486 self::log( $this->postdatadefaults['order_id'] . ' Finished sending transaction to ' . self::getGatewayName() );
471487 break;
472488 }
473489 }
474490
475 - $this->saveCommunicationStats( __FUNCTION__, $this->currentTransaction(), "Request:" . print_r( $data, true ) . "\nResponse" . print_r( $return, true ) );
 491+ $this->saveCommunicationStats( __FUNCTION__, $this->currentTransaction(), "Request:" . print_r( $data, true ) . "\nResponse" . print_r( $results, true ) );
476492
477 - if ( $return['headers']['http_code'] != 200 ) {
478 - $return['result'] = false;
 493+ if ( $results['headers']['http_code'] != 200 ) {
 494+ $results['result'] = false;
479495 //TODO: i18n here!
480496 //TODO: But also, fire off some kind of "No response from the gateway" thing to somebody so we know right away.
481 - $return['message'] = 'No response from ' . self::getGatewayName() . '. Please try again later!';
 497+ $results['message'] = 'No response from ' . self::getGatewayName() . '. Please try again later!';
482498 $when = time();
483499 self::log( $this->postdatadefaults['order_id'] . ' No response from ' . self::getGatewayName() . ': ' . curl_error( $ch ) );
484500 curl_close( $ch );
485 - return $return;
 501+ return false;
486502 }
487503
488504 curl_close( $ch );
489505
490 - return $return;
 506+ $this->setTransactionResult( $results );
 507+ return true;
491508 }
492509
493510 function stripXMLResponseHeaders( $rawResponse ) {
@@ -499,16 +516,18 @@
500517 return false;
501518 }
502519 $justXML = substr( $rawResponse, $xmlStart );
 520+ $this->setTransactionResult( $justXML, 'unparsed_data' );
503521 return $justXML;
504522 }
505523
506524 function stripNameValueResponseHeaders( $rawResponse ) {
507525 $result = strstr( $rawResponse, 'RESULT' );
 526+ $this->setTransactionResult( $result, 'unparsed_data' );
508527 return $result;
509528 }
510529
511 - public static function log( $msg, $log_level=LOG_INFO ) {
512 - $identifier = self::getIdentifier() . "_gateway";
 530+ public static function log( $msg, $log_level=LOG_INFO, $log_id_suffix = '' ) {
 531+ $identifier = self::getIdentifier() . "_gateway" . $log_id_suffix;
513532
514533 // if we're not using the syslog facility, use wfDebugLog
515534 if ( !self::getGlobal( 'UseSyslog' ) ) {
@@ -817,4 +836,101 @@
818837
819838 $this->transaction_type = $transaction_type;
820839 }
 840+
 841+ public function getTransactionAllResults() {
 842+ if ( !empty( $this->transaction_results ) && is_array( $this->transaction_results ) ) {
 843+ return $this->transaction_results;
 844+ } else {
 845+ return false;
 846+ }
 847+ }
 848+
 849+ public function setTransactionResult( $value, $key = false ) {
 850+ if ( $key === false ) {
 851+ $this->transaction_results = $value;
 852+ } else {
 853+ $this->transaction_results[$key] = $value;
 854+ }
 855+ }
 856+
 857+ public function getTransactionRawResponse() {
 858+ if ( array_key_exists( 'result', $this->transaction_results ) ) {
 859+ return $this->transaction_results['result'];
 860+ } else {
 861+ return false;
 862+ }
 863+ }
 864+
 865+ public function getTransactionStatus() {
 866+ if ( array_key_exists( 'status', $this->transaction_results ) ) {
 867+ return $this->transaction_results['status'];
 868+ } else {
 869+ return false;
 870+ }
 871+ }
 872+
 873+ public function getTransactionMessage() {
 874+ if ( array_key_exists( 'txn_message', $this->transaction_results ) ) {
 875+ return $this->transaction_results['txn_message'];
 876+ } else {
 877+ return false;
 878+ }
 879+ }
 880+
 881+ public function getTransactionData() { //this is the FORMATTED data returned from the reply.
 882+ if ( array_key_exists( 'data', $this->transaction_results ) ) {
 883+ return $this->transaction_results['data'];
 884+ } else {
 885+ return false;
 886+ }
 887+ }
 888+
 889+ public function setFormClass( $formClassName ) {
 890+ //I'm adding this because Captcha needs it, and we're gonna fire the hook inside. Nothing else really needs it as far as I know.
 891+ $this->form_class = $formClassName;
 892+ }
 893+
 894+ public function getFormClass() {
 895+ if ( isset( $this->form_class ) && class_exists( $this->form_class ) ) {
 896+ return $this->form_class;
 897+ } else {
 898+ return false;
 899+ }
 900+ }
 901+
 902+ public function getGatewayAdapterClass() {
 903+ return get_called_class();
 904+ }
 905+
 906+ public function setValidationErrors( $errors ) {
 907+ $this->validation_errors = $errors;
 908+ }
 909+
 910+ public function getValidationErrors() {
 911+ if ( !empty( $this->validation_errors ) ) {
 912+ return $this->validation_errors;
 913+ } else {
 914+ return false;
 915+ }
 916+ }
 917+
 918+ public function incrementNumAttempt() {
 919+ $this->dataObj->incrementNumAttempt();
 920+ }
 921+
 922+ public function setHash( $hashval ) {
 923+ $this->dataObj->setVal( 'data_hash', $hashval );
 924+ }
 925+
 926+ public function unsetHash() {
 927+ $this->dataObj->expunge( 'data_hash' );
 928+ }
 929+
 930+ public function setActionHash( $hashval ) {
 931+ $this->dataObj->setVal( 'action', $hashval );
 932+ }
 933+
 934+ public function unsetActionHash() {
 935+ $this->dataObj->expunge( 'action' );
 936+ }
821937 }
Index: branches/fundraising/extensions/DonationInterface/gateway_common/DonationData.php
@@ -769,6 +769,31 @@
770770 $this->normalizeAndSanitize();
771771 }
772772
 773+ public function incrementNumAttempt() {
 774+ if ( $this->isSomething( 'numAttempt' ) ) {
 775+ $attempts = $this->getVal( 'numAttempt' );
 776+ if ( is_numeric( $attempts ) ) {
 777+ $this->setVal( 'numAttempt', $attempts + 1 );
 778+ } else {
 779+ //assume garbage = 0, so...
 780+ $this->setVal( 'numAttempt', 1 );
 781+ }
 782+ }
 783+ }
 784+
 785+ public function decrementNumAttempt() {
 786+ //minfraud...
 787+ if ( $this->isSomething( 'numAttempt' ) ) {
 788+ $attempts = $this->getVal( 'numAttempt' );
 789+ if ( is_numeric( $attempts ) ) {
 790+ $this->setVal( 'numAttempt', $attempts - 1 );
 791+ } else {
 792+ //I guess...
 793+ $this->setVal( 'numAttempt', 0 );
 794+ }
 795+ }
 796+ }
 797+
773798 }
774799
775800 ?>
Index: branches/fundraising/extensions/DonationInterface/gateway_common/GatewayForm.php
@@ -29,6 +29,7 @@
3030 * @var array
3131 */
3232 public $errors = array( );
 33+ public $adapter; //the adapter goes here.
3334
3435 /**
3536 * The form is assumed to be successful. Errors in the form must set this to
@@ -113,6 +114,7 @@
114115 //$error[ 'card_num' ] = wfMsg( $gateway_identifier . '_gateway-error-msg-card-num' );
115116 }
116117
 118+ $this->adapter->setValidationErrors( $error );
117119 return $error_result;
118120 }
119121
@@ -393,6 +395,9 @@
394396 }
395397 }
396398 $this->form_class = $class_name;
 399+
 400+ //this should... maybe replace the other thing? I need it in the adapter so reCaptcha can get to it.
 401+ $this->adapter->setFormClass( $class_name );
397402 }
398403
399404 /**
@@ -570,6 +575,16 @@
571576 // submit the data to the paypal redirect URL
572577 $wgOut->redirect( $this->adapter->getPaypalRedirectURL() );
573578 }
 579+
 580+
 581+ /**
 582+ * Fetch the array of iso country codes => country names
 583+ * @return array
 584+ */
 585+ public static function getCountries() {
 586+ require_once( dirname( __FILE__ ) . '/../gateway_forms/includes/countryCodes.inc' );
 587+ return countryCodes();
 588+ }
574589
575590 /**
576591 * Get validate form result
@@ -593,4 +608,4 @@
594609
595610 }
596611
597 -//end of GatewayForm class definiton
\ No newline at end of file
 612+//end of GatewayForm class definiton

Follow-up revisions

RevisionCommit summaryAuthorDate
r98581Various bug squashings after my last big commit. Also moved all the runHooks ...khorn23:09, 30 September 2011
r98826More bug squashing surrounding the extras in DonationInterface. r98498khorn23:09, 3 October 2011
r98830Correcting the pfp gateway identifier in Donation Interface. r98498khorn23:30, 3 October 2011
r98833Found a bug that truncated some values during key-value array translation of ...khorn23:45, 3 October 2011
r98844Located and fixed a couple places where an old function was being called, ins...khorn01:40, 4 October 2011
r98921Even more bug fixes and adjustments. The biggest one in this batch would be a...khorn21:05, 4 October 2011
r99036Latest round of bug fixes and additions for DonationInterface:...khorn19:52, 5 October 2011
r99058Even more bug fixes and additions for DonationInterface:...khorn23:02, 5 October 2011

Comments

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

All follow-ups have been reviewed.

Status & tagging log