mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-03 22:29:01 +02:00
c1ec3044d7
* Implement LATAM geo-pricing split test * Hide Paypal if currency is one of INR, COP, CLP, PEN * Only send the LATAM/INR banner events when banner is rendered * Workaround in Subscription dashboard for CLP not having minor units GitOrigin-RevId: a677086a7762900563558126d2f81a4c57bbe9d7
58 lines
1.2 KiB
JavaScript
58 lines
1.2 KiB
JavaScript
const dateformat = require('dateformat')
|
|
|
|
const currencySymbols = {
|
|
EUR: '€',
|
|
USD: '$',
|
|
GBP: '£',
|
|
SEK: 'kr',
|
|
CAD: '$',
|
|
NOK: 'kr',
|
|
DKK: 'kr',
|
|
AUD: '$',
|
|
NZD: '$',
|
|
CHF: 'Fr',
|
|
SGD: '$',
|
|
INR: '₹',
|
|
BRL: 'R$',
|
|
MXN: '$',
|
|
COP: '$',
|
|
CLP: '$',
|
|
PEN: 'S/',
|
|
}
|
|
|
|
module.exports = {
|
|
formatPrice(priceInCents, currency) {
|
|
if (!currency) {
|
|
currency = 'USD'
|
|
} else if (currency === 'CLP') {
|
|
// CLP doesn't have minor units, recurly stores the whole major unit without cents
|
|
return priceInCents.toLocaleString('es-CL', {
|
|
style: 'currency',
|
|
currency,
|
|
minimumFractionDigits: 0,
|
|
})
|
|
}
|
|
let string = String(Math.round(priceInCents))
|
|
if (string.length === 2) {
|
|
string = `0${string}`
|
|
}
|
|
if (string.length === 1) {
|
|
string = `00${string}`
|
|
}
|
|
if (string.length === 0) {
|
|
string = '000'
|
|
}
|
|
const cents = string.slice(-2)
|
|
const dollars = string.slice(0, -2)
|
|
const symbol = currencySymbols[currency]
|
|
return `${symbol}${dollars}.${cents}`
|
|
},
|
|
|
|
formatDate(date) {
|
|
if (!date) {
|
|
return null
|
|
}
|
|
return dateformat(date, 'mmmm dS, yyyy h:MM TT Z', true)
|
|
},
|
|
}
|