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 @@ |
37 | 37 | No processors are available.', |
38 | 38 | |
39 | 39 | // Currency translations |
40 | | - 'donate_interface-AEB' => 'AEB: UAE dirham', |
| 40 | + 'donate_interface-AED' => 'AED: UAE dirham', |
41 | 41 | 'donate_interface-ARS' => 'ARS: Argentinian peso', |
42 | 42 | 'donate_interface-AUD' => 'AUD: Australian dollar', |
43 | 43 | 'donate_interface-BBD' => 'BBD: Barbadian dollar', |
— | — | @@ -112,7 +112,7 @@ |
113 | 113 | 'donate_interface-TWD' => 'TWD: New Taiwan dollar', |
114 | 114 | 'donate_interface-UAH' => 'UAH: Ukrainian hryvnia', |
115 | 115 | 'donate_interface-USD' => 'USD: U.S. dollar', |
116 | | - 'donate_interface-UTU' => 'UTU: Uruguayan peso', |
| 116 | + 'donate_interface-UYU' => 'UYU: Uruguayan peso', |
117 | 117 | 'donate_interface-UZS' => 'UZS: Uzbekistani som', |
118 | 118 | 'donate_interface-VND' => 'VND: Vietnamese dong', |
119 | 119 | 'donate_interface-XAF' => 'XAF: Central African CFA franc', |
— | — | @@ -319,7 +319,7 @@ |
320 | 320 | 'donate_interface-change' => 'Change', |
321 | 321 | 'donate_interface-select-credit-card' => 'Select credit card', |
322 | 322 | |
323 | | - // For more USA states, see donate_interface.us-states.i18n.php. |
| 323 | + // For more USA states, see us-states.i18n.php. |
324 | 324 | 'donate_interface-state-dropdown-YY' => 'Select a state', |
325 | 325 | 'donate_interface-state-dropdown-XX' => 'Outside the U.S.', |
326 | 326 | |
— | — | @@ -408,7 +408,7 @@ |
409 | 409 | 'donate_interface-comment-title' => "Next to check box; to choose whether the donor's comment shall be publically viewable or not.", |
410 | 410 | 'donate_interface-amount-error' => 'Error prompt if an invalid amount is entered (e.g. if the amount has letters in it).', |
411 | 411 | '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.', |
413 | 413 | 'donate_interface-ARS' => 'Used in drop-down field for currency.', |
414 | 414 | 'donate_interface-AUD' => 'Used in drop-down field for currency.', |
415 | 415 | 'donate_interface-BBD' => 'Used in drop-down field for currency.', |
— | — | @@ -484,7 +484,7 @@ |
485 | 485 | 'donate_interface-TWD' => 'Used in drop-down field for currency.', |
486 | 486 | 'donate_interface-UAH' => 'Used in drop-down field for currency.', |
487 | 487 | '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.', |
489 | 489 | 'donate_interface-UZS' => 'Used in drop-down field for currency.', |
490 | 490 | 'donate_interface-VND' => 'Used in drop-down field for currency.', |
491 | 491 | 'donate_interface-XAF' => 'Used in drop-down field for currency.', |
Index: trunk/extensions/DonationInterface/gateway_common/GatewayForm.php |
— | — | @@ -443,68 +443,19 @@ |
444 | 444 | * In reality, this probably ought to use some sort of webservice to get real-time |
445 | 445 | * conversion rates. |
446 | 446 | * |
447 | | - * @param $currency_code |
448 | | - * @param $amount |
449 | | - * @return unknown_type |
| 447 | + * @param string $currency_code |
| 448 | + * @param float $amount |
| 449 | + * @return float |
450 | 450 | */ |
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; |
507 | 459 | } |
508 | | - |
509 | 460 | return $usd_amount; |
510 | 461 | } |
511 | 462 | |