r101910 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101909‎ | r101910 | r101911 >
Date:23:06, 3 November 2011
Author:kaldari
Status:ok
Tags:
Comment:
adding new currencies for sanity check, correcting 2 currency codes, follow-up to r101563
Modified paths:
  • /trunk/extensions/DonationInterface/gateway_common/GatewayForm.php (modified) (history)
  • /trunk/extensions/DonationInterface/gateway_common/currencyRates.inc (added) (history)
  • /trunk/extensions/DonationInterface/gateway_common/interface.i18n.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/gateway_common/currencyRates.inc
@@ -0,0 +1,95 @@
 2+<?php
 3+
 4+/**
 5+ * Supplies rough (not up-to-date) conversion rates for currencies
 6+ * Last updated November 3, 2011 (rounded down)
 7+ */
 8+function getCurrencyRates() {
 9+ $currencyRates = array(
 10+ 'AED' => '4',
 11+ 'ARS' => '4',
 12+ 'AUD' => '1',
 13+ 'BBD' => '2',
 14+ 'BDT' => '76',
 15+ 'BGN' => '1.4',
 16+ 'BHD' => '0.4',
 17+ 'BMD' => '1',
 18+ 'BND' => '1.3',
 19+ 'BOB' => '7',
 20+ 'BRL' => '1.7',
 21+ 'BSD' => '1',
 22+ 'BZD' => '2',
 23+ 'CAD' => '1',
 24+ 'CHF' => '0.9',
 25+ 'CLP' => '494',
 26+ 'CNY' => '6',
 27+ 'COP' => '1910',
 28+ 'CRC' => '512',
 29+ 'CZK' => '18',
 30+ 'DKK' => '5',
 31+ 'DOP' => '38',
 32+ 'DZD' => '73',
 33+ 'EEK' => '11',
 34+ 'EGP' => '6',
 35+ 'EUR' => '0.7',
 36+ 'GBP' => '0.6',
 37+ 'GTQ' => '7.8',
 38+ 'HKD' => '7.7',
 39+ 'HNL' => '19',
 40+ 'HRK' => '5',
 41+ 'HUF' => '219',
 42+ 'IDR' => '8960',
 43+ 'ILS' => '3.6',
 44+ 'INR' => '49',
 45+ 'JMD' => '85',
 46+ 'JOD' => '0.7',
 47+ 'JPY' => '78',
 48+ 'KES' => '97',
 49+ 'KRW' => '1127',
 50+ 'KYD' => '0.8',
 51+ 'KZT' => '147',
 52+ 'LBP' => '1500',
 53+ 'LKR' => '110',
 54+ 'LTL' => '2.5',
 55+ 'LVL' => '0.5',
 56+ 'MAD' => '8.1',
 57+ 'MKD' => '45',
 58+ 'MUR' => '29',
 59+ 'MVR' => '15',
 60+ 'MXN' => '13',
 61+ 'MYR' => '3',
 62+ 'NOK' => '5.5',
 63+ 'NZD' => '1.2',
 64+ 'OMR' => '0.3',
 65+ 'PAB' => '1',
 66+ 'PEN' => '2.7',
 67+ 'PHP' => '43',
 68+ 'PKR' => '86',
 69+ 'PLN' => '3',
 70+ 'PYG' => '4190',
 71+ 'QAR' => '3.6',
 72+ 'RON' => '3.1',
 73+ 'RUB' => '30',
 74+ 'SAR' => '3.7',
 75+ 'SEK' => '6.5',
 76+ 'SGD' => '1.2',
 77+ 'SVC' => '8.7',
 78+ 'THB' => '30',
 79+ 'TJS' => '4.7',
 80+ 'TND' => '1.4',
 81+ 'TRY' => '1.7',
 82+ 'TTD' => '6',
 83+ 'TWD' => '30',
 84+ 'UAH' => '8',
 85+ 'USD' => '1',
 86+ 'UYU' => '19',
 87+ 'UZS' => '1760',
 88+ 'VND' => '21000',
 89+ 'XAF' => '470',
 90+ 'XCD' => '2.7',
 91+ 'XOF' => '476',
 92+ 'ZAR' => '7.8',
 93+ );
 94+
 95+ return $currencyRates;
 96+}
Index: trunk/extensions/DonationInterface/gateway_common/interface.i18n.php
@@ -36,7 +36,7 @@
3737 No processors are available.',
3838
3939 // Currency translations
40 - 'donate_interface-AEB' => 'AEB: UAE dirham',
 40+ 'donate_interface-AED' => 'AED: UAE dirham',
4141 'donate_interface-ARS' => 'ARS: Argentinian peso',
4242 'donate_interface-AUD' => 'AUD: Australian dollar',
4343 'donate_interface-BBD' => 'BBD: Barbadian dollar',
@@ -112,7 +112,7 @@
113113 'donate_interface-TWD' => 'TWD: New Taiwan dollar',
114114 'donate_interface-UAH' => 'UAH: Ukrainian hryvnia',
115115 'donate_interface-USD' => 'USD: U.S. dollar',
116 - 'donate_interface-UTU' => 'UTU: Uruguayan peso',
 116+ 'donate_interface-UYU' => 'UYU: Uruguayan peso',
117117 'donate_interface-UZS' => 'UZS: Uzbekistani som',
118118 'donate_interface-VND' => 'VND: Vietnamese dong',
119119 'donate_interface-XAF' => 'XAF: Central African CFA franc',
@@ -319,7 +319,7 @@
320320 'donate_interface-change' => 'Change',
321321 'donate_interface-select-credit-card' => 'Select credit card',
322322
323 - // For more USA states, see donate_interface.us-states.i18n.php.
 323+ // For more USA states, see us-states.i18n.php.
324324 'donate_interface-state-dropdown-YY' => 'Select a state',
325325 'donate_interface-state-dropdown-XX' => 'Outside the U.S.',
326326
@@ -408,7 +408,7 @@
409409 'donate_interface-comment-title' => "Next to check box; to choose whether the donor's comment shall be publically viewable or not.",
410410 'donate_interface-amount-error' => 'Error prompt if an invalid amount is entered (e.g. if the amount has letters in it).',
411411 'donate_interface-processing-error' => 'Error message.',
412 - 'donate_interface-AEB' => 'Used in drop-down field for currency.',
 412+ 'donate_interface-AED' => 'Used in drop-down field for currency.',
413413 'donate_interface-ARS' => 'Used in drop-down field for currency.',
414414 'donate_interface-AUD' => 'Used in drop-down field for currency.',
415415 'donate_interface-BBD' => 'Used in drop-down field for currency.',
@@ -484,7 +484,7 @@
485485 'donate_interface-TWD' => 'Used in drop-down field for currency.',
486486 'donate_interface-UAH' => 'Used in drop-down field for currency.',
487487 'donate_interface-USD' => 'Used in drop-down field for currency.',
488 - 'donate_interface-UTU' => 'Used in drop-down field for currency.',
 488+ 'donate_interface-UYU' => 'Used in drop-down field for currency.',
489489 'donate_interface-UZS' => 'Used in drop-down field for currency.',
490490 'donate_interface-VND' => 'Used in drop-down field for currency.',
491491 'donate_interface-XAF' => 'Used in drop-down field for currency.',
Index: trunk/extensions/DonationInterface/gateway_common/GatewayForm.php
@@ -443,68 +443,19 @@
444444 * In reality, this probably ought to use some sort of webservice to get real-time
445445 * conversion rates.
446446 *
447 - * @param $currency_code
448 - * @param $amount
449 - * @return unknown_type
 447+ * @param string $currency_code
 448+ * @param float $amount
 449+ * @return float
450450 */
451 - public function convert_to_usd( $currency_code, $amount ) {
452 - switch ( strtoupper( $currency_code ) ) {
453 - case 'USD':
454 - $usd_amount = $amount / 1;
455 - break;
456 - case 'GBP':
457 - $usd_amount = $amount / 1;
458 - break;
459 - case 'EUR':
460 - $usd_amount = $amount / 1;
461 - break;
462 - case 'AUD':
463 - $usd_amount = $amount / 2;
464 - break;
465 - case 'CAD':
466 - $usd_amount = $amount / 1;
467 - break;
468 - case 'CHF':
469 - $usd_amount = $amount / 1;
470 - break;
471 - case 'CZK':
472 - $usd_amount = $amount / 20;
473 - break;
474 - case 'DKK':
475 - $usd_amount = $amount / 5;
476 - break;
477 - case 'HKD':
478 - $usd_amount = $amount / 10;
479 - break;
480 - case 'HUF':
481 - $usd_amount = $amount / 200;
482 - break;
483 - case 'JPY':
484 - $usd_amount = $amount / 100;
485 - break;
486 - case 'NZD':
487 - $usd_amount = $amount / 2;
488 - break;
489 - case 'NOK':
490 - $usd_amount = $amount / 10;
491 - break;
492 - case 'PLN':
493 - $usd_amount = $amount / 5;
494 - break;
495 - case 'SGD':
496 - $usd_amount = $amount / 2;
497 - break;
498 - case 'SEK':
499 - $usd_amount = $amount / 10;
500 - break;
501 - case 'ILS':
502 - $usd_amount = $amount / 5;
503 - break;
504 - default:
505 - $usd_amount = $amount;
506 - break;
 451+ static function convert_to_usd( $currency_code, $amount ) {
 452+ require_once( dirname( __FILE__ ) . '/currencyRates.inc' );
 453+ $rates = getCurrencyRates();
 454+ $code = strtoupper( $currency_code );
 455+ if ( array_key_exists( $code, $rates ) ) {
 456+ $usd_amount = $amount / $rates[$code];
 457+ } else {
 458+ $usd_amount = $amount;
507459 }
508 -
509460 return $usd_amount;
510461 }
511462

Follow-up revisions

RevisionCommit summaryAuthorDate
r102236MFT r90286, r100671, r100837, r100950, r101060, r101063, r101064, r101073, r1......khorn03:06, 7 November 2011
r102237MFT r90286, r100671, r100837, r100950, r101060, r101063, r101064, r101073, r1......khorn03:07, 7 November 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r101563adding 54 new accepted currencies and 21 more pending ones to start translationjamesur00:21, 2 November 2011

Status & tagging log