Skip to content

Commit

Permalink
🐛 (billing) Fix currency possible mismatch on sub update
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Nov 29, 2022
1 parent 43a85b5 commit f9ffdbc
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const ChangePlanForm = () => {
workspaceId: workspace.id,
additionalChats: selectedChatsLimitIndex,
additionalStorage: selectedStorageLimitIndex,
currency: data?.currency,
})
if (typeof response === 'object' && response?.error) {
showToast({ description: response.error.message })
Expand Down Expand Up @@ -75,6 +76,7 @@ export const ChangePlanForm = () => {
onPayClick={(props) =>
handlePayClick({ ...props, plan: Plan.STARTER })
}
currency={data?.currency}
/>

<ProPlanContent
Expand All @@ -85,6 +87,7 @@ export const ChangePlanForm = () => {
workspace?.plan === Plan.PRO ? data?.additionalStorageIndex : 0
}
onPayClick={(props) => handlePayClick({ ...props, plan: Plan.PRO })}
currency={data?.currency}
/>
</HStack>
<Text color="gray.500">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { MoreInfoTooltip } from '@/components/MoreInfoTooltip'
type ProPlanContentProps = {
initialChatsLimitIndex?: number
initialStorageLimitIndex?: number
currency?: 'usd' | 'eur'
onPayClick: (props: {
selectedChatsLimitIndex: number
selectedStorageLimitIndex: number
Expand All @@ -41,6 +42,7 @@ type ProPlanContentProps = {
export const ProPlanContent = ({
initialChatsLimitIndex,
initialStorageLimitIndex,
currency,
onPayClick,
}: ProPlanContentProps) => {
const { workspace } = useWorkspace()
Expand Down Expand Up @@ -153,7 +155,8 @@ export const ProPlanContent = ({
Plan.PRO,
selectedChatsLimitIndex ?? 0,
selectedStorageLimitIndex ?? 0
) ?? NaN
) ?? NaN,
currency
)}
<chakra.span fontSize="md">/ month</chakra.span>
</Heading>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { MoreInfoTooltip } from '@/components/MoreInfoTooltip'
type StarterPlanContentProps = {
initialChatsLimitIndex?: number
initialStorageLimitIndex?: number
currency?: 'eur' | 'usd'
onPayClick: (props: {
selectedChatsLimitIndex: number
selectedStorageLimitIndex: number
Expand All @@ -38,6 +39,7 @@ type StarterPlanContentProps = {
export const StarterPlanContent = ({
initialChatsLimitIndex,
initialStorageLimitIndex,
currency,
onPayClick,
}: StarterPlanContentProps) => {
const { workspace } = useWorkspace()
Expand Down Expand Up @@ -126,7 +128,8 @@ export const StarterPlanContent = ({
Plan.STARTER,
selectedChatsLimitIndex ?? 0,
selectedStorageLimitIndex ?? 0
) ?? NaN
) ?? NaN,
currency
)}
<chakra.span fontSize="md">/ month</chakra.span>
</Heading>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const useCurrentSubscriptionInfo = ({
{
additionalChatsIndex: number
additionalStorageIndex: number
currency?: 'eur' | 'usd'
},
Error
>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type UpgradeProps = {
workspaceId: string
additionalChats: number
additionalStorage: number
currency?: 'eur' | 'usd'
}

export const upgradePlanQuery = async ({
Expand All @@ -31,6 +32,7 @@ const updatePlan = async ({
workspaceId,
additionalChats,
additionalStorage,
currency,
}: Omit<UpgradeProps, 'user'>): Promise<{ newPlan?: Plan; error?: Error }> => {
const { data, error } = await sendRequest<{ message: string }>({
method: 'PUT',
Expand All @@ -41,7 +43,7 @@ const updatePlan = async ({
stripeId,
additionalChats,
additionalStorage,
currency: guessIfUserIsEuropean() ? 'eur' : 'usd',
currency: currency ?? (guessIfUserIsEuropean() ? 'eur' : 'usd'),
},
})
if (error || !data) return { error }
Expand Down
1 change: 1 addition & 0 deletions apps/builder/src/pages/api/stripe/subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const getSubscriptionDetails =
(item) =>
item.price.id === process.env.STRIPE_ADDITIONAL_STORAGE_PRICE_ID
)?.quantity ?? 0,
currency: subscriptions.data[0]?.currency,
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/utils/pricing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ export const guessIfUserIsEuropean = () =>
: europeanUnionExclusiveLanguageCodes.includes(languageCode)
})

export const formatPrice = (price: number) => {
export const formatPrice = (price: number, currency?: 'eur' | 'usd') => {
const isEuropean = guessIfUserIsEuropean()
const formatter = new Intl.NumberFormat(isEuropean ? 'fr-FR' : 'en-US', {
style: 'currency',
currency: isEuropean ? 'EUR' : 'USD',
currency: currency?.toUpperCase() ?? (isEuropean ? 'EUR' : 'USD'),
maximumFractionDigits: 0, // (causes 2500.99 to be printed as $2,501)
})
return formatter.format(price)
Expand Down

5 comments on commit f9ffdbc

@vercel
Copy link

@vercel vercel bot commented on f9ffdbc Nov 29, 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 f9ffdbc Nov 29, 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:

viewer-v2-alpha – ./apps/viewer

bot.phuonghub.com
bot.reviewzer.com
cares.urlabout.me
fmm.wpwakanda.com
gentleman-shop.fr
k1.kandabrand.com
ov1.wpwakanda.com
sellmycarglasgow.com
talkbot.agfunnel.com
tenorioadvogados.com
uppity.wpwakanda.com
abutton.wpwakanda.com
aidigitalmarketing.kr
bbutton.wpwakanda.com
bot.incusservices.com
bot.meuesocial.com.br
bot.ramonmatos.com.br
cdd.searchcube.com.sg
chat.missarkansas.org
chatbot.ownacademy.co
sbutton.wpwakanda.com
815639944.21000000.one
aplicacao.bmind.com.br
apply.ansuraniphone.my
bbutton.wpwwakanda.com
bot.louismarcondes.com
bot.t20worldcup.com.au
c23111azqw.nigerias.io
felipewelington.com.br
form.searchcube.com.sg
gcase.barrettamario.it
help.giversforgood.com
info.clickasuransi.com
kodawariab736.skeep.it
my.swamprecordsgnv.com
premium.kandabrand.com
report.gratirabbit.com
resume.gratirabbit.com
83242573.actualizar.xyz
bot.blackboxtips.com.br
bot.upgradesolutions.eu
help.comebackreward.com
mainmenu.diddancing.com
register.kandabrand.com
signup.hypemarketing.in
subfooter.wpwakanda.com
survey.hypemarketing.in
testbot.afterorigin.com
91181264.your-access.one
ai.chromebookstoreph.com
form.sergiolimajr.com.br
hunterbot.saleshunter.ai
instant.botscientis.info
link.cascadigital.com.br
onboarding.growthside.io
reward.onlinebotdemo.xyz
type.opaulovieira.com.br
aibot.angrybranding.co.uk
bot.aidigitalmarketing.kr
bot.arraesecenteno.com.br
bot.blackboxsports.com.br
bot.cabinrentalagency.com
boyfriend-breakup.riku.ai
brigadeirosemdrama.com.br
chat.ertcrebateportal.com
chat.thisiscrushhouse.com
sellmyharleylouisiana.com
verfica.botmachine.com.br
configurator.bouclidom.com
help.atlasoutfittersk9.com
ted.meujalecobrasil.com.br
type.dericsoncalari.com.br
chatbot.berbelanjabiz.trade
designguide.techyscouts.com
presente.empresarias.com.mx
sell.sellthemotorhome.co.uk
anamnese.odontopavani.com.br
austin.channelautomation.com
bot.marketingplusmindset.com
piazzatorre.barrettamario.it
requests.swamprecordsgnv.com
type.cookieacademyonline.com
bot.brigadeirosemdrama.com.br
onboarding.libertydreamcare.ie
type.talitasouzamarques.com.br
agendamento.sergiolimajr.com.br
anamnese.clinicamegasjdr.com.br
bookings.littlepartymonkeys.com
bot.comercializadoraomicron.com
elevateyourmind.groovepages.com
yourfeedback.comebackreward.com
personal-trainer.barrettamario.it
preagendamento.sergiolimajr.com.br
studiotecnicoimmobiliaremerelli.it
download.thailandmicespecialist.com
register.thailandmicespecialist.com
viewer-v2-alpha-typebot-io.vercel.app
pesquisa.escolamodacomproposito.com.br
anamnese.clinicaramosodontologia.com.br
viewer-v2-alpha-git-main-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on f9ffdbc Nov 29, 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:

docs – ./apps/docs

docs.typebot.io
docs-git-main-typebot-io.vercel.app
docs-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on f9ffdbc Nov 29, 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 f9ffdbc Nov 29, 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

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

Please sign in to comment.