From b0dbe80b5bb2df61a2af2009cbf7f1c8780c31ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Mon, 6 Nov 2023 09:28:02 +0000 Subject: [PATCH] fix: Correctly parse amount as number (#2378) --- api.planx.uk/inviteToPay/paymentRequest.ts | 31 ++++++++++++++++++---- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/api.planx.uk/inviteToPay/paymentRequest.ts b/api.planx.uk/inviteToPay/paymentRequest.ts index 39d6321afa..e6a82a34b4 100644 --- a/api.planx.uk/inviteToPay/paymentRequest.ts +++ b/api.planx.uk/inviteToPay/paymentRequest.ts @@ -8,6 +8,14 @@ import { import { GovUKPayment } from "@opensystemslab/planx-core/types"; import { $api } from "../client"; +// https://docs.payments.service.gov.uk/api_reference/create_a_payment_reference/#json-body-parameters-for-39-create-a-payment-39 +interface GovPayCreatePayment { + amount: number; + reference: string; + description: string; + return_url: string; +} + interface GetPaymentRequestDetails { paymentRequest: { sessionId: string; @@ -83,17 +91,30 @@ export async function buildPaymentPayload( if (!req.query.returnURL) { return next( new ServerError({ - message: "missing required returnURL query param", + message: "Missing required returnURL query param", + status: 400, + }), + ); + } + + if (!req.query.sessionId) { + return next( + new ServerError({ + message: "Missing required sessionId query param", status: 400, }), ); } - req.body = { - amount: req.params.paymentAmount, - reference: req.query.sessionId, + + const createPaymentBody: GovPayCreatePayment = { + amount: parseInt(req.params.paymentAmount), + reference: req.query.sessionId as string, description: "New application (nominated payee)", - return_url: req.query.returnURL, + return_url: req.query.returnURL as string, }; + + req.body = createPaymentBody; + next(); }