Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions src/components/app/routes/loaders/checkoutStepperLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getAuthenticatedUser } from '@edx/frontend-platform/auth';
import { QueryClient } from '@tanstack/react-query';
import { redirect } from 'react-router-dom';

import { queryBffContext } from '@/components/app/data/queries/queries';
import { queryBffContext, queryBffSuccess, queryCheckoutIntent } from '@/components/app/data/queries/queries';
import { getCheckoutSessionClientSecret, validateFormState } from '@/components/app/routes/loaders/utils';
import { CheckoutPageRoute } from '@/constants/checkout';
import { checkoutFormStore } from '@/hooks/useCheckoutFormStore';
Expand Down Expand Up @@ -144,12 +144,31 @@ async function billingDetailsSuccessLoader(queryClient: QueryClient): Promise<Re
const contextMetadata: CheckoutContextResponse = await queryClient.ensureQueryData(
queryBffContext(authenticatedUser?.userId || null),
);

const { checkoutIntent } = contextMetadata;

const checkoutIntentType = checkoutFormStore.getState().checkoutSessionStatus?.type;
if (!checkoutIntent) {
return redirect(CheckoutPageRoute.PlanDetails);
}

await queryClient.ensureQueryData(
queryBffSuccess(authenticatedUser?.userId || null),
);
if (checkoutIntent.id) {
await queryClient.ensureQueryData(
queryCheckoutIntent(checkoutIntent.id),
);
}

const stripeCheckoutSessionType = checkoutFormStore.getState().checkoutSessionStatus?.type;

if (checkoutIntentType !== 'complete' && !checkoutIntent?.existingSuccessfulCheckoutIntent) {
// Explicitly check that the intent is in a successful state
// If the intent is successful but the type is not 'complete',
// or if there is no existingSuccessfulCheckoutIntent flag,
// redirect to Plan Details to restart the process.
if (
!checkoutIntent.existingSuccessfulCheckoutIntent
|| stripeCheckoutSessionType !== 'complete'
) {
Comment thread
brobro10000 marked this conversation as resolved.
return redirect(CheckoutPageRoute.PlanDetails);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ describe('PlanDetailsPage - Admin Email Validation', () => {
// Fill in required form fields using proper user interaction
const fullNameInput = screen.getByLabelText(/full name/i);
const adminEmailInput = screen.getByLabelText(/work email/i);
const quantityInput = screen.getByLabelText(/how many users/i);
const quantityInput = screen.getByLabelText(/number of licenses/i);
const countrySelect = screen.getByLabelText(/country of residence/i);

await user.type(fullNameInput, 'John Doe');
Expand Down Expand Up @@ -222,7 +222,7 @@ describe('PlanDetailsPage - Admin Email Validation', () => {
// Fill in required form fields using proper user interaction
const fullNameInput = screen.getByLabelText(/full name/i);
const adminEmailInput = screen.getByLabelText(/work email/i);
const quantityInput = screen.getByLabelText(/how many users/i);
const quantityInput = screen.getByLabelText(/number of licenses/i);
const countrySelect = screen.getByLabelText(/country of residence/i);

await user.type(fullNameInput, 'John Doe');
Expand Down Expand Up @@ -271,7 +271,7 @@ describe('PlanDetailsPage - Admin Email Validation', () => {
// Fill in required form fields using proper user interaction
const fullNameInput = screen.getByLabelText(/full name/i);
const adminEmailInput = screen.getByLabelText(/work email/i);
const quantityInput = screen.getByLabelText(/how many users/i);
const quantityInput = screen.getByLabelText(/number of licenses/i);
const countrySelect = screen.getByLabelText(/country of residence/i);

await user.type(fullNameInput, 'John Doe');
Expand Down