PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.4
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.4
1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk 1.2.0 All 47 releases
fluent-cart / app / Helpers / CurrenciesHelper.php

CurrenciesHelper.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.4, at app/Helpers/CurrenciesHelper.php

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