http://www.mediawiki.org/wiki/Special:Code/MediaWiki/95923

Revision: 95923
Author:   khorn
Date:     2011-09-01 00:43:35 +0000 (Thu, 01 Sep 2011)
Log Message:
-----------
More refactoring. The new globalcollect gateway is now inheriting from the 
common gateway abstract class. 
(Also cleaned up the formatting more than somewhat)

Modified Paths:
--------------
    branches/fundraising/extensions/DonationInterface/donationinterface.php
    
branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php
    
branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect_gateway.php
    
branches/fundraising/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.php

Added Paths:
-----------
    branches/fundraising/extensions/DonationInterface/gateway_common/
    
branches/fundraising/extensions/DonationInterface/gateway_common/gateway.adapter.php
    branches/fundraising/extensions/DonationInterface/tests/
    
branches/fundraising/extensions/DonationInterface/tests/DonationInterfaceTest.php

Modified: 
branches/fundraising/extensions/DonationInterface/donationinterface.php
===================================================================
--- branches/fundraising/extensions/DonationInterface/donationinterface.php     
2011-08-31 23:24:21 UTC (rev 95922)
+++ branches/fundraising/extensions/DonationInterface/donationinterface.php     
2011-09-01 00:43:35 UTC (rev 95923)
@@ -2,26 +2,26 @@
 
 # Alert the user that this is not a valid entry point to MediaWiki if they try 
to access the special pages file directly.
 if ( !defined( 'MEDIAWIKI' ) ) {
-        echo <<<EOT
+       echo <<<EOT
 To install the DontaionInterface extension, put the following line in 
LocalSettings.php:
 require_once( "\$IP/extensions/DonationInterface/donationinterface.php" );
 EOT;
-        exit( 1 );
+       exit( 1 );
 }
 
 // Extension credits that will show up on Special:Version
 $wgExtensionCredits['specialpage'][] = array(
-        'name' => 'Donation Interface',
-        'author' => 'Katie Horn',
-        'version' => '1.0.0',
-        'descriptionmsg' => 'donationinterface-desc',
-        'url' => 'http://www.mediawiki.org/wiki/Extension:DonationInterface',
+       'name' => 'Donation Interface',
+       'author' => 'Katie Horn',
+       'version' => '1.0.0',
+       'descriptionmsg' => 'donationinterface-desc',
+       'url' => 'http://www.mediawiki.org/wiki/Extension:DonationInterface',
 );
 
 //This is going to be a little funky. 
 //Override this in LocalSettings.php BEFORE you include this file, if you want 
 //to disable gateways.
-if (!isset($wgDonationInterfaceEnabledGateways)){
+if ( !isset( $wgDonationInterfaceEnabledGateways ) ) {
        $wgDonationInterfaceEnabledGateways = array(
                'paypal',
                'payflowpro',
@@ -33,54 +33,37 @@
 
 require_once( $donationinterface_dir . 'donate_interface/donate_interface.php' 
);
 
-foreach ($wgDonationInterfaceEnabledGateways as $gateway){
+foreach ( $wgDonationInterfaceEnabledGateways as $gateway ) {
        //include 'em
        require_once( $donationinterface_dir . $gateway . '_gateway/' . 
$gateway . '_gateway.php' );
 }
 
 //load all possible form classes
-$wgAutoloadClasses[ 'Gateway_Form' ] = $donationinterface_dir . 
'gateway_forms/Form.php';
-$wgAutoloadClasses[ 'Gateway_Form_OneStepTwoColumn' ] = $donationinterface_dir 
. 'gateway_forms/OneStepTwoColumn.php';
-$wgAutoloadClasses[ 'Gateway_Form_TwoStepTwoColumn' ] = $donationinterface_dir 
. 'gateway_forms/TwoStepTwoColumn.php';
-$wgAutoloadClasses[ 'Gateway_Form_TwoColumnPayPal' ] = $donationinterface_dir 
. 'gateway_forms/TwoColumnPayPal.php';
-$wgAutoloadClasses[ 'Gateway_Form_TwoColumnLetter' ] = $donationinterface_dir 
. 'gateway_forms/TwoColumnLetter.php';
-$wgAutoloadClasses[ 'Gateway_Form_TwoColumnLetter2' ] = $donationinterface_dir 
. 'gateway_forms/TwoColumnLetter2.php';
-$wgAutoloadClasses[ 'Gateway_Form_TwoColumnLetter3' ] = $donationinterface_dir 
. 'gateway_forms/TwoColumnLetter3.php';
-$wgAutoloadClasses[ 'Gateway_Form_TwoColumnLetter4' ] = $donationinterface_dir 
. 'gateway_forms/TwoColumnLetter4.php';
-$wgAutoloadClasses[ 'Gateway_Form_TwoColumnLetter5' ] = $donationinterface_dir 
. 'gateway_forms/TwoColumnLetter5.php';
-$wgAutoloadClasses[ 'Gateway_Form_TwoColumnLetter6' ] = $donationinterface_dir 
. 'gateway_forms/TwoColumnLetter6.php';
-$wgAutoloadClasses[ 'Gateway_Form_TwoColumnLetter7' ] = $donationinterface_dir 
. 'gateway_forms/TwoColumnLetter7.php';
-$wgAutoloadClasses[ 'Gateway_Form_TwoStepTwoColumnLetter' ] = 
$donationinterface_dir . 'gateway_forms/TwoStepTwoColumnLetter.php';
-$wgAutoloadClasses[ 'Gateway_Form_TwoStepTwoColumnLetterCA' ] = 
$donationinterface_dir . 'gateway_forms/TwoStepTwoColumnLetterCA.php';
-$wgAutoloadClasses[ 'Gateway_Form_TwoStepTwoColumnLetter2' ] = 
$donationinterface_dir . 'gateway_forms/TwoStepTwoColumnLetter2.php';
-$wgAutoloadClasses[ 'Gateway_Form_TwoStepTwoColumnLetter3' ] = 
$donationinterface_dir . 'gateway_forms/TwoStepTwoColumnLetter3.php';
-$wgAutoloadClasses[ 'Gateway_Form_TwoStepTwoColumnPremium' ] = 
$donationinterface_dir . 'gateway_forms/TwoStepTwoColumnPremium.php';
-$wgAutoloadClasses[ 'Gateway_Form_TwoStepTwoColumnPremiumUS' ] = 
$donationinterface_dir . 'gateway_forms/TwoStepTwoColumnPremiumUS.php';
-$wgAutoloadClasses[ 'Gateway_Form_RapidHtml' ] = $donationinterface_dir . 
'gateway_forms/RapidHtml.php';
-$wgAutoloadClasses[ 'Gateway_Form_SingleColumn' ] = $donationinterface_dir . 
'gateway_forms/SingleColumn.php';
+$wgAutoloadClasses['Gateway_Form'] = $donationinterface_dir . 
'gateway_forms/Form.php';
+$wgAutoloadClasses['Gateway_Form_OneStepTwoColumn'] = $donationinterface_dir . 
'gateway_forms/OneStepTwoColumn.php';
+$wgAutoloadClasses['Gateway_Form_TwoStepTwoColumn'] = $donationinterface_dir . 
'gateway_forms/TwoStepTwoColumn.php';
+$wgAutoloadClasses['Gateway_Form_TwoColumnPayPal'] = $donationinterface_dir . 
'gateway_forms/TwoColumnPayPal.php';
+$wgAutoloadClasses['Gateway_Form_TwoColumnLetter'] = $donationinterface_dir . 
'gateway_forms/TwoColumnLetter.php';
+$wgAutoloadClasses['Gateway_Form_TwoColumnLetter2'] = $donationinterface_dir . 
'gateway_forms/TwoColumnLetter2.php';
+$wgAutoloadClasses['Gateway_Form_TwoColumnLetter3'] = $donationinterface_dir . 
'gateway_forms/TwoColumnLetter3.php';
+$wgAutoloadClasses['Gateway_Form_TwoColumnLetter4'] = $donationinterface_dir . 
'gateway_forms/TwoColumnLetter4.php';
+$wgAutoloadClasses['Gateway_Form_TwoColumnLetter5'] = $donationinterface_dir . 
'gateway_forms/TwoColumnLetter5.php';
+$wgAutoloadClasses['Gateway_Form_TwoColumnLetter6'] = $donationinterface_dir . 
'gateway_forms/TwoColumnLetter6.php';
+$wgAutoloadClasses['Gateway_Form_TwoColumnLetter7'] = $donationinterface_dir . 
'gateway_forms/TwoColumnLetter7.php';
+$wgAutoloadClasses['Gateway_Form_TwoStepTwoColumnLetter'] = 
$donationinterface_dir . 'gateway_forms/TwoStepTwoColumnLetter.php';
+$wgAutoloadClasses['Gateway_Form_TwoStepTwoColumnLetterCA'] = 
$donationinterface_dir . 'gateway_forms/TwoStepTwoColumnLetterCA.php';
+$wgAutoloadClasses['Gateway_Form_TwoStepTwoColumnLetter2'] = 
$donationinterface_dir . 'gateway_forms/TwoStepTwoColumnLetter2.php';
+$wgAutoloadClasses['Gateway_Form_TwoStepTwoColumnLetter3'] = 
$donationinterface_dir . 'gateway_forms/TwoStepTwoColumnLetter3.php';
+$wgAutoloadClasses['Gateway_Form_TwoStepTwoColumnPremium'] = 
$donationinterface_dir . 'gateway_forms/TwoStepTwoColumnPremium.php';
+$wgAutoloadClasses['Gateway_Form_TwoStepTwoColumnPremiumUS'] = 
$donationinterface_dir . 'gateway_forms/TwoStepTwoColumnPremiumUS.php';
+$wgAutoloadClasses['Gateway_Form_RapidHtml'] = $donationinterface_dir . 
'gateway_forms/RapidHtml.php';
+$wgAutoloadClasses['Gateway_Form_SingleColumn'] = $donationinterface_dir . 
'gateway_forms/SingleColumn.php';
 
 
 
-
-
-
-
-
-
-
-
-
-//$wgAutoloadClasses['GlobalCollectGateway'] = $dir . 
'globalcollect_gateway.body.php';
-//$wgExtensionMessagesFiles['GlobalCollectGateway'] = $dir . 
'globalcollect_gateway.i18n.php';
-//$wgExtensionAliasesFiles['GlobalCollectGateway'] = $dir . 
'globalcollect_gateway.alias.php';
-//$wgSpecialPages['GlobalCollectGateway'] = 'GlobalCollectGateway';
-//$wgAjaxExportList[] = "fnGlobalCollectofofWork";
-
-
 // set defaults, these should be assigned in LocalSettings.php
 //$wgGlobalCollectURL = 'https://globalcollect.paypal.com';
 //$wgGlobalCollectTestingURL = 'https://pilot-globalcollect.paypal.com'; // 
Payflow testing URL
-
 //$wgGlobalCollectGatewayCSSVersion = 1;
 //
 //$wgGlobalCollectPartnerID = ''; // PayPal or original authorized reseller
@@ -167,7 +150,7 @@
  * /never/ be loaded by the rapid html form loader!
  * @var string
  */
-$wgPayflowAllowedHtmlForms = array(    $wgPayflowHtmlFormDir . "/demo.html" );
+$wgPayflowAllowedHtmlForms = array( $wgPayflowHtmlFormDir . "/demo.html" );
 
 /**
  * Configure PayflowproGateway to use syslog for log messages rather than 
wfDebugLog

Added: 
branches/fundraising/extensions/DonationInterface/gateway_common/gateway.adapter.php
===================================================================
--- 
branches/fundraising/extensions/DonationInterface/gateway_common/gateway.adapter.php
                                (rev 0)
+++ 
branches/fundraising/extensions/DonationInterface/gateway_common/gateway.adapter.php
        2011-09-01 00:43:35 UTC (rev 95923)
@@ -0,0 +1,380 @@
+<?php
+
+interface GatewayType {
+       //all the particulars of the child classes. Aaaaall.
+
+       /**
+        * return either 'xml' or 'namevalue', depending on the gateway's web 
API 
+        */
+       function getCommunicationType();
+
+       /**
+        * Pretty sure it's not worth it to even try to abstract this.
+        * ...hm. Too general? I'm thinking "maybe". 
+        * Actually: Yes. So...
+        * TODO: Get way more specific here. 
+        */
+       function parseXMLResponse( $rawResponse );
+}
+
+abstract class GatewayAdapter implements GatewayType {
+
+       //Contains the map of THEIR var names, to OURS.
+       //I'd have gone the other way, but we'd run into 1:many pretty quick. 
+       protected $var_map;
+       protected $accountInfo;
+       protected $url;
+       protected $transactions;
+       protected $postdata;
+       protected $postdatadefaults;
+       protected $xmlDoc;
+
+       const logidentifier = 'donation_gateway';
+
+       function getValue( $gateway_field_name ) {
+               if ( empty( $this->transactions ) ) {
+                       //TODO: These dies should all just throw fatal errors 
instead. 
+                       die( 'Transactions structure is empty! Aborting.' );
+               }
+               //How do we determine the value of a field asked for in a 
particular transaction? 
+               $transaction = $this->currentTransaction();
+
+               //If there's a hard-coded value in the transaction definition, 
use that.
+               if ( array_key_exists( $transaction, $this->transactions ) && 
is_array( $this->transactions[$transaction] ) &&
+                       array_key_exists( 'values', 
$this->transactions[$transaction] ) &&
+                       array_key_exists( $gateway_field_name, 
$this->transactions[$transaction]['values'] ) ) {
+                       return 
$this->transactions[$transaction]['values'][$gateway_field_name];
+               }
+
+               //if it's account info, use that.
+               //$this->accountInfo;
+               if ( array_key_exists( $gateway_field_name, $this->accountInfo 
) ) {
+                       return $this->accountInfo[$gateway_field_name];
+               }
+
+
+               //If there's a value in the post data (name-translated by the 
var_map), use that.
+               if ( array_key_exists( $gateway_field_name, $this->var_map ) ) {
+                       if ( array_key_exists( 
$this->var_map[$gateway_field_name], $this->postdata ) &&
+                               
$this->postdata[$this->var_map[$gateway_field_name]] !== '' ) {
+                               //if it was sent, use that. 
+                               return 
$this->postdata[$this->var_map[$gateway_field_name]];
+                       } else {
+                               //return the default for that form value
+                               return 
$this->postdatadefaults[$this->var_map[$gateway_field_name]];
+                       }
+               }
+
+               //not in the map, or hard coded. What then? 
+               //Complain furiously, for your code is faulty. 
+               //TODO: Something that plays nice with others, instead of... 
+               die( "getValue found NOTHING for $gateway_field_name, 
$transaction." );
+       }
+
+       function buildRequestXML() {
+               $this->xmlDoc = new DomDocument( '1.0' );
+               $node = $this->xmlDoc->createElement( 'XML' );
+
+               $structure = 
$this->transactions[$this->currentTransaction()]['request'];
+
+               $this->buildTransactionNodes( $structure, $node );
+               $this->xmlDoc->appendChild( $node );
+               return $this->xmlDoc->saveXML();
+       }
+
+       function buildTransactionNodes( $structure, &$node ) {
+               $transaction = $this->currentTransaction();
+
+               if ( !is_array( $structure ) ) { //this is a weird case that 
shouldn't ever happen. I'm just being... thorough. But, yeah: It's like... the 
base-1 case. 
+                       $this->appendNodeIfValue( $structure, $node );
+               } else {
+                       foreach ( $structure as $key => $value ) {
+                               if ( !is_array( $value ) ) {
+                                       //do not use $key. $key is meaningless 
in this case.                    
+                                       $this->appendNodeIfValue( $value, $node 
);
+                               } else {
+                                       $keynode = 
$this->xmlDoc->createElement( $key );
+                                       $this->buildTransactionNodes( $value, 
$keynode );
+                                       $node->appendChild( $keynode );
+                               }
+                       }
+               }
+               //not actually returning anything. It's all side-effects. 
Because I suck like that. 
+       }
+
+       function appendNodeIfValue( $value, &$node ) {
+               $nodevalue = $this->getValue( $value );
+               if ( $nodevalue !== '' && $nodevalue !== false ) {
+                       $temp = $this->xmlDoc->createElement( $value, 
$nodevalue );
+                       $node->appendChild( $temp );
+               }
+       }
+
+       function do_transaction( $transaction ) {
+               $this->currentTransaction( $transaction );
+               if ( $this->getCommunicationType() === 'xml' ) {
+                       $xml = $this->buildRequestXML();
+                       $response = $this->curl_transaction( $xml );
+                       //put the response in a universal form, and return it. 
+               }
+
+               //TODO: Actually pull these from somewhere legit. 
+               if ( $response['status'] === true ) {
+                       $response['message'] = "$transaction Transaction 
Successful!";
+               } elseif ( $response['status'] === false ) {
+                       $response['message'] = "$transaction Transaction 
FAILED!";
+               } else {
+                       $response['message'] = "$transaction Transaction... 
weird. I have no idea what happened there.";
+               }
+
+               return $response;
+
+               //speaking of universal form: 
+               //$result['status'] = something I wish could be boiled down to 
a bool, but that's way too optimistic, I think.
+               //$result['message'] = whatever we want to display back? 
+               //$result['errors'][]['code'] = their error code
+               //$result['errors'][]['value'] = Error message
+               //$result['return'][$whatever] = values they pass back to us 
for whatever reason. We might... log it, or pieces of it, or something? 
+       }
+
+       function getCurlBaseOpts() {
+               //I chose to return this as a function so it's easy to 
override. 
+               //TODO: probably this for all the junk I currently have stashed 
in the constructor.
+               //...maybe. 
+               global $wgGlobalCollectTimeout, $wgPayflowGatewayUseHTTPProxy;
+               $opts = array(
+                       CURLOPT_URL => $this->url,
+                       //CURLOPT_USERAGENT => Http::userAgent(),
+                       CURLOPT_HEADER => 1,
+                       CURLOPT_RETURNTRANSFER => 1,
+                       CURLOPT_TIMEOUT => $wgGlobalCollectTimeout,
+                       //CURLOPT_FOLLOWLOCATION => 0,
+                       //CURLOPT_SSL_VERIFYPEER => 0,
+                       //CURLOPT_SSL_VERIFYHOST => 2,
+                       //CURLOPT_FORBID_REUSE => true,
+                       CURLOPT_POST => 1,
+               );
+
+               // set proxy settings if necessary
+               if ( $wgPayflowGatewayUseHTTPProxy ) {
+                       $opts[CURLOPT_HTTPPROXYTUNNEL] = 1;
+                       $opts[CURLOPT_PROXY] = $wgPayflowGatewayHTTPProxy;
+               }
+               return $opts;
+       }
+
+       function getCurlBaseHeaders() {
+               $headers = array(
+                       'Content-Type: text/' . $this->getCommunicationType() . 
'; charset=utf-8',
+                       //      'X-VPS-Client-Timeout: 45',
+                       //      'X-VPS-Request-ID:' . 
$this->postdatadefaults['order_id'],
+               );
+               return $headers;
+       }
+
+       protected function currentTransaction( $transaction = '' ) { //get&set 
in one!
+               static $current_transaction;
+               if ( $transaction != '' ) {
+                       $current_transaction = $transaction;
+               }
+               if ( !isset( $current_transaction ) ) {
+                       return false;
+               }
+               return $current_transaction;
+       }
+
+       /**
+        * Sends a name-value pair string to Payflow gateway
+        *
+        * @param $data String: The exact thing we want to send.
+        */
+       protected function curl_transaction( $data ) {
+               global $wgOut; //TODO: Uhm, this shouldn't touch the view. 
Something further upstream should decide what to do with this. 
+               // TODO: This, but way before we get here. 
+               //$this->updateContributionTracking( $data, defined( 'OWA' ) );
+               // assign header data necessary for the curl_setopt() function
+
+               $ch = curl_init();
+
+               $headers = $this->getCurlBaseHeaders();
+               $headers[] = 'Content-Length: ' . strlen( $data );
+
+               self::log( "Sending Data: " . $this->formatXmlString( $data ) );
+
+               $curl_opts = $this->getCurlBaseOpts();
+               $curl_opts[CURLOPT_HTTPHEADER] = $headers;
+               $curl_opts[CURLOPT_POSTFIELDS] = $data;
+
+               foreach ( $curl_opts as $option => $value ) {
+                       curl_setopt( $ch, $option, $value );
+               }
+
+               // As suggested in the PayPal developer forum sample code, try 
more than once to get a response
+               // in case there is a general network issue
+               $i = 1;
+
+               $return = array( );
+
+               while ( $i++ <= 3 ) {
+                       self::log( $this->postdatadefaults['order_id'] . ' 
Preparing to send transaction to GlobalCollect' );
+                       $return['result'] = curl_exec( $ch );
+                       $return['headers'] = curl_getinfo( $ch );
+
+                       if ( $return['headers']['http_code'] != 200 && 
$return['headers']['http_code'] != 403 ) {
+                               self::log( $this->postdatadefaults['order_id'] 
. ' Failed sending transaction to GlobalCollect, retrying' );
+                               sleep( 1 );
+                       } elseif ( $return['headers']['http_code'] == 200 || 
$return['headers']['http_code'] == 403 ) {
+                               self::log( $this->postdatadefaults['order_id'] 
. ' Finished sending transaction to GlobalCollect' );
+                               break;
+                       }
+               }
+
+               if ( $return['headers']['http_code'] != 200 ) {
+                       $return['result'] = false;
+                       //TODO: i18n here! 
+                       $return['message'] = 'No response from credit card 
processor.  Please try again later!';
+                       $when = time();
+                       self::log( $this->postdatadefaults['order_id'] . ' No 
response from credit card processor: ' . curl_error( $ch ) );
+                       curl_close( $ch );
+                       return $return;
+               }
+
+               curl_close( $ch );
+               self::log( "Results: " . print_r( $return['result'], true ) );
+
+//             if ($this->getCommunicationType() === 'namevalue'){
+//                     $return['result'] = strstr( $return['result'], 'RESULT' 
);
+//                     //TODO: Finish this for namevalue. 
+//             }
+               if ( $this->getCommunicationType() === 'xml' ) {
+                       //$return['result'] = 
$this->stripResponseHeaders($return['result']);
+                       $return['status'] = $this->parseXMLResponse( 
$return['result'] );
+               }
+
+               return $return;
+
+               // parse string and display results to the user
+               //TODO: NO NO NO. NO DISPLAY HERE. 
+               //$this->fnPayflowGetResults( $data, $return['result'] );
+       }
+
+       function stripResponseHeaders( $rawResponse ) {
+               $xmlStart = strpos( $rawResponse, '<?xml' );
+               if ( $xmlStart == false ) { //I totally saw this happen one 
time. No XML, just <RESPONSE>...
+                       $xmlStart = strpos( $rawResponse, '<RESPONSE' );
+               }
+               if ( $xmlStart == false ) { //Still false. Your Head Asplode.
+                       self::log( "Wow, that was so messed up I couldn't even 
parse the response, so here's the thing in its entirety:\n" . $rawResponse );
+                       return false;
+               }
+               $justXML = substr( $rawResponse, $xmlStart );
+               return $justXML;
+       }
+
+       public static function log( $msg, $log_level=LOG_INFO ) {
+               global $wgGlobalCollectGatewayUseSyslog;
+               $c = get_called_class();
+               $identifier = $c::logidentifier;
+
+               // if we're not using the syslog facility, use wfDebugLog
+               if ( !$wgGlobalCollectGatewayUseSyslog ) {
+                       wfDebugLog( $identifier, $msg );
+                       return;
+               }
+
+               // otherwise, use syslogging
+               openlog( $identifier, LOG_ODELAY, LOG_SYSLOG );
+               syslog( $log_level, $msg );
+               closelog();
+       }
+
+       //_______________________________________________________________
+       //copied from  payflowpro_gateway/includes/payflowUser.inc
+
+       /**
+        * Fetch and return the 'order_id' for a transaction
+        * 
+        * Since transactions to PayPal are initially matched internally on 
their end
+        * with the 'order_id' field, but we don't actually care what the order 
id is,
+        * we generate a sufficiently random number to avoid duplication. 
+        * 
+        * We go ahead and always generate a random order id becuse if PayPal 
detects
+        * the same order_id more than once, it considers the request a 
duplicate, even
+        * if the data is completely different.
+        * 
+        * @return int
+        */
+       function getOrderId() {
+               return $this->generateOrderId();
+       }
+
+       /**
+        * Generate an internal order id
+        * 
+        * This is only used internally for tracking a user's 'session' with 
the credit
+        * card form.  I mean 'session' in the sense of the moment a credit 
card page
+        * is loaded for the first time (nothing posted to it - a discrete 
donation 
+        * session) as opposed to the $_SESSION - as the $_SESSION id could 
potentially
+        * not change between contribution attempts.
+        */
+       function getInternalOrderId() {
+               global $wgRequest;
+
+               // is an order_id already set?
+               //TODO: Change all these to look instead at $this->postdata... 
I think.
+               $i_order_id = $wgRequest->getText( 'i_order_id', 0 );
+
+               // if the form was not just posted OR there's no order_id set, 
generate one.
+               if ( !$wgRequest->wasPosted() || !$i_order_id ) {
+                       $i_order_id = $this->generateOrderId();
+               }
+
+               return $i_order_id;
+       }
+
+       /**
+        * Generate an order id
+        */
+       function generateOrderId() {
+               return ( double ) microtime() * 1000000 . mt_rand( 1000, 9999 );
+       }
+
+       //To avoid reinventing the wheel: taken from 
http://recursive-design.com/blog/2007/04/05/format-xml-with-php/
+       function formatXmlString( $xml ) {
+               // add marker linefeeds to aid the pretty-tokeniser (adds a 
linefeed between all tag-end boundaries)
+               $xml = preg_replace( '/(>)(<)(\/*)/', "$1\n$2$3", $xml );
+
+               // now indent the tags
+               $token = strtok( $xml, "\n" );
+               $result = ''; // holds formatted version as it is built
+               $pad = 0; // initial indent
+               $matches = array( ); // returns from preg_matches()
+               // scan each line and adjust indent based on opening/closing 
tags
+               while ( $token !== false ) :
+
+                       // test for the various tag states
+                       // 1. open and closing tags on same line - no change
+                       if ( preg_match( '/.+<\/\w[^>]*>$/', $token, $matches ) 
) :
+                               $indent = 0;
+                       // 2. closing tag - outdent now
+                       elseif ( preg_match( '/^<\/\w/', $token, $matches ) ) :
+                               $pad--;
+                       // 3. opening tag - don't pad this one, only subsequent 
tags
+                       elseif ( preg_match( '/^<\w[^>]*[^\/]>.*$/', $token, 
$matches ) ) :
+                               $indent = 1;
+                       // 4. no indentation needed
+                       else :
+                               $indent = 0;
+                       endif;
+
+                       // pad the line with the required number of leading 
spaces
+                       $line = str_pad( $token, strlen( $token ) + $pad, ' ', 
STR_PAD_LEFT );
+                       $result .= $line . "\n"; // add to the cumulative 
result, with linefeed
+                       $token = strtok( "\n" ); // get the next token
+                       $pad += $indent; // update the pad size for subsequent 
lines    
+               endwhile;
+
+               return $result;
+       }
+
+}


Property changes on: 
branches/fundraising/extensions/DonationInterface/gateway_common/gateway.adapter.php
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: 
branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php
===================================================================
--- 
branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php
   2011-08-31 23:24:21 UTC (rev 95922)
+++ 
branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php
   2011-09-01 00:43:35 UTC (rev 95923)
@@ -1,33 +1,29 @@
 <?php
 
+$dir = dirname( __FILE__ ) . '/';
+require_once( $dir . '../gateway_common/gateway.adapter.php' );
 
-class GlobalCollectAdapter {
-
+class GlobalCollectAdapter extends GatewayAdapter {
        //Contains the map of THEIR var names, to OURS.
        //I'd have gone the other way, but we'd run into 1:many pretty quick. 
-       private $var_map;
-       private $accountInfo;
-       private $url;
-       private $transactions;
-       private $postdata;
-       private $postdatadefaults;
-       private $xmlDoc;
-       
-       function __construct($data){
+
+       const logidentifier = 'globalcollect_gateway';
+
+       function __construct( $data ) {
                //TODO: Squish ALL the globals here, in the constructor. 
                //easier to abstract out that way. 
                global $wgGatewayTest;
-               
+
                $this->postdata = $data;
-               
+
                //TODO: Make a Thing in which we do things like this. 
                $this->postdata['amount'] = $this->postdata['amount'] * 100;
-               
-               
+
+
                $returnTitle = Title::newFromText( 'Donate-thanks/en' );
                $returnto = $returnTitle->getFullURL();
                $returnto = "http://www.katiehorn.com";;
-               
+
                //this DEFINITELY needs to be defined in the parent class, and 
contain everything anybody might want to know.
                $this->postdatadefaults = array(
                        'order_id' => '112358' . rand(),
@@ -40,10 +36,10 @@
                        'order_id' => $this->getOrderId(),
                        'i_order_id' => $this->getInternalOrderId(),
                );
-       
-               
+
+
                ///ehh. Most of this should be broken up into functions for the 
sake of readibility. 
-               
+
                $this->var_map = array(
                        'ORDERID' => 'order_id',
                        'AMOUNT' => 'amount',
@@ -53,22 +49,21 @@
                        'MERCHANTREFERENCE' => 'order_id',
                        'RETURNURL' => 'returnto', //I think. It might not even 
BE here yet. Boo-urns. 
                        'IPADDRESS' => 'user_ip', //TODO: Not sure if this 
should be OUR ip, or the user's ip. Hurm.
-                       
                );
-               
-               $this->return_value_map  = array(
+
+               $this->return_value_map = array(
                        'OK' => true,
                        'NOK' => false,
                );
-               
+
                global $wgGlobalCollectURL, $wgGlobalCollectMerchantID;
-               if ($wgGatewayTest){
+               if ( $wgGatewayTest ) {
                        $this->url = $wgGlobalCollectURL;
                } else {
                        $this->url = $wgGlobalCollectURL;
                }
-               
-               
+
+
                $this->accountInfo = array(
 //                     'PAYMENTPRODUCTID' => '3', //actually, these are almost 
certainly transaction-specific.
 //                     'HOSTEDINDICATOR' => '1',
@@ -76,20 +71,20 @@
                        //'IPADDRESS' => '', //TODO: Not sure if this should be 
OUR ip, or the user's ip. Hurm. 
                        'VERSION' => "1.0",
                );
-               
+
                //oof. This is getting a little long and unwieldy. Maybe we 
should build it. Or maybe that sucks. I can't tell yet.
                /* General idea here:
                 * This bad boy will (probably) contain the structure of all 
possible transactions as defined by the gateway. 
                 * First array key: Some way for us to id the transaction. 
Doesn't actually have to be the gateway's name for it, but
                 * I'm starting with that.
                 * Second array key: 
-                *              'structure' contains the layout of that 
transaction.
-                *              'defaults' contains default values for the leaf 
'values' 
-                *              I could put a 'type' in here, but I think we 
can assume that if 'structure' is multi-layer, we're XML.
+                *              'structure' contains the layout of that 
transaction.
+                *              'defaults' contains default values for the leaf 
'values' 
+                *              I could put a 'type' in here, but I think we 
can assume that if 'structure' is multi-layer, we're XML.
                 * Array "leaves" in 'structure' will be assigned a value 
according to the var_map, and the posted data. 
-                *      There should also be a mechanism for assigning 
defaults, but I'm not entirely sure what that would look like quite yet...
+                *      There should also be a mechanism for assigning 
defaults, but I'm not entirely sure what that would look like quite yet...
                 * 
-                */ 
+                */
                $this->transactions = array(
                        'INSERT_ORDERWITHPAYMENT' => array(
                                'request' => array(
@@ -108,7 +103,7 @@
                                                                'LANGUAGECODE',
                                                                'COUNTRYCODE',
                                                                
'MERCHANTREFERENCE'
-                                                               ),
+                                                       ),
                                                        'PAYMENT' => array(
                                                                
'PAYMENTPRODUCTID',
                                                                'AMOUNT',
@@ -137,7 +132,7 @@
                                ),
                                'result_data' => array(
                                        'ROW' => array(
-                                               //uhh... presumably we'd look 
for some Stuff in here. 
+                                       //uhh... presumably we'd look for some 
Stuff in here. 
                                        )
                                )
                        ),
@@ -150,7 +145,7 @@
 //                                                     'IPADDRESS',
                                                        'VERSION'
                                                ),
-                                               'PARAMS' => array()
+                                               'PARAMS' => array( )
                                        )
                                ),
                                'values' => array(
@@ -167,114 +162,36 @@
                                ),
                                'result_data' => array(
                                        'ROW' => array(
-                                               //uhh... presumably we'd look 
for some Stuff in here. 
+                                       //uhh... presumably we'd look for some 
Stuff in here. 
                                        )
                                )
                        ),
                );
-       
        }
-       
-       function getCommunicationType(){
+
+       function getCommunicationType() {
                return 'xml'; //'xml' or 'namevalue'.
        }
-       
-       
-       function getValue($gateway_field_name, $transaction = ''){
-               //How do we determine the value of a field asked for in a 
particular transaction? 
-               
-               //If there's a hard-coded value in the transaction definition, 
use that.
-               if(array_key_exists($transaction, $this->transactions) && 
-                       array_key_exists('values', 
$this->transactions[$transaction]) && 
-                       array_key_exists($gateway_field_name, 
$this->transactions[$transaction]['values'])){
-                       return 
$this->transactions[$transaction]['values'][$gateway_field_name];
-               }
-               
-               //if it's account info, use that.
-               //$this->accountInfo;
-               if(array_key_exists($gateway_field_name, $this->accountInfo)){
-                       return $this->accountInfo[$gateway_field_name];
-               }
-               
-               
-               //If there's a value in the post data (name-translated by the 
var_map), use that.
-               if (array_key_exists($gateway_field_name, $this->var_map)){
-                       if 
(array_key_exists($this->var_map[$gateway_field_name], $this->postdata) && 
-                               
$this->postdata[$this->var_map[$gateway_field_name]] !== ''){
-                               //if it was sent, use that. 
-                               return 
$this->postdata[$this->var_map[$gateway_field_name]];
-                       } else {
-                               //return the default for that form value
-                               return 
$this->postdatadefaults[$this->var_map[$gateway_field_name]];
-                       }
-               }
-               
-               //not in the map, or hard coded. What then? 
-               //Complain furiously, for your code is faulty. 
-               //TODO: Something that plays nice with others, instead of... 
-               die("getValue found NOTHING for $gateway_field_name, 
$transaction.");   
-               
-       }
 
-       function buildRequestXML(){
-               $this->xmlDoc = new DomDocument('1.0');
-               $node = $this->xmlDoc->createElement('XML');
-               
-               $structure = 
$this->transactions[$this->currentTransaction()]['request'];
-               
-               $this->buildTransactionNodes($structure, $node);
-               $this->xmlDoc->appendChild($node);
-               return $this->xmlDoc->saveXML();
-       }
-       
-       
-       function buildTransactionNodes($structure, &$node){
-               $transaction = $this->currentTransaction();
-               
-               if (!is_array($structure)){ //this is a weird case that 
shouldn't ever happen. I'm just being... thorough. But, yeah: It's like... the 
base-1 case. 
-                       $this->appendNodeIfValue($structure, $node);
-               } else {
-                       foreach ($structure as $key => $value){
-                               if (!is_array($value)){
-                                       //do not use $key. $key is meaningless 
in this case.                    
-                                       $this->appendNodeIfValue($value, $node);
-                               } else {
-                                       $keynode = 
$this->xmlDoc->createElement($key);
-                                       $this->buildTransactionNodes( $value, 
$keynode);
-                                       $node->appendChild($keynode);
-                               }
-                       }
-               }
-               //not actually returning anything. It's all side-effects. 
Because I suck like that. 
-       }
-       
-       function appendNodeIfValue($value, &$node){
-               $nodevalue = $this->getValue($value, 
$this->currentTransaction());
-               if ($nodevalue !== '' && $nodevalue !== false){
-                       $temp = $this->xmlDoc->createElement($value, 
$nodevalue);
-                       $node->appendChild($temp);
-               }
-       }
-       
-       function do_transaction($transaction){
-               $this->currentTransaction($transaction);
-               if ($this->getCommunicationType() === 'xml'){
+       function do_transaction( $transaction ) {
+               $this->currentTransaction( $transaction );
+               if ( $this->getCommunicationType() === 'xml' ) {
                        $xml = $this->buildRequestXML();
-                       $response = $this->curl_transaction($xml);
+                       $response = $this->curl_transaction( $xml );
                        //put the response in a universal form, and return it. 
                }
-               
+
                //TODO: Actually pull these from somewhere legit. 
-               if ($response['status'] === true){
+               if ( $response['status'] === true ) {
                        $response['message'] = "$transaction Transaction 
Successful!";
-               } elseif ($response['status'] === false){
+               } elseif ( $response['status'] === false ) {
                        $response['message'] = "$transaction Transaction 
FAILED!";
                } else {
                        $response['message'] = "$transaction Transaction... 
weird. I have no idea what happened there.";
                }
-               
+
                return $response;
-               
+
                //speaking of universal form: 
                //$result['status'] = something I wish could be boiled down to 
a bool, but that's way too optimistic, I think.
                //$result['message'] = whatever we want to display back? 
@@ -282,265 +199,76 @@
                //$result['errors'][]['value'] = Error message
                //$result['return'][$whatever] = values they pass back to us 
for whatever reason. We might... log it, or pieces of it, or something? 
        }
-       
-       function getCurlBaseOpts(){
-               //I chose to return this as a function so it's easy to 
override. 
-               //TODO: probably this for all the junk I currently have stashed 
in the constructor.
-               //...maybe. 
-               global $wgGlobalCollectTimeout, $wgPayflowGatewayUseHTTPProxy;
-               $opts = array(
-                       CURLOPT_URL => $this->url,
-                       //CURLOPT_USERAGENT => Http::userAgent(),
-                       CURLOPT_HEADER => 1,
-                       CURLOPT_RETURNTRANSFER => 1,
-                       CURLOPT_TIMEOUT => $wgGlobalCollectTimeout,
-                       //CURLOPT_FOLLOWLOCATION => 0,
-                       //CURLOPT_SSL_VERIFYPEER => 0,
-                       //CURLOPT_SSL_VERIFYHOST => 2,
-                       //CURLOPT_FORBID_REUSE => true,
-                       CURLOPT_POST => 1,
-               );
 
-               // set proxy settings if necessary
-               if ( $wgPayflowGatewayUseHTTPProxy ) {
-                       $opts[CURLOPT_HTTPPROXYTUNNEL] = 1;
-                       $opts[CURLOPT_PROXY] = $wgPayflowGatewayHTTPProxy;
-               }
-               return $opts;
-       }
-       
-       
-       function getCurlBaseHeaders(){
-               $headers = array (
-                       'Content-Type: text/' . $this->getCommunicationType() . 
'; charset=utf-8',
-               //      'X-VPS-Client-Timeout: 45',
-               //      'X-VPS-Request-ID:' . 
$this->postdatadefaults['order_id'],
-               );
-               return $headers;
-       }
-       
-       private function currentTransaction($transaction = ''){ //get&set in 
one!
-               static $current_transaction;
-               if ($transaction != ''){
-                       $current_transaction = $transaction;
-               }
-               if (!isset($current_transaction)){
-                       return false;
-               }
-               return $current_transaction;
-       }
-
-       /**
-        * Sends a name-value pair string to Payflow gateway
-        *
-        * @param $data String: The exact thing we want to send.
-        */
-       private function curl_transaction( $data ) {
-               global $wgOut; //TODO: Uhm, this shouldn't touch the view. 
Something further upstream should decide what to do with this. 
-
-               // TODO: This, but way before we get here. 
-               //$this->updateContributionTracking( $data, defined( 'OWA' ) );
-
-               // assign header data necessary for the curl_setopt() function
-               
-               $ch = curl_init();
-               
-               $headers = $this->getCurlBaseHeaders();
-               $headers[] = 'Content-Length: ' . strlen( $data );
-               
-               self::log("Sending Data: " . $data);
-               
-               $curl_opts = $this->getCurlBaseOpts();
-               $curl_opts[CURLOPT_HTTPHEADER] = $headers;
-               $curl_opts[CURLOPT_POSTFIELDS] = $data;
-               
-               foreach ($curl_opts as $option => $value){
-                       curl_setopt($ch, $option, $value);
-               }
-
-               // As suggested in the PayPal developer forum sample code, try 
more than once to get a response
-               // in case there is a general network issue
-               $i = 1;
-               
-               $return = array();
-
-               while ( $i++ <= 3 ) {
-                       self::log( $this->postdatadefaults['order_id'] . ' 
Preparing to send transaction to GlobalCollect' );
-                       $return['result'] = curl_exec( $ch );
-                       $return['headers'] = curl_getinfo( $ch );
-
-                       if ( $return['headers']['http_code'] != 200 && 
$return['headers']['http_code'] != 403 ) {
-                               self::log( $this->postdatadefaults['order_id'] 
. ' Failed sending transaction to GlobalCollect, retrying' );
-                               sleep( 1 );
-                       } elseif ( $return['headers']['http_code'] == 200 || 
$return['headers']['http_code'] == 403 ) {
-                               self::log( $this->postdatadefaults['order_id'] 
. ' Finished sending transaction to GlobalCollect' );
-                               break;
-                       }
-               }
-
-               if ( $return['headers']['http_code'] != 200 ) {
-                       $return['result'] = false;
-                       //TODO: i18n here! 
-                       $return['message'] = 'No response from credit card 
processor.  Please try again later!';
-                       $when = time();
-                       self::log( $this->postdatadefaults['order_id'] . ' No 
response from credit card processor: ' . curl_error( $ch ) );
-                       curl_close( $ch );
-                       return $return;
-               }
-
-               curl_close( $ch );
-               self::log("Results: " . print_r($return['result'], true));      
        
-               
-//             if ($this->getCommunicationType() === 'namevalue'){
-//                     $return['result'] = strstr( $return['result'], 'RESULT' 
);
-//                     //TODO: Finish this for namevalue. 
-//             }
-               if ($this->getCommunicationType() === 'xml'){
-                       //$return['result'] = 
$this->stripResponseHeaders($return['result']);
-                       $return['status'] = 
$this->parseXMLResponse($return['result']);
-               }
-               
-               return $return;
-
-               // parse string and display results to the user
-               //TODO: NO NO NO. NO DISPLAY HERE. 
-               //$this->fnPayflowGetResults( $data, $return['result'] );
-       }
-       
-       function parseXMLResponse($rawResponse){
+       function parseXMLResponse( $rawResponse ) {
                //TODO: Something.
-               $rawXML = $this->stripResponseHeaders($rawResponse);
-               if ($rawXML === false){
+               $rawXML = $this->stripResponseHeaders( $rawResponse );
+               if ( $rawXML === false ) {
                        return false;
+               } else {
+                       $rawXML = $this->formatXmlString( $rawXML );
                }
-               $realXML = new DomDocument('1.0');
-               self::log("Here is the Raw XML: " . $rawXML);
-               $realXML->loadXML(trim($rawXML));
+               $realXML = new DomDocument( '1.0' );
+               self::log( "Here is the Raw XML: " . $rawXML );
+               $realXML->loadXML( trim( $rawXML ) );
 
                $aok = true;
-               
+
                //find the node specified by the transaction structure. 
                //TODO: Error handling, because: Ugh. 
-               $result_structure = 
$this->transactions[$this->currentTransaction()]['result']; 
-               if(is_array($result_structure)){
-                       foreach ($result_structure as $key=>$value){ //should 
only be one. 
-                               foreach($realXML->getElementsByTagName($key) as 
$node) {
-                                       if ($value === 'value') { //...stupid. 
But it's 'value' as opposed to 'attribute'
-                                               if 
(array_key_exists($node->nodeValue, $this->return_value_map) && 
$this->return_value_map[$node->nodeValue] !==  true){
+               $result_structure = 
$this->transactions[$this->currentTransaction()]['result'];
+               if ( is_array( $result_structure ) ) {
+                       foreach ( $result_structure as $key => $value ) { 
//should only be one. 
+                               foreach ( $realXML->getElementsByTagName( $key 
) as $node ) {
+                                       if ( $value === 'value' ) { 
//...stupid. But it's 'value' as opposed to 'attribute'
+                                               if ( array_key_exists( 
$node->nodeValue, $this->return_value_map ) && 
$this->return_value_map[$node->nodeValue] !== true ) {
                                                        $aok = false;
-                                               }                               
                
+                                               }
                                        }
-                                       if ($value === 'attribute') {
+                                       if ( $value === 'attribute' ) {
                                                //TODO: Figure this out. This 
should mean the key name of one array up, which sounds painful.
                                        }
-                                       if (is_array($value)){
+                                       if ( is_array( $value ) ) {
                                                //TODO: ...this is looking like 
a recursive deal, here. Again. So do that. 
                                        }
                                }
                        }
                }
-               
+
                //TODO: Make this... you know: abstracty.
-               if ($aok === false){
-                       foreach($realXML->getElementsByTagName('ERROR') as 
$node) {
+               if ( $aok === false ) {
+                       foreach ( $realXML->getElementsByTagName( 'ERROR' ) as 
$node ) {
                                $errdata = '';
-                               foreach($node->childNodes as $childnode){
+                               foreach ( $node->childNodes as $childnode ) {
                                        $errdata .= "\n" . $childnode->nodeName 
. " " . $childnode->nodeValue;
 //                                     if ($childnode->nodeName == "CODE"){
 //                                             //Excellent place to deal with 
the particular codes if we want to.
 //                                     }
                                }
-                               self::log("ON NOES! ERROR: $errdata");
+                               self::log( "ON NOES! ERROR: $errdata" );
                        }
                } else {
-                       self::log("Response OK");
+                       self::log( "Response OK" );
                }
-               
+
                //TODO: The bit where you strip all the response data that we 
might want to save, toss it into an array, and hand it back.
                //We need to be handing more back here than just the... success 
or failure. Things need to be processed! I mean, probably.
-               
 
+
                return $aok;
        }
 
-       function stripResponseHeaders($rawResponse){
-               $xmlStart = strpos($rawResponse, '<?xml');
-               if ($xmlStart == false){ //I totally saw this happen one time. 
No XML, just <RESPONSE>...
-                       $xmlStart = strpos($rawResponse, '<RESPONSE');
+       function stripResponseHeaders( $rawResponse ) {
+               $xmlStart = strpos( $rawResponse, '<?xml' );
+               if ( $xmlStart == false ) { //I totally saw this happen one 
time. No XML, just <RESPONSE>...
+                       $xmlStart = strpos( $rawResponse, '<RESPONSE' );
                }
-               if ($xmlStart == false){ //Still false. Your Head Asplode.
-                       self::log("Wow, that was so messed up I couldn't even 
parse the response, so here's the thing in its entirety:\n" . $rawResponse, 
true);
+               if ( $xmlStart == false ) { //Still false. Your Head Asplode.
+                       self::log( "Wow, that was so messed up I couldn't even 
parse the response, so here's the thing in its entirety:\n" . $rawResponse );
                        return false;
                }
-               $justXML = substr($rawResponse, $xmlStart);
+               $justXML = substr( $rawResponse, $xmlStart );
                return $justXML;
        }
-       
-       
-       public static function log( $msg, $identifier='globalcollect_gateway', 
$log_level=LOG_INFO ) {
-               global $wgGlobalCollectGatewayUseSyslog;
-               
-               // if we're not using the syslog facility, use wfDebugLog
-               if ( !$wgGlobalCollectGatewayUseSyslog ) {
-                       wfDebugLog( $identifier, $msg );
-                       return;
-               }
-               
-               // otherwise, use syslogging
-               openlog( $identifier, LOG_ODELAY, LOG_SYSLOG );
-               syslog( $log_level, $msg );
-               closelog();     
-       }
 
-
-       //_______________________________________________________________
-       //copied from  payflowpro_gateway/includes/payflowUser.inc
-
-       /**
-        * Fetch and return the 'order_id' for a transaction
-        * 
-        * Since transactions to PayPal are initially matched internally on 
their end
-        * with the 'order_id' field, but we don't actually care what the order 
id is,
-        * we generate a sufficiently random number to avoid duplication. 
-        * 
-        * We go ahead and always generate a random order id becuse if PayPal 
detects
-        * the same order_id more than once, it considers the request a 
duplicate, even
-        * if the data is completely different.
-        * 
-        * @return int
-        */
-       function getOrderId() {
-               return $this->generateOrderId();
-       }
-
-       /**
-        * Generate an internal order id
-        * 
-        * This is only used internally for tracking a user's 'session' with 
the credit
-        * card form.  I mean 'session' in the sense of the moment a credit 
card page
-        * is loaded for the first time (nothing posted to it - a discrete 
donation 
-        * session) as opposed to the $_SESSION - as the $_SESSION id could 
potentially
-        * not change between contribution attempts.
-        */
-       function getInternalOrderId() {
-               global $wgRequest;
-
-               // is an order_id already set?
-               //TODO: Change all these to look instead at $this->postdata... 
I think.
-               $i_order_id = $wgRequest->getText( 'i_order_id', 0 );
-
-               // if the form was not just posted OR there's no order_id set, 
generate one.
-               if ( !$wgRequest->wasPosted() || !$i_order_id ) {
-                       $i_order_id = $this->generateOrderId();
-               }
-
-               return $i_order_id;
-       }
-
-       /**
-        * Generate an order id
-        */
-       function generateOrderId() {
-               return (double) microtime() * 1000000 . mt_rand(1000, 9999);
-       }
 }

Modified: 
branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect_gateway.php
===================================================================
--- 
branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect_gateway.php
   2011-08-31 23:24:21 UTC (rev 95922)
+++ 
branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect_gateway.php
   2011-09-01 00:43:35 UTC (rev 95923)
@@ -2,20 +2,20 @@
 
 # Alert the user that this is not a valid entry point to MediaWiki if they try 
to access the special pages file directly.
 if ( !defined( 'MEDIAWIKI' ) ) {
-        echo <<<EOT
+       echo <<<EOT
 To install GlobalCollect Gateway extension, put the following line in 
LocalSettings.php:
 require_once( 
"\$IP/extensions/globalcollect_gateway/globalcollect_gateway.php" );
 EOT;
-        exit( 1 );
+       exit( 1 );
 }
 
 // Extension credits that will show up on Special:Version
 $wgExtensionCredits['specialpage'][] = array(
-        'name' => 'GlobalCollect Gateway',
-        'author' => 'Four Kitchens',
-        'version' => '1.0.0',
-        'descriptionmsg' => 'globalcollect_gateway-desc',
-        'url' => 
'http://www.mediawiki.org/wiki/Extension:GlobalCollectGateway',
+       'name' => 'GlobalCollect Gateway',
+       'author' => 'Four Kitchens',
+       'version' => '1.0.0',
+       'descriptionmsg' => 'globalcollect_gateway-desc',
+       'url' => 'http://www.mediawiki.org/wiki/Extension:GlobalCollectGateway',
 );
 
 $wgGlobalCollectGatewayUseSyslog = false;
@@ -48,14 +48,11 @@
 $wgExtensionAliasesFiles['GlobalCollectGateway'] = $dir . 
'../payflowpro_gateway/payflowpro_gateway.alias.php';
 $wgSpecialPages['GlobalCollectGateway'] = 'GlobalCollectGateway';
 //$wgAjaxExportList[] = "fnGlobalCollectofofWork";
-
-
 // set defaults, these should be assigned in LocalSettings.php
 $wgGlobalCollectURL = 'https://ps.gcsip.nl/wdl/wdl';
 $wgGlobalCollectTestingURL = 'https://'; // GlobalCollect testing URL
 
 $wgGlobalCollectMerchantID = ''; // GlobalCollect ID
-
 // a boolean to determine if we're in testing mode
 $wgGlobalCollectGatewayTest = FALSE;
 
@@ -130,7 +127,7 @@
  * /never/ be loaded by the rapid html form loader!
  * @var string
  */
-$wgGlobalCollectAllowedHtmlForms = array(      $wgGlobalCollectHtmlFormDir . 
"/demo.html" );
+$wgGlobalCollectAllowedHtmlForms = array( $wgGlobalCollectHtmlFormDir . 
"/demo.html" );
 
 /**
  * Configure price cieling and floor for valid contribution amount.  Values 

Modified: 
branches/fundraising/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.php
===================================================================
--- 
branches/fundraising/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.php
 2011-08-31 23:24:21 UTC (rev 95922)
+++ 
branches/fundraising/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.php
 2011-09-01 00:43:35 UTC (rev 95923)
@@ -2,45 +2,45 @@
 
 # Alert the user that this is not a valid entry point to MediaWiki if they try 
to access the special pages file directly.
 if ( !defined( 'MEDIAWIKI' ) ) {
-        echo <<<EOT
+       echo <<<EOT
 To install PayflowPro Gateway extension, put the following line in 
LocalSettings.php:
 require_once( "\$IP/extensions/payflowpro_gateway/payflowpro_gateway.php" );
 EOT;
-        exit( 1 );
+       exit( 1 );
 }
 
 // Extension credits that will show up on Special:Version
 $wgExtensionCredits['specialpage'][] = array(
-        'name' => 'PayflowPro Gateway',
-        'author' => 'Four Kitchens',
-        'version' => '1.0.0',
-        'descriptionmsg' => 'payflowpro_gateway-desc',
-        'url' => 'http://www.mediawiki.org/wiki/Extension:PayflowProGateway',
+       'name' => 'PayflowPro Gateway',
+       'author' => 'Four Kitchens',
+       'version' => '1.0.0',
+       'descriptionmsg' => 'payflowpro_gateway-desc',
+       'url' => 'http://www.mediawiki.org/wiki/Extension:PayflowProGateway',
 );
 
 // Set up the new special page
 $dir = dirname( __FILE__ ) . '/';
 $wgAutoloadClasses['PayflowProGateway'] = $dir . 'payflowpro_gateway.body.php';
 
-$wgAutoloadClasses[ 'PayflowProGateway_Form' ] = $dir . 'forms/Form.php';
-$wgAutoloadClasses[ 'PayflowProGateway_Form_OneStepTwoColumn' ] = $dir . 
'forms/OneStepTwoColumn.php';
-$wgAutoloadClasses[ 'PayflowProGateway_Form_TwoStepTwoColumn' ] = $dir . 
'forms/TwoStepTwoColumn.php';
-$wgAutoloadClasses[ 'PayflowProGateway_Form_TwoColumnPayPal' ] = $dir . 
'forms/TwoColumnPayPal.php';
-$wgAutoloadClasses[ 'PayflowProGateway_Form_TwoColumnLetter' ] = $dir . 
'forms/TwoColumnLetter.php';
-$wgAutoloadClasses[ 'PayflowProGateway_Form_TwoColumnLetter2' ] = $dir . 
'forms/TwoColumnLetter2.php';
-$wgAutoloadClasses[ 'PayflowProGateway_Form_TwoColumnLetter3' ] = $dir . 
'forms/TwoColumnLetter3.php';
-$wgAutoloadClasses[ 'PayflowProGateway_Form_TwoColumnLetter4' ] = $dir . 
'forms/TwoColumnLetter4.php';
-$wgAutoloadClasses[ 'PayflowProGateway_Form_TwoColumnLetter5' ] = $dir . 
'forms/TwoColumnLetter5.php';
-$wgAutoloadClasses[ 'PayflowProGateway_Form_TwoColumnLetter6' ] = $dir . 
'forms/TwoColumnLetter6.php';
-$wgAutoloadClasses[ 'PayflowProGateway_Form_TwoColumnLetter7' ] = $dir . 
'forms/TwoColumnLetter7.php';
-$wgAutoloadClasses[ 'PayflowProGateway_Form_TwoStepTwoColumnLetter' ] = $dir . 
'forms/TwoStepTwoColumnLetter.php';
-$wgAutoloadClasses[ 'PayflowProGateway_Form_TwoStepTwoColumnLetterCA' ] = $dir 
. 'forms/TwoStepTwoColumnLetterCA.php';
-$wgAutoloadClasses[ 'PayflowProGateway_Form_TwoStepTwoColumnLetter2' ] = $dir 
. 'forms/TwoStepTwoColumnLetter2.php';
-$wgAutoloadClasses[ 'PayflowProGateway_Form_TwoStepTwoColumnLetter3' ] = $dir 
. 'forms/TwoStepTwoColumnLetter3.php';
-$wgAutoloadClasses[ 'PayflowProGateway_Form_TwoStepTwoColumnPremium' ] = $dir 
. 'forms/TwoStepTwoColumnPremium.php';
-$wgAutoloadClasses[ 'PayflowProGateway_Form_TwoStepTwoColumnPremiumUS' ] = 
$dir . 'forms/TwoStepTwoColumnPremiumUS.php';
-$wgAutoloadClasses[ 'PayflowProGateway_Form_RapidHtml' ] = $dir . 
'forms/RapidHtml.php';
-$wgAutoloadClasses[ 'PayflowProGateway_Form_SingleColumn' ] = $dir . 
'forms/SingleColumn.php';
+$wgAutoloadClasses['PayflowProGateway_Form'] = $dir . 'forms/Form.php';
+$wgAutoloadClasses['PayflowProGateway_Form_OneStepTwoColumn'] = $dir . 
'forms/OneStepTwoColumn.php';
+$wgAutoloadClasses['PayflowProGateway_Form_TwoStepTwoColumn'] = $dir . 
'forms/TwoStepTwoColumn.php';
+$wgAutoloadClasses['PayflowProGateway_Form_TwoColumnPayPal'] = $dir . 
'forms/TwoColumnPayPal.php';
+$wgAutoloadClasses['PayflowProGateway_Form_TwoColumnLetter'] = $dir . 
'forms/TwoColumnLetter.php';
+$wgAutoloadClasses['PayflowProGateway_Form_TwoColumnLetter2'] = $dir . 
'forms/TwoColumnLetter2.php';
+$wgAutoloadClasses['PayflowProGateway_Form_TwoColumnLetter3'] = $dir . 
'forms/TwoColumnLetter3.php';
+$wgAutoloadClasses['PayflowProGateway_Form_TwoColumnLetter4'] = $dir . 
'forms/TwoColumnLetter4.php';
+$wgAutoloadClasses['PayflowProGateway_Form_TwoColumnLetter5'] = $dir . 
'forms/TwoColumnLetter5.php';
+$wgAutoloadClasses['PayflowProGateway_Form_TwoColumnLetter6'] = $dir . 
'forms/TwoColumnLetter6.php';
+$wgAutoloadClasses['PayflowProGateway_Form_TwoColumnLetter7'] = $dir . 
'forms/TwoColumnLetter7.php';
+$wgAutoloadClasses['PayflowProGateway_Form_TwoStepTwoColumnLetter'] = $dir . 
'forms/TwoStepTwoColumnLetter.php';
+$wgAutoloadClasses['PayflowProGateway_Form_TwoStepTwoColumnLetterCA'] = $dir . 
'forms/TwoStepTwoColumnLetterCA.php';
+$wgAutoloadClasses['PayflowProGateway_Form_TwoStepTwoColumnLetter2'] = $dir . 
'forms/TwoStepTwoColumnLetter2.php';
+$wgAutoloadClasses['PayflowProGateway_Form_TwoStepTwoColumnLetter3'] = $dir . 
'forms/TwoStepTwoColumnLetter3.php';
+$wgAutoloadClasses['PayflowProGateway_Form_TwoStepTwoColumnPremium'] = $dir . 
'forms/TwoStepTwoColumnPremium.php';
+$wgAutoloadClasses['PayflowProGateway_Form_TwoStepTwoColumnPremiumUS'] = $dir 
. 'forms/TwoStepTwoColumnPremiumUS.php';
+$wgAutoloadClasses['PayflowProGateway_Form_RapidHtml'] = $dir . 
'forms/RapidHtml.php';
+$wgAutoloadClasses['PayflowProGateway_Form_SingleColumn'] = $dir . 
'forms/SingleColumn.php';
 
 $wgExtensionMessagesFiles['PayflowProGateway'] = $dir . 
'payflowpro_gateway.i18n.php';
 $wgExtensionMessagesFiles['PayflowProGatewayCountries'] = $dir . 
'payflowpro_gateway.countries.i18n.php';
@@ -60,7 +60,6 @@
 $wgPayflowProVendorID = ''; // paypal merchant login ID
 $wgPayflowProUserID = ''; // if one or more users are set up, authorized user 
ID, else same as VENDOR
 $wgPayflowProPassword = ''; // merchant login password
-
 // a boolean to determine if we're in testing mode
 $wgPayflowGatewayTest = FALSE;
 
@@ -140,7 +139,7 @@
  * /never/ be loaded by the rapid html form loader!
  * @var string
  */
-$wgPayflowAllowedHtmlForms = array(    $wgPayflowHtmlFormDir . "/demo.html" );
+$wgPayflowAllowedHtmlForms = array( $wgPayflowHtmlFormDir . "/demo.html" );
 
 /**
  * Configure PayflowproGateway to use syslog for log messages rather than 
wfDebugLog
@@ -166,8 +165,8 @@
 $wgHooks['DonationInterface_Page'][] = 'pfpGatewayPage';
 
 // enable the API
-$wgAPIModules[ 'pfp' ] = 'ApiPayflowProGateway';
-$wgAutoloadClasses[ 'ApiPayflowProGateway' ] = $dir . 
'api_payflowpro_gateway.php';
+$wgAPIModules['pfp'] = 'ApiPayflowProGateway';
+$wgAutoloadClasses['ApiPayflowProGateway'] = $dir . 
'api_payflowpro_gateway.php';
 
 function payflowGatewayConnection() {
        global $wgPayflowGatewayDBserver, $wgPayflowGatewayDBname;
@@ -176,12 +175,12 @@
        static $db;
 
        if ( !$db ) {
-                       $db = new DatabaseMysql(
-                                       $wgPayflowGatewayDBserver,
-                                       $wgPayflowGatewayDBuser,
-                                       $wgPayflowGatewayDBpassword,
-                                       $wgPayflowGatewayDBname );
-                                       $db->query( "SET names utf8" );
+               $db = new DatabaseMysql(
+                               $wgPayflowGatewayDBserver,
+                               $wgPayflowGatewayDBuser,
+                               $wgPayflowGatewayDBpassword,
+                               $wgPayflowGatewayDBname );
+               $db->query( "SET names utf8" );
        }
 
        return $db;
@@ -193,17 +192,17 @@
  */
 function pfpGatewayValue( &$values ) {
        $values['payflow'] = array(
-                       'gateway' => 'payflow',
-                       'display_name' => 'Credit Card',
-                       'form_value' => 'payflow',
-                       'currencies' => array(
-                                       'GBP' => 'GBP: British Pound',
-                                       'EUR' => 'EUR: Euro',
-                                       'USD' => 'USD: U.S. Dollar',
-                                       'AUD' => 'AUD: Australian Dollar',
-                                       'CAD' => 'CAD: Canadian Dollar',
-                                       'JPY' => 'JPY: Japanese Yen',
-                       ),
+               'gateway' => 'payflow',
+               'display_name' => 'Credit Card',
+               'form_value' => 'payflow',
+               'currencies' => array(
+                       'GBP' => 'GBP: British Pound',
+                       'EUR' => 'EUR: Euro',
+                       'USD' => 'USD: U.S. Dollar',
+                       'AUD' => 'AUD: Australian Dollar',
+                       'CAD' => 'CAD: Canadian Dollar',
+                       'JPY' => 'JPY: Japanese Yen',
+               ),
        );
 
        return true;

Added: 
branches/fundraising/extensions/DonationInterface/tests/DonationInterfaceTest.php
===================================================================
--- 
branches/fundraising/extensions/DonationInterface/tests/DonationInterfaceTest.php
                           (rev 0)
+++ 
branches/fundraising/extensions/DonationInterface/tests/DonationInterfaceTest.php
   2011-09-01 00:43:35 UTC (rev 95923)
@@ -0,0 +1,27 @@
+<?php
+
+/**
+ * TODO: Something. 
+ * Something roughly test-shaped. Here.
+ * ...to be more precise: Test that ALL the gateway adapters (Yes: All two of 
them)
+ * are building the XML we think they are, and that they can process sample 
+ * return XML the way we think they should. 
+ * 
+ * TODO: Then, write all the other tests as well. :|
+ * 
+ * @group Fundraising
+ * @group Splunge
+ * @author Katie Horn <[email protected]>
+ */
+class DonationInterfaceTest extends MediaWikiTestCase {
+
+       /**
+        * This test is deeply stupid, btw. 
+        */
+       function assertTestClassExists() {
+               $this->assertTrue( true, "WeeeooooOOOHOO!!1one1" );
+       }
+
+}
+
+?>


Property changes on: 
branches/fundraising/extensions/DonationInterface/tests/DonationInterfaceTest.php
___________________________________________________________________
Added: svn:eol-style
   + native


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to