-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add payment exemption status to Slack notifications (#2251)
* refactor: Move webhook routes from server to module * refactor: Update sendSlackNotification to modular structure * test: Add email-submission tests * refactor: Rename and restructure folders, simplify service * feat: Add exemption status to notification * docs: Add Swagger docs * fix: Don't use fee to calculate exemption statuses
- Loading branch information
1 parent
d6eb95d
commit 8fb8e06
Showing
21 changed files
with
740 additions
and
320 deletions.
There are no files selected for viewing
6 changes: 3 additions & 3 deletions
6
...x.uk/webhooks/lowcalSessionEvents.test.ts → ...webhooks/_old/lowcalSessionEvents.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
api.planx.uk/webhooks/lowcalSessionEvents.ts → ...ules/webhooks/_old/lowcalSessionEvents.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
....uk/webhooks/paymentRequestEvents.test.ts → ...ebhooks/_old/paymentRequestEvents.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...planx.uk/webhooks/paymentRequestEvents.ts → ...les/webhooks/_old/paymentRequestEvents.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...oks/sanitiseApplicationData/index.test.ts → ...old/sanitiseApplicationData/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { ServerError } from "../../errors"; | ||
import { sendSlackNotification } from "./sendNotification/service"; | ||
import { SendSlackNotification } from "./sendNotification/types"; | ||
|
||
export const sendSlackNotificationController: SendSlackNotification = async ( | ||
req, | ||
res, | ||
next, | ||
) => { | ||
const isProduction = process.env.APP_ENVIRONMENT === "production"; | ||
if (!isProduction) { | ||
return res.status(200).send({ | ||
message: `Staging application submitted, skipping Slack notification`, | ||
}); | ||
} | ||
|
||
const eventData = req.body.event.data.new; | ||
const eventType = req.query.type; | ||
|
||
try { | ||
const data = await sendSlackNotification(eventData, eventType); | ||
return res.status(200).send({ message: "Posted to Slack", data }); | ||
} catch (error) { | ||
return next( | ||
new ServerError({ | ||
message: `Failed to send ${eventType} Slack notification`, | ||
cause: error, | ||
}), | ||
); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
openapi: 3.1.0 | ||
info: | ||
title: Plan✕ API | ||
version: 0.1.0 | ||
tags: | ||
- name: webhooks | ||
description: Webhooks for event management | ||
components: | ||
schemas: | ||
Payload: | ||
type: object | ||
properties: | ||
sessionId: | ||
type: string | ||
required: | ||
- sessionId | ||
BopsSubmissionSchema: | ||
type: object | ||
properties: | ||
body: | ||
type: object | ||
properties: | ||
event: | ||
type: object | ||
properties: | ||
data: | ||
type: object | ||
properties: | ||
new: | ||
type: object | ||
properties: | ||
payload: | ||
$ref: "#/components/schemas/Payload" | ||
bops_id: | ||
type: string | ||
destination_url: | ||
type: string | ||
required: | ||
- body | ||
UniformSubmissionSchema: | ||
type: object | ||
properties: | ||
body: | ||
type: object | ||
properties: | ||
event: | ||
type: object | ||
properties: | ||
data: | ||
type: object | ||
properties: | ||
new: | ||
type: object | ||
properties: | ||
payload: | ||
$ref: "#/components/schemas/Payload" | ||
submission_reference: | ||
type: string | ||
response: | ||
type: object | ||
properties: | ||
organisation: | ||
type: string | ||
required: | ||
- body | ||
EmailSubmissionSchema: | ||
type: object | ||
properties: | ||
body: | ||
type: object | ||
properties: | ||
event: | ||
type: object | ||
properties: | ||
data: | ||
type: object | ||
properties: | ||
new: | ||
type: object | ||
properties: | ||
session_id: | ||
type: string | ||
team_slug: | ||
type: string | ||
request: | ||
type: object | ||
properties: | ||
personalisation: | ||
type: object | ||
properties: | ||
serviceName: | ||
type: string | ||
required: | ||
- body | ||
SendSlackNotificationSchema: | ||
oneOf: | ||
- $ref: "#/components/schemas/BopsSubmissionSchema" | ||
- $ref: "#/components/schemas/UniformSubmissionSchema" | ||
- $ref: "#/components/schemas/EmailSubmissionSchema" | ||
responses: | ||
SlackNotificationSuccessMessage: | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
properties: | ||
data: | ||
type: string | ||
required: false | ||
description: The generated Slack message | ||
message: | ||
type: string | ||
required: true | ||
paths: | ||
/webhooks/hasura/sendSlackNotification: | ||
post: | ||
tags: ["webhooks"] | ||
summary: Send Slack notification | ||
description: Endpoint to trigger a Slack notification following a submission event | ||
parameters: | ||
- in: query | ||
name: type | ||
type: string | ||
enum: ["bops-submission", "uniform-submission", "email-submission"] | ||
required: true | ||
requestBody: | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/SendSlackNotificationSchema" | ||
responses: | ||
"200": | ||
$ref: "#/components/responses/SlackNotificationSuccessMessage" | ||
"500": | ||
$ref: "#/components/responses/ErrorMessage" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Router } from "express"; | ||
import { useHasuraAuth } from "../auth/middleware"; | ||
import { createPaymentSendEvents } from "../../inviteToPay/createPaymentSendEvents"; | ||
import { sanitiseApplicationData } from "./_old/sanitiseApplicationData"; | ||
import { | ||
createExpiryEvent, | ||
createReminderEvent, | ||
} from "./_old/lowcalSessionEvents"; | ||
import { | ||
createPaymentExpiryEvents, | ||
createPaymentInvitationEvents, | ||
createPaymentReminderEvents, | ||
} from "./_old/paymentRequestEvents"; | ||
import { validate } from "../../shared/middleware/validate"; | ||
import { sendSlackNotificationController } from "./controller"; | ||
import { sendSlackNotificationSchema } from "./sendNotification/schema"; | ||
|
||
const router = Router(); | ||
|
||
router.use("/hasura", useHasuraAuth); | ||
router.post("/hasura/create-reminder-event", createReminderEvent); | ||
router.post("/hasura/create-expiry-event", createExpiryEvent); | ||
router.post( | ||
"/hasura/create-payment-invitation-events", | ||
createPaymentInvitationEvents, | ||
); | ||
router.post( | ||
"/hasura/create-payment-reminder-events", | ||
createPaymentReminderEvents, | ||
); | ||
router.post("/hasura/create-payment-expiry-events", createPaymentExpiryEvents); | ||
router.post("/hasura/create-payment-send-events", createPaymentSendEvents); | ||
router.post( | ||
"/hasura/send-slack-notification", | ||
validate(sendSlackNotificationSchema), | ||
sendSlackNotificationController, | ||
); | ||
router.post("/hasura/sanitise-application-data", sanitiseApplicationData); | ||
|
||
export default router; |
Oops, something went wrong.