Skip to content

Commit

Permalink
update stripe utils, impl confirmation page, update premium section
Browse files Browse the repository at this point in the history
  • Loading branch information
dallen4 committed Aug 1, 2023
1 parent 2e887b0 commit ca7b2f8
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 10 deletions.
12 changes: 7 additions & 5 deletions web/api/stripe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ export function buildEvent(request: NextApiRequest) {
}

export async function getEmailForCheckout(id: string) {
const session = await client.checkout.sessions.retrieve(id, {
expand: ['line_items'],
});

// session.line_items!.data[0]
const session = await client.checkout.sessions.retrieve(id);

return session.customer_email!;
}

export async function validateCheckoutSession(id: string) {
const session = await client.checkout.sessions.retrieve(id);

return session.payment_status === 'paid';
}
44 changes: 44 additions & 0 deletions web/pages/confirmation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React from 'react';
import { Center, Container, Title, useMantineTheme } from '@mantine/core';
import { GetServerSideProps } from 'next/types';
import { validateCheckoutSession } from 'api/stripe';

const PremiumConfirmation = (props: { success: boolean }) => {
const theme = useMantineTheme();
return (
<Container style={{ maxWidth: '700px' }}>
<Center
style={{
minHeight: '230px',
paddingTop: theme.spacing.xl,
paddingBottom: theme.spacing.md,
}}
>
<Title size={'h2'}>
Premium{' '}
{props.success ? 'Activated' : 'Subscription Failed'}!
</Title>
</Center>
</Container>
);
};

export const getServerSideProps: GetServerSideProps<
any,
{ id: string }
> = async ({ params, res }) => {
res.setHeader('Cache-Control', 'private, maxage=600');

let success = false;
const checkoutSessionId = params?.id;

if (checkoutSessionId) {
const sessionPaid = await validateCheckoutSession(checkoutSessionId);

if (sessionPaid) success = true;
}

return { props: { success } };
};

export default PremiumConfirmation;
32 changes: 27 additions & 5 deletions web/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,37 @@ const Home = () => {
<Faq />
<Center
style={{
minHeight: '230px',
minHeight: '200px',
paddingTop: theme.spacing.xl,
paddingBottom: theme.spacing.md,
display: 'flex',
flexDirection: 'column',
justifyContent: 'space-evenly',
alignItems: 'center',
}}
>
<Button
onClick={() => (window.location.href = paymentLink)}
type={'button'}
>Get Premium</Button>
<Title size={'h4'}>
Get unlimited daily drops and upcoming features by support
deadrop!
</Title>
<Center
style={{
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
}}
>
<Button
onClick={() => (window.location.href = paymentLink)}
type={'button'}
>
Get Premium
</Button>
<Text size={'xs'}>
All licenses are attached to your email.
</Text>
</Center>
</Center>
</>
);
Expand Down

0 comments on commit ca7b2f8

Please sign in to comment.