Index: trunk/extensions/DonationInterface/donationinterface.php |
— | — | @@ -70,6 +70,7 @@ |
71 | 71 | |
72 | 72 | //and at least one of them is a custom filter. |
73 | 73 | $optionalParts['CustomFilters'] = true; |
| 74 | + $wgDonationInterfaceEnableCustomFilters = true; //override this for specific gateways to disable |
74 | 75 | } |
75 | 76 | } |
76 | 77 | |
— | — | @@ -363,7 +364,7 @@ |
364 | 365 | * These are evauluated on a >= or <= basis. Please refer to minFraud |
365 | 366 | * documentation for a thorough explanation of the 'riskScore'. |
366 | 367 | */ |
367 | | - $wgMinFraudActionRanges = array( |
| 368 | + $wgDonationInterfaceMinFraudActionRanges = array( |
368 | 369 | 'process' => array( 0, 100 ), |
369 | 370 | 'review' => array( -1, -1 ), |
370 | 371 | 'challenge' => array( -1, -1 ), |
— | — | @@ -393,12 +394,12 @@ |
394 | 395 | |
395 | 396 | //Referrer Filter globals |
396 | 397 | if ( $optionalParts['ReferrerFilter'] === true ){ |
397 | | - $wgCustomFiltersRefRules = array( ); |
| 398 | + $wgDonationInterfaceCustomFiltersRefRules = array( ); |
398 | 399 | } |
399 | 400 | |
400 | 401 | //Source Filter globals |
401 | 402 | if ( $optionalParts['SourceFilter'] === true ){ |
402 | | - $wgCustomFiltersSrcRules = array( ); |
| 403 | + $wgDonationInterfaceCustomFiltersSrcRules = array( ); |
403 | 404 | } |
404 | 405 | |
405 | 406 | //Recaptcha globals |
Index: trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php |
— | — | @@ -51,11 +51,11 @@ |
52 | 52 | $result = $this->adapter->do_transaction( 'Card' ); |
53 | 53 | |
54 | 54 | // if the transaction was flagged for rejection |
55 | | - if ( $this->adapter->action == 'reject' ) { |
| 55 | + if ( $this->adapter->getValidationAction() == 'reject' ) { |
56 | 56 | $this->fnPayflowDisplayDeclinedResults( '' ); |
57 | 57 | } |
58 | 58 | |
59 | | - if ( $this->adapter->action == 'process' ) { |
| 59 | + if ( $this->adapter->getValidationAction() == 'process' ) { |
60 | 60 | $this->fnPayflowDisplayResults( $result ); |
61 | 61 | } |
62 | 62 | $this->displayResultsForDebug( $result ); |
Index: trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro.adapter.php |
— | — | @@ -78,8 +78,6 @@ |
79 | 79 | 'TENDER' => 'C', |
80 | 80 | 'VERBOSITY' => 'MEDIUM', |
81 | 81 | ), |
82 | | - 'do_validation' => true, |
83 | | - 'do_processhooks' => true, |
84 | 82 | ); |
85 | 83 | } |
86 | 84 | |
— | — | @@ -208,7 +206,9 @@ |
209 | 207 | function processResponse( $response ) { |
210 | 208 | //set the transaction result message |
211 | 209 | $this->setTransactionResult( $response['RESPMSG'], 'txn_message' ); |
212 | | - $this->setTransactionResult( $response['PNREF'], 'gateway_txn_id' ); |
| 210 | + if ( isset( $response['PNREF'] ) ){ |
| 211 | + $this->setTransactionResult( $response['PNREF'], 'gateway_txn_id' ); |
| 212 | + } |
213 | 213 | } |
214 | 214 | |
215 | 215 | function defineStagedVars() { |
— | — | @@ -233,5 +233,13 @@ |
234 | 234 | } |
235 | 235 | } |
236 | 236 | } |
| 237 | + |
| 238 | + protected function pre_process_card(){ |
| 239 | + $this->runPreProcessHooks(); |
| 240 | + } |
| 241 | + |
| 242 | + protected function post_process_card(){ |
| 243 | + $this->runPostProcessHooks(); |
| 244 | + } |
237 | 245 | |
238 | 246 | } |
Index: trunk/extensions/DonationInterface/extras/custom_filters/custom_filters.body.php |
— | — | @@ -55,14 +55,18 @@ |
56 | 56 | public function validate() { |
57 | 57 | // expose a hook for custom filters |
58 | 58 | wfRunHooks( 'GatewayCustomFilter', array( &$this->gateway_adapter, &$this ) ); |
59 | | - $this->gateway_adapter->action = $this->determineAction(); |
| 59 | + $localAction = $this->determineAction(); |
| 60 | + $this->gateway_adapter->setValidationAction( $localAction ); |
60 | 61 | |
61 | | - $log_msg = '"' . $this->gateway_adapter->action . "\"\t\"" . $this->risk_score . "\""; |
| 62 | + $log_msg = '"' . $localAction . "\"\t\"" . $this->risk_score . "\""; |
62 | 63 | $this->log( $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'Filtered', $log_msg ); |
63 | 64 | return TRUE; |
64 | 65 | } |
65 | 66 | |
66 | 67 | static function onValidate( &$gateway_adapter ) { |
| 68 | + if ( !$gateway_adapter->getGlobal( 'EnableCustomFilters' ) ){ |
| 69 | + return true; |
| 70 | + } |
67 | 71 | $gateway_adapter->debugarray[] = 'custom filters onValidate hook!'; |
68 | 72 | return self::singleton( $gateway_adapter )->validate(); |
69 | 73 | } |
Index: trunk/extensions/DonationInterface/extras/custom_filters/filters/source/source.body.php |
— | — | @@ -24,8 +24,8 @@ |
25 | 25 | $source = $this->gateway_adapter->getData( 'utm_source' ); |
26 | 26 | |
27 | 27 | // a very complex filtering algorithm for sources |
28 | | - global $wgCustomFiltersSrcRules; |
29 | | - foreach ( $wgCustomFiltersSrcRules as $regex => $risk_score_modifier ) { |
| 28 | + $srcRules = $this->gateway_adapter->getGlobal( 'CustomFiltersSrcRules' ); |
| 29 | + foreach ( $srcRules as $regex => $risk_score_modifier ) { |
30 | 30 | /** |
31 | 31 | * Note that regex pattern does not include delimiters. |
32 | 32 | * These will need to be included in your custom regex patterns. |
— | — | @@ -47,6 +47,9 @@ |
48 | 48 | } |
49 | 49 | |
50 | 50 | static function onFilter( &$gateway_adapter, &$custom_filter_object ) { |
| 51 | + if ( !$gateway_adapter->getGlobal( 'EnableSourceFilter' ) ){ |
| 52 | + return true; |
| 53 | + } |
51 | 54 | $gateway_adapter->debugarray[] = 'source onFilter hook!'; |
52 | 55 | return self::singleton( $gateway_adapter, $custom_filter_object )->filter(); |
53 | 56 | } |
Index: trunk/extensions/DonationInterface/extras/custom_filters/filters/minfraud/minfraud.body.php |
— | — | @@ -13,22 +13,25 @@ |
14 | 14 | |
15 | 15 | public function filter( &$custom_filter_object ) { |
16 | 16 | // see if we can bypass minfraud |
17 | | - if ( $this->can_bypass_minfraud() ) |
| 17 | + if ( $this->can_bypass_minfraud() ){ |
18 | 18 | return TRUE; |
| 19 | + } |
19 | 20 | |
20 | 21 | $minfraud_query = $this->build_query( $this->gateway_adapter->getData() ); |
21 | 22 | $this->query_minfraud( $minfraud_query ); |
22 | | - $this->gateway_adapter->action = 'Filter'; |
| 23 | + |
23 | 24 | |
24 | 25 | $custom_filter_object->risk_score += $this->minfraud_response['riskScore']; |
25 | 26 | |
26 | 27 | // Write the query/response to the log |
27 | | - // @fixme this will cause the 'action' to be logged even though it's premature here |
28 | | - $this->log_query( $minfraud_query ); |
| 28 | + $this->log_query( $minfraud_query, '' ); |
29 | 29 | return TRUE; |
30 | 30 | } |
31 | 31 | |
32 | | - static function onFilter( &$gateway_adapter, &$custom_filter_object ) { |
| 32 | + static function onFilter( &$gateway_adapter, &$custom_filter_object ) { |
| 33 | + if ( !$gateway_adapter->getGlobal( 'EnableMinfraud_as_filter' ) ){ |
| 34 | + return true; |
| 35 | + } |
33 | 36 | $gateway_adapter->debugarray[] = 'minfraud onFilter hook!'; |
34 | 37 | return self::singleton( $gateway_adapter )->filter( $custom_filter_object ); |
35 | 38 | } |
Index: trunk/extensions/DonationInterface/extras/custom_filters/filters/minfraud/minfraud.php |
— | — | @@ -10,7 +10,7 @@ |
11 | 11 | * |
12 | 12 | * This inherits minFraud settings form the main minFraud extension. To make |
13 | 13 | * transactions run through minFraud outside of custom filters, set |
14 | | - * $wgMinFraudStandalone = TRUE |
| 14 | + * $wgDonationInterfaceEnableMinfraud = TRUE |
15 | 15 | * |
16 | 16 | * To install: |
17 | 17 | * require_once( "$IP/extensions/DonationInterface/extras/custom_filters/filters/minfraud.php" ); |
— | — | @@ -41,7 +41,7 @@ |
42 | 42 | */ |
43 | 43 | |
44 | 44 | function efCustomFiltersMinFraudSetup() { |
45 | | - global $wgMinFraudStandalone, $wgHooks; |
46 | | - if ( !$wgMinFraudStandalone ) |
| 45 | + global $wgDonationInterfaceEnableMinfraud, $wgHooks; |
| 46 | + if ( !$wgDonationInterfaceEnableMinfraud ) |
47 | 47 | $wgHooks['GatewayCustomFilter'][] = array( "Gateway_Extras_CustomFilters_MinFraud::onFilter" ); |
48 | 48 | } |
Index: trunk/extensions/DonationInterface/extras/custom_filters/filters/referrer/referrer.body.php |
— | — | @@ -24,8 +24,8 @@ |
25 | 25 | $referrer = $this->gateway_adapter->getData( 'referrer' ); |
26 | 26 | |
27 | 27 | // a very complex filtering algorithm for referrers |
28 | | - global $wgCustomFiltersRefRules; |
29 | | - foreach ( $wgCustomFiltersRefRules as $regex => $risk_score_modifier ) { |
| 28 | + $refRules = $this->gateway_adapter->getGlobal( 'CustomFiltersRefRules' ); |
| 29 | + foreach ( $refRules as $regex => $risk_score_modifier ) { |
30 | 30 | /** |
31 | 31 | * note that the regex pattern does NOT include delimiters. |
32 | 32 | * these will need to be included in your custom regex patterns. |
— | — | @@ -47,6 +47,9 @@ |
48 | 48 | } |
49 | 49 | |
50 | 50 | static function onFilter( &$gateway_adapter, &$custom_filter_object ) { |
| 51 | + if ( !$gateway_adapter->getGlobal( 'EnableReferrerFilter' ) ){ |
| 52 | + return true; |
| 53 | + } |
51 | 54 | $gateway_adapter->debugarray[] = 'referrer onFilter hook!'; |
52 | 55 | return self::singleton( $gateway_adapter, $custom_filter_object )->filter(); |
53 | 56 | } |
Index: trunk/extensions/DonationInterface/extras/minfraud/minfraud.body.php |
— | — | @@ -17,7 +17,7 @@ |
18 | 18 | /** |
19 | 19 | * User-definable riskScore ranges for actions to take |
20 | 20 | * |
21 | | - * Overload with $wgMinFraudActionRanges |
| 21 | + * Overload with $wgDonationInterfaceMinFraudActionRanges |
22 | 22 | * @var public array |
23 | 23 | */ |
24 | 24 | public $action_ranges = array( |
— | — | @@ -42,16 +42,17 @@ |
43 | 43 | parent::__construct( $gateway_adapter ); |
44 | 44 | $dir = dirname( __FILE__ ) . '/'; |
45 | 45 | require_once( $dir . "ccfd/CreditCardFraudDetection.php" ); |
46 | | - global $wgMinFraudLicenseKey, $wgMinFraudActionRanges; |
| 46 | + global $wgMinFraudLicenseKey; |
47 | 47 | |
48 | 48 | // set the minfraud license key, go no further if we don't have it |
49 | 49 | if ( !$license_key && !$wgMinFraudLicenseKey ) { |
50 | 50 | throw new MWException( "minFraud license key required but not present." ); |
51 | 51 | } |
52 | 52 | $this->minfraud_license_key = ( $license_key ) ? $license_key : $wgMinFraudLicenseKey; |
53 | | - |
54 | | - if ( isset( $wgMinFraudActionRanges ) ) |
55 | | - $this->action_ranges = $wgMinFraudActionRanges; |
| 53 | + |
| 54 | + $gateway_ranges = $gateway_adapter->getGlobal( 'MinFraudActionRanges' ); |
| 55 | + if ( !is_null( $gateway_ranges ) ) |
| 56 | + $this->action_ranges = $gateway_ranges; |
56 | 57 | } |
57 | 58 | |
58 | 59 | /** |
— | — | @@ -63,33 +64,35 @@ |
64 | 65 | */ |
65 | 66 | public function validate() { |
66 | 67 | // see if we can bypass minfraud |
67 | | - if ( $this->can_bypass_minfraud() ) |
| 68 | + if ( $this->can_bypass_minfraud() ){ |
68 | 69 | return TRUE; |
| 70 | + } |
69 | 71 | |
70 | 72 | $minfraud_query = $this->build_query( $this->gateway_adapter->getData() ); |
71 | 73 | $this->query_minfraud( $minfraud_query ); |
72 | | - $this->gateway_adapter->action = $this->determine_action( $this->minfraud_response['riskScore'] ); |
| 74 | + $localAction = $this->determine_action( $this->minfraud_response['riskScore'] ); |
| 75 | + $this->gateway_adapter->setValidationAction( $localAction ); |
73 | 76 | |
74 | 77 | // reset the data hash |
75 | 78 | $this->gateway_adapter->unsetHash(); |
76 | | - $this->gateway_adapter->setActionHash( $this->generate_hash( $this->gateway_adapter->action ) ); |
| 79 | + $this->gateway_adapter->setActionHash( $this->generate_hash( $localAction ) ); |
77 | 80 | $this->gateway_adapter->setHash( $this->generate_hash( $this->gateway_adapter->getData() ) ); |
78 | 81 | |
79 | 82 | // Write the query/response to the log |
80 | | - $this->log_query( $minfraud_query ); |
| 83 | + $this->log_query( $minfraud_query, $localAction ); |
81 | 84 | return TRUE; |
82 | 85 | } |
83 | 86 | |
84 | 87 | /** |
85 | 88 | * Logs a minFraud query and its response |
86 | 89 | */ |
87 | | - public function log_query( $minfraud_query ) { |
| 90 | + public function log_query( $minfraud_query, $action ) { |
88 | 91 | if ( $this->log_fh ) { |
89 | 92 | $log_message = '"' . addslashes( $this->gateway_adapter->getData( 'comment' ) ) . '"'; |
90 | 93 | $log_message .= "\t" . '"' . addslashes( $this->gateway_adapter->getData( 'amount' ) . ' ' . $this->gateway_adapter->getData( 'currency' ) ) . '"'; |
91 | 94 | $log_message .= "\t" . '"' . addslashes( json_encode( $minfraud_query ) ) . '"'; |
92 | 95 | $log_message .= "\t" . '"' . addslashes( json_encode( $this->minfraud_response ) ) . '"'; |
93 | | - $log_message .= "\t" . '"' . addslashes( $this->gateway_adapter->action ) . '"'; |
| 96 | + $log_message .= "\t" . '"' . addslashes( $action ) . '"'; |
94 | 97 | $log_message .= "\t" . '"' . addslashes( $this->gateway_adapter->getData( 'referrer' ) ) . '"'; |
95 | 98 | $this->log( $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'minFraud query', $log_message ); |
96 | 99 | } |
— | — | @@ -127,7 +130,7 @@ |
128 | 131 | foreach ( $actions as $action ) { |
129 | 132 | if ( $this->compare_hash( $action_hash, $action ) ) { |
130 | 133 | // set the action that should be taken |
131 | | - $this->gateway_adapter->action = $action; |
| 134 | + $this->gateway_adapter->setValidationAction( $action ); |
132 | 135 | return TRUE; |
133 | 136 | } |
134 | 137 | } |
— | — | @@ -266,7 +269,10 @@ |
267 | 270 | } |
268 | 271 | } |
269 | 272 | |
270 | | - static function onValidate( &$gateway_adapter ) { |
| 273 | + static function onValidate( &$gateway_adapter ) { |
| 274 | + if ( !$gateway_adapter->getGlobal( 'EnableMinfraud' ) ){ |
| 275 | + return true; |
| 276 | + } |
271 | 277 | $gateway_adapter->debugarray[] = "minfraud onValidate hook!"; |
272 | 278 | return self::singleton( $gateway_adapter )->validate(); |
273 | 279 | } |
Index: trunk/extensions/DonationInterface/extras/minfraud/minfraud.php |
— | — | @@ -24,7 +24,6 @@ |
25 | 25 | |
26 | 26 | function efMinFraudSetup() { |
27 | 27 | // if we're in standalone mode, use the GatewayValidate hook |
28 | | - global $wgMinFraudStandalone, $wgHooks; |
29 | | - if ( $wgMinFraudStandalone ) |
30 | | - $wgHooks["GatewayValidate"][] = array( 'Gateway_Extras_MinFraud::onValidate' ); |
| 28 | + global $wgHooks; |
| 29 | + $wgHooks["GatewayValidate"][] = array( 'Gateway_Extras_MinFraud::onValidate' ); |
31 | 30 | } |
Index: trunk/extensions/DonationInterface/extras/conversion_log/conversion_log.body.php |
— | — | @@ -9,7 +9,7 @@ |
10 | 10 | */ |
11 | 11 | public function post_process() { |
12 | 12 | // if the trxn has been outright rejected, log it |
13 | | - if ( $this->gateway_adapter->action == 'reject' ) { |
| 13 | + if ( $this->gateway_adapter->getValidationAction() == 'reject' ) { |
14 | 14 | $this->log( |
15 | 15 | $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'Rejected' |
16 | 16 | ); |
— | — | @@ -27,6 +27,9 @@ |
28 | 28 | } |
29 | 29 | |
30 | 30 | static function onPostProcess( &$gateway_adapter ) { |
| 31 | + if ( !$gateway_adapter->getGlobal( 'EnableConversionLog' ) ){ |
| 32 | + return true; |
| 33 | + } |
31 | 34 | $gateway_adapter->debugarray[] = 'conversion log onPostProcess hook!'; |
32 | 35 | return self::singleton( $gateway_adapter )->post_process(); |
33 | 36 | } |
Index: trunk/extensions/DonationInterface/extras/recaptcha/recaptcha.body.php |
— | — | @@ -43,7 +43,7 @@ |
44 | 44 | if ( $captcha_resp->is_valid ) { |
45 | 45 | // if validated, update the action and move on |
46 | 46 | $this->log( $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'Captcha passed' ); |
47 | | - $this->gateway_adapter->action = "process"; |
| 47 | + $this->gateway_adapter->setValidationAction( 'process' ); |
48 | 48 | return TRUE; |
49 | 49 | } else { |
50 | 50 | $this->recap_err = $captcha_resp->error; |
— | — | @@ -99,6 +99,9 @@ |
100 | 100 | } |
101 | 101 | |
102 | 102 | static function onChallenge( &$gateway_adapter ) { |
| 103 | + if ( !$gateway_adapter->getGlobal( 'EnableRecaptcha' ) ){ |
| 104 | + return true; |
| 105 | + } |
103 | 106 | $gateway_adapter->debugarray[] = 'recaptcha onChallenge hook!'; |
104 | 107 | return self::singleton( $gateway_adapter )->challenge(); |
105 | 108 | } |
Index: trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect_resultswitcher.body.php |
— | — | @@ -75,19 +75,21 @@ |
76 | 76 | $this->displayResultsForDebug( $result ); |
77 | 77 | //do the switching between the... stuff. |
78 | 78 | |
79 | | - switch ( $this->adapter->getTransactionWMFStatus() ) { |
80 | | - case 'complete': |
81 | | - case 'pending': |
82 | | - case 'pending-poke': |
83 | | - $go = $this->adapter->getThankYouPage(); |
84 | | - break; |
85 | | - case 'failed': |
86 | | - $go = $this->getDeclinedResultPage(); |
87 | | - break; |
| 79 | + if ( $this->adapter->getTransactionWMFStatus() ){ |
| 80 | + switch ( $this->adapter->getTransactionWMFStatus() ) { |
| 81 | + case 'complete': |
| 82 | + case 'pending': |
| 83 | + case 'pending-poke': |
| 84 | + $go = $this->adapter->getThankYouPage(); |
| 85 | + break; |
| 86 | + case 'failed': |
| 87 | + $go = $this->getDeclinedResultPage(); |
| 88 | + break; |
| 89 | + } |
| 90 | + |
| 91 | + $wgOut->addHTML( "<br>Redirecting to page $go" ); |
| 92 | + $wgOut->redirect( $go ); |
88 | 93 | } |
89 | | - |
90 | | - $wgOut->addHTML( "<br>Redirecting to page $go" ); |
91 | | - $wgOut->redirect( $go ); |
92 | 94 | } |
93 | 95 | } else { |
94 | 96 | if ( !$this->adapter->isCache() ) { |
Index: trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect_gateway.body.php |
— | — | @@ -81,8 +81,8 @@ |
82 | 82 | $this->paypalRedirect(); |
83 | 83 | return; |
84 | 84 | } |
| 85 | + |
85 | 86 | |
86 | | - |
87 | 87 | // dispatch forms/handling |
88 | 88 | if ( $this->adapter->checkTokens() ) { |
89 | 89 | if ( $this->adapter->posted ) { |
— | — | @@ -118,7 +118,6 @@ |
119 | 119 | $this->displayResultsForDebug( $result ); |
120 | 120 | |
121 | 121 | if ( $payment_method == 'cc' ) { |
122 | | - |
123 | 122 | $this->executeIframeForCreditCard( $result ); |
124 | 123 | } |
125 | 124 | |
Index: trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php |
— | — | @@ -92,8 +92,6 @@ |
93 | 93 | * @todo |
94 | 94 | * - Does DO_BANKVALIDATION need IPADDRESS? What about the other transactions. Is this the user's IPA? |
95 | 95 | * - Does DO_BANKVALIDATION need HOSTEDINDICATOR? |
96 | | - * - Does DO_BANKVALIDATION need do_validation? |
97 | | - * - Does DO_BANKVALIDATION need addDonorDataToSession? We should not save bank account information |
98 | 96 | * |
99 | 97 | * This method should define: |
100 | 98 | * - DO_BANKVALIDATION: used prior to INSERT_ORDERWITHPAYMENT for direct debit |
— | — | @@ -139,10 +137,7 @@ |
140 | 138 | ), |
141 | 139 | 'values' => array( |
142 | 140 | 'ACTION' => 'DO_BANKVALIDATION', |
143 | | - 'HOSTEDINDICATOR' => '1', |
144 | 141 | ), |
145 | | - 'do_validation' => true, |
146 | | - 'addDonorDataToSession' => false, |
147 | 142 | ); |
148 | 143 | |
149 | 144 | $this->transactions['INSERT_ORDERWITHPAYMENT'] = array( |
— | — | @@ -189,8 +184,6 @@ |
190 | 185 | 'ACTION' => 'INSERT_ORDERWITHPAYMENT', |
191 | 186 | 'HOSTEDINDICATOR' => '1', |
192 | 187 | ), |
193 | | - 'do_validation' => true, |
194 | | - 'addDonorDataToSession' => true, |
195 | 188 | ); |
196 | 189 | |
197 | 190 | $this->transactions['TEST_CONNECTION'] = array( |
— | — | @@ -230,8 +223,6 @@ |
231 | 224 | 'ACTION' => 'GET_ORDERSTATUS', |
232 | 225 | 'VERSION' => '2.0' |
233 | 226 | ), |
234 | | - 'do_processhooks' => true, |
235 | | - 'pullDonorDataFromSession' => true, |
236 | 227 | 'loop_for_status' => array( |
237 | 228 | //'pending', |
238 | 229 | 'pending_poke', |
— | — | @@ -816,5 +807,31 @@ |
817 | 808 | $this->postdata['returnto'] = $this->postdata['returnto'] . '?' . wfArrayToCGI( array( 'order_id' => $this->postdata['order_id'] ) ); |
818 | 809 | } |
819 | 810 | } |
| 811 | + |
| 812 | + protected function pre_process_insert_orderwithpayment(){ |
| 813 | + if ( $this->getData( 'payment_method' ) === 'cc' ){ |
| 814 | + $this->runPreProcessHooks(); //this is shortly to move elsewhere. |
| 815 | + $this->addDonorDataToSession(); |
| 816 | + } |
| 817 | + } |
| 818 | + |
| 819 | + protected function pre_process_get_orderstatus(){ |
| 820 | + if ( $this->getData( 'payment_method' ) === 'cc' ){ |
| 821 | + //if they're set, get CVVRESULT && AVSRESULT |
| 822 | + global $wgRequest; |
| 823 | + $cvv_result = $wgRequest->getVal( 'CVVRESULT', null ); |
| 824 | + $avs_result = $wgRequest->getVal( 'AVSRESULT', null ); |
| 825 | + if ( !is_null($cvv_result) ){ |
| 826 | + $this->debugarray[] = "CVV result: $cvv_result"; |
| 827 | + } |
| 828 | + if ( !is_null($avs_result) ){ |
| 829 | + $this->debugarray[] = "AVS result: $avs_result"; |
| 830 | + } |
| 831 | + } |
| 832 | + } |
| 833 | + |
| 834 | + protected function post_process_get_orderstatus(){ |
| 835 | + $this->runPostProcessHooks(); |
| 836 | + } |
820 | 837 | |
821 | 838 | } |
\ No newline at end of file |
Index: trunk/extensions/DonationInterface/gateway_common/gateway.adapter.php |
— | — | @@ -1,4 +1,5 @@ |
2 | 2 | <?php |
| 3 | + |
3 | 4 | /** |
4 | 5 | * Wikimedia Foundation |
5 | 6 | * |
— | — | @@ -136,7 +137,7 @@ |
137 | 138 | protected $form_class; |
138 | 139 | protected $validation_errors; |
139 | 140 | protected $current_transaction; |
140 | | - public $action; //Currently, hooks need to be able to set this directly. |
| 141 | + protected $action; |
141 | 142 | public $debugarray; //TODO: Take me out. |
142 | 143 | |
143 | 144 | //ALL OF THESE need to be redefined in the children. Much voodoo depends on the accuracy of these constants. |
— | — | @@ -178,7 +179,7 @@ |
179 | 180 | //TODO: Fix this a bit. |
180 | 181 | |
181 | 182 | $this->posted = ( $wgRequest->wasPosted() && ( !is_null( $wgRequest->getVal( 'numAttempt', null ) ) ) ); |
182 | | - |
| 183 | + |
183 | 184 | $this->setPostDefaults( $postDefaults ); |
184 | 185 | $this->defineTransactions(); |
185 | 186 | $this->defineVarMap(); |
— | — | @@ -241,13 +242,13 @@ |
242 | 243 | */ |
243 | 244 | public function checkTokens() { |
244 | 245 | $checkResult = $this->dataObj->token_checkTokens(); |
245 | | - |
| 246 | + |
246 | 247 | if ( $checkResult ) { |
247 | 248 | $this->debugarray[] = 'Token Match'; |
248 | 249 | } else { |
249 | 250 | $this->debugarray[] = 'Token MISMATCH'; |
250 | 251 | } |
251 | | - |
| 252 | + |
252 | 253 | $this->refreshGatewayValueFromSource( 'token' ); |
253 | 254 | return $checkResult; |
254 | 255 | } |
— | — | @@ -277,10 +278,10 @@ |
278 | 279 | * @return DonationData |
279 | 280 | */ |
280 | 281 | public function getDonationData() { |
281 | | - |
| 282 | + |
282 | 283 | return $this->dataObj; |
283 | 284 | } |
284 | | - |
| 285 | + |
285 | 286 | function getDisplayData( $val = '' ) { |
286 | 287 | if ( $val === '' ) { |
287 | 288 | return $this->displaydata; |
— | — | @@ -338,10 +339,10 @@ |
339 | 340 | * @return array Returns @see GatewayAdapter::$var_map |
340 | 341 | */ |
341 | 342 | public function getVarMap() { |
342 | | - |
| 343 | + |
343 | 344 | return $this->var_map; |
344 | 345 | } |
345 | | - |
| 346 | + |
346 | 347 | /** |
347 | 348 | * This function is used exclusively by the two functions that build |
348 | 349 | * requests to be sent directly to external payment gateway servers. Those |
— | — | @@ -374,7 +375,7 @@ |
375 | 376 | } |
376 | 377 | //Ensures we are using the correct transaction structure for our various lookups. |
377 | 378 | $transaction = $this->getCurrentTransaction(); |
378 | | - |
| 379 | + |
379 | 380 | if ( !$transaction ){ |
380 | 381 | return null; |
381 | 382 | } |
— | — | @@ -406,15 +407,15 @@ |
407 | 408 | return $this->postdata[$this->var_map[$gateway_field_name]]; |
408 | 409 | } else { |
409 | 410 | //return the default for that form value |
410 | | - |
| 411 | + |
411 | 412 | $tempField = isset( $this->var_map[ $gateway_field_name ] ) ? $this->var_map[ $gateway_field_name ] : false; |
412 | | - |
| 413 | + |
413 | 414 | $tempValue = ''; |
414 | | - |
| 415 | + |
415 | 416 | if ( $tempField && isset( $this->postdatadefaults[ $tempField ] ) ) { |
416 | 417 | $tempValue = $this->postdatadefaults[ $tempField ]; |
417 | 418 | } |
418 | | - |
| 419 | + |
419 | 420 | return $tempValue; |
420 | 421 | } |
421 | 422 | } |
— | — | @@ -425,8 +426,7 @@ |
426 | 427 | self::log( $msg, LOG_CRIT ); |
427 | 428 | throw new MWException( $msg ); |
428 | 429 | } |
429 | | - |
430 | | - |
| 430 | + |
431 | 431 | /** |
432 | 432 | * Returns the current transaction request structure if it exists, otherwise |
433 | 433 | * returns false. |
— | — | @@ -439,16 +439,16 @@ |
440 | 440 | if ( !$transaction ){ |
441 | 441 | return false; |
442 | 442 | } |
443 | | - |
444 | | - if ( empty( $this->transactions ) || |
445 | | - !array_key_exists( $transaction, $this->transactions ) || |
| 443 | + |
| 444 | + if ( empty( $this->transactions ) || |
| 445 | + !array_key_exists( $transaction, $this->transactions ) || |
446 | 446 | !array_key_exists( 'request', $this->transactions[$transaction] ) ) { |
447 | | - |
| 447 | + |
448 | 448 | $msg = self::getGatewayName() . ": $transaction request structure is empty! No transaction can be constructed."; |
449 | 449 | self::log( $msg, LOG_CRIT ); |
450 | 450 | throw new MWException( $msg ); |
451 | 451 | } |
452 | | - |
| 452 | + |
453 | 453 | return $this->transactions[$transaction]['request']; |
454 | 454 | } |
455 | 455 | |
— | — | @@ -572,7 +572,7 @@ |
573 | 573 | $this->xmlDoc = new DomDocument( '1.0' ); |
574 | 574 | $node = $this->xmlDoc->createElement( 'XML' ); |
575 | 575 | |
576 | | - $structure = $this->getTransactionRequestStructure(); |
| 576 | + $structure = $this->getTransactionRequestStructure(); |
577 | 577 | if ( !is_array( $structure ) ) { |
578 | 578 | return ''; |
579 | 579 | } |
— | — | @@ -621,14 +621,16 @@ |
622 | 622 | //update the contribution tracking data |
623 | 623 | $this->incrementNumAttempt(); |
624 | 624 | |
625 | | - //if we're supposed to add the donor data to the session, do that. |
626 | | - if ( $this->transaction_option( 'addDonorDataToSession' ) ) { |
627 | | - $this->addDonorDataToSession(); |
628 | | - } |
| 625 | + //If we have any special pre-process instructions for this |
| 626 | + //transaction, do 'em. |
| 627 | + //NOTE: If you want your transaction to fire off the pre-process |
| 628 | + //hooks, you need to run $this->runPreProcessHooks in a function |
| 629 | + //called |
| 630 | + // 'pre_process' . strtolower($transaction) |
| 631 | + //in the appropriate gateway object. |
| 632 | + $this->executeIfFunctionExists( 'pre_process_' . $transaction ); |
629 | 633 | |
630 | | - $this->runPreProcess(); //many hooks get fired here... |
631 | | - |
632 | | - if ( $this->action != 'process' ) { |
| 634 | + if ( $this->getValidationAction() != 'process' ) { |
633 | 635 | return array( |
634 | 636 | 'status' => false, |
635 | 637 | //TODO: appropriate messages. |
— | — | @@ -636,15 +638,10 @@ |
637 | 639 | 'errors' => array( |
638 | 640 | '1000000' => 'pre-process failed you.' //...stupid code. |
639 | 641 | ), |
640 | | - 'action' => $this->action, |
| 642 | + 'action' => $this->getValidationAction(), |
641 | 643 | ); |
642 | 644 | } |
643 | 645 | |
644 | | - // expose a hook for external handling of trxns ready for processing |
645 | | - if ( $this->transaction_option( 'do_processhooks' ) ) { |
646 | | - wfRunHooks( 'GatewayProcess', array( &$this ) ); //don't think anybody is using this yet, but you could! |
647 | | - } |
648 | | - |
649 | 646 | $this->dataObj->updateContributionTracking( defined( 'OWA' ) ); |
650 | 647 | |
651 | 648 | // If the payment processor requires XML, package our data into XML. |
— | — | @@ -661,15 +658,15 @@ |
662 | 659 | $this->saveCommunicationStats( "buildRequestNameValueString", $transaction ); // save profiling data |
663 | 660 | } |
664 | 661 | } catch ( MWException $e ) { |
665 | | - self::log( "Malformed gateway definition. Cannot continue: Aborting.", LOG_CRIT ); |
| 662 | + self::log( "Malformed gateway definition. Cannot continue: Aborting.\n" . $e->getMessage(), LOG_CRIT ); |
666 | 663 | return array( |
667 | 664 | 'status' => false, |
668 | 665 | //TODO: appropriate messages. |
669 | | - 'message' => "$transaction : Malformed gateway definition. Cannot continue: Aborting.", |
| 666 | + 'message' => "$transaction : Malformed gateway definition. Cannot continue: Aborting.\n" . $e->getMessage(), |
670 | 667 | 'errors' => array( |
671 | 668 | '1000000' => 'Transaction could not be processed due to an internal error.' |
672 | 669 | ), |
673 | | - 'action' => $this->action, |
| 670 | + 'action' => $this->getValidationAction(), |
674 | 671 | ); |
675 | 672 | } |
676 | 673 | |
— | — | @@ -732,16 +729,18 @@ |
733 | 730 | ); |
734 | 731 | } |
735 | 732 | |
736 | | - // expose a hook for any post processing |
737 | | - if ( $this->transaction_option( 'do_processhooks' ) ) { |
738 | | - wfRunHooks( 'GatewayPostProcess', array( &$this ) ); //conversion log (at least) |
739 | | - $this->doStompTransaction(); |
740 | | - } |
| 733 | + //If we have any special post-process instructions for this |
| 734 | + //transaction, do 'em. |
| 735 | + //NOTE: If you want your transaction to fire off the post-process |
| 736 | + //hooks, you need to run $this->runPostProcessHooks in a function |
| 737 | + //called |
| 738 | + // 'post_process' . strtolower($transaction) |
| 739 | + //in the appropriate gateway object. |
| 740 | + $this->executeIfFunctionExists( 'post_process_' . $transaction ); |
741 | 741 | |
742 | 742 | //TODO: Actually pull these from somewhere legit. |
743 | 743 | if ( $this->getTransactionStatus() === true ) { |
744 | 744 | $this->setTransactionResult( "$transaction Transaction Successful!", 'message' ); |
745 | | - |
746 | 745 | } elseif ( $this->getTransactionStatus() === false ) { |
747 | 746 | $this->setTransactionResult( "$transaction Transaction FAILED!", 'message' ); |
748 | 747 | } else { |
— | — | @@ -765,11 +764,8 @@ |
766 | 765 | case 'pending' : |
767 | 766 | case 'pending-poke' : |
768 | 767 | $this->unsetAllSessionData(); |
769 | | - } |
770 | | - //if we're not actively adding the donor data to the session, kill it. |
771 | | - if ( !$this->transaction_option( 'addDonorDataToSession' ) ) { |
772 | | - $this->dataObj->unsetDonorSessionData(); //just that. Not the whole session. |
773 | 768 | } |
| 769 | + |
774 | 770 | $this->debugarray[] = 'numAttempt = ' . $this->postdata['numAttempt']; |
775 | 771 | |
776 | 772 | return $this->getTransactionAllResults(); |
— | — | @@ -832,7 +828,7 @@ |
833 | 829 | $this->current_transaction = $transaction_name; |
834 | 830 | } |
835 | 831 | } |
836 | | - |
| 832 | + |
837 | 833 | /** |
838 | 834 | * Gets the currently set transaction name. This value should only ever be |
839 | 835 | * set with setCurrentTransaction: A function that ensures the current |
— | — | @@ -848,7 +844,7 @@ |
849 | 845 | return $this->current_transaction; |
850 | 846 | } |
851 | 847 | } |
852 | | - |
| 848 | + |
853 | 849 | /** |
854 | 850 | * Define payment methods |
855 | 851 | * |
— | — | @@ -864,16 +860,16 @@ |
865 | 861 | * @return array Returns the available payment methods for the specific adapter |
866 | 862 | */ |
867 | 863 | public function getPaymentMethods() { |
868 | | - |
| 864 | + |
869 | 865 | // Define the payment methods if they have not been set yet. |
870 | 866 | if ( empty( $this->payment_methods ) ) { |
871 | | - |
| 867 | + |
872 | 868 | $this->definePaymentMethods(); |
873 | 869 | } |
874 | | - |
| 870 | + |
875 | 871 | return $this->payment_methods; |
876 | 872 | } |
877 | | - |
| 873 | + |
878 | 874 | /** |
879 | 875 | * Define payment methods |
880 | 876 | * |
— | — | @@ -892,16 +888,16 @@ |
893 | 889 | * @return array Returns the available payment submethods for the specific adapter |
894 | 890 | */ |
895 | 891 | public function getPaymentSubmethods() { |
896 | | - |
| 892 | + |
897 | 893 | // Define the payment methods if they have not been set yet. |
898 | 894 | if ( empty( $this->payment_submethods ) ) { |
899 | | - |
| 895 | + |
900 | 896 | $this->definePaymentSubmethods(); |
901 | 897 | } |
902 | | - |
| 898 | + |
903 | 899 | return $this->payment_methods; |
904 | 900 | } |
905 | | - |
| 901 | + |
906 | 902 | /** |
907 | 903 | * Sends a curl request to the gateway server, and gets a response. |
908 | 904 | * Saves that response to the gateway object with setTransactionResult(); |
— | — | @@ -1214,8 +1210,6 @@ |
1215 | 1211 | } |
1216 | 1212 | |
1217 | 1213 | /** |
1218 | | - * Called in do_transaction, in the case that we have successfully completed |
1219 | | - * a transaction that has 'do_processhooks' enabled. |
1220 | 1214 | * Saves a stomp frame to the configured server and queue, based on the |
1221 | 1215 | * outcome of our current transaction. |
1222 | 1216 | * The big tricky thing here, is that we DO NOT SET a TransactionWMFStatus, |
— | — | @@ -1224,9 +1218,15 @@ |
1225 | 1219 | * To put it another way, getTransactionWMFStatus should always return |
1226 | 1220 | * false, unless it's new data about a new transaction. In that case, the |
1227 | 1221 | * outcome will be assigned and the proper stomp hook selected. |
| 1222 | + * |
| 1223 | + * Probably called in runPostProcessHooks(), which is itself most likely to |
| 1224 | + * be called through executeFunctionIfExists, later on in do_transaction. |
1228 | 1225 | * @return null |
1229 | 1226 | */ |
1230 | 1227 | protected function doStompTransaction() { |
| 1228 | + if ( !$this->getGlobal( 'EnableStomp' ) ){ |
| 1229 | + return; |
| 1230 | + } |
1231 | 1231 | $this->debugarray[] = "Attempting Stomp Transaction!"; |
1232 | 1232 | $hook = ''; |
1233 | 1233 | |
— | — | @@ -1253,13 +1253,12 @@ |
1254 | 1254 | //'language' => '', |
1255 | 1255 | ); |
1256 | 1256 | $transaction += $this->getDisplayData(); |
1257 | | - |
| 1257 | + |
1258 | 1258 | try { |
1259 | 1259 | wfRunHooks( $hook, array( $transaction ) ); |
1260 | 1260 | } catch ( Exception $e ) { |
1261 | 1261 | self::log( "STOMP ERROR. Could not add message. " . $e->getMessage() , LOG_CRIT ); |
1262 | 1262 | } |
1263 | | - |
1264 | 1263 | } |
1265 | 1264 | |
1266 | 1265 | function smooshVarsForStaging() { |
— | — | @@ -1273,8 +1272,23 @@ |
1274 | 1273 | //what do we do in the event that we're still nothing? (just move on.) |
1275 | 1274 | } |
1276 | 1275 | } |
1277 | | - |
| 1276 | + |
1278 | 1277 | /** |
| 1278 | + * Executes the specified function in $this, if one exists. |
| 1279 | + * NOTE: THIS WILL LCASE YOUR FUNCTION_NAME. |
| 1280 | + * ...I like to keep the voodoo functions tidy. |
| 1281 | + * @param string $function_name The name of the function you're hoping to |
| 1282 | + * execute. |
| 1283 | + * @param mixed $parameter That's right: For now you only get one. |
| 1284 | + */ |
| 1285 | + function executeIfFunctionExists( $function_name, $parameter = null ) { |
| 1286 | + $function_name = strtolower( $function_name ); //Because, that's why. |
| 1287 | + if ( method_exists( $this, $function_name ) ) { |
| 1288 | + $this->{$function_name}( $parameter ); |
| 1289 | + } |
| 1290 | + } |
| 1291 | + |
| 1292 | + /** |
1279 | 1293 | * |
1280 | 1294 | * @param type $type Whatever types of staging you feel like having in your child class. |
1281 | 1295 | * ...but usually request and response. I think. |
— | — | @@ -1286,11 +1300,9 @@ |
1287 | 1301 | //multiple variables. |
1288 | 1302 | foreach ( $this->staged_vars as $field ) { |
1289 | 1303 | $function_name = 'stage_' . $field; |
1290 | | - if ( method_exists( $this, $function_name ) ) { |
1291 | | - $this->{$function_name}( $type ); |
| 1304 | + $this->executeIfFunctionExists( $function_name, $type ); |
1292 | 1305 | } |
1293 | 1306 | } |
1294 | | - } |
1295 | 1307 | |
1296 | 1308 | function getPaypalRedirectURL() { |
1297 | 1309 | $utm_source = $this->getData( 'utm_source' ); |
— | — | @@ -1311,7 +1323,6 @@ |
1312 | 1324 | //In fact, put that in addData, and restage anything that's either the explicit key, |
1313 | 1325 | //or any of the calculated keys. |
1314 | 1326 | $this->refreshGatewayValueFromSource( 'utm_source' ); //calculated field! |
1315 | | - |
1316 | 1327 | //update contribution tracking |
1317 | 1328 | $this->dataObj->updateContributionTracking( true ); |
1318 | 1329 | |
— | — | @@ -1319,7 +1330,7 @@ |
1320 | 1331 | self::log( $ret ); |
1321 | 1332 | return $ret; |
1322 | 1333 | } |
1323 | | - |
| 1334 | + |
1324 | 1335 | protected function getPaypalData() { |
1325 | 1336 | $paypalkeys = array( |
1326 | 1337 | 'contribution_tracking_id', |
— | — | @@ -1349,7 +1360,7 @@ |
1350 | 1361 | 'amount', |
1351 | 1362 | 'amountGiven', |
1352 | 1363 | 'size', |
1353 | | - 'premium_language', |
| 1364 | + 'premium_language', |
1354 | 1365 | ); |
1355 | 1366 | $ret = array(); |
1356 | 1367 | foreach ( $paypalkeys as $key ){ |
— | — | @@ -1415,7 +1426,7 @@ |
1416 | 1427 | * Possible valid statuses are: 'complete', 'pending', 'pending-poke', 'failed' and 'revised'. |
1417 | 1428 | */ |
1418 | 1429 | public function getTransactionWMFStatus() { |
1419 | | - if ( array_key_exists( 'WMF_STATUS', $this->transaction_results ) ) { |
| 1430 | + if ( is_array( $this->transaction_results ) && array_key_exists( 'WMF_STATUS', $this->transaction_results ) ) { |
1420 | 1431 | return $this->transaction_results['WMF_STATUS']; |
1421 | 1432 | } else { |
1422 | 1433 | return false; |
— | — | @@ -1425,6 +1436,13 @@ |
1426 | 1437 | /** |
1427 | 1438 | * Sets the WMF Transaction Status. This is the one we care about for |
1428 | 1439 | * switching on behavior. |
| 1440 | + * DO NOT SET THE WMF STATUS unless you've just taken an entire donation |
| 1441 | + * process to completion: This status being set at all, denotes the very end |
| 1442 | + * of the donation process on our end. Further attempts by the same user |
| 1443 | + * will be seen as starting over. |
| 1444 | + * @param string $status Only five strings will do anything good in the rest |
| 1445 | + * of the code so far: |
| 1446 | + * 'complete', 'pending', 'pending-poke', 'failed', 'revised' |
1429 | 1447 | */ |
1430 | 1448 | public function setTransactionWMFStatus( $status ) { |
1431 | 1449 | $this->transaction_results['WMF_STATUS'] = $status; |
— | — | @@ -1508,43 +1526,66 @@ |
1509 | 1527 | $this->dataObj->expunge( 'action' ); |
1510 | 1528 | } |
1511 | 1529 | |
1512 | | - function runPreProcess() { |
1513 | | - global $wgHooks; |
1514 | | - if ( $this->transaction_option( 'do_validation' ) ) { |
1515 | | - if ( !isset( $wgHooks['GatewayValidate'] ) ) { |
1516 | | - //if there ARE no validate hooks, we're okay. |
1517 | | - $this->action = 'process'; |
1518 | | - return; |
1519 | | - } |
1520 | | - // allow any external validators to have their way with the data |
1521 | | - self::log( $this->getData( 'contribution_tracking_id' ) . " Preparing to query MaxMind" ); |
1522 | | - wfRunHooks( 'GatewayValidate', array( &$this ) ); |
1523 | | - self::log( $this->getData( 'contribution_tracking_id' ) . ' Finished querying Maxmind' ); |
| 1530 | + /** |
| 1531 | + * Runs all the pre-process hooks that have been enabled and configured in |
| 1532 | + * donationdata.php and/or LocalSettings.php |
| 1533 | + * This function is most likely to be called through |
| 1534 | + * executeFunctionIfExists, early on in do_transaction. |
| 1535 | + */ |
| 1536 | + function runPreProcessHooks() { |
| 1537 | + // allow any external validators to have their way with the data |
| 1538 | + self::log( $this->getData( 'contribution_tracking_id' ) . " Preparing to query MaxMind" ); |
| 1539 | + wfRunHooks( 'GatewayValidate', array( &$this ) ); |
| 1540 | + self::log( $this->getData( 'contribution_tracking_id' ) . ' Finished querying Maxmind' ); |
1524 | 1541 | |
1525 | | - // if the transaction was flagged for review |
1526 | | - if ( $this->action == 'review' ) { |
1527 | | - // expose a hook for external handling of trxns flagged for review |
1528 | | - wfRunHooks( 'GatewayReview', array( &$this ) ); |
1529 | | - } |
| 1542 | + //DO NOT set some variable as getValidationAction() here, and keep |
| 1543 | + //checking that. getValidationAction could change with each one of these |
| 1544 | + //hooks, and this ought to cascade. |
| 1545 | + // if the transaction was flagged for review |
| 1546 | + if ( $this->getValidationAction() == 'review' ) { |
| 1547 | + // expose a hook for external handling of trxns flagged for review |
| 1548 | + wfRunHooks( 'GatewayReview', array( &$this ) ); |
| 1549 | + } |
1530 | 1550 | |
1531 | | - // if the transaction was flagged to be 'challenged' |
1532 | | - if ( $this->action == 'challenge' ) { |
1533 | | - // expose a hook for external handling of trxns flagged for challenge (eg captcha) |
1534 | | - wfRunHooks( 'GatewayChallenge', array( &$this ) ); |
1535 | | - } |
| 1551 | + // if the transaction was flagged to be 'challenged' |
| 1552 | + if ( $this->getValidationAction() == 'challenge' ) { |
| 1553 | + // expose a hook for external handling of trxns flagged for challenge (eg captcha) |
| 1554 | + wfRunHooks( 'GatewayChallenge', array( &$this ) ); |
1536 | 1555 | |
1537 | 1556 | // if the transaction was flagged for rejection |
1538 | | - if ( $this->action == 'reject' ) { |
| 1557 | + if ( $this->getValidationAction() == 'reject' ) { |
1539 | 1558 | // expose a hook for external handling of trxns flagged for rejection |
1540 | 1559 | wfRunHooks( 'GatewayReject', array( &$this ) ); |
1541 | 1560 | $this->unsetAllSessionData(); |
1542 | 1561 | } |
1543 | | - } else { |
1544 | | - $this->action = 'process'; //we have to do this so do_transaction doesn't kick out. |
| 1562 | + } |
1545 | 1563 | } |
| 1564 | + |
| 1565 | + /** |
| 1566 | + * Runs all the post-process hooks that have been enabled and configured in |
| 1567 | + * donationdata.php and/or LocalSettings.php, including the ActiveMQ/Stomp |
| 1568 | + * hooks. |
| 1569 | + * This function is most likely to be called through |
| 1570 | + * executeFunctionIfExists, later on in do_transaction. |
| 1571 | + */ |
| 1572 | + protected function runPostProcessHooks() { |
| 1573 | + // expose a hook for any post processing |
| 1574 | + wfRunHooks( 'GatewayPostProcess', array( &$this ) ); //conversion log (at least) |
| 1575 | + $this->doStompTransaction(); |
1546 | 1576 | } |
1547 | 1577 | |
1548 | | - function transaction_option( $option_value ) { |
| 1578 | + /** |
| 1579 | + * If there are things about a transaction that we need to stash in the |
| 1580 | + * transaction's definition (defined in a local defineTransactions() ), we |
| 1581 | + * can recall them here. Currently, this is only being used to determine if |
| 1582 | + * we have a transaction whose transmission would require multiple attempts |
| 1583 | + * to wait for a certain status (or set of statuses), but we could do more |
| 1584 | + * with this mechanism if we need to. |
| 1585 | + * @param string $option_value the name of the key we're looking for in the |
| 1586 | + * transaction definition. |
| 1587 | + * @return mixed the transaction's value for that key if it exists, or false. |
| 1588 | + */ |
| 1589 | + protected function transaction_option( $option_value ) { |
1549 | 1590 | //ooo, ugly. |
1550 | 1591 | $transaction = $this->getCurrentTransaction(); |
1551 | 1592 | if ( !$transaction ){ |
— | — | @@ -1561,7 +1602,7 @@ |
1562 | 1603 | } |
1563 | 1604 | return false; |
1564 | 1605 | } |
1565 | | - |
| 1606 | + |
1566 | 1607 | /** |
1567 | 1608 | * Instead of pulling all the DonationData back through to update one local |
1568 | 1609 | * value, use this. It updates both postdata (which is intended to be |
— | — | @@ -1576,7 +1617,7 @@ |
1577 | 1618 | * @param string $val The field name that we are looking to retrieve from |
1578 | 1619 | * our DonationData object. |
1579 | 1620 | */ |
1580 | | - function refreshGatewayValueFromSource( $val ){ |
| 1621 | + function refreshGatewayValueFromSource( $val ) { |
1581 | 1622 | $refreshed = $this->dataObj->getVal( $val ); |
1582 | 1623 | if ( !is_null($refreshed) ){ |
1583 | 1624 | $this->postdata[$val] = $refreshed; |
— | — | @@ -1586,5 +1627,48 @@ |
1587 | 1628 | unset( $this->displaydata[$val] ); |
1588 | 1629 | } |
1589 | 1630 | } |
1590 | | - |
1591 | | -} |
| 1631 | + |
| 1632 | + /** |
| 1633 | + * Sets the current validation action. This is meant to be used by the |
| 1634 | + * process hooks, and as such, by default, only worse news than was already |
| 1635 | + * being stored will be retained for the final result. |
| 1636 | + * @param string $action the value you want to set as the action. |
| 1637 | + * @param bool $reset set to true to do a hard set on the action value. |
| 1638 | + * Otherwise, the status will only change if it fails harder than it already |
| 1639 | + * was. |
| 1640 | + */ |
| 1641 | + public function setValidationAction( $action, $reset = false ) { |
| 1642 | + //our choices are: |
| 1643 | + $actions = array( |
| 1644 | + 'process' => 0, |
| 1645 | + 'review' => 1, |
| 1646 | + 'challenge' => 2, |
| 1647 | + 'reject' => 3, |
| 1648 | + ); |
| 1649 | + if ( !isset( $actions[$action] ) ) { |
| 1650 | + throw new MWException( "Action $action is invalid." ); |
| 1651 | + } |
| 1652 | + |
| 1653 | + if ( $reset ) { |
| 1654 | + $this->action = $action; |
| 1655 | + return; |
| 1656 | + } |
| 1657 | + |
| 1658 | + if ( ( int ) $actions[$action] > ( int ) $actions[$this->getValidationAction()] ) { |
| 1659 | + $this->action = $action; |
| 1660 | + } |
| 1661 | + } |
| 1662 | + |
| 1663 | + /** |
| 1664 | + * Returns the current validation action. |
| 1665 | + * This will typically get set and altered by the various enabled process hooks. |
| 1666 | + * @return string the current process action. |
| 1667 | + */ |
| 1668 | + public function getValidationAction() { |
| 1669 | + if ( !isset( $this->action ) ) { |
| 1670 | + $this->action = 'process'; |
| 1671 | + } |
| 1672 | + return $this->action; |
| 1673 | + } |
| 1674 | + |
| 1675 | +} |
\ No newline at end of file |