r97780 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97779‎ | r97780 | r97781 >
Date:02:02, 22 September 2011
Author:khorn
Status:resolved (Comments)
Tags:fundraising 
Comment:
Card #282, and a significant redefinition of what it means to stage gateway data (we get to do it backwards now! Yes!)
Modified paths:
  • /branches/fundraising/extensions/DonationInterface/activemq_stomp/Stomp.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/activemq_stomp/activemq_stomp.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/donationinterface.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/gateway_common/DonationData.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/gateway_common/gateway.adapter.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/gateway_forms/Form.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect_gateway.body.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect_resultswitcher.body.php (modified) (history)

Diff [purge]

Index: branches/fundraising/extensions/DonationInterface/donationinterface.php
@@ -21,6 +21,7 @@
2222 $donationinterface_dir = dirname( __FILE__ ) . '/';
2323
2424 require_once( $donationinterface_dir . 'donate_interface/donate_interface.php' );
 25+require_once( $donationinterface_dir . 'activemq_stomp/activemq_stomp.php' );
2526
2627
2728 /**
Index: branches/fundraising/extensions/DonationInterface/gateway_forms/Form.php
@@ -127,7 +127,8 @@
128128 * @return array
129129 */
130130 public function getCountries() {
131 - return PayflowProGateway::getCountries();
 131+ require_once( dirname( __FILE__ ) . '/includes/countryCodes.inc' );
 132+ return countryCodes();
132133 }
133134
134135 /**
Index: branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect_resultswitcher.body.php
@@ -42,13 +42,13 @@
4343 $wgPayFlowProGatewayCSSVersion;
4444
4545 $referrer = $wgRequest->getHeader( 'referer' );
46 -
 46+
4747 global $wgServer;
4848 //TODO: Whitelist! We only want to do this for servers we are configured to like!
4949 //I didn't do this already, because this may turn out to be backwards anyway. It might be good to do the work in the iframe,
5050 //and then pop out. Maybe. We're probably going to have to test it a couple different ways, for user experience.
5151 //However, we're _definitely_ going to need to pop out _before_ we redirect to the thank you or fail pages.
52 - if ( strpos( $referrer, $wgServer ) === false ) {
 52+ if ( strpos( $referrer, $wgServer ) === false ) {
5353 $wgOut->allowClickjacking();
5454 $wgOut->addModules( 'iframe.liberator' );
5555 return;
@@ -96,8 +96,8 @@
9797 $go = $this->adapter->getFailPage();
9898 break;
9999 }
100 -
101 - //TODO: Save your user session data before you get here...
 100+ $this->adapter->doStompTransaction( $result['data'], $result['message'], $result['data']['WMF_STATUS'], true );
 101+
102102 $this->adapter->unsetAllGatewaySessionData();
103103 $wgOut->addHTML( "<br>Redirecting to page $go" );
104104 $wgOut->redirect( $go );
Index: branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect_gateway.body.php
@@ -103,11 +103,10 @@
104104 if ( $this->adapter->checkTokens() ) {
105105 if ( $this->adapter->posted && $data['payment_method'] == 'processed' ) {
106106 // The form was submitted and the payment method has been set
107 - $this->adapter->log("Form posted and payment method set.");
 107+ $this->adapter->log( "Form posted and payment method set." );
108108
109109 // increase the count of attempts
110110 //++$data['numAttempt'];
111 -
112111 // Check form for errors
113112 $form_errors = $this->fnPayflowValidateForm( $data, $this->errors );
114113
@@ -119,14 +118,13 @@
120119 $result = $this->adapter->do_transaction( 'INSERT_ORDERWITHPAYMENT' );
121120 $this->adapter->addDonorDataToSession();
122121 //$result = $this->adapter->do_transaction( 'TEST_CONNECTION' );
123 -
124 - $this->displayResultsForDebug($result);
125122
 123+ $this->displayResultsForDebug( $result );
 124+
126125 if ( !empty( $result['data'] ) ) {
127 -
128 - if (array_key_exists('FORMACTION', $result['data'])){
129 - $paymentFrame = Xml::openElement( 'iframe',
130 - array(
 126+
 127+ if ( array_key_exists( 'FORMACTION', $result['data'] ) ) {
 128+ $paymentFrame = Xml::openElement( 'iframe', array(
131129 'id' => 'globalcollectframe',
132130 'name' => 'globalcollectframe',
133131 'width' => '680',
@@ -134,12 +132,11 @@
135133 'frameborder' => '0',
136134 'style' => 'display:block;',
137135 'src' => $result['data']['FORMACTION']
138 - )
 136+ )
139137 );
140138 $paymentFrame .= Xml::closeElement( 'iframe' );
141139
142140 $wgOut->addHTML( $paymentFrame );
143 -
144141 }
145142 }
146143
@@ -183,11 +180,10 @@
184181 } else {
185182 // Display form for the first time
186183 $oid = $wgRequest->getText( 'order_id' );
187 - if ($oid && !empty($oid)){
188 - $wgOut->addHTML("<pre>CAME BACK FROM SOMETHING.</pre>");
 184+ if ( $oid && !empty( $oid ) ) {
 185+ $wgOut->addHTML( "<pre>CAME BACK FROM SOMETHING.</pre>" );
189186 $result = $this->adapter->do_transaction( 'GET_ORDERSTATUS' );
190 - $this->displayResultsForDebug($result);
191 -
 187+ $this->displayResultsForDebug( $result );
192188 }
193189 $this->adapter->log( "Not posted, or not processed. Showing the form for the first time." );
194190 $this->fnPayflowDisplayForm( $data, $this->errors );
@@ -200,11 +196,11 @@
201197 $this->fnPayflowDisplayForm( $data, $this->errors );
202198 }
203199 }
204 -
205 - function displayResultsForDebug($results){
 200+
 201+ function displayResultsForDebug( $results ) {
206202 global $wgOut;
207203 $wgOut->addHTML( $results['message'] );
208 -
 204+
209205 if ( !empty( $results['errors'] ) ) {
210206 $wgOut->addHTML( "<ul>" );
211207 foreach ( $results['errors'] as $code => $value ) {
@@ -212,13 +208,13 @@
213209 }
214210 $wgOut->addHTML( "</ul>" );
215211 }
216 -
 212+
217213 if ( !empty( $results['data'] ) ) {
218214 $wgOut->addHTML( "<ul>" );
219215 foreach ( $results['data'] as $key => $value ) {
220 - if (is_array($value)){
 216+ if ( is_array( $value ) ) {
221217 $wgOut->addHTML( "<li>$key:<ul>" );
222 - foreach ($value as $key2 => $val2){
 218+ foreach ( $value as $key2 => $val2 ) {
223219 $wgOut->addHTML( "<li>$key2: $val2" );
224220 }
225221 $wgOut->addHTML( "</ul>" );
@@ -228,16 +224,16 @@
229225 }
230226 $wgOut->addHTML( "</ul>" );
231227 } else {
232 - $wgOut->addHTML("Empty Results");
 228+ $wgOut->addHTML( "Empty Results" );
233229 }
234 - if (array_key_exists('Donor', $_SESSION)){
235 - $wgOut->addHTML("Session Donor Vars:<ul>");
236 - foreach ($_SESSION['Donor'] as $key=>$val){
 230+ if ( array_key_exists( 'Donor', $_SESSION ) ) {
 231+ $wgOut->addHTML( "Session Donor Vars:<ul>" );
 232+ foreach ( $_SESSION['Donor'] as $key => $val ) {
237233 $wgOut->addHTML( "<li>$key: $val" );
238234 }
239 - $wgOut->addHTML("</ul>");
 235+ $wgOut->addHTML( "</ul>" );
240236 } else {
241 - $wgOut->addHTML("No Session Donor Vars:<ul>");
 237+ $wgOut->addHTML( "No Session Donor Vars:<ul>" );
242238 }
243239 }
244240
@@ -509,8 +505,6 @@
510506 * @return array
511507 */
512508 public function prepareStompTransaction( $data, $responseArray, $responseMsg ) {
513 - $countries = $this->getCountries();
514 -
515509 $transaction = array( );
516510
517511 // include response message
Index: branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php
@@ -6,48 +6,6 @@
77 const COMMUNICATION_TYPE = 'xml';
88 const GLOBAL_PREFIX = 'wgGlobalCollectGateway';
99
10 - /**
11 - * stageData should alter the postdata array in all ways necessary in preparation for
12 - * communication with the gateway.
13 - */
14 - function stageData() {
15 - $this->postdata['amount'] = $this->postdata['amount'] * 100;
16 -
17 - $card_type = '';
18 - if ( array_key_exists( 'card_type', $this->postdata ) && !empty( $this->postdata['card_type'] ) ) {
19 - $card_type = $this->postdata['card_type'];
20 - } else {
21 - $card_type = $this->postdatadefaults['card_type'];
22 - }
23 -
24 - switch ( $card_type ) {
25 - case 'visa':
26 - $this->postdata['card_type'] = 1;
27 - break;
28 - case 'mastercard':
29 - $this->postdata['card_type'] = 3;
30 - break;
31 - case 'american':
32 - $this->postdata['card_type'] = 2;
33 - break;
34 - case 'discover':
35 - $this->postdata['card_type'] = 128;
36 - break;
37 - }
38 -
39 - $this->postdata['expiry'] = $this->postdata['expiration']; //. ($this->postdata['year'] % 100);
40 - $this->postdata['card_num'] = str_replace( ' ', '', $this->postdata['card_num'] );
41 -
42 - $returnto = '';
43 - if ( array_key_exists( 'returnto', $this->postdata ) ) {
44 - $returnto = $this->postdata['returnto'];
45 - } else {
46 - $returnto = $this->postdatadefaults['returnto'];
47 - }
48 -
49 - $this->postdata['returnto'] = $returnto . "?order_id=" . $this->postdata['order_id'];
50 - }
51 -
5210 function defineAccountInfo() {
5311 $this->accountInfo = array(
5412 'MERCHANTID' => self::getGlobal( 'MerchantID' ),
@@ -68,7 +26,7 @@
6927 'IPADDRESS' => 'user_ip', //TODO: Not sure if this should be OUR ip, or the user's ip. Hurm.
7028 'PAYMENTPRODUCTID' => 'card_type',
7129 'CVV' => 'cvv',
72 - 'EXPIRYDATE' => 'expiry',
 30+ 'EXPIRYDATE' => 'expiration',
7331 'CREDITCARDNUMBER' => 'card_num',
7432 'FIRSTNAME' => 'fname',
7533 'SURNAME' => 'lname',
@@ -273,4 +231,58 @@
274232 //TODO: Stuff.
275233 }
276234
277 -}
 235+ function defineStagedVars() {
 236+ //OUR field names.
 237+ $this->staged_vars = array(
 238+ 'amount',
 239+ 'card_type',
 240+ 'card_num',
 241+ 'returnto',
 242+ 'order_id', //This may or may not oughta-be-here...
 243+ );
 244+ }
 245+
 246+ protected function stage_amount( $type = 'request' ) {
 247+ switch ( $type ) {
 248+ case 'request':
 249+ $this->postdata['amount'] = $this->postdata['amount'] * 100;
 250+ break;
 251+ case 'response':
 252+ $this->postdata['amount'] = $this->postdata['amount'] / 100;
 253+ break;
 254+ }
 255+ }
 256+
 257+ protected function stage_card_type( $type = 'request' ) {
 258+
 259+ $types = array(
 260+ 'visa' => '1',
 261+ 'mastercard' => '3',
 262+ 'american' => '2',
 263+ 'discover' => '128'
 264+ );
 265+
 266+ if ( $type === 'response' ) {
 267+ $types = array_flip( $types );
 268+ }
 269+
 270+ if ( array_key_exists( $this->postdata['card_type'], $types ) ) {
 271+ $this->postdata['card_type'] = $types[$this->postdata['card_type']];
 272+ } else {
 273+ //$this->postdata['card_type'] = '';
 274+ //iono: maybe nothing?
 275+ }
 276+ }
 277+
 278+ protected function stage_card_num( $type = 'request' ) {
 279+ //I realize that the $type isn't used. Voodoo.
 280+ $this->postdata['card_num'] = str_replace( ' ', '', $this->postdata['card_num'] );
 281+ }
 282+
 283+ protected function stage_returnto( $type = 'request' ) {
 284+ if ( $type === 'request' ) {
 285+ $this->postdata['returnto'] = $this->postdata['returnto'] . "?order_id=" . $this->postdata['order_id'];
 286+ }
 287+ }
 288+
 289+}
\ No newline at end of file
Index: branches/fundraising/extensions/DonationInterface/gateway_common/gateway.adapter.php
@@ -35,9 +35,10 @@
3636 function processResponse( $response );
3737
3838 /**
39 - * Anything we need to do to the data coming in, before we send it off.
 39+ * Should be a list of our variables that need special staging.
 40+ * Define $this->staged_vars
4041 */
41 - function stageData();
 42+ function defineStagedVars();
4243
4344 /**
4445 * defineTransactions will define the $transactions array.
@@ -645,4 +646,84 @@
646647 $this->dataObj->unsetAllDDSessionData();
647648 }
648649
 650+ function doStompTransaction( $responseArray, $responseMsg, $status, $useSession = false ) {
 651+ $hook = '';
 652+ switch ( $status ) {
 653+ case 'complete':
 654+ $hook = 'gwStomp';
 655+ break;
 656+ case 'pending':
 657+ case 'pending-poke':
 658+ $hook = 'gwPendingStomp';
 659+ break;
 660+ }
 661+ if ( $hook === '' ) {
 662+ return;
 663+ }
 664+
 665+ foreach ( $responseArray as $key => $val ) {
 666+ if ( array_key_exists( $key, $this->var_map ) ) {
 667+ $responseArray[$this->var_map[$key]] = $val;
 668+ unset( $responseArray[$key] );
 669+ }
 670+ }
 671+
 672+ //Gah. I might want to move all this data prep business upstream more than somewhat.
 673+ //...but that's for later.
 674+ // Add the session vars to the data object
 675+ if ( $useSession ) {
 676+ $this->dataObj->populateDonorFromSession();
 677+ }
 678+
 679+ // Add our response vars to the data object.
 680+ $this->dataObj->addData( $responseArray );
 681+
 682+ // refresh our data
 683+ $this->postdata = $this->dataObj->getData();
 684+
 685+ // stage the gateway data
 686+ $this->stageData( 'response' );
 687+
 688+ // send the thing.
 689+ $transaction = array(
 690+ 'response' => $responseMsg,
 691+ 'date' => time(),
 692+ );
 693+ $transaction += $this->getData();
 694+
 695+ self::log( "Intended STOMP transaction: " . print_r( $transaction, true ) );
 696+
 697+ wfRunHooks( $hook, array( $transaction ) );
 698+ }
 699+
 700+ function smooshVarsForStaging() {
 701+
 702+ foreach ( $this->staged_vars as $field ) {
 703+ if ( !array_key_exists( $field, $this->postdata ) || empty( $this->postdata[$field] ) ) {
 704+ if ( array_key_exists( $field, $this->postdatadefaults ) ) {
 705+ $this->postdata[$field] = $this->postdatadefaults[$field];
 706+ }
 707+ }
 708+ //what do we do in the event that we're still nothing? (just move on.)
 709+ }
 710+ }
 711+
 712+ /**
 713+ *
 714+ * @param type $type Whatever types of staging you feel like having in your child class.
 715+ * ...but usually request and response. I think.
 716+ */
 717+ function stageData( $type = 'request' ) {
 718+ $this->defineStagedVars();
 719+ $this->smooshVarsForStaging(); //yup, we do need to do this seperately.
 720+ //If we tried to piggyback off the same loop, all the vars wouldn't be ready, and some staging functions will require
 721+ //multiple variables.
 722+ foreach ( $this->staged_vars as $field ) {
 723+ $function_name = 'stage_' . $field;
 724+ if ( method_exists( $this, $function_name ) ) {
 725+ $this->{$function_name}( $type );
 726+ }
 727+ }
 728+ }
 729+
649730 }
Index: branches/fundraising/extensions/DonationInterface/gateway_common/DonationData.php
@@ -29,13 +29,8 @@
3030 }
3131 $this->doCacheStuff();
3232
 33+ $this->normalizeAndSanitize();
3334
34 - if ( !empty( $this->normalized ) ) {
35 - $this->setNormalizedAmount();
36 - $this->setNormalizedOrderIDs();
37 - $this->setGateway();
38 - array_walk( $this->normalized, array( $this, 'sanitizeInput' ) );
39 - }
4035 //TODO: determine if _nocache_ is still a thing anywhere.
4136 if ( !empty( $this->normalized ) && ( $this->getVal( 'numAttempt' ) == '0' && ((!$this->getVal( 'utm_source_id' ) == false ) || $this->getVal( '_nocache_' ) == 'true' ) ) ) {
4237 $this->saveContributionTracking();
@@ -209,6 +204,16 @@
210205 }
211206 }
212207
 208+ function normalizeAndSanitize() {
 209+ if ( !empty( $this->normalized ) ) {
 210+ $this->setNormalizedAmount();
 211+ $this->setNormalizedOrderIDs();
 212+ $this->setGateway();
 213+ $this->setNormalizedOptOuts();
 214+ array_walk( $this->normalized, array( $this, 'sanitizeInput' ) );
 215+ }
 216+ }
 217+
213218 function setNormalizedAmount() {
214219
215220 if ( !($this->isSomething( 'amount' )) || !(preg_match( '/^\d+(\.(\d+)?)?$/', $this->getVal( 'amount' ) ) ) ) {
@@ -244,7 +249,6 @@
245250 }
246251
247252 $this->setVal( 'order_id', $this->generateOrderId() );
248 -
249253 if ( !$this->isSomething( 'i_order_id' ) ) {
250254 $this->setVal( 'i_order_id', $this->generateOrderId() );
251255 }
@@ -526,10 +530,14 @@
527531 * are backwards (they are really opt-in) relative to contribution_tracking
528532 * (which is opt-out), we need to reverse the values
529533 */
530 - public function getOptOuts() {
 534+ function setNormalizedOptOuts() {
531535 $optout['optout'] = ( $this->isSomething( 'email-opt' ) && $this->getVal( 'email-opt' ) == "1" ) ? '0' : '1';
532536 $optout['anonymous'] = ( $this->isSomething( 'comment-option' ) && $this->getVal( 'comment-option' ) == "1" ) ? '0' : '1';
533 - return $optout;
 537+ foreach ( $optout as $thing => $stuff ) {
 538+ $this->setVal( $thing, $stuff );
 539+ }
 540+ $this->expunge( 'email-opt' );
 541+ $this->expunge( 'comment-option' );
534542 }
535543
536544 /**
@@ -540,7 +548,7 @@
541549 * 'null' values.
542550 * @param bool $clean_opouts
543551 */
544 - public function getCleanTrackingData( $clean_optouts = false ) {
 552+ public function getCleanTrackingData() {
545553
546554 // define valid tracking fields
547555 $tracking_fields = array(
@@ -563,13 +571,6 @@
564572 }
565573 }
566574
567 - // clean up the optout values if necessary
568 - if ( $clean_optouts ) {
569 - $optouts = $this->getOptOuts();
570 - $tracking_data['optout'] = $optouts['optout'];
571 - $tracking_data['anonymous'] = $optouts['anonymous'];
572 - }
573 -
574575 return $tracking_data;
575576 }
576577
@@ -577,7 +578,7 @@
578579 //so, basically, if this is the first attempt. This seems to get called nowhere else.
579580 function saveContributionTracking() {
580581
581 - $tracked_contribution = $this->getCleanTrackingData( true );
 582+ $tracked_contribution = $this->getCleanTrackingData();
582583
583584 // insert tracking data and get the tracking id
584585 $result = self::insertContributionTracking( $tracked_contribution );
@@ -641,7 +642,7 @@
642643 return true;
643644 } ///wait, what? TODO: This line was straight copied from the _gateway.body. Find out if there's a good reason we're not returning false here.
644645
645 - $tracked_contribution = $this->getCleanTrackingData( true );
 646+ $tracked_contribution = $this->getCleanTrackingData();
646647
647648 // if contrib tracking id is not already set, we need to insert the data, otherwise update
648649 if ( !$this->getVal( 'contribution_tracking_id' ) ) {
@@ -673,6 +674,12 @@
674675 }
675676 }
676677
 678+ public function populateDonorFromSession() {
 679+ if ( array_key_exists( 'Donor', $_SESSION ) ) {
 680+ $this->addData( $_SESSION['Donor'] );
 681+ }
 682+ }
 683+
677684 /**
678685 * TODO: Consider putting all the session data for a gateway under something like
679686 * $_SESSION[$gateway_identifier]
@@ -683,6 +690,17 @@
684691 $this->unsetEditToken();
685692 }
686693
 694+ public function addData( $newdata ) {
 695+ if ( is_array( $newdata ) && !empty( $newdata ) ) {
 696+ foreach ( $newdata as $key => $val ) {
 697+ if ( !is_array( $val ) ) {
 698+ $this->setVal( $key, $val );
 699+ }
 700+ }
 701+ }
 702+ $this->normalizeAndSanitize();
 703+ }
 704+
687705 }
688706
689707 ?>
Index: branches/fundraising/extensions/DonationInterface/activemq_stomp/activemq_stomp.php
@@ -1,11 +1,12 @@
22 <?php
 3+
34 # Alert the user that this is not a valid entry point to MediaWiki if they try to access the special pages file directly.
45 if ( !defined( 'MEDIAWIKI' ) ) {
5 - echo <<<EOT
 6+ echo <<<EOT
67 To install my extension, put the following line in LocalSettings.php:
78 require_once( "\$IP/extensions/DonationInterface/activemq_stomp/activemq_stomp.php" );
89 EOT;
9 - exit( 1 );
 10+ exit( 1 );
1011 }
1112
1213 $wgExtensionCredits['other'][] = array(
@@ -19,15 +20,15 @@
2021 $dir = dirname( __FILE__ ) . '/';
2122
2223 $wgAutoloadClasses['activemq_stomp'] = $dir . 'activemq_stomp.php'; # Tell MediaWiki to load the extension body.
23 -
2424 // default variables that should be set in LocalSettings
2525 $wgStompServer = "";
2626
2727 $wgHooks['ParserFirstCallInit'][] = 'efStompSetup';
2828
2929 /*
30 -* Create <donate /> tag to include landing page donation form
31 -*/
 30+ * Create <donate /> tag to include landing page donation form
 31+ */
 32+
3233 function efStompSetup( &$parser ) {
3334 // redundant and causes Fatal Error
3435 // $parser->disableCache();
@@ -48,19 +49,20 @@
4950 }
5051
5152 /**
52 -* Hook to get user provided and order data
53 -*
54 -*/
 53+ * Hook to get user provided and order data
 54+ *
 55+ */
5556 $wgHooks['gwStomp'][] = 'sendSTOMP';
5657 $wgHooks['gwPendingStomp'][] = 'sendPendingSTOMP';
5758
5859 /*
59 -* Hook to send transaction information to ActiveMQ server
60 -*/
 60+ * Hook to send transaction information to ActiveMQ server
 61+ */
 62+
6163 function sendSTOMP( $transaction ) {
6264 global $wgStompServer, $wgStompQueueName;
6365
64 - $queueName = isset ( $wgStompQueueName ) ? $wgStompQueueName : 'test';
 66+ $queueName = isset( $wgStompQueueName ) ? $wgStompQueueName : 'test';
6567
6668 // include a library
6769 require_once( "Stomp.php" );
@@ -77,7 +79,7 @@
7880 $result = $con->send( "/queue/$queueName", $message, array( 'persistent' => 'true' ) );
7981
8082 if ( !$result ) {
81 - wfDebugLog( 'activemq_stomp', 'Send to Q failed for this message: ' . $message );
 83+ wfDebugLog( 'activemq_stomp', 'Send to Q failed for this message: ' . $message );
8284 }
8385
8486 $con->disconnect();
@@ -86,12 +88,13 @@
8789 }
8890
8991 /*
90 -* Hook to send transaction information to ActiveMQ server
91 -*/
 92+ * Hook to send transaction information to ActiveMQ server
 93+ */
 94+
9295 function sendPendingSTOMP( $transaction ) {
9396 global $wgStompServer, $wgPendingStompQueueName;
9497
95 - $queueName = isset ( $wgPendingStompQueueName ) ? $wgPendingStompQueueName : 'pending';
 98+ $queueName = isset( $wgPendingStompQueueName ) ? $wgPendingStompQueueName : 'pending';
9699
97100 // include a library
98101 require_once( "Stomp.php" );
@@ -108,7 +111,7 @@
109112 $result = $con->send( "/queue/$queueName", $message, array( 'persistent' => 'true' ) );
110113
111114 if ( !$result ) {
112 - wfDebugLog( 'activemq_stomp', 'Send to Pending Q failed for this message: ' . $message );
 115+ wfDebugLog( 'activemq_stomp', 'Send to Pending Q failed for this message: ' . $message );
113116 }
114117
115118 $con->disconnect();
@@ -134,44 +137,44 @@
135138 // edit this array to include/ignore transaction data sent to the server
136139 $message = array(
137140 'contribution_tracking_id' => $transaction['contribution_tracking_id'],
138 - 'optout' => $transaction['optout'],
139 - 'anonymous' => $transaction['anonymous'],
140 - 'comment' => $transaction['comment'],
141 - 'size' => $transaction['size'],
142 - 'premium_language' => $transaction['premium_language'],
143 - 'utm_source' => $transaction['utm_source'],
144 - 'utm_medium' => $transaction['utm_medium'],
145 - 'utm_campaign' => $transaction['utm_campaign'],
146 - 'language' => $transaction['language'],
147 - 'referrer' => $transaction['referrer'],
148 - 'email' => $transaction['email'],
149 - 'first_name' => $transaction['fname'],
150 - 'middle_name' => $transaction['mname'],
151 - 'last_name' => $transaction['lname'],
152 - 'street_address' => $transaction['street'],
 141+ 'optout' => $transaction['optout'],
 142+ 'anonymous' => $transaction['anonymous'],
 143+ 'comment' => $transaction['comment'],
 144+ 'size' => $transaction['size'],
 145+ 'premium_language' => $transaction['premium_language'],
 146+ 'utm_source' => $transaction['utm_source'],
 147+ 'utm_medium' => $transaction['utm_medium'],
 148+ 'utm_campaign' => $transaction['utm_campaign'],
 149+ 'language' => $transaction['language'],
 150+ 'referrer' => $transaction['referrer'],
 151+ 'email' => $transaction['email'],
 152+ 'first_name' => $transaction['fname'],
 153+ 'middle_name' => $transaction['mname'],
 154+ 'last_name' => $transaction['lname'],
 155+ 'street_address' => $transaction['street'],
153156 'supplemental_address_1' => '',
154 - 'city' => $transaction['city'],
155 - 'state_province' => $transaction['state'],
156 - 'country' => $transaction['country'],
157 - 'postal_code' => $transaction['zip'],
158 - 'first_name_2' => $transaction['fname2'],
159 - 'last_name_2' => $transaction['lname2'],
160 - 'street_address_2' => $transaction['street2'],
 157+ 'city' => $transaction['city'],
 158+ 'state_province' => $transaction['state'],
 159+ 'country' => $transaction['country'],
 160+ 'postal_code' => $transaction['zip'],
 161+ 'first_name_2' => $transaction['fname2'],
 162+ 'last_name_2' => $transaction['lname2'],
 163+ 'street_address_2' => $transaction['street2'],
161164 'supplemental_address_2' => '',
162 - 'city_2' => $transaction['city2'],
163 - 'state_province_2' => $transaction['state2'],
164 - 'country_2' => $transaction['country2'],
165 - 'postal_code_2' => $transaction['zip'],
166 - 'gateway' => $transaction[ 'gateway' ],
167 - 'gateway_txn_id' => $transaction['PNREF'],
168 - 'response' => $transaction['RESPMSG'],
169 - 'currency' => $transaction['currency'],
170 - 'original_currency' => $transaction['currency'],
171 - 'original_gross' => $transaction['amount'],
172 - 'fee' => '0',
173 - 'gross' => $transaction['amount'],
174 - 'net' => $transaction['amount'],
175 - 'date' => $transaction['date'],
 165+ 'city_2' => $transaction['city2'],
 166+ 'state_province_2' => $transaction['state2'],
 167+ 'country_2' => $transaction['country2'],
 168+ 'postal_code_2' => $transaction['zip2'],
 169+ 'gateway' => $transaction['gateway'],
 170+ 'gateway_txn_id' => $transaction['order_id'], //pretty sure.
 171+ 'response' => $transaction['response'],
 172+ 'currency' => $transaction['currency'],
 173+ 'original_currency' => $transaction['currency'],
 174+ 'original_gross' => $transaction['amount'],
 175+ 'fee' => '0',
 176+ 'gross' => $transaction['amount'],
 177+ 'net' => $transaction['amount'],
 178+ 'date' => $transaction['date'],
176179 );
177180
178181 return $message;
Index: branches/fundraising/extensions/DonationInterface/activemq_stomp/Stomp.php
@@ -456,6 +456,8 @@
457457 {
458458 if ( $this->clientId != null ) {
459459 $headers["client-id"] = $this->clientId;
 460+ } else {
 461+ $headers = array();
460462 }
461463
462464 if ( is_resource( $this->_socket ) ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r99407Cleans up some confusion surrounding the gateway_txn_id in the two available ...khorn16:38, 10 October 2011
r100052We need this variable to be staged, or cc transactions won't work. After r977......khorn16:53, 17 October 2011
r100064Prevents the donation Thank You page from displaying only a stack trace in th...khorn18:05, 17 October 2011

Comments

#Comment by Khorn (WMF) (talk | contribs)   18:42, 23 September 2011

Please note that this branch is in the middle of a serious refactoring, and is by no means ready to be merged back into trunk. (Latest DonationInterface branch rev at the time of this comment is r97833.)

#Comment by Awjrichards (talk | contribs)   17:44, 29 September 2011

In activemq_stomp.php: + 'gateway_txn_id' => $transaction['order_id'], //pretty sure. This is not necessarily true. With PayflowPro, they return their own txn id in their response which is what needs to go here. Whatever passes data to the actaivemq_stomp hooks should probably provide some mechanism to correctly assign the gateway_txn_id

#Comment by Khorn (WMF) (talk | contribs)   00:10, 8 October 2011

Ah yes: This is interesting. Before I had to abstract this out for use with multiple gateways, it was taking PayflowPro's "PNREF" field directly. ...I'll fix it.

#Comment by Khorn (WMF) (talk | contribs)   16:39, 10 October 2011

Fixed in r99407

#Comment by Awjrichards (talk | contribs)   21:55, 29 September 2011

Also, as a general note, I think it would be cleaner if createQueueMessage( $transaction ) happened outside of the activemq_stomp code - probably on a per gateway and/or transaction type basis - esp. considering that the fields we need to package up into a messge will likely be different depending on the gateway/trxn type. It would be better if the activemq_stomp code's sole purpose was to interface with activemq via stomp rather than do message formatting etc.

#Comment by Khorn (WMF) (talk | contribs)   23:56, 7 October 2011

Agreed: Stomp should be more agnostic. Should this be a new card? I was trying (halfheartedly, I'll admit) to avoid shredding the existing functionality.

#Comment by Awjrichards (talk | contribs)   20:56, 21 October 2011

Yeah, it's something for the future. This is now otherwise just fine :)

Status & tagging log