* Create a billing portal URL for a Stripe customer
(stripeCustomerId: string)
| 174 | * Create a billing portal URL for a Stripe customer |
| 175 | */ |
| 176 | async function createBillingPortalUrl(stripeCustomerId: string): Promise<string> { |
| 177 | try { |
| 178 | const stripe = requireStripeClient() |
| 179 | const baseUrl = getBaseUrl() |
| 180 | const portal = await stripe.billingPortal.sessions.create({ |
| 181 | customer: stripeCustomerId, |
| 182 | return_url: `${baseUrl}/workspace?billing=updated`, |
| 183 | }) |
| 184 | return portal.url |
| 185 | } catch (error) { |
| 186 | logger.error('Failed to create billing portal URL', { error, stripeCustomerId }) |
| 187 | // Fallback to generic billing page |
| 188 | return `${getBaseUrl()}/workspace?tab=subscription` |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * Get payment method details from Stripe invoice |
no test coverage detected