Skip to content

Commit

Permalink
feat: add basic metadata to GOV.UK Pay requests (#2556)
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicamcinchak authored Dec 12, 2023
1 parent 0314b68 commit 35bb5d1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
5 changes: 5 additions & 0 deletions api.planx.uk/modules/pay/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
12 changes: 12 additions & 0 deletions api.planx.uk/modules/pay/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ interface GovPayCreatePayment {
reference: string;
description: string;
return_url: string;
metadata?: {
source: "PlanX";
flow: string;
inviteToPay: boolean;
};
}

export async function buildPaymentPayload(
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 10 additions & 1 deletion editor.planx.uk/src/@planx/components/Pay/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -63,6 +67,11 @@ export const createPayload = (
reference,
description: "New application",
return_url: getReturnURL(reference),
metadata: {
source: "PlanX",
flow: useStore.getState().flowSlug,
inviteToPay: false,
},
});

/**
Expand Down

0 comments on commit 35bb5d1

Please sign in to comment.