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

fix: Set up defaults for non-updated Pay components #2922

Merged
merged 1 commit into from
Mar 26, 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
17 changes: 16 additions & 1 deletion api.planx.uk/modules/pay/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,27 @@ export async function buildPaymentPayload(
]),
);

const defaultGovPayMetadata = {
source: "PlanX",
// Payment requests have /pay path suffix, so get flow-slug from second-to-last position
flow:
(req.query.returnURL as string)
.split("?")?.[0]
?.split("/")
?.slice(-2, -1)?.[0] || "Could not parse service name",
inviteToPay: true,
};

const metadata = govPayMetadata.length
? govPayMetadata
: defaultGovPayMetadata;

const createPaymentBody: GovPayCreatePayment = {
amount: parseInt(req.params.paymentAmount),
reference: req.query.sessionId as string,
description: "New application (nominated payee)",
return_url: req.query.returnURL as string,
metadata: govPayMetadata,
metadata,
};

req.body = createPaymentBody;
Expand Down
12 changes: 11 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 @@ -56,6 +56,7 @@ function Component(props: Props) {
passport,
environment,
teamSlug,
flowSlug,
] = useStore((state) => [
state.id,
state.sessionId,
Expand All @@ -65,8 +66,17 @@ function Component(props: Props) {
state.computePassport(),
state.previewEnvironment,
state.teamSlug,
state.flowSlug,
]);
const fee = props.fn ? Number(passport.data?.[props.fn]) : 0;
const defaultMetadata = [
{ key: "source", value: "PlanX" },
{ key: "flow", value: flowSlug },
{ key: "isInviteToPay", value: false },
];
const metadata = props.govPayMetadata.length
? props.govPayMetadata
: defaultMetadata;

// Handles UI states
const reducer = (_state: ComponentState, action: Action): ComponentState => {
Expand Down Expand Up @@ -236,7 +246,7 @@ function Component(props: Props) {
await axios
.post(
getGovUkPayUrlForTeam({ sessionId, flowId, teamSlug }),
createPayload(fee, sessionId, props.govPayMetadata),
createPayload(fee, sessionId, metadata),
)
.then(async (res) => {
const payment = await resolvePaymentResponse(res.data);
Expand Down
Loading