-
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.
- Loading branch information
Showing
8 changed files
with
104 additions
and
13 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
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,25 @@ | ||
'use server'; | ||
|
||
import { stripe } from './client'; | ||
|
||
export const createCheckoutSession = async ({ | ||
baseUrl, | ||
priceId, | ||
}: { | ||
baseUrl: string; | ||
priceId: string; | ||
}) => { | ||
const session = await stripe.checkout.sessions.create({ | ||
cancel_url: `${baseUrl}?status=cancel`, | ||
line_items: [ | ||
{ | ||
price: priceId, | ||
quantity: 1, | ||
}, | ||
], | ||
mode: 'payment', | ||
success_url: `${baseUrl}?status=success`, | ||
}); | ||
|
||
return session; | ||
}; |
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,7 @@ | ||
import { env } from '@/env.mjs'; | ||
import { createExternalServiceError } from '@/lib/errors'; | ||
import { Stripe } from 'stripe'; | ||
|
||
export const stripe = new Stripe(env.STRIPE_SECRET_KEY); | ||
|
||
export const StripeError = createExternalServiceError('Stripe'); |
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,22 @@ | ||
'use server'; | ||
|
||
import { StripeError, stripe } from './client'; | ||
|
||
const getProduct = async () => { | ||
const products = await stripe.products.list(); | ||
const product = products.data.find((p) => p.metadata.project === 'beecast'); | ||
|
||
if (!product) { | ||
throw new StripeError('Product not found!'); | ||
} | ||
|
||
return product; | ||
}; | ||
|
||
export const getPrices = async () => { | ||
const product = await getProduct(); | ||
const prices = await stripe.prices.list({ product: product.id }); | ||
return prices.data | ||
.filter((p) => p.active) | ||
.sort((a, b) => a.unit_amount! - b.unit_amount!); | ||
}; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.