From 35bb5d18cdfe1d6a8317d1955a204f710c429a8a Mon Sep 17 00:00:00 2001 From: Jessica McInchak Date: Tue, 12 Dec 2023 15:07:21 +0000 Subject: [PATCH] feat: add basic metadata to GOV.UK Pay requests (#2556) --- api.planx.uk/modules/pay/index.test.ts | 5 +++++ api.planx.uk/modules/pay/middleware.ts | 12 ++++++++++++ editor.planx.uk/src/@planx/components/Pay/model.ts | 11 ++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/api.planx.uk/modules/pay/index.test.ts b/api.planx.uk/modules/pay/index.test.ts index ab4a129d37..4f7b5a0e01 100644 --- a/api.planx.uk/modules/pay/index.test.ts +++ b/api.planx.uk/modules/pay/index.test.ts @@ -53,6 +53,11 @@ describe("sending a payment to GOV.UK Pay", () => { reference: "12343543", description: "New application", return_url: "https://editor.planx.uk", + metadata: { + source: "PlanX", + flow: "apply-for-a-lawful-development-certificate", + inviteToPay: false, + }, }) .expect(200) .then((res) => { diff --git a/api.planx.uk/modules/pay/middleware.ts b/api.planx.uk/modules/pay/middleware.ts index f0a205899a..8bd6ad50b6 100644 --- a/api.planx.uk/modules/pay/middleware.ts +++ b/api.planx.uk/modules/pay/middleware.ts @@ -90,6 +90,11 @@ interface GovPayCreatePayment { reference: string; description: string; return_url: string; + metadata?: { + source: "PlanX"; + flow: string; + inviteToPay: boolean; + }; } export async function buildPaymentPayload( @@ -120,6 +125,13 @@ export async function buildPaymentPayload( reference: req.query.sessionId as string, description: "New application (nominated payee)", return_url: req.query.returnURL as string, + metadata: { + source: "PlanX", + flow: + new URL(req.query.returnURL as string).pathname.split("/")[0] || + (req.query.returnURL as string), + inviteToPay: true, + }, }; req.body = createPaymentBody; diff --git a/editor.planx.uk/src/@planx/components/Pay/model.ts b/editor.planx.uk/src/@planx/components/Pay/model.ts index 9d0fe202d3..983f6a21d8 100644 --- a/editor.planx.uk/src/@planx/components/Pay/model.ts +++ b/editor.planx.uk/src/@planx/components/Pay/model.ts @@ -40,7 +40,11 @@ export interface GovUKCreatePaymentPayload { }; }; language?: string; - metadata?: any; + metadata?: { + source: "PlanX"; + flow: string; + inviteToPay: boolean; + }; } export const toPence = (decimal: number) => Math.trunc(decimal * 100); @@ -63,6 +67,11 @@ export const createPayload = ( reference, description: "New application", return_url: getReturnURL(reference), + metadata: { + source: "PlanX", + flow: useStore.getState().flowSlug, + inviteToPay: false, + }, }); /**