Index: branches/fundraising/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php |
— | — | @@ -22,7 +22,7 @@ |
23 | 23 | $wgOut->addExtensionStyle( |
24 | 24 | $wgExtensionAssetsPath . '/DonationInterface/gateway_forms/css/gateway.css?284' . |
25 | 25 | $CSSVersion ); |
26 | | - |
| 26 | + |
27 | 27 | // Hide unneeded interface elements |
28 | 28 | $wgOut->addModules( 'donationInterface.skinOverride' ); |
29 | 29 | |
— | — | @@ -63,8 +63,6 @@ |
64 | 64 | // The form was submitted and the payment method has been set |
65 | 65 | $this->adapter->log( "Form posted and payment method set." ); |
66 | 66 | |
67 | | - // increase the count of attempts |
68 | | - //++$data['numAttempt']; |
69 | 67 | // Check form for errors |
70 | 68 | $form_errors = $this->fnValidateForm( $data, $this->errors ); |
71 | 69 | |
— | — | @@ -74,25 +72,25 @@ |
75 | 73 | } else { // The submitted form data is valid, so process it |
76 | 74 | // allow any external validators to have their way with the data |
77 | 75 | self::log( $data['order_id'] . " Preparing to query MaxMind" ); |
78 | | - wfRunHooks( 'PayflowGatewayValidate', array( &$this, &$data ) ); |
| 76 | + wfRunHooks( 'GatewayValidate', array( &$this->adapter ) ); |
79 | 77 | self::log( $data['order_id'] . ' Finished querying Maxmind' ); |
80 | 78 | |
81 | 79 | // if the transaction was flagged for review |
82 | 80 | if ( $this->action == 'review' ) { |
83 | 81 | // expose a hook for external handling of trxns flagged for review |
84 | | - wfRunHooks( 'PayflowGatewayReview', array( &$this, &$data ) ); |
| 82 | + wfRunHooks( 'GatewayReview', array( &$this->adapter ) ); |
85 | 83 | } |
86 | 84 | |
87 | 85 | // if the transaction was flagged to be 'challenged' |
88 | 86 | if ( $this->action == 'challenge' ) { |
89 | 87 | // expose a hook for external handling of trxns flagged for challenge (eg captcha) |
90 | | - wfRunHooks( 'PayflowGatewayChallenge', array( &$this, &$data ) ); |
| 88 | + wfRunHooks( 'GatewayChallenge', array( &$this->adapter ) ); |
91 | 89 | } |
92 | 90 | |
93 | 91 | // if the transaction was flagged for rejection |
94 | 92 | if ( $this->action == 'reject' ) { |
95 | 93 | // expose a hook for external handling of trxns flagged for rejection |
96 | | - wfRunHooks( 'PayflowGatewayReject', array( &$this, &$data ) ); |
| 94 | + wfRunHooks( 'GatewayReject', array( &$this->adapter ) ); |
97 | 95 | |
98 | 96 | $this->fnPayflowDisplayDeclinedResults( '' ); |
99 | 97 | $this->fnPayflowUnsetEditToken(); |
— | — | @@ -101,12 +99,12 @@ |
102 | 100 | // if the transaction was flagged for processing |
103 | 101 | if ( $this->action == 'process' ) { |
104 | 102 | // expose a hook for external handling of trxns ready for processing |
105 | | - wfRunHooks( 'PayflowGatewayProcess', array( &$this, &$data ) ); |
| 103 | + wfRunHooks( 'GatewayProcess', array( &$this->adapter ) ); |
106 | 104 | $this->fnPayflowProcessTransaction( $data, $payflow_data ); |
107 | 105 | } |
108 | 106 | |
109 | 107 | // expose a hook for any post processing |
110 | | - wfRunHooks( 'PayflowGatewayPostProcess', array( &$this, &$data ) ); |
| 108 | + wfRunHooks( 'GatewayPostProcess', array( &$this->adapter ) ); |
111 | 109 | } |
112 | 110 | } else { |
113 | 111 | // Display form for the first time |
— | — | @@ -380,7 +378,7 @@ |
381 | 379 | $wgOut->addHTML( '<h3 class="response_message">' . $responseMsg . '</h3>' ); |
382 | 380 | |
383 | 381 | // translate country code into text |
384 | | - $countries = $this->getCountries(); |
| 382 | + $countries = GatewayForm::getCountries(); |
385 | 383 | |
386 | 384 | $rows = array( |
387 | 385 | 'title' => array( wfMsg( 'payflowpro_gateway-post-transaction' ) ), |
Index: branches/fundraising/extensions/DonationInterface/payflowpro_gateway/payflowpro.adapter.php |
— | — | @@ -104,7 +104,7 @@ |
105 | 105 | $responseArray[$key] = $value; |
106 | 106 | } |
107 | 107 | |
108 | | - self::log( "Here is the response as an array: " . print_r( $responseArray, true ) ); //I am apparently a huge fibber. |
| 108 | + self::log( "Here is the response as an array: " . print_r( $responseArray, true ) ); |
109 | 109 | return $responseArray; |
110 | 110 | } |
111 | 111 | |
— | — | @@ -121,8 +121,11 @@ |
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
125 | | - * Parse the response to get the errors in a format we can log and otherwise deal with. |
126 | | - * return a key/value array of codes (if they exist) and messages. |
| 125 | + * Interpret response code, return |
| 126 | + * 1 if approved |
| 127 | + * 2 if declined |
| 128 | + * 3 if invalid data was submitted by user |
| 129 | + * 4 all other errors |
127 | 130 | */ |
128 | 131 | function getResponseErrors( $response ) { |
129 | 132 | |
— | — | @@ -188,7 +191,8 @@ |
189 | 192 | * Process the entire response gott'd by the last four functions. |
190 | 193 | */ |
191 | 194 | function processResponse( $response ) { |
192 | | - |
| 195 | + //set the transaction result message |
| 196 | + $this->setTransactionResult( $response['RESPMSG'], 'txn_message' ); |
193 | 197 | } |
194 | 198 | |
195 | 199 | function defineStagedVars() { |
Index: branches/fundraising/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->getGlobal( 'CustomFiltersActionRanges' ); |
| 31 | + $this->risk_score = $this->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,23 @@ |
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 | + return self::singleton( &$gateway_adapter )->validate(); |
85 | 68 | } |
86 | 69 | |
87 | | - static function singleton( &$pfp_gateway_object, &$data ) { |
| 70 | + static function singleton( &$gateway_adapter ) { |
88 | 71 | if ( !self::$instance ) { |
89 | | - self::$instance = new self( $pfp_gateway_object, $data ); |
| 72 | + self::$instance = new self( &$gateway_adapter ); |
90 | 73 | } |
91 | 74 | return self::$instance; |
92 | 75 | } |
| 76 | + |
93 | 77 | } |
Index: branches/fundraising/extensions/DonationInterface/extras/custom_filters/custom_filters.php |
— | — | @@ -1,4 +1,5 @@ |
2 | 2 | <?php |
| 3 | + |
3 | 4 | /** |
4 | 5 | * Provides a unified way to define and run custom filters for incoming transactions |
5 | 6 | * |
— | — | @@ -7,30 +8,29 @@ |
8 | 9 | * needed to perform more complex validation/filtering of transactions. |
9 | 10 | * |
10 | 11 | * The actual filters themselves are regular MW extensions and can optional be organized in filters/ |
11 | | - * They should be invoked by using the 'PayflowGatewayCustomFilter' hook, which will pass the entire |
| 12 | + * They should be invoked by using the 'GatewayCustomFilter' hook, which will pass the entire |
12 | 13 | * CustomFilter object to the filter. The gateway object and its data are included in the CustomFilter |
13 | 14 | * object. |
14 | 15 | */ |
15 | | - |
16 | 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" ); |
| 17 | + die( "This file is part of the MinFraud for Gateway extension. It is not a valid entry point.\n" ); |
18 | 18 | } |
19 | 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.' |
| 20 | +$wgExtensionCredits['gateway_custom_filters'][] = array( |
| 21 | + 'name' => 'custom filters', |
| 22 | + 'author' => 'Arthur Richards', |
| 23 | + 'url' => '', |
| 24 | + 'description' => 'This extension provides a way to define custom filters for incoming transactions for the gateway.' |
25 | 25 | ); |
26 | 26 | |
27 | 27 | /** |
28 | 28 | * Define the action to take for a given $risk_score |
29 | 29 | */ |
30 | | -$wgPayflowGatewayCustomFiltersActionRanges = array( |
31 | | - 'process' => array( 0, 100 ), |
32 | | - 'review' => array( -1, -1 ), |
| 30 | +$wgDonationInterfaceCustomFiltersActionRanges = array( |
| 31 | + 'process' => array( 0, 100 ), |
| 32 | + 'review' => array( -1, -1 ), |
33 | 33 | 'challenge' => array( -1, -1 ), |
34 | | - 'reject' => array( -1, -1 ), |
| 34 | + 'reject' => array( -1, -1 ), |
35 | 35 | ); |
36 | 36 | |
37 | 37 | /** |
— | — | @@ -40,9 +40,9 @@ |
41 | 41 | * $action_ranges. This is built assuming a range of possible risk scores |
42 | 42 | * as 0-100, although you can probably bend this as needed. |
43 | 43 | */ |
44 | | -$wgPayflowGatewayCustomFiltersRiskScore = 0; |
| 44 | +$wgDonationInterfaceCustomFiltersRiskScore = 0; |
45 | 45 | |
46 | 46 | $dir = dirname( __FILE__ ) . "/"; |
47 | | -$wgAutoloadClasses['PayflowProGateway_Extras_CustomFilters'] = $dir . "custom_filters.body.php"; |
| 47 | +$wgAutoloadClasses['Gateway_Extras_CustomFilters'] = $dir . "custom_filters.body.php"; |
48 | 48 | |
49 | | -$wgHooks["PayflowGatewayValidate"][] = array( 'PayflowProGateway_Extras_CustomFilters::onValidate' ); |
| 49 | +$wgHooks["GatewayValidate"][] = array( 'Gateway_Extras_CustomFilters::onValidate' ); |
Index: branches/fundraising/extensions/DonationInterface/extras/custom_filters/filters/source/source.body.php |
— | — | @@ -1,6 +1,7 @@ |
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 | } |
— | — | @@ -57,4 +56,5 @@ |
58 | 57 | } |
59 | 58 | return self::$instance; |
60 | 59 | } |
| 60 | + |
61 | 61 | } |
Index: branches/fundraising/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 | 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: branches/fundraising/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,34 @@ |
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 | + return self::singleton( &$gateway_adapter )->filter( $custom_filter_object ); |
36 | 34 | } |
37 | 35 | |
38 | | - static function singleton() { |
| 36 | + static function singleton( &$gateway_adapter ) { |
39 | 37 | if ( !self::$instance ) { |
40 | | - self::$instance = new self; |
| 38 | + self::$instance = new self( &$gateway_adapter ); |
41 | 39 | } |
42 | 40 | return self::$instance; |
43 | 41 | } |
Index: branches/fundraising/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 | * |
— | — | @@ -14,12 +15,11 @@ |
15 | 16 | * To install: |
16 | 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 | /** |
— | — | @@ -36,11 +36,12 @@ |
37 | 37 | $wgMinFraudStandalone = FALSE; |
38 | 38 | |
39 | 39 | $dir = dirname( __FILE__ ) . "/"; |
40 | | -$wgAutoloadClasses['PayflowProGateway_Extras_MinFraud'] = $dir . "../../../minfraud/minfraud.body.php"; |
41 | | -$wgAutoloadClasses['PayflowProGateway_Extras_CustomFilters_MinFraud'] = $dir . "minfraud.body.php"; |
| 40 | +$wgAutoloadClasses['Gateway_Extras_MinFraud'] = $dir . "../../../minfraud/minfraud.body.php"; |
| 41 | +$wgAutoloadClasses['Gateway_Extras_CustomFilters_MinFraud'] = $dir . "minfraud.body.php"; |
42 | 42 | $wgExtensionFunctions[] = 'efCustomFiltersMinFraudSetup'; |
43 | 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: branches/fundraising/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 | 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: branches/fundraising/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 | } |
— | — | @@ -57,4 +56,5 @@ |
58 | 57 | } |
59 | 58 | return self::$instance; |
60 | 59 | } |
| 60 | + |
61 | 61 | } |
Index: branches/fundraising/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,408 @@ |
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 | + } |
184 | 163 | |
185 | | - function readIpAddressFromWeb() { |
186 | | - // check if the curl module exists |
187 | | - $url = "http://www.maxmind.com/app/ws_ipaddr"; |
188 | | - if ( extension_loaded( 'curl' ) ) { |
189 | | - // open curl |
190 | | - $ch = curl_init(); |
| 164 | + // if the ip addresses expired or don't exist then |
| 165 | + // get them from the web and write |
| 166 | + // them to the cache file |
| 167 | + if ( ( ( time() - $datetime ) > $this->wsIpaddrRefreshTimeout ) | (!$ipstr ) ) { |
| 168 | + $tryIpstr = $this->readIpAddressFromWeb(); |
| 169 | + if ( $tryIpstr ) { |
| 170 | + $ipstr = $tryIpstr; |
| 171 | + } else { |
| 172 | + if ( $this->debug == 1 ) { |
| 173 | + print "Warning, unable to get ws_ipaddr from www.maxmind.com\n"; |
| 174 | + } |
| 175 | + } |
| 176 | + // we write to cache whether or not we were able to get $tryIpStr, since |
| 177 | + // in case DNS goes down, we don't want to check app/ws_ipaddr over and over |
| 178 | + $this->writeIpAddressToCache( $this->wsIpaddrCacheFile, $ipstr ); |
| 179 | + } |
| 180 | + if ( $this->debug == 1 ) { |
| 181 | + print "reading ip address from cache\n"; |
| 182 | + print "ip str: " . $ipstr . "\n"; |
| 183 | + print "date time: " . $datetime . "\n"; |
| 184 | + } |
| 185 | + // return the ip addresses |
| 186 | + return $ipstr; |
| 187 | + } |
191 | 188 | |
192 | | - // set curl options |
193 | | - curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); |
194 | | - curl_setopt( $ch, CURLOPT_URL, $url ); |
195 | | - curl_setopt( $ch, CURLOPT_TIMEOUT, $this->timeout ); |
| 189 | + function readIpAddressFromWeb() { |
| 190 | + // check if the curl module exists |
| 191 | + $url = "http://www.maxmind.com/app/ws_ipaddr"; |
| 192 | + if ( extension_loaded( 'curl' ) ) { |
| 193 | + // open curl |
| 194 | + $ch = curl_init(); |
196 | 195 | |
197 | | - // get the content |
198 | | - $content = curl_exec( $ch ); |
199 | | - $content = rtrim( $content ); |
200 | | - if ( $this->debug == 1 ) { |
201 | | - print "using curl\n"; |
202 | | - } |
203 | | - } else { |
204 | | - // we using HTTP without curl |
| 196 | + // set curl options |
| 197 | + curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); |
| 198 | + curl_setopt( $ch, CURLOPT_URL, $url ); |
| 199 | + curl_setopt( $ch, CURLOPT_TIMEOUT, $this->timeout ); |
205 | 200 | |
206 | | - // parse the url to get |
207 | | - // host, path and query |
208 | | - $url3 = parse_url( $url ); |
209 | | - $host = $url3["host"]; |
210 | | - $path = $url3["path"]; |
| 201 | + // get the content |
| 202 | + $content = curl_exec( $ch ); |
| 203 | + $content = rtrim( $content ); |
| 204 | + if ( $this->debug == 1 ) { |
| 205 | + print "using curl\n"; |
| 206 | + } |
| 207 | + } else { |
| 208 | + // we using HTTP without curl |
| 209 | + // parse the url to get |
| 210 | + // host, path and query |
| 211 | + $url3 = parse_url( $url ); |
| 212 | + $host = $url3["host"]; |
| 213 | + $path = $url3["path"]; |
211 | 214 | |
212 | | - // open the connection |
213 | | - $fp = fsockopen ( $host, 80, $errno, $errstr, $this->timeout ); |
214 | | - if ( $fp ) { |
215 | | - // send the request |
216 | | - fputs ( $fp, "GET $path HTTP/1.0\nHost: " . $host . "\n\n" ); |
217 | | - while ( !feof( $fp ) ) { |
218 | | - $buf .= fgets( $fp, 128 ); |
219 | | - } |
220 | | - $lines = preg_split( "/\n/", $buf ); |
221 | | - // get the content |
222 | | - $content = $lines[count( $lines ) -1]; |
223 | | - // close the connection |
224 | | - fclose( $fp ); |
225 | | - } |
226 | | - if ( $this->debug == 1 ) { |
227 | | - print "using fsockopen\n"; |
228 | | - } |
229 | | - } |
230 | | - if ( $this->debug == 1 ) { |
231 | | - print "readIpAddressFromWeb found ip addresses: " . $content . "\n"; |
232 | | - } |
233 | | - // TODO fix regexp so that it checks if it only has IP addresses |
234 | | - if ( preg_match( "/([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/", $content ) ) { |
235 | | - return $content; |
236 | | - } |
237 | | - return ""; |
238 | | - } |
| 215 | + // open the connection |
| 216 | + $fp = fsockopen( $host, 80, $errno, $errstr, $this->timeout ); |
| 217 | + if ( $fp ) { |
| 218 | + // send the request |
| 219 | + fputs( $fp, "GET $path HTTP/1.0\nHost: " . $host . "\n\n" ); |
| 220 | + while ( !feof( $fp ) ) { |
| 221 | + $buf .= fgets( $fp, 128 ); |
| 222 | + } |
| 223 | + $lines = preg_split( "/\n/", $buf ); |
| 224 | + // get the content |
| 225 | + $content = $lines[count( $lines ) - 1]; |
| 226 | + // close the connection |
| 227 | + fclose( $fp ); |
| 228 | + } |
| 229 | + if ( $this->debug == 1 ) { |
| 230 | + print "using fsockopen\n"; |
| 231 | + } |
| 232 | + } |
| 233 | + if ( $this->debug == 1 ) { |
| 234 | + print "readIpAddressFromWeb found ip addresses: " . $content . "\n"; |
| 235 | + } |
| 236 | + // TODO fix regexp so that it checks if it only has IP addresses |
| 237 | + if ( preg_match( "/([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/", $content ) ) { |
| 238 | + return $content; |
| 239 | + } |
| 240 | + return ""; |
| 241 | + } |
239 | 242 | |
240 | | - // this function queries a single server |
241 | | - function querySingleServer( $server ) { |
242 | | - global $wgPayflowProGatewayUseHTTPProxy, $wgPayflowProGatewayHTTPProxy; |
| 243 | + // this function queries a single server |
| 244 | + function querySingleServer( $server ) { |
| 245 | + $useHTTPProxy = $this->gateway_adapter->getGlobal( 'UseHTTPProxy' ); |
| 246 | + $HTTPProxy = $this->gateway_adapter->getGlobal( 'HTTPProxy' ); |
243 | 247 | |
244 | | - // check if we using the Secure HTTPS proctol |
245 | | - if ( $this->isSecure == 1 ) { |
246 | | - $scheme = "https://"; // Secure HTTPS proctol |
247 | | - } else { |
248 | | - $scheme = "http://"; // Regular HTTP proctol |
249 | | - } |
| 248 | + // check if we using the Secure HTTPS proctol |
| 249 | + if ( $this->isSecure == 1 ) { |
| 250 | + $scheme = "https://"; // Secure HTTPS proctol |
| 251 | + } else { |
| 252 | + $scheme = "http://"; // Regular HTTP proctol |
| 253 | + } |
250 | 254 | |
251 | | - // build a query string from the hash called queries |
252 | | - $numquerieskeys = count( $this->queries ); // get the number of keys in the hash called queries |
253 | | - $querieskeys = array_keys( $this->queries ); // get a array of keys in the hash called queries |
254 | | - if ( $this->debug == 1 ) { |
255 | | - print "number of query keys " . $numquerieskeys . "\n"; |
256 | | - } |
| 255 | + // build a query string from the hash called queries |
| 256 | + $numquerieskeys = count( $this->queries ); // get the number of keys in the hash called queries |
| 257 | + $querieskeys = array_keys( $this->queries ); // get a array of keys in the hash called queries |
| 258 | + if ( $this->debug == 1 ) { |
| 259 | + print "number of query keys " . $numquerieskeys . "\n"; |
| 260 | + } |
257 | 261 | |
258 | | - $query_string = ""; |
| 262 | + $query_string = ""; |
259 | 263 | |
260 | | - for ( $i = 0; $i < $numquerieskeys; $i++ ) { |
261 | | - // for each element in the hash called queries |
262 | | - // append the key and value of the element to the query string |
263 | | - $key = $querieskeys[$i]; |
264 | | - $value = $this->queries[$key]; |
265 | | - // encode the key and value before adding it to the string |
266 | | - // $key = urlencode($key); |
267 | | - // $value = urlencode($value); |
268 | | - if ( $this->debug == 1 ) { |
269 | | - print " query key " . $key . " query value " . $value . "\n"; |
270 | | - } |
271 | | - $query_string = $query_string . $key . "=" . $value; |
272 | | - if ( $i < $numquerieskeys - 1 ) { |
273 | | - $query_string = $query_string . "&"; |
274 | | - } |
275 | | - } |
| 264 | + for ( $i = 0; $i < $numquerieskeys; $i++ ) { |
| 265 | + // for each element in the hash called queries |
| 266 | + // append the key and value of the element to the query string |
| 267 | + $key = $querieskeys[$i]; |
| 268 | + $value = $this->queries[$key]; |
| 269 | + // encode the key and value before adding it to the string |
| 270 | + // $key = urlencode($key); |
| 271 | + // $value = urlencode($value); |
| 272 | + if ( $this->debug == 1 ) { |
| 273 | + print " query key " . $key . " query value " . $value . "\n"; |
| 274 | + } |
| 275 | + $query_string = $query_string . $key . "=" . $value; |
| 276 | + if ( $i < $numquerieskeys - 1 ) { |
| 277 | + $query_string = $query_string . "&"; |
| 278 | + } |
| 279 | + } |
276 | 280 | |
277 | | - // check if the curl module exists |
278 | | - if ( extension_loaded( 'curl' ) ) { |
279 | | - // use curl |
280 | | - if ( $this->debug == 1 ) { |
281 | | - print "using curl\n"; |
282 | | - } |
| 281 | + // check if the curl module exists |
| 282 | + if ( extension_loaded( 'curl' ) ) { |
| 283 | + // use curl |
| 284 | + if ( $this->debug == 1 ) { |
| 285 | + print "using curl\n"; |
| 286 | + } |
283 | 287 | |
284 | | - // open curl |
285 | | - $ch = curl_init(); |
| 288 | + // open curl |
| 289 | + $ch = curl_init(); |
286 | 290 | |
287 | | - $url = $scheme . $server . "/" . $this->url; |
| 291 | + $url = $scheme . $server . "/" . $this->url; |
288 | 292 | |
289 | | - // set curl options |
290 | | - if ( $this->debug == 1 ) { |
291 | | - print "url " . $url . "\n"; |
292 | | - } |
293 | | - curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); |
294 | | - curl_setopt( $ch, CURLOPT_URL, $url ); |
295 | | - curl_setopt( $ch, CURLOPT_TIMEOUT, $this->timeout ); |
296 | | - curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 ); |
| 293 | + // set curl options |
| 294 | + if ( $this->debug == 1 ) { |
| 295 | + print "url " . $url . "\n"; |
| 296 | + } |
| 297 | + curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); |
| 298 | + curl_setopt( $ch, CURLOPT_URL, $url ); |
| 299 | + curl_setopt( $ch, CURLOPT_TIMEOUT, $this->timeout ); |
| 300 | + curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 ); |
297 | 301 | |
298 | | - // this option lets you store the result in a string |
299 | | - curl_setopt( $ch, CURLOPT_POST, 1 ); |
300 | | - curl_setopt( $ch, CURLOPT_POSTFIELDS, $query_string ); |
| 302 | + // this option lets you store the result in a string |
| 303 | + curl_setopt( $ch, CURLOPT_POST, 1 ); |
| 304 | + curl_setopt( $ch, CURLOPT_POSTFIELDS, $query_string ); |
301 | 305 | |
302 | | - // set proxy settings if necessary |
303 | | - if ( $wgPayflowProGatewayUseHTTPProxy ) { |
304 | | - curl_setopt( $ch, CURLOPT_HTTPPROXYTUNNEL, 1 ); |
305 | | - curl_setopt( $ch, CURLOPT_PROXY, $wgPayflowProGatewayHTTPProxy ); |
306 | | - } |
| 306 | + // set proxy settings if necessary |
| 307 | + if ( $useHTTPProxy ) { |
| 308 | + curl_setopt( $ch, CURLOPT_HTTPPROXYTUNNEL, 1 ); |
| 309 | + curl_setopt( $ch, CURLOPT_PROXY, $HTTPProxy ); |
| 310 | + } |
307 | 311 | |
308 | | - // get the content |
309 | | - $content = curl_exec( $ch ); |
| 312 | + // get the content |
| 313 | + $content = curl_exec( $ch ); |
310 | 314 | |
311 | | - // For some reason curl_errno returns an error even when function works |
312 | | - // Until we figure this out, will ignore curl errors - (not good i know) |
| 315 | + // For some reason curl_errno returns an error even when function works |
| 316 | + // Until we figure this out, will ignore curl errors - (not good i know) |
313 | 317 | // $e = curl_errno($ch);//get error or sucess |
314 | | - |
315 | 318 | // if (($e == 1) & ($this->isSecure == 1)) { |
316 | | - // HTTPS does not work print error message |
| 319 | + // HTTPS does not work print error message |
317 | 320 | // print "error: this version of curl does not support HTTPS try build curl with SSL or specify \$ccfs->isSecure = 0\n"; |
318 | 321 | // } |
319 | 322 | // if ($e > 0) { |
320 | | - // we get a error msg print it |
| 323 | + // we get a error msg print it |
321 | 324 | // print "Received error message $e from curl: " . curl_error($ch) . "\n"; |
322 | 325 | // return 0; |
323 | 326 | // } |
324 | | - // close curl |
325 | | - curl_close( $ch ); |
326 | | - } else { |
327 | | - // curl does not exist |
328 | | - // use the fsockopen function, |
329 | | - // the fgets function and the fclose function |
330 | | - if ( $this->debug == 1 ) { |
331 | | - print "using fsockopen for querySingleServer\n"; |
332 | | - } |
| 327 | + // close curl |
| 328 | + curl_close( $ch ); |
| 329 | + } else { |
| 330 | + // curl does not exist |
| 331 | + // use the fsockopen function, |
| 332 | + // the fgets function and the fclose function |
| 333 | + if ( $this->debug == 1 ) { |
| 334 | + print "using fsockopen for querySingleServer\n"; |
| 335 | + } |
333 | 336 | |
334 | | - $url = $scheme . $server . "/" . $this->url . "?" . $query_string; |
335 | | - if ( $this->debug == 1 ) { |
336 | | - print "url " . $url . " " . "\n"; |
337 | | - } |
| 337 | + $url = $scheme . $server . "/" . $this->url . "?" . $query_string; |
| 338 | + if ( $this->debug == 1 ) { |
| 339 | + print "url " . $url . " " . "\n"; |
| 340 | + } |
338 | 341 | |
339 | | - // now check if we are using regular HTTP |
340 | | - if ( $this->isSecure == 0 ) { |
341 | | - // we using regular HTTP |
| 342 | + // now check if we are using regular HTTP |
| 343 | + if ( $this->isSecure == 0 ) { |
| 344 | + // we using regular HTTP |
| 345 | + // parse the url to get |
| 346 | + // host, path and query |
| 347 | + $url3 = parse_url( $url ); |
| 348 | + $host = $url3["host"]; |
| 349 | + $path = $url3["path"]; |
| 350 | + $query = $url3["query"]; |
342 | 351 | |
343 | | - // parse the url to get |
344 | | - // host, path and query |
345 | | - $url3 = parse_url( $url ); |
346 | | - $host = $url3["host"]; |
347 | | - $path = $url3["path"]; |
348 | | - $query = $url3["query"]; |
| 352 | + // open the connection |
| 353 | + $fp = fsockopen( $host, 80, $errno, $errstr, $this->timeout ); |
| 354 | + if ( $fp ) { |
| 355 | + // send the request |
| 356 | + $post = "POST $path HTTP/1.0\nHost: " . $host . "\nContent-type: application/x-www-form-urlencoded\nUser-Agent: Mozilla 4.0\nContent-length: " . strlen( $query ) . "\nConnection: close\n\n$query"; |
| 357 | + fputs( $fp, $post ); |
| 358 | + while ( !feof( $fp ) ) { |
| 359 | + $buf .= fgets( $fp, 128 ); |
| 360 | + } |
| 361 | + $lines = preg_split( "/\n/", $buf ); |
| 362 | + // get the content |
| 363 | + $content = $lines[count( $lines ) - 1]; |
| 364 | + // close the connection |
| 365 | + fclose( $fp ); |
| 366 | + } else { |
| 367 | + return 0; |
| 368 | + } |
| 369 | + } else { |
| 370 | + // secure HTTPS requires CURL |
| 371 | + print "error: you need to install curl if you want secure HTTPS or specify the variable to be $ccfs->isSecure = 0"; |
| 372 | + return 0; |
| 373 | + } |
| 374 | + } |
349 | 375 | |
350 | | - // open the connection |
351 | | - $fp = fsockopen ( $host, 80, $errno, $errstr, $this->timeout ); |
352 | | - if ( $fp ) { |
353 | | - // send the request |
354 | | - $post = "POST $path HTTP/1.0\nHost: " . $host . "\nContent-type: application/x-www-form-urlencoded\nUser-Agent: Mozilla 4.0\nContent-length: " . strlen( $query ) . "\nConnection: close\n\n$query"; |
355 | | - fputs ( $fp, $post ); |
356 | | - while ( !feof( $fp ) ) { |
357 | | - $buf .= fgets( $fp, 128 ); |
358 | | - } |
359 | | - $lines = preg_split( "/\n/", $buf ); |
360 | | - // get the content |
361 | | - $content = $lines[count( $lines ) -1]; |
362 | | - // close the connection |
363 | | - fclose( $fp ); |
364 | | - } else { |
365 | | - return 0; |
366 | | - } |
367 | | - } else { |
368 | | - // secure HTTPS requires CURL |
369 | | - print "error: you need to install curl if you want secure HTTPS or specify the variable to be $ccfs->isSecure = 0"; |
370 | | - return 0; |
371 | | - } |
372 | | - } |
| 376 | + if ( $this->debug == 1 ) { |
| 377 | + print "content = " . $content . "\n"; |
| 378 | + } |
| 379 | + // get the keys and values from |
| 380 | + // the string content and store them |
| 381 | + // the hash named outputstr |
| 382 | + // split content into pairs containing both |
| 383 | + // the key and the value |
| 384 | + $keyvaluepairs = explode( ";", $content ); |
373 | 385 | |
374 | | - if ( $this->debug == 1 ) { |
375 | | - print "content = " . $content . "\n"; |
376 | | - } |
377 | | - // get the keys and values from |
378 | | - // the string content and store them |
379 | | - // the hash named outputstr |
| 386 | + // get the number of key and value pairs |
| 387 | + $numkeyvaluepairs = count( $keyvaluepairs ); |
380 | 388 | |
381 | | - // split content into pairs containing both |
382 | | - // the key and the value |
383 | | - $keyvaluepairs = explode( ";", $content ); |
| 389 | + // for each pair store key and value into the |
| 390 | + // hash named outputstr |
| 391 | + $this->outputstr = array( ); |
| 392 | + for ( $i = 0; $i < $numkeyvaluepairs; $i++ ) { |
| 393 | + // split the pair into a key and a value |
| 394 | + list( $key, $value ) = explode( "=", $keyvaluepairs[$i] ); |
| 395 | + if ( $this->debug == 1 ) { |
| 396 | + print " output " . $key . " = " . $value . "\n"; |
| 397 | + } |
| 398 | + // store the key and the value into the |
| 399 | + // hash named outputstr |
| 400 | + $this->outputstr[$key] = $value; |
| 401 | + } |
| 402 | + // check if outputstr has the score if outputstr does not have |
| 403 | + // the score return 0 |
| 404 | + if ( $this->outputstr[$this->check_field] == "" ) { |
| 405 | + return 0; |
| 406 | + } |
| 407 | + // one other way to do it |
| 408 | + // if (!array_key_exists("score",$this->outputstr)) { |
| 409 | + // return 0; |
| 410 | + // } |
| 411 | + return 1; |
| 412 | + } |
384 | 413 | |
385 | | - // get the number of key and value pairs |
386 | | - $numkeyvaluepairs = count( $keyvaluepairs ); |
| 414 | + function _getTempDir() { |
| 415 | + if ( ini_get( 'upload_tmp_dir' ) ) { |
| 416 | + return ini_get( 'upload_tmp_dir' ); |
| 417 | + } |
387 | 418 | |
388 | | - // for each pair store key and value into the |
389 | | - // hash named outputstr |
390 | | - $this->outputstr = array(); |
391 | | - for ( $i = 0; $i < $numkeyvaluepairs; $i++ ) { |
392 | | - // split the pair into a key and a value |
393 | | - list( $key, $value ) = explode( "=", $keyvaluepairs[$i] ); |
394 | | - if ( $this->debug == 1 ) { |
395 | | - print " output " . $key . " = " . $value . "\n"; |
396 | | - } |
397 | | - // store the key and the value into the |
398 | | - // hash named outputstr |
399 | | - $this->outputstr[$key] = $value; |
400 | | - } |
401 | | - // check if outputstr has the score if outputstr does not have |
402 | | - // the score return 0 |
403 | | - if ( $this->outputstr[$this->check_field] == "" ) { |
404 | | - return 0; |
405 | | - } |
406 | | - // one other way to do it |
407 | | - // if (!array_key_exists("score",$this->outputstr)) { |
408 | | - // return 0; |
409 | | - // } |
410 | | - return 1; |
411 | | - } |
| 419 | + if ( substr( PHP_OS, 0, 3 ) != 'WIN' ) { |
| 420 | + return '/tmp'; |
| 421 | + } |
412 | 422 | |
413 | | - function _getTempDir() { |
414 | | - if ( ini_get( 'upload_tmp_dir' ) ) { |
415 | | - return ini_get( 'upload_tmp_dir' ); |
416 | | - } |
| 423 | + if ( isset( $_ENV['TMP'] ) ) { |
| 424 | + return $_ENV['TMP']; |
| 425 | + } |
417 | 426 | |
418 | | - if ( substr( PHP_OS, 0, 3 ) != 'WIN' ) { |
419 | | - return '/tmp'; |
420 | | - } |
| 427 | + if ( isset( $_ENV['TEMP'] ) ) { |
| 428 | + return $_ENV['TEMP']; |
| 429 | + } |
421 | 430 | |
422 | | - if ( isset( $_ENV['TMP'] ) ) { |
423 | | - return $_ENV['TMP']; |
424 | | - } |
| 431 | + if ( is_dir( 'c:\\windows\\temp' ) ) { |
| 432 | + return 'c:\\windows\\temp'; |
| 433 | + } |
425 | 434 | |
426 | | - if ( isset( $_ENV['TEMP'] ) ) { |
427 | | - return $_ENV['TEMP']; |
428 | | - } |
| 435 | + if ( is_dir( 'c:\\winnt\\temp' ) ) { |
| 436 | + return 'c:\\winnt\\temp'; |
| 437 | + } |
429 | 438 | |
430 | | - if ( is_dir( 'c:\\windows\\temp' ) ) { |
431 | | - return 'c:\\windows\\temp'; |
432 | | - } |
| 439 | + return '.'; |
| 440 | + } |
433 | 441 | |
434 | | - if ( is_dir( 'c:\\winnt\\temp' ) ) { |
435 | | - return 'c:\\winnt\\temp'; |
436 | | - } |
| 442 | +} |
437 | 443 | |
438 | | - return '.'; |
439 | | - } |
440 | | -} |
441 | 444 | ?> |
Index: branches/fundraising/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: branches/fundraising/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: branches/fundraising/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: branches/fundraising/extensions/DonationInterface/extras/minfraud/tests/minfraudTest.php |
— | — | @@ -1,25 +1,29 @@ |
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 | 15 | require_once( $dir . "../../../includes/countryCodes.inc" ); |
15 | | - global $wgPayflowGatewayLog; |
16 | | - $wgPayflowGatewayLog = dirname( __FILE__ ) . "/test_log"; |
| 16 | + global $wgDonationInterfaceExtrasLog; |
| 17 | + $wgDonationInterfaceExtrasLog = dirname( __FILE__ ) . "/test_log"; |
17 | 18 | $license_key = 'XBCKSF4gnHA7'; |
18 | | - $this->fixture = new PayflowProGateway_Extras_MinFraud( $license_key ); |
| 19 | + global $wgPayflowProGatewayTest; |
| 20 | + $wgPayflowProGatewayTest = true; |
| 21 | + $adapter = new PayflowProAdapter(); |
| 22 | + $this->fixture = new Gateway_Extras_MinFraud( &$adapter, $license_key ); |
19 | 23 | } |
20 | 24 | |
21 | 25 | protected function tearDown() { |
22 | | - global $wgPayflowGatewayLog; |
23 | | - unlink( $wgPayflowGatewayLog ); |
| 26 | + global $wgDonationInterfaceExtrasLog; |
| 27 | + unlink( $wgDonationInterfaceExtrasLog ); |
24 | 28 | } |
25 | 29 | |
26 | 30 | public function testCcfdInstance() { |
— | — | @@ -43,8 +47,8 @@ |
44 | 48 | $this->assertArrayHasKey( "bin", $query ); |
45 | 49 | $this->assertArrayHasKey( "txnID", $query ); |
46 | 50 | $this->assertArrayNotHasKey( "foo", $query ); // make sure we're not adding extraneous info |
47 | | - $this->assertNotContains( "@", $query[ 'domain' ] ); // make sure we're only getting domains from email addresses |
48 | | - $this->assertEquals( 6, strlen( $query[ 'bin' ] ) ); // make sure our bin is 6 digits long |
| 51 | + $this->assertNotContains( "@", $query['domain'] ); // make sure we're only getting domains from email addresses |
| 52 | + $this->assertEquals( 6, strlen( $query['bin'] ) ); // make sure our bin is 6 digits long |
49 | 53 | } |
50 | 54 | |
51 | 55 | public function queryDataProvider() { |
— | — | @@ -68,11 +72,11 @@ |
69 | 73 | /** |
70 | 74 | * @dataProvider queryDataProvider |
71 | 75 | */ |
72 | | -/* public function testQueryMinfraud( $data ) { |
73 | | - $query = $this->fixture->build_query( $data ); |
74 | | - $this->fixture->query_minfraud( $query ); |
75 | | - $this->assertType( 'array', $this->fixture->minfraud_response ); |
76 | | - }*/ |
| 76 | + /* public function testQueryMinfraud( $data ) { |
| 77 | + $query = $this->fixture->build_query( $data ); |
| 78 | + $this->fixture->query_minfraud( $query ); |
| 79 | + $this->assertType( 'array', $this->fixture->minfraud_response ); |
| 80 | + } */ |
77 | 81 | |
78 | 82 | /** |
79 | 83 | * @dataProvider hashValidateFalseData |
— | — | @@ -81,10 +85,18 @@ |
82 | 86 | $this->assertFalse( $this->fixture->validate_minfraud_query( $data ) ); |
83 | 87 | } |
84 | 88 | |
| 89 | + public function setExtrasGlobal( $varname, $value ) { |
| 90 | + //Just set the one for the adapter. |
| 91 | + $adapter_prefix = $this->fixture->gateway_adapter->getGlobalPrefix(); |
| 92 | + $globalname = $adapter_prefix . $varname; |
| 93 | + global $$globalname; |
| 94 | + $$globalname = $value; |
| 95 | + } |
| 96 | + |
85 | 97 | public function hashValidateFalseData() { |
86 | 98 | return array( |
87 | 99 | array( |
88 | | - array(), |
| 100 | + array( ), |
89 | 101 | array( 'license_key' => 'a' ), |
90 | 102 | array( |
91 | 103 | 'license_key' => 'a', |
— | — | @@ -154,29 +166,26 @@ |
155 | 167 | } |
156 | 168 | |
157 | 169 | public function testLogging() { |
158 | | - global $wgPayflowGatewayLog; |
| 170 | + global $wgDonationInterfaceExtrasLog; |
159 | 171 | $this->fixture->log( '', '', "\"foo\"" ); |
160 | | - $new_fh = fopen( $wgPayflowGatewayLog, 'r' ); |
161 | | - $this->assertEquals( '"' . date( 'c' ) . '"' . "\t\"\"\t\"\"\t\"foo\"\n", fread( $new_fh, filesize( $wgPayflowGatewayLog ) ) ); |
| 172 | + $new_fh = fopen( $wgDonationInterfaceExtrasLog, 'r' ); |
| 173 | + $this->assertEquals( '"' . date( 'c' ) . '"' . "\t\"\"\t\"\"\t\"foo\"\n", fread( $new_fh, filesize( $wgDonationInterfaceExtrasLog ) ) ); |
162 | 174 | fclose( $new_fh ); |
163 | 175 | } |
164 | 176 | |
165 | 177 | public function testGenerateHash() { |
166 | | - global $wgPayflowProGatewaySalt; |
167 | | - $wgPayflowProGatewaySalt = 'salt'; |
| 178 | + $this->setExtrasGlobal( 'Salt', 'salt' ); |
168 | 179 | $this->assertEquals( '5a9ee1e4a15adbf03b3ef9f7baa6caffa9f6bcd72c736498f045c073e57753e7b244bc97fe82b075eabd80778a4d56eb14406e9a1ac4b13737b2c3fd8c3717e8', $this->fixture->generate_hash( 'foo' ) ); |
169 | 180 | } |
170 | 181 | |
171 | 182 | public function testCompareHash() { |
172 | | - global $wgPayflowProGatewaySalt; |
173 | | - $wgPayflowProGatewaySalt = 'salt'; |
| 183 | + $this->setExtrasGlobal( 'Salt', 'salt' ); |
174 | 184 | $this->assertTrue( $this->fixture->compare_hash( '5a9ee1e4a15adbf03b3ef9f7baa6caffa9f6bcd72c736498f045c073e57753e7b244bc97fe82b075eabd80778a4d56eb14406e9a1ac4b13737b2c3fd8c3717e8', 'foo' ) ); |
175 | 185 | $this->assertFalse( $this->fixture->compare_hash( '5a9ee1e4a15adbf03b3ef9f7baa6caffa9f6bcd72c736498f045c073e57753e7b244bc97fe82b075eabd80778a4d56eb14406e9a1ac4b13737b2c3fd8c3717e8', 'bar' ) ); |
176 | 186 | } |
177 | 187 | |
178 | 188 | public function testBypassMinfraud() { |
179 | | - global $wgPayflowProGatewaySalt; |
180 | | - $wgPayflowProGatewaySalt = 'salt'; |
| 189 | + $this->setExtrasGlobal( 'Salt', 'salt' ); |
181 | 190 | $data = array( |
182 | 191 | 'action' => '4bd7857c851039d1e07a434800fe752c6bd99aec61c325aef460441be1b95c3ab5236e43c8d06f41d77715dbd3cf94e679b86422ec3204f00ad433501e5005e9', |
183 | 192 | 'data_hash' => '029ef6f5c2a165215b5a92ff1a194e4a6de8c668d6193582da42713f119c1b07d8358b5cd94a3bd51c9aa50709c8533295215ce3cce8c2b61e69078d789bc3f3', |
— | — | @@ -191,4 +200,5 @@ |
192 | 201 | $data[] = 'bar'; |
193 | 202 | $this->assertFalse( $this->fixture->can_bypass_minfraud( $this->fixture, $data ) ); |
194 | 203 | } |
| 204 | + |
195 | 205 | } |
Index: branches/fundraising/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,8 +38,8 @@ |
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 | 46 | require_once( $dir . "../../includes/countryCodes.inc" ); |
— | — | @@ -50,46 +51,48 @@ |
51 | 52 | } |
52 | 53 | $this->minfraud_license_key = ( $license_key ) ? $license_key : $wgMinFraudLicenseKey; |
53 | 54 | |
54 | | - if ( isset( $wgMinFraudActionRanges ) ) $this->action_ranges = $wgMinFraudActionRanges; |
| 55 | + if ( isset( $wgMinFraudActionRanges ) ) |
| 56 | + $this->action_ranges = $wgMinFraudActionRanges; |
55 | 57 | } |
56 | 58 | |
57 | 59 | /** |
58 | 60 | * Query minFraud with the transaction, set actions to take and make a log entry |
59 | 61 | * |
60 | | - * Accessible via $wgHooks[ 'PayflowGatewayValidate' ] |
61 | | - * @param object PayflowPro Gateway object |
| 62 | + * Accessible via $wgHooks[ 'GatewayValidate' ] |
| 63 | + * @param object Gateway object |
62 | 64 | * @param array The array of data generated from an attempted transaction |
63 | 65 | */ |
64 | | - public function validate( &$pfp_gateway_object, &$data ) { |
| 66 | + public function validate() { |
65 | 67 | // see if we can bypass minfraud |
66 | | - if ( $this->can_bypass_minfraud( $pfp_gateway_object, $data ) ) return TRUE; |
| 68 | + if ( $this->can_bypass_minfraud() ) |
| 69 | + return TRUE; |
67 | 70 | |
68 | | - $minfraud_query = $this->build_query( $data ); |
| 71 | + $minfraud_query = $this->build_query( $this->gateway_adapter->getData() ); |
69 | 72 | $this->query_minfraud( $minfraud_query ); |
70 | | - $pfp_gateway_object->action = $this->determine_action( $this->minfraud_response[ 'riskScore' ] ); |
| 73 | + $this->gateway_adapter->action = $this->determine_action( $this->minfraud_response['riskScore'] ); |
71 | 74 | |
72 | 75 | // reset the data hash |
73 | | - if ( isset( $data[ 'data_hash' ] ) ) unset( $data[ 'data_hash' ] ); |
74 | | - $data[ 'action' ] = $this->generate_hash( $pfp_gateway_object->action ); |
75 | | - $data[ 'data_hash' ] = $this->generate_hash( serialize( $data ) ); |
| 76 | + $this->gateway_adapter->unsetHash(); |
| 77 | + $this->gateway_adapter->setActionHash( $this->generate_hash( $this->gateway_adapter->action ) ); |
| 78 | + $this->gateway_adapter->setHash( $this->generate_hash( $this->gateway_adapter->getData() ) ); |
76 | 79 | |
77 | 80 | // Write the query/response to the log |
78 | | - $this->log_query( $minfraud_query, $pfp_gateway_object, $data ); |
| 81 | + $this->log_query( $minfraud_query ); |
79 | 82 | return TRUE; |
80 | 83 | } |
81 | 84 | |
82 | 85 | /** |
83 | 86 | * Logs a minFraud query and its response |
84 | 87 | */ |
85 | | - public function log_query( $minfraud_query, $pfp_gateway_object, $data ) { |
| 88 | + public function log_query( $minfraud_query ) { |
86 | 89 | if ( $this->log_fh ) { |
87 | | - $log_message = '"' . addslashes( $data[ 'comment' ] ) . '"'; |
88 | | - $log_message .= "\t" . '"' . addslashes( $data[ 'amount' ] . ' ' . $data[ 'currency' ] ) . '"'; |
| 90 | + $log_message = '"' . addslashes( $this->gateway_adapter->getData( 'comment' ) ) . '"'; |
| 91 | + $log_message .= "\t" . '"' . addslashes( $this->gateway_adapter->getData( 'amount' ) . ' ' . $this->gateway_adapter->getData( 'currency' ) ) . '"'; |
89 | 92 | $log_message .= "\t" . '"' . addslashes( json_encode( $minfraud_query ) ) . '"'; |
90 | 93 | $log_message .= "\t" . '"' . addslashes( json_encode( $this->minfraud_response ) ) . '"'; |
91 | | - $log_message .= "\t" . '"' . addslashes( $pfp_gateway_object->action ) . '"'; |
92 | | - $log_message .= "\t" . '"' . addslashes( $data[ 'referrer' ] ) . '"'; |
93 | | - $this->log( $data[ 'contribution_tracking_id' ], 'minFraud query', $log_message ); |
| 94 | + $log_message .= "\t" . '"' . addslashes( $this->gateway_adapter->action ) . '"'; |
| 95 | + $log_message .= "\t" . '"' . addslashes( $this->gateway_adapter->getData( 'referrer' ) ) . '"'; |
| 96 | + $this->log( $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'minFraud query', $log_message ); |
94 | 97 | } |
95 | 98 | } |
96 | 99 | |
— | — | @@ -102,40 +105,37 @@ |
103 | 106 | * assume the transaction has already gone through the minFraud check and can be passed |
104 | 107 | * on to the appropriate action. |
105 | 108 | * |
106 | | - * @param object $pfp_gateway_object The PayflowPro gateway object |
107 | | - * @param array $data The array of data from the form submission |
108 | 109 | * @return bool |
109 | 110 | */ |
110 | | - public function can_bypass_minfraud( &$pfp_gateway_object, &$data ) { |
| 111 | + public function can_bypass_minfraud() { |
111 | 112 | // if the data bits data_hash and action are not set, we need to hit minFraud |
112 | | - if ( !strlen( $data[ 'data_hash' ] ) || !strlen( $data[ 'action' ] ) ) { |
| 113 | + $localdata = $this->gateway_adapter->getData(); |
| 114 | + if ( !strlen( $localdata['data_hash'] ) || !strlen( $localdata['action'] ) ) { |
113 | 115 | return FALSE; |
114 | 116 | } |
115 | 117 | |
116 | | - $data_hash = $data[ 'data_hash' ]; // the data hash passed in by the form submission |
117 | | - $num_attempt = $data[ 'numAttempt' ]; // the num_attempt has been increased by one, so we have to adjust slightly |
118 | | - $data[ 'numAttempt' ] = $num_attempt - 1; |
119 | | - |
120 | | - // unset these values from the data aray since they are not part of the overall data hash |
121 | | - unset( $data[ 'data_hash' ] ); |
| 118 | + $data_hash = $localdata['data_hash']; // the data hash passed in by the form submission |
| 119 | + // unset these values since they are not part of the overall data hash |
| 120 | + $this->gateway_adapter->unsetHash(); |
| 121 | + unset( $localdata['data_hash'] ); |
122 | 122 | // compare the data hash to make sure it's legit |
123 | | - if ( $this->compare_hash( $data_hash, serialize( $data ) ) ) { |
124 | | - $data[ 'numAttempt' ] = $num_attempt; // reset the current num attempt |
125 | | - $data[ 'data_hash' ] = $this->generate_hash( serialize( $data ) ); // hash the data array |
| 123 | + if ( $this->compare_hash( $data_hash, serialize( $localdata ) ) ) { |
126 | 124 | |
| 125 | + $this->gateway_adapter->setHash( $this->generate_hash( $this->gateway_adapter->getData() ) ); // hash the data array |
127 | 126 | // check to see if we have a valid action set for us to bypass minfraud |
128 | 127 | $actions = array( 'process', 'challenge', 'review', 'reject' ); |
129 | | - $action_hash = $data[ 'action' ]; // a hash of the action to take passed in by the form submission |
| 128 | + $action_hash = $localdata['action']; // a hash of the action to take passed in by the form submission |
130 | 129 | foreach ( $actions as $action ) { |
131 | 130 | if ( $this->compare_hash( $action_hash, $action ) ) { |
132 | 131 | // set the action that should be taken |
133 | | - $pfp_gateway_object->action = $action; |
| 132 | + $this->gateway_adapter->action = $action; |
134 | 133 | return TRUE; |
135 | 134 | } |
136 | 135 | } |
137 | 136 | } else { |
138 | 137 | // log potential tampering |
139 | | - if ( $this->log_fh ) $this->log( $data[ 'contribution_tracking_id'], 'Data hash/action mismatch' ); |
| 138 | + if ( $this->log_fh ) |
| 139 | + $this->log( $localdata['contribution_tracking_id'], 'Data hash/action mismatch' ); |
140 | 140 | } |
141 | 141 | |
142 | 142 | return FALSE; |
— | — | @@ -147,7 +147,7 @@ |
148 | 148 | */ |
149 | 149 | public function get_ccfd() { |
150 | 150 | if ( !$this->ccfd ) { |
151 | | - $this->ccfd = new CreditCardFraudDetection; |
| 151 | + $this->ccfd = new CreditCardFraudDetection( &$this->gateway_adapter ); |
152 | 152 | } |
153 | 153 | return $this->ccfd; |
154 | 154 | } |
— | — | @@ -172,20 +172,20 @@ |
173 | 173 | ); |
174 | 174 | |
175 | 175 | // minfraud license key |
176 | | - $minfraud_array[ "license_key" ] = $this->minfraud_license_key; |
| 176 | + $minfraud_array["license_key"] = $this->minfraud_license_key; |
177 | 177 | |
178 | 178 | // user's IP address |
179 | | - $minfraud_array[ "i" ] = ( $wgDonationInterfaceTest ) ? '12.12.12.12' : wfGetIP(); |
| 179 | + $minfraud_array["i"] = ( $wgDonationInterfaceTest ) ? '12.12.12.12' : wfGetIP(); |
180 | 180 | |
181 | 181 | // user's user agent |
182 | 182 | global $wgRequest; |
183 | | - $minfraud_array[ "user_agent" ] = $wgRequest->getHeader( 'user-agent' ); |
| 183 | + $minfraud_array["user_agent"] = $wgRequest->getHeader( 'user-agent' ); |
184 | 184 | |
185 | 185 | // user's language |
186 | | - $minfraud_array[ 'accept_language' ] = $wgRequest->getHeader( 'accept-language' ); |
| 186 | + $minfraud_array['accept_language'] = $wgRequest->getHeader( 'accept-language' ); |
187 | 187 | |
188 | 188 | // fetch the array of country codes |
189 | | - $country_codes = PayflowProGateway::getCountries(); |
| 189 | + $country_codes = GatewayForm::getCountries(); |
190 | 190 | |
191 | 191 | // loop through the map and add pertinent values from $data to the hash |
192 | 192 | foreach ( $map as $key => $value ) { |
— | — | @@ -193,19 +193,19 @@ |
194 | 194 | // do some data processing to clean up values for minfraud |
195 | 195 | switch ( $key ) { |
196 | 196 | case "domain": // get just the domain from the email address |
197 | | - $newdata[ $value ] = substr( strstr( $data[ $value ], '@' ), 1 ); |
| 197 | + $newdata[$value] = substr( strstr( $data[$value], '@' ), 1 ); |
198 | 198 | break; |
199 | 199 | case "bin": // get just the first 6 digits from CC# |
200 | | - $newdata[ $value ] = substr( $data[ $value ], 0, 6 ); |
| 200 | + $newdata[$value] = substr( $data[$value], 0, 6 ); |
201 | 201 | break; |
202 | 202 | case "country": |
203 | | - $newdata[ $value ] = $country_codes[ $data[ $value ]]; |
| 203 | + $newdata[$value] = $country_codes[$data[$value]]; |
204 | 204 | break; |
205 | 205 | default: |
206 | | - $newdata[ $value ] = $data[ $value ]; |
| 206 | + $newdata[$value] = $data[$value]; |
207 | 207 | } |
208 | 208 | |
209 | | - $minfraud_array[ $key ] = $newdata[ $value ]; |
| 209 | + $minfraud_array[$key] = $newdata[$value]; |
210 | 210 | } |
211 | 211 | |
212 | 212 | return $minfraud_array; |
— | — | @@ -229,7 +229,7 @@ |
230 | 230 | * there is a value for a required field and if its length is > 0 |
231 | 231 | * |
232 | 232 | * @param array $minfraud_query which is the array you would pass to |
233 | | - * minfraud in a query |
| 233 | + * minfraud in a query |
234 | 234 | * @result bool |
235 | 235 | */ |
236 | 236 | public function validate_minfraud_query( array $minfraud_query ) { |
— | — | @@ -244,8 +244,8 @@ |
245 | 245 | ); |
246 | 246 | |
247 | 247 | foreach ( $reqd_fields as $reqd_field ) { |
248 | | - if ( !isset( $minfraud_query[ $reqd_field ] ) || |
249 | | - strlen( $minfraud_query[ $reqd_field ] ) < 1 ) { |
| 248 | + if ( !isset( $minfraud_query[$reqd_field] ) || |
| 249 | + strlen( $minfraud_query[$reqd_field] ) < 1 ) { |
250 | 250 | return FALSE; |
251 | 251 | } |
252 | 252 | } |
— | — | @@ -261,7 +261,7 @@ |
262 | 262 | * @param float risk score (returned from minFraud) |
263 | 263 | * @return array of actions to be taken |
264 | 264 | */ |
265 | | - public function determine_action( $risk_score ) { |
| 265 | + public function determine_action( $risk_score ) { |
266 | 266 | foreach ( $this->action_ranges as $action => $range ) { |
267 | 267 | if ( $risk_score >= $range[0] && $risk_score <= $range[1] ) { |
268 | 268 | return $action; |
— | — | @@ -269,14 +269,15 @@ |
270 | 270 | } |
271 | 271 | } |
272 | 272 | |
273 | | - static function onValidate( &$pfp_gateway_object, &$data ) { |
274 | | - return self::singleton()->validate( $pfp_gateway_object, $data ); |
| 273 | + static function onValidate( &$gateway_adapter ) { |
| 274 | + return self::singleton( &$gateway_adapter )->validate(); |
275 | 275 | } |
276 | 276 | |
277 | | - static function singleton() { |
| 277 | + static function singleton( &$gateway_adapter ) { |
278 | 278 | if ( !self::$instance ) { |
279 | | - self::$instance = new self; |
| 279 | + self::$instance = new self( &$gateway_adapter ); |
280 | 280 | } |
281 | 281 | return self::$instance; |
282 | 282 | } |
| 283 | + |
283 | 284 | } |
Index: branches/fundraising/extensions/DonationInterface/extras/minfraud/minfraud.php |
— | — | @@ -1,4 +1,5 @@ |
2 | 2 | <?php |
| 3 | + |
3 | 4 | /** |
4 | 5 | * Validates a transaction against MaxMind's minFraud service |
5 | 6 | * |
— | — | @@ -8,16 +9,15 @@ |
9 | 10 | * require_once( "$IP/extensions/DonationInterface/extras/minfraud/minfraud.php" ); |
10 | 11 | * |
11 | 12 | */ |
12 | | - |
13 | 13 | if ( !defined( 'MEDIAWIKI' ) ) { |
14 | | - die( "This file is part of the MinFraud for PayflowPro Gateway extension. It is not a valid entry point.\n" ); |
| 14 | + die( "This file is part of the MinFraud for Gateway extension. It is not a valid entry point.\n" ); |
15 | 15 | } |
16 | 16 | |
17 | | -$wgExtensionCredits['payflowprogateway_extras_minfraud'][] = array( |
| 17 | +$wgExtensionCredits['gateway_extras_minfraud'][] = array( |
18 | 18 | 'name' => 'minfraud', |
19 | 19 | 'author' => 'Arthur Richards', |
20 | 20 | 'url' => '', |
21 | | - 'description' => 'This extension uses the MaxMind minFraud service as a validator for the Payflow Pro gateway.' |
| 21 | + 'description' => 'This extension uses the MaxMind minFraud service as a validator for the gateway.' |
22 | 22 | ); |
23 | 23 | |
24 | 24 | /** |
— | — | @@ -32,9 +32,9 @@ |
33 | 33 | * The value for one of these keys is an array representing the lower |
34 | 34 | * and upper bounds for that action. For instance, |
35 | 35 | * $wgMinFraudActionRagnes = array( |
36 | | - * 'process' => array( 0, 100) |
37 | | - * ... |
38 | | - * ); |
| 36 | + * 'process' => array( 0, 100) |
| 37 | + * ... |
| 38 | + * ); |
39 | 39 | * means that any transaction with a risk score greather than or equal |
40 | 40 | * to 0 and less than or equal to 100 will be given the 'process' action. |
41 | 41 | * |
— | — | @@ -55,7 +55,7 @@ |
56 | 56 | * Define whether or not to run minFraud in stand alone mode |
57 | 57 | * |
58 | 58 | * If this is set to run in standalone, these scripts will be |
59 | | - * accessed directly via the "PayflowGatewayValidate" hook. |
| 59 | + * accessed directly via the "GatewayValidate" hook. |
60 | 60 | * You may not want to run this in standalone mode if you prefer |
61 | 61 | * to use this in conjunction with Custom Filters. This has the |
62 | 62 | * advantage of sharing minFraud info with other filters. |
— | — | @@ -63,12 +63,13 @@ |
64 | 64 | $wgMinFraudStandalone = TRUE; |
65 | 65 | |
66 | 66 | $dir = dirname( __FILE__ ) . "/"; |
67 | | -$wgAutoloadClasses['PayflowProGateway_Extras_MinFraud'] = $dir . "minfraud.body.php"; |
| 67 | +$wgAutoloadClasses['Gateway_Extras_MinFraud'] = $dir . "minfraud.body.php"; |
68 | 68 | |
69 | 69 | $wgExtensionFunctions[] = 'efMinFraudSetup'; |
70 | 70 | |
71 | 71 | function efMinFraudSetup() { |
72 | | - // if we're in standalone mode, use the PayflowGatewayValidate hook |
| 72 | + // if we're in standalone mode, use the GatewayValidate hook |
73 | 73 | global $wgMinFraudStandalone, $wgHooks; |
74 | | - if ( $wgMinFraudStandalone ) $wgHooks["PayflowGatewayValidate"][] = array( 'PayflowProGateway_Extras_MinFraud::onValidate' ); |
| 74 | + if ( $wgMinFraudStandalone ) |
| 75 | + $wgHooks["GatewayValidate"][] = array( 'Gateway_Extras_MinFraud::onValidate' ); |
75 | 76 | } |
Index: branches/fundraising/extensions/DonationInterface/extras/conversion_log/conversion_log.body.php |
— | — | @@ -1,39 +1,40 @@ |
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 | + return self::singleton( $gateway_adapter )->post_process(); |
32 | 32 | } |
33 | 33 | |
34 | | - static function singleton() { |
| 34 | + static function singleton( &$gateway_adapter ) { |
35 | 35 | if ( !self::$instance ) { |
36 | | - self::$instance = new self; |
| 36 | + self::$instance = new self( $gateway_adapter ); |
37 | 37 | } |
38 | 38 | return self::$instance; |
39 | 39 | } |
| 40 | + |
40 | 41 | } |
Index: branches/fundraising/extensions/DonationInterface/extras/conversion_log/conversion_log.php |
— | — | @@ -1,26 +1,26 @@ |
2 | 2 | <?php |
| 3 | + |
3 | 4 | /** |
4 | | - * Extra to log payflow response during post processing hook |
| 5 | + * Extra to log gateway response during post processing hook |
5 | 6 | * |
6 | 7 | * @fixme Class/file names should likely change to reflect change in purpose... |
7 | 8 | * |
8 | 9 | * To install: |
9 | 10 | * require_once( "$IP/extensions/DonationInterface/extras/conversion_log/conversion_log.php" |
10 | 11 | */ |
11 | | - |
12 | 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" ); |
| 13 | + die( "This file is part of the Conversion Log for Gateway extension. It is not a valid entry point.\n" ); |
14 | 14 | } |
15 | 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'" |
| 16 | +$wgExtensionCredits['gateway_extras_conversionLog'][] = array( |
| 17 | + 'name' => 'conversion log', |
| 18 | + 'author' => 'Arthur Richards', |
| 19 | + 'url' => '', |
| 20 | + 'description' => "This extension handles logging for Gateway extension 'extras'" |
21 | 21 | ); |
22 | 22 | |
23 | 23 | $dir = dirname( __FILE__ ) . "/"; |
24 | | -$wgAutoloadClasses['PayflowProGateway_Extras_ConversionLog'] = $dir . "conversion_log.body.php"; |
| 24 | +$wgAutoloadClasses['Gateway_Extras_ConversionLog'] = $dir . "conversion_log.body.php"; |
25 | 25 | |
26 | 26 | // Sets the 'conversion log' as logger for post-processing |
27 | | -$wgHooks["PayflowGatewayPostProcess"][] = array( "PayflowProGateway_Extras_ConversionLog::onPostProcess" ); |
| 27 | +$wgHooks["GatewayPostProcess"][] = array( "Gateway_Extras_ConversionLog::onPostProcess" ); |
Index: branches/fundraising/extensions/DonationInterface/extras/extras.body.php |
— | — | @@ -1,21 +1,38 @@ |
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->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 | |
| 25 | + function getGlobal( $varname ) { |
| 26 | + //basically, if the global is defined in the adapter, use the overridden value. |
| 27 | + //otherwise, grab the default. |
| 28 | + $ret = $this->gateway_adapter->getGlobal( $varname ); |
| 29 | + if ( empty( $ret ) ) { |
| 30 | + $globalname = 'wgDonationInterface' . $varname; |
| 31 | + global $$globalname; |
| 32 | + $ret = $$globalname; |
| 33 | + } |
| 34 | + return $ret; |
| 35 | + } |
| 36 | + |
20 | 37 | /** |
21 | 38 | * Prepare logging mechanism |
22 | 39 | * |
— | — | @@ -25,19 +42,16 @@ |
26 | 43 | * @param string path to log file |
27 | 44 | */ |
28 | 45 | protected function prepare_log_file( $log_file ) { |
29 | | - |
| 46 | + |
30 | 47 | if ( strtolower( $log_file ) == "syslog" ) { |
31 | 48 | |
32 | | - $this->log_fh = 'syslog'; |
33 | | - |
34 | | - } elseif( is_file( $log_file )) { |
35 | | - |
| 49 | + $this->log_fh = 'syslog'; |
| 50 | + } elseif ( is_file( $log_file ) ) { |
| 51 | + |
36 | 52 | $this->log_fh = fopen( $log_file, 'a+' ); |
37 | | - |
38 | 53 | } else { |
39 | 54 | |
40 | 55 | $this->log_fh = null; |
41 | | - |
42 | 56 | } |
43 | 57 | } |
44 | 58 | |
— | — | @@ -54,26 +68,20 @@ |
55 | 69 | echo "what log file?"; |
56 | 70 | return; |
57 | 71 | } |
58 | | - |
| 72 | + |
59 | 73 | // format the message |
60 | 74 | $msg = '"' . date( 'c' ) . '"'; |
61 | 75 | $msg .= "\t" . '"' . $id . '"'; |
62 | 76 | $msg .= "\t" . '"' . $status . '"'; |
63 | 77 | $msg .= "\t" . $data . "\n"; |
64 | | - |
| 78 | + |
65 | 79 | // write to the log |
66 | 80 | if ( $this->log_fh == 'syslog' ) { //use syslog facility |
67 | 81 | // replace tabs with spaces - maybe do this universally? cuz who needs tabs. |
68 | 82 | $msg = str_replace( "\t", " ", $msg ); |
69 | | - |
70 | | - openlog( "payflowpro_gateway_trxn", LOG_ODELAY, LOG_SYSLOG ); |
71 | | - syslog( $log_level, $msg ); |
72 | | - closelog(); |
73 | | - |
| 83 | + $this->gateway_adapter->log( $msg, $log_level, '_trxn' ); |
74 | 84 | } else { //write to file |
75 | | - |
76 | 85 | fwrite( $this->log_fh, $msg ); |
77 | | - |
78 | 86 | } |
79 | 87 | } |
80 | 88 | |
— | — | @@ -83,8 +91,8 @@ |
84 | 92 | * @return string The hash of the data |
85 | 93 | */ |
86 | 94 | public function generate_hash( $data ) { |
87 | | - global $wgPayflowProGatewaySalt; |
88 | | - return hash( "sha512", $wgPayflowProGatewaySalt . $data ); |
| 95 | + $salt = $this->getGlobal( 'Salt' ); |
| 96 | + return hash( "sha512", $salt . $data ); |
89 | 97 | } |
90 | 98 | |
91 | 99 | /** |
— | — | @@ -105,6 +113,8 @@ |
106 | 114 | * Close the open log file handler if it's open |
107 | 115 | */ |
108 | 116 | public function __destruct() { |
109 | | - if ( is_resource( $this->log_fh ) ) fclose( $this->log_fh ); |
| 117 | + if ( is_resource( $this->log_fh ) ) |
| 118 | + fclose( $this->log_fh ); |
110 | 119 | } |
| 120 | + |
111 | 121 | } |
Index: branches/fundraising/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: branches/fundraising/extensions/DonationInterface/extras/recaptcha/recaptcha.php |
— | — | @@ -1,20 +1,20 @@ |
2 | 2 | <?php |
| 3 | + |
3 | 4 | /** |
4 | 5 | * Extra to expose a recaptcha for 'challenged' transactions |
5 | 6 | * |
6 | 7 | * To install: |
7 | 8 | * require_once( "$IP/extensions/DonationInterface/extras/recaptcha/recaptcha.php" |
8 | 9 | */ |
9 | | - |
10 | 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" ); |
| 11 | + die( "This file is part of the ReCaptcha for Gateway extension. It is not a valid entry point.\n" ); |
12 | 12 | } |
13 | 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" |
| 14 | +$wgExtensionCredits['extras_recaptcha'][] = array( |
| 15 | + 'name' => 'reCaptcha', |
| 16 | + 'author' => 'Arthur Richards', |
| 17 | + 'url' => '', |
| 18 | + 'description' => "This extension exposes a reCpathca for 'challenged' transactions in the Gateway" |
19 | 19 | ); |
20 | 20 | |
21 | 21 | /** |
— | — | @@ -23,33 +23,33 @@ |
24 | 24 | * These can be obtained at: |
25 | 25 | * http://www.google.com/recaptcha/whyrecaptcha |
26 | 26 | */ |
27 | | -$wgPayflowRecaptchaPublicKey = ''; |
28 | | -$wgPayflowRecaptchaPrivateKey = ''; |
| 27 | +$wgDonationInterfaceRecaptchaPublicKey = ''; |
| 28 | +$wgDonationInterfaceRecaptchaPrivateKey = ''; |
29 | 29 | |
30 | 30 | // Timeout (in seconds) for communicating with reCatpcha |
31 | | -$wgPayflowRecaptchaTimeout = 2; |
| 31 | +$wgDonationInterfaceRecaptchaTimeout = 2; |
32 | 32 | |
33 | 33 | /** |
34 | 34 | * HTTP Proxy settings |
35 | 35 | * |
36 | | - * Default to settings in PayflowPro Gateway |
| 36 | + * Default to settings in DonationInterface |
37 | 37 | */ |
38 | | -$wgPayflowRecaptchaUseHTTPProxy = $wgPayflowProGatewayUseHTTPProxy; |
39 | | -$wgPayflowRecaptchaHTTPProxy = $wgPayflowProGatewayHTTPProxy; |
| 38 | +$wgDonationInterfaceRecaptchaUseHTTPProxy = $wgDonationInterfaceUseHTTPProxy; |
| 39 | +$wgDonationInterfaceRecaptchaHTTPProxy = $wgDonationInterfaceHTTPProxy; |
40 | 40 | |
41 | 41 | /** |
42 | 42 | * Use SSL to communicate with reCaptcha |
43 | 43 | */ |
44 | | -$wgPayflowRecaptchaUseSSL = 1; |
| 44 | +$wgDonationInterfaceRecaptchaUseSSL = 1; |
45 | 45 | |
46 | 46 | /** |
47 | 47 | * The # of times to retry communicating with reCaptcha if communication fails |
48 | 48 | * @var int |
49 | 49 | */ |
50 | | -$wgPayflowRecaptchaComsRetryLimit = 3; |
| 50 | +$wgDonationInterfaceRecaptchaComsRetryLimit = 3; |
51 | 51 | |
52 | 52 | $dir = dirname( __FILE__ ) . "/"; |
53 | | -$wgAutoloadClasses['PayflowProGateway_Extras_ReCaptcha'] = $dir . "recaptcha.body.php"; |
| 53 | +$wgAutoloadClasses['Gateway_Extras_ReCaptcha'] = $dir . "recaptcha.body.php"; |
54 | 54 | |
55 | 55 | // Set reCpatcha as plugin for 'challenge' action |
56 | | -$wgHooks["PayflowGatewayChallenge"][] = array( "PayflowProGateway_Extras_ReCaptcha::onChallenge" ); |
| 56 | +$wgHooks["GatewayChallenge"][] = array( "Gateway_Extras_ReCaptcha::onChallenge" ); |
Index: branches/fundraising/extensions/DonationInterface/extras/recaptcha/recaptcha.body.php |
— | — | @@ -3,7 +3,7 @@ |
4 | 4 | * Validates a transaction against MaxMind's minFraud service |
5 | 5 | */ |
6 | 6 | |
7 | | -class PayflowProGateway_Extras_reCaptcha extends PayflowProGateway_Extras { |
| 7 | +class Gateway_Extras_reCaptcha extends Gateway_Extras { |
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Container for singelton instance of self |
— | — | @@ -16,9 +16,19 @@ |
17 | 17 | */ |
18 | 18 | public $recap_err; |
19 | 19 | |
20 | | - public function __construct() { |
21 | | - parent::__construct(); |
22 | | - |
| 20 | + public function __construct( &$gateway_adapter ) { |
| 21 | + parent::__construct( &$gateway_adapter ); |
| 22 | + |
| 23 | + //stash all the vars that reCaptcha is going to need in a global just for it. |
| 24 | + //I know this is vaguely unpleasant, but it's the quickest way back to zero. |
| 25 | + global $wgReCaptchaConfData; |
| 26 | + $wgReCaptchaConfData['UseHTTPProxy'] = $this->getGlobal( 'RecaptchaUseHTTPProxy' ); |
| 27 | + $wgReCaptchaConfData['HTTPProxy'] = $this->getGlobal( 'RecaptchaHTTPProxy' ); |
| 28 | + $wgReCaptchaConfData['Timeout'] = $this->getGlobal( 'RecaptchaTimeout' ); |
| 29 | + $wgReCaptchaConfData['UseSSL'] = $this->getGlobal( 'RecaptchaUseSSL' ); |
| 30 | + $wgReCaptchaConfData['ComsRetryLimit'] = $this->getGlobal( 'RecaptchaComsRetryLimit' ); |
| 31 | + $wgReCaptchaConfData['GatewayClass'] = $this->gateway_adapter->getGatewayAdapterClass(); //for properly routing the logging |
| 32 | + |
23 | 33 | // load the reCaptcha API |
24 | 34 | require_once( dirname( __FILE__ ) . '/recaptcha-php/recaptchalib.php' ); |
25 | 35 | } |
— | — | @@ -26,44 +36,49 @@ |
27 | 37 | /** |
28 | 38 | * Handle the challenge logic |
29 | 39 | */ |
30 | | - public function challenge( &$pfp_gateway_object, &$data ) { |
| 40 | + public function challenge() { |
31 | 41 | // if captcha posted, validate |
32 | 42 | if ( isset( $_POST[ 'recaptcha_response_field' ] ) ) { |
33 | 43 | // check the captcha response |
34 | 44 | $captcha_resp = $this->check_captcha(); |
35 | 45 | if ( $captcha_resp->is_valid ) { |
36 | 46 | // if validated, update the action and move on |
37 | | - $this->log( $data[ 'contribution_tracking_id' ], 'Captcha passed' ); |
38 | | - $pfp_gateway_object->action = "process"; |
| 47 | + $this->log( $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'Captcha passed' ); |
| 48 | + $this->gateway_adapter->action = "process"; |
39 | 49 | return TRUE; |
40 | 50 | } else { |
41 | 51 | $this->recap_err = $captcha_resp->error; |
42 | | - $this->log( $data[ 'contribution_tracking_id' ], 'Captcha failed' ); |
| 52 | + $this->log( $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'Captcha failed' ); |
43 | 53 | } |
44 | 54 | } |
45 | 55 | // display captcha |
46 | | - $this->display_captcha( $pfp_gateway_object, $data ); |
| 56 | + $this->display_captcha(); |
47 | 57 | return TRUE; |
48 | 58 | } |
49 | 59 | |
50 | 60 | /** |
51 | 61 | * Display the submission form with the captcha injected into it |
52 | 62 | */ |
53 | | - public function display_captcha( &$pfp_gateway_object, &$data ) { |
54 | | - global $wgOut, $wgPayflowRecaptchaPublicKey, $wgPayflowRecaptchaUseSSL; |
| 63 | + public function display_captcha() { |
| 64 | + global $wgOut; |
| 65 | + $publicKey = $this->getGlobal( 'RecaptchaPublicKey' ); |
| 66 | + $useSSL = $this->getGlobal( 'RecaptchaUseSSL' ); |
55 | 67 | |
56 | 68 | // log that a captcha's been triggered |
57 | | - $this->log( $data[ 'contribution_tracking_id' ], 'Captcha triggered' ); |
| 69 | + $this->log( $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'Captcha triggered' ); |
58 | 70 | |
59 | 71 | // construct the HTML used to display the captcha |
60 | 72 | $captcha_html = Xml::openElement( 'div', array( 'id' => 'mw-donate-captcha' ) ); |
61 | | - $captcha_html .= recaptcha_get_html( $wgPayflowRecaptchaPublicKey, $this->recap_err, $wgPayflowRecaptchaUseSSL ); |
62 | | - $captcha_html .= '<span class="creditcard-error-msg">' . wfMsg( 'payflowpro_gateway-error-msg-captcha-please' ) . '</span>'; |
| 73 | + $captcha_html .= recaptcha_get_html( $publicKey, $this->recap_err, $useSSL ); |
| 74 | + $captcha_html .= '<span class="creditcard-error-msg">' . wfMsg( $this->gateway_adapter->getIdentifier() . '_gateway-error-msg-captcha-please' ) . '</span>'; |
63 | 75 | $captcha_html .= Xml::closeElement( 'div' ); // close div#mw-donate-captcha |
64 | 76 | |
65 | 77 | // load up the form class |
66 | | - $form_class = $pfp_gateway_object->getFormClass(); |
67 | | - $form_obj = new $form_class( $data, $pfp_gateway_object->errors ); |
| 78 | + $form_class = $this->gateway_adapter->getFormClass(); |
| 79 | + |
| 80 | + //hmm. Looking at this now, makes me want to say |
| 81 | + //TODO: Refactor the Form Class constructors. Again. |
| 82 | + $form_obj = new $form_class( $this->gateway_adapter->getData(), $this->gateway_adapter->getValidationErrors(), $this->gateway_adapter); |
68 | 83 | |
69 | 84 | // set the captcha HTML to use in the form |
70 | 85 | $form_obj->setCaptchaHTML( $captcha_html ); |
— | — | @@ -76,8 +91,9 @@ |
77 | 92 | * Check recaptcha answer |
78 | 93 | */ |
79 | 94 | public function check_captcha() { |
80 | | - global $wgPayflowRecaptchaPrivateKey, $wgRequest; |
81 | | - $resp = recaptcha_check_answer( $wgPayflowRecaptchaPrivateKey, |
| 95 | + global $wgRequest; |
| 96 | + $privateKey = $this->getGlobal( 'RecaptchaPrivateKey' ); |
| 97 | + $resp = recaptcha_check_answer( $privateKey, |
82 | 98 | wfGetIP(), |
83 | 99 | $wgRequest->getText( 'recaptcha_challenge_field' ), |
84 | 100 | $wgRequest->getText( 'recaptcha_response_field' ) ); |
— | — | @@ -85,13 +101,13 @@ |
86 | 102 | return $resp; |
87 | 103 | } |
88 | 104 | |
89 | | - static function onChallenge( &$pfp_gateway_object, &$data ) { |
90 | | - return self::singleton()->challenge( $pfp_gateway_object, $data ); |
| 105 | + static function onChallenge( &$gateway_adapter ) { |
| 106 | + return self::singleton( &$gateway_adapter )->challenge(); |
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 | } |
Index: branches/fundraising/extensions/DonationInterface/extras/extras.php |
— | — | @@ -1,29 +1,29 @@ |
2 | 2 | <?php |
| 3 | + |
3 | 4 | /** |
4 | | - * An abstract class and set up for payflowpro gateway 'extras' |
| 5 | + * An abstract class and set up for gateway 'extras' |
5 | 6 | * |
6 | 7 | * To install: |
7 | 8 | * require_once( "$IP/extensions/DonationInterface/extras/extras.php" |
8 | 9 | * Note: This should be specified in LocalSettings.php BEFORE requiring any of the other 'extras' |
9 | 10 | */ |
10 | | - |
11 | 11 | if ( !defined( 'MEDIAWIKI' ) ) { |
12 | | - die( "This file is part of PayflowPro Gateway extension. It is not a valid entry point.\n" ); |
| 12 | + die( "This file is part of Gateway extension. It is not a valid entry point.\n" ); |
13 | 13 | } |
14 | 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" |
| 15 | +$wgExtensionCredits['gateway_extras'][] = array( |
| 16 | + 'name' => 'extras', |
| 17 | + 'author' => 'Arthur Richards', |
| 18 | + 'url' => '', |
| 19 | + 'description' => "This extension handles some of the set up required for Gateway extras" |
20 | 20 | ); |
21 | 21 | |
22 | 22 | /** |
23 | | - * Full path to file to use for logging for Payflowpro Gateway scripts |
| 23 | + * Full path to file to use for logging for Gateway scripts |
24 | 24 | * |
25 | 25 | * Declare in LocalSettings.php |
26 | 26 | */ |
27 | | -$wgPayflowGatewayLog = ''; |
| 27 | +$wgDonationInterfaceExtrasLog = ''; |
28 | 28 | |
29 | 29 | $dir = dirname( __FILE__ ) . "/"; |
30 | | -$wgAutoloadClasses['PayflowProGateway_Extras'] = $dir . "extras.body.php"; |
\ No newline at end of file |
| 30 | +$wgAutoloadClasses['Gateway_Extras'] = $dir . "extras.body.php"; |
\ No newline at end of file |
Index: branches/fundraising/extensions/DonationInterface/gateway_forms/Form.php |
— | — | @@ -123,15 +123,6 @@ |
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
127 | | - * Fetch the array of iso country codes => country names |
128 | | - * @return array |
129 | | - */ |
130 | | - public function getCountries() { |
131 | | - require_once( dirname( __FILE__ ) . '/includes/countryCodes.inc' ); |
132 | | - return countryCodes(); |
133 | | - } |
134 | | - |
135 | | - /** |
136 | 127 | * Generate the menu select of countries |
137 | 128 | * @fixme It would be great if we could default the country to the user's locale |
138 | 129 | * @fixme We should also do a locale-based asort on the country dropdown |
— | — | @@ -142,7 +133,7 @@ |
143 | 134 | $country_options = ''; |
144 | 135 | |
145 | 136 | // create a new array of countries with potentially translated country names for alphabetizing later |
146 | | - foreach ( $this->getCountries() as $iso_value => $full_name ) { |
| 137 | + foreach ( GatewayForm::getCountries() as $iso_value => $full_name ) { |
147 | 138 | $countries[$iso_value] = wfMsg( 'payflowpro_gateway-country-dropdown-' . $iso_value ); |
148 | 139 | } |
149 | 140 | |
Index: branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect_resultswitcher.body.php |
— | — | @@ -160,7 +160,7 @@ |
161 | 161 | * @return array |
162 | 162 | */ |
163 | 163 | public function prepareStompTransaction( $data, $responseArray, $responseMsg ) { |
164 | | - $countries = $this->getCountries(); |
| 164 | + $countries = GatewayForm::getCountries(); |
165 | 165 | |
166 | 166 | $transaction = array( ); |
167 | 167 | |
Index: branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect_gateway.body.php |
— | — | @@ -85,8 +85,6 @@ |
86 | 86 | // The form was submitted and the payment method has been set |
87 | 87 | $this->adapter->log( "Form posted and payment method set." ); |
88 | 88 | |
89 | | - // increase the count of attempts |
90 | | - //++$data['numAttempt']; |
91 | 89 | // Check form for errors |
92 | 90 | |
93 | 91 | $options = array(); |
— | — | @@ -133,40 +131,9 @@ |
134 | 132 | throw new Exception( $message ); |
135 | 133 | } |
136 | 134 | |
137 | | -// self::log( $data[ 'order_id' ] . " Preparing to query MaxMind" ); |
138 | | -// wfRunHooks( 'PayflowGatewayValidate', array( &$this, &$data ) ); |
139 | | -// self::log( $data[ 'order_id' ] . ' Finished querying Maxmind' ); |
140 | | -// |
141 | | -// // if the transaction was flagged for review |
142 | | -// if ( $this->action == 'review' ) { |
143 | | -// // expose a hook for external handling of trxns flagged for review |
144 | | -// wfRunHooks( 'PayflowGatewayReview', array( &$this, &$data )); |
145 | | -// } |
146 | | -// |
147 | | -// // if the transaction was flagged to be 'challenged' |
148 | | -// if ( $this->action == 'challenge' ) { |
149 | | -// // expose a hook for external handling of trxns flagged for challenge (eg captcha) |
150 | | -// wfRunHooks( 'PayflowGatewayChallenge', array( &$this, &$data ) ); |
151 | | -// } |
152 | | -// |
153 | | -// // if the transaction was flagged for rejection |
154 | | -// if ( $this->action == 'reject' ) { |
155 | | -// // expose a hook for external handling of trxns flagged for rejection |
156 | | -// wfRunHooks( 'PayflowGatewayReject', array( &$this, &$data ) ); |
157 | | -// |
158 | | -// $this->fnPayflowDisplayDeclinedResults( '' ); |
159 | | -// $this->fnPayflowUnsetEditToken(); |
160 | | -// } |
161 | | -// |
162 | | -// // if the transaction was flagged for processing |
163 | | -// if ( $this->action == 'process' ) { |
164 | | -// // expose a hook for external handling of trxns ready for processing |
165 | | -// wfRunHooks( 'PayflowGatewayProcess', array( &$this, &$data ) ); |
166 | | -// $this->fnGlobalCollectProcessTransaction( $data, $payflow_data ); |
167 | | -// } |
168 | | -// |
169 | | -// // expose a hook for any post processing |
170 | | -// wfRunHooks( 'PayflowGatewayPostProcess', array( &$this, &$data ) ); |
| 135 | + |
| 136 | + //TODO: add all the hooks back in. |
| 137 | + |
171 | 138 | } |
172 | 139 | } else { |
173 | 140 | // Display form for the first time |
Index: branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php |
— | — | @@ -282,7 +282,8 @@ |
283 | 283 | } |
284 | 284 | |
285 | 285 | function processResponse( $response ) { |
286 | | - //TODO: Stuff. |
| 286 | + //set the transaction result message |
| 287 | + $this->setTransactionResult( "Response Status: " . $response['STATUSID'], 'txn_message' ); //TODO: Translate for GC. |
287 | 288 | } |
288 | 289 | |
289 | 290 | function defineStagedVars() { |
Index: branches/fundraising/extensions/DonationInterface/gateway_common/gateway.adapter.php |
— | — | @@ -97,6 +97,9 @@ |
98 | 98 | protected $postdatadefaults; |
99 | 99 | protected $xmlDoc; |
100 | 100 | protected $dataObj; |
| 101 | + protected $transaction_results; |
| 102 | + protected $form_class; |
| 103 | + protected $validation_errors; |
101 | 104 | |
102 | 105 | //ALL OF THESE need to be redefined in the children. Much voodoo depends on the accuracy of these constants. |
103 | 106 | const GATEWAY_NAME = 'Donation Gateway'; |
— | — | @@ -176,7 +179,11 @@ |
177 | 180 | if ( empty( $val ) ) { |
178 | 181 | return $this->postdata; |
179 | 182 | } else { |
180 | | - return $this->postdata[$val]; |
| 183 | + if ( array_key_exists( $val, $this->postdata ) ) { |
| 184 | + return $this->postdata[$val]; |
| 185 | + } else { |
| 186 | + return null; |
| 187 | + } |
181 | 188 | } |
182 | 189 | } |
183 | 190 | |
— | — | @@ -324,12 +331,13 @@ |
325 | 332 | function do_transaction( $transaction ) { |
326 | 333 | $this->currentTransaction( $transaction ); |
327 | 334 | //update the contribution tracking data |
| 335 | + $this->incrementNumAttempt(); |
328 | 336 | $this->dataObj->updateContributionTracking( defined( 'OWA' ) ); |
329 | 337 | if ( $this->getCommunicationType() === 'xml' ) { |
330 | 338 | $this->getStopwatch( "buildRequestXML" ); |
331 | 339 | $xml = $this->buildRequestXML(); |
332 | 340 | $this->saveCommunicationStats( "buildRequestXML", $transaction ); |
333 | | - $returned = $this->curl_transaction( $xml ); |
| 341 | + $txn_ok = $this->curl_transaction( $xml ); |
334 | 342 | //put the response in a universal form, and return it. |
335 | 343 | } |
336 | 344 | |
— | — | @@ -339,37 +347,45 @@ |
340 | 348 | $this->getStopwatch( "buildRequestNameValueString" ); |
341 | 349 | $namevalstring = $this->buildRequestNameValueString(); |
342 | 350 | $this->saveCommunicationStats( "buildRequestNameValueString", $transaction ); |
343 | | - $returned = $this->curl_transaction( $namevalstring ); |
| 351 | + $txn_ok = $this->curl_transaction( $namevalstring ); |
344 | 352 | //put the response in a universal form, and return it. |
345 | 353 | } |
346 | 354 | |
347 | | - self::log( "RETURNED FROM CURL:" . print_r( $returned, true ) ); |
348 | | - if ( $returned['result'] === false ) { //couldn't make contact. Bail. |
349 | | - return $returned; |
| 355 | + if ( $txn_ok === false ) { //nothing to process, so we have to build it manually |
| 356 | + self::log( "Transaction Communication failed" . print_r( $this->getTransactionAllResults(), true ) ); |
| 357 | + return array( |
| 358 | + 'status' => false, |
| 359 | + 'message' => "$transaction Communication Failed!", |
| 360 | + 'errors' => array( |
| 361 | + '1000000' => 'communication failure' //...stupid code. |
| 362 | + ), |
| 363 | + ); |
350 | 364 | } |
351 | 365 | |
352 | | - //get the status of the response |
353 | | - $formatted = $this->getFormattedResponse( $returned['result'] ); |
354 | | - $returned['status'] = $this->getResponseStatus( $formatted ); |
| 366 | + self::log( "RETURNED FROM CURL:" . print_r( $this->getTransactionAllResults(), true ) ); |
355 | 367 | |
356 | | - //get errors |
357 | | - $returned['errors'] = $this->getResponseErrors( $formatted ); |
| 368 | + //set the status of the response |
| 369 | + $formatted = $this->getFormattedResponse( $this->getTransactionRawResponse() ); |
| 370 | + $this->setTransactionResult( $this->getResponseStatus( $formatted ), 'status' ); |
358 | 371 | |
| 372 | + //set errors |
| 373 | + $this->setTransactionResult( $this->getResponseErrors( $formatted ), 'errors' ); |
| 374 | + |
359 | 375 | //if we're still okay (hey, even if we're not), get relevent dataz. |
360 | | - $returned['data'] = $this->getResponseData( $formatted ); |
| 376 | + $this->setTransactionResult( $this->getResponseData( $formatted ), 'data' ); |
361 | 377 | |
362 | | - $this->processResponse( $returned ); |
| 378 | + $this->processResponse( $formatted ); |
363 | 379 | |
364 | 380 | //TODO: Actually pull these from somewhere legit. |
365 | | - if ( $returned['status'] === true ) { |
366 | | - $returned['message'] = "$transaction Transaction Successful!"; |
367 | | - } elseif ( $returned['status'] === false ) { |
368 | | - $returned['message'] = "$transaction Transaction FAILED!"; |
| 381 | + if ( $this->getTransactionStatus() === true ) { |
| 382 | + $this->setTransactionResult( "$transaction Transaction Successful!", 'message' ); |
| 383 | + } elseif ( $this->getTransactionStatus() === false ) { |
| 384 | + $this->setTransactionResult( "$transaction Transaction FAILED!", 'message' ); |
369 | 385 | } else { |
370 | | - $returned['message'] = "$transaction Transaction... weird. I have no idea what happened there."; |
| 386 | + $this->setTransactionResult( "$transaction Transaction... weird. I have no idea what happened there.", 'message' ); |
371 | 387 | } |
372 | 388 | |
373 | | - return $returned; |
| 389 | + return $this->getTransactionAllResults(); |
374 | 390 | |
375 | 391 | //speaking of universal form: |
376 | 392 | //$result['status'] = something I wish could be boiled down to a bool, but that's way too optimistic, I think. |
— | — | @@ -398,7 +414,7 @@ |
399 | 415 | // set proxy settings if necessary |
400 | 416 | if ( self::getGlobal( 'UseHTTPProxy' ) ) { |
401 | 417 | $opts[CURLOPT_HTTPPROXYTUNNEL] = 1; |
402 | | - $opts[CURLOPT_PROXY] = self::getGlobal( 'UseHTTPProxy' ); |
| 418 | + $opts[CURLOPT_PROXY] = self::getGlobal( 'HTTPProxy' ); |
403 | 419 | } |
404 | 420 | return $opts; |
405 | 421 | } |
— | — | @@ -455,38 +471,39 @@ |
456 | 472 | // in case there is a general network issue |
457 | 473 | $i = 1; |
458 | 474 | |
459 | | - $return = array( ); |
| 475 | + $results = array( ); |
460 | 476 | |
461 | 477 | while ( $i++ <= 3 ) { |
462 | 478 | self::log( $this->postdatadefaults['order_id'] . ' Preparing to send transaction to ' . self::getGatewayName() ); |
463 | | - $return['result'] = curl_exec( $ch ); |
464 | | - $return['headers'] = curl_getinfo( $ch ); |
| 479 | + $results['result'] = curl_exec( $ch ); |
| 480 | + $results['headers'] = curl_getinfo( $ch ); |
465 | 481 | |
466 | | - if ( $return['headers']['http_code'] != 200 && $return['headers']['http_code'] != 403 ) { |
| 482 | + if ( $results['headers']['http_code'] != 200 && $results['headers']['http_code'] != 403 ) { |
467 | 483 | self::log( $this->postdatadefaults['order_id'] . ' Failed sending transaction to ' . self::getGatewayName() . ', retrying' ); |
468 | 484 | sleep( 1 ); |
469 | | - } elseif ( $return['headers']['http_code'] == 200 || $return['headers']['http_code'] == 403 ) { |
| 485 | + } elseif ( $results['headers']['http_code'] == 200 || $results['headers']['http_code'] == 403 ) { |
470 | 486 | self::log( $this->postdatadefaults['order_id'] . ' Finished sending transaction to ' . self::getGatewayName() ); |
471 | 487 | break; |
472 | 488 | } |
473 | 489 | } |
474 | 490 | |
475 | | - $this->saveCommunicationStats( __FUNCTION__, $this->currentTransaction(), "Request:" . print_r( $data, true ) . "\nResponse" . print_r( $return, true ) ); |
| 491 | + $this->saveCommunicationStats( __FUNCTION__, $this->currentTransaction(), "Request:" . print_r( $data, true ) . "\nResponse" . print_r( $results, true ) ); |
476 | 492 | |
477 | | - if ( $return['headers']['http_code'] != 200 ) { |
478 | | - $return['result'] = false; |
| 493 | + if ( $results['headers']['http_code'] != 200 ) { |
| 494 | + $results['result'] = false; |
479 | 495 | //TODO: i18n here! |
480 | 496 | //TODO: But also, fire off some kind of "No response from the gateway" thing to somebody so we know right away. |
481 | | - $return['message'] = 'No response from ' . self::getGatewayName() . '. Please try again later!'; |
| 497 | + $results['message'] = 'No response from ' . self::getGatewayName() . '. Please try again later!'; |
482 | 498 | $when = time(); |
483 | 499 | self::log( $this->postdatadefaults['order_id'] . ' No response from ' . self::getGatewayName() . ': ' . curl_error( $ch ) ); |
484 | 500 | curl_close( $ch ); |
485 | | - return $return; |
| 501 | + return false; |
486 | 502 | } |
487 | 503 | |
488 | 504 | curl_close( $ch ); |
489 | 505 | |
490 | | - return $return; |
| 506 | + $this->setTransactionResult( $results ); |
| 507 | + return true; |
491 | 508 | } |
492 | 509 | |
493 | 510 | function stripXMLResponseHeaders( $rawResponse ) { |
— | — | @@ -499,16 +516,18 @@ |
500 | 517 | return false; |
501 | 518 | } |
502 | 519 | $justXML = substr( $rawResponse, $xmlStart ); |
| 520 | + $this->setTransactionResult( $justXML, 'unparsed_data' ); |
503 | 521 | return $justXML; |
504 | 522 | } |
505 | 523 | |
506 | 524 | function stripNameValueResponseHeaders( $rawResponse ) { |
507 | 525 | $result = strstr( $rawResponse, 'RESULT' ); |
| 526 | + $this->setTransactionResult( $result, 'unparsed_data' ); |
508 | 527 | return $result; |
509 | 528 | } |
510 | 529 | |
511 | | - public static function log( $msg, $log_level=LOG_INFO ) { |
512 | | - $identifier = self::getIdentifier() . "_gateway"; |
| 530 | + public static function log( $msg, $log_level=LOG_INFO, $log_id_suffix = '' ) { |
| 531 | + $identifier = self::getIdentifier() . "_gateway" . $log_id_suffix; |
513 | 532 | |
514 | 533 | // if we're not using the syslog facility, use wfDebugLog |
515 | 534 | if ( !self::getGlobal( 'UseSyslog' ) ) { |
— | — | @@ -817,4 +836,101 @@ |
818 | 837 | |
819 | 838 | $this->transaction_type = $transaction_type; |
820 | 839 | } |
| 840 | + |
| 841 | + public function getTransactionAllResults() { |
| 842 | + if ( !empty( $this->transaction_results ) && is_array( $this->transaction_results ) ) { |
| 843 | + return $this->transaction_results; |
| 844 | + } else { |
| 845 | + return false; |
| 846 | + } |
| 847 | + } |
| 848 | + |
| 849 | + public function setTransactionResult( $value, $key = false ) { |
| 850 | + if ( $key === false ) { |
| 851 | + $this->transaction_results = $value; |
| 852 | + } else { |
| 853 | + $this->transaction_results[$key] = $value; |
| 854 | + } |
| 855 | + } |
| 856 | + |
| 857 | + public function getTransactionRawResponse() { |
| 858 | + if ( array_key_exists( 'result', $this->transaction_results ) ) { |
| 859 | + return $this->transaction_results['result']; |
| 860 | + } else { |
| 861 | + return false; |
| 862 | + } |
| 863 | + } |
| 864 | + |
| 865 | + public function getTransactionStatus() { |
| 866 | + if ( array_key_exists( 'status', $this->transaction_results ) ) { |
| 867 | + return $this->transaction_results['status']; |
| 868 | + } else { |
| 869 | + return false; |
| 870 | + } |
| 871 | + } |
| 872 | + |
| 873 | + public function getTransactionMessage() { |
| 874 | + if ( array_key_exists( 'txn_message', $this->transaction_results ) ) { |
| 875 | + return $this->transaction_results['txn_message']; |
| 876 | + } else { |
| 877 | + return false; |
| 878 | + } |
| 879 | + } |
| 880 | + |
| 881 | + public function getTransactionData() { //this is the FORMATTED data returned from the reply. |
| 882 | + if ( array_key_exists( 'data', $this->transaction_results ) ) { |
| 883 | + return $this->transaction_results['data']; |
| 884 | + } else { |
| 885 | + return false; |
| 886 | + } |
| 887 | + } |
| 888 | + |
| 889 | + public function setFormClass( $formClassName ) { |
| 890 | + //I'm adding this because Captcha needs it, and we're gonna fire the hook inside. Nothing else really needs it as far as I know. |
| 891 | + $this->form_class = $formClassName; |
| 892 | + } |
| 893 | + |
| 894 | + public function getFormClass() { |
| 895 | + if ( isset( $this->form_class ) && class_exists( $this->form_class ) ) { |
| 896 | + return $this->form_class; |
| 897 | + } else { |
| 898 | + return false; |
| 899 | + } |
| 900 | + } |
| 901 | + |
| 902 | + public function getGatewayAdapterClass() { |
| 903 | + return get_called_class(); |
| 904 | + } |
| 905 | + |
| 906 | + public function setValidationErrors( $errors ) { |
| 907 | + $this->validation_errors = $errors; |
| 908 | + } |
| 909 | + |
| 910 | + public function getValidationErrors() { |
| 911 | + if ( !empty( $this->validation_errors ) ) { |
| 912 | + return $this->validation_errors; |
| 913 | + } else { |
| 914 | + return false; |
| 915 | + } |
| 916 | + } |
| 917 | + |
| 918 | + public function incrementNumAttempt() { |
| 919 | + $this->dataObj->incrementNumAttempt(); |
| 920 | + } |
| 921 | + |
| 922 | + public function setHash( $hashval ) { |
| 923 | + $this->dataObj->setVal( 'data_hash', $hashval ); |
| 924 | + } |
| 925 | + |
| 926 | + public function unsetHash() { |
| 927 | + $this->dataObj->expunge( 'data_hash' ); |
| 928 | + } |
| 929 | + |
| 930 | + public function setActionHash( $hashval ) { |
| 931 | + $this->dataObj->setVal( 'action', $hashval ); |
| 932 | + } |
| 933 | + |
| 934 | + public function unsetActionHash() { |
| 935 | + $this->dataObj->expunge( 'action' ); |
| 936 | + } |
821 | 937 | } |
Index: branches/fundraising/extensions/DonationInterface/gateway_common/DonationData.php |
— | — | @@ -769,6 +769,31 @@ |
770 | 770 | $this->normalizeAndSanitize(); |
771 | 771 | } |
772 | 772 | |
| 773 | + public function incrementNumAttempt() { |
| 774 | + if ( $this->isSomething( 'numAttempt' ) ) { |
| 775 | + $attempts = $this->getVal( 'numAttempt' ); |
| 776 | + if ( is_numeric( $attempts ) ) { |
| 777 | + $this->setVal( 'numAttempt', $attempts + 1 ); |
| 778 | + } else { |
| 779 | + //assume garbage = 0, so... |
| 780 | + $this->setVal( 'numAttempt', 1 ); |
| 781 | + } |
| 782 | + } |
| 783 | + } |
| 784 | + |
| 785 | + public function decrementNumAttempt() { |
| 786 | + //minfraud... |
| 787 | + if ( $this->isSomething( 'numAttempt' ) ) { |
| 788 | + $attempts = $this->getVal( 'numAttempt' ); |
| 789 | + if ( is_numeric( $attempts ) ) { |
| 790 | + $this->setVal( 'numAttempt', $attempts - 1 ); |
| 791 | + } else { |
| 792 | + //I guess... |
| 793 | + $this->setVal( 'numAttempt', 0 ); |
| 794 | + } |
| 795 | + } |
| 796 | + } |
| 797 | + |
773 | 798 | } |
774 | 799 | |
775 | 800 | ?> |
Index: branches/fundraising/extensions/DonationInterface/gateway_common/GatewayForm.php |
— | — | @@ -29,6 +29,7 @@ |
30 | 30 | * @var array |
31 | 31 | */ |
32 | 32 | public $errors = array( ); |
| 33 | + public $adapter; //the adapter goes here. |
33 | 34 | |
34 | 35 | /** |
35 | 36 | * The form is assumed to be successful. Errors in the form must set this to |
— | — | @@ -113,6 +114,7 @@ |
114 | 115 | //$error[ 'card_num' ] = wfMsg( $gateway_identifier . '_gateway-error-msg-card-num' ); |
115 | 116 | } |
116 | 117 | |
| 118 | + $this->adapter->setValidationErrors( $error ); |
117 | 119 | return $error_result; |
118 | 120 | } |
119 | 121 | |
— | — | @@ -393,6 +395,9 @@ |
394 | 396 | } |
395 | 397 | } |
396 | 398 | $this->form_class = $class_name; |
| 399 | + |
| 400 | + //this should... maybe replace the other thing? I need it in the adapter so reCaptcha can get to it. |
| 401 | + $this->adapter->setFormClass( $class_name ); |
397 | 402 | } |
398 | 403 | |
399 | 404 | /** |
— | — | @@ -570,6 +575,16 @@ |
571 | 576 | // submit the data to the paypal redirect URL |
572 | 577 | $wgOut->redirect( $this->adapter->getPaypalRedirectURL() ); |
573 | 578 | } |
| 579 | + |
| 580 | + |
| 581 | + /** |
| 582 | + * Fetch the array of iso country codes => country names |
| 583 | + * @return array |
| 584 | + */ |
| 585 | + public static function getCountries() { |
| 586 | + require_once( dirname( __FILE__ ) . '/../gateway_forms/includes/countryCodes.inc' ); |
| 587 | + return countryCodes(); |
| 588 | + } |
574 | 589 | |
575 | 590 | /** |
576 | 591 | * Get validate form result |
— | — | @@ -593,4 +608,4 @@ |
594 | 609 | |
595 | 610 | } |
596 | 611 | |
597 | | -//end of GatewayForm class definiton |
\ No newline at end of file |
| 612 | +//end of GatewayForm class definiton |