PluginProbe ʕ •ᴥ•ʔ
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 3.0.3
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v3.0.3
4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.11.0 1.11.1 1.11.2 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.9.0 1.9.1 1.9.2 1.9.3 1.9.4 1.9.5 2.0.0 2.0.1 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.10.0 2.10.1 2.11.0 2.11.1 2.11.2 2.11.3 2.11.4 2.12.0 2.13.0 2.14.0 2.14.1 2.15.0 2.15.1 2.16.0 2.16.1 2.16.2 2.16.3 2.17.0 2.17.1 2.17.2 2.18.0 2.19.0 2.19.2 2.19.3 2.19.4 2.2.0 2.2.1 2.20.0 2.20.1 2.20.2 2.20.3 2.20.4 2.20.5 2.20.6 2.21.0 2.22.0 2.22.1 2.23.0 2.24.0 2.25.0 2.25.1 2.25.2 2.26.0 2.27.0 2.27.1 2.28.0 2.29.0 2.29.1 2.29.2 2.29.3 2.29.4 2.3.0 2.3.1 2.30.0 2.31.0 2.31.1 2.31.2 2.31.3 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.40.0 2.40.1 2.5.0 2.5.1 2.5.2 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.9.0 3.0.0 3.0.0-RC1 3.0.0-RC2 3.0.0-beta1 3.0.0-beta2 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.10.0 3.10.1 3.11.0 3.12.0 3.13.0 3.13.1 3.13.2 3.13.3 3.13.4 3.14.0 3.15.0 3.15.1 3.15.2 3.15.3 3.15.4 3.15.5 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.16.6 3.16.7 3.16.8 3.17.0 3.17.1 3.17.2 3.17.3 3.17.4 3.17.5 3.17.6 3.18.0 3.19.0 3.19.1 3.19.2 3.2.0 3.2.1 3.2.2 3.20.0 3.20.1 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 4.0.0 4.0.1 4.0.2 4.0.3 trunk 4.1.0 0.2.19.1 4.1.1 1.0.0 4.2.0 1.0.1 1.0.2
surecart / app / src / Support / Currency.php
surecart / app / src / Support Last commit date
Blocks 1 year ago Contracts 1 year ago Errors 1 year ago Scripts 1 year ago Arrays.php 3 years ago ColorService.php 3 years ago Currency.php 1 year ago Encryption.php 3 years ago Interval.php 1 year ago Server.php 2 years ago TimeDate.php 1 year ago Translations.php 3 years ago URL.php 2 years ago UtilityService.php 3 years ago UtilityServiceProvider.php 3 years ago kses.json 1 year ago
Currency.php
461 lines
1 <?php
2
3 namespace SureCart\Support;
4
5 /**
6 * Handles currency coversion and formatting
7 */
8 class Currency {
9 /**
10 * Get all available Currency symbols.
11 * Currency symbols and names should follow the Unicode CLDR recommendation (http://cldr.unicode.org/translation/currency-names)
12 */
13 public static function getCurrencySymbol( $key = null ) {
14 $key = strtoupper( $key ?? \SureCart::account()->currency ?? '' );
15 $symbols = apply_filters(
16 'surecart/currency_symbols',
17 array(
18 'AED' => '&#x62f;.&#x625;',
19 'AFN' => '&#x60b;',
20 'ALL' => 'L',
21 'AMD' => 'AMD',
22 'ANG' => '&fnof;',
23 'AOA' => 'Kz',
24 'ARS' => '&#36;',
25 'AUD' => '&#36;',
26 'AWG' => 'Afl.',
27 'AZN' => 'AZN',
28 'BAM' => 'KM',
29 'BBD' => '&#36;',
30 'BDT' => '&#2547;&nbsp;',
31 'BGN' => '&#1083;&#1074;.',
32 'BHD' => '.&#x62f;.&#x628;',
33 'BIF' => 'Fr',
34 'BMD' => '&#36;',
35 'BND' => '&#36;',
36 'BOB' => 'Bs.',
37 'BRL' => '&#82;&#36;',
38 'BSD' => '&#36;',
39 'BTC' => '&#3647;',
40 'BTN' => 'Nu.',
41 'BWP' => 'P',
42 'BYR' => 'Br',
43 'BYN' => 'Br',
44 'BZD' => '&#36;',
45 'CAD' => '&#36;',
46 'CDF' => 'Fr',
47 'CHF' => '&#67;&#72;&#70;',
48 'CLP' => '&#36;',
49 'CNY' => '&yen;',
50 'COP' => '&#36;',
51 'CRC' => '&#x20a1;',
52 'CUC' => '&#36;',
53 'CUP' => '&#36;',
54 'CVE' => '&#36;',
55 'CZK' => '&#75;&#269;',
56 'DJF' => 'Fr',
57 'DKK' => 'DKK',
58 'DOP' => 'RD&#36;',
59 'DZD' => '&#x62f;.&#x62c;',
60 'EGP' => 'EGP',
61 'ERN' => 'Nfk',
62 'ETB' => 'Br',
63 'EUR' => '&euro;',
64 'FJD' => '&#36;',
65 'FKP' => '&pound;',
66 'GBP' => '&pound;',
67 'GEL' => '&#x20be;',
68 'GGP' => '&pound;',
69 'GHS' => '&#x20b5;',
70 'GIP' => '&pound;',
71 'GMD' => 'D',
72 'GNF' => 'Fr',
73 'GTQ' => 'Q',
74 'GYD' => '&#36;',
75 'HKD' => '&#36;',
76 'HNL' => 'L',
77 'HRK' => 'kn',
78 'HTG' => 'G',
79 'HUF' => '&#70;&#116;',
80 'IDR' => 'Rp',
81 'ILS' => '&#8362;',
82 'IMP' => '&pound;',
83 'INR' => '&#8377;',
84 'IQD' => '&#x639;.&#x62f;',
85 'IRR' => '&#xfdfc;',
86 'IRT' => '&#x062A;&#x0648;&#x0645;&#x0627;&#x0646;',
87 'ISK' => 'kr.',
88 'JEP' => '&pound;',
89 'JMD' => '&#36;',
90 'JOD' => '&#x62f;.&#x627;',
91 'JPY' => '&yen;',
92 'KES' => 'KSh',
93 'KGS' => '&#x441;&#x43e;&#x43c;',
94 'KHR' => '&#x17db;',
95 'KMF' => 'Fr',
96 'KPW' => '&#x20a9;',
97 'KRW' => '&#8361;',
98 'KWD' => '&#x62f;.&#x643;',
99 'KYD' => '&#36;',
100 'KZT' => '&#8376;',
101 'LAK' => '&#8365;',
102 'LBP' => '&#x644;.&#x644;',
103 'LKR' => '&#xdbb;&#xdd4;',
104 'LRD' => '&#36;',
105 'LSL' => 'L',
106 'LYD' => '&#x644;.&#x62f;',
107 'MAD' => '&#x62f;.&#x645;.',
108 'MDL' => 'MDL',
109 'MKD' => '&#x434;&#x435;&#x43d;',
110 'MMK' => 'Ks',
111 'MNT' => '&#x20ae;',
112 'MOP' => 'P',
113 'MRU' => 'UM',
114 'MUR' => '&#x20a8;',
115 'MVR' => '.&#x783;',
116 'MWK' => 'MK',
117 'MXN' => '&#36;',
118 'MYR' => '&#82;&#77;',
119 'MZN' => 'MT',
120 'NAD' => 'N&#36;',
121 'NGN' => '&#8358;',
122 'NIO' => 'C&#36;',
123 'NOK' => '&#107;&#114;',
124 'NPR' => '&#8360;',
125 'NZD' => '&#36;',
126 'OMR' => '&#x631;.&#x639;.',
127 'PAB' => 'B/.',
128 'PEN' => 'S/',
129 'PGK' => 'K',
130 'PHP' => '&#8369;',
131 'PKR' => '&#8360;',
132 'PLN' => '&#122;&#322;',
133 'PRB' => '&#x440;.',
134 'PYG' => '&#8370;',
135 'QAR' => '&#x631;.&#x642;',
136 'RMB' => '&yen;',
137 'RON' => 'lei',
138 'RSD' => '&#1088;&#1089;&#1076;',
139 'RUB' => '&#8381;',
140 'RWF' => 'Fr',
141 'SAR' => '&#x631;.&#x633;',
142 'SBD' => '&#36;',
143 'SCR' => '&#x20a8;',
144 'SDG' => '&#x62c;.&#x633;.',
145 'SEK' => '&#107;&#114;',
146 'SGD' => '&#36;',
147 'SHP' => '&pound;',
148 'SLL' => 'Le',
149 'SOS' => 'Sh',
150 'SRD' => '&#36;',
151 'SSP' => '&pound;',
152 'STN' => 'Db',
153 'SYP' => '&#x644;.&#x633;',
154 'SZL' => 'L',
155 'THB' => '&#3647;',
156 'TJS' => '&#x405;&#x41c;',
157 'TMT' => 'm',
158 'TND' => '&#x62f;.&#x62a;',
159 'TOP' => 'T&#36;',
160 'TRY' => '&#8378;',
161 'TTD' => '&#36;',
162 'TWD' => '&#78;&#84;&#36;',
163 'TZS' => 'Sh',
164 'UAH' => '&#8372;',
165 'UGX' => 'UGX',
166 'USD' => '&#36;',
167 'UYU' => '&#36;',
168 'UZS' => 'UZS',
169 'VEF' => 'Bs F',
170 'VES' => 'Bs.S',
171 'VND' => '&#8363;',
172 'VUV' => 'Vt',
173 'WST' => 'T',
174 'XAF' => 'CFA',
175 'XCD' => '&#36;',
176 'XOF' => 'CFA',
177 'XPF' => 'Fr',
178 'YER' => '&#xfdfc;',
179 'ZAR' => '&#82;',
180 'ZMW' => 'ZK',
181 )
182 );
183 return $symbols[ $key ] ?? '&#36;';
184 }
185
186 /**
187 * Format the currency into the current locale.
188 *
189 * @param integer $amount Amount as an integer.
190 * @param string $currency_code 3 digit currency code.
191 *
192 * @return string
193 */
194 public static function format( $amount, $currency_code = null ) {
195 if ( empty( $currency_code ) ) {
196 $currency_code = \SureCart::account()->currency;
197 }
198
199 if ( class_exists( 'NumberFormatter' ) ) {
200 $fmt = new \NumberFormatter( get_locale(), \NumberFormatter::CURRENCY );
201 $converted_amount = self::maybeConvertAmount( $amount, $currency_code );
202
203 // Extract the fractional part.
204 $fractional_part = fmod( $converted_amount, 1 );
205
206 // Check if the fractional part is .00.
207 $minimum_fraction_digits = ( 0.00 === $fractional_part ) ? 0 : 2;
208
209 $fmt->setAttribute( \NumberFormatter::MAX_FRACTION_DIGITS, apply_filters( 'surecart/currency/max_cents', $minimum_fraction_digits, $amount, $converted_amount ) );
210 return $fmt->formatCurrency( $converted_amount, strtoupper( $currency_code ) );
211 }
212
213 return html_entity_decode( self::getCurrencySymbol( $currency_code ) ) . self::formatCurrencyNumber( $amount );
214 }
215
216 /**
217 * Get zero decimal currencies in uppercase.
218 *
219 * @return array
220 */
221 public static function getZeroDecicalCurrencies(): array {
222 return array(
223 'BIF',
224 'BYR',
225 'CLP',
226 'DJF',
227 'GNF',
228 'ISK',
229 'JPY',
230 'KMF',
231 'KRW',
232 'PYG',
233 'RWF',
234 'UGX',
235 'VND',
236 'VUV',
237 'XAF',
238 'XAG',
239 'XAU',
240 'XBA',
241 'XBB',
242 'XBC',
243 'XBD',
244 'XDR',
245 'XOF',
246 'XPD',
247 'XPF',
248 'XPT',
249 'XTS',
250 );
251 }
252
253 /**
254 * Format the currency number
255 */
256 public static function formatCurrencyNumber( $amount, $currency_code = 'usd' ) {
257 $amount = (float) $amount;
258 // TODO: Test this.
259 if ( in_array( strtoupper( $currency_code ), self::getZeroDecicalCurrencies(), true ) ) {
260 return self::formatCents( $amount, 1 );
261 }
262 return self::formatCents( $amount / 100, 1 );
263 }
264
265 /**
266 * Format the cents.
267 *
268 * @param integer $number Number.
269 * @param integer $cents Cents.
270 *
271 * @return string
272 */
273 public static function formatCents( $number, $cents = 1 ) {
274 // cents: 0=never, 1=if needed, 2=always.
275 if ( is_numeric( $number ) ) { // a number.
276 if ( ! $number ) { // zero.
277 $money = ( 2 === $cents ? '0.00' : '0' ); // output zero.
278 } else { // value.
279 if ( floor( $number ) == $number ) { // whole number.
280 $money = number_format_i18n( (float) $number, ( 2 === $cents ? 2 : 0 ) ); // format.
281 } else { // cents.
282 $money = number_format_i18n( round( (float) $number, 2 ), ( 0 === $cents ? 0 : 2 ) ); // format.
283 } // integer or decimal.
284 } // value.
285 return number_format_i18n( (float) $money, 2 );
286 } // numeric.
287 }
288
289 /**
290 * Get a list of supported currencies.
291 *
292 * @param string $provider Provider.
293 */
294 public static function getSupportedCurrencies() {
295 return [
296 'all' => __( 'Albanian Lek', 'surecart' ),
297 'dzd' => __( 'Algerian Dinar', 'surecart' ),
298 'aoa' => __( 'Angolan Kwanza', 'surecart' ),
299 'ars' => __( 'Argentine Peso', 'surecart' ),
300 'amd' => __( 'Armenian Dram', 'surecart' ),
301 'awg' => __( 'Aruban Florin', 'surecart' ),
302 'aud' => __( 'Australian Dollar', 'surecart' ),
303 'azn' => __( 'Azerbaijani Manat', 'surecart' ),
304 'bsd' => __( 'Bahamian Dollar', 'surecart' ),
305 'bdt' => __( 'Bangladeshi Taka', 'surecart' ),
306 'bbd' => __( 'Barbadian Dollar', 'surecart' ),
307 'byn' => __( 'Belarusian Ruble', 'surecart' ),
308 'bzd' => __( 'Belize Dollar', 'surecart' ),
309 'bmd' => __( 'Bermudian Dollar', 'surecart' ),
310 'bob' => __( 'Bolivian Boliviano', 'surecart' ),
311 'bam' => __( 'Bosnia and Herzegovina Convertible Mark', 'surecart' ),
312 'bwp' => __( 'Botswana Pula', 'surecart' ),
313 'brl' => __( 'Brazilian Real', 'surecart' ),
314 'gbp' => __( 'British Pound', 'surecart' ),
315 'bnd' => __( 'Brunei Dollar', 'surecart' ),
316 'bgn' => __( 'Bulgarian Lev', 'surecart' ),
317 'bif' => __( 'Burundian Franc', 'surecart' ),
318 'khr' => __( 'Cambodian Riel', 'surecart' ),
319 'cad' => __( 'Canadian Dollar', 'surecart' ),
320 'cve' => __( 'Cape Verdean Escudo', 'surecart' ),
321 'kyd' => __( 'Cayman Islands Dollar', 'surecart' ),
322 'xaf' => __( 'Central African Cfa Franc', 'surecart' ),
323 'xpf' => __( 'Cfp Franc', 'surecart' ),
324 'clp' => __( 'Chilean Peso', 'surecart' ),
325 'cny' => __( 'Chinese Renminbi Yuan', 'surecart' ),
326 'cop' => __( 'Colombian Peso', 'surecart' ),
327 'kmf' => __( 'Comorian Franc', 'surecart' ),
328 'cdf' => __( 'Congolese Franc', 'surecart' ),
329 'crc' => __( 'Costa Rican Colón', 'surecart' ),
330 'hrk' => __( 'Croatian Kuna', 'surecart' ),
331 'czk' => __( 'Czech Koruna', 'surecart' ),
332 'dkk' => __( 'Danish Krone', 'surecart' ),
333 'djf' => __( 'Djiboutian Franc', 'surecart' ),
334 'dop' => __( 'Dominican Peso', 'surecart' ),
335 'xcd' => __( 'East Caribbean Dollar', 'surecart' ),
336 'egp' => __( 'Egyptian Pound', 'surecart' ),
337 'etb' => __( 'Ethiopian Birr', 'surecart' ),
338 'eur' => __( 'Euro', 'surecart' ),
339 'fkp' => __( 'Falkland Pound', 'surecart' ),
340 'fjd' => __( 'Fijian Dollar', 'surecart' ),
341 'gmd' => __( 'Gambian Dalasi', 'surecart' ),
342 'gel' => __( 'Georgian Lari', 'surecart' ),
343 'ghs' => __( 'Ghanaian Cedi', 'surecart' ),
344 'gip' => __( 'Gibraltar Pound', 'surecart' ),
345 'gtq' => __( 'Guatemalan Quetzal', 'surecart' ),
346 'gnf' => __( 'Guinean Franc', 'surecart' ),
347 'gyd' => __( 'Guyanese Dollar', 'surecart' ),
348 'htg' => __( 'Haitian Gourde', 'surecart' ),
349 'hnl' => __( 'Honduran Lempira', 'surecart' ),
350 'hkd' => __( 'Hong Kong Dollar', 'surecart' ),
351 'huf' => __( 'Hungarian Forint', 'surecart' ),
352 'isk' => __( 'Icelandic Króna', 'surecart' ),
353 'inr' => __( 'Indian Rupee', 'surecart' ),
354 'idr' => __( 'Indonesian Rupiah', 'surecart' ),
355 'ils' => __( 'Israeli New Sheqel', 'surecart' ),
356 'jmd' => __( 'Jamaican Dollar', 'surecart' ),
357 'jpy' => __( 'Japanese Yen', 'surecart' ),
358 'kzt' => __( 'Kazakhstani Tenge', 'surecart' ),
359 'kes' => __( 'Kenyan Shilling', 'surecart' ),
360 'kgs' => __( 'Kyrgyzstani Som', 'surecart' ),
361 'lak' => __( 'Lao Kip', 'surecart' ),
362 'lbp' => __( 'Lebanese Pound', 'surecart' ),
363 'lsl' => __( 'Lesotho Loti', 'surecart' ),
364 'lrd' => __( 'Liberian Dollar', 'surecart' ),
365 'mop' => __( 'Macanese Pataca', 'surecart' ),
366 'mkd' => __( 'Macedonian Denar', 'surecart' ),
367 'mwk' => __( 'Malawian Kwacha', 'surecart' ),
368 'myr' => __( 'Malaysian Ringgit', 'surecart' ),
369 'mvr' => __( 'Maldivian Rufiyaa', 'surecart' ),
370 'mro' => __( 'Mauritanian Ouguiya', 'surecart' ),
371 'mur' => __( 'Mauritian Rupee', 'surecart' ),
372 'mxn' => __( 'Mexican Peso', 'surecart' ),
373 'mdl' => __( 'Moldovan Leu', 'surecart' ),
374 'mnt' => __( 'Mongolian Tögrög', 'surecart' ),
375 'mad' => __( 'Moroccan Dirham', 'surecart' ),
376 'mzn' => __( 'Mozambican Metical', 'surecart' ),
377 'mmk' => __( 'Myanmar Kyat', 'surecart' ),
378 'nad' => __( 'Namibian Dollar', 'surecart' ),
379 'npr' => __( 'Nepalese Rupee', 'surecart' ),
380 'ang' => __( 'Netherlands Antillean Gulden', 'surecart' ),
381 'twd' => __( 'New Taiwan Dollar', 'surecart' ),
382 'nzd' => __( 'New Zealand Dollar', 'surecart' ),
383 'nio' => __( 'Nicaraguan Córdoba', 'surecart' ),
384 'ngn' => __( 'Nigerian Naira', 'surecart' ),
385 'nok' => __( 'Norwegian Krone', 'surecart' ),
386 'pkr' => __( 'Pakistani Rupee', 'surecart' ),
387 'pab' => __( 'Panamanian Balboa', 'surecart' ),
388 'pgk' => __( 'Papua New Guinean Kina', 'surecart' ),
389 'pyg' => __( 'Paraguayan Guaraní', 'surecart' ),
390 'pen' => __( 'Peruvian Sol', 'surecart' ),
391 'php' => __( 'Philippine Peso', 'surecart' ),
392 'pln' => __( 'Polish Złoty', 'surecart' ),
393 'qar' => __( 'Qatari Riyal', 'surecart' ),
394 'ron' => __( 'Romanian Leu', 'surecart' ),
395 'rub' => __( 'Russian Ruble', 'surecart' ),
396 'rwf' => __( 'Rwandan Franc', 'surecart' ),
397 'shp' => __( 'Saint Helenian Pound', 'surecart' ),
398 'wst' => __( 'Samoan Tala', 'surecart' ),
399 'sar' => __( 'Saudi Riyal', 'surecart' ),
400 'rsd' => __( 'Serbian Dinar', 'surecart' ),
401 'scr' => __( 'Seychellois Rupee', 'surecart' ),
402 'sll' => __( 'Sierra Leonean Leone', 'surecart' ),
403 'sgd' => __( 'Singapore Dollar', 'surecart' ),
404 'sbd' => __( 'Solomon Islands Dollar', 'surecart' ),
405 'sos' => __( 'Somali Shilling', 'surecart' ),
406 'zar' => __( 'South African Rand', 'surecart' ),
407 'krw' => __( 'South Korean Won', 'surecart' ),
408 'lkr' => __( 'Sri Lankan Rupee', 'surecart' ),
409 'srd' => __( 'Surinamese Dollar', 'surecart' ),
410 'szl' => __( 'Swazi Lilangeni', 'surecart' ),
411 'sek' => __( 'Swedish Krona', 'surecart' ),
412 'chf' => __( 'Swiss Franc', 'surecart' ),
413 'std' => __( 'São Tomé and Príncipe Dobra', 'surecart' ),
414 'tjs' => __( 'Tajikistani Somoni', 'surecart' ),
415 'tzs' => __( 'Tanzanian Shilling', 'surecart' ),
416 'thb' => __( 'Thai Baht', 'surecart' ),
417 'top' => __( 'Tongan Paʻanga', 'surecart' ),
418 'ttd' => __( 'Trinidad and Tobago Dollar', 'surecart' ),
419 'try' => __( 'Turkish Lira', 'surecart' ),
420 'ugx' => __( 'Ugandan Shilling', 'surecart' ),
421 'uah' => __( 'Ukrainian Hryvnia', 'surecart' ),
422 'aed' => __( 'United Arab Emirates Dirham', 'surecart' ),
423 'usd' => __( 'United States Dollar', 'surecart' ),
424 'uyu' => __( 'Uruguayan Peso', 'surecart' ),
425 'uzs' => __( 'Uzbekistan Som', 'surecart' ),
426 'vuv' => __( 'Vanuatu Vatu', 'surecart' ),
427 'vnd' => __( 'Vietnamese Đồng', 'surecart' ),
428 'xof' => __( 'West African Cfa Franc', 'surecart' ),
429 'yer' => __( 'Yemeni Rial', 'surecart' ),
430 'zmw' => __( 'Zambian Kwacha', 'surecart' ),
431 'tnd' => __( 'Tunisian Dinar', 'surecart' ),
432 ];
433 }
434
435 /**
436 * Determine if this is a zero decimal currency.
437 *
438 * @param string $currency The currency code.
439 *
440 * @return bool
441 */
442 public static function isZeroDecimal( $currency ) {
443 return in_array( strtoupper( $currency ), self::getZeroDecicalCurrencies(), true );
444 }
445
446 /**
447 * Convery product amount.
448 *
449 * @param int $amount The Amount.
450 * @param string $currency The Currency.
451 *
452 * @return int
453 */
454 public static function maybeConvertAmount( $amount, $currency = null ) {
455 if ( ! $currency ) {
456 $currency = \SureCart::account()->currency;
457 }
458 return self::isZeroDecimal( (string) $currency ) ? $amount : $amount / 100;
459 }
460 }
461