Skip to content

Commit

Permalink
fix(engine): 🐛 Payment for zero-decimal currencies
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Jun 2, 2022
1 parent 89d91f9 commit 274f30c
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions apps/viewer/pages/api/integrations/stripe/createPaymentIntent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
: stripeKeys.live.secretKey,
{ apiVersion: '2020-08-27' }
)
const amount = Math.round(
Number(parseVariables(variables)(inputOptions.amount)) * 100
)
const amount =
Number(parseVariables(variables)(inputOptions.amount)) *
(isZeroDecimalCurrency(inputOptions.currency) ? 1 : 100)
if (isNaN(amount)) return badRequest(res)
// Create a PaymentIntent with the order amount and currency
const receiptEmail = parseVariables(variables)(
Expand All @@ -77,7 +77,9 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
isPreview && stripeKeys.test?.publicKey
? stripeKeys.test.publicKey
: stripeKeys.live.publicKey,
amountLabel: `${amount / 100}${
amountLabel: `${
amount / (isZeroDecimalCurrency(inputOptions.currency) ? 1 : 100)
}${
currencySymbols[inputOptions.currency] ?? ` ${inputOptions.currency}`
}`,
})
Expand Down Expand Up @@ -108,4 +110,25 @@ const getStripeInfo = async (
return decrypt(credentials.data, credentials.iv) as StripeCredentialsData
}

// https://stripe.com/docs/currencies#zero-decimal
const isZeroDecimalCurrency = (currency: string) =>
[
'BIF',
'CLP',
'DJF',
'GNF',
'JPY',
'KMF',
'KRW',
'MGA',
'PYG',
'RWF',
'UGX',
'VND',
'VUV',
'XAF',
'XOF',
'XPF',
].includes(currency)

export default withSentry(handler)

4 comments on commit 274f30c

@vercel
Copy link

@vercel vercel bot commented on 274f30c Jun 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

app.typebot.io
builder-v2-git-main-typebot-io.vercel.app
builder-v2-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 274f30c Jun 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 274f30c Jun 2, 2022

@vercel
Copy link

@vercel vercel bot commented on 274f30c Jun 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.