PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / trunk
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution vtrunk
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 1.7.2 All 33 releases
fluent-booking / app / Services / CurrenciesHelper.php

CurrenciesHelper.php in Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution trunk, at app/Services/CurrenciesHelper.php

441 lines 15.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentBooking\App\Services;
4
5 use FluentBooking\Framework\Support\Arr;
6
7 class CurrenciesHelper
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
42 public static function getGlobalCurrency()
43 {
44 $globalCurrencySettings = self::getGlobalCurrencySettings();
45
46 return Arr::get($globalCurrencySettings, 'currency', 'USD');
47 }
48
49 public static function getGlobalCurrencySign()
50 {
51 $currency = static::getGlobalCurrency();
52
53 return static::getCurrencySign($currency);
54 }
55
56 public static function getFormattedCurrencies()
57 {
58 $currencies = static::getCurrencies();
59 $formatted = array();
60 foreach ($currencies as $code => $name) {
61 $formatted[] = array(
62 "label" => $name,
63 "value" => $code,
64 );
65 }
66 return $formatted;
67 }
68 /**
69 * https://support.stripe.com/questions/which-currencies-does-stripe-support
70 */
71 public static function getCurrencies($code = null)
72 {
73 $currencies = apply_filters('fluent_booking/accepted_currencies', array(
74 'AED' => 'United Arab Emirates Dirham',
75 'AFN' => 'Afghan Afghani',
76 'ALL' => 'Albanian Lek',
77 'AMD' => 'Armenian Dram',
78 'ANG' => 'Netherlands Antillean Gulden',
79 'AOA' => 'Angolan Kwanza',
80 'ARS' => 'Argentine Peso', // non amex
81 'AUD' => 'Australian Dollar',
82 'AWG' => 'Aruban Florin',
83 'AZN' => 'Azerbaijani Manat',
84 'BAM' => 'Bosnia & Herzegovina Convertible Mark',
85 'BBD' => 'Barbadian Dollar',
86 'BDT' => 'Bangladeshi Taka',
87 'BIF' => 'Burundian Franc',
88 'BGN' => 'Bulgarian Lev',
89 'BMD' => 'Bermudian Dollar',
90 'BND' => 'Brunei Dollar',
91 'BOB' => 'Bolivian Boliviano',
92 'BRL' => 'Brazilian Real',
93 'BSD' => 'Bahamian Dollar',
94 'BWP' => 'Botswana Pula',
95 'BZD' => 'Belize Dollar',
96 'CAD' => 'Canadian Dollar',
97 'CDF' => 'Congolese Franc',
98 'CHF' => 'Swiss Franc',
99 'CLP' => 'Chilean Peso',
100 'CNY' => 'Chinese Renminbi Yuan',
101 'COP' => 'Colombian Peso',
102 'CRC' => 'Costa Rican Colón',
103 'CVE' => 'Cape Verdean Escudo',
104 'CZK' => 'Czech Koruna',
105 'DJF' => 'Djiboutian Franc',
106 'DKK' => 'Danish Krone',
107 'DOP' => 'Dominican Peso',
108 'DZD' => 'Algerian Dinar',
109 'EGP' => 'Egyptian Pound',
110 'ETB' => 'Ethiopian Birr',
111 'EUR' => 'Euro',
112 'FJD' => 'Fijian Dollar',
113 'FKP' => 'Falkland Islands Pound',
114 'GBP' => 'British Pound',
115 'GEL' => 'Georgian Lari',
116 'GIP' => 'Gibraltar Pound',
117 'GMD' => 'Gambian Dalasi',
118 'GNF' => 'Guinean Franc',
119 'GTQ' => 'Guatemalan Quetzal',
120 'GYD' => 'Guyanese Dollar',
121 'HKD' => 'Hong Kong Dollar',
122 'HNL' => 'Honduran Lempira',
123 'HRK' => 'Croatian Kuna',
124 'HTG' => 'Haitian Gourde',
125 'HUF' => 'Hungarian Forint',
126 'IDR' => 'Indonesian Rupiah',
127 'ILS' => 'Israeli New Sheqel',
128 'INR' => 'Indian Rupee',
129 'ISK' => 'Icelandic Króna',
130 'JMD' => 'Jamaican Dollar',
131 'JPY' => 'Japanese Yen',
132 'KES' => 'Kenyan Shilling',
133 'KGS' => 'Kyrgyzstani Som',
134 'KHR' => 'Cambodian Riel',
135 'KMF' => 'Comorian Franc',
136 'KRW' => 'South Korean Won',
137 'KYD' => 'Cayman Islands Dollar',
138 'KZT' => 'Kazakhstani Tenge',
139 'LAK' => 'Lao Kip',
140 'LBP' => 'Lebanese Pound',
141 'LKR' => 'Sri Lankan Rupee',
142 'LRD' => 'Liberian Dollar',
143 'LSL' => 'Lesotho Loti',
144 'MAD' => 'Moroccan Dirham',
145 'MDL' => 'Moldovan Leu',
146 'MGA' => 'Malagasy Ariary',
147 'MKD' => 'Macedonian Denar',
148 'MNT' => 'Mongolian Tögrög',
149 'MOP' => 'Macanese Pataca',
150 'MRO' => 'Mauritanian Ouguiya',
151 'MUR' => 'Mauritian Rupee',
152 'MVR' => 'Maldivian Rufiyaa',
153 'MWK' => 'Malawian Kwacha',
154 'MXN' => 'Mexican Peso',
155 'MYR' => 'Malaysian Ringgit',
156 'MZN' => 'Mozambican Metical',
157 'NAD' => 'Namibian Dollar',
158 'NGN' => 'Nigerian Naira',
159 'NIO' => 'Nicaraguan Córdoba',
160 'NOK' => 'Norwegian Krone',
161 'NPR' => 'Nepalese Rupee',
162 'NZD' => 'New Zealand Dollar',
163 'PAB' => 'Panamanian Balboa',
164 'PEN' => 'Peruvian Nuevo Sol',
165 'PGK' => 'Papua New Guinean Kina',
166 'PHP' => 'Philippine Peso',
167 'PKR' => 'Pakistani Rupee',
168 'PLN' => 'Polish Złoty',
169 'PYG' => 'Paraguayan Guaraní',
170 'QAR' => 'Qatari Riyal',
171 'RON' => 'Romanian Leu',
172 'RSD' => 'Serbian Dinar',
173 'RUB' => 'Russian Ruble',
174 'RWF' => 'Rwandan Franc',
175 'SAR' => 'Saudi Riyal',
176 'SBD' => 'Solomon Islands Dollar',
177 'SCR' => 'Seychellois Rupee',
178 'SEK' => 'Swedish Krona',
179 'SGD' => 'Singapore Dollar',
180 'SHP' => 'Saint Helenian Pound',
181 'SLL' => 'Sierra Leonean Leone',
182 'SOS' => 'Somali Shilling',
183 'SRD' => 'Surinamese Dollar',
184 'STD' => 'São Tomé and Príncipe Dobra',
185 'SVC' => 'Salvadoran Colón',
186 'SZL' => 'Swazi Lilangeni',
187 'THB' => 'Thai Baht',
188 'TJS' => 'Tajikistani Somoni',
189 'TOP' => 'Tongan Paʻanga',
190 'TRY' => 'Turkish Lira',
191 'TTD' => 'Trinidad and Tobago Dollar',
192 'TWD' => 'New Taiwan Dollar',
193 'TZS' => 'Tanzanian Shilling',
194 'UAH' => 'Ukrainian Hryvnia',
195 'UGX' => 'Ugandan Shilling',
196 'USD' => 'United States Dollar',
197 'UYU' => 'Uruguayan Peso',
198 'UZS' => 'Uzbekistani Som',
199 'VND' => 'Vietnamese Đồng',
200 'VUV' => 'Vanuatu Vatu',
201 'WST' => 'Samoan Tala',
202 'XAF' => 'Central African Cfa Franc',
203 'XCD' => 'East Caribbean Dollar',
204 'XOF' => 'West African Cfa Franc',
205 'XPF' => 'Cfp Franc',
206 'YER' => 'Yemeni Rial',
207 'ZAR' => 'South African Rand',
208 'ZMW' => 'Zambian Kwacha',
209 ));
210
211 if ($code) {
212 return isset($currencies[$code]) ? $currencies[$code] : '';
213 }
214
215 return $currencies;
216 }
217
218 /**
219 * Get the available locales that Stripe can use
220 *
221 * @return array
222 */
223 public static function getLocales()
224 {
225 return array(
226 '' => 'English (en) (default)',
227 'auto' => 'Auto-detect locale',
228 'zh' => 'Simplified Chinese (zh)',
229 'da' => 'Danish (da)',
230 'nl' => 'Dutch (nl)',
231 'fi' => 'Finnish (fi)',
232 'fr' => 'French (fr)',
233 'de' => 'German (de)',
234 'it' => 'Italian (it)',
235 'ja' => 'Japanese (ja)',
236 'no' => 'Norwegian (no)',
237 'es' => 'Spanish (es)',
238 'sv' => 'Swedish (sv)',
239 );
240 }
241
242 public static function getCurrencySign($currency = 'USD')
243 {
244 $currency = strtoupper($currency);
245
246 $symbols = apply_filters('fluent_booking/global_currency_symbols', array(
247 'AED' => '&#x62f;.&#x625;',
248 'AFN' => '&#x60b;',
249 'ALL' => 'L',
250 'AMD' => 'AMD',
251 'ANG' => '&fnof;',
252 'AOA' => 'Kz',
253 'ARS' => '&#36;',
254 'AUD' => '&#36;',
255 'AWG' => '&fnof;',
256 'AZN' => 'AZN',
257 'BAM' => 'KM',
258 'BBD' => '&#36;',
259 'BDT' => '&#2547;&nbsp;',
260 'BGN' => '&#1083;&#1074;.',
261 'BHD' => '.&#x62f;.&#x628;',
262 'BIF' => 'Fr',
263 'BMD' => '&#36;',
264 'BND' => '&#36;',
265 'BOB' => 'Bs.',
266 'BRL' => '&#82;&#36;',
267 'BSD' => '&#36;',
268 'BTC' => '&#3647;',
269 'BTN' => 'Nu.',
270 'BWP' => 'P',
271 'BYR' => 'Br',
272 'BZD' => '&#36;',
273 'CAD' => '&#36;',
274 'CDF' => 'Fr',
275 'CHF' => '&#67;&#72;&#70;',
276 'CLP' => '&#36;',
277 'CNY' => '&yen;',
278 'COP' => '&#36;',
279 'CRC' => '&#x20a1;',
280 'CUC' => '&#36;',
281 'CUP' => '&#36;',
282 'CVE' => '&#36;',
283 'CZK' => '&#75;&#269;',
284 'DJF' => 'Fr',
285 'DKK' => 'DKK',
286 'DOP' => 'RD&#36;',
287 'DZD' => '&#x62f;.&#x62c;',
288 'EGP' => 'EGP',
289 'ERN' => 'Nfk',
290 'ETB' => 'Br',
291 'EUR' => '&euro;',
292 'FJD' => '&#36;',
293 'FKP' => '&pound;',
294 'GBP' => '&pound;',
295 'GEL' => '&#x10da;',
296 'GGP' => '&pound;',
297 'GHS' => '&#x20b5;',
298 'GIP' => '&pound;',
299 'GMD' => 'D',
300 'GNF' => 'Fr',
301 'GTQ' => 'Q',
302 'GYD' => '&#36;',
303 'HKD' => '&#36;',
304 'HNL' => 'L',
305 'HRK' => 'Kn',
306 'HTG' => 'G',
307 'HUF' => '&#70;&#116;',
308 'IDR' => 'Rp',
309 'ILS' => '&#8362;',
310 'IMP' => '&pound;',
311 'INR' => '&#8377;',
312 'IQD' => '&#x639;.&#x62f;',
313 'IRR' => '&#xfdfc;',
314 'ISK' => 'Kr.',
315 'JEP' => '&pound;',
316 'JMD' => '&#36;',
317 'JOD' => '&#x62f;.&#x627;',
318 'JPY' => '&yen;',
319 'KES' => 'KSh',
320 'KGS' => '&#x43b;&#x432;',
321 'KHR' => '&#x17db;',
322 'KMF' => 'Fr',
323 'KPW' => '&#x20a9;',
324 'KRW' => '&#8361;',
325 'KWD' => '&#x62f;.&#x643;',
326 'KYD' => '&#36;',
327 'KZT' => 'KZT',
328 'LAK' => '&#8365;',
329 'LBP' => '&#x644;.&#x644;',
330 'LKR' => '&#xdbb;&#xdd4;',
331 'LRD' => '&#36;',
332 'LSL' => 'L',
333 'LYD' => '&#x644;.&#x62f;',
334 'MAD' => '&#x62f;. &#x645;.',
335 'MDL' => 'L',
336 'MGA' => 'Ar',
337 'MKD' => '&#x434;&#x435;&#x43d;',
338 'MMK' => 'Ks',
339 'MNT' => '&#x20ae;',
340 'MOP' => 'P',
341 'MRO' => 'UM',
342 'MUR' => '&#x20a8;',
343 'MVR' => '.&#x783;',
344 'MWK' => 'MK',
345 'MXN' => '&#36;',
346 'MYR' => '&#82;&#77;',
347 'MZN' => 'MT',
348 'NAD' => '&#36;',
349 'NGN' => '&#8358;',
350 'NIO' => 'C&#36;',
351 'NOK' => '&#107;&#114;',
352 'NPR' => '&#8360;',
353 'NZD' => '&#36;',
354 'OMR' => '&#x631;.&#x639;.',
355 'PAB' => 'B/.',
356 'PEN' => 'S/.',
357 'PGK' => 'K',
358 'PHP' => '&#8369;',
359 'PKR' => '&#8360;',
360 'PLN' => '&#122;&#322;',
361 'PRB' => '&#x440;.',
362 'PYG' => '&#8370;',
363 'QAR' => '&#x631;.&#x642;',
364 'RMB' => '&yen;',
365 'RON' => 'lei',
366 'RSD' => '&#x434;&#x438;&#x43d;.',
367 'RUB' => '&#8381;',
368 'RWF' => 'Fr',
369 'SAR' => '&#x631;.&#x633;',
370 'SBD' => '&#36;',
371 'SCR' => '&#x20a8;',
372 'SDG' => '&#x62c;.&#x633;.',
373 'SEK' => '&#107;&#114;',
374 'SGD' => '&#36;',
375 'SHP' => '&pound;',
376 'SLL' => 'Le',
377 'SOS' => 'Sh',
378 'SRD' => '&#36;',
379 'SSP' => '&pound;',
380 'STD' => 'Db',
381 'SVC' => '',
382 'SYP' => '&#x644;.&#x633;',
383 'SZL' => 'L',
384 'THB' => '&#3647;',
385 'TJS' => '&#x405;&#x41c;',
386 'TMT' => 'm',
387 'TND' => '&#x62f;.&#x62a;',
388 'TOP' => 'T&#36;',
389 'TRY' => '&#8378;',
390 'TTD' => '&#36;',
391 'TWD' => '&#78;&#84;&#36;',
392 'TZS' => 'Sh',
393 'UAH' => '&#8372;',
394 'UGX' => 'UGX',
395 'USD' => '&#36;',
396 'UYU' => '&#36;',
397 'UZS' => 'UZS',
398 'VEF' => 'Bs F',
399 'VND' => '&#8363;',
400 'VUV' => 'Vt',
401 'WST' => 'T',
402 'XAF' => 'Fr',
403 'XCD' => '&#36;',
404 'XOF' => 'Fr',
405 'XPF' => 'Fr',
406 'YER' => '&#xfdfc;',
407 'ZAR' => '&#82;',
408 'ZMW' => 'ZK',
409 ));
410 return isset($symbols[$currency]) ? $symbols[$currency] : '';
411 }
412
413 public static function zeroDecimalCurrencies()
414 {
415 return apply_filters('fluent_booking/zero_decimal_currencies', array(
416 'BIF' => esc_html__('Burundian Franc', 'fluent-booking'),
417 'CLP' => esc_html__('Chilean Peso', 'fluent-booking'),
418 'DJF' => esc_html__('Djiboutian Franc', 'fluent-booking'),
419 'GNF' => esc_html__('Guinean Franc', 'fluent-booking'),
420 'JPY' => esc_html__('Japanese Yen', 'fluent-booking'),
421 'KMF' => esc_html__('Comorian Franc', 'fluent-booking'),
422 'KRW' => esc_html__('South Korean Won', 'fluent-booking'),
423 'MGA' => esc_html__('Malagasy Ariary', 'fluent-booking'),
424 'PYG' => esc_html__('Paraguayan Guaraní', 'fluent-booking'),
425 'RWF' => esc_html__('Rwandan Franc', 'fluent-booking'),
426 'VND' => esc_html__('Vietnamese Dong', 'fluent-booking'),
427 'VUV' => esc_html__('Vanuatu Vatu', 'fluent-booking'),
428 'XAF' => esc_html__('Central African Cfa Franc', 'fluent-booking'),
429 'XOF' => esc_html__('West African Cfa Franc', 'fluent-booking'),
430 'XPF' => esc_html__('Cfp Franc', 'fluent-booking'),
431 ));
432 }
433
434 public static function isZeroDecimal($currencyCode)
435 {
436 $currencyCode = strtoupper($currencyCode);
437 $zeroDecimals = self::zeroDecimalCurrencies();
438 return isset($zeroDecimals[$currencyCode]);
439 }
440 }
441