Skip to content

Commit

Permalink
feat: Setup defaults in planx-core
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Apr 17, 2024
1 parent 30728f4 commit c1e0944
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
17 changes: 1 addition & 16 deletions api.planx.uk/modules/pay/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,26 +137,11 @@ export async function buildPaymentPayload(
}

// Convert metadata to format required by GovPay
const govPayMetadata = formatGovPayMetadata(
const metadata = formatGovPayMetadata(
res.locals.govPayMetadata,
res.locals.passport,
);

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 = Object.keys(govPayMetadata).length
? govPayMetadata
: defaultGovPayMetadata;

const createPaymentBody: GovPayCreatePayment = {
amount: parseInt(req.params.paymentAmount),
reference: req.query.sessionId as string,
Expand Down
5 changes: 5 additions & 0 deletions api.planx.uk/tests/mocks/inviteToPayMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ export const createPaymentRequestQueryMock = {
payeeName: payee.name,
payeeEmail: payee.email,
sessionPreviewData: sessionPreviewData,
govPayMetadata: [
{ key: "source", value: "PlanX" },
{ key: "isInviteToPay", value: true },
{ key: "flow", value: validSession.flow.slug },
],
},
};

Expand Down

0 comments on commit c1e0944

Please sign in to comment.