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: Send metadata to GovPay #2911

Merged
merged 9 commits into from
Mar 25, 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
34 changes: 17 additions & 17 deletions api.planx.uk/modules/pay/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { NextFunction, Request, RequestHandler, Response } from "express";
import { gql } from "graphql-request";
import { $api } from "../../client";
import { ServerError } from "../../errors";
import { GovPayMetadata } from "./types";

/**
* Confirm that this local authority (aka team) has a pay token
Expand Down Expand Up @@ -32,6 +33,7 @@ interface GetPaymentRequestDetails {
paymentRequest: {
sessionId: string;
paymentAmount: number;
govPayMetadata: GovPayMetadata[];
session: {
flowId: string;
flow: {
Expand All @@ -45,14 +47,15 @@ interface GetPaymentRequestDetails {

export async function fetchPaymentRequestDetails(
req: Request,
_res: Response,
res: Response,
next: NextFunction,
) {
const query = gql`
query GetPaymentRequestDetails($paymentRequestId: uuid!) {
paymentRequest: payment_requests_by_pk(id: $paymentRequestId) {
sessionId: session_id
paymentAmount: payment_amount
govPayMetadata: govpay_metadata
session {
flowId: flow_id
flow {
Expand Down Expand Up @@ -88,6 +91,8 @@ export async function fetchPaymentRequestDetails(
const paymentAmount = paymentRequest.paymentAmount.toString();
if (paymentAmount) req.params.paymentAmount = paymentAmount;

res.locals.govPayMetadata = paymentRequest.govPayMetadata;

next();
}

Expand All @@ -97,16 +102,12 @@ interface GovPayCreatePayment {
reference: string;
description: string;
return_url: string;
metadata?: {
source: "PlanX";
flow: string;
inviteToPay: boolean;
};
metadata: Record<string, string | boolean>;
}

export async function buildPaymentPayload(
req: Request,
_res: Response,
res: Response,
next: NextFunction,
) {
if (!req.query.returnURL) {
Expand All @@ -127,21 +128,20 @@ export async function buildPaymentPayload(
);
}

// Convert metadata to format required by GovPay
const govPayMetadata = Object.fromEntries(
res.locals.govPayMetadata.map(({ key, value }: GovPayMetadata) => [
key,
value,
]),
);

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: {
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,
},
metadata: govPayMetadata,
};

req.body = createPaymentBody;
Expand Down
5 changes: 5 additions & 0 deletions api.planx.uk/modules/pay/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,8 @@ export type PaymentRequestProxyController = ValidatedRequestHandler<
typeof paymentRequestProxySchema,
Buffer
>;

export interface GovPayMetadata {
key: string;
value: string | boolean;
}
2 changes: 1 addition & 1 deletion api.planx.uk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"dependencies": {
"@airbrake/node": "^2.1.8",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#eda1e67",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#10f239a",
"@types/isomorphic-fetch": "^0.0.36",
"adm-zip": "^0.5.10",
"aws-sdk": "^2.1467.0",
Expand Down
14 changes: 7 additions & 7 deletions api.planx.uk/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/api-driven/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"dependencies": {
"@cucumber/cucumber": "^9.3.0",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#eda1e67",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#10f239a",
"axios": "^1.6.8",
"dotenv": "^16.3.1",
"dotenv-expand": "^10.0.0",
Expand Down
14 changes: 7 additions & 7 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.

16 changes: 15 additions & 1 deletion e2e/tests/api-driven/src/invite-to-pay/mocks/flow.json
Original file line number Diff line number Diff line change
Expand Up @@ -63279,7 +63279,21 @@
"yourDetailsTitle": "Your details",
"instructionsTitle": "How to pay",
"secondaryPageTitle": "Invite someone else to pay for this application",
"instructionsDescription": "<p>You can pay for your application by using GOV.UK Pay.</p> <p>Your application will be sent after you have paid the fee. Wait until you see an application sent message before closing your browser.</p>"
"instructionsDescription": "<p>You can pay for your application by using GOV.UK Pay.</p> <p>Your application will be sent after you have paid the fee. Wait until you see an application sent message before closing your browser.</p>",
"govPayMetadata": [
{
"key": "flow",
"value": "flow-name"
},
{
"key": "source",
"value": "PlanX"
},
{
"key": "isInviteToPay",
"value": true
}
]
},
"type": 400
},
Expand Down
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#eda1e67",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#10f239a",
"axios": "^1.6.8",
"dotenv": "^16.3.1",
"eslint": "^8.56.0",
Expand Down
14 changes: 7 additions & 7 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.

2 changes: 1 addition & 1 deletion editor.planx.uk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@mui/styles": "^5.15.2",
"@mui/utils": "^5.15.2",
"@opensystemslab/map": "^0.8.0",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#eda1e67",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#10f239a",
"@tiptap/core": "^2.0.3",
"@tiptap/extension-bold": "^2.0.3",
"@tiptap/extension-bubble-menu": "^2.1.13",
Expand Down
41 changes: 9 additions & 32 deletions editor.planx.uk/pnpm-lock.yaml

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

Loading
Loading