-
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
5 changed files
with
80 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { RouteModal } from '@/components/route-modal'; | ||
import { fetchAccountAICredits } from '@/lib/services/account'; | ||
import { getPrices } from '@/lib/services/stripe/client'; | ||
import { | ||
CalloutIcon, | ||
CalloutRoot, | ||
CalloutText, | ||
Flex, | ||
Heading, | ||
} from '@radix-ui/themes'; | ||
import { CgInfo } from 'react-icons/cg'; | ||
|
||
export default async function Page() { | ||
const _prices = await getPrices(); | ||
const credits = await fetchAccountAICredits(); | ||
|
||
return ( | ||
<RouteModal> | ||
<Flex direction="column" gap="4"> | ||
<Heading as="h2" size="6"> | ||
Your credits | ||
</Heading> | ||
|
||
<CalloutRoot size="1"> | ||
<CalloutIcon> | ||
<CgInfo /> | ||
</CalloutIcon> | ||
|
||
<CalloutText>You have {credits} credits remaining.</CalloutText> | ||
</CalloutRoot> | ||
</Flex> | ||
</RouteModal> | ||
); | ||
} |
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,23 @@ | ||
import { env } from '@/env.mjs'; | ||
import { createExternalServiceError } from '@/lib/errors'; | ||
import { Stripe } from 'stripe'; | ||
|
||
const stripe = new Stripe(env.STRIPE_SECRET_KEY); | ||
const StripeError = createExternalServiceError('Stripe'); | ||
|
||
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; | ||
}; |
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.