Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(fee-breakdown): Display for "invite to pay" journeys #4057

Merged
merged 7 commits into from
Dec 10, 2024
Merged
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
2 changes: 1 addition & 1 deletion api.planx.uk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@airbrake/node": "^2.1.8",
"@aws-sdk/client-s3": "^3.696.0",
"@aws-sdk/s3-request-presigner": "^3.701.0",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#29b4851",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#6c6f308",
"@types/isomorphic-fetch": "^0.0.36",
"adm-zip": "^0.5.10",
"axios": "^1.7.4",
Expand Down
8 changes: 4 additions & 4 deletions api.planx.uk/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions api.planx.uk/tests/mocks/inviteToPayData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ export const paymentRequestResponse: Partial<PaymentRequest> = {
payeeEmail: payee.email,
paymentAmount: paymentAmountPence,
sessionPreviewData: sessionPreviewData,
feeBreakdown: {
amount: {
payable: 123.45,
calculated: 123.45,
vat: 0,
reduction: 0,
},
reductions: [],
exemptions: [],
},
};

export const validPaymentRequest = {
Expand Down
10 changes: 10 additions & 0 deletions api.planx.uk/tests/mocks/inviteToPayMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ export const createPaymentRequestQueryMock = {
{ key: "paidViaInviteToPay", value: true },
{ key: "flow", value: validSession.flow.slug },
],
feeBreakdown: {
amount: {
payable: 123.45,
calculated: 123.45,
vat: 0,
reduction: 0,
},
reductions: [],
exemptions: [],
},
},
};

Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/api-driven/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"packageManager": "[email protected]",
"dependencies": {
"@cucumber/cucumber": "^9.3.0",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#29b4851",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#6c6f308",
"axios": "^1.7.4",
"dotenv": "^16.3.1",
"dotenv-expand": "^10.0.0",
Expand Down
8 changes: 4 additions & 4 deletions e2e/tests/api-driven/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion e2e/tests/ui-driven/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"postinstall": "./install-dependencies.sh"
},
"dependencies": {
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#29b4851",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#6c6f308",
"axios": "^1.7.4",
"dotenv": "^16.3.1",
"eslint": "^8.56.0",
Expand Down
8 changes: 4 additions & 4 deletions e2e/tests/ui-driven/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions e2e/tests/ui-driven/src/invite-to-pay/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export async function getPaymentRequestBySessionId({
paymentAmount: payment_amount
applicantName: applicant_name
paidAt: paid_at
feeBreakdown: fee_breakdown
}
}
`,
Expand Down
10 changes: 10 additions & 0 deletions e2e/tests/ui-driven/src/invite-to-pay/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ export const mockPaymentRequest: Partial<PaymentRequest> = {
},
paymentAmount: 12345,
applicantName: "Mr Agent (Agency Ltd)",
feeBreakdown: {
amount: {
calculated: 123.45,
payable: 123.45,
vat: 0,
reduction: 0,
},
reductions: [],
exemptions: [],
},
};

export const mockSessionData: Omit<SessionData, "id"> = {
Expand Down
2 changes: 2 additions & 0 deletions e2e/tests/ui-driven/src/invite-to-pay/nominee.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
"Add a verandah or deck and changes to internal walls or layout";
await expect(page.getByText(formattedProjectType)).toBeVisible();

await expect(page.getByText("Fee breakdown")).toBeVisible();

const payButton = page.getByRole("button", {
name: "Pay using GOV.UK Pay",
});
Expand All @@ -86,7 +88,7 @@
context.flow?.slug
}/pay?analytics=false&paymentRequestId=INVALID-ID`;
await page.goto(invalidPaymentRequestURL);
await page.waitForLoadState("networkidle");

Check warning on line 91 in e2e/tests/ui-driven/src/invite-to-pay/nominee.spec.ts

View workflow job for this annotation

GitHub Actions / E2E tests

Unexpected use of networkidle

await expect(page.getByText(PAYMENT_NOT_FOUND_TEXT)).toBeVisible();
});
Expand All @@ -94,7 +96,7 @@
test("navigating to a URL without a paymentRequestId", async ({ page }) => {
const invalidPaymentRequestURL = `/${context.team!.slug!}/${context.flow?.slug}/pay?analytics=false`;
await page.goto(invalidPaymentRequestURL);
await page.waitForLoadState("networkidle");

Check warning on line 99 in e2e/tests/ui-driven/src/invite-to-pay/nominee.spec.ts

View workflow job for this annotation

GitHub Actions / E2E tests

Unexpected use of networkidle

await expect(page.getByText(PAYMENT_NOT_FOUND_TEXT)).toBeVisible();
});
Expand Down Expand Up @@ -128,7 +130,7 @@
) {
const paymentRequestURL = `/${context.team!.slug!}/${context.flow?.slug}/pay?analytics=false&paymentRequestId=${paymentRequest.id}`;
await page.goto(paymentRequestURL);
await page.waitForLoadState("networkidle");

Check warning on line 133 in e2e/tests/ui-driven/src/invite-to-pay/nominee.spec.ts

View workflow job for this annotation

GitHub Actions / E2E tests

Unexpected use of networkidle
}

async function setupPaymentRequest(
Expand Down
2 changes: 1 addition & 1 deletion editor.planx.uk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@mui/material": "^5.15.10",
"@mui/utils": "^5.15.11",
"@opensystemslab/map": "1.0.0-alpha.4",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#29b4851",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#6c6f308",
"@tiptap/core": "^2.4.0",
"@tiptap/extension-bold": "^2.0.3",
"@tiptap/extension-bubble-menu": "^2.1.13",
Expand Down
10 changes: 5 additions & 5 deletions editor.planx.uk/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import TableContainer from "@mui/material/TableContainer";
import TableHead from "@mui/material/TableHead";
import TableRow from "@mui/material/TableRow";
import Typography from "@mui/material/Typography";
import type { FeeBreakdown as IFeeBreakdown } from "@opensystemslab/planx-core/types";
import React from "react";
import { FONT_WEIGHT_SEMI_BOLD } from "theme";

Expand Down Expand Up @@ -122,16 +123,17 @@ const Total: React.FC<{ amount: number }> = ({ amount }) => (
</BoldTableRow>
);

export const FeeBreakdown: React.FC = () => {
const breakdown = useFeeBreakdown();
export const FeeBreakdown: React.FC<{ inviteToPayFeeBreakdown?: IFeeBreakdown }> = ({ inviteToPayFeeBreakdown }) => {
const passportFeeBreakdown = useFeeBreakdown();
const breakdown = passportFeeBreakdown || inviteToPayFeeBreakdown;
if (!breakdown) return null;

const { amount, reductions, exemptions } = breakdown;

return (
<Box mt={3}>
<Typography variant="h3" mb={1}>
Fee breakdown
Fee
</Typography>
<Typography variant="body1" mb={2}>
{DESCRIPTION}
Expand Down
55 changes: 33 additions & 22 deletions editor.planx.uk/src/pages/Pay/MakePayment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import {
type PaymentRequest,
PaymentStatus,
} from "@opensystemslab/planx-core/types";
import { FeeBreakdown } from "@planx/components/Pay/Public/FeeBreakdown/FeeBreakdown";
import axios from "axios";
import { format } from "date-fns";
import { hasFeatureFlag } from "lib/featureFlags";
import { getExpiryDateForPaymentRequest } from "lib/pay";
import { useStore } from "pages/FlowEditor/lib/store";
import React, { useEffect, useState } from "react";
Expand Down Expand Up @@ -63,6 +65,7 @@ export default function MakePayment({
govPayPaymentId,
paymentAmount,
paidAt,
feeBreakdown,
}: PaymentRequest) {
const { address, rawProjectTypes } =
parseSessionPreviewData(sessionPreviewData);
Expand Down Expand Up @@ -170,14 +173,10 @@ export default function MakePayment({
</Container>
);

const PaymentDetails = () => {
const PaymentDetails: React.FC<{ hasFeeBreakdown: boolean}> = ({ hasFeeBreakdown }) => {
const projectType = formatRawProjectTypes(rawProjectTypes);
const data = [
{ term: "Application type", details: flowName },
{
term: "Fee",
details: formattedPriceWithCurrencySymbol(toDecimal(paymentAmount)),
},
{
term: "Property address",
details: address,
Expand All @@ -188,6 +187,13 @@ export default function MakePayment({
},
];

if (!hasFeeBreakdown) {
data.splice(1, 0, {
term: "Fee",
details: formattedPriceWithCurrencySymbol(toDecimal(paymentAmount))
});
};

// Handle payments completed before page load
if (paidAt) {
data.push({
Expand Down Expand Up @@ -220,19 +226,26 @@ export default function MakePayment({
) : (
<>
<Header />
<PaymentDetails />
<PaymentDetails hasFeeBreakdown={Boolean(feeBreakdown)}/>
{(currentState === States.Ready ||
currentState === States.Reset ||
currentState === States.ReadyToRetry) &&
!isLoading && (
<Confirm
fee={toDecimal(paymentAmount)}
onConfirm={readyAction}
buttonTitle={currentState.button!}
showInviteToPay={false}
hideFeeBanner={true}
paymentStatus={payment?.state.status}
/>
<>
{hasFeatureFlag("FEE_BREAKDOWN") && (
<Container maxWidth="contentWrap" sx={{ mt: 6, pb: 0 }}>
<FeeBreakdown inviteToPayFeeBreakdown={feeBreakdown} />
</Container>
)}
<Confirm
fee={toDecimal(paymentAmount)}
onConfirm={readyAction}
buttonTitle={currentState.button!}
showInviteToPay={false}
hideFeeBanner={true}
paymentStatus={payment?.state.status}
/>
</>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think this should be feature-flagged ? I can see a breakdown here with & without feature flag: https://4057.planx.pizza/barnet/invite-to-pay-test/pay?paymentRequestId=f0babfb3-4a57-4c01-bdc2-cd344bac865c

Also, minor style nitpick: should we remove "Fee" line from top table, and then simply call bottom part "Fee" instead of "Fee breakdown" ?
Screenshot from 2024-12-09 16-46-37

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, do we need to account for any active invitations that won't have saved breakdown details when this merges? Will the breakdown simply not display/be hidden?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep - feature flag should be here thanks!

Changed from "Fee breakdown" to "Fee".

This will just not show at all if there's no fee breakdown, so we should be ok for that transition period 👍

I'd love a pass over this page by Ian at some point also - the two tables, one horizontal and one vertical just feel a bit weird back to back here.

)}
</>
);
Expand All @@ -247,9 +260,8 @@ async function fetchPayment({
govPayPaymentId?: string;
}): Promise<GovUKPayment | null> {
if (!govPayPaymentId) return Promise.resolve(null);
const paymentURL = `${
import.meta.env.VITE_APP_API_URL
}/payment-request/${paymentRequestId}/payment/${govPayPaymentId}`;
const paymentURL = `${import.meta.env.VITE_APP_API_URL
}/payment-request/${paymentRequestId}/payment/${govPayPaymentId}`;
const response = await axios.get<GovUKPayment>(paymentURL);
return response.data;
}
Expand All @@ -258,11 +270,10 @@ async function fetchPayment({
async function startNewPayment(
paymentRequestId: string,
): Promise<GovUKPayment> {
const paymentURL = `${
import.meta.env.VITE_APP_API_URL
}/payment-request/${paymentRequestId}/pay?returnURL=${encodeURIComponent(
window.location.href,
)}`;
const paymentURL = `${import.meta.env.VITE_APP_API_URL
}/payment-request/${paymentRequestId}/pay?returnURL=${encodeURIComponent(
window.location.href,
)}`;
const response = await axios.post<GovUKPayment>(paymentURL);
return response.data;
}
Expand Down
1 change: 1 addition & 0 deletions editor.planx.uk/src/routes/pay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ const fetchPaymentRequest = async (paymentRequestId: string) => {
) {
id
sessionPreviewData: session_preview_data
feeBreakdown: fee_breakdown
createdAt: created_at
paymentAmount: payment_amount
govPayPaymentId: govpay_payment_id
Expand Down
4 changes: 4 additions & 0 deletions hasura.planx.uk/metadata/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,7 @@
columns:
- applicant_name
- created_at
- fee_breakdown
- govpay_metadata
- govpay_payment_id
- id
Expand All @@ -1250,6 +1251,7 @@
columns:
- applicant_name
- created_at
- fee_breakdown
- govpay_metadata
- govpay_payment_id
- id
Expand All @@ -1265,6 +1267,7 @@
columns:
- applicant_name
- created_at
- fee_breakdown
- govpay_payment_id
- id
- paid_at
Expand All @@ -1279,6 +1282,7 @@
columns:
- applicant_name
- created_at
- fee_breakdown
- govpay_metadata
- govpay_payment_id
- id
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE "public"."payment_requests"
DROP COLUMN "fee_breakdown";
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "public"."payment_requests" add column "fee_breakdown" jsonb
null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Loading