Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions apps/api/src/stripe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
notifyDevPlanCancelled,
notifyDevPlanRenewed,
notifyDevPlanSubscribed,
notifyResetPassPurchased,
} from "./utils/discord.js";
import {
generateDevPlanCancellationFeedbackEmailHtml,
Expand Down Expand Up @@ -2589,6 +2590,21 @@ export async function fulfillResetPassPurchase(
);
}

// Notify the internal Discord channel, mirroring the other purchase
// notifications. Runs after the transaction insert (guarded by the
// payment-intent dedupe above), so webhook retries won't double-notify.
if (organization.billingEmail) {
const purchaseUser = await db.query.user.findFirst({
where: { email: { eq: organization.billingEmail } },
});
await notifyResetPassPurchased(
organization.billingEmail,
purchaseUser?.name,
tier,
amountPaid,
);
}
Comment on lines +2596 to +2606

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Wrap the notification block in a try-catch to protect subsequent telemetry.

If the database query db.query.user.findFirst fails (e.g., due to a transient database issue), it will throw an exception that permanently skips the posthog.capture step below. Because the purchase transaction has already been committed, subsequent Stripe webhook retries will exit early at the deduplication check and never reach the telemetry step.

Wrapping this block in a try-catch ensures that the notification remains truly "best-effort" without interrupting the remaining post-fulfillment pipeline.

🛡️ Proposed fix to isolate failures
 	if (organization.billingEmail) {
-		const purchaseUser = await db.query.user.findFirst({
-			where: { email: { eq: organization.billingEmail } },
-		});
-		await notifyResetPassPurchased(
-			organization.billingEmail,
-			purchaseUser?.name,
-			tier,
-			amountPaid,
-		);
+		try {
+			const purchaseUser = await db.query.user.findFirst({
+				where: { email: { eq: organization.billingEmail } },
+			});
+			await notifyResetPassPurchased(
+				organization.billingEmail,
+				purchaseUser?.name,
+				tier,
+				amountPaid,
+			);
+		} catch (e) {
+			logger.error(
+				"Reset Pass Discord notification failed; suppressing failure",
+				e as Error,
+			);
+		}
 	}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (organization.billingEmail) {
const purchaseUser = await db.query.user.findFirst({
where: { email: { eq: organization.billingEmail } },
});
await notifyResetPassPurchased(
organization.billingEmail,
purchaseUser?.name,
tier,
amountPaid,
);
}
if (organization.billingEmail) {
try {
const purchaseUser = await db.query.user.findFirst({
where: { email: { eq: organization.billingEmail } },
});
await notifyResetPassPurchased(
organization.billingEmail,
purchaseUser?.name,
tier,
amountPaid,
);
} catch (e) {
logger.error(
"Reset Pass Discord notification failed; suppressing failure",
e as Error,
);
}
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/api/src/stripe.ts` around lines 2596 - 2606, Wrap the billingEmail
notification block in the surrounding purchase fulfillment flow, including
db.query.user.findFirst and notifyResetPassPurchased, with a try-catch. Log or
otherwise handle the notification error without rethrowing, so execution always
continues to the subsequent posthog.capture telemetry step while preserving
best-effort notification behavior.


posthog.capture({
distinctId: "organization",
event: "reset_pass_purchased",
Expand Down
41 changes: 41 additions & 0 deletions apps/api/src/utils/discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,47 @@ export async function notifyDevPlanSubscribed(
});
}

export async function notifyResetPassPurchased(
email: string,
name: string | null | undefined,
devPlan: string,
amount: number,
): Promise<void> {
const displayName = name ?? "Unknown";

await sendDiscordNotification({
embeds: [
{
title: "Reset Pass Purchased",
color: 0x06b6d4, // Cyan
fields: [
{
name: "Email",
value: email,
inline: true,
},
{
name: "Name",
value: displayName,
inline: true,
},
{
name: "Tier",
value: devPlan.toUpperCase(),
inline: true,
},
{
name: "Amount",
value: `$${amount.toFixed(2)}`,
inline: true,
},
],
timestamp: new Date().toISOString(),
},
],
});
}

export async function notifyDevPlanCancelled(
email: string,
name: string | null | undefined,
Expand Down
Loading