-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement support for customer portal (#201)
* Implement support for customer portal * yay types * Border for pricing table
- Loading branch information
1 parent
3138a4e
commit 74d7dd8
Showing
5 changed files
with
126 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import {getServerSession} from 'next-auth/next'; | ||
import {authOptions} from '@/lib/auth'; | ||
import {stripe} from '@/lib/stripe'; | ||
import {NextRequest} from 'next/server'; | ||
|
||
export async function GET(req: NextRequest) { | ||
try { | ||
const session = await getServerSession(authOptions); | ||
|
||
const accountId = session?.user?.stripeAccount?.id; | ||
|
||
if (!accountId) { | ||
console.error('No account ID found for user'); | ||
return new Response('No account ID found for user', { | ||
status: 400, | ||
}); | ||
} | ||
|
||
const returnUrl = | ||
process.env.NODE_ENV === 'development' | ||
? 'http://localhost:3000/billing' | ||
: 'https://stripe-connect-furever-v2.onrender.com/billing'; | ||
|
||
const billingPortalSession = await stripe.billingPortal.sessions.create({ | ||
customer: accountId, | ||
return_url: returnUrl, | ||
}); | ||
|
||
return new Response(JSON.stringify(billingPortalSession), { | ||
status: 200, | ||
headers: {'Content-Type': 'application/json'}, | ||
}); | ||
} catch (error: any) { | ||
console.error( | ||
'An error occurred when calling the Stripe API to create an account session', | ||
error | ||
); | ||
return new Response(error.message, {status: 500}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters