Skip to content

Commit

Permalink
unsupported_team state needs to account for recently changed API mess…
Browse files Browse the repository at this point in the history
…ages
  • Loading branch information
jessicamcinchak committed Oct 6, 2023
1 parent 7f6e2ab commit dab5692
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion editor.planx.uk/src/@planx/components/Pay/Public/Confirm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import ReactMarkdownOrHtml from "ui/ReactMarkdownOrHtml";

import { formattedPriceWithCurrencySymbol } from "../model";
import InviteToPayForm, { InviteToPayFormProps } from "./InviteToPayForm";
import { PAY_API_ERROR_UNSUPPORTED_TEAM } from "./Pay";

export interface Props {
title?: string;
Expand Down Expand Up @@ -62,7 +63,7 @@ const PayBody: React.FC<PayBodyProps> = (props) => {
const isSaveReturn = path === ApplicationPath.SaveAndReturn;

if (props.error) {
if (props.error.endsWith("local authority")) {
if (props.error.startsWith(PAY_API_ERROR_UNSUPPORTED_TEAM)) {
return (
<Card handleSubmit={props.onConfirm} isValid>
<ErrorSummary role="status" data-testid="error-summary">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ describe("Confirm component without inviteToPay", () => {

it("displays an error and continue-with-testing button if Pay is not enabled for this team", async () => {
const handleSubmit = jest.fn();
const errorMessage = "No pay token found for this local authority";
const errorMessage =
"GOV.UK Pay is not enabled for this local authority (testing)";

const { user } = setup(
<Confirm
Expand Down
9 changes: 8 additions & 1 deletion editor.planx.uk/src/@planx/components/Pay/Public/Pay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ enum Action {
Success,
}

export const PAY_API_ERROR_UNSUPPORTED_TEAM =
"GOV.UK Pay is not enabled for this local authority";

function Component(props: Props) {
const [
flowId,
Expand Down Expand Up @@ -242,7 +245,11 @@ function Component(props: Props) {
window.location.replace(payment._links.next_url.href);
})
.catch((error) => {
if (error.response?.data?.error?.endsWith("local authority")) {
if (
error.response?.data?.error?.startsWith(
PAY_API_ERROR_UNSUPPORTED_TEAM,
)
) {
// Show a custom message if this team isn't set up to use Pay yet
dispatch(Action.StartNewPaymentError);
} else {
Expand Down

0 comments on commit dab5692

Please sign in to comment.