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

Revision: 100132
Author:   khorn
Date:     2011-10-18 17:36:59 +0000 (Tue, 18 Oct 2011)
Log Message:
-----------
Merging the fundraising branch of DonationInterface back into trunk.
Relatively straightforward merge changes, with some deletions, and one new 
file. 
As this is a mid-merge commit, the extension will be broken until the merge is 
completed.

Modified Paths:
--------------
    trunk/extensions/DonationInterface/activemq_stomp/Stomp.php
    trunk/extensions/DonationInterface/activemq_stomp/activemq_stomp.php
    
trunk/extensions/DonationInterface/payflowpro_gateway/api_payflowpro_gateway.php

Added Paths:
-----------
    trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro.adapter.php

Removed Paths:
-------------
    trunk/extensions/DonationInterface/donate_interface/chapters.inc
    trunk/extensions/DonationInterface/donate_interface/country2currency.inc
    trunk/extensions/DonationInterface/donate_interface/donate_interface.php
    
trunk/extensions/DonationInterface/donate_interface/donate_interface_validate_donation.js
    trunk/extensions/DonationInterface/donate_interface/validate_donation.js

Modified: trunk/extensions/DonationInterface/activemq_stomp/Stomp.php
===================================================================
--- trunk/extensions/DonationInterface/activemq_stomp/Stomp.php 2011-10-18 
17:32:20 UTC (rev 100131)
+++ trunk/extensions/DonationInterface/activemq_stomp/Stomp.php 2011-10-18 
17:36:59 UTC (rev 100132)
@@ -456,6 +456,8 @@
     {
                if ( $this->clientId != null ) {
                        $headers["client-id"] = $this->clientId;
+               } else {
+                       $headers = array();
                }
 
         if ( is_resource( $this->_socket ) ) {

Modified: trunk/extensions/DonationInterface/activemq_stomp/activemq_stomp.php
===================================================================
--- trunk/extensions/DonationInterface/activemq_stomp/activemq_stomp.php        
2011-10-18 17:32:20 UTC (rev 100131)
+++ trunk/extensions/DonationInterface/activemq_stomp/activemq_stomp.php        
2011-10-18 17:36:59 UTC (rev 100132)
@@ -1,11 +1,12 @@
 <?php
+
 # 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 my extension, put the following line in LocalSettings.php:
 require_once( 
"\$IP/extensions/DonationInterface/activemq_stomp/activemq_stomp.php" );
 EOT;
-  exit( 1 );
+       exit( 1 );
 }
 
 $wgExtensionCredits['other'][] = array(
@@ -16,18 +17,10 @@
        'version' => '1.0.0',
 );
 
-$dir = dirname( __FILE__ ) . '/';
+/*
+ * Create <donate /> tag to include landing page donation form
+ */
 
-$wgAutoloadClasses['activemq_stomp'] = $dir . 'activemq_stomp.php'; # Tell 
MediaWiki to load the extension body.
-
-// default variables that should be set in LocalSettings
-$wgStompServer = "";
-
-$wgHooks['ParserFirstCallInit'][] = 'efStompSetup';
-
-/*
-* Create <donate /> tag to include landing page donation form
-*/
 function efStompSetup( &$parser ) {
        // redundant and causes Fatal Error
        // $parser->disableCache();
@@ -48,19 +41,17 @@
 }
 
 /**
-* Hook to get user provided and order data
-*
-*/
-$wgHooks['gwStomp'][] = 'sendSTOMP';
-$wgHooks['gwPendingStomp'][] = 'sendPendingSTOMP';
-
-/*
-* Hook to send transaction information to ActiveMQ server
-*/
+ * Hook to send complete transaction information to ActiveMQ server
+ * @global string $wgStompServer ActiveMQ server name. 
+ * @global string $wgStompQueueName Name of the destination queue for 
completed transactions. 
+ * @param array $transaction Key-value array of staged and ready donation 
data. 
+ * @return bool Just returns true all the time. Presumably an indication that 
+ * nothing exploded big enough to kill the whole thing.
+ */
 function sendSTOMP( $transaction ) {
        global $wgStompServer, $wgStompQueueName;
 
-       $queueName = isset ( $wgStompQueueName ) ? $wgStompQueueName : 'test';
+       $queueName = isset( $wgStompQueueName ) ? $wgStompQueueName : 'test';
 
        // include a library
        require_once( "Stomp.php" );
@@ -77,7 +68,7 @@
        $result = $con->send( "/queue/$queueName", $message, array( 
'persistent' => 'true' ) );
 
        if ( !$result ) {
-                       wfDebugLog( 'activemq_stomp', 'Send to Q failed for 
this message: ' . $message );
+               wfDebugLog( 'activemq_stomp', 'Send to Q failed for this 
message: ' . $message );
        }
 
        $con->disconnect();
@@ -85,13 +76,20 @@
        return true;
 }
 
-/*
-* Hook to send transaction information to ActiveMQ server
-*/
+/**
+ * Hook to send transaction information to ActiveMQ server
+ * TODO: Parameterize sendStomp instead of maintaining this copy. 
+ * @global string $wgStompServer ActiveMQ server name. 
+ * @global string $wgPendingStompQueueName Name of the destination queue for 
+ * pending transactions. 
+ * @param array $transaction Key-value array of staged and ready donation 
data. 
+ * @return bool Just returns true all the time. Presumably an indication that 
+ * nothing exploded big enough to kill the whole thing.
+ */
 function sendPendingSTOMP( $transaction ) {
        global $wgStompServer, $wgPendingStompQueueName;
 
-       $queueName = isset ( $wgPendingStompQueueName ) ? 
$wgPendingStompQueueName : 'pending';
+       $queueName = isset( $wgPendingStompQueueName ) ? 
$wgPendingStompQueueName : 'pending';
 
        // include a library
        require_once( "Stomp.php" );
@@ -108,7 +106,7 @@
        $result = $con->send( "/queue/$queueName", $message, array( 
'persistent' => 'true' ) );
 
        if ( !$result ) {
-                       wfDebugLog( 'activemq_stomp', 'Send to Pending Q failed 
for this message: ' . $message );
+               wfDebugLog( 'activemq_stomp', 'Send to Pending Q failed for 
this message: ' . $message );
        }
 
        $con->disconnect();
@@ -118,6 +116,9 @@
 
 /**
  * Assign correct values to the array of data to be sent to the ActiveMQ server
+ * TODO: Probably something else. I don't like the way this works and neither 
do you.
+ * 
+ * Older notes follow:  
  * TODO: include optout and comments option in the donation page
  * NOTES: includes middle name
  * Currency in receiving module has currency set to USD, should take passed 
variable for these
@@ -134,44 +135,44 @@
        // edit this array to include/ignore transaction data sent to the server
        $message = array(
                'contribution_tracking_id' => 
$transaction['contribution_tracking_id'],
-               'optout'                 => $transaction['optout'],
-               'anonymous'              => $transaction['anonymous'],
-               'comment'                => $transaction['comment'],
-               'size'                   => $transaction['size'],
-               'premium_language'       => $transaction['premium_language'],
-               'utm_source'             => $transaction['utm_source'],
-               'utm_medium'             => $transaction['utm_medium'],
-               'utm_campaign'           => $transaction['utm_campaign'],
-               'language'               => $transaction['language'],
-               'referrer'               => $transaction['referrer'],
-               'email'                  => $transaction['email'],
-               'first_name'             => $transaction['fname'],
-               'middle_name'            => $transaction['mname'],
-               'last_name'              => $transaction['lname'],
-               'street_address'         => $transaction['street'],
+               'optout' => $transaction['optout'],
+               'anonymous' => $transaction['anonymous'],
+               'comment' => $transaction['comment'],
+               'size' => $transaction['size'],
+               'premium_language' => $transaction['premium_language'],
+               'utm_source' => $transaction['utm_source'],
+               'utm_medium' => $transaction['utm_medium'],
+               'utm_campaign' => $transaction['utm_campaign'],
+               'language' => $transaction['language'],
+               'referrer' => $transaction['referrer'],
+               'email' => $transaction['email'],
+               'first_name' => $transaction['fname'],
+               'middle_name' => $transaction['mname'],
+               'last_name' => $transaction['lname'],
+               'street_address' => $transaction['street'],
                'supplemental_address_1' => '',
-               'city'                   => $transaction['city'],
-               'state_province'         => $transaction['state'],
-               'country'                => $transaction['country'],
-               'postal_code'            => $transaction['zip'],
-               'first_name_2'           => $transaction['fname2'],
-               'last_name_2'            => $transaction['lname2'],
-               'street_address_2'       => $transaction['street2'],
+               'city' => $transaction['city'],
+               'state_province' => $transaction['state'],
+               'country' => $transaction['country'],
+               'postal_code' => $transaction['zip'],
+               'first_name_2' => $transaction['fname2'],
+               'last_name_2' => $transaction['lname2'],
+               'street_address_2' => $transaction['street2'],
                'supplemental_address_2' => '',
-               'city_2'                 => $transaction['city2'],
-               'state_province_2'       => $transaction['state2'],
-               'country_2'              => $transaction['country2'],
-               'postal_code_2'          => $transaction['zip'],
-               'gateway'                => $transaction[ 'gateway' ],
-               'gateway_txn_id'         => $transaction['PNREF'],
-               'response'               => $transaction['RESPMSG'],
-               'currency'               => $transaction['currency'],
-               'original_currency'      => $transaction['currency'],
-               'original_gross'         => $transaction['amount'],
-               'fee'                    => '0',
-               'gross'                  => $transaction['amount'],
-               'net'                    => $transaction['amount'],
-               'date'                   => $transaction['date'],
+               'city_2' => $transaction['city2'],
+               'state_province_2' => $transaction['state2'],
+               'country_2' => $transaction['country2'],
+               'postal_code_2' => $transaction['zip2'],
+               'gateway' => $transaction['gateway'],
+               'gateway_txn_id' => $transaction['gateway_txn_id'],
+               'response' => $transaction['response'],
+               'currency' => $transaction['currency'],
+               'original_currency' => $transaction['currency'],
+               'original_gross' => $transaction['amount'],
+               'fee' => '0',
+               'gross' => $transaction['amount'],
+               'net' => $transaction['amount'],
+               'date' => $transaction['date'],
        );
 
        return $message;

Deleted: trunk/extensions/DonationInterface/donate_interface/chapters.inc
===================================================================
--- trunk/extensions/DonationInterface/donate_interface/chapters.inc    
2011-10-18 17:32:20 UTC (rev 100131)
+++ trunk/extensions/DonationInterface/donate_interface/chapters.inc    
2011-10-18 17:36:59 UTC (rev 100132)
@@ -1,46 +0,0 @@
-<?php
-
-function fnDonateGetChapter($country = NULL) {
-  
-  switch ($country) {
-          
-            case 'AR':
-                    return 'www.wikimedia.org.ar';
-            case 'AU':
-                    return 'www.wikimedia.org.au';
-            case 'AT':
-                    return 'www.wikimedia.at';
-            case 'BR':
-                    return 'www.wikimedia.org.br';
-            case 'CZ':
-                    return 'www.wikimedia.cz';
-            case 'CH':
-                    return 'CHF';
-            case 'CZ':
-                    return 'CZK'; 
-            case 'DK':
-                    return 'DKK';
-            case 'HK':
-                    return 'HKD';
-            case 'HU':
-                    return 'HUF';
-            case 'JP':
-                    return 'JPY';
-            case 'NZ':
-                    return 'NZD';
-            case 'NO':
-                    return 'NOK';
-            case 'PL':
-                    return 'PLN';
-            case 'SG':
-                    return 'SGD';
-            case 'SE':
-                    return 'SEK';
-            case 'IL':
-                    return 'ILS';                 
-    }
-    
-    return NULL;
-    
-    //http://wikimediafoundation.org/wiki/Local_chapters
-}
\ No newline at end of file

Deleted: 
trunk/extensions/DonationInterface/donate_interface/country2currency.inc
===================================================================
--- trunk/extensions/DonationInterface/donate_interface/country2currency.inc    
2011-10-18 17:32:20 UTC (rev 100131)
+++ trunk/extensions/DonationInterface/donate_interface/country2currency.inc    
2011-10-18 17:36:59 UTC (rev 100132)
@@ -1,66 +0,0 @@
-<?php
-
-function fnCountry2Currency($country = NULL) {
-  
-  switch ($country) {
-            case 'CA':
-                    return 'CAD';
-            case 'US':
-                    return 'USD';
-            //euro countries
-            case 'FR':
-            case 'DE':
-            case 'BE':
-            case 'IE':
-            case 'GR':
-            case 'ES':
-            case 'FR':
-            case 'IT':
-            case 'CY':
-            case 'LU':
-            case 'MT':
-            case 'NL':
-            case 'AT':
-            case 'PT':
-            case 'SI':
-            case 'SK':
-            case 'FI':
-            case 'MC':
-            case 'SM':
-            case 'VA':
-            case 'AD':
-            case 'ME':
-                    return 'EUR';
-            case 'GB':
-            case 'UK':
-                    return 'GBP';
-            case 'AU':
-                    return 'AUD';
-            case 'CH':
-                    return 'CHF';
-            case 'CZ':
-                    return 'CZK'; 
-            case 'DK':
-                    return 'DKK';
-            case 'HK':
-                    return 'HKD';
-            case 'HU':
-                    return 'HUF';
-            case 'JP':
-                    return 'JPY';
-            case 'NZ':
-                    return 'NZD';
-            case 'NO':
-                    return 'NOK';
-            case 'PL':
-                    return 'PLN';
-            case 'SG':
-                    return 'SGD';
-            case 'SE':
-                    return 'SEK';
-            case 'IL':
-                    return 'ILS';                 
-    }
-    
-    return 'USD';
-}
\ No newline at end of file

Deleted: 
trunk/extensions/DonationInterface/donate_interface/donate_interface.php
===================================================================
--- trunk/extensions/DonationInterface/donate_interface/donate_interface.php    
2011-10-18 17:32:20 UTC (rev 100131)
+++ trunk/extensions/DonationInterface/donate_interface/donate_interface.php    
2011-10-18 17:36:59 UTC (rev 100132)
@@ -1,349 +0,0 @@
-<?php
-/**
- * DonateInterface extension
- *
- * @file
- * @ingroup Extensions
- * @link http://www.mediawiki.org/wiki/Extension:DonateInterface Documentation
- */
-
-if ( !defined( 'MEDIAWIKI' ) ) {
-       die( "This is not a valid entry point.\n" );
-}
-
-// Extension credits that will show up on Special:Version
-
-$wgExtensionCredits['specialpage'][] = array(
-       'path' => __FILE__,
-       'name' => 'DonateInterface',
-       // 'author' => array( 'diana' ), // FIXME: Committer does not have 
details in http://svn.wikimedia.org/viewvc/mediawiki/USERINFO/
-       'descriptionmsg' => 'donate_interface-desc',
-       'url' => 'http://www.mediawiki.org/wiki/Extension:DonateInterface',
-);
-
-// Set up i18n
-$dir = dirname( __FILE__ ) . '/';
-$wgExtensionMessagesFiles['DonateInterface'] = $dir . 
'donate_interface.i18n.php';
-
-$wgHooks['ParserFirstCallInit'][] = 'efDonateSetup';
-$wgHooks['DonationInterface_DisplayForm'][] = 'fnProcessDonationForm';
-
-/**
- * Create <donate /> tag to include landing page donation form
- */
-function efDonateSetup( &$parser ) {
-       $parser->setHook( 'donate', 'efDonateRender' );
-
-       return true;
-}
-
-
-
-/**
- * Function called by the <donate> parser tag
- *
- * Outputs the donation landing page form which collects
- * the donation amount, currency and payment processor type.
- */
-function efDonateRender( $input, $args, $parser ) {
-       global $wgOut, $wgExtensionAssetsPath;
-       static $formProcessed = false;
-
-       $parser->disableCache();
-
-       // if chapter exists for user's country, redirect
-       // not currently in use - in place for adding it when ready
-       // $chapter = fnDonateChapterRedirect();
-
-       // add JavaScript validation to <head>
-       $wgOut->addScriptFile( $wgExtensionAssetsPath . 
'/DonationInterface/donate_interface/donate_interface_validate_donation.js' );
-
-       if ( !$formProcessed ) {
-         // process form
-           wfRunHooks( 'DonationInterface_DisplayForm' );
-               $formProcessed = true;
-       }
-
-       // display form to gather data from user
-       $output = fnDonateCreateOutput();
-
-       return $output;
-}
-
-/**
- * Supplies the form to efDonateRender()
- *
- * Payment gateway options are created with the hook "gwValue". Each potential 
payment
- * option supplies it's value and name for the form, as well as currencies it 
supports.
- */
-function fnDonateCreateOutput() {
-       global $wgRequest;
-
-       // set them equal to post data
-       $utm_source = $wgRequest->getText( 'utm_source' );
-       $utm_medium = $wgRequest->getText( 'utm_medium' );
-       $utm_campaign = $wgRequest->getText( 'utm_campaign' );
-       $referrer = $wgRequest->getHeader( 'referer' );
-
-       // get language from URL
-       $url = $wgRequest->getRequestURL();
-
-       if ( $url ) {
-               $getLang = explode( '/', $url );
-               $language = substr( $getLang[3], 0, 2 );
-       }
-
-       // error check and set "en" as default
-       if ( !preg_match( '/^[a-z-]+$/', $language ) ) {
-               $language = 'en';
-       }
-
-       // get payment method gateway value and name from each gateway and 
create menu of options
-       $values = array();
-       wfRunHooks( 'DonationInterface_Value', array( &$values ) );
-
-       $gatewayMenu = '';
-
-       foreach ( $values as $current ) {
-               $gatewayMenu .= Xml::option( $current['display_name'], 
$current['form_value'] );
-       }
-
-    // get available currencies
-
-       $currencies = array( 'USD' => "USD: U.S. Dollar" );
-       // FIXME: It uses the currencies of the last gateway to be loaded. It 
should probably use the union of currencies, (currencies allowed by any 
gateway).
-    foreach ( $values as $key ) {
-               if ( isset( $key['currencies'] ) ) {
-                       $currencies = $key['currencies'];
-               }
-    }
-
-       $currencyMenu = '';
-
-       foreach ( $currencies as $value => $fullName ) {
-               $currencyMenu .= Xml::option( $fullName, $value );
-       }
-
-    $output = Xml::openElement( 'form', array( 'name' => "donate", 'method' => 
"post", 'action' => "", 'onsubmit' => 'return DonateValidateForm(this)' ) ) .
-               Xml::openElement( 'div', array( 'id' => 'mw-donation-intro' ) ) 
.
-               Xml::element( 'p', array( 'class' => 'mw-donation-intro-text' 
), wfMsg( 'donate_interface-intro' ) ) .
-               Xml::closeElement( 'div' );
-
-    $output .= Html::hidden( 'utm_source', $utm_source ) .
-        Html::hidden( 'utm_medium', $utm_medium ) .
-        Html::hidden( 'utm_campaign', $utm_campaign ) .
-        Html::hidden( 'language', $language ) .
-        Html::hidden( 'referrer', $referrer ) .
-        Html::hidden( 'process', '_yes_' );
-
-    $amount = array(
-        Xml::radioLabel( wfMsg( 'donate_interface-big-amount-display' ), 
'amount', wfMsg( 'donate_interface-big-amount-value' ), 'input_amount_3', false 
 ),
-        Xml::radioLabel( wfMsg( 'donate_interface-medium-amount-display' ), 
'amount', wfMsg( 'donate_interface-medium-amount-value' ), 'input_amount_2', 
false ),
-        Xml::radioLabel( wfMsg( 'donate_interface-small-amount-display' ), 
'amount', wfMsg( 'donate_interface-small-amount-value' ), 'input_amount_1', 
false ),
-        Xml::inputLabel( wfMsg( 'donate_interface-other-amount' ), 
'amountGiven', 'input_amount_other', '5' ),
-    );
-
-       $amountFields = '<table><tr>';
-       foreach ( $amount as $value ) {
-               $amountFields .= '<td>' . $value . '</td>';
-       }
-       $amountFields .= '</tr></table>';
-
-       $output .= Xml::fieldset( wfMsg( 'donate_interface-amount' ), 
$amountFields,  array( 'class' => "mw-donation-amount" ) );
-
-       // Build currency options
-       $default_currency = fnDonateDefaultCurrency();
-
-       $currency_options = '';
-    foreach ( $currencies as $code => $name ) {
-               $selected = '';
-               if ( $code == $default_currency ) {
-                       $selected = ' selected="selected"';
-               }
-               $currency_options .= '<option value="' . $code . '"' . 
$selected . '>' . wfMsg( 'donate_interface-' . $code ) . '</option>';
-    }
-
-       $currencyFields = Xml::openElement( 'select', array( 'name' => 
'currency_code', 'id' => "input_currency_code" ) ) .
-            $currency_options .
-              Xml::closeElement( 'select' );
-
-       $output .= Xml::fieldset( wfMsg( 'donate_interface-currency' ), 
$currencyFields,  array( 'class' => "mw-donation-currency" ) );
-
-       $gatewayFields = Xml::openElement( 'select', array( 'name' => 
'payment_method', 'id' => 'select_payment_method' ) ) .
-              $gatewayMenu .
-              Xml::closeElement( 'select' );
-
-       $output .= Xml::fieldset( wfMsg( 'donate_interface-gateway' ), 
$gatewayFields,  array( 'class' => 'mw-donation-gateway' ) );
-
-       $publicComment = Xml::element( 'div', array( 'class' => 
'mw-donation-comment-message' ), wfMsg( 'donate_interface-comment-message' ) ) .
-        Xml::inputLabel( wfMsg( 'donate_interface-comment-label' ), 'comment', 
'comment', '30', '', array( 'maxlength' => '200' ) ) .
-        Xml::openElement( 'div', array( 'id' => 'mw-donation-checkbox' ) ) .
-        Xml::checkLabel( wfMsg( 'donate_interface-anon-message' ), 
'comment-option', 'input_comment-option', TRUE ) .
-        Xml::closeElement( 'div' ) .
-        Xml::openElement( 'div', array( 'id' => 'mw-donation-checkbox' ) ) .
-        Xml::check( 'email-opt', TRUE ) .
-        Xml::tags( 'span', array( 'class' => 'mw-email-agreement' ), wfMsg( 
'donate_interface-email-agreement' ) ) .
-        Xml::closeElement( 'div' );
-
-       $output .= Xml::fieldset( wfMsg( 'donate_interface-comment-title' ), 
$publicComment, array( 'class' => 'mw-donation-public-comment' ) );
-
-       $output .= Xml::submitButton( wfMsg( 'donate_interface-submit-button' ) 
);
-
-       $output .= Xml::closeElement( 'form' );
-
-       // NOTE: For testing: show country of origin
-       // $country = fnDonateGetCountry();
-       // $output .= Xml::element('p', array('class' => 
'mw-donation-test-message'), 'Country:' . $country);
-
-       // NOTE: for testing: show default currency
-       // $currencyTest = fnDonateDefaultCurrency();
-       // $output .= Xml::element('p', array('class' => 
'mw-donation-test-message'), wfMsg( 'donate_interface-currency' ) . 
$currencyTest);
-
-       // NOTE: for testing: show IP address
-       // $referrer = $_SERVER['HTTP_REFERER'];
-       // $output .= '<p>' . 'Referrer:' . $referrer . '</p>';
-
-       // for testing to show language culled from URL
-       $output .= '<p>' . ' Language: ' . $language . '</p>';
-
-       return $output;
-}
-
-/*
-* Redirects user to their chosen payment processor
-*
-* Includes the user's input passed as GET
-* $url for the gateway was supplied with the gwPage hook and the key
-* matches the form value (also supplied by the gateway)
-*/
-function fnDonateRedirectToProcessorPage( $userInput, $url ) {
-       global $wgOut;
-
-       $chosenGateway = $userInput['gateway'];
-
-       $redirectionData = wfArrayToCGI( $userInput );
-
-       // $wgOut->redirect(
-       // $wgPaymentGatewayHost . $url[$chosenGateway] . $redirectionData
-       // );
-
-       $wgOut->redirect(
-               $url[$chosenGateway] . '&' . $redirectionData
-       );
-}
-
-/**
- * Gets country code based on IP if GeoIP extension is installed
- * returns country code or UNKNOWN if unable to assign one
- */
-function fnDonateGetCountry() {
-       $country_code = null;
-
-       if ( function_exists( 'fnGetGeoIP' ) ) {
-               try {
-                       $country_code = fnGetGeoIP();
-               } catch ( NotFoundGeoIP $e ) {
-                       $country_code = 'UNKNOWN';
-               } catch ( UnsupportedGeoIP $e ) {
-                       $country_code = 'UNKNOWN';
-               }
-       }
-
-       return $country_code;
-}
-
-/**
- * Uses GeoIP extension to translate country based on IP
- * into default currency shown in drop down menu
- */
-function fnDonateDefaultCurrency() {
-       require_once( 'country2currency.inc' );
-
-       $country_code = null;
-
-       if ( function_exists( 'fnGetCountry' ) ) {
-               $country_code = fnGetCountry();
-       }
-
-       $currency = fnCountry2Currency( $country_code );
-
-       return $currency ? $currency : 'USD';
-}
-
-/**
- * Will use GeoIP extension to redirect user to
- * chapter page as dictated by IP address
- * NOT CURRENTLY IN USE
- */
-function fnDonateChapterRedirect() {
-       require_once( 'chapters.inc' );
-
-  $country_code = null;
-
-       if ( function_exists( 'fnGetCountry' ) ) {
-               $country_code = fnDonateGetCountry();
-       }
-
-       $chapter = fnDonateGetChapter( $country_code );
-
-       if ( $chapter ) {
-               global $wgOut;
-               $wgOut->redirect( 'http://' . $chapter );
-       } else {
-               return null;
-       }
-
-}
-
-function fnProcessDonationForm( ) {
-  global $wgRequest, $wgOut;
-
-    // Checking that it was posted is not enough, donate_interface-amount-error
-    // would be shown on previews, anon purges... (bug 22640)
-    if ( ( !$wgRequest->wasPosted() ) || ( $wgRequest->getVal( 'process' ) != 
"_yes_" ) ) {
-        return true;
-    }
-    // if form has been submitted, assign data and redirect user to chosen 
payment gateway
-
-    // find out which amount option was chosen for amount, redefined buttons 
or text box
-    if ( preg_match( '/^\d+(\.(\d+)?)?$/', $wgRequest->getText( 'amount' ) ) ) 
{
-                 $amount = number_format( $wgRequest->getText( 'amount' ), 2 );
-    } elseif ( preg_match( '/^\d+(\.(\d+)?)?$/', $wgRequest->getText( 
'amountGiven' ) ) ) {
-        $amount = number_format( $wgRequest->getText( 'amountGiven' ), 2, '.', 
'' );
-    } else {
-        $wgOut->addHTML( wfMsg( 'donate_interface-amount-error' ) );
-        return true;
-    }
-
-  // create    array of user input from post data
-  $userInput = array (
-        'currency_code' => $wgRequest->getText( 'currency_code', 'USD' ),
-        'amount' => $amount,
-        'gateway' => $wgRequest->getText( 'payment_method', 'payflow' ),
-        'referrer' => $wgRequest->getText( 'referrer', '' ),
-        'utm_source' => $wgRequest->getText( 'utm_source', '' ),
-        'utm_medium' => $wgRequest->getText( 'utm_medium', '' ),
-        'utm_campaign' => $wgRequest->getText( 'utm_campaign', '' ),
-        'language' => $wgRequest->getText( 'language', 'en' ),
-        'comment' => $wgRequest->getText( 'comment', '' ),
-        'comment-option' => $wgRequest->getText( 'comment-option', '0' ),
-        'email-opt' => $wgRequest->getText( 'email-opt', 0 ),
-               'fname' => $wgRequest->getText( 'fname', null ),
-               'lname' => $wgRequest->getText( 'lname', null ),
-               'email' => $wgRequest->getText( 'emailAdd', null ),
-  );
-
-  // ask payment processor extensions for their URL/page title
-  $url = '';
-
-  if ( wfRunHooks( 'DonationInterface_Page', array( &$url ) ) ) {
-      // send user to correct page for payment
-      fnDonateRedirectToProcessorPage( $userInput, $url );
-  } else {
-      $wgOut->addHTML( wfMsg( 'donate_interface-processing-error' ) );
-  }
-
-  return true;
-}
-
-

Deleted: 
trunk/extensions/DonationInterface/donate_interface/donate_interface_validate_donation.js
===================================================================
--- 
trunk/extensions/DonationInterface/donate_interface/donate_interface_validate_donation.js
   2011-10-18 17:32:20 UTC (rev 100131)
+++ 
trunk/extensions/DonationInterface/donate_interface/donate_interface_validate_donation.js
   2011-10-18 17:36:59 UTC (rev 100132)
@@ -1,53 +0,0 @@
-//<![CDATA[
-function DonateValidateForm( form ) {
-
-  var minimums = {
-    'USD' : 1,
-    'GBP' : 1, // $1.26
-    'EUR' : 1, // $1.26
-    'AUD' : 2, // $1.35
-    'CAD' : 1, // $0.84
-    'CHF' : 1, // $0.85
-    'CZK' : 20, // $1.03
-    'DKK' : 5, // $0.85
-    'HKD' : 10, // $1.29
-    'HUF' : 200, // $0.97
-    'JPY' : 100, // $1
-    'NZD' : 2, // $1.18
-    'NOK' : 10, // $1.44
-    'PLN' : 5, // $1.78
-    'SGD' : 2, // $1.35
-    'SEK' : 10, // $1.28
-  };
-
-  var error = true;
-
-  // Get amount selection
-  var amount = null;
-  for ( var i = 0; i < form.amount.length; i++ ) {
-    if ( form.amount[i].checked ) {
-      amount = form.amount[i].value;
-    }
-  }
-  if ( form.amount2.value != "" ) {
-    amount = form.amount2.value;
-  }
-  // Check amount is a real number
-  error = ( amount == null || isNaN( amount ) || amount.value <= 0 );
-  if ( error ) {
-    alert( 'You must enter a valid amount.' );
-  }
-
-  // Check amount is at least the minimum
-  var currency = form.currency_code[form.currency_code.selectedIndex].value;
-  if ( typeof( minimums[currency] ) == 'undefined' ) {
-    minimums[currency] = 1;
-  }
-  if ( amount < minimums[currency] ) {
-    alert( 'You must contribute at least $1'.replace('$1', minimums[currency] 
+ ' ' + currency ) );
-    error = true;
-  }
-
-  return !error;
-}
-//]]>

Deleted: 
trunk/extensions/DonationInterface/donate_interface/validate_donation.js
===================================================================
--- trunk/extensions/DonationInterface/donate_interface/validate_donation.js    
2011-10-18 17:32:20 UTC (rev 100131)
+++ trunk/extensions/DonationInterface/donate_interface/validate_donation.js    
2011-10-18 17:36:59 UTC (rev 100132)
@@ -1,54 +0,0 @@
-//<![CDATA[
-function validateForm( form ) {
-
-       var minimums = {
-               'USD' : 1,
-               'GBP' : 1, // $1.26
-               'EUR' : 1, // $1.26
-               'AUD' : 2, // $1.35
-               'CAD' : 1, // $0.84
-               'CHF' : 1, // $0.85
-               'CZK' : 20, // $1.03
-               'DKK' : 5, // $0.85
-               'HKD' : 10, // $1.29
-               'HUF' : 200, // $0.97
-               'JPY' : 100, // $1
-               'NZD' : 2, // $1.18
-               'NOK' : 10, // $1.44
-               'PLN' : 5, // $1.78
-               'SGD' : 2, // $1.35
-               'SEK' : 10, // $1.28
-       };
-
-       var error = true;
-
-       // Get amount selection
-       var amount = null;
-       for ( var i = 0; i < form.amount.length; i++ ) {
-               if ( form.amount[i].checked ) {
-                       amount = form.amount[i].value;
-               }
-       }
-       if ( form.amount2.value != '' ) {
-               amount = form.amount2.value;
-       }
-       // Check amount is a real number
-       error = ( amount == null || isNaN( amount ) || amount.value <= 0 );
-       if ( error ) {
-               alert( 'You must enter a valid amount.' );
-       }
-
-       // Check amount is at least the minimum
-       var currency = 
form.currency_code[form.currency_code.selectedIndex].value;
-       if ( typeof( minimums[currency] ) == 'undefined' ) {
-               minimums[currency] = 1;
-       }
-
-       if ( amount < minimums[currency] ) {
-               alert( 'You must contribute at least $1'.replace('$1', 
minimums[currency] + ' ' + currency ) );
-               error = true;
-       }
-
-       return !error;
-}
-//]]>
\ No newline at end of file

Modified: 
trunk/extensions/DonationInterface/payflowpro_gateway/api_payflowpro_gateway.php
===================================================================
--- 
trunk/extensions/DonationInterface/payflowpro_gateway/api_payflowpro_gateway.php
    2011-10-18 17:32:20 UTC (rev 100131)
+++ 
trunk/extensions/DonationInterface/payflowpro_gateway/api_payflowpro_gateway.php
    2011-10-18 17:36:59 UTC (rev 100132)
@@ -1,6 +1,8 @@
 <?php
 /**
  * PayflowPro Gateway API extension
+ * Call with api.php?action=pfp
+ * TODO: Determine if this is being used by anything anymore, and if so, what. 
  */
 
 class ApiPayflowProGateway extends ApiBase {
@@ -120,15 +122,17 @@
         * elements.
         */
        protected function dispatch_get_required_dynamic_form_elements( $params 
) {
-               global $wgPayflowGatewaySalt;
+               global $wgPayflowProGatewaySalt;
 
                // fetch the order_id
+               //TODO: This include should be *very* deprecated. All the 
functionality there has been 
+               //recently eaten by gateway.adapter.php and DontationData.php. 
                require_once( 'includes/payflowUser.inc' );
                $payflow_data = payflowUser();
                $order_id = $payflow_data[ 'order_id' ];
 
                // fetch the CSRF prevention token and set it if it's not 
already set
-               $token = PayflowProGateway::fnPayflowEditToken( 
$wgPayflowGatewaySalt );
+               $token = PayflowProGateway::fnPayflowEditToken( 
$wgPayflowProGatewaySalt );
 
                /**
                 * retrieve and unpack the json encoded string of tracking data

Copied: 
trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro.adapter.php 
(from rev 100121, 
branches/fundraising/extensions/DonationInterface/payflowpro_gateway/payflowpro.adapter.php)
===================================================================
--- 
trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro.adapter.php    
                            (rev 0)
+++ 
trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro.adapter.php    
    2011-10-18 17:36:59 UTC (rev 100132)
@@ -0,0 +1,237 @@
+<?php
+
+class PayflowProAdapter extends GatewayAdapter {
+       const GATEWAY_NAME = 'Payflow Pro';
+       const IDENTIFIER = 'payflowpro';
+       const COMMUNICATION_TYPE = 'namevalue';
+       const GLOBAL_PREFIX = 'wgPayflowProGateway';
+
+       function defineAccountInfo() {
+               $this->accountInfo = array(
+                       'PARTNER' => self::getGlobal( 'PartnerID' ), // PayPal 
or original authorized reseller
+                       'VENDOR' => self::getGlobal( 'VendorID' ), // paypal 
merchant login ID
+                       'USER' => self::getGlobal( 'UserID' ), // if one or 
more users are set up, authorized user ID, else same as VENDOR
+                       'PWD' => self::getGlobal( 'Password' ), // merchant 
login password
+               );
+       }
+
+       function defineVarMap() {
+               $this->var_map = array(
+                       'ACCT' => 'card_num',
+                       'EXPDATE' => 'expiration',
+                       'AMT' => 'amount',
+                       'FIRSTNAME' => 'fname',
+                       'LASTNAME' => 'lname',
+                       'STREET' => 'street',
+                       'CITY' => 'city',
+                       'STATE' => 'state',
+                       'COUNTRY' => 'country',
+                       'ZIP' => 'zip',
+                       'INVNUM' => 'order_id',
+                       'CVV2' => 'cvv',
+                       'CURRENCY' => 'currency',
+                       'CUSTIP' => 'user_ip',
+//                     'ORDERID' => 'order_id',
+//                     'AMOUNT' => 'amount',
+//                     'CURRENCYCODE' => 'currency',
+//                     'LANGUAGECODE' => 'language',
+//                     'COUNTRYCODE' => 'country',
+//                     '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.
+               );
+       }
+
+       function defineReturnValueMap() {
+               $this->return_value_map = array( ); //we don't really need 
this... maybe. 
+       }
+
+       function defineTransactions() {
+               $this->transactions = array( );
+
+               $this->transactions['Card'] = array(
+                       'request' => array(
+                               'TRXTYPE',
+                               'TENDER',
+                               'USER',
+                               'VENDOR',
+                               'PARTNER',
+                               'PWD',
+                               'ACCT',
+                               'EXPDATE',
+                               'AMT',
+                               'FIRSTNAME',
+                               'LASTNAME',
+                               'STREET',
+                               'CITY',
+                               'STATE',
+                               'COUNTRY',
+                               'ZIP',
+                               'INVNUM',
+                               'CVV2',
+                               'CURRENCY',
+                               'VERBOSITY',
+                               'CUSTIP',
+                       ),
+                       'values' => array(
+                               'TRXTYPE' => 'S',
+                               'TENDER' => 'C',
+                               'VERBOSITY' => 'MEDIUM',
+                       ),
+                       'do_validation' => true,
+                       'do_processhooks' => true,
+               );
+       }
+
+       /**
+        * Take the entire response string, and strip everything we don't care 
about.
+        * For instance: If it's XML, we only want correctly-formatted XML. 
Headers must be killed off. 
+        * return a string.
+        */
+       function getFormattedResponse( $rawResponse ) {
+               $nvString = $this->stripNameValueResponseHeaders( $rawResponse 
);
+
+               // prepare NVP response for sorting and outputting
+               $responseArray = array( );
+
+               /**
+                * The result response string looks like:
+                *      RESULT=7&PNREF=E79P2C651DC2&RESPMSG=Field format 
error&HOSTCODE=10747&DUPLICATE=1
+                * We want to turn this into an array of key value pairs, so 
explode on '&' and then
+                * split up the resulting strings into $key => $value
+                */
+               $result_arr = explode( "&", $nvString );
+               foreach ( $result_arr as $result_pair ) {
+                       list( $key, $value ) = preg_split( "/=/", $result_pair, 
2 );
+                       $responseArray[$key] = $value;
+               }
+
+               self::log( "Here is the response as an array: " . print_r( 
$responseArray, true ) );
+               return $responseArray;
+       }
+
+       /**
+        * Parse the response to get the status. Not sure if this should return 
a bool, or something more... telling.
+        */
+       function getResponseStatus( $response ) {
+               //this function is only supposed to make sure the communication 
was well-formed... 
+               if ( is_array( $response ) && array_key_exists( 'RESULT', 
$response ) ) {
+                       return true;
+               } else {
+                       return false;
+               }
+       }
+
+       /**
+        * Interpret response code, return
+        * 1 if approved - 'complete'
+        * 2 if declined - 'failed'
+        * 3 if invalid data was submitted by user
+        * 4 all other errors
+        * 5 if pending - 'pending'
+        */
+       function getResponseErrors( $response ) {
+
+               if ( is_array( $response ) && array_key_exists( 'RESULT', 
$response ) ) {
+                       $resultCode = $response['RESULT'];
+               } else {
+                       return;
+               }
+
+               $errors = array( );
+
+               switch ( $resultCode ) {
+                       case '0':
+                               $errors['1'] = wfMsg( 
'payflowpro_gateway-response-0' );
+                               $this->setTransactionWMFStatus( 'complete' );
+                               break;
+                       case '126':
+                               $errors['5'] = wfMsg( 
'payflowpro_gateway-response-126-2' );
+                               $this->setTransactionWMFStatus( 'pending' );
+                               break;
+                       case '12':
+                               $errors['2'] = wfMsg( 
'payflowpro_gateway-response-12' );
+                               $this->setTransactionWMFStatus( 'failed' );
+                               break;
+                       case '13':
+                               $errors['2'] = wfMsg( 
'payflowpro_gateway-response-13' );
+                               $this->setTransactionWMFStatus( 'failed' );
+                               break;
+                       case '114':
+                               $errors['2'] = wfMsg( 
'payflowpro_gateway-response-114' );
+                               $this->setTransactionWMFStatus( 'failed' );
+                               break;
+                       case '4':
+                               $errors['3'] = wfMsg( 
'payflowpro_gateway-response-4' );
+                               $this->setTransactionWMFStatus( 'failed' );
+                               break;
+                       case '23':
+                               $errors['3'] = wfMsg( 
'payflowpro_gateway-response-23' );
+                               $this->setTransactionWMFStatus( 'failed' );
+                               break;
+                       case '24':
+                               $errors['3'] = wfMsg( 
'payflowpro_gateway-response-24' );
+                               $this->setTransactionWMFStatus( 'failed' );
+                               break;
+                       case '112':
+                               $errors['3'] = wfMsg( 
'payflowpro_gateway-response-112' );
+                               $this->setTransactionWMFStatus( 'failed' );
+                               break;
+                       case '125':
+                               $errors['3'] = wfMsg( 
'payflowpro_gateway-response-125-2' );
+                               $this->setTransactionWMFStatus( 'failed' );
+                               break;
+                       default:
+                               $errors['4'] = wfMsg( 
'payflowpro_gateway-response-default' );
+                               $this->setTransactionWMFStatus( 'failed' );
+               }
+
+               return $errors;
+       }
+
+       /**
+        * Harvest the data we need back from the gateway. 
+        * return a key/value array
+        */
+       function getResponseData( $response ) {
+               
+               if ( is_array( $response ) && !empty( $response ) ) {
+                       return $response;
+               }
+       }
+
+       /**
+        * Actually do... stuff. Here. 
+        * TODO: Better comment. 
+        * Process the entire response gott'd by the last four functions. 
+        */
+       function processResponse( $response ) {
+               //set the transaction result message
+               $this->setTransactionResult( $response['RESPMSG'], 
'txn_message' );
+               $this->setTransactionResult( $response['PNREF'], 
'gateway_txn_id' );
+       }
+
+       function defineStagedVars() {
+               //OUR field names. 
+               $this->staged_vars = array(
+                       'card_num',
+                       'user_ip'
+               );
+       }
+
+       protected function stage_card_num( $type = 'request' ) {
+               //I realize that the $type isn't used. Voodoo.
+               $this->postdata['card_num'] = str_replace( ' ', '', 
$this->postdata['card_num'] );
+       }
+
+       //TODO: Something much fancier here. 
+       protected function stage_user_ip( $type = 'request' ) {
+               if ( $this->postdata['user_ip'] === '127.0.0.1' ) {
+                       global $wgDonationInterfaceIPAddress;
+                       if ( !empty( $wgDonationInterfaceIPAddress ) ) {
+                               $this->postdata['user_ip'] = 
$wgDonationInterfaceIPAddress;
+                       }
+               }
+       }
+
+}


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

Reply via email to