Skip to content

Commit

Permalink
馃悰 (stripe) Update additional items when they didn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Sep 27, 2022
1 parent c94a658 commit f83e0ef
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 45 deletions.
24 changes: 14 additions & 10 deletions apps/builder/components/shared/ChangePlanForm/ProPlanContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,13 @@ export const ProPlanContent = ({
size="sm"
isLoading={selectedChatsLimitIndex === undefined}
>
{parseNumberWithCommas(
chatsLimit.PRO.totalIncluded +
chatsLimit.PRO.increaseStep.amount *
(selectedChatsLimitIndex ?? 0)
)}
{selectedChatsLimitIndex !== undefined
? parseNumberWithCommas(
chatsLimit.PRO.totalIncluded +
chatsLimit.PRO.increaseStep.amount *
selectedChatsLimitIndex
)
: undefined}
</MenuButton>
<MenuList>
{selectedChatsLimitIndex !== 0 && (
Expand Down Expand Up @@ -252,11 +254,13 @@ export const ProPlanContent = ({
size="sm"
isLoading={selectedStorageLimitIndex === undefined}
>
{parseNumberWithCommas(
storageLimit.PRO.totalIncluded +
storageLimit.PRO.increaseStep.amount *
(selectedStorageLimitIndex ?? 0)
)}
{selectedStorageLimitIndex !== undefined
? parseNumberWithCommas(
storageLimit.PRO.totalIncluded +
storageLimit.PRO.increaseStep.amount *
selectedStorageLimitIndex
)
: undefined}
</MenuButton>
<MenuList>
{selectedStorageLimitIndex !== 0 && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,13 @@ export const StarterPlanContent = ({
size="sm"
isLoading={selectedChatsLimitIndex === undefined}
>
{parseNumberWithCommas(
chatsLimit.STARTER.totalIncluded +
chatsLimit.STARTER.increaseStep.amount *
(selectedChatsLimitIndex ?? 0)
)}
{selectedChatsLimitIndex !== undefined
? parseNumberWithCommas(
chatsLimit.STARTER.totalIncluded +
chatsLimit.STARTER.increaseStep.amount *
selectedChatsLimitIndex
)
: undefined}
</MenuButton>
<MenuList>
{selectedChatsLimitIndex !== 0 && (
Expand Down Expand Up @@ -206,11 +208,13 @@ export const StarterPlanContent = ({
size="sm"
isLoading={selectedStorageLimitIndex === undefined}
>
{parseNumberWithCommas(
storageLimit.STARTER.totalIncluded +
storageLimit.STARTER.increaseStep.amount *
(selectedStorageLimitIndex ?? 0)
)}
{selectedStorageLimitIndex !== undefined
? parseNumberWithCommas(
storageLimit.STARTER.totalIncluded +
storageLimit.STARTER.increaseStep.amount *
selectedStorageLimitIndex
)
: undefined}
</MenuButton>
<MenuList>
{selectedStorageLimitIndex !== 0 && (
Expand Down
16 changes: 8 additions & 8 deletions apps/builder/pages/api/stripe/subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,22 +138,22 @@ const updateSubscription = async (req: NextApiRequest) => {
: process.env.STRIPE_PRO_PRICE_ID,
quantity: 1,
},
currentAdditionalChatsItemId
? {
additionalChats === 0 && !currentAdditionalChatsItemId
? undefined
: {
id: currentAdditionalChatsItemId,
price: process.env.STRIPE_ADDITIONAL_CHATS_PRICE_ID,
quantity: additionalChats,
deleted: additionalChats === 0,
}
: undefined,
currentAdditionalStorageItemId
? {
},
additionalStorage === 0 && !currentAdditionalStorageItemId
? undefined
: {
id: currentAdditionalStorageItemId,
price: process.env.STRIPE_ADDITIONAL_STORAGE_PRICE_ID,
quantity: additionalStorage,
deleted: additionalStorage === 0,
}
: undefined,
},
].filter(isDefined)
await stripe.subscriptions.update(subscription.id, {
items,
Expand Down
32 changes: 15 additions & 17 deletions apps/builder/playwright/tests/billing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,38 +95,36 @@ test('plan changes should work', async ({ page }) => {
price: process.env.STRIPE_STARTER_PRICE_ID,
quantity: 1,
},
{
price: process.env.STRIPE_ADDITIONAL_CHATS_PRICE_ID,
quantity: 3,
},
{
price: process.env.STRIPE_ADDITIONAL_STORAGE_PRICE_ID,
quantity: 2,
},
],
{ plan: Plan.STARTER, additionalChatsIndex: 3, additionalStorageIndex: 2 }
{ plan: Plan.STARTER, additionalChatsIndex: 0, additionalStorageIndex: 0 }
)

// Update plan with additional quotas
await page.goto('/typebots')
await page.click('text=Settings & Members')
await page.click('text=Billing & Usage')
await expect(page.locator('text="/ 3,500"')).toBeVisible()
await expect(page.locator('text="/ 4 GB"')).toBeVisible()
await expect(page.locator('button >> text="3,500"')).toBeVisible()
await expect(page.locator('button >> text="4"')).toBeVisible()
await expect(page.locator('text="$73"')).toBeVisible()
await page.click('button >> text="3,500"')
await expect(page.locator('text="/ 2,000"')).toBeVisible()
await expect(page.locator('text="/ 2 GB"')).toBeVisible()
await expect(page.locator('button >> text="2,000"')).toBeVisible()
await expect(page.locator('button >> text="2"')).toBeVisible()
await page.click('button >> text="2,000"')
await page.click('button >> text="3,500"')
await page.click('button >> text="2"')
await page.click('button >> text="4"')
await page.click('button >> text="6"')
await expect(page.locator('text="$47"')).toBeVisible()
await expect(page.locator('text="$73"')).toBeVisible()
await page.click('button >> text=Update')
await expect(
page.locator(
'text="Workspace STARTER plan successfully updated 馃帀" >> nth=0'
)
).toBeVisible()
await page.click('text="Members"')
await page.click('text="Billing & Usage"')
await expect(page.locator('text="$73"')).toBeVisible()
await expect(page.locator('text="/ 3,500"')).toBeVisible()
await expect(page.locator('text="/ 4 GB"')).toBeVisible()
await expect(page.locator('button >> text="3,500"')).toBeVisible()
await expect(page.locator('button >> text="4"')).toBeVisible()

// Upgrade to PRO
await page.click('button >> text="10,000"')
Expand Down

0 comments on commit f83e0ef

Please sign in to comment.