Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: send active education subscriptions directly to Team checkout (#43659)

Joeld96b261dca0f
diff --git a/web/__tests__/billing/cloud-plan-payment-flow.test.tsx b/web/__tests__/billing/cloud-plan-payment-flow.test.tsx
index 66b2e54465f..c87c3975d62 100644
--- a/web/__tests__/billing/cloud-plan-payment-flow.test.tsx
+++ b/web/__tests__/billing/cloud-plan-payment-flow.test.tsx
@@ -91,7 +91,7 @@ const renderCloudPlanItem = ({
<CloudPlanItem
plan={plan}
billingInterval={billingInterval}
- billing={{ currentPlan, isEducationDiscountEligible }}
+ billing={{ currentPlan, isEducationDiscountEligible, isEducationDiscountActivated: false }}
/>
</>,
{ wrapper },
diff --git a/web/app/components/billing/pricing/__tests__/content.spec.tsx b/web/app/components/billing/pricing/__tests__/content.spec.tsx
index afeda57b628..f1928bf60dd 100644
--- a/web/app/components/billing/pricing/__tests__/content.spec.tsx
+++ b/web/app/components/billing/pricing/__tests__/content.spec.tsx
@@ -6,6 +6,7 @@ import { consoleQuery } from '@/service/console'
import {
createConsoleQueryClient,
createConsoleQueryWrapper,
+ seedEducationStatus,
seedFeatures,
} from '@/test/console/query-data'
import { render } from '@/test/console/render'
@@ -160,6 +161,58 @@ it('shows yearly pricing immediately for a cached eligible education account', (
expect(screen.queryByRole('status')).not.toBeInTheDocument()
})
+it.each(['year', 'month'] as const)(
+ 'takes an active education subscription directly to Team checkout with %s billing',
+ async (interval) => {
+ const user = userEvent.setup()
+ const { queryClient, show } = setup()
+ seedFeatures(queryClient, {
+ billing: { subscription: { plan: 'professional', interval: 'year' } },
+ education: { enabled: true, activated: true },
+ })
+ seedEducationStatus(queryClient, { is_student: true })
+ const checkoutUrl = 'https://billing.example.com/team-checkout'
+ const checkout = vi.spyOn(globalThis, 'fetch').mockResolvedValue(
+ new Response(JSON.stringify({ url: checkoutUrl }), {
+ headers: { 'Content-Type': 'application/json' },
+ }),
+ )
+ const navigate = vi.spyOn(window.location, 'href', 'set').mockImplementation(() => {})
+ show()
+ if (interval === 'month') await user.click(screen.getByRole('switch'))
+
+ await user.click(screen.getByRole('button', { name: 'billing.plansCommon.getStarted' }))
+
+ await waitFor(() => expect(navigate).toHaveBeenCalledWith(checkoutUrl))
+ expect(checkout).toHaveBeenCalledTimes(1)
+ const requestUrl = new URL((checkout.mock.calls[0]?.[0] as Request).url)
+ expect(requestUrl.pathname).toBe('/console/api/billing/subscription')
+ expect(requestUrl.searchParams.get('plan')).toBe('team')
+ expect(requestUrl.searchParams.get('interval')).toBe(interval)
+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument()
+ },
+)
+
+it('offers education pricing before Team checkout when the discount has not been activated', async () => {
+ const user = userEvent.setup()
+ const { queryClient, show } = setup()
+ seedFeatures(queryClient, { education: { enabled: true, activated: false } })
+ seedEducationStatus(queryClient, { is_student: true })
+ const checkout = vi.spyOn(globalThis, 'fetch').mockResolvedValue(
+ new Response(JSON.stringify({ url: 'https://billing.example.com/team-checkout' }), {
+ headers: { 'Content-Type': 'application/json' },
+ }),
+ )
+ show()
+
+ await user.click(screen.getByRole('button', { name: 'billing.plansCommon.getStarted' }))
+
+ expect(
+ await screen.findByRole('dialog', { name: 'education.educationPricingConfirm.title' }),
+ ).toBeVisible()
+ expect(checkout).not.toHaveBeenCalled()
+})
+
it('keeps plan information visible after a request failure and restores billing on retry', async () => {
const user = userEvent.setup()
const { queryClient, show } = setup()
diff --git a/web/app/components/billing/pricing/content.tsx b/web/app/components/billing/pricing/content.tsx
index a1aedaaacc6..d18fe8f8ac4 100644
--- a/web/app/components/billing/pricing/content.tsx
+++ b/web/app/components/billing/pricing/content.tsx
@@ -49,6 +49,7 @@ export function PricingContent() {
? {
currentPlan: currentCloudPlan,
isEducationDiscountEligible,
+ isEducationDiscountActivated: features.education.activated,
}
: undefined
diff --git a/web/app/components/billing/pricing/plans/cloud-plan-item/index.tsx b/web/app/components/billing/pricing/plans/cloud-plan-item/index.tsx
index 3a00e6ead50..8a6097661b2 100644
--- a/web/app/components/billing/pricing/plans/cloud-plan-item/index.tsx
+++ b/web/app/components/billing/pricing/plans/cloud-plan-item/index.tsx
@@ -37,6 +37,7 @@ type CloudPlanItemProps = {
| {
currentPlan: CloudPlan
isEducationDiscountEligible: boolean | undefined
+ isEducationDiscountActivated: boolean
}
| undefined
}
@@ -135,7 +136,7 @@ export function CloudPlanItem({ plan, billingInterval, billing }: CloudPlanItemP
}
}
const handlePlanButtonClick = async () => {
- if (educationDiscountWarningText && !isPlanDisabled) {
+ if (educationDiscountWarningText && !billing?.isEducationDiscountActivated && !isPlanDisabled) {
setShowEducationPricingConfirm(true)
return
}