Skip to content

Commit

Permalink
♿ (payment) Improve payment input amount label format
Browse files Browse the repository at this point in the history
Closes #553
  • Loading branch information
baptisteArno committed Jun 9, 2023
1 parent 25524ac commit 290b491
Showing 1 changed file with 10 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,23 @@ const createStripePaymentIntent =
message: 'Could not create payment intent',
})

const priceFormatter = new Intl.NumberFormat(
options.currency === 'EUR' ? 'fr-FR' : undefined,
{
style: 'currency',
currency: options.currency,
}
)

return {
paymentIntentSecret: paymentIntent.client_secret,
publicKey:
isPreview && stripeKeys.test?.publicKey
? stripeKeys.test.publicKey
: stripeKeys.live.publicKey,
amountLabel: `${
amountLabel: priceFormatter.format(
amount / (isZeroDecimalCurrency(options.currency) ? 1 : 100)
}${currencySymbols[options.currency] ?? ` ${options.currency}`}`,
),
}
}

Expand Down Expand Up @@ -115,21 +123,3 @@ const isZeroDecimalCurrency = (currency: string) =>
'XOF',
'XPF',
].includes(currency)

const currencySymbols: { [key: string]: string } = {
USD: '$',
EUR: '€',
CRC: '₡',
GBP: '£',
ILS: '₪',
INR: '₹',
JPY: '¥',
KRW: '₩',
NGN: '₦',
PHP: '₱',
PLN: 'zł',
PYG: '₲',
THB: '฿',
UAH: '₴',
VND: '₫',
}

0 comments on commit 290b491

Please sign in to comment.