Skip to content

Commit

Permalink
Merge pull request #382 from ubc-biztech/dev
Browse files Browse the repository at this point in the history
Update email message if QR code doesn't display; add SNS topic for monitoring
  • Loading branch information
voctory authored Sep 1, 2024
2 parents e907acf + fc53d32 commit eee6a02
Show file tree
Hide file tree
Showing 12 changed files with 1,440 additions and 247 deletions.
23 changes: 23 additions & 0 deletions lib/snsHelper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {
SNSClient, PublishCommand
} from "@aws-sdk/client-sns";

const snsClient = new SNSClient({
region: "us-west-2"
});

export async function sendSNSNotification(message, topicArn = process.env.SNS_TOPIC_ARN) {
const params = {
Message: JSON.stringify(message),
TopicArn: topicArn
};

try {
const command = new PublishCommand(params);
await snsClient.send(command);
console.log("SNS notification sent successfully");
} catch (error) {
console.error("Error sending SNS notification:", error);
throw error; // Rethrow the error so the calling function can handle it if needed
}
}
468 changes: 448 additions & 20 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@aws-sdk/client-dynamodb": "^3.620.1",
"@aws-sdk/client-lambda": "^3.620.1",
"@aws-sdk/client-ses": "^3.620.1",
"@aws-sdk/client-sns": "^3.637.0",
"@aws-sdk/lib-dynamodb": "^3.620.1",
"concurrently": "^6.2.0",
"copy-dynamodb-table": "^2.2.1",
Expand Down
42 changes: 42 additions & 0 deletions services/payments/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import {
import {
updateHelper
} from "../registrations/handler";
import {
sendSNSNotification
} from "../../lib/snsHelper";
import db from "../../lib/db";
import docClient from "../../lib/docClient";
const {
Expand Down Expand Up @@ -286,6 +289,19 @@ export const webhook = async (event, ctx, callback) => {
return helpers.inputError("Invalid email", data.email);
}

try {
await sendSNSNotification({
type: "payment_completed",
paymentType: data.paymentType,
email: data.email,
eventID: data.eventID,
year: data.year,
timestamp: new Date().toISOString()
});
} catch (error) {
console.error("Failed to send SNS notification for payment completion:", error);
}

switch (data.paymentType) {
case "UserMember":
await userMemberSignup(data);
Expand Down Expand Up @@ -345,6 +361,19 @@ export const payment = async (event, ctx, callback) => {
checkoutLink: session.url
};
await updateHelper(body, false, data.email, data.fname);

try {
await sendSNSNotification({
type: "payment_initiated",
paymentType: "Event",
email: data.email,
eventID: data.eventID,
year: data.year,
timestamp: new Date().toISOString()
});
} catch (error) {
console.error("Failed to send SNS notification for payment initiation:", error);
}
}

let response = helpers.createResponse(200, session.url);
Expand Down Expand Up @@ -377,6 +406,19 @@ export const cancel = async (event, ctx, callback) => {
// ["eventID;year"]: eventIDAndYear
// });

try {
await sendSNSNotification({
type: "payment_cancelled",
paymentType: "Event",
email,
eventID,
year,
timestamp: new Date().toISOString()
});
} catch (error) {
console.error("Failed to send SNS notification for payment cancellation:", error);
}

const response = helpers.createResponse(200, {
message: "Cancel webhook disabled",
response: {
Expand Down
Loading

0 comments on commit eee6a02

Please sign in to comment.