Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checkout and pricing #153

Merged
merged 11 commits into from Nov 11, 2020
Merged

checkout and pricing #153

merged 11 commits into from Nov 11, 2020

Conversation

joelhooks
Copy link
Contributor

This adds checkout flow.

  • load price from stripe
  • pick a plan (only 1 currently)
  • get email if not logged in
  • redirect to stripe checkout
  • bring them back after

Requires this to be merged on the backend: https://github.com/eggheadio/egghead-rails/pull/4155

scrooge mcduck counting his money

@vercel
Copy link

vercel bot commented Nov 11, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/eggheadio/egghead-io-nextjs/n4styzys7
✅ Preview: https://egghead-io-nextjs-git-jh-checkout-and-pricing.eggheadio1.vercel.app

const stripeCheckoutRedirect = async (priceId: string, email: string) => {
return await axios
.post(
`${process.env.NEXT_PUBLIC_AUTH_DOMAIN}/api/v1/stripe/subscription`,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loads a checkout session from backend with the configured price ID

stripePromise.then((stripe: any) => {
if (!stripe) throw new Error('Stripe not loaded 😭')
stripe
.redirectToCheckout({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

send us to Stripe if all looks good!


console.log(isPro)

if (isPro) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a quick and dirty lookup to see if we already have a subscription on this particular email

not great UX

)
} else {
setIsError(false)
stripeCheckoutRedirect(priceId, email)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no sub? let's fix that quick.

}

return (
<div className="text-text w-full mx-auto flex flex-col justify-center sm:mt-24 mt-5">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just reused the login form here 😅

export async function loadPrice(priceId: string) {
const price = await stripe.prices.retrieve(priceId)

return price
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a Stripe Price object

@@ -0,0 +1,15 @@
import Stripe from 'stripe'

if (!process.env.STRIPE_SECRET_KEY) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a concern with this because technically it could be imported into a frontend file and exposed, where currently it's being used in a SSR method, and doesn't expose it.

Alternative would be to be more explicit and migrate to a /src/pages/api function where it might be more clear it's not meant to be used in the UI. 🤔

}
}

const Pricing: FunctionComponent<PricingProps> = ({annualPrice}) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modestly sloppy UX that could probably use a little state machine...

})
.then(({data}) => data)

res.status(200).json(!isEmpty(eggheadUser.subscription))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are checking if the user has a subscription, which is probably not a sufficient check but will at least prevent a double subscription for now

Copy link
Contributor Author

@joelhooks joelhooks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is "safe" in that it can be live and if it gets used people should be fine and get a membership, but there are a lot of rough UX edges.

Co-authored-by: Ian Jones <jones58ian@gmail.com>
Co-authored-by: Ian Jones <jones58ian@gmail.com>
@kodiakhq kodiakhq bot merged commit 73f6ba0 into main Nov 11, 2020
@kodiakhq kodiakhq bot deleted the jh/checkout-and-pricing branch November 11, 2020 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants