-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add payment exemption status to Slack notifications #2251
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
26e5b60
refactor: Move webhook routes from server to module
DafyddLlyr 4c7541f
refactor: Update sendSlackNotification to modular structure
DafyddLlyr b27fff3
test: Add email-submission tests
DafyddLlyr 4e4da97
refactor: Rename and restructure folders, simplify service
DafyddLlyr b686bce
feat: Add exemption status to notification
DafyddLlyr db74eeb
docs: Add Swagger docs
DafyddLlyr ad08273
fix: Don't use fee to calculate exemption statuses
DafyddLlyr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the new API structure leads to a lot of long/messy relative import paths we could look at resolving this with path aliases - https://blog.logrocket.com/using-path-aliases-cleaner-react-typescript-imports/