fix(stripe): correct Stripe secret key environment variable typo#4
fix(stripe): correct Stripe secret key environment variable typo#4Yuankai619 wants to merge 1 commit into
Conversation
Fixes the typo in the Stripe secret key environment variable spelling, allowing the client to successfully initialize using Stripe_CHANNEL_SECRET while retaining compatibility with the typo'd Stripe_CHANEL_SECRET. Co-Authored-By: Corvo Agent <noreply@corvo.dev>
There was a problem hiding this comment.
Code Review
This pull request corrects a typo in the Stripe secret environment variable name while maintaining backward compatibility with the legacy name. Feedback suggests improving the robustness of the Stripe initialization by explicitly validating the secret key instead of using non-null assertions. Additionally, it is recommended to centralize the environment variable retrieval logic to eliminate code duplication between the API route and the Stripe library.
| export function getStripe(): Stripe { | ||
| if (!_stripe) { | ||
| const stripeSecretKey = process.env.Stripe_CHANEL_SECRET; | ||
| const stripeSecretKey = process.env.Stripe_CHANNEL_SECRET || process.env.Stripe_CHANEL_SECRET; |
There was a problem hiding this comment.
While this change correctly addresses the typo and provides a fallback, the code still relies on a non-null assertion (!) on the following line. If neither environment variable is configured, the application will crash with a generic error from the Stripe library. It is better to explicitly validate the presence of the secret key and throw a descriptive error to improve observability and prevent runtime surprises, especially since this area was already identified as a source of production incidents.
| const stripeSecretKey = process.env.Stripe_CHANNEL_SECRET || process.env.Stripe_CHANEL_SECRET; | |
| const stripeSecretKey = process.env.Stripe_CHANNEL_SECRET || process.env.Stripe_CHANEL_SECRET; | |
| if (!stripeSecretKey) { | |
| throw new Error('Stripe secret key is missing. Please set Stripe_CHANNEL_SECRET.'); | |
| } |
| } | ||
|
|
||
| if (isMockKey(process.env.Stripe_CHANEL_SECRET)) { | ||
| if (isMockKey(process.env.Stripe_CHANNEL_SECRET || process.env.Stripe_CHANEL_SECRET)) { |
There was a problem hiding this comment.
The logic for retrieving the Stripe secret key (including the fallback for the legacy typo) is duplicated here and in lib/stripe.ts. This duplication increases the maintenance burden and the risk of future errors if the environment variable configuration changes again. Consider centralizing this lookup in lib/stripe.ts by exporting the key or a helper function to ensure consistency across the application.
What does this PR do?
This pull request resolves a spelling discrepancy in the Stripe secret key environment variable by updating both
lib/stripe.tsandapp/api/checkout/payment/route.tsto utilize the correctStripe_CHANNEL_SECRETenvironment variable (spelled with two 'L's). For extra safety and backward compatibility, it falls back to the typo'dStripe_CHANEL_SECRET(one 'L') if that is what's configured.Why is this change needed?
Link the alert / incident that triggered the investigation:
0.o85rqsbrm37aTicket flow error alert(dev)2026-05-22T17:19:16.000Zticketflowhad Stripe environment variables configured with the standard spelling (Stripe_CHANNEL_SECRET), but the code initialized Stripe using the typo'dStripe_CHANEL_SECRET, resulting in anundefinedAPI key passing tonew Stripe(...)and throwing the runtime error:Neither apiKey nor config.authenticator provided.How was this change tested?
npm run lint(verified that no syntax or type errors were introduced in the changed files)Stripeinitialization to succeed properly.What should reviewers focus on?
Review the fallback logic
process.env.Stripe_CHANNEL_SECRET || process.env.Stripe_CHANEL_SECRETinlib/stripe.tsandapp/api/checkout/payment/route.tsto ensure maximum robustness and zero disruption across environments.Out of scope
Changing existing Cloud Run configuration, CI workflows, or other files. The focus remains exclusively on correcting the source code lookup for Stripe keys.
Generated by
🤖 Corvo Agent — investigation traced to commit
0760376where Stripe client lazy initialization was refactored and locked in the spelling typo.