-
-
Notifications
You must be signed in to change notification settings - Fork 134
feat(billing): scaffold dual Stripe account support (EE default) #3219
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
base: main
Are you sure you want to change the base?
Changes from all commits
72a1881
0fd63bd
3577bdf
415605e
0603a6e
58ec483
762dba4
c81191b
cacee2b
9668e87
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,11 +5,13 @@ import { middlewareAuth } from '../utils/hono_jwt.ts' | |||||||||
| import { cloudlog } from '../utils/logging.ts' | ||||||||||
| import { checkPermission } from '../utils/rbac.ts' | ||||||||||
| import { createCheckout } from '../utils/stripe.ts' | ||||||||||
| import { supabaseClient } from '../utils/supabase.ts' | ||||||||||
| import { resolveBillingAccount, resolvePlanProductId } from '../utils/stripe_billing_account.ts' | ||||||||||
| import { supabaseAdmin, supabaseClient } from '../utils/supabase.ts' | ||||||||||
| import { getEnv } from '../utils/utils.ts' | ||||||||||
|
|
||||||||||
| interface CheckoutData { | ||||||||||
| priceId: string | ||||||||||
| priceId?: string | ||||||||||
| planName?: string | ||||||||||
| clientReferenceId?: string | ||||||||||
| recurrence: 'month' | 'year' | ||||||||||
| attributionId?: string | ||||||||||
|
|
@@ -25,6 +27,27 @@ export const app = new Hono<MiddlewareKeyVariables>() | |||||||||
|
|
||||||||||
| app.use('/', useCors) | ||||||||||
|
|
||||||||||
| async function resolveCheckoutPlanProductId(c: Parameters<typeof createCheckout>[0], customerId: string, body: CheckoutData) { | ||||||||||
| if (body.planName) { | ||||||||||
| const account = await resolveBillingAccount(c, customerId) | ||||||||||
| const { data: plan, error } = await supabaseAdmin(c) | ||||||||||
| .from('plans') | ||||||||||
| .select('stripe_id, stripe_id_us, name') | ||||||||||
| .eq('name', body.planName) | ||||||||||
| .single() | ||||||||||
|
|
||||||||||
| if (error || !plan) | ||||||||||
| throw simpleError('invalid_plan', 'Invalid plan', { planName: body.planName }) | ||||||||||
|
|
||||||||||
| return resolvePlanProductId(plan, account) | ||||||||||
|
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. P1: When a customer is assigned to the US account before Prompt for AI agents
Suggested change
|
||||||||||
| } | ||||||||||
|
|
||||||||||
| if (body.priceId) | ||||||||||
| return body.priceId | ||||||||||
|
|
||||||||||
| throw simpleError('no_plan_provided', 'No plan provided') | ||||||||||
| } | ||||||||||
|
|
||||||||||
| app.post('/', middlewareAuth, async (c) => { | ||||||||||
| const body = await parseBody<CheckoutData>(c) | ||||||||||
| cloudlog({ requestId: c.get('requestId'), message: 'post stripe checkout body', body }) | ||||||||||
|
|
@@ -58,8 +81,10 @@ app.post('/', middlewareAuth, async (c) => { | |||||||||
| if (!await checkPermission(c, 'org.update_billing', { orgId: body.orgId })) | ||||||||||
| throw simpleError('not_authorize', 'Not authorize') | ||||||||||
|
|
||||||||||
| const planProductId = await resolveCheckoutPlanProductId(c, org.customer_id, body) | ||||||||||
|
|
||||||||||
| cloudlog({ requestId: c.get('requestId'), message: 'user', org }) | ||||||||||
| const checkout = await createCheckout(c, org.customer_id, body.recurrence ?? 'month', body.priceId ?? 'price_1KkINoGH46eYKnWwwEi97h1B', body.successUrl ?? `${getEnv(c, 'WEBAPP_URL')}/app/usage`, body.cancelUrl ?? `${getEnv(c, 'WEBAPP_URL')}/app/usage`, body.clientReferenceId, body.attributionId, { | ||||||||||
| const checkout = await createCheckout(c, org.customer_id, body.recurrence ?? 'month', planProductId, body.successUrl ?? `${getEnv(c, 'WEBAPP_URL')}/app/usage`, body.cancelUrl ?? `${getEnv(c, 'WEBAPP_URL')}/app/usage`, body.clientReferenceId, body.attributionId, { | ||||||||||
| visitorId: body.datafastVisitorId, | ||||||||||
| sessionId: body.datafastSessionId, | ||||||||||
| }, body.affonsoReferral) | ||||||||||
|
|
||||||||||
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.
P2: When a US billing account has a distinct product, this account-aware checkout path still records
plan.stripe_id(the EE product) in theCheckout Startedevent. Return or otherwise use the account-resolved product ID for tracking so US checkout analytics are not attributed to EE.Prompt for AI agents