-
Notifications
You must be signed in to change notification settings - Fork 35
refactor: streamline Dodo Payments integration and error handling: #256
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 all commits
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 | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,21 @@ | ||||||||||||||||||||
| import { DodoPayments } from "dodopayments" | ||||||||||||||||||||
|
|
||||||||||||||||||||
| export type DodoEnvironment = "test_mode" | "live_mode" | ||||||||||||||||||||
|
|
||||||||||||||||||||
| export function getDodoEnvironment(): DodoEnvironment { | ||||||||||||||||||||
| return process.env.DODO_MODE === "test" ? "test_mode" : "live_mode" | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
Comment on lines
+5
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Reject unknown An unset or invalid value, such as Proposed fix export function getDodoEnvironment(): DodoEnvironment {
- return process.env.DODO_MODE === "test" ? "test_mode" : "live_mode"
+ if (process.env.DODO_MODE === "test") return "test_mode"
+ if (process.env.DODO_MODE === "live") return "live_mode"
+
+ throw new Error('DODO_MODE must be "test" or "live"')
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||
|
|
||||||||||||||||||||
| /** Shared Dodo SDK client. Honors DODO_MODE so test keys hit the test API. */ | ||||||||||||||||||||
| export function getDodo(options?: { webhookKey?: boolean }): DodoPayments | null { | ||||||||||||||||||||
| const key = process.env.DODO_PAYMENTS_API_KEY | ||||||||||||||||||||
| if (!key) return null | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return new DodoPayments({ | ||||||||||||||||||||
| bearerToken: key, | ||||||||||||||||||||
| environment: getDodoEnvironment(), | ||||||||||||||||||||
| ...(options?.webhookKey | ||||||||||||||||||||
| ? { webhookKey: process.env.DODO_PAYMENTS_WEBHOOK_KEY } | ||||||||||||||||||||
| : {}), | ||||||||||||||||||||
| }) | ||||||||||||||||||||
| } | ||||||||||||||||||||
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.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: yashdev9274/supercli
Length of output: 3782
🏁 Script executed:
Repository: yashdev9274/supercli
Length of output: 25788
🏁 Script executed:
Repository: yashdev9274/supercli
Length of output: 13442
Reject checkout requests where
userIddoes not match the authenticated user./api/billing/checkoutacceptsuserIddirectly from the request body and creates the Dodo checkout using that value. Add middleware that resolves the request user, then compare it withreq.body.userIdbefore queryingUseror creating the checkout session.🤖 Prompt for AI Agents