Repository navigation
feat(stripe): handle payment failures with email, tracking and backoff #1407
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
Changes from 1 commit
6296da0
41a1146
60e001b
8de2602
9ae245d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -248,6 +248,142 @@ export function generateTrialStartedEmailHtml( | |||||||||
| `.trim(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| export interface PaymentFailureDetails { | ||||||||||
| errorMessage: string; | ||||||||||
| errorCode?: string; | ||||||||||
| declineCode?: string; | ||||||||||
| amount?: number; | ||||||||||
| currency?: string; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| export function generatePaymentFailureEmailHtml( | ||||||||||
| organizationName: string, | ||||||||||
| details: PaymentFailureDetails, | ||||||||||
| ): string { | ||||||||||
| const escapedOrgName = escapeHtml(organizationName); | ||||||||||
| const escapedErrorMessage = escapeHtml(details.errorMessage); | ||||||||||
|
|
||||||||||
| const formattedAmount = | ||||||||||
| details.amount && details.currency | ||||||||||
|
||||||||||
| details.amount && details.currency | |
| details.amount !== undefined && | |
| details.amount !== null && | |
| details.currency |
Copilot
AI
Jan 5, 2026
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.
The currency formatting displays the currency code followed by the amount (e.g., "USD 10.00"), but standard formatting conventions typically place currency symbols before amounts (e.g., "$10.00") or use proper locale-specific formatting. Consider using Intl.NumberFormat for proper currency formatting based on the currency code, which will handle both symbol placement and decimal precision correctly.
Copilot
AI
Jan 5, 2026
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.
The formattedAmount variable is not HTML-escaped before being interpolated into the email template at line 333. While the amount itself is a number and currency is converted to uppercase, it's a best practice to escape all user-controlled or external data before inserting it into HTML to prevent potential XSS vulnerabilities. The currency string comes from Stripe's paymentIntent.currency which should be safe, but defense-in-depth suggests escaping this value.
| ${formattedAmount ? `<p style="margin: 10px 0 0 0; font-size: 14px; color: #7f1d1d;">Amount: ${formattedAmount}</p>` : ""} | |
| ${formattedAmount ? `<p style="margin: 10px 0 0 0; font-size: 14px; color: #7f1d1d;">Amount: ${escapeHtml(formattedAmount)}</p>` : ""} |
Copilot
AI
Jan 5, 2026
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.
The hardcoded year "2025" in the footer copyright notice will become outdated. Consider using dynamic year generation based on the current date to avoid manual updates each year.
| © 2025 LLM Gateway. All rights reserved. This is a transactional email and it can't be unsubscribed from. | |
| © ${new Date().getFullYear()} LLM Gateway. All rights reserved. This is a transactional email and it can't be unsubscribed from. |
Copilot
AI
Jan 5, 2026
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.
The new generatePaymentFailureEmailHtml function lacks test coverage. Since the repository includes comprehensive automated testing for utility functions (as seen in email-validation.spec.ts and invoice.spec.ts), this new email generation function should have corresponding tests to cover various error scenarios including different decline codes, error codes, and edge cases like missing amount/currency values.
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.
The nullish coalescing operator with undefined conversion (
errorCode ?? undefined) is redundant. WhenerrorCodeis null or undefined, the nullish coalescing operator will return undefined, which is the same as just passingerrorCodedirectly since the PaymentFailureDetails interface already accepts optional string fields. The same applies todeclineCode ?? undefined. These conversions can be simplified to justerrorCodeanddeclineCode.