| @@ -5,8 +5,10 @@ | ||
| 5 | 5 | use FluentBooking\Framework\Support\Arr; |
| 6 | 6 | |
| 7 | 7 | class CurrenciesHelper |
| 8 | 8 | { |
| 9 | + private static $globalCurrencySettings = null; | |
| 10 | + | |
| 9 | 11 | public static function getDefaultCurrencySettings() |
| 10 | 12 | { |
| 11 | 13 | return apply_filters('fluent_booking/default_currency_settings', [ |
| 12 | 14 | 'currency' => 'USD', |
| @@ -17,10 +19,14 @@ | ||
| 17 | 19 | 'decimal_points' => 2 |
| 18 | 20 | ]); |
| 19 | 21 | } |
| 20 | 22 | |
| 21 | - public static function getGlobalCurrencySettings() | |
| 23 | + public static function getGlobalCurrencySettings($force = false) | |
| 22 | 24 | { |
| 25 | + if (!$force && self::$globalCurrencySettings !== null) { | |
| 26 | + return self::$globalCurrencySettings; | |
| 27 | + } | |
| 28 | + | |
| 23 | 29 | $defaultSettings = self::getDefaultCurrencySettings(); |
| 24 | 30 | |
| 25 | 31 | $globalSettings = Helper::getGlobalPaymentSettings(); |
| 26 | 32 | |
| @@ -27,9 +33,11 @@ | ||
| 27 | 33 | $currencySettings = wp_parse_args($globalSettings, $defaultSettings); |
| 28 | 34 | |
| 29 | 35 | $currencySettings['currency_sign'] = self::getCurrencySign($currencySettings['currency']); |
| 30 | 36 | |
| 31 | - return apply_filters('fluent_booking/global_currency_settings', $currencySettings); | |
| 37 | + self::$globalCurrencySettings = apply_filters('fluent_booking/global_currency_settings', $currencySettings); | |
| 38 | + | |
| 39 | + return self::$globalCurrencySettings; | |
| 32 | 40 | } |
| 33 | 41 | |
| 34 | 42 | public static function getGlobalCurrency() |
| 35 | 43 | { |
| @@ -369,8 +377,9 @@ | ||
| 369 | 377 | 'SOS' => 'Sh', |
| 370 | 378 | 'SRD' => '$', |
| 371 | 379 | 'SSP' => '£', |
| 372 | 380 | 'STD' => 'Db', |
| 381 | + 'SVC' => '₡', | |
| 373 | 382 | 'SYP' => 'ل.س', |
| 374 | 383 | 'SZL' => 'L', |
| 375 | 384 | 'THB' => '฿', |
| 376 | 385 | 'TJS' => 'ЅМ', |
| @@ -419,8 +428,16 @@ | ||
| 419 | 428 | 'XAF' => esc_html__('Central African Cfa Franc', 'fluent-booking'), |
| 420 | 429 | 'XOF' => esc_html__('West African Cfa Franc', 'fluent-booking'), |
| 421 | 430 | 'XPF' => esc_html__('Cfp Franc', 'fluent-booking'), |
| 422 | 431 | )); |
| 432 | + } | |
| 433 | + | |
| 434 | + // Every money write goes through here so the ledger and the gateway cannot diverge. | |
| 435 | + // Rounds rather than truncates: 2.01 * 100 is 200.99999999999997 in IEEE-754, so | |
| 436 | + // intval() records 200 where the card is charged 201. Factor is 1 for zero-decimal. | |
| 437 | + public static function toCents($value, $conversionFactor = 100) | |
| 438 | + { | |
| 439 | + return (int) round((float) $value * $conversionFactor); | |
| 423 | 440 | } |
| 424 | 441 | |
| 425 | 442 | public static function isZeroDecimal($currencyCode) |
| 426 | 443 | { |