-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from wizelineacademy/stripe-payments
feat: Configured stripe process for payment
- Loading branch information
Showing
11 changed files
with
270 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,24 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
images: { | ||
remotePatterns: [ | ||
{ | ||
protocol: 'https', | ||
hostname: 'oaidalleapiprodscus.blob.core.windows.net', | ||
port: '', | ||
}, | ||
{ | ||
protocol: "https", | ||
hostname: "vita-juliomeza2510-mybucket-uvkhksmm.s3.us-east-1.amazonaws.com", | ||
port: '' | ||
} | ||
], | ||
}, | ||
reactStrictMode: false, | ||
experimental: { | ||
serverComponentsExternalPackages: [ | ||
'puppeteer-core', | ||
'@sparticuz/chromium' | ||
] | ||
} | ||
}; | ||
images: { | ||
remotePatterns: [ | ||
{ | ||
protocol: 'https', | ||
hostname: 'oaidalleapiprodscus.blob.core.windows.net', | ||
port: '', | ||
}, | ||
{ | ||
protocol: 'https', | ||
hostname: | ||
'vita-juliomeza2510-mybucket-uvkhksmm.s3.us-east-1.amazonaws.com', | ||
port: '', | ||
}, | ||
], | ||
}, | ||
reactStrictMode: false, | ||
experimental: { | ||
serverComponentsExternalPackages: ['puppeteer-core', '@sparticuz/chromium'], | ||
}, | ||
} | ||
|
||
export default nextConfig; | ||
export default nextConfig |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,46 @@ | ||
import { authOptions } from '@/src/lib/auth/authOptions' | ||
import { stripe } from '@/src/lib/stripe/stripe' | ||
import { getServerSession } from 'next-auth' | ||
import { NextResponse } from 'next/server' | ||
import Stripe from 'stripe' | ||
|
||
export async function POST(req: Request) { | ||
const body = await req.json() | ||
const session = await getServerSession(authOptions) | ||
const { priceId, allowTrial } = body | ||
|
||
const stripeConfig: Stripe.Checkout.SessionCreateParams = { | ||
success_url: 'http://localhost:3000/home', | ||
cancel_url: 'http://localhost:3000', | ||
payment_method_types: ['card'], | ||
mode: 'subscription', | ||
billing_address_collection: 'auto', | ||
customer_email: session?.user.email, | ||
allow_promotion_codes: true, | ||
line_items: [ | ||
{ | ||
price: priceId, | ||
quantity: 1, | ||
}, | ||
], | ||
metadata: { | ||
userId: session?.user.id, | ||
}, | ||
subscription_data: { | ||
trial_settings: { | ||
end_behavior: { | ||
missing_payment_method: 'cancel', | ||
}, | ||
}, | ||
}, | ||
payment_method_collection: 'if_required', | ||
} | ||
|
||
if (stripeConfig.subscription_data && allowTrial) { | ||
stripeConfig.subscription_data.trial_period_days = 7 | ||
} | ||
|
||
const res = await stripe.checkout.sessions.create(stripeConfig) | ||
|
||
return NextResponse.json({ url: res.url }, { status: 200 }) | ||
} |
Oops, something went wrong.