Skip to content
Open
Changes from 1 commit
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
Loading