2
0

🐛 (billing) Fix currency possible mismatch on sub update

This commit is contained in:
Baptiste Arnaud
2022-11-29 13:17:46 +01:00
parent 43a85b5529
commit f9ffdbc4c5
7 changed files with 18 additions and 5 deletions

View File

@ -15,6 +15,7 @@ type UpgradeProps = {
workspaceId: string
additionalChats: number
additionalStorage: number
currency?: 'eur' | 'usd'
}
export const upgradePlanQuery = async ({
@ -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',
@ -41,7 +43,7 @@ const updatePlan = async ({
stripeId,
additionalChats,
additionalStorage,
currency: guessIfUserIsEuropean() ? 'eur' : 'usd',
currency: currency ?? (guessIfUserIsEuropean() ? 'eur' : 'usd'),
},
})
if (error || !data) return { error }