Index: branches/fundraising/extensions/DonationInterface/donationinterface.php |
— | — | @@ -89,17 +89,17 @@ |
90 | 90 | # Unit tests |
91 | 91 | $wgHooks['UnitTestsList'][] = 'efDonationInterfaceUnitTests'; |
92 | 92 | |
93 | | -// |
94 | | -//// Resource modules |
95 | | -//$wgResourceTemplate = array( |
96 | | -// 'localBasePath' => $donationinterface_dir . 'modules', |
97 | | -// 'remoteExtPath' => 'DonationInterface/modules', |
98 | | -//); |
99 | | -//$wgResourceModules['jquery.donationInterface'] = array( |
100 | | -// 'scripts' => 'jquery.donationInterface.js', |
101 | | -// 'dependencies' => 'jquery.json', |
102 | | -//) + $wgResourceTemplate; |
103 | 93 | |
| 94 | +// Resource modules |
| 95 | +$wgResourceTemplate = array( |
| 96 | + 'localBasePath' => $donationinterface_dir . 'modules', |
| 97 | + 'remoteExtPath' => 'DonationInterface/modules', |
| 98 | +); |
| 99 | +$wgResourceModules['iframe.liberator'] = array( |
| 100 | + 'scripts' => 'iframe.liberator.js', |
| 101 | + 'position' => 'top' |
| 102 | +) + $wgResourceTemplate; |
| 103 | + |
104 | 104 | function efDonationInterfaceUnitTests( &$files ) { |
105 | 105 | $files[] = dirname( __FILE__ ) . '/tests/GatewayAdapterTest.php'; |
106 | 106 | $files[] = dirname( __FILE__ ) . '/tests/DonationDataTest.php'; |
Index: branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect_resultswitcher.body.php |
— | — | @@ -0,0 +1,190 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class GlobalCollectGatewayResult extends UnlistedSpecialPage { |
| 5 | + |
| 6 | + /** |
| 7 | + * Defines the action to take on a PFP transaction. |
| 8 | + * |
| 9 | + * Possible values include 'process', 'challenge', |
| 10 | + * 'review', 'reject'. These values can be set during |
| 11 | + * data processing validation, for instance. |
| 12 | + * |
| 13 | + * Hooks are exposed to handle the different actions. |
| 14 | + * |
| 15 | + * Defaults to 'process'. |
| 16 | + * @var string |
| 17 | + */ |
| 18 | + public $action = 'process'; |
| 19 | + |
| 20 | + /** |
| 21 | + * An array of form errors |
| 22 | + * @var array |
| 23 | + */ |
| 24 | + public $errors = array( ); |
| 25 | + |
| 26 | + /** |
| 27 | + * Constructor - set up the new special page |
| 28 | + */ |
| 29 | + public function __construct() { |
| 30 | + parent::__construct( 'GlobalCollectGatewayResult' ); |
| 31 | + $this->errors = $this->getPossibleErrors(); |
| 32 | + |
| 33 | + $this->adapter = new GlobalCollectAdapter(); |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * Show the special page |
| 38 | + * |
| 39 | + * @param $par Mixed: parameter passed to the page or null |
| 40 | + */ |
| 41 | + public function execute( $par ) { |
| 42 | + global $wgRequest, $wgOut, $wgExtensionAssetsPath, |
| 43 | + $wgPayFlowProGatewayCSSVersion; |
| 44 | + |
| 45 | + $wgOut->allowClickjacking(); |
| 46 | + $wgOut->addModules( 'iframe.liberator' ); |
| 47 | + |
| 48 | + $wgOut->addExtensionStyle( |
| 49 | + $wgExtensionAssetsPath . '/DonationInterface/gateway_forms/css/gateway.css?284' . |
| 50 | + $wgPayFlowProGatewayCSSVersion ); |
| 51 | + |
| 52 | + $this->setHeaders(); |
| 53 | + |
| 54 | + |
| 55 | + // dispatch forms/handling |
| 56 | + if ( $this->adapter->checkTokens() ) { |
| 57 | + // Display form for the first time |
| 58 | + $oid = $wgRequest->getText( 'order_id' ); |
| 59 | + if ( $oid && !empty( $oid ) ) { |
| 60 | + $result = $this->adapter->do_transaction( 'GET_ORDERSTATUS' ); |
| 61 | + $this->displayResultsForDebug( $result ); |
| 62 | + } |
| 63 | + $this->adapter->log( "Not posted, or not processed. Showing the form for the first time." ); |
| 64 | + } else { |
| 65 | + if ( !$this->adapter->isCache() ) { |
| 66 | + // if we're not caching, there's a token mismatch |
| 67 | + $this->errors['general']['token-mismatch'] = wfMsg( 'payflowpro_gateway-token-mismatch' ); |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + function displayResultsForDebug( $results ) { |
| 73 | + global $wgOut; |
| 74 | + $wgOut->addHTML( $results['message'] ); |
| 75 | + |
| 76 | + if ( !empty( $results['errors'] ) ) { |
| 77 | + $wgOut->addHTML( "<ul>" ); |
| 78 | + foreach ( $results['errors'] as $code => $value ) { |
| 79 | + $wgOut->addHTML( "<li>Error $code: $value" ); |
| 80 | + } |
| 81 | + $wgOut->addHTML( "</ul>" ); |
| 82 | + } |
| 83 | + |
| 84 | + if ( !empty( $results['data'] ) ) { |
| 85 | + $wgOut->addHTML( "<ul>" ); |
| 86 | + foreach ( $results['data'] as $key => $value ) { |
| 87 | + if ( is_array( $value ) ) { |
| 88 | + $wgOut->addHTML( "<li>$key:<ul>" ); |
| 89 | + foreach ( $value as $key2 => $val2 ) { |
| 90 | + $wgOut->addHTML( "<li>$key2: $val2" ); |
| 91 | + } |
| 92 | + $wgOut->addHTML( "</ul>" ); |
| 93 | + } else { |
| 94 | + $wgOut->addHTML( "<li>$key: $value" ); |
| 95 | + } |
| 96 | + } |
| 97 | + $wgOut->addHTML( "</ul>" ); |
| 98 | + } else { |
| 99 | + $wgOut->addHTML( "Empty Results" ); |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + /** |
| 104 | + * Prepares the transactional message to be sent via Stomp to queueing service |
| 105 | + * |
| 106 | + * @param array $data |
| 107 | + * @param array $resposneArray |
| 108 | + * @param array $responseMsg |
| 109 | + * @return array |
| 110 | + */ |
| 111 | + public function prepareStompTransaction( $data, $responseArray, $responseMsg ) { |
| 112 | + $countries = $this->getCountries(); |
| 113 | + |
| 114 | + $transaction = array( ); |
| 115 | + |
| 116 | + // include response message |
| 117 | + $transaction['response'] = $responseMsg; |
| 118 | + |
| 119 | + // include date |
| 120 | + $transaction['date'] = time(); |
| 121 | + |
| 122 | + // put all data into one array |
| 123 | + $optout = $this->determineOptOut( $data ); |
| 124 | + $data['anonymous'] = $optout['anonymous']; |
| 125 | + $data['optout'] = $optout['optout']; |
| 126 | + |
| 127 | + $transaction += array_merge( $data, $responseArray ); |
| 128 | + |
| 129 | + return $transaction; |
| 130 | + } |
| 131 | + |
| 132 | + public function getPossibleErrors() { |
| 133 | + return array( |
| 134 | + 'general' => '', |
| 135 | + 'retryMsg' => '', |
| 136 | + 'invalidamount' => '', |
| 137 | + 'card_num' => '', |
| 138 | + 'card_type' => '', |
| 139 | + 'cvv' => '', |
| 140 | + 'fname' => '', |
| 141 | + 'lname' => '', |
| 142 | + 'city' => '', |
| 143 | + 'country' => '', |
| 144 | + 'street' => '', |
| 145 | + 'state' => '', |
| 146 | + 'zip' => '', |
| 147 | + 'emailAdd' => '', |
| 148 | + ); |
| 149 | + } |
| 150 | + |
| 151 | + /** |
| 152 | + * Handle redirection of form content to PayPal |
| 153 | + * |
| 154 | + * @fixme If we can update contrib tracking table in ContributionTracking |
| 155 | + * extension, we can probably get rid of this method and just submit the form |
| 156 | + * directly to the paypal URL, and have all processing handled by ContributionTracking |
| 157 | + * This would make this a lot less hack-ish |
| 158 | + */ |
| 159 | + public function paypalRedirect( &$data ) { |
| 160 | + global $wgPayflowProGatewayPaypalURL, $wgOut; |
| 161 | + |
| 162 | + // if we don't have a URL enabled throw a graceful error to the user |
| 163 | + if ( !strlen( $wgPayflowProGatewayPaypalURL ) ) { |
| 164 | + $this->errors['general']['nopaypal'] = wfMsg( 'payflow_gateway-error-msg-nopaypal' ); |
| 165 | + return; |
| 166 | + } |
| 167 | + |
| 168 | + // update the utm source to set the payment instrument to pp rather than cc |
| 169 | + $utm_source_parts = explode( ".", $data['utm_source'] ); |
| 170 | + $utm_source_parts[2] = 'pp'; |
| 171 | + $data['utm_source'] = implode( ".", $utm_source_parts ); |
| 172 | + $data['gateway'] = 'paypal'; |
| 173 | + $data['currency_code'] = $data['currency']; |
| 174 | + /** |
| 175 | + * update contribution tracking |
| 176 | + */ |
| 177 | + $this->updateContributionTracking( $data, true ); |
| 178 | + |
| 179 | + $wgPayflowProGatewayPaypalURL .= "/" . $data['language'] . "?gateway=paypal"; |
| 180 | + |
| 181 | + // submit the data to the paypal redirect URL |
| 182 | + $wgOut->redirect( $wgPayflowProGatewayPaypalURL . '&' . http_build_query( $data ) ); |
| 183 | + } |
| 184 | + |
| 185 | + public static function log( $msg, $log_level=LOG_INFO ) { |
| 186 | + $this->adapter->log( $msg, $log_level ); |
| 187 | + } |
| 188 | + |
| 189 | +} |
| 190 | + |
| 191 | +// end class |
Property changes on: branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect_resultswitcher.body.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 192 | + native |
Index: branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php |
— | — | @@ -12,14 +12,14 @@ |
13 | 13 | */ |
14 | 14 | function stageData() { |
15 | 15 | $this->postdata['amount'] = $this->postdata['amount'] * 100; |
16 | | - |
| 16 | + |
17 | 17 | $card_type = ''; |
18 | | - if (array_key_exists('card_type', $this->postdata) && !empty($this->postdata['card_type'])){ |
| 18 | + if ( array_key_exists( 'card_type', $this->postdata ) && !empty( $this->postdata['card_type'] ) ) { |
19 | 19 | $card_type = $this->postdata['card_type']; |
20 | 20 | } else { |
21 | 21 | $card_type = $this->postdatadefaults['card_type']; |
22 | 22 | } |
23 | | - |
| 23 | + |
24 | 24 | switch ( $card_type ) { |
25 | 25 | case 'visa': |
26 | 26 | $this->postdata['card_type'] = 1; |
— | — | @@ -34,19 +34,18 @@ |
35 | 35 | $this->postdata['card_type'] = 128; |
36 | 36 | break; |
37 | 37 | } |
38 | | - |
| 38 | + |
39 | 39 | $this->postdata['expiry'] = $this->postdata['expiration']; //. ($this->postdata['year'] % 100); |
40 | | - $this->postdata['card_num'] = str_replace(' ', '', $this->postdata['card_num']); |
41 | | - |
| 40 | + $this->postdata['card_num'] = str_replace( ' ', '', $this->postdata['card_num'] ); |
| 41 | + |
42 | 42 | $returnto = ''; |
43 | | - if (array_key_exists('returnto', $this->postdata)){ |
| 43 | + if ( array_key_exists( 'returnto', $this->postdata ) ) { |
44 | 44 | $returnto = $this->postdata['returnto']; |
45 | 45 | } else { |
46 | 46 | $returnto = $this->postdatadefaults['returnto']; |
47 | 47 | } |
48 | | - |
| 48 | + |
49 | 49 | $this->postdata['returnto'] = $returnto . "?order_id=" . $this->postdata['order_id']; |
50 | | - |
51 | 50 | } |
52 | 51 | |
53 | 52 | function defineAccountInfo() { |
— | — | @@ -70,7 +69,7 @@ |
71 | 70 | 'PAYMENTPRODUCTID' => 'card_type', |
72 | 71 | 'CVV' => 'cvv', |
73 | 72 | 'EXPIRYDATE' => 'expiry', |
74 | | - 'CREDITCARDNUMBER' => 'card_num', |
| 73 | + 'CREDITCARDNUMBER' => 'card_num', |
75 | 74 | 'FIRSTNAME' => 'fname', |
76 | 75 | 'SURNAME' => 'lname', |
77 | 76 | 'STREET' => 'street', |
— | — | @@ -86,6 +85,19 @@ |
87 | 86 | 'OK' => true, |
88 | 87 | 'NOK' => false, |
89 | 88 | ); |
| 89 | + $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'pending', 0, 70 ); |
| 90 | + $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'failed', 100, 180 ); |
| 91 | + $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'pending', 200 ); |
| 92 | + $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'failed', 220, 280 ); |
| 93 | + $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'pending', 300 ); |
| 94 | + $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'failed', 310, 350 ); |
| 95 | + $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'revised', 400 ); |
| 96 | + $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'pending_poke', 525 ); |
| 97 | + $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'pending', 550, 850 ); |
| 98 | + $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'pending', 900 ); //There's two 900s in the doc. The heck? |
| 99 | + $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'pending', 950, 975 ); |
| 100 | + $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'complete', 1000, 1050 ); |
| 101 | + $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'failed', 1100, 99999 ); |
90 | 102 | } |
91 | 103 | |
92 | 104 | function defineTransactions() { |
— | — | @@ -235,22 +247,23 @@ |
236 | 248 | */ |
237 | 249 | function getResponseData( $response ) { |
238 | 250 | $data = array( ); |
239 | | - |
| 251 | + |
240 | 252 | $transaction = $this->currentTransaction(); |
241 | 253 | |
242 | 254 | switch ( $transaction ) { |
243 | 255 | case 'INSERT_ORDERWITHPAYMENT': |
244 | | - $data = $this->xmlChildrenToArray($response, 'ROW'); |
245 | | - $data['ORDER'] = $this->xmlChildrenToArray($response, 'ORDER'); |
246 | | - $data['PAYMENT'] = $this->xmlChildrenToArray($response, 'PAYMENT'); |
| 256 | + $data = $this->xmlChildrenToArray( $response, 'ROW' ); |
| 257 | + $data['ORDER'] = $this->xmlChildrenToArray( $response, 'ORDER' ); |
| 258 | + $data['PAYMENT'] = $this->xmlChildrenToArray( $response, 'PAYMENT' ); |
247 | 259 | break; |
248 | 260 | case 'GET_ORDERSTATUS': |
249 | | - $data = $this->xmlChildrenToArray($response, 'STATUS'); |
250 | | - $data['ORDER'] = $this->xmlChildrenToArray($response, 'ORDER'); |
| 261 | + $data = $this->xmlChildrenToArray( $response, 'STATUS' ); |
| 262 | + $data['WMF_TRANSLATEDCODE'] = $this->findCodeAction( 'GET_ORDERSTATUS', 'STATUSID', $data['STATUSID'] ); |
| 263 | + $data['ORDER'] = $this->xmlChildrenToArray( $response, 'ORDER' ); |
251 | 264 | break; |
252 | 265 | } |
253 | | - |
254 | | - |
| 266 | + |
| 267 | + |
255 | 268 | self::log( "Returned Data: " . print_r( $data, true ) ); |
256 | 269 | return $data; |
257 | 270 | } |
Index: branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect_gateway.php |
— | — | @@ -23,12 +23,14 @@ |
24 | 24 | // Set up the new special page |
25 | 25 | $dir = dirname( __FILE__ ) . '/'; |
26 | 26 | $wgAutoloadClasses['GlobalCollectGateway'] = $dir . 'globalcollect_gateway.body.php'; |
| 27 | +$wgAutoloadClasses['GlobalCollectGatewayResult'] = $dir . 'globalcollect_resultswitcher.body.php'; |
27 | 28 | $wgAutoloadClasses['GlobalCollectAdapter'] = $dir . 'globalcollect.adapter.php'; |
28 | 29 | $wgExtensionMessagesFiles['GlobalCollectGateway'] = $dir . '../payflowpro_gateway/payflowpro_gateway.i18n.php'; |
29 | 30 | $wgExtensionMessagesFiles['GlobalCollectGatewayCountries'] = $dir . '../payflowpro_gateway/payflowpro_gateway.countries.i18n.php'; |
30 | 31 | $wgExtensionMessagesFiles['GlobalCollectGatewayUSStates'] = $dir . '../payflowpro_gateway/payflowpro_gateway.us-states.i18n.php'; |
31 | 32 | $wgExtensionAliasesFiles['GlobalCollectGateway'] = $dir . '../payflowpro_gateway/payflowpro_gateway.alias.php'; |
32 | 33 | $wgSpecialPages['GlobalCollectGateway'] = 'GlobalCollectGateway'; |
| 34 | +$wgSpecialPages['GlobalCollectGatewayResult'] = 'GlobalCollectGatewayResult'; |
33 | 35 | //$wgAjaxExportList[] = "fnGlobalCollectofofWork"; |
34 | 36 | // set defaults, these should be assigned in LocalSettings.php |
35 | 37 | $wgGlobalCollectGatewayURL = 'https://ps.gcsip.nl/wdl/wdl'; |
Index: branches/fundraising/extensions/DonationInterface/modules/iframe.liberator.js |
— | — | @@ -0,0 +1,4 @@ |
| 2 | + |
| 3 | +if (top.frames.length!=0){ |
| 4 | + top.location=self.document.location; |
| 5 | +} |
\ No newline at end of file |
Property changes on: branches/fundraising/extensions/DonationInterface/modules/iframe.liberator.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 6 | + native |
Index: branches/fundraising/extensions/DonationInterface/gateway_common/gateway.adapter.php |
— | — | @@ -124,8 +124,8 @@ |
125 | 125 | * Override this in children if you want different defaults. |
126 | 126 | */ |
127 | 127 | function setPostDefaults() { |
128 | | - $returnTitle = Title::newFromText( 'Donate-thanks/en' ); |
129 | | -// $returnTitle = Title::newFromText( 'Special:GlobalCollectGateway' ); |
| 128 | +// $returnTitle = Title::newFromText( 'Donate-thanks/en' ); |
| 129 | + $returnTitle = Title::newFromText( 'Special:GlobalCollectGatewayResult' ); |
130 | 130 | $returnto = $returnTitle->getFullURL(); |
131 | 131 | |
132 | 132 | $this->postdatadefaults = array( |
— | — | @@ -192,7 +192,7 @@ |
193 | 193 | |
194 | 194 | //If there's a value in the post data (name-translated by the var_map), use that. |
195 | 195 | if ( array_key_exists( $gateway_field_name, $this->var_map ) ) { |
196 | | - if ($token === true){ //we just want the field name to use, so short-circuit all that mess. |
| 196 | + if ( $token === true ) { //we just want the field name to use, so short-circuit all that mess. |
197 | 197 | return '@' . $this->var_map[$gateway_field_name]; |
198 | 198 | } |
199 | 199 | if ( array_key_exists( $this->var_map[$gateway_field_name], $this->postdata ) && |
— | — | @@ -249,9 +249,9 @@ |
250 | 250 | $node->appendChild( $temp ); |
251 | 251 | } |
252 | 252 | } |
253 | | - |
| 253 | + |
254 | 254 | //TODO: You can actually take this out if we never ever want to use ajax for a gateway. |
255 | | - function buildTransactionFormat($transaction){ |
| 255 | + function buildTransactionFormat( $transaction ) { |
256 | 256 | $this->currentTransaction( $transaction ); |
257 | 257 | $this->xmlDoc = new DomDocument( '1.0' ); |
258 | 258 | $node = $this->xmlDoc->createElement( 'XML' ); |
— | — | @@ -261,34 +261,34 @@ |
262 | 262 | $this->buildTransactionNodes( $structure, $node, true ); |
263 | 263 | $this->xmlDoc->appendChild( $node ); |
264 | 264 | $xml = $this->xmlDoc->saveXML(); |
265 | | - $xmlStart = strpos($xml, "<XML>"); |
266 | | - self::log("XML START" . $xmlStart); |
| 265 | + $xmlStart = strpos( $xml, "<XML>" ); |
| 266 | + self::log( "XML START" . $xmlStart ); |
267 | 267 | $xml = substr( $xml, $xmlStart ); |
268 | | - self::log("XML stubby thing..." . $xml); |
269 | | - |
| 268 | + self::log( "XML stubby thing..." . $xml ); |
| 269 | + |
270 | 270 | return $xml; |
271 | 271 | } |
272 | | - |
| 272 | + |
273 | 273 | function do_transaction( $transaction ) { |
274 | 274 | $this->currentTransaction( $transaction ); |
275 | 275 | //update the contribution tracking data |
276 | 276 | $this->dataObj->updateContributionTracking( defined( 'OWA' ) ); |
277 | 277 | if ( $this->getCommunicationType() === 'xml' ) { |
278 | | - $this->getStopwatch(__FUNCTION__); |
| 278 | + $this->getStopwatch( "buildRequestXML" ); |
279 | 279 | $xml = $this->buildRequestXML(); |
280 | | - $this->saveCommunicationStats(__FUNCTION__, "Building Request XML", "Transaction = $transaction"); |
| 280 | + $this->saveCommunicationStats( "buildRequestXML", $transaction ); |
281 | 281 | $returned = $this->curl_transaction( $xml ); |
282 | 282 | //put the response in a universal form, and return it. |
283 | 283 | } |
284 | 284 | |
285 | 285 | if ( $this->getCommunicationType() === 'namevalue' ) { |
286 | 286 | $namevalue = $this->postdata; |
287 | | - $this->getStopwatch(__FUNCTION__); |
| 287 | + $this->getStopwatch( __FUNCTION__ ); |
288 | 288 | $returned = $this->curl_transaction( $namevalue ); |
289 | 289 | $this->saveCommunicationStats(); |
290 | 290 | //put the response in a universal form, and return it. |
291 | 291 | } |
292 | | - |
| 292 | + |
293 | 293 | self::log( "RETURNED FROM CURL:" . print_r( $returned, true ) ); |
294 | 294 | if ( $returned['result'] === false ) { //couldn't make contact. Bail. |
295 | 295 | return $returned; |
— | — | @@ -376,8 +376,8 @@ |
377 | 377 | */ |
378 | 378 | protected function curl_transaction( $data ) { |
379 | 379 | // assign header data necessary for the curl_setopt() function |
380 | | - $this->getStopwatch(__FUNCTION__, true); |
381 | | - |
| 380 | + $this->getStopwatch( __FUNCTION__, true ); |
| 381 | + |
382 | 382 | $ch = curl_init(); |
383 | 383 | |
384 | 384 | $headers = $this->getCurlBaseHeaders(); |
— | — | @@ -413,8 +413,8 @@ |
414 | 414 | } |
415 | 415 | } |
416 | 416 | |
417 | | - $this->saveCommunicationStats(__FUNCTION__, $this->currentTransaction(), "Request:" . print_r($data, true) . "\nResponse" . print_r($return, true)); |
418 | | - |
| 417 | + $this->saveCommunicationStats( __FUNCTION__, $this->currentTransaction(), "Request:" . print_r( $data, true ) . "\nResponse" . print_r( $return, true ) ); |
| 418 | + |
419 | 419 | if ( $return['headers']['http_code'] != 200 ) { |
420 | 420 | $return['result'] = false; |
421 | 421 | //TODO: i18n here! |
— | — | @@ -516,19 +516,19 @@ |
517 | 517 | $c = get_called_class(); |
518 | 518 | return $c::IDENTIFIER; |
519 | 519 | } |
520 | | - |
521 | | - public function getStopwatch($string, $reset = false){ |
| 520 | + |
| 521 | + public function getStopwatch( $string, $reset = false ) { |
522 | 522 | static $start = null; |
523 | | - $now = microtime(true); |
| 523 | + $now = microtime( true ); |
524 | 524 | |
525 | | - if ($start == null || $reset === true){ |
| 525 | + if ( $start == null || $reset === true ) { |
526 | 526 | $start = $now; |
527 | 527 | } |
528 | | - $clock = round($now - $start, 4); |
529 | | - self::log("\nClock at $string: $clock ($now)"); |
| 528 | + $clock = round( $now - $start, 4 ); |
| 529 | + self::log( "\nClock at $string: $clock ($now)" ); |
530 | 530 | return $clock; |
531 | 531 | } |
532 | | - |
| 532 | + |
533 | 533 | /** |
534 | 534 | * |
535 | 535 | * @param type $function |
— | — | @@ -536,12 +536,12 @@ |
537 | 537 | * @param type $vars |
538 | 538 | */ |
539 | 539 | function saveCommunicationStats( $function = '', $additional = '', $vars = '' ) { //easier than looking at logs... |
540 | | - $params = array(); |
541 | | - if (self::getGlobal('SaveCommStats')){ //TODO: I should do this for real at some point. |
| 540 | + $params = array( ); |
| 541 | + if ( self::getGlobal( 'SaveCommStats' ) ) { //TODO: I should do this for real at some point. |
542 | 542 | $db = ContributionTrackingProcessor::contributionTrackingConnection(); |
543 | 543 | $params['contribution_id'] = $this->dataObj->getVal( 'contribution_tracking_id' ); |
544 | 544 | $params['ts'] = $db->timestamp(); |
545 | | - $params['duration'] = $this->getStopwatch(__FUNCTION__); |
| 545 | + $params['duration'] = $this->getStopwatch( __FUNCTION__ ); |
546 | 546 | $params['gateway'] = self::getGatewayName(); |
547 | 547 | $params['function'] = $function; |
548 | 548 | $params['vars'] = $vars; |
— | — | @@ -551,11 +551,10 @@ |
552 | 552 | |
553 | 553 | $db->insert( 'communication_stats', $params ); |
554 | 554 | } |
| 555 | + } |
555 | 556 | |
556 | | - } |
557 | | - |
558 | | - function xmlChildrenToArray($xml, $nodename){ |
559 | | - $data = array(); |
| 557 | + function xmlChildrenToArray( $xml, $nodename ) { |
| 558 | + $data = array( ); |
560 | 559 | foreach ( $xml->getElementsByTagName( $nodename ) as $node ) { |
561 | 560 | foreach ( $node->childNodes as $childnode ) { |
562 | 561 | if ( trim( $childnode->nodeValue ) != '' ) { |
— | — | @@ -566,4 +565,59 @@ |
567 | 566 | return $data; |
568 | 567 | } |
569 | 568 | |
| 569 | + /** |
| 570 | + * DO NOT DEFINE OVERLAPPING RANGES! |
| 571 | + * TODO: Make sure it won't let you add overlapping ranges. That would probably necessitate the sort moving to here, too. |
| 572 | + * @param type $transaction |
| 573 | + * @param type $key |
| 574 | + * @param type $action |
| 575 | + * @param type $lower |
| 576 | + * @param type $upper |
| 577 | + */ |
| 578 | + function addCodeRange( $transaction, $key, $action, $lower, $upper = null ) { |
| 579 | + if ( $upper === null ) { |
| 580 | + $this->return_value_map[$transaction][$key][$lower] = $action; |
| 581 | + } else { |
| 582 | + $this->return_value_map[$transaction][$key][$upper] = array( 'action' => $action, 'lower' => $lower ); |
| 583 | + } |
| 584 | + } |
| 585 | + |
| 586 | + function findCodeAction( $transaction, $key, $code ) { |
| 587 | + $this->getStopwatch( __FUNCTION__, true ); |
| 588 | + if ( !array_key_exists( $transaction, $this->return_value_map ) || !array_key_exists( $key, $this->return_value_map[$transaction] ) ) { |
| 589 | + return null; |
| 590 | + } |
| 591 | + if ( !is_array( $this->return_value_map[$transaction][$key] ) ) { |
| 592 | + return null; |
| 593 | + } |
| 594 | + //sort the array so we can do this quickly. |
| 595 | + ksort( $this->return_value_map[$transaction][$key], SORT_NUMERIC ); |
| 596 | + |
| 597 | + $ranges = $this->return_value_map[$transaction][$key]; |
| 598 | + //so, you have a code, which is a number. You also have a numerically sorted array. |
| 599 | + //loop through until you find an upper >= your code. |
| 600 | + //make sure it's in the range, and return the action. |
| 601 | + foreach ( $ranges as $upper => $val ) { |
| 602 | + if ( $upper >= $code ) { //you've arrived. It's either here or it's nowhere. |
| 603 | + if ( is_array( $val ) ) { |
| 604 | + if ( $val['lower'] <= $code ) { |
| 605 | + $this->saveCommunicationStats( __FUNCTION__, $transaction, "code = $code" ); |
| 606 | + return $val['action']; |
| 607 | + } else { |
| 608 | + return null; |
| 609 | + } |
| 610 | + } else { |
| 611 | + if ( $upper === $code ) { |
| 612 | + $this->saveCommunicationStats( __FUNCTION__, $transaction, "code = $code" ); |
| 613 | + return $val; |
| 614 | + } else { |
| 615 | + return null; |
| 616 | + } |
| 617 | + } |
| 618 | + } |
| 619 | + } |
| 620 | + //if we walk straight off the end... |
| 621 | + return null; |
| 622 | + } |
| 623 | + |
570 | 624 | } |