https://www.mediawiki.org/wiki/Special:Code/MediaWiki/101947

Revision: 101947
Author:   kaldari
Date:     2011-11-04 02:10:45 +0000 (Fri, 04 Nov 2011)
Log Message:
-----------
adding separate currency support for different gateways, adding support for 
passing a default currency, de-obfuscating generateCurrencyDropdown params

Modified Paths:
--------------
    trunk/extensions/DonationInterface/gateway_common/DonationData.php
    trunk/extensions/DonationInterface/gateway_forms/Form.php
    
trunk/extensions/DonationInterface/gateway_forms/TwoStepTwoColumnLetterCA.php
    
trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php
    trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro.adapter.php

Modified: trunk/extensions/DonationInterface/gateway_common/DonationData.php
===================================================================
--- trunk/extensions/DonationInterface/gateway_common/DonationData.php  
2011-11-04 01:56:51 UTC (rev 101946)
+++ trunk/extensions/DonationInterface/gateway_common/DonationData.php  
2011-11-04 02:10:45 UTC (rev 101947)
@@ -57,7 +57,7 @@
                                'card_type' => $wgRequest->getText( 'card_type' 
),
                                'expiration' => $wgRequest->getText( 'mos' ) . 
substr( $wgRequest->getText( 'year' ), 2, 2 ),
                                'cvv' => $wgRequest->getText( 'cvv' ),
-                               'currency' => $wgRequest->getText( 
'currency_code', 'USD' ),
+                               'currency' => $wgRequest->getVal( 
'currency_code' ),
                                'payment_method' => $wgRequest->getText( 
'payment_method', 'cc' ),
                                'payment_submethod' => $wgRequest->getText( 
'payment_submethod', null ), // Used by GlobalCollect for payment types
                                'issuer_id' => $wgRequest->getText( 'issuer_id' 
),

Modified: trunk/extensions/DonationInterface/gateway_forms/Form.php
===================================================================
--- trunk/extensions/DonationInterface/gateway_forms/Form.php   2011-11-04 
01:56:51 UTC (rev 101946)
+++ trunk/extensions/DonationInterface/gateway_forms/Form.php   2011-11-04 
02:10:45 UTC (rev 101947)
@@ -348,50 +348,57 @@
        /**
         * Generates the dropdown list for available currencies
         *
-        * @param       array   $options
+        * @param string $defaultCurrencyCode default currency code to select
+        * @param boolean $showCardsOnCurrencyChange Allow javascript 
onchange="showCards();" to be executed.
         *
-        * $options:
-        * - showCardsOnCurrencyChange: Allow javascript 
onchange="showCards();" to be executed.
-        *
         * @fixme The list of available currencies should NOT be defined here 
but rather
         *      be customizable
         * @fixme It would be great to default the currency to a locale's 
currency
         * @return string The entire HTML select for the currency dropdown
         */
-       public function generateCurrencyDropdown( $options = array() ) {
+       public function generateCurrencyDropdown( $defaultCurrencyCode = 'USD', 
$showCardsOnCurrencyChange = false ) {
                
-               extract( $options );
+               // Get an array of currency codes from the current payment 
gateway
+               $availableCurrencies = $this->gateway->getCurrencies();
                
-               $showCardsOnCurrencyChange = isset( $showCardsOnCurrencyChange 
) ? (boolean) $showCardsOnCurrencyChange : true;
+               // If a currency has already been posted, use that, otherwise 
use the default.
+               if ( $this->form_data['currency'] ) {
+                       $selectedCurrency = $this->form_data['currency'];
+               } else {
+                       $selectedCurrency = $defaultCurrencyCode;
+               }
                
-               $available_currencies = array(
-                       'USD' => 'USD: U.S. Dollar',
-                       'GBP' => 'GBP: British Pound',
-                       'EUR' => 'EUR: Euro',
-                       'AUD' => 'AUD: Australian Dollar',
-                       'CAD' => 'CAD: Canadian Dollar',
-                       'JPY' => 'JPY: Japanese Yen',
-               );
+               $currencyOpts = ''; // Initialize variable for the select list 
options
 
-               $currency_opts = '';
-
                // generate dropdown of currency opts
-               foreach ( $available_currencies as $value => $currency_name ) {
-                       $selected = ( $this->form_data['currency'] == $value ) 
? true : false;
-                       $currency_opts .= Xml::option( wfMsg( 
'donate_interface-' . $value ), $value, $selected );
+               foreach ( $availableCurrencies as $currencyCode ) {
+               
+                       // Should this option be selected?
+                       $selected = ( $selectedCurrency == $currencyCode ) ? 
true : false;
+                       
+                       $optionText = wfMsg( 'donate_interface-' . 
$currencyCode ); // name of the currency
+                       /* uncomment this to get currency name and code in the 
drop-down list
+                       $optionText = wfMsg(
+                               'donate_interface-currency-display', // 
formatting
+                               wfMsg( 'donate_interface-' . $currencyCode ), 
// name of the currency
+                               $currencyCode // code of the currency
+                       );
+                       */
+                       
+                       $currencyOpts .= Xml::option( $optionText, 
$currencyCode, $selected );
                }
 
-               $currency_menu = Xml::openElement(
+               $currencyMenu = Xml::openElement(
                        'select',
                        array(
                                'name' => 'currency_code',
                                'id' => 'input_currency_code',
                                'onchange' => $showCardsOnCurrencyChange ? 
'showCards()' : '',
                        ) );
-               $currency_menu .= $currency_opts;
-               $currency_menu .= Xml::closeElement( 'select' );
+               $currencyMenu .= $currencyOpts;
+               $currencyMenu .= Xml::closeElement( 'select' );
 
-               return $currency_menu;
+               return $currencyMenu;
        }
 
        /**
@@ -412,7 +419,7 @@
                
                extract( $options );
 
-               $options['showCardsOnCurrencyChange'] = isset( 
$showCardsOnCurrencyChange ) ? (boolean) $showCardsOnCurrencyChange : true;
+               $showCardsOnCurrencyChange = isset( $showCardsOnCurrencyChange 
) ? (boolean) $showCardsOnCurrencyChange : true;
                $displayCurrencyDropdown = isset( $displayCurrencyDropdown ) ? 
(boolean) $displayCurrencyDropdown : true;
                $setCurrency = isset( $setCurrency ) ? (string) $setCurrency : 
'';
                $displayCurrencyDropdown = empty( $setCurrency ) ? 
$displayCurrencyDropdown : false;
@@ -458,7 +465,7 @@
                if ( $displayCurrencyDropdown ) {
                        $return .= '    <tr>';
                        $return .= '            <td colspan="4" >';
-                       $return .= $this->generateCurrencyDropdown( $options );
+                       $return .= $this->generateCurrencyDropdown( null, 
$showCardsOnCurrencyChange );
                        $return .= '            </td>';
                        $return .= '    </tr>';
                }

Modified: 
trunk/extensions/DonationInterface/gateway_forms/TwoStepTwoColumnLetterCA.php
===================================================================
--- 
trunk/extensions/DonationInterface/gateway_forms/TwoStepTwoColumnLetterCA.php   
    2011-11-04 01:56:51 UTC (rev 101946)
+++ 
trunk/extensions/DonationInterface/gateway_forms/TwoStepTwoColumnLetterCA.php   
    2011-11-04 02:10:45 UTC (rev 101947)
@@ -95,7 +95,7 @@
                $form .= '<tr>';
                $form .= '<td class="label">' . Xml::label( wfMsg( 
'donate_interface-donor-amount' ), 'amount' ) . '</td>';
                $form .= '<td>' . Xml::input( 'amount', '7', 
$this->form_data['amount'], array( 'type' => 'text', 'maxlength' => '10', 'id' 
=> 'amount' ) ) .
-                       ' ' . $this->generateCurrencyDropdown() . '</td>';
+                       ' ' . $this->generateCurrencyDropdown( 'CAD' ) . 
'</td>';
                $form .= '</tr>';
 
                // card logos

Modified: 
trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php
===================================================================
--- 
trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php
  2011-11-04 01:56:51 UTC (rev 101946)
+++ 
trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php
  2011-11-04 02:10:45 UTC (rev 101947)
@@ -615,8 +615,100 @@
 
                return $data;
        }
+       
+       /**
+        * Gets all the currency codes appropriate for this gateway
+        * @return array of currency codes
+        */
+       function getCurrencies() {
+               $currencies = array(
+                       'AED', // UAE dirham
+                       'ARS', // Argentinian peso
+                       'AUD', // Australian dollar
+                       'BBD', // Barbadian dollar
+                       'BDT', // Bagladesh taka
+                       'BGN', // Bulgarian lev
+                       'BHD', // Bahraini dinar
+                       'BMD', // Bermudian dollar
+                       'BND', // Brunei dollar
+                       'BOB', // Bolivia boliviano
+                       'BRL', // Brazilian real
+                       'BSD', // Bahamian dollar
+                       'BZD', // Belize dollar
+                       'CAD', // Canadian dollar
+                       'CHF', // Swiss franc
+                       'CLP', // Chilean deso
+                       'CNY', // Chinese yuan renminbi
+                       'COP', // Colombia columb
+                       'CRC', // Costa Rican colon
+                       'CZK', // Czech koruna
+                       'DKK', // Danish krone
+                       'DOP', // Dominican peso
+                       'DZD', // Algerian dinar
+                       'EEK', // Estonian kroon
+                       'EGP', // Egyptian pound
+                       'EUR', // Euro
+                       'GBP', // British pound
+                       'GTQ', // Guatemala quetzal
+                       'HKD', // Hong Kong dollar
+                       'HNL', // Honduras lempira
+                       'HRK', // Croatian kuna
+                       'HUF', // Hungarian forint
+                       'IDR', // Indonesian rupiah
+                       'ILS', // Israeli shekel
+                       'INR', // Indian rupee
+                       'JMD', // Jamaican dollar
+                       'JOD', // Jordanian dinar
+                       'JPY', // Japanese yen
+                       'KES', // Kenyan shilling
+                       'KRW', // South Korean won
+                       'KYD', // Cayman Islands dollar
+                       'KZT', // Kazakhstani tenge
+                       'LBP', // Lebanese pound
+                       'LKR', // Sri Lankan rupee
+                       'LTL', // Lithuanian litas
+                       'LVL', // Latvian lats
+                       'MAD', // Moroccan dirham
+                       'MKD', // Macedonia denar
+                       'MUR', // Mauritius rupee
+                       'MVR', // Maldives rufiyaa
+                       'MXN', // Mexican peso
+                       'MYR', // Malaysian ringgit
+                       'NOK', // Norwegian krone
+                       'NZD', // New Zealand dollar
+                       'OMR', // Omani rial
+                       'PAB', // Panamanian balboa
+                       'PEN', // Peru nuevo sol
+                       'PHP', // Philippine peso
+                       'PKR', // Pakistani rupee
+                       'PLN', // Polish złoty
+                       'PYG', // Paraguayan guaraní
+                       'QAR', // Qatari rial
+                       'RON', // Romanian leu
+                       'RUB', // Russian ruble
+                       'SAR', // Saudi riyal
+                       'SEK', // Swedish krona
+                       'SGD', // Singapore dollar
+                       'SVC', // Salvadoran colón
+                       'THB', // Thai baht
+                       'TJS', // Tajikistani Somoni
+                       'TND', // Tunisan dinar
+                       'TRY', // Turkish lira
+                       'TTD', // Trinidad and Tobago dollar
+                       'TWD', // New Taiwan dollar
+                       'UAH', // Ukrainian hryvnia
+                       'UYU', // Uruguayan peso
+                       'USD', // U.S. dollar
+                       'UZS', // Uzbekistani som
+                       'VND', // Vietnamese dong
+                       'XAF', // Central African CFA franc
+                       'XCD', // East Caribbean dollar
+                       'XOF', // West African CFA franc
+                       'ZAR', // South African rand
+               );
+               return $currencies;
+       }
 
-
        /**
         * Process the response
         *

Modified: 
trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro.adapter.php
===================================================================
--- 
trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro.adapter.php    
    2011-11-04 01:56:51 UTC (rev 101946)
+++ 
trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro.adapter.php    
    2011-11-04 02:10:45 UTC (rev 101947)
@@ -197,6 +197,22 @@
                        return $response;
                }
        }
+       
+       /**
+        * Gets all the currency codes appropriate for this gateway
+        * @return array of currency codes
+        */
+       function getCurrencies() {
+               $currencies = array(
+                       'USD', // U.S. Dollar
+                       'GBP', // British Pound
+                       'EUR', // Euro
+                       'AUD', // Australian Dollar
+                       'CAD', // Canadian Dollar
+                       'JPY', // Japanese Yen
+               );
+               return $currencies;
+       }
 
        /**
         * Actually do... stuff. Here. 


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

Reply via email to