Index: trunk/extensions/DonationInterface/extras/extras.php |
— | — | @@ -1,29 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * An abstract class and set up for payflowpro gateway 'extras' |
5 | | - * |
6 | | - * To install: |
7 | | - * require_once( "$IP/extensions/DonationInterface/payflowpro_gateway/extras/extras.php" |
8 | | - * Note: This should be specified in LocalSettings.php BEFORE requiring any of the other 'extras' |
9 | | - */ |
10 | | - |
11 | | -if ( !defined( 'MEDIAWIKI' ) ) { |
12 | | - die( "This file is part of PayflowPro Gateway extension. It is not a valid entry point.\n" ); |
13 | | -} |
14 | | - |
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" |
20 | | -); |
21 | | - |
22 | | -/** |
23 | | - * Full path to file to use for logging for Payflowpro Gateway scripts |
24 | | - * |
25 | | - * Declare in LocalSettings.php |
26 | | - */ |
27 | | -$wgPayflowGatewayLog = ''; |
28 | | - |
29 | | -$dir = dirname( __FILE__ ) . "/"; |
30 | | -$wgAutoloadClasses['PayflowProGateway_Extras'] = $dir . "extras.body.php"; |
\ No newline at end of file |
Index: trunk/extensions/DonationInterface/extras/custom_filters/custom_filters.php |
— | — | @@ -1,48 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * Provides a unified way to define and run custom filters for incoming transactions |
5 | | - * |
6 | | - * Running filters through 'custom filters' rather than directly through the validate hook in the gateway |
7 | | - * offers the advantage of simplifying the passage of relvent data between filters/validators that's |
8 | | - * needed to perform more complex validation/filtering of transactions. |
9 | | - * |
10 | | - * 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 | | - * CustomFilter object to the filter. The gateway object and its data are included in the CustomFilter |
13 | | - * object. |
14 | | - */ |
15 | | - |
16 | | -if ( !defined( 'MEDIAWIKI' ) ) { |
17 | | - die( "This file is part of the MinFraud for PayflowPro Gateway extension. It is not a valid entry point.\n" ); |
18 | | -} |
19 | | - |
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.' |
25 | | -); |
26 | | - |
27 | | -/** |
28 | | - * Define the action to take for a given $risk_score |
29 | | - */ |
30 | | -$wgPayflowGatewayCustomFiltersActionRanges = array( |
31 | | - 'process' => array( 0, 100 ), |
32 | | - 'review' => array( -1, -1 ), |
33 | | - 'challenge' => array( -1, -1 ), |
34 | | - 'reject' => array( -1, -1 ), |
35 | | -); |
36 | | - |
37 | | -/** |
38 | | - * A value for tracking the 'riskiness' of a transaction |
39 | | - * |
40 | | - * The action to take based on a transaction's riskScore is determined by |
41 | | - * $action_ranges. This is built assuming a range of possible risk scores |
42 | | - * as 0-100, although you can probably bend this as needed. |
43 | | - */ |
44 | | -$wgPayflowGatewayCustomFiltersRiskScore = 0; |
45 | | - |
46 | | -$dir = dirname( __FILE__ ) . "/"; |
47 | | -$wgAutoloadClasses['PayflowProGateway_Extras_CustomFilters'] = $dir . "custom_filters.body.php"; |
48 | | - |
49 | | -$wgHooks["PayflowGatewayValidate"][] = array( 'PayflowProGateway_Extras_CustomFilters::onValidate' ); |
Index: trunk/extensions/DonationInterface/extras/custom_filters/custom_filters.body.php |
— | — | @@ -1,6 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -class PayflowProGateway_Extras_CustomFilters extends PayflowProGateway_Extras { |
| 4 | +class Gateway_Extras_CustomFilters extends Gateway_Extras { |
| 5 | + |
5 | 6 | /** |
6 | 7 | * A value for tracking the 'riskiness' of a transaction |
7 | 8 | * |
— | — | @@ -18,35 +19,15 @@ |
19 | 20 | public $action_ranges; |
20 | 21 | |
21 | 22 | /** |
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 | | - /** |
37 | 23 | * A container for an instance of self |
38 | 24 | */ |
39 | 25 | static $instance; |
40 | 26 | |
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->gateway_adapter->getGlobal( 'CustomFiltersActionRanges' ); |
| 31 | + $this->risk_score = $this->gateway_adapter->getGlobal( 'CustomFiltersRiskScore' ); |
51 | 32 | } |
52 | 33 | |
53 | 34 | /** |
— | — | @@ -56,11 +37,13 @@ |
57 | 38 | */ |
58 | 39 | public function determineAction() { |
59 | 40 | // 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; |
62 | 45 | |
63 | 46 | 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] ) { |
65 | 48 | return $action; |
66 | 49 | } |
67 | 50 | } |
— | — | @@ -71,22 +54,24 @@ |
72 | 55 | */ |
73 | 56 | public function validate() { |
74 | 57 | // 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(); |
77 | 60 | |
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 ); |
80 | 63 | return TRUE; |
81 | 64 | } |
82 | 65 | |
83 | | - static function onValidate( &$pfp_gateway_object, &$data ) { |
84 | | - return self::singleton( $pfp_gateway_object, $data )->validate(); |
| 66 | + static function onValidate( &$gateway_adapter ) { |
| 67 | + $gateway_adapter->debugarray[] = 'custom filters onValidate hook!'; |
| 68 | + return self::singleton( $gateway_adapter )->validate(); |
85 | 69 | } |
86 | 70 | |
87 | | - static function singleton( &$pfp_gateway_object, &$data ) { |
| 71 | + static function singleton( &$gateway_adapter ) { |
88 | 72 | if ( !self::$instance ) { |
89 | | - self::$instance = new self( $pfp_gateway_object, $data ); |
| 73 | + self::$instance = new self( $gateway_adapter ); |
90 | 74 | } |
91 | 75 | return self::$instance; |
92 | 76 | } |
| 77 | + |
93 | 78 | } |
Property changes on: trunk/extensions/DonationInterface/extras/custom_filters/custom_filters.body.php |
___________________________________________________________________ |
Added: svn:mergeinfo |
94 | 79 | Merged /branches/fundraising/extensions/DonationInterface/extras/custom_filters/custom_filters.body.php:r98262-100243 |
95 | 80 | Merged /branches/fundraising/extensions/DonationInterface/payflowpro_gateway/extras/custom_filters/custom_filters.body.php:r95444-98261 |
Index: trunk/extensions/DonationInterface/extras/custom_filters/filters/source/source.body.php |
— | — | @@ -1,6 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -class PayflowProGateway_Extras_CustomFilters_Source extends PayflowProGateway_Extras { |
| 4 | +class Gateway_Extras_CustomFilters_Source extends Gateway_Extras { |
| 5 | + |
5 | 6 | /** |
6 | 7 | * Container for an instance of self |
7 | 8 | * @var object |
— | — | @@ -13,14 +14,14 @@ |
14 | 15 | */ |
15 | 16 | public $cfo; |
16 | 17 | |
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; |
20 | 21 | } |
21 | 22 | |
22 | 23 | public function filter() { |
23 | 24 | // pull out the source from the filter object |
24 | | - $source = $this->cfo->gateway_data['utm_source']; |
| 25 | + $source = $this->gateway_adapter->getData( 'utm_source' ); |
25 | 26 | |
26 | 27 | // a very complex filtering algorithm for sources |
27 | 28 | global $wgCustomFiltersSrcRules; |
— | — | @@ -37,9 +38,7 @@ |
38 | 39 | $log_msg .= "\t\"" . addslashes( $regex ) . "\""; |
39 | 40 | $log_msg .= "\t\"" . $this->cfo->risk_score . "\""; |
40 | 41 | $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 |
44 | 43 | ); |
45 | 44 | } |
46 | 45 | } |
— | — | @@ -48,6 +47,7 @@ |
49 | 48 | } |
50 | 49 | |
51 | 50 | static function onFilter( &$custom_filter_object ) { |
| 51 | + $gateway_adapter->debugarray[] = 'source onFilter hook!'; |
52 | 52 | return self::singleton( $custom_filter_object )->filter(); |
53 | 53 | } |
54 | 54 | |
— | — | @@ -57,4 +57,5 @@ |
58 | 58 | } |
59 | 59 | return self::$instance; |
60 | 60 | } |
| 61 | + |
61 | 62 | } |
Index: trunk/extensions/DonationInterface/extras/custom_filters/filters/source/source.php |
— | — | @@ -1,16 +1,16 @@ |
2 | 2 | <?php |
| 3 | + |
3 | 4 | /** |
4 | 5 | * Provides a method for filtering transactions based on source |
5 | 6 | * |
6 | 7 | * To install: |
7 | | - * require_once( "$IP/extensions/DonationInterface/payflowpro_gateway/extras/custom_filters/filters/source/source.php" ); |
| 8 | + * require_once( "$IP/extensions/DonationInterface/extras/custom_filters/filters/source/source.php" ); |
8 | 9 | */ |
9 | | - |
10 | 10 | 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" ); |
12 | 12 | } |
13 | 13 | |
14 | | -$wgExtensionCredits['payflowprogateway_customfilters_source'][] = array( |
| 14 | +$wgExtensionCredits['gateway_customfilters_source'][] = array( |
15 | 15 | 'name' => 'custom filter: source', |
16 | 16 | 'author' => 'Arthur Richards', |
17 | 17 | 'url' => '', |
— | — | @@ -28,7 +28,7 @@ |
29 | 29 | * $wgCustomFiltersSrcRules['support.cc'] = "100"; |
30 | 30 | * // increases risk score for trxns with source of 'support.cc' referrals by 100 |
31 | 31 | */ |
32 | | -$wgCustomFiltersSrcRules = array(); |
| 32 | +$wgCustomFiltersSrcRules = array( ); |
33 | 33 | |
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: trunk/extensions/DonationInterface/extras/custom_filters/filters/minfraud/minfraud.body.php |
— | — | @@ -1,4 +1,5 @@ |
2 | 2 | <?php |
| 3 | + |
3 | 4 | /** |
4 | 5 | * Wrapper for using minFraud extra as a custom filter |
5 | 6 | * |
— | — | @@ -6,37 +7,35 @@ |
7 | 8 | * with slight modifications. So all we do here is overload validate() |
8 | 9 | * and add in some extra customFilters specific stuff. |
9 | 10 | */ |
| 11 | +class Gateway_Extras_CustomFilters_MinFraud extends Gateway_Extras_MinFraud { |
10 | 12 | |
11 | | -class PayflowProGateway_Extras_CustomFilters_MinFraud extends PayflowProGateway_Extras_MinFraud { |
12 | 13 | static $instance; |
13 | 14 | |
14 | 15 | public function filter( &$custom_filter_object ) { |
15 | | - $pfp_gateway_object =& $custom_filter_object->gateway_object; |
16 | | - $data =& $custom_filter_object->gateway_data; |
17 | | - |
18 | 16 | // 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; |
20 | 19 | |
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'; |
24 | 23 | |
25 | 24 | $custom_filter_object->risk_score += $this->minfraud_response['riskScore']; |
26 | 25 | |
27 | 26 | // Write the query/response to the log |
28 | 27 | // @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 ); |
30 | 29 | return TRUE; |
31 | | - |
32 | 30 | } |
33 | 31 | |
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 | + $gateway_adapter->debugarray[] = 'minfraud onFilter hook!'; |
| 34 | + return self::singleton( &$gateway_adapter )->filter( $custom_filter_object ); |
36 | 35 | } |
37 | 36 | |
38 | | - static function singleton() { |
| 37 | + static function singleton( &$gateway_adapter ) { |
39 | 38 | if ( !self::$instance ) { |
40 | | - self::$instance = new self; |
| 39 | + self::$instance = new self( &$gateway_adapter ); |
41 | 40 | } |
42 | 41 | return self::$instance; |
43 | 42 | } |
Index: trunk/extensions/DonationInterface/extras/custom_filters/filters/minfraud/minfraud.php |
— | — | @@ -1,4 +1,5 @@ |
2 | 2 | <?php |
| 3 | + |
3 | 4 | /** |
4 | 5 | * Custom filter using minFraud |
5 | 6 | * |
— | — | @@ -12,14 +13,13 @@ |
13 | 14 | * $wgMinFraudStandalone = TRUE |
14 | 15 | * |
15 | 16 | * To install: |
16 | | - * require_once( "$IP/extensions/DonationInterface/payflowpro_gateway/extras/custom_filters/filters/minfraud.php" ); |
| 17 | + * require_once( "$IP/extensions/DonationInterface/extras/custom_filters/filters/minfraud.php" ); |
17 | 18 | */ |
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', |
21 | 21 | 'author' => 'Arthur Richards', |
22 | 22 | '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.' |
24 | 24 | ); |
25 | 25 | |
26 | 26 | /** |
— | — | @@ -32,15 +32,16 @@ |
33 | 33 | * you will want to make sure you know whether minFraud queries are |
34 | 34 | * happening before or after custom filters, defined by the order of |
35 | 35 | * your require statements in LocalSettings. |
| 36 | + * |
| 37 | + * To install the DontaionInterface extension, put the following line in LocalSettings.php: |
| 38 | + * require_once( "\$IP/extensions/DonationInterface/donationinterface.php" ); |
| 39 | + * |
| 40 | + * TODO: Outline required globals to include this bad boy! |
| 41 | + * |
36 | 42 | */ |
37 | | -$wgMinFraudStandalone = FALSE; |
38 | 43 | |
39 | | -$dir = dirname( __FILE__ ) . "/"; |
40 | | -$wgAutoloadClasses['PayflowProGateway_Extras_MinFraud'] = $dir . "../../../minfraud/minfraud.body.php"; |
41 | | -$wgAutoloadClasses['PayflowProGateway_Extras_CustomFilters_MinFraud'] = $dir . "minfraud.body.php"; |
42 | | -$wgExtensionFunctions[] = 'efCustomFiltersMinFraudSetup'; |
43 | | - |
44 | 44 | function efCustomFiltersMinFraudSetup() { |
45 | 45 | 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" ); |
47 | 48 | } |
Index: trunk/extensions/DonationInterface/extras/custom_filters/filters/referrer/referrer.php |
— | — | @@ -1,16 +1,16 @@ |
2 | 2 | <?php |
| 3 | + |
3 | 4 | /** |
4 | 5 | * Provides a method for filtering transactions based on referrer |
5 | 6 | * |
6 | 7 | * To install: |
7 | | - * require_once( "$IP/extensions/DonationInterface/payflowpro_gateway/extras/custom_filters/filters/referrer/referrer.php" ); |
| 8 | + * require_once( "$IP/extensions/DonationInterface/extras/custom_filters/filters/referrer/referrer.php" ); |
8 | 9 | */ |
9 | | - |
10 | 10 | 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" ); |
12 | 12 | } |
13 | 13 | |
14 | | -$wgExtensionCredits['payflowprogateway_customfilters_referrer'][] = array( |
| 14 | +$wgExtensionCredits['gateway_customfilters_referrer'][] = array( |
15 | 15 | 'name' => 'custom filter: referrer', |
16 | 16 | 'author' => 'Arthur Richards', |
17 | 17 | 'url' => '', |
— | — | @@ -28,7 +28,7 @@ |
29 | 29 | * $wgCustomFiltersRefRules['fraud\.com'] = "100"; |
30 | 30 | * // increases risk score for trxns with http://fraud.com referrals by 100 |
31 | 31 | */ |
32 | | -$wgCustomFiltersRefRules = array(); |
| 32 | +$wgCustomFiltersRefRules = array( ); |
33 | 33 | |
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: trunk/extensions/DonationInterface/extras/custom_filters/filters/referrer/referrer.body.php |
— | — | @@ -1,6 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -class PayflowProGateway_Extras_CustomFilters_Referrer extends PayflowProGateway_Extras { |
| 4 | +class Gateway_Extras_CustomFilters_Referrer extends Gateway_Extras { |
| 5 | + |
5 | 6 | /** |
6 | 7 | * Container for an instance of self |
7 | 8 | * @var object |
— | — | @@ -13,14 +14,14 @@ |
14 | 15 | */ |
15 | 16 | public $cfo; |
16 | 17 | |
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; |
20 | 21 | } |
21 | 22 | |
22 | 23 | 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' ); |
25 | 26 | |
26 | 27 | // a very complex filtering algorithm for referrers |
27 | 28 | global $wgCustomFiltersRefRules; |
— | — | @@ -37,9 +38,7 @@ |
38 | 39 | $log_msg .= "\t\"" . addslashes( $regex ) . "\""; |
39 | 40 | $log_msg .= "\t\"" . $this->cfo->risk_score . "\""; |
40 | 41 | $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 |
44 | 43 | ); |
45 | 44 | } |
46 | 45 | } |
— | — | @@ -48,6 +47,7 @@ |
49 | 48 | } |
50 | 49 | |
51 | 50 | static function onFilter( &$custom_filter_object ) { |
| 51 | + $gateway_adapter->debugarray[] = 'referrer onFilter hook!'; |
52 | 52 | return self::singleton( $custom_filter_object )->filter(); |
53 | 53 | } |
54 | 54 | |
— | — | @@ -57,4 +57,5 @@ |
58 | 58 | } |
59 | 59 | return self::$instance; |
60 | 60 | } |
| 61 | + |
61 | 62 | } |
Index: trunk/extensions/DonationInterface/extras/minfraud/ccfd/HTTPBase.php |
— | — | @@ -20,6 +20,7 @@ |
21 | 21 | */ |
22 | 22 | |
23 | 23 | class HTTPBase { |
| 24 | + |
24 | 25 | var $server; |
25 | 26 | var $numservers; |
26 | 27 | var $url; |
— | — | @@ -35,406 +36,411 @@ |
36 | 37 | var $wsIpaddrCacheFile; |
37 | 38 | var $useDNS; |
38 | 39 | 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 | | - } |
52 | 40 | |
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 | + } |
57 | 56 | |
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 | + } |
63 | 61 | |
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 ); |
84 | 66 | } |
85 | | - if ( $result ) { |
86 | | - return $result; |
87 | | - } |
88 | | - } |
89 | | - } |
90 | 67 | |
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 | + } |
103 | 94 | |
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 | + } |
121 | 107 | |
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 | + } |
126 | 125 | |
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 | + } |
131 | 130 | |
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 | + } |
146 | 135 | |
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 | + } |
159 | 150 | |
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 | + } else { |
| 163 | + //otherwise, this thing complains loudly when the file doesn't exist. |
| 164 | + $datetime = time(); |
| 165 | + } |
184 | 166 | |
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(); |
| 167 | + // if the ip addresses expired or don't exist then |
| 168 | + // get them from the web and write |
| 169 | + // them to the cache file |
| 170 | + if ( ( ( time() - $datetime ) > $this->wsIpaddrRefreshTimeout ) | (!$ipstr ) ) { |
| 171 | + $tryIpstr = $this->readIpAddressFromWeb(); |
| 172 | + if ( $tryIpstr ) { |
| 173 | + $ipstr = $tryIpstr; |
| 174 | + } else { |
| 175 | + if ( $this->debug == 1 ) { |
| 176 | + print "Warning, unable to get ws_ipaddr from www.maxmind.com\n"; |
| 177 | + } |
| 178 | + } |
| 179 | + // we write to cache whether or not we were able to get $tryIpStr, since |
| 180 | + // in case DNS goes down, we don't want to check app/ws_ipaddr over and over |
| 181 | + $this->writeIpAddressToCache( $this->wsIpaddrCacheFile, $ipstr ); |
| 182 | + } |
| 183 | + if ( $this->debug == 1 ) { |
| 184 | + print "reading ip address from cache\n"; |
| 185 | + print "ip str: " . $ipstr . "\n"; |
| 186 | + print "date time: " . $datetime . "\n"; |
| 187 | + } |
| 188 | + // return the ip addresses |
| 189 | + return $ipstr; |
| 190 | + } |
191 | 191 | |
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 ); |
| 192 | + function readIpAddressFromWeb() { |
| 193 | + // check if the curl module exists |
| 194 | + $url = "http://www.maxmind.com/app/ws_ipaddr"; |
| 195 | + if ( extension_loaded( 'curl' ) ) { |
| 196 | + // open curl |
| 197 | + $ch = curl_init(); |
196 | 198 | |
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 |
| 199 | + // set curl options |
| 200 | + curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); |
| 201 | + curl_setopt( $ch, CURLOPT_URL, $url ); |
| 202 | + curl_setopt( $ch, CURLOPT_TIMEOUT, $this->timeout ); |
205 | 203 | |
206 | | - // parse the url to get |
207 | | - // host, path and query |
208 | | - $url3 = parse_url( $url ); |
209 | | - $host = $url3["host"]; |
210 | | - $path = $url3["path"]; |
| 204 | + // get the content |
| 205 | + $content = curl_exec( $ch ); |
| 206 | + $content = rtrim( $content ); |
| 207 | + if ( $this->debug == 1 ) { |
| 208 | + print "using curl\n"; |
| 209 | + } |
| 210 | + } else { |
| 211 | + // we using HTTP without curl |
| 212 | + // parse the url to get |
| 213 | + // host, path and query |
| 214 | + $url3 = parse_url( $url ); |
| 215 | + $host = $url3["host"]; |
| 216 | + $path = $url3["path"]; |
211 | 217 | |
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 | | - } |
| 218 | + // open the connection |
| 219 | + $fp = fsockopen( $host, 80, $errno, $errstr, $this->timeout ); |
| 220 | + if ( $fp ) { |
| 221 | + // send the request |
| 222 | + fputs( $fp, "GET $path HTTP/1.0\nHost: " . $host . "\n\n" ); |
| 223 | + while ( !feof( $fp ) ) { |
| 224 | + $buf .= fgets( $fp, 128 ); |
| 225 | + } |
| 226 | + $lines = preg_split( "/\n/", $buf ); |
| 227 | + // get the content |
| 228 | + $content = $lines[count( $lines ) - 1]; |
| 229 | + // close the connection |
| 230 | + fclose( $fp ); |
| 231 | + } |
| 232 | + if ( $this->debug == 1 ) { |
| 233 | + print "using fsockopen\n"; |
| 234 | + } |
| 235 | + } |
| 236 | + if ( $this->debug == 1 ) { |
| 237 | + print "readIpAddressFromWeb found ip addresses: " . $content . "\n"; |
| 238 | + } |
| 239 | + // TODO fix regexp so that it checks if it only has IP addresses |
| 240 | + if ( preg_match( "/([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/", $content ) ) { |
| 241 | + return $content; |
| 242 | + } |
| 243 | + return ""; |
| 244 | + } |
239 | 245 | |
240 | | - // this function queries a single server |
241 | | - function querySingleServer( $server ) { |
242 | | - global $wgPayflowGatewayUseHTTPProxy, $wgPayflowGatewayHTTPProxy; |
| 246 | + // this function queries a single server |
| 247 | + function querySingleServer( $server ) { |
| 248 | + $useHTTPProxy = $this->gateway_adapter->getGlobal( 'UseHTTPProxy' ); |
| 249 | + $HTTPProxy = $this->gateway_adapter->getGlobal( 'HTTPProxy' ); |
243 | 250 | |
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 | | - } |
| 251 | + // check if we using the Secure HTTPS proctol |
| 252 | + if ( $this->isSecure == 1 ) { |
| 253 | + $scheme = "https://"; // Secure HTTPS proctol |
| 254 | + } else { |
| 255 | + $scheme = "http://"; // Regular HTTP proctol |
| 256 | + } |
250 | 257 | |
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 | | - } |
| 258 | + // build a query string from the hash called queries |
| 259 | + $numquerieskeys = count( $this->queries ); // get the number of keys in the hash called queries |
| 260 | + $querieskeys = array_keys( $this->queries ); // get a array of keys in the hash called queries |
| 261 | + if ( $this->debug == 1 ) { |
| 262 | + print "number of query keys " . $numquerieskeys . "\n"; |
| 263 | + } |
257 | 264 | |
258 | | - $query_string = ""; |
| 265 | + $query_string = ""; |
259 | 266 | |
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 | | - } |
| 267 | + for ( $i = 0; $i < $numquerieskeys; $i++ ) { |
| 268 | + // for each element in the hash called queries |
| 269 | + // append the key and value of the element to the query string |
| 270 | + $key = $querieskeys[$i]; |
| 271 | + $value = $this->queries[$key]; |
| 272 | + // encode the key and value before adding it to the string |
| 273 | + // $key = urlencode($key); |
| 274 | + // $value = urlencode($value); |
| 275 | + if ( $this->debug == 1 ) { |
| 276 | + print " query key " . $key . " query value " . $value . "\n"; |
| 277 | + } |
| 278 | + $query_string = $query_string . $key . "=" . $value; |
| 279 | + if ( $i < $numquerieskeys - 1 ) { |
| 280 | + $query_string = $query_string . "&"; |
| 281 | + } |
| 282 | + } |
276 | 283 | |
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 | | - } |
| 284 | + // check if the curl module exists |
| 285 | + if ( extension_loaded( 'curl' ) ) { |
| 286 | + // use curl |
| 287 | + if ( $this->debug == 1 ) { |
| 288 | + print "using curl\n"; |
| 289 | + } |
283 | 290 | |
284 | | - // open curl |
285 | | - $ch = curl_init(); |
| 291 | + // open curl |
| 292 | + $ch = curl_init(); |
286 | 293 | |
287 | | - $url = $scheme . $server . "/" . $this->url; |
| 294 | + $url = $scheme . $server . "/" . $this->url; |
288 | 295 | |
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 ); |
| 296 | + // set curl options |
| 297 | + if ( $this->debug == 1 ) { |
| 298 | + print "url " . $url . "\n"; |
| 299 | + } |
| 300 | + curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); |
| 301 | + curl_setopt( $ch, CURLOPT_URL, $url ); |
| 302 | + curl_setopt( $ch, CURLOPT_TIMEOUT, $this->timeout ); |
| 303 | + curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 ); |
297 | 304 | |
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 ); |
| 305 | + // this option lets you store the result in a string |
| 306 | + curl_setopt( $ch, CURLOPT_POST, 1 ); |
| 307 | + curl_setopt( $ch, CURLOPT_POSTFIELDS, $query_string ); |
301 | 308 | |
302 | | - // set proxy settings if necessary |
303 | | - if ( $wgPayflowGatewayUseHTTPProxy ) { |
304 | | - curl_setopt( $ch, CURLOPT_HTTPPROXYTUNNEL, 1 ); |
305 | | - curl_setopt( $ch, CURLOPT_PROXY, $wgPayflowGatewayHTTPProxy ); |
306 | | - } |
| 309 | + // set proxy settings if necessary |
| 310 | + if ( $useHTTPProxy ) { |
| 311 | + curl_setopt( $ch, CURLOPT_HTTPPROXYTUNNEL, 1 ); |
| 312 | + curl_setopt( $ch, CURLOPT_PROXY, $HTTPProxy ); |
| 313 | + } |
307 | 314 | |
308 | | - // get the content |
309 | | - $content = curl_exec( $ch ); |
| 315 | + // get the content |
| 316 | + $content = curl_exec( $ch ); |
310 | 317 | |
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) |
| 318 | + // For some reason curl_errno returns an error even when function works |
| 319 | + // Until we figure this out, will ignore curl errors - (not good i know) |
313 | 320 | // $e = curl_errno($ch);//get error or sucess |
314 | | - |
315 | 321 | // if (($e == 1) & ($this->isSecure == 1)) { |
316 | | - // HTTPS does not work print error message |
| 322 | + // HTTPS does not work print error message |
317 | 323 | // print "error: this version of curl does not support HTTPS try build curl with SSL or specify \$ccfs->isSecure = 0\n"; |
318 | 324 | // } |
319 | 325 | // if ($e > 0) { |
320 | | - // we get a error msg print it |
| 326 | + // we get a error msg print it |
321 | 327 | // print "Received error message $e from curl: " . curl_error($ch) . "\n"; |
322 | 328 | // return 0; |
323 | 329 | // } |
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 | | - } |
| 330 | + // close curl |
| 331 | + curl_close( $ch ); |
| 332 | + } else { |
| 333 | + // curl does not exist |
| 334 | + // use the fsockopen function, |
| 335 | + // the fgets function and the fclose function |
| 336 | + if ( $this->debug == 1 ) { |
| 337 | + print "using fsockopen for querySingleServer\n"; |
| 338 | + } |
333 | 339 | |
334 | | - $url = $scheme . $server . "/" . $this->url . "?" . $query_string; |
335 | | - if ( $this->debug == 1 ) { |
336 | | - print "url " . $url . " " . "\n"; |
337 | | - } |
| 340 | + $url = $scheme . $server . "/" . $this->url . "?" . $query_string; |
| 341 | + if ( $this->debug == 1 ) { |
| 342 | + print "url " . $url . " " . "\n"; |
| 343 | + } |
338 | 344 | |
339 | | - // now check if we are using regular HTTP |
340 | | - if ( $this->isSecure == 0 ) { |
341 | | - // we using regular HTTP |
| 345 | + // now check if we are using regular HTTP |
| 346 | + if ( $this->isSecure == 0 ) { |
| 347 | + // we using regular HTTP |
| 348 | + // parse the url to get |
| 349 | + // host, path and query |
| 350 | + $url3 = parse_url( $url ); |
| 351 | + $host = $url3["host"]; |
| 352 | + $path = $url3["path"]; |
| 353 | + $query = $url3["query"]; |
342 | 354 | |
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"]; |
| 355 | + // open the connection |
| 356 | + $fp = fsockopen( $host, 80, $errno, $errstr, $this->timeout ); |
| 357 | + if ( $fp ) { |
| 358 | + // send the request |
| 359 | + $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"; |
| 360 | + fputs( $fp, $post ); |
| 361 | + while ( !feof( $fp ) ) { |
| 362 | + $buf .= fgets( $fp, 128 ); |
| 363 | + } |
| 364 | + $lines = preg_split( "/\n/", $buf ); |
| 365 | + // get the content |
| 366 | + $content = $lines[count( $lines ) - 1]; |
| 367 | + // close the connection |
| 368 | + fclose( $fp ); |
| 369 | + } else { |
| 370 | + return 0; |
| 371 | + } |
| 372 | + } else { |
| 373 | + // secure HTTPS requires CURL |
| 374 | + print "error: you need to install curl if you want secure HTTPS or specify the variable to be $ccfs->isSecure = 0"; |
| 375 | + return 0; |
| 376 | + } |
| 377 | + } |
349 | 378 | |
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 | | - } |
| 379 | + if ( $this->debug == 1 ) { |
| 380 | + print "content = " . $content . "\n"; |
| 381 | + } |
| 382 | + // get the keys and values from |
| 383 | + // the string content and store them |
| 384 | + // the hash named outputstr |
| 385 | + // split content into pairs containing both |
| 386 | + // the key and the value |
| 387 | + $keyvaluepairs = explode( ";", $content ); |
373 | 388 | |
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 |
| 389 | + // get the number of key and value pairs |
| 390 | + $numkeyvaluepairs = count( $keyvaluepairs ); |
380 | 391 | |
381 | | - // split content into pairs containing both |
382 | | - // the key and the value |
383 | | - $keyvaluepairs = explode( ";", $content ); |
| 392 | + // for each pair store key and value into the |
| 393 | + // hash named outputstr |
| 394 | + $this->outputstr = array( ); |
| 395 | + for ( $i = 0; $i < $numkeyvaluepairs; $i++ ) { |
| 396 | + // split the pair into a key and a value |
| 397 | + list( $key, $value ) = explode( "=", $keyvaluepairs[$i] ); |
| 398 | + if ( $this->debug == 1 ) { |
| 399 | + print " output " . $key . " = " . $value . "\n"; |
| 400 | + } |
| 401 | + // store the key and the value into the |
| 402 | + // hash named outputstr |
| 403 | + $this->outputstr[$key] = $value; |
| 404 | + } |
| 405 | + // check if outputstr has the score if outputstr does not have |
| 406 | + // the score return 0 |
| 407 | + if ( $this->outputstr[$this->check_field] == "" ) { |
| 408 | + return 0; |
| 409 | + } |
| 410 | + // one other way to do it |
| 411 | + // if (!array_key_exists("score",$this->outputstr)) { |
| 412 | + // return 0; |
| 413 | + // } |
| 414 | + return 1; |
| 415 | + } |
384 | 416 | |
385 | | - // get the number of key and value pairs |
386 | | - $numkeyvaluepairs = count( $keyvaluepairs ); |
| 417 | + function _getTempDir() { |
| 418 | + if ( ini_get( 'upload_tmp_dir' ) ) { |
| 419 | + return ini_get( 'upload_tmp_dir' ); |
| 420 | + } |
387 | 421 | |
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 | | - } |
| 422 | + if ( substr( PHP_OS, 0, 3 ) != 'WIN' ) { |
| 423 | + return '/tmp'; |
| 424 | + } |
412 | 425 | |
413 | | - function _getTempDir() { |
414 | | - if ( ini_get( 'upload_tmp_dir' ) ) { |
415 | | - return ini_get( 'upload_tmp_dir' ); |
416 | | - } |
| 426 | + if ( isset( $_ENV['TMP'] ) ) { |
| 427 | + return $_ENV['TMP']; |
| 428 | + } |
417 | 429 | |
418 | | - if ( substr( PHP_OS, 0, 3 ) != 'WIN' ) { |
419 | | - return '/tmp'; |
420 | | - } |
| 430 | + if ( isset( $_ENV['TEMP'] ) ) { |
| 431 | + return $_ENV['TEMP']; |
| 432 | + } |
421 | 433 | |
422 | | - if ( isset( $_ENV['TMP'] ) ) { |
423 | | - return $_ENV['TMP']; |
424 | | - } |
| 434 | + if ( is_dir( 'c:\\windows\\temp' ) ) { |
| 435 | + return 'c:\\windows\\temp'; |
| 436 | + } |
425 | 437 | |
426 | | - if ( isset( $_ENV['TEMP'] ) ) { |
427 | | - return $_ENV['TEMP']; |
428 | | - } |
| 438 | + if ( is_dir( 'c:\\winnt\\temp' ) ) { |
| 439 | + return 'c:\\winnt\\temp'; |
| 440 | + } |
429 | 441 | |
430 | | - if ( is_dir( 'c:\\windows\\temp' ) ) { |
431 | | - return 'c:\\windows\\temp'; |
432 | | - } |
| 442 | + return '.'; |
| 443 | + } |
433 | 444 | |
434 | | - if ( is_dir( 'c:\\winnt\\temp' ) ) { |
435 | | - return 'c:\\winnt\\temp'; |
436 | | - } |
| 445 | +} |
437 | 446 | |
438 | | - return '.'; |
439 | | - } |
440 | | -} |
441 | 447 | ?> |
Index: trunk/extensions/DonationInterface/extras/minfraud/ccfd/LocationVerification.php |
— | — | @@ -20,31 +20,34 @@ |
21 | 21 | */ |
22 | 22 | |
23 | 23 | require_once ( "HTTPBase.php" ); |
| 24 | + |
24 | 25 | class LocationVerification extends HTTPBase { |
25 | | - var $server; |
26 | | - var $numservers; |
27 | | - var $API_VERSION; |
28 | 26 | |
29 | | - function __construct() { |
30 | | - parent::__construct(); |
31 | | - $this->isSecure = 1; // use HTTPS by default |
| 27 | + var $server; |
| 28 | + var $numservers; |
| 29 | + var $API_VERSION; |
32 | 30 | |
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 ); |
41 | 42 | |
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"; |
45 | 46 | |
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 | + |
50 | 52 | } |
| 53 | + |
51 | 54 | ?> |
Index: trunk/extensions/DonationInterface/extras/minfraud/ccfd/CreditCardFraudDetection.php |
— | — | @@ -20,64 +20,67 @@ |
21 | 21 | */ |
22 | 22 | |
23 | 23 | require_once ( "HTTPBase.php" ); |
| 24 | + |
24 | 25 | class CreditCardFraudDetection extends HTTPBase { |
25 | | - var $server; |
26 | | - var $numservers; |
27 | | - var $API_VERSION; |
28 | 26 | |
29 | | - function __construct() { |
30 | | - parent::__construct(); |
31 | | - $this->isSecure = 1; // use HTTPS by default |
| 27 | + var $server; |
| 28 | + var $numservers; |
| 29 | + var $API_VERSION; |
32 | 30 | |
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; |
59 | 60 | |
60 | 61 | |
61 | | - $this->num_allowed_fields = count( $this->allowed_fields ); |
| 62 | + $this->num_allowed_fields = count( $this->allowed_fields ); |
62 | 63 | |
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 | + } |
70 | 71 | |
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 | + |
83 | 85 | } |
| 86 | + |
84 | 87 | ?> |
Index: trunk/extensions/DonationInterface/extras/minfraud/ccfd/TelephoneVerification.php |
— | — | @@ -1,26 +1,31 @@ |
2 | 2 | <?php |
| 3 | + |
3 | 4 | require_once ( "HTTPBase.php" ); |
| 5 | + |
4 | 6 | 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 |
11 | 7 | |
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; |
17 | 11 | |
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 | + |
26 | 30 | } |
| 31 | + |
27 | 32 | ?> |
Index: trunk/extensions/DonationInterface/extras/minfraud/tests/minfraudTest.php |
— | — | @@ -1,25 +1,28 @@ |
2 | 2 | <?php |
| 3 | + |
3 | 4 | /** |
4 | 5 | * @fixme wfGetIP() in minfraud.body.php wonks this up |
5 | 6 | */ |
6 | 7 | require_once "PHPUnit/Framework.php"; |
7 | 8 | |
8 | | -class minfraudTest extends PHPUnit_Framework_TestCase |
9 | | -{ |
| 9 | +class minfraudTest extends PHPUnit_Framework_TestCase { |
| 10 | + |
10 | 11 | protected function setUp() { |
11 | 12 | $dir = dirname( __FILE__ ) . '/'; |
12 | 13 | require_once( $dir . '../../extras.php' ); |
13 | 14 | require_once( $dir . '../minfraud.body.php' ); |
14 | | - require_once( $dir . "../../../includes/countryCodes.inc" ); |
15 | | - global $wgPayflowGatewayLog; |
16 | | - $wgPayflowGatewayLog = dirname( __FILE__ ) . "/test_log"; |
| 15 | + global $wgDonationInterfaceExtrasLog; |
| 16 | + $wgDonationInterfaceExtrasLog = dirname( __FILE__ ) . "/test_log"; |
17 | 17 | $license_key = 'XBCKSF4gnHA7'; |
18 | | - $this->fixture = new PayflowProGateway_Extras_MinFraud( $license_key ); |
| 18 | + global $wgPayflowProGatewayTest; |
| 19 | + $wgPayflowProGatewayTest = true; |
| 20 | + $adapter = new PayflowProAdapter(); |
| 21 | + $this->fixture = new Gateway_Extras_MinFraud( &$adapter, $license_key ); |
19 | 22 | } |
20 | 23 | |
21 | 24 | protected function tearDown() { |
22 | | - global $wgPayflowGatewayLog; |
23 | | - unlink( $wgPayflowGatewayLog ); |
| 25 | + global $wgDonationInterfaceExtrasLog; |
| 26 | + unlink( $wgDonationInterfaceExtrasLog ); |
24 | 27 | } |
25 | 28 | |
26 | 29 | public function testCcfdInstance() { |
— | — | @@ -43,8 +46,8 @@ |
44 | 47 | $this->assertArrayHasKey( "bin", $query ); |
45 | 48 | $this->assertArrayHasKey( "txnID", $query ); |
46 | 49 | $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 |
| 50 | + $this->assertNotContains( "@", $query['domain'] ); // make sure we're only getting domains from email addresses |
| 51 | + $this->assertEquals( 6, strlen( $query['bin'] ) ); // make sure our bin is 6 digits long |
49 | 52 | } |
50 | 53 | |
51 | 54 | public function queryDataProvider() { |
— | — | @@ -68,11 +71,11 @@ |
69 | 72 | /** |
70 | 73 | * @dataProvider queryDataProvider |
71 | 74 | */ |
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 | | - }*/ |
| 75 | + /* public function testQueryMinfraud( $data ) { |
| 76 | + $query = $this->fixture->build_query( $data ); |
| 77 | + $this->fixture->query_minfraud( $query ); |
| 78 | + $this->assertType( 'array', $this->fixture->minfraud_response ); |
| 79 | + } */ |
77 | 80 | |
78 | 81 | /** |
79 | 82 | * @dataProvider hashValidateFalseData |
— | — | @@ -81,10 +84,18 @@ |
82 | 85 | $this->assertFalse( $this->fixture->validate_minfraud_query( $data ) ); |
83 | 86 | } |
84 | 87 | |
| 88 | + public function setExtrasGlobal( $varname, $value ) { |
| 89 | + //Just set the one for the adapter. |
| 90 | + $adapter_prefix = $this->fixture->gateway_adapter->getGlobalPrefix(); |
| 91 | + $globalname = $adapter_prefix . $varname; |
| 92 | + global $$globalname; |
| 93 | + $$globalname = $value; |
| 94 | + } |
| 95 | + |
85 | 96 | public function hashValidateFalseData() { |
86 | 97 | return array( |
87 | 98 | array( |
88 | | - array(), |
| 99 | + array( ), |
89 | 100 | array( 'license_key' => 'a' ), |
90 | 101 | array( |
91 | 102 | 'license_key' => 'a', |
— | — | @@ -154,29 +165,26 @@ |
155 | 166 | } |
156 | 167 | |
157 | 168 | public function testLogging() { |
158 | | - global $wgPayflowGatewayLog; |
| 169 | + global $wgDonationInterfaceExtrasLog; |
159 | 170 | $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 ) ) ); |
| 171 | + $new_fh = fopen( $wgDonationInterfaceExtrasLog, 'r' ); |
| 172 | + $this->assertEquals( '"' . date( 'c' ) . '"' . "\t\"\"\t\"\"\t\"foo\"\n", fread( $new_fh, filesize( $wgDonationInterfaceExtrasLog ) ) ); |
162 | 173 | fclose( $new_fh ); |
163 | 174 | } |
164 | 175 | |
165 | 176 | public function testGenerateHash() { |
166 | | - global $wgPayflowGatewaySalt; |
167 | | - $wgPayflowGatewaySalt = 'salt'; |
| 177 | + $this->setExtrasGlobal( 'Salt', 'salt' ); |
168 | 178 | $this->assertEquals( '5a9ee1e4a15adbf03b3ef9f7baa6caffa9f6bcd72c736498f045c073e57753e7b244bc97fe82b075eabd80778a4d56eb14406e9a1ac4b13737b2c3fd8c3717e8', $this->fixture->generate_hash( 'foo' ) ); |
169 | 179 | } |
170 | 180 | |
171 | 181 | public function testCompareHash() { |
172 | | - global $wgPayflowGatewaySalt; |
173 | | - $wgPayflowGatewaySalt = 'salt'; |
| 182 | + $this->setExtrasGlobal( 'Salt', 'salt' ); |
174 | 183 | $this->assertTrue( $this->fixture->compare_hash( '5a9ee1e4a15adbf03b3ef9f7baa6caffa9f6bcd72c736498f045c073e57753e7b244bc97fe82b075eabd80778a4d56eb14406e9a1ac4b13737b2c3fd8c3717e8', 'foo' ) ); |
175 | 184 | $this->assertFalse( $this->fixture->compare_hash( '5a9ee1e4a15adbf03b3ef9f7baa6caffa9f6bcd72c736498f045c073e57753e7b244bc97fe82b075eabd80778a4d56eb14406e9a1ac4b13737b2c3fd8c3717e8', 'bar' ) ); |
176 | 185 | } |
177 | 186 | |
178 | 187 | public function testBypassMinfraud() { |
179 | | - global $wgPayflowGatewaySalt; |
180 | | - $wgPayflowGatewaySalt = 'salt'; |
| 188 | + $this->setExtrasGlobal( 'Salt', 'salt' ); |
181 | 189 | $data = array( |
182 | 190 | 'action' => '4bd7857c851039d1e07a434800fe752c6bd99aec61c325aef460441be1b95c3ab5236e43c8d06f41d77715dbd3cf94e679b86422ec3204f00ad433501e5005e9', |
183 | 191 | 'data_hash' => '029ef6f5c2a165215b5a92ff1a194e4a6de8c668d6193582da42713f119c1b07d8358b5cd94a3bd51c9aa50709c8533295215ce3cce8c2b61e69078d789bc3f3', |
— | — | @@ -191,4 +199,5 @@ |
192 | 200 | $data[] = 'bar'; |
193 | 201 | $this->assertFalse( $this->fixture->can_bypass_minfraud( $this->fixture, $data ) ); |
194 | 202 | } |
| 203 | + |
195 | 204 | } |
Index: trunk/extensions/DonationInterface/extras/minfraud/minfraud.body.php |
— | — | @@ -1,6 +1,7 @@ |
2 | 2 | <?php |
3 | | -class PayflowProGateway_Extras_MinFraud extends PayflowProGateway_Extras { |
4 | 3 | |
| 4 | +class Gateway_Extras_MinFraud extends Gateway_Extras { |
| 5 | + |
5 | 6 | /** |
6 | 7 | * Full response from minFraud |
7 | 8 | * @var public array |
— | — | @@ -16,14 +17,14 @@ |
17 | 18 | /** |
18 | 19 | * User-definable riskScore ranges for actions to take |
19 | 20 | * |
20 | | - * Overload with $wgMinFraudActionRanges |
| 21 | + * Overload with $wgMinFraudActionRanges |
21 | 22 | * @var public array |
22 | 23 | */ |
23 | 24 | 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 ), |
28 | 29 | ); |
29 | 30 | |
30 | 31 | /** |
— | — | @@ -37,11 +38,10 @@ |
38 | 39 | */ |
39 | 40 | static $instance; |
40 | 41 | |
41 | | - function __construct( $license_key = NULL ) { |
42 | | - parent::__construct(); |
| 42 | + function __construct( &$gateway_adapter, $license_key = NULL ) { |
| 43 | + parent::__construct( $gateway_adapter ); |
43 | 44 | $dir = dirname( __FILE__ ) . '/'; |
44 | 45 | require_once( $dir . "ccfd/CreditCardFraudDetection.php" ); |
45 | | - require_once( $dir . "../../includes/countryCodes.inc" ); |
46 | 46 | global $wgMinFraudLicenseKey, $wgMinFraudActionRanges; |
47 | 47 | |
48 | 48 | // set the minfraud license key, go no further if we don't have it |
— | — | @@ -50,46 +50,48 @@ |
51 | 51 | } |
52 | 52 | $this->minfraud_license_key = ( $license_key ) ? $license_key : $wgMinFraudLicenseKey; |
53 | 53 | |
54 | | - if ( isset( $wgMinFraudActionRanges ) ) $this->action_ranges = $wgMinFraudActionRanges; |
| 54 | + if ( isset( $wgMinFraudActionRanges ) ) |
| 55 | + $this->action_ranges = $wgMinFraudActionRanges; |
55 | 56 | } |
56 | 57 | |
57 | 58 | /** |
58 | 59 | * Query minFraud with the transaction, set actions to take and make a log entry |
59 | 60 | * |
60 | | - * Accessible via $wgHooks[ 'PayflowGatewayValidate' ] |
61 | | - * @param object PayflowPro Gateway object |
| 61 | + * Accessible via $wgHooks[ 'GatewayValidate' ] |
| 62 | + * @param object Gateway object |
62 | 63 | * @param array The array of data generated from an attempted transaction |
63 | 64 | */ |
64 | | - public function validate( &$pfp_gateway_object, &$data ) { |
| 65 | + public function validate() { |
65 | 66 | // see if we can bypass minfraud |
66 | | - if ( $this->can_bypass_minfraud( $pfp_gateway_object, $data ) ) return TRUE; |
| 67 | + if ( $this->can_bypass_minfraud() ) |
| 68 | + return TRUE; |
67 | 69 | |
68 | | - $minfraud_query = $this->build_query( $data ); |
| 70 | + $minfraud_query = $this->build_query( $this->gateway_adapter->getData() ); |
69 | 71 | $this->query_minfraud( $minfraud_query ); |
70 | | - $pfp_gateway_object->action = $this->determine_action( $this->minfraud_response[ 'riskScore' ] ); |
| 72 | + $this->gateway_adapter->action = $this->determine_action( $this->minfraud_response['riskScore'] ); |
71 | 73 | |
72 | 74 | // 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 ) ); |
| 75 | + $this->gateway_adapter->unsetHash(); |
| 76 | + $this->gateway_adapter->setActionHash( $this->generate_hash( $this->gateway_adapter->action ) ); |
| 77 | + $this->gateway_adapter->setHash( $this->generate_hash( $this->gateway_adapter->getData() ) ); |
76 | 78 | |
77 | 79 | // Write the query/response to the log |
78 | | - $this->log_query( $minfraud_query, $pfp_gateway_object, $data ); |
| 80 | + $this->log_query( $minfraud_query ); |
79 | 81 | return TRUE; |
80 | 82 | } |
81 | 83 | |
82 | 84 | /** |
83 | 85 | * Logs a minFraud query and its response |
84 | 86 | */ |
85 | | - public function log_query( $minfraud_query, $pfp_gateway_object, $data ) { |
| 87 | + public function log_query( $minfraud_query ) { |
86 | 88 | if ( $this->log_fh ) { |
87 | | - $log_message = '"' . addslashes( $data[ 'comment' ] ) . '"'; |
88 | | - $log_message .= "\t" . '"' . addslashes( $data[ 'amount' ] . ' ' . $data[ 'currency' ] ) . '"'; |
| 89 | + $log_message = '"' . addslashes( $this->gateway_adapter->getData( 'comment' ) ) . '"'; |
| 90 | + $log_message .= "\t" . '"' . addslashes( $this->gateway_adapter->getData( 'amount' ) . ' ' . $this->gateway_adapter->getData( 'currency' ) ) . '"'; |
89 | 91 | $log_message .= "\t" . '"' . addslashes( json_encode( $minfraud_query ) ) . '"'; |
90 | 92 | $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 ); |
| 93 | + $log_message .= "\t" . '"' . addslashes( $this->gateway_adapter->action ) . '"'; |
| 94 | + $log_message .= "\t" . '"' . addslashes( $this->gateway_adapter->getData( 'referrer' ) ) . '"'; |
| 95 | + $this->log( $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'minFraud query', $log_message ); |
94 | 96 | } |
95 | 97 | } |
96 | 98 | |
— | — | @@ -102,40 +104,37 @@ |
103 | 105 | * assume the transaction has already gone through the minFraud check and can be passed |
104 | 106 | * on to the appropriate action. |
105 | 107 | * |
106 | | - * @param object $pfp_gateway_object The PayflowPro gateway object |
107 | | - * @param array $data The array of data from the form submission |
108 | 108 | * @return bool |
109 | 109 | */ |
110 | | - public function can_bypass_minfraud( &$pfp_gateway_object, &$data ) { |
| 110 | + public function can_bypass_minfraud() { |
111 | 111 | // 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' ] ) ) { |
| 112 | + $localdata = $this->gateway_adapter->getData(); |
| 113 | + if ( !strlen( $localdata['data_hash'] ) || !strlen( $localdata['action'] ) ) { |
113 | 114 | return FALSE; |
114 | 115 | } |
115 | 116 | |
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' ] ); |
| 117 | + $data_hash = $localdata['data_hash']; // the data hash passed in by the form submission |
| 118 | + // unset these values since they are not part of the overall data hash |
| 119 | + $this->gateway_adapter->unsetHash(); |
| 120 | + unset( $localdata['data_hash'] ); |
122 | 121 | // 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 |
| 122 | + if ( $this->compare_hash( $data_hash, serialize( $localdata ) ) ) { |
126 | 123 | |
| 124 | + $this->gateway_adapter->setHash( $this->generate_hash( $this->gateway_adapter->getData() ) ); // hash the data array |
127 | 125 | // check to see if we have a valid action set for us to bypass minfraud |
128 | 126 | $actions = array( 'process', 'challenge', 'review', 'reject' ); |
129 | | - $action_hash = $data[ 'action' ]; // a hash of the action to take passed in by the form submission |
| 127 | + $action_hash = $localdata['action']; // a hash of the action to take passed in by the form submission |
130 | 128 | foreach ( $actions as $action ) { |
131 | 129 | if ( $this->compare_hash( $action_hash, $action ) ) { |
132 | 130 | // set the action that should be taken |
133 | | - $pfp_gateway_object->action = $action; |
| 131 | + $this->gateway_adapter->action = $action; |
134 | 132 | return TRUE; |
135 | 133 | } |
136 | 134 | } |
137 | 135 | } else { |
138 | 136 | // log potential tampering |
139 | | - if ( $this->log_fh ) $this->log( $data[ 'contribution_tracking_id'], 'Data hash/action mismatch' ); |
| 137 | + if ( $this->log_fh ) |
| 138 | + $this->log( $localdata['contribution_tracking_id'], 'Data hash/action mismatch' ); |
140 | 139 | } |
141 | 140 | |
142 | 141 | return FALSE; |
— | — | @@ -147,7 +146,7 @@ |
148 | 147 | */ |
149 | 148 | public function get_ccfd() { |
150 | 149 | if ( !$this->ccfd ) { |
151 | | - $this->ccfd = new CreditCardFraudDetection; |
| 150 | + $this->ccfd = new CreditCardFraudDetection( $this->gateway_adapter ); |
152 | 151 | } |
153 | 152 | return $this->ccfd; |
154 | 153 | } |
— | — | @@ -157,8 +156,6 @@ |
158 | 157 | * @return array containing hash for minfraud query |
159 | 158 | */ |
160 | 159 | public function build_query( array $data ) { |
161 | | - global $wgPayflowGatewayTest; |
162 | | - |
163 | 160 | // mapping of data keys -> minfraud array keys |
164 | 161 | $map = array( |
165 | 162 | "city" => "city", |
— | — | @@ -172,20 +169,20 @@ |
173 | 170 | ); |
174 | 171 | |
175 | 172 | // minfraud license key |
176 | | - $minfraud_array[ "license_key" ] = $this->minfraud_license_key; |
| 173 | + $minfraud_array["license_key"] = $this->minfraud_license_key; |
177 | 174 | |
178 | 175 | // user's IP address |
179 | | - $minfraud_array[ "i" ] = ( $wgPayflowGatewayTest ) ? '12.12.12.12' : wfGetIP(); |
| 176 | + $minfraud_array["i"] = ( $this->gateway_adapter->getGlobal( "Test" ) ) ? '12.12.12.12' : wfGetIP(); |
180 | 177 | |
181 | 178 | // user's user agent |
182 | 179 | global $wgRequest; |
183 | | - $minfraud_array[ "user_agent" ] = $wgRequest->getHeader( 'user-agent' ); |
| 180 | + $minfraud_array["user_agent"] = $wgRequest->getHeader( 'user-agent' ); |
184 | 181 | |
185 | 182 | // user's language |
186 | | - $minfraud_array[ 'accept_language' ] = $wgRequest->getHeader( 'accept-language' ); |
| 183 | + $minfraud_array['accept_language'] = $wgRequest->getHeader( 'accept-language' ); |
187 | 184 | |
188 | 185 | // fetch the array of country codes |
189 | | - $country_codes = PayflowProGateway::getCountries(); |
| 186 | + $country_codes = GatewayForm::getCountries(); |
190 | 187 | |
191 | 188 | // loop through the map and add pertinent values from $data to the hash |
192 | 189 | foreach ( $map as $key => $value ) { |
— | — | @@ -193,19 +190,19 @@ |
194 | 191 | // do some data processing to clean up values for minfraud |
195 | 192 | switch ( $key ) { |
196 | 193 | case "domain": // get just the domain from the email address |
197 | | - $newdata[ $value ] = substr( strstr( $data[ $value ], '@' ), 1 ); |
| 194 | + $newdata[$value] = substr( strstr( $data[$value], '@' ), 1 ); |
198 | 195 | break; |
199 | 196 | case "bin": // get just the first 6 digits from CC# |
200 | | - $newdata[ $value ] = substr( $data[ $value ], 0, 6 ); |
| 197 | + $newdata[$value] = substr( $data[$value], 0, 6 ); |
201 | 198 | break; |
202 | 199 | case "country": |
203 | | - $newdata[ $value ] = $country_codes[ $data[ $value ]]; |
| 200 | + $newdata[$value] = $country_codes[$data[$value]]; |
204 | 201 | break; |
205 | 202 | default: |
206 | | - $newdata[ $value ] = $data[ $value ]; |
| 203 | + $newdata[$value] = $data[$value]; |
207 | 204 | } |
208 | 205 | |
209 | | - $minfraud_array[ $key ] = $newdata[ $value ]; |
| 206 | + $minfraud_array[$key] = $newdata[$value]; |
210 | 207 | } |
211 | 208 | |
212 | 209 | return $minfraud_array; |
— | — | @@ -229,7 +226,7 @@ |
230 | 227 | * there is a value for a required field and if its length is > 0 |
231 | 228 | * |
232 | 229 | * @param array $minfraud_query which is the array you would pass to |
233 | | - * minfraud in a query |
| 230 | + * minfraud in a query |
234 | 231 | * @result bool |
235 | 232 | */ |
236 | 233 | public function validate_minfraud_query( array $minfraud_query ) { |
— | — | @@ -244,8 +241,8 @@ |
245 | 242 | ); |
246 | 243 | |
247 | 244 | foreach ( $reqd_fields as $reqd_field ) { |
248 | | - if ( !isset( $minfraud_query[ $reqd_field ] ) || |
249 | | - strlen( $minfraud_query[ $reqd_field ] ) < 1 ) { |
| 245 | + if ( !isset( $minfraud_query[$reqd_field] ) || |
| 246 | + strlen( $minfraud_query[$reqd_field] ) < 1 ) { |
250 | 247 | return FALSE; |
251 | 248 | } |
252 | 249 | } |
— | — | @@ -261,7 +258,7 @@ |
262 | 259 | * @param float risk score (returned from minFraud) |
263 | 260 | * @return array of actions to be taken |
264 | 261 | */ |
265 | | - public function determine_action( $risk_score ) { |
| 262 | + public function determine_action( $risk_score ) { |
266 | 263 | foreach ( $this->action_ranges as $action => $range ) { |
267 | 264 | if ( $risk_score >= $range[0] && $risk_score <= $range[1] ) { |
268 | 265 | return $action; |
— | — | @@ -269,14 +266,16 @@ |
270 | 267 | } |
271 | 268 | } |
272 | 269 | |
273 | | - static function onValidate( &$pfp_gateway_object, &$data ) { |
274 | | - return self::singleton()->validate( $pfp_gateway_object, $data ); |
| 270 | + static function onValidate( &$gateway_adapter ) { |
| 271 | + $gateway_adapter->debugarray[] = "minfraud onValidate hook!"; |
| 272 | + return self::singleton( $gateway_adapter )->validate(); |
275 | 273 | } |
276 | 274 | |
277 | | - static function singleton() { |
| 275 | + static function singleton( &$gateway_adapter ) { |
278 | 276 | if ( !self::$instance ) { |
279 | | - self::$instance = new self; |
| 277 | + self::$instance = new self( $gateway_adapter ); |
280 | 278 | } |
281 | 279 | return self::$instance; |
282 | 280 | } |
| 281 | + |
283 | 282 | } |
Index: trunk/extensions/DonationInterface/extras/minfraud/minfraud.php |
— | — | @@ -1,74 +1,30 @@ |
2 | 2 | <?php |
| 3 | + |
3 | 4 | /** |
4 | 5 | * Validates a transaction against MaxMind's minFraud service |
5 | 6 | * |
6 | 7 | * For more details on minFraud, go: http://www.maxmind.com/app/minfraud |
7 | 8 | * |
8 | | - * To install: |
9 | | - * require_once( "$IP/extensions/DonationInterface/payflowpro_gateway/extras/minfraud/minfraud.php" ); |
10 | | - * |
| 9 | + * To install the DontaionInterface extension, put the following line in LocalSettings.php: |
| 10 | + * require_once( "\$IP/extensions/DonationInterface/donationinterface.php" ); |
| 11 | + * |
| 12 | + * TODO: Outline required globals to include this bad boy! |
| 13 | + * |
11 | 14 | */ |
12 | | - |
13 | 15 | if ( !defined( 'MEDIAWIKI' ) ) { |
14 | | - die( "This file is part of the MinFraud for PayflowPro Gateway extension. It is not a valid entry point.\n" ); |
| 16 | + die( "This file is part of the MinFraud for Gateway extension. It is not a valid entry point.\n" ); |
15 | 17 | } |
16 | 18 | |
17 | | -$wgExtensionCredits['payflowprogateway_extras_minfraud'][] = array( |
| 19 | +$wgExtensionCredits['gateway_extras_minfraud'][] = array( |
18 | 20 | 'name' => 'minfraud', |
19 | 21 | 'author' => 'Arthur Richards', |
20 | 22 | 'url' => '', |
21 | | - 'description' => 'This extension uses the MaxMind minFraud service as a validator for the Payflow Pro gateway.' |
| 23 | + 'description' => 'This extension uses the MaxMind minFraud service as a validator for the gateway.' |
22 | 24 | ); |
23 | 25 | |
24 | | -/** |
25 | | - * Your minFraud license key. |
26 | | - */ |
27 | | -$wgMinFraudLicenseKey = ''; |
28 | | - |
29 | | -/** |
30 | | - * Set the risk score ranges that will cause a particular 'action' |
31 | | - * |
32 | | - * The keys to the array are the 'actions' to be taken (eg 'process'). |
33 | | - * The value for one of these keys is an array representing the lower |
34 | | - * and upper bounds for that action. For instance, |
35 | | - * $wgMinFraudActionRagnes = array( |
36 | | - * 'process' => array( 0, 100) |
37 | | - * ... |
38 | | - * ); |
39 | | - * means that any transaction with a risk score greather than or equal |
40 | | - * to 0 and less than or equal to 100 will be given the 'process' action. |
41 | | - * |
42 | | - * These are evauluated on a >= or <= basis. Please refer to minFraud |
43 | | - * documentation for a thorough explanation of the 'riskScore'. |
44 | | - */ |
45 | | -$wgMinFraudActionRanges = array( |
46 | | - 'process' => array( 0, 100 ), |
47 | | - 'review' => array( -1, -1 ), |
48 | | - 'challenge' => array( -1, -1 ), |
49 | | - 'reject' => array( -1, -1 ) |
50 | | -); |
51 | | - |
52 | | -// Timeout in seconds for communicating with MaxMind |
53 | | -$wgMinFraudTimeout = 2; |
54 | | - |
55 | | -/** |
56 | | - * Define whether or not to run minFraud in stand alone mode |
57 | | - * |
58 | | - * If this is set to run in standalone, these scripts will be |
59 | | - * accessed directly via the "PayflowGatewayValidate" hook. |
60 | | - * You may not want to run this in standalone mode if you prefer |
61 | | - * to use this in conjunction with Custom Filters. This has the |
62 | | - * advantage of sharing minFraud info with other filters. |
63 | | - */ |
64 | | -$wgMinFraudStandalone = TRUE; |
65 | | - |
66 | | -$dir = dirname( __FILE__ ) . "/"; |
67 | | -$wgAutoloadClasses['PayflowProGateway_Extras_MinFraud'] = $dir . "minfraud.body.php"; |
68 | | - |
69 | | -$wgExtensionFunctions[] = 'efMinFraudSetup'; |
70 | | - |
71 | 26 | function efMinFraudSetup() { |
72 | | - // if we're in standalone mode, use the PayflowGatewayValidate hook |
| 27 | + // if we're in standalone mode, use the GatewayValidate hook |
73 | 28 | global $wgMinFraudStandalone, $wgHooks; |
74 | | - if ( $wgMinFraudStandalone ) $wgHooks["PayflowGatewayValidate"][] = array( 'PayflowProGateway_Extras_MinFraud::onValidate' ); |
| 29 | + if ( $wgMinFraudStandalone ) |
| 30 | + $wgHooks["GatewayValidate"][] = array( 'Gateway_Extras_MinFraud::onValidate' ); |
75 | 31 | } |
Index: trunk/extensions/DonationInterface/extras/conversion_log/conversion_log.php |
— | — | @@ -1,26 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * Extra to log payflow response during post processing hook |
5 | | - * |
6 | | - * @fixme Class/file names should likely change to reflect change in purpose... |
7 | | - * |
8 | | - * To install: |
9 | | - * require_once( "$IP/extensions/DonationInterface/payflowpro_gateway/extras/conversion_log/conversion_log.php" |
10 | | - */ |
11 | | - |
12 | | -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" ); |
14 | | -} |
15 | | - |
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'" |
21 | | -); |
22 | | - |
23 | | -$dir = dirname( __FILE__ ) . "/"; |
24 | | -$wgAutoloadClasses['PayflowProGateway_Extras_ConversionLog'] = $dir . "conversion_log.body.php"; |
25 | | - |
26 | | -// Sets the 'conversion log' as logger for post-processing |
27 | | -$wgHooks["PayflowGatewayPostProcess"][] = array( "PayflowProGateway_Extras_ConversionLog::onPostProcess" ); |
Index: trunk/extensions/DonationInterface/extras/conversion_log/conversion_log.body.php |
— | — | @@ -1,39 +1,41 @@ |
2 | 2 | <?php |
3 | | -class PayflowProGateway_Extras_ConversionLog extends PayflowProGateway_Extras { |
| 3 | + |
| 4 | +class Gateway_Extras_ConversionLog extends Gateway_Extras { |
| 5 | + |
4 | 6 | static $instance; |
5 | 7 | |
6 | 8 | /** |
7 | | - * Logs the response from a payflow transaction |
| 9 | + * Logs the response from a transaction |
8 | 10 | */ |
9 | | - public function post_process( &$pfp_gateway_object, &$data ) { |
| 11 | + public function post_process() { |
10 | 12 | // if the trxn has been outright rejected, log it |
11 | | - if ( $pfp_gateway_object->action == 'reject' ) { |
| 13 | + if ( $this->gateway_adapter->action == 'reject' ) { |
12 | 14 | $this->log( |
13 | | - $data[ 'contribution_tracking_id' ], |
14 | | - 'Rejected' |
| 15 | + $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'Rejected' |
15 | 16 | ); |
16 | 17 | return TRUE; |
17 | 18 | } |
18 | 19 | |
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; |
21 | 23 | |
22 | 24 | $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() ) ) . '"' |
26 | 26 | ); |
27 | 27 | return TRUE; |
28 | 28 | } |
29 | 29 | |
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 | + $gateway_adapter->debugarray[] = 'conversion log onPostProcess hook!'; |
| 32 | + return self::singleton( $gateway_adapter )->post_process(); |
32 | 33 | } |
33 | 34 | |
34 | | - static function singleton() { |
| 35 | + static function singleton( &$gateway_adapter ) { |
35 | 36 | if ( !self::$instance ) { |
36 | | - self::$instance = new self; |
| 37 | + self::$instance = new self( $gateway_adapter ); |
37 | 38 | } |
38 | 39 | return self::$instance; |
39 | 40 | } |
| 41 | + |
40 | 42 | } |
Index: trunk/extensions/DonationInterface/extras/extras.body.php |
— | — | @@ -1,19 +1,24 @@ |
2 | 2 | <?php |
| 3 | + |
3 | 4 | /** |
4 | | - * An abstract class for payflowpro gateway 'extras' |
| 5 | + * An abstract class for gateway 'extras' |
5 | 6 | */ |
| 7 | +abstract class Gateway_Extras { |
6 | 8 | |
7 | | -abstract class PayflowProGateway_Extras { |
8 | 9 | /** |
9 | 10 | * File handle for log file |
10 | 11 | * @var public |
11 | 12 | */ |
12 | 13 | public $log_fh = NULL; |
| 14 | + public $gateway_adapter; |
13 | 15 | |
14 | | - public function __construct() { |
15 | | - global $wgPayflowGatewayLog; |
| 16 | + public function __construct( &$gateway_adapter ) { |
| 17 | + $this->gateway_adapter = &$gateway_adapter; |
| 18 | + |
| 19 | + $extrasLog = $this->gateway_adapter->getGlobal( 'ExtrasLog' ); |
16 | 20 | // 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 ); |
18 | 23 | } |
19 | 24 | |
20 | 25 | /** |
— | — | @@ -25,19 +30,16 @@ |
26 | 31 | * @param string path to log file |
27 | 32 | */ |
28 | 33 | protected function prepare_log_file( $log_file ) { |
29 | | - |
| 34 | + |
30 | 35 | if ( strtolower( $log_file ) == "syslog" ) { |
31 | 36 | |
32 | | - $this->log_fh = 'syslog'; |
33 | | - |
34 | | - } elseif( is_file( $log_file )) { |
35 | | - |
| 37 | + $this->log_fh = 'syslog'; |
| 38 | + } elseif ( is_file( $log_file ) ) { |
| 39 | + |
36 | 40 | $this->log_fh = fopen( $log_file, 'a+' ); |
37 | | - |
38 | 41 | } else { |
39 | 42 | |
40 | 43 | $this->log_fh = null; |
41 | | - |
42 | 44 | } |
43 | 45 | } |
44 | 46 | |
— | — | @@ -54,26 +56,20 @@ |
55 | 57 | echo "what log file?"; |
56 | 58 | return; |
57 | 59 | } |
58 | | - |
| 60 | + |
59 | 61 | // format the message |
60 | 62 | $msg = '"' . date( 'c' ) . '"'; |
61 | 63 | $msg .= "\t" . '"' . $id . '"'; |
62 | 64 | $msg .= "\t" . '"' . $status . '"'; |
63 | 65 | $msg .= "\t" . $data . "\n"; |
64 | | - |
| 66 | + |
65 | 67 | // write to the log |
66 | 68 | if ( $this->log_fh == 'syslog' ) { //use syslog facility |
67 | 69 | // replace tabs with spaces - maybe do this universally? cuz who needs tabs. |
68 | 70 | $msg = str_replace( "\t", " ", $msg ); |
69 | | - |
70 | | - openlog( "payflowpro_gateway_trxn", LOG_ODELAY, LOG_SYSLOG ); |
71 | | - syslog( $log_level, $msg ); |
72 | | - closelog(); |
73 | | - |
| 71 | + $this->gateway_adapter->log( $msg, $log_level, '_trxn' ); |
74 | 72 | } else { //write to file |
75 | | - |
76 | 73 | fwrite( $this->log_fh, $msg ); |
77 | | - |
78 | 74 | } |
79 | 75 | } |
80 | 76 | |
— | — | @@ -83,8 +79,8 @@ |
84 | 80 | * @return string The hash of the data |
85 | 81 | */ |
86 | 82 | public function generate_hash( $data ) { |
87 | | - global $wgPayflowGatewaySalt; |
88 | | - return hash( "sha512", $wgPayflowGatewaySalt . $data ); |
| 83 | + $salt = $this->gateway_adapter->getGlobal( 'Salt' ); |
| 84 | + return hash( "sha512", $salt . $data ); |
89 | 85 | } |
90 | 86 | |
91 | 87 | /** |
— | — | @@ -105,6 +101,8 @@ |
106 | 102 | * Close the open log file handler if it's open |
107 | 103 | */ |
108 | 104 | public function __destruct() { |
109 | | - if ( is_resource( $this->log_fh ) ) fclose( $this->log_fh ); |
| 105 | + if ( is_resource( $this->log_fh ) ) |
| 106 | + fclose( $this->log_fh ); |
110 | 107 | } |
| 108 | + |
111 | 109 | } |
Index: trunk/extensions/DonationInterface/extras/recaptcha/recaptcha.php |
— | — | @@ -1,55 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * Extra to expose a recaptcha for 'challenged' transactions |
5 | | - * |
6 | | - * To install: |
7 | | - * require_once( "$IP/extensions/DonationInterface/payflowpro_gateway/extras/recaptcha/recaptcha.php" |
8 | | - */ |
9 | | - |
10 | | -if ( !defined( 'MEDIAWIKI' ) ) { |
11 | | - die( "This file is part of the ReCaptcha for PayflowPro Gateway extension. It is not a valid entry point.\n" ); |
12 | | -} |
13 | | - |
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" |
19 | | -); |
20 | | - |
21 | | -/** |
22 | | - * Public and Private reCaptcha keys |
23 | | - * |
24 | | - * These can be obtained at: |
25 | | - * http://www.google.com/recaptcha/whyrecaptcha |
26 | | - */ |
27 | | -$wgPayflowRecaptchaPublicKey = ''; |
28 | | -$wgPayflowRecaptchaPrivateKey = ''; |
29 | | - |
30 | | -// Timeout (in seconds) for communicating with reCatpcha |
31 | | -$wgPayflowRecaptchaTimeout = 2; |
32 | | - |
33 | | -/** |
34 | | - * HTTP Proxy settings |
35 | | - * |
36 | | - * Default to settings in PayflowPro Gateway |
37 | | - */ |
38 | | -$wgPayflowRecaptchaUseHTTPProxy = $wgPayflowGatewayUseHTTPProxy; |
39 | | -$wgPayflowRecaptchaHTTPProxy = $wgPayflowGatewayHTTPProxy; |
40 | | - |
41 | | -/** |
42 | | - * Use SSL to communicate with reCaptcha |
43 | | - */ |
44 | | -$wgPayflowRecaptchaUseSSL = 1; |
45 | | - |
46 | | -/** |
47 | | - * The # of times to retry communicating with reCaptcha if communication fails |
48 | | - * @var int |
49 | | - */ |
50 | | -$wgPayflowRecaptchaComsRetryLimit = 3; |
51 | | - |
52 | | -$dir = dirname( __FILE__ ) . "/"; |
53 | | -$wgAutoloadClasses['PayflowProGateway_Extras_ReCaptcha'] = $dir . "recaptcha.body.php"; |
54 | | - |
55 | | -// Set reCpatcha as plugin for 'challenge' action |
56 | | -$wgHooks["PayflowGatewayChallenge"][] = array( "PayflowProGateway_Extras_ReCaptcha::onChallenge" ); |
Index: trunk/extensions/DonationInterface/extras/recaptcha/recaptcha-php/recaptchalib.php |
— | — | @@ -42,8 +42,7 @@ |
43 | 43 | */ |
44 | 44 | |
45 | 45 | // global MW variables that should be available |
46 | | -global $wgPayflowRecaptchaUseHTTPProxy, $wgPayflowRecaptchaHTTPProxy, |
47 | | - $wgPayflowRecaptchaTimeout, $wgPayflowRecaptchaUseSSL, $wgPayflowRecaptchaComsRetryLimit; |
| 46 | +global $wgReCaptchaConfData; |
48 | 47 | |
49 | 48 | /** |
50 | 49 | * The reCAPTCHA server URL's |
— | — | @@ -55,16 +54,18 @@ |
56 | 55 | /** |
57 | 56 | * Proxy settings |
58 | 57 | */ |
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'] ); |
61 | 60 | |
62 | 61 | /** |
63 | 62 | * Other reCAPTCHA settings |
64 | 63 | */ |
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'] ); |
68 | 67 | |
| 68 | +define( "RECAPTCHA_GATEWAY", $wgReCaptchaConfData['GatewayClass'] ); |
| 69 | + |
69 | 70 | /** |
70 | 71 | * Encodes the given data into a query string format |
71 | 72 | * @param $data - array of string elements to be encoded |
— | — | @@ -125,7 +126,8 @@ |
126 | 127 | |
127 | 128 | $response = ''; |
128 | 129 | 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.' ); |
130 | 132 | die ( 'Could not open socket' ); |
131 | 133 | } |
132 | 134 | |
— | — | @@ -158,20 +160,22 @@ |
159 | 161 | curl_setopt( $ch, CURLOPT_HEADER, true ); |
160 | 162 | curl_setopt( $ch, CURLOPT_HTTPHEADER, array( "Host: " . $host ) ); |
161 | 163 | |
| 164 | + $c = RECAPTCHA_GATEWAY; |
| 165 | + |
162 | 166 | // set proxy settings if necessary |
163 | 167 | if ( RECAPTCHA_USE_HTTP_PROXY ) { |
164 | | - PayflowProGateway::log( 'Using http proxy ' . RECAPTCHA_HTTP_PROXY ); |
| 168 | + $c::log( 'Using http proxy ' . RECAPTCHA_HTTP_PROXY ); |
165 | 169 | curl_setopt( $ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP ); |
166 | 170 | curl_setopt( $ch, CURLOPT_PROXY, RECAPTCHA_HTTP_PROXY ); |
167 | 171 | } |
168 | 172 | |
169 | 173 | // try up to three times |
170 | 174 | 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 . '.' ); |
172 | 176 | $response = curl_exec( $ch ); |
173 | | - PayflowProGateway::log( "Finished communicating with reCaptcha." ); |
| 177 | + $c::log( "Finished communicating with reCaptcha." ); |
174 | 178 | if ( $response ) { |
175 | | - PayflowProGateway::log( 'Response from reCaptcha: ' . $response ); |
| 179 | + $c::log( 'Response from reCaptcha: ' . $response ); |
176 | 180 | break; |
177 | 181 | } |
178 | 182 | } |
— | — | @@ -186,7 +190,7 @@ |
187 | 191 | * the user entered the correct values. |
188 | 192 | */ |
189 | 193 | if ( !$response ) { |
190 | | - PayflowProGateway::log( 'Failed communicating with reCaptcha: ' . curl_error( $ch ) ); |
| 194 | + $c::log( 'Failed communicating with reCaptcha: ' . curl_error( $ch ) ); |
191 | 195 | $response = "true\r\n\r\nsuccess"; |
192 | 196 | } |
193 | 197 | |
Index: trunk/extensions/DonationInterface/extras/recaptcha/recaptcha.body.php |
— | — | @@ -1,10 +1,10 @@ |
2 | 2 | <?php |
| 3 | + |
3 | 4 | /** |
4 | 5 | * Validates a transaction against MaxMind's minFraud service |
5 | 6 | */ |
| 7 | +class Gateway_Extras_reCaptcha extends Gateway_Extras { |
6 | 8 | |
7 | | -class PayflowProGateway_Extras_reCaptcha extends PayflowProGateway_Extras { |
8 | | - |
9 | 9 | /** |
10 | 10 | * Container for singelton instance of self |
11 | 11 | */ |
— | — | @@ -16,9 +16,18 @@ |
17 | 17 | */ |
18 | 18 | public $recap_err; |
19 | 19 | |
20 | | - public function __construct() { |
21 | | - parent::__construct(); |
| 20 | + public function __construct( &$gateway_adapter ) { |
| 21 | + parent::__construct( $gateway_adapter ); |
22 | 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->gateway_adapter->getGlobal( 'RecaptchaUseHTTPProxy' ); |
| 27 | + $wgReCaptchaConfData['HTTPProxy'] = $this->gateway_adapter->getGlobal( 'RecaptchaHTTPProxy' ); |
| 28 | + $wgReCaptchaConfData['Timeout'] = $this->gateway_adapter->getGlobal( 'RecaptchaTimeout' ); |
| 29 | + $wgReCaptchaConfData['UseSSL'] = $this->gateway_adapter->getGlobal( 'RecaptchaUseSSL' ); |
| 30 | + $wgReCaptchaConfData['ComsRetryLimit'] = $this->gateway_adapter->getGlobal( 'RecaptchaComsRetryLimit' ); |
| 31 | + $wgReCaptchaConfData['GatewayClass'] = $this->gateway_adapter->getGatewayAdapterClass(); //for properly routing the logging |
23 | 32 | // load the reCaptcha API |
24 | 33 | require_once( dirname( __FILE__ ) . '/recaptcha-php/recaptchalib.php' ); |
25 | 34 | } |
— | — | @@ -26,45 +35,53 @@ |
27 | 36 | /** |
28 | 37 | * Handle the challenge logic |
29 | 38 | */ |
30 | | - public function challenge( &$pfp_gateway_object, &$data ) { |
| 39 | + public function challenge() { |
31 | 40 | // if captcha posted, validate |
32 | | - if ( isset( $_POST[ 'recaptcha_response_field' ] ) ) { |
| 41 | + if ( isset( $_POST['recaptcha_response_field'] ) ) { |
33 | 42 | // check the captcha response |
34 | 43 | $captcha_resp = $this->check_captcha(); |
35 | 44 | if ( $captcha_resp->is_valid ) { |
36 | 45 | // if validated, update the action and move on |
37 | | - $this->log( $data[ 'contribution_tracking_id' ], 'Captcha passed' ); |
38 | | - $pfp_gateway_object->action = "process"; |
| 46 | + $this->log( $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'Captcha passed' ); |
| 47 | + $this->gateway_adapter->action = "process"; |
39 | 48 | return TRUE; |
40 | 49 | } else { |
41 | 50 | $this->recap_err = $captcha_resp->error; |
42 | | - $this->log( $data[ 'contribution_tracking_id' ], 'Captcha failed' ); |
| 51 | + $this->log( $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'Captcha failed' ); |
43 | 52 | } |
44 | 53 | } |
45 | 54 | // display captcha |
46 | | - $this->display_captcha( $pfp_gateway_object, $data ); |
| 55 | + $this->display_captcha(); |
47 | 56 | return TRUE; |
48 | 57 | } |
49 | 58 | |
50 | 59 | /** |
51 | 60 | * Display the submission form with the captcha injected into it |
52 | 61 | */ |
53 | | - public function display_captcha( &$pfp_gateway_object, &$data ) { |
54 | | - global $wgOut, $wgPayflowRecaptchaPublicKey, $wgPayflowRecaptchaUseSSL; |
| 62 | + public function display_captcha() { |
| 63 | + global $wgOut; |
| 64 | + $publicKey = $this->gateway_adapter->getGlobal( 'RecaptchaPublicKey' ); |
| 65 | + $useSSL = $this->gateway_adapter->getGlobal( 'RecaptchaUseSSL' ); |
55 | 66 | |
56 | 67 | // log that a captcha's been triggered |
57 | | - $this->log( $data[ 'contribution_tracking_id' ], 'Captcha triggered' ); |
| 68 | + $this->log( $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'Captcha triggered' ); |
58 | 69 | |
59 | 70 | // construct the HTML used to display the captcha |
60 | 71 | $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>'; |
| 72 | + $captcha_html .= recaptcha_get_html( $publicKey, $this->recap_err, $useSSL ); |
| 73 | + $captcha_html .= '<span class="creditcard-error-msg">' . wfMsg( $this->gateway_adapter->getIdentifier() . '_gateway-error-msg-captcha-please' ) . '</span>'; |
63 | 74 | $captcha_html .= Xml::closeElement( 'div' ); // close div#mw-donate-captcha |
64 | | - |
65 | 75 | // load up the form class |
66 | | - $form_class = $pfp_gateway_object->getFormClass(); |
67 | | - $form_obj = new $form_class( $data, $pfp_gateway_object->errors ); |
| 76 | + $form_class = $this->gateway_adapter->getFormClass(); |
68 | 77 | |
| 78 | + //hmm. Looking at this now, makes me want to say |
| 79 | + //TODO: Refactor the Form Class constructors. Again. Because the next three lines of code anger me deeply. |
| 80 | + //#1 - all three things are clearly in the gateway adapter, and we're passing that already. |
| 81 | + //#2 - I have to stuff them in variables because Form wants parameters by reference. |
| 82 | + $data = $this->gateway_adapter->getData(); |
| 83 | + $erros = $this->gateway_adapter->getValidationErrors(); |
| 84 | + $form_obj = new $form_class( $data, $errors, $this->gateway_adapter ); |
| 85 | + |
69 | 86 | // set the captcha HTML to use in the form |
70 | 87 | $form_obj->setCaptchaHTML( $captcha_html ); |
71 | 88 | |
— | — | @@ -76,23 +93,23 @@ |
77 | 94 | * Check recaptcha answer |
78 | 95 | */ |
79 | 96 | public function check_captcha() { |
80 | | - global $wgPayflowRecaptchaPrivateKey, $wgRequest; |
81 | | - $resp = recaptcha_check_answer( $wgPayflowRecaptchaPrivateKey, |
82 | | - wfGetIP(), |
83 | | - $wgRequest->getText( 'recaptcha_challenge_field' ), |
84 | | - $wgRequest->getText( 'recaptcha_response_field' ) ); |
| 97 | + global $wgRequest; |
| 98 | + $privateKey = $this->gateway_adapter->getGlobal( 'RecaptchaPrivateKey' ); |
| 99 | + $resp = recaptcha_check_answer( $privateKey, wfGetIP(), $wgRequest->getText( 'recaptcha_challenge_field' ), $wgRequest->getText( 'recaptcha_response_field' ) ); |
85 | 100 | |
86 | 101 | return $resp; |
87 | 102 | } |
88 | 103 | |
89 | | - static function onChallenge( &$pfp_gateway_object, &$data ) { |
90 | | - return self::singleton()->challenge( $pfp_gateway_object, $data ); |
| 104 | + static function onChallenge( &$gateway_adapter ) { |
| 105 | + $gateway_adapter->debugarray[] = 'recaptcha onChallenge hook!'; |
| 106 | + return self::singleton( $gateway_adapter )->challenge(); |
91 | 107 | } |
92 | 108 | |
93 | | - static function singleton() { |
| 109 | + static function singleton( &$gateway_adapter ) { |
94 | 110 | if ( !self::$instance ) { |
95 | | - self::$instance = new self; |
| 111 | + self::$instance = new self( $gateway_adapter ); |
96 | 112 | } |
97 | 113 | return self::$instance; |
98 | 114 | } |
| 115 | + |
99 | 116 | } |
Property changes on: trunk/extensions/DonationInterface/extras |
___________________________________________________________________ |
Added: svn:mergeinfo |
100 | 117 | Merged /branches/fundraising/extensions/DonationInterface/extras:r98263-100243 |
Index: trunk/extensions/DonationInterface/gateway_forms/TwoStepTwoColumn.php |
— | — | @@ -7,6 +7,7 @@ |
8 | 8 | |
9 | 9 | parent::__construct( $form_data, $form_errors, $gateway ); |
10 | 10 | // load validation and placeholder JS |
| 11 | + $this->loadValidateJs(); |
11 | 12 | $this->loadPlaceholders(); |
12 | 13 | } |
13 | 14 | |
Index: trunk/extensions/DonationInterface/gateway_forms/RapidHtml.php |
— | — | @@ -83,6 +83,8 @@ |
84 | 84 | global $wgRequest; |
85 | 85 | parent::__construct( $form_data, $form_errors, $gateway ); |
86 | 86 | |
| 87 | + $this->loadValidateJs(); |
| 88 | + |
87 | 89 | $country = $wgRequest->getText( 'country', '' ); |
88 | 90 | |
89 | 91 | if ( $country != '' ){ |