Skip to content

feat(devpass): notify Discord on Reset Pass buys - #3106

Merged
smakosh merged 1 commit into
mainfrom
feat/reset-pass-discord-notif
Jul 17, 2026
Merged

smakosh merged 1 commit into
mainfrom
feat/reset-pass-discord-notif

Conversation

@smakosh

@smakosh smakosh commented Jul 17, 2026 •

Copy link
Copy Markdown
Member

Summary

Reset Pass purchases (#3093) were the only paid flow with no internal Discord notification — credits, DevPass/chat plan subscribe/renew/cancel, and refunds all post to the billing channel, and a refunded Reset Pass already notified via the generic refund handler. This closes that gap.

  • Add notifyResetPassPurchased to apps/api/src/utils/discord.ts (email, name, tier, amount — same embed pattern as the other purchase notifiers, posts to DISCORD_NOTIFICATION_URL)
  • Call it from fulfillResetPassPurchase after the payment-intent dedupe guard, so the synchronous purchase route and the payment_intent.succeeded recovery webhook can't double-notify
  • Resolves the recipient from organization.billingEmail + user lookup, mirroring the refund notification path

Test plan

  • pnpm exec turbo run build --filter=api passes
  • Notification is best-effort: sendDiscordNotification already swallows webhook failures and skips when DISCORD_NOTIFICATION_URL is unset, so fulfilment is unaffected either way

Summary by CodeRabbit

  • Improvements
    • Improved handling of reset pass purchases to ensure completed transactions are recorded reliably.
    • Added more detailed purchase information to internal notifications, including the purchaser’s email, name, selected tier, and payment amount.
    • Duplicate purchase fulfillment remains prevented, and notification failures do not interrupt payment processing.

@coderabbitai

coderabbitai Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Reset-pass purchase fulfilment now sends billing email, user name, tier, and paid amount to an internal Discord notification through a new reusable webhook helper.

Changes

Reset pass notifications

Layer / File(s) Summary
Discord notification helper
apps/api/src/utils/discord.ts
Adds notifyResetPassPurchased, which builds and sends a formatted reset-pass purchase embed.
Reset-pass fulfilment integration
apps/api/src/stripe.ts
Looks up the billing user and invokes the notification after purchase insertion when a billing email exists.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: steebchen

Sequence Diagram(s)

sequenceDiagram
  participant fulfillResetPassPurchase
  participant UserDatabase
  participant notifyResetPassPurchased
  participant DiscordWebhook
  fulfillResetPassPurchase->>UserDatabase: Look up billing-email user name
  fulfillResetPassPurchase->>notifyResetPassPurchased: Pass email, name, tier, and amount
  notifyResetPassPurchased->>DiscordWebhook: Send purchase embed
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding Discord notifications for Reset Pass purchases.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/reset-pass-discord-notif

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@smakosh
smakosh enabled auto-merge July 17, 2026 19:04

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with 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.

Inline comments:
In `@apps/api/src/stripe.ts`:
- Around line 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.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f9bc9018-490c-4aee-a586-3eb31c24bcf1

📥 Commits

Reviewing files that changed from the base of the PR and between 05fa84c and 66c637b.

📒 Files selected for processing (2)
  • apps/api/src/stripe.ts
  • apps/api/src/utils/discord.ts

Comment thread apps/api/src/stripe.ts
Comment on lines +2596 to +2606
if (organization.billingEmail) {
const purchaseUser = await db.query.user.findFirst({
where: { email: { eq: organization.billingEmail } },
});
await notifyResetPassPurchased(
organization.billingEmail,
purchaseUser?.name,
tier,
amountPaid,
);
}

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.

@smakosh
smakosh added this pull request to the merge queue Jul 17, 2026
Merged via the queue into main with commit a3c6c1e Jul 17, 2026
12 checks passed
@smakosh
smakosh deleted the feat/reset-pass-discord-notif branch July 17, 2026 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant