PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / 2.5.0
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution v2.5.0
2.5.0 2.4.0 2.3.0 2.2.5 2.2.0 2.1.2 2.1.1 trunk 1.10.0 1.10.01 1.10.02 1.5.0 1.5.01 1.5.02 1.5.1 1.5.10 1.5.20 1.5.21 1.5.22 1.5.23 1.5.24 1.5.25 1.6.0 1.7.0 1.7.1 All 34 releases
← All changes | app/Services/CurrenciesHelper.php +46 -2 1.5.02 → 2.5.0 View file →
@@ -5,17 +5,52 @@
5 5 use FluentBooking\Framework\Support\Arr;
6 6
7 7 class CurrenciesHelper
8 8 {
9 + private static $globalCurrencySettings = null;
10 +
11 + public static function getDefaultCurrencySettings()
12 + {
13 + return apply_filters('fluent_booking/default_currency_settings', [
14 + 'currency' => 'USD',
15 + 'is_active' => 'no',
16 + 'currency_sign' => '$',
17 + 'currency_position' => 'left', // left, right, left_space, right_space
18 + 'number_format' => 'comma_separated', // or dot_separated
19 + 'decimal_points' => 2
20 + ]);
21 + }
22 +
23 + public static function getGlobalCurrencySettings($force = false)
24 + {
25 + if (!$force && self::$globalCurrencySettings !== null) {
26 + return self::$globalCurrencySettings;
27 + }
28 +
29 + $defaultSettings = self::getDefaultCurrencySettings();
30 +
31 + $globalSettings = Helper::getGlobalPaymentSettings();
32 +
33 + $currencySettings = wp_parse_args($globalSettings, $defaultSettings);
34 +
35 + $currencySettings['currency_sign'] = self::getCurrencySign($currencySettings['currency']);
36 +
37 + self::$globalCurrencySettings = apply_filters('fluent_booking/global_currency_settings', $currencySettings);
38 +
39 + return self::$globalCurrencySettings;
40 + }
41 +
9 42 public static function getGlobalCurrency()
10 43 {
11 - $globalPaymentSettings = get_option('fluent_booking_global_payment_settings', ['currency' => 'USD']);
12 - return Arr::get($globalPaymentSettings, 'currency', 'USD');
44 + $globalCurrencySettings = self::getGlobalCurrencySettings();
45 +
46 + return Arr::get($globalCurrencySettings, 'currency', 'USD');
13 47 }
14 48
15 49 public static function getGlobalCurrencySign()
16 50 {
17 51 $currency = static::getGlobalCurrency();
52 +
18 53 return static::getCurrencySign($currency);
19 54 }
20 55
21 56 public static function getFormattedCurrencies()
@@ -342,8 +377,9 @@
342 377 'SOS' => 'Sh',
343 378 'SRD' => '$',
344 379 'SSP' => '£',
345 380 'STD' => 'Db',
381 + 'SVC' => '₡',
346 382 'SYP' => 'ل.س',
347 383 'SZL' => 'L',
348 384 'THB' => '฿',
349 385 'TJS' => 'ЅМ',
@@ -392,8 +428,16 @@
392 428 'XAF' => esc_html__('Central African Cfa Franc', 'fluent-booking'),
393 429 'XOF' => esc_html__('West African Cfa Franc', 'fluent-booking'),
394 430 'XPF' => esc_html__('Cfp Franc', 'fluent-booking'),
395 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);
396 440 }
397 441
398 442 public static function isZeroDecimal($currencyCode)
399 443 {